Skip to content

Commit 27211fe

Browse files
authored
Merge branch '5.3' into feature/com-271-improve-purchasable-stock-updating
2 parents f29a51a + e563b00 commit 27211fe

File tree

8 files changed

+98
-10
lines changed

8 files changed

+98
-10
lines changed

CHANGELOG-WIP.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
# Release Notes for Craft Commerce (WIP)
22

3+
### Store Management
4+
5+
- Order conditions can now have a “Payment Gateway” rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722))
6+
- Variant conditions can now have a “Product” rule.
7+
38
### Administration
49

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

12+
### Development
13+
14+
- Added an `originalCart` value to the `commerce/update-cart` failed ajax response. ([#430](https://github.com/craftcms/commerce/issues/430))
915

10-
### System
16+
### Extensibility
1117

1218
- Added `craft\commerce\base\InventoryItemTrait`.
1319
- Added `craft\commerce\base\InventoryLocationTrait`.
20+
- Added `craft\commerce\elements\conditions\variants\ProductConditionRule`.
1421
- Added `craft\commerce\services\Inventory::updateInventoryLevel()`.
15-
- Added `craft\commerce\services\Inventory::updatePurchasableInventoryLevel()`.
22+
- Added `craft\commerce\services\Inventory::updatePurchasableInventoryLevel()`.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release Notes for Craft Commerce
22

3+
## Unreleased
4+
5+
- 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))
6+
- Fixed a bug where inline-editable Matrix fields weren’t saving content on product variants. ([#3805](https://github.com/craftcms/commerce/issues/3805))
7+
- Fixed a bug where order errors weren't showing on the Edit Order page.
8+
39
## 5.2.8 - 2024-12-04
410

511
- Fixed a bug where line items weren’t getting hyperlinked within Edit Order pages. ([#3792](https://github.com/craftcms/commerce/issues/3792))

src/base/Purchasable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,8 @@ public function afterSave(bool $isNew): void
11321132
*/
11331133
public function afterPropagate(bool $isNew): void
11341134
{
1135+
parent::afterPropagate($isNew);
1136+
11351137
Plugin::getInstance()->getCatalogPricing()->createCatalogPricingJob([
11361138
'purchasableIds' => [$this->getCanonicalId()],
11371139
'storeId' => $this->getStoreId(),

src/controllers/OrdersController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,7 @@ private function _registerJavascript(array $variables): void
14471447

14481448
if ($order->hasErrors()) {
14491449
$response['order']['errors'] = $order->getErrors();
1450+
$response['errors'] = $order->getErrors();
14501451
$response['error'] = Craft::t('commerce', 'The order is not valid.');
14511452
}
14521453

src/elements/Variant.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ public function afterSave(bool $isNew): void
10681068
parent::afterSave($isNew);
10691069

10701070
if (!$this->propagating && $this->isDefault && $ownerId && $this->duplicateOf === null) {
1071+
// @TODO - this data is now joined in on the product query so can be removed at the next breaking change
10711072
$defaultData = [
10721073
'defaultVariantId' => $this->id,
10731074
'defaultSku' => $this->getSkuAsText(),
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* @link https://craftcms.com/
4+
* @copyright Copyright (c) Pixel & Tonic, Inc.
5+
* @license https://craftcms.github.io/license/
6+
*/
7+
8+
namespace craft\commerce\elements\conditions\variants;
9+
10+
use Craft;
11+
use craft\base\conditions\BaseElementSelectConditionRule;
12+
use craft\base\ElementInterface;
13+
use craft\commerce\elements\db\VariantQuery;
14+
use craft\commerce\elements\Product;
15+
use craft\commerce\elements\Variant;
16+
use craft\elements\conditions\ElementConditionRuleInterface;
17+
use craft\elements\db\ElementQueryInterface;
18+
19+
/**
20+
* Products Condition Rule
21+
*
22+
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
23+
* @since 5.3.0
24+
*/
25+
class ProductConditionRule extends BaseElementSelectConditionRule implements ElementConditionRuleInterface
26+
{
27+
/**
28+
* @inheritdoc
29+
*/
30+
protected function elementType(): string
31+
{
32+
return Product::class;
33+
}
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
public function getLabel(): string
39+
{
40+
return Craft::t('commerce', 'Product');
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
public function getExclusiveQueryParams(): array
47+
{
48+
return ['product', 'productId', 'primaryOwnerId', 'primaryOwner', 'owner', 'ownerId'];
49+
}
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
public function modifyQuery(ElementQueryInterface $query): void
55+
{
56+
/** @var VariantQuery $query */
57+
$query->ownerId($this->getElementId());
58+
}
59+
60+
/**
61+
* @inheritdoc
62+
*/
63+
public function matchElement(ElementInterface $element): bool
64+
{
65+
/** @var Variant $element */
66+
return $element->getOwnerId() == $this->getElementId();
67+
}
68+
}

src/elements/conditions/variants/VariantCondition.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class VariantCondition extends ElementCondition
2525
protected function selectableConditionRules(): array
2626
{
2727
return array_merge(parent::selectableConditionRules(), [
28+
ProductConditionRule::class,
2829
SkuConditionRule::class,
2930
]);
3031
}

src/elements/db/ProductQuery.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,18 +768,20 @@ protected function beforePrepare(): bool
768768
'commerce_products.postDate',
769769
'commerce_products.expiryDate',
770770
'subquery.price as defaultPrice',
771-
'commerce_products.defaultPrice as defaultBasePrice',
771+
'purchasablesstores.basePrice as defaultBasePrice',
772772
'commerce_products.defaultVariantId',
773-
'commerce_products.defaultSku',
774-
'commerce_products.defaultWeight',
775-
'commerce_products.defaultLength',
776-
'commerce_products.defaultWidth',
777-
'commerce_products.defaultHeight',
773+
'purchasables.sku as defaultSku',
774+
'purchasables.weight as defaultWeight',
775+
'purchasables.length as defaultLength',
776+
'purchasables.width as defaultWidth',
777+
'purchasables.height as defaultHeight',
778778
'sitestores.storeId',
779779
]);
780780

781781
// Join in sites stores to get product's store for current request
782782
$this->query->leftJoin(['sitestores' => Table::SITESTORES], '[[elements_sites.siteId]] = [[sitestores.siteId]]');
783+
$this->query->leftJoin(['purchasables' => Table::PURCHASABLES], '[[purchasables.id]] = [[commerce_products.defaultVariantId]]');
784+
$this->query->leftJoin(['purchasablesstores' => Table::PURCHASABLES_STORES], '[[purchasablesstores.purchasableId]] = [[commerce_products.defaultVariantId]] and [[sitestores.storeId]] = [[purchasablesstores.storeId]]');
783785

784786
$this->subQuery->addSelect(['catalogprices.price']);
785787

0 commit comments

Comments
 (0)