Skip to content

Commit

Permalink
Merge branch '5.x' into 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Nov 14, 2024
2 parents 842b6d4 + c31d5a3 commit ae351db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

## Unreleased

- Fixed a bug where purchasables were showing incorrectly on the Edit Order screen. ([#3756](https://github.com/craftcms/commerce/issues/3756))
- Fixed a SQL error that could occur when creating a variant. ([#3763](https://github.com/craftcms/commerce/issues/))

## 5.2.3 - 2024-11-13

- Fixed a performance degradation bug with variant queries. ([#3758](https://github.com/craftcms/commerce/issues/3758))
- Fixed a bug where it was possible to select purchasables that didn’t belong to an order’s site, from Edit Order pages. ([#3756](https://github.com/craftcms/commerce/issues/3756))

## 5.2.2.1 - 2024-11-08

Expand Down
6 changes: 5 additions & 1 deletion src/base/Purchasable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Craft;
use craft\base\Element;
use craft\base\NestedElementInterface;
use craft\commerce\db\Table;
use craft\commerce\elements\Order;
use craft\commerce\errors\StoreNotFoundException;
use craft\commerce\helpers\Currency;
Expand All @@ -28,6 +29,7 @@
use craft\commerce\records\Purchasable as PurchasableRecord;
use craft\commerce\records\PurchasableStore;
use craft\db\ActiveQuery;
use craft\db\Table as CraftTable;
use craft\errors\DeprecationException;
use craft\errors\SiteNotFoundException;
use craft\helpers\ArrayHelper;
Expand Down Expand Up @@ -819,7 +821,9 @@ protected function defineRules(): array
'targetClass' => PurchasableRecord::class,
'caseInsensitive' => true,
'filter' => function(ActiveQuery $query) {
$query->leftJoin(\craft\db\Table::ELEMENTS . ' elements', '[[elements.id]] = [[commerce_purchasables.id]]');
$targetRecordClassTableName = $query->modelClass::tableName();
$elementsTable = CraftTable::ELEMENTS;
$query->leftJoin(['elements' => $elementsTable], "[[elements.id]] = {$targetRecordClassTableName}.id");
$query->andWhere(['elements.revisionId' => null, 'elements.draftId' => null]);
},
'on' => self::SCENARIO_LIVE,
Expand Down
11 changes: 11 additions & 0 deletions src/elements/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ public function attributes(): array
*/
public function getFieldLayout(): ?FieldLayout
{
$fieldLayout = parent::getFieldLayout();

if ($fieldLayout) {
// Variant field layouts are stored on the product type so retrieving the field layout by ID does not set the provider
$productType = collect(Plugin::getInstance()->getProductTypes()->getAllProductTypes())->firstWhere('variantFieldLayoutId', $fieldLayout->id);
if ($productType) {
$fieldLayout->provider = $productType;
return $fieldLayout;
}
}

try {
if ($this->getOwner() === null) {
return parent::getFieldLayout();
Expand Down

0 comments on commit ae351db

Please sign in to comment.