Skip to content

Commit

Permalink
Merge branch '5.3' into feature/5.x-purgeevent
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder authored Dec 11, 2024
2 parents a1fa1bf + 87db3ad commit 27a3b34
Show file tree
Hide file tree
Showing 51 changed files with 1,384 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: ci
uses: craftcms/.github/.github/workflows/ci.yml@v3
with:
php_version: '8.2'
php_version: '["8.2", "8.3"]'
craft_version: '5'
node_version: '20'
jobs: '["ecs", "phpstan", "prettier", "tests"]'
Expand Down
24 changes: 21 additions & 3 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# Release Notes for Craft Commerce (WIP)

## Administration
### Store Management
- It is now possible to design card views for Products and Variants. ([#3809](https://github.com/craftcms/commerce/pull/3809))
- Order conditions can now have a “Coupon Code” rule. ([#3776](https://github.com/craftcms/commerce/discussions/3776))
- Order conditions can now have a “Payment Gateway” rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722))
- Variant conditions can now have a “Product” rule.

- Added `craft\commerce\events\CartPurgeEvent`.
### Development
- Added support for `to`, `bcc`, and `cc` email fields to support environment variables. ([#3738](https://github.com/craftcms/commerce/issues/3738))
- Added the `couponCode` order query param.
- Added an `originalCart` value to the `commerce/update-cart` failed ajax response. ([#430](https://github.com/craftcms/commerce/issues/430))
- Added a new "Payment Gateway" order condition rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722))

### Extensibility
- Added `craft\commerce\base\InventoryItemTrait`.
- Added `craft\commerce\base\InventoryLocationTrait`.
- Added `craft\commerce\elements\conditions\orders\CouponCodeConditionRule`.
- Added `craft\commerce\elements\conditions\variants\ProductConditionRule`.
- Added `craft\commerce\elements\db\OrderQuery::$couponCode`.
- Added `craft\commerce\elements\db\OrderQuery::couponCode()`.
- Added `craft\commerce\events\CartPurgeEvent`.
- Added `craft\commerce\services\Inventory::updateInventoryLevel()`.
- Added `craft\commerce\services\Inventory::updatePurchasableInventoryLevel()`.

### System
- Craft Commerce now requires Craft CMS 5.5 or later.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Release Notes for Craft Commerce

## Unreleased

- Fixed a bug where a product’s default price was showing incorrectly on the Products index page. ([#3807](https://github.com/craftcms/commerce/issues/3807))
- Fixed a bug where inline-editable Matrix fields weren’t saving content on product variants. ([#3805](https://github.com/craftcms/commerce/issues/3805))
- Fixed a bug where order errors weren't showing on the Edit Order page.

## 5.2.8 - 2024-12-04

- Fixed a bug where line items weren’t getting hyperlinked within Edit Order pages. ([#3792](https://github.com/craftcms/commerce/issues/3792))
- Fixed a bug where Inventory pages were showing draft purchasables.
- Fixed a PHP error that could occur when creating inventory transfers. ([#3696](https://github.com/craftcms/commerce/issues/3696))
- Fixed a bug where prices weren’t getting formatted per the user’s formatting locale, in payment models on Edit Order pages. ([#3789](https://github.com/craftcms/commerce/issues/3789))
- Fixed a bug where store settings weren’t respecting environment variables. ([#3786](https://github.com/craftcms/commerce/issues/3786))

## 5.2.7 - 2024-12-02

- Fixed an error that occurred on the Orders index page when running Craft CMS 5.5.4 or later. ([#3793](https://github.com/craftcms/commerce/issues/3793))
- Fixed a bug where a structured product type’s “Max Levels” setting wasn’t being respected. ([#3785](https://github.com/craftcms/commerce/issues/3785))
- Fixed an information disclosure vulnerability.

## 5.2.6 - 2024-11-26

- Fixed a bug where variant prices could be displayed incorrectly when inline editing. ([#3768](https://github.com/craftcms/commerce/issues/3768))
- Fixed a performance degradation bug with variant queries. ([#3758](https://github.com/craftcms/commerce/issues/3758))
- Fixed a PHP error that could occur when managing store settings. ([#3780](https://github.com/craftcms/commerce/issues/3780))

## 5.2.5 - 2024-11-20

- The `resave/products`, `resave/orders`, and `resave/carts` commands now support the `--with-fields` option.
- Fixed a SQL error that could occur when updating. ([#3778](https://github.com/craftcms/commerce/issues/3778))

## 5.2.4 - 2024-11-14

- Improved the performance of `craft\commerce\elements\Product::getVariants()`. ([#3578](https://github.com/craftcms/commerce/issues/3758))
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"prefer-stable": true,
"require": {
"php": "^8.2",
"craftcms/cms": "^5.2.0",
"craftcms/cms": "^5.5.0",
"dompdf/dompdf": "^2.0.2",
"ibericode/vat": "^1.2.2",
"iio/libmergepdf": "^4.0",
Expand Down
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 49 additions & 5 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use craft\commerce\helpers\ProjectConfigData;
use craft\commerce\linktypes\Product as ProductLinkType;
use craft\commerce\migrations\Install;
use craft\commerce\models\ProductType;
use craft\commerce\models\Settings;
use craft\commerce\plugin\Routes;
use craft\commerce\plugin\Services as CommerceServices;
Expand Down Expand Up @@ -165,7 +166,9 @@
use craft\web\Application;
use craft\web\twig\variables\CraftVariable;
use Exception;
use Illuminate\Support\Collection;
use yii\base\Event;
use yii\console\ExitCode;
use yii\web\User;

/**
Expand Down Expand Up @@ -254,7 +257,7 @@ public static function editions(): array
/**
* @inheritDoc
*/
public string $schemaVersion = '5.2.0.5';
public string $schemaVersion = '5.2.7.1';

/**
* @inheritdoc
Expand Down Expand Up @@ -794,7 +797,10 @@ function(DefineBehaviorsEvent $event) {

// Add Commerce info to user edit screen
Event::on(UsersController::class, UsersController::EVENT_DEFINE_EDIT_SCREENS, function(DefineEditUserScreensEvent $event) {
$event->screens[CommerceUsersController::SCREEN_COMMERCE] = ['label' => Craft::t('commerce', 'Commerce')];
// Add Commerce screen to user edit screen if the user has permission to access Commerce
if (Craft::$app->getUser()->checkPermission('accessPlugin-commerce')) {
$event->screens[CommerceUsersController::SCREEN_COMMERCE] = ['label' => Craft::t('commerce', 'Commerce')];
}
});

// Site models are instantiated early meaning we have to manually attach the behavior alongside using the event
Expand Down Expand Up @@ -1143,12 +1149,32 @@ private function _defineResaveCommand(): void
/** @var ResaveController $controller */
$controller = Craft::$app->controller;
$criteria = [];

if ($controller->type !== null) {
$criteria['type'] = explode(',', $controller->type);
}

// @TODO Remove this check when Commerce requires Craft 5.5
if (version_compare(Craft::$app->getInfo()->version, '5.5.0', '>=') && !empty($controller->withFields)) {
$handles = Collection::make(self::getInstance()->getProductTypes()->getAllProductTypes())
->filter(fn(ProductType $productType) => $controller->hasTheFields($productType->getFieldLayout()))
->map(fn(ProductType $productType) => $productType->handle)
->all();
if (isset($criteria['type'])) {
$criteria['type'] = array_intersect($criteria['type'], $handles);
} else {
$criteria['type'] = $handles;
}

if (empty($criteria['type'])) {
$controller->output($controller->markdownToAnsi('No product types satisfy `--with-fields`.'));
return ExitCode::UNSPECIFIED_ERROR;
}
}

return $controller->resaveElements(Product::class, $criteria);
},
'options' => ['type'],
'options' => array_filter(['type', (property_exists(ResaveController::class, 'withFields') ? 'withFields' : null)]),
'helpSummary' => 'Re-saves Commerce products.',
'optionsHelp' => [
'type' => 'The product type handle(s) of the products to resave.',
Expand All @@ -1159,23 +1185,41 @@ private function _defineResaveCommand(): void
'action' => function(): int {
/** @var ResaveController $controller */
$controller = Craft::$app->controller;
// @TODO Remove this check when Commerce requires Craft 5.5
if (version_compare(Craft::$app->getInfo()->version, '5.5.0', '>=') && !empty($controller->withFields)) {
$fieldLayout = Craft::$app->getFields()->getLayoutByType(Order::class);
if (!$controller->hasTheFields($fieldLayout)) {
$controller->output($controller->markdownToAnsi('The order field layout doesn’t satisfy `--with-fields`.'));
return ExitCode::UNSPECIFIED_ERROR;
}
}

return $controller->resaveElements(Order::class, [
'isCompleted' => true,
]);
},
'options' => [],
'options' => array_filter([(property_exists(ResaveController::class, 'withFields') ? 'withFields' : null)]),
'helpSummary' => 'Re-saves completed Commerce orders.',
];

$e->actions['carts'] = [
'action' => function(): int {
/** @var ResaveController $controller */
$controller = Craft::$app->controller;
// @TODO Remove this check when Commerce requires Craft 5.5
if (version_compare(Craft::$app->getInfo()->version, '5.5.0', '>=') && !empty($controller->withFields)) {
$fieldLayout = Craft::$app->getFields()->getLayoutByType(Order::class);
if (!$controller->hasTheFields($fieldLayout)) {
$controller->output($controller->markdownToAnsi('The order field layout doesn’t satisfy `--with-fields`.'));
return ExitCode::UNSPECIFIED_ERROR;
}
}

return $controller->resaveElements(Order::class, [
'isCompleted' => false,
]);
},
'options' => [],
'options' => array_filter([(property_exists(ResaveController::class, 'withFields') ? 'withFields' : null)]),
'helpSummary' => 'Re-saves Commerce carts.',
];
});
Expand Down
61 changes: 61 additions & 0 deletions src/base/InventoryItemTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\commerce\base;

use craft\commerce\models\InventoryItem;
use craft\commerce\Plugin;

/**
* Inventory Item Trait
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 5.3.0
*/
trait InventoryItemTrait
{
/**
* @var int|null The inventory item ID
*/
public ?int $inventoryItemId = null;

/**
* @var InventoryItem|null The inventory item
* @see getInventoryItem()
* @see setInventoryItem()
*/
private ?InventoryItem $_inventoryItem = null;

/**
* @param InventoryItem|null $inventoryItem
* @return void
*/
public function setInventoryItem(?InventoryItem $inventoryItem): void
{
$this->_inventoryItem = $inventoryItem;
$this->inventoryItemId = $inventoryItem?->id ?? null;
}

/**
* @return InventoryItem|null
* @throws \yii\base\InvalidConfigException
*/
public function getInventoryItem(): ?InventoryItem
{
if (isset($this->_inventoryItem)) {
return $this->_inventoryItem;
}

if ($this->inventoryItemId) {
$this->_inventoryItem = Plugin::getInstance()->getInventory()->getInventoryItemById($this->inventoryItemId);

return $this->_inventoryItem;
}

return null;
}
}
61 changes: 61 additions & 0 deletions src/base/InventoryLocationTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\commerce\base;

use craft\commerce\models\InventoryLocation;
use craft\commerce\Plugin;

/**
* Inventory Location Trait
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 5.3.0
*/
trait InventoryLocationTrait
{
/**
* @var int|null The inventory item ID
*/
public ?int $inventoryLocationId = null;

/**
* @var InventoryLocation|null The inventory item
* @see getInventoryLocation()
* @see setInventoryLocation()
*/
private ?InventoryLocation $_inventoryLocation = null;

/**
* @param InventoryLocation|null $inventoryLocation
* @return void
*/
public function setInventoryLocation(?InventoryLocation $inventoryLocation): void
{
$this->_inventoryLocation = $inventoryLocation;
$this->inventoryLocationId = $inventoryLocation?->id ?? null;
}

/**
* @return InventoryLocation|null
* @throws \yii\base\InvalidConfigException
*/
public function getInventoryLocation(): ?InventoryLocation
{
if (isset($this->_inventoryLocation)) {
return $this->_inventoryLocation;
}

if ($this->inventoryLocationId) {
$this->_inventoryLocation = Plugin::getInstance()->getInventoryLocations()->getInventoryLocationById($this->inventoryLocationId);

return $this->_inventoryLocation;
}

return null;
}
}
Loading

0 comments on commit 27a3b34

Please sign in to comment.