Skip to content

Commit

Permalink
#3807 default price showing incorrectly for products in CP
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Dec 10, 2024
1 parent 1d92fc9 commit 206b1f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 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 order errors weren't showing on the Edit Order page.

## 5.2.8 - 2024-12-04
Expand Down
1 change: 1 addition & 0 deletions src/elements/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ public function afterSave(bool $isNew): void
parent::afterSave($isNew);

if (!$this->propagating && $this->isDefault && $ownerId && $this->duplicateOf === null) {
// @TODO - this data is now joined in on the product query so can be removed at the next breaking change
$defaultData = [
'defaultVariantId' => $this->id,
'defaultSku' => $this->getSkuAsText(),
Expand Down
14 changes: 8 additions & 6 deletions src/elements/db/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,18 +768,20 @@ protected function beforePrepare(): bool
'commerce_products.postDate',
'commerce_products.expiryDate',
'subquery.price as defaultPrice',
'commerce_products.defaultPrice as defaultBasePrice',
'purchasablesstores.basePrice as defaultBasePrice',
'commerce_products.defaultVariantId',
'commerce_products.defaultSku',
'commerce_products.defaultWeight',
'commerce_products.defaultLength',
'commerce_products.defaultWidth',
'commerce_products.defaultHeight',
'purchasables.sku as defaultSku',
'purchasables.weight as defaultWeight',
'purchasables.length as defaultLength',
'purchasables.width as defaultWidth',
'purchasables.height as defaultHeight',
'sitestores.storeId',
]);

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

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

Expand Down

0 comments on commit 206b1f8

Please sign in to comment.