Skip to content

Commit 3ca0c93

Browse files
committed
Merge branch '5.x' of github.com:craftcms/commerce into 5.x
2 parents 11a4b2a + f9e8f8c commit 3ca0c93

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

CHANGELOG.md

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

3+
## Unreleased
4+
5+
- Fixed a bug where newly created variants weren’t visible on Edit product screens.
6+
- Fixed a SQL error that could occur when viewing product indexes.
7+
38
## 5.5.0.1 - 2025-11-24
49

510
- Fixed an error that could occur when querying for products via GraphQL. ([#4122](https://github.com/craftcms/commerce/issues/4122))

src/elements/Variant.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,19 @@ public function updateSku(Product $product): void
715715
*/
716716
protected function cacheTags(): array
717717
{
718-
return [
719-
"product:$this->primaryOwnerId",
720-
];
718+
$tags = [];
719+
720+
if ($primaryOwnerId = $this->getPrimaryOwnerId()) {
721+
$tags[] = "element::{$primaryOwnerId}";
722+
$tags[] = "product:{$primaryOwnerId}";
723+
}
724+
725+
$ownerId = $this->getOwnerId();
726+
if ($ownerId && $ownerId !== $primaryOwnerId) {
727+
$tags[] = "element::{$ownerId}";
728+
}
729+
730+
return $tags;
721731
}
722732

723733
/**
@@ -1181,7 +1191,7 @@ public function beforeSave(bool $isNew): bool
11811191
// Validate shipping category ID is available for this product type
11821192
$availableShippingCategories = $this->availableShippingCategories();
11831193
$availableShippingCategoryIds = ArrayHelper::getColumn($availableShippingCategories, 'id');
1184-
1194+
11851195
// If the current shipping category ID is not in the available categories, set it to the default one
11861196
$currentShippingCategoryId = $this->getShippingCategoryId();
11871197
if (!in_array($currentShippingCategoryId, $availableShippingCategoryIds)) {

src/elements/db/VariantQuery.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use craft\db\Query;
2121
use craft\db\QueryAbortedException;
2222
use craft\db\Table as CraftTable;
23+
use craft\elements\db\NestedElementQueryTrait;
2324
use craft\helpers\ArrayHelper;
2425
use craft\helpers\Db;
2526
use craft\helpers\StringHelper;
@@ -56,6 +57,9 @@
5657
*/
5758
class VariantQuery extends PurchasableQuery
5859
{
60+
use NestedElementQueryTrait {
61+
cacheTags as nestedTraitCacheTags;
62+
}
5963
/**
6064
* @inheritdoc
6165
*/
@@ -484,7 +488,7 @@ protected function beforePrepare(): bool
484488
// Forcing the use of the `sortOrder` index if no custom `orderBy` is set
485489
if ($sortOrderIndex !== null && empty($this->orderBy)) {
486490
$elementOwnersTable = Craft::$app->getDb()->schema->getRawTableName(\craft\db\Table::ELEMENTS_OWNERS);
487-
$this->subQuery->innerJoin([new Expression('[['.$elementOwnersTable.']] AS elements_owners USE INDEX (' . $sortOrderIndex . ')')], $ownersCondition);
491+
$this->subQuery->innerJoin([new Expression('[[' . $elementOwnersTable . ']] AS elements_owners USE INDEX (' . $sortOrderIndex . ')')], $ownersCondition);
488492
} else {
489493
$this->subQuery->innerJoin(['elements_owners' => CraftTable::ELEMENTS_OWNERS], $ownersCondition);
490494
}
@@ -874,6 +878,8 @@ protected function cacheTags(): array
874878
}
875879
}
876880

881+
array_push($tags, ...$this->nestedTraitCacheTags());
882+
877883
return $tags;
878884
}
879885
}

0 commit comments

Comments
 (0)