Skip to content

Commit 420a15e

Browse files
committed
MC-42243: Sorting by price is incorrect if price for shared catalog is 0
1 parent 5f05166 commit 420a15e

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/Query/BaseFinalPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private function getTotalTierPriceExpression(\Zend_Db_Expr $priceExpression)
305305
private function getTierPriceExpressionForTable($tableAlias, \Zend_Db_Expr $priceExpression): \Zend_Db_Expr
306306
{
307307
return $this->getConnection()->getCheckSql(
308-
sprintf('%s.value = 0', $tableAlias),
308+
sprintf('%s.percentage_value IS NOT NULL', $tableAlias),
309309
sprintf(
310310
'ROUND(%s * (1 - ROUND(%s.percentage_value * cwd.rate, 4) / 100), 4)',
311311
$priceExpression,

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductPriceTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,20 @@ public function testGetMinPriceForComposite(): void
133133
$product = $collection->getFirstItem();
134134
$this->assertEquals(20, $product->getData('min_price'));
135135
}
136+
137+
/**
138+
* @magentoDbIsolation disabled
139+
* @magentoDataFixture Magento/Catalog/_files/simple_product_with_tier_price_equal_zero.php
140+
*/
141+
public function testGetMinPriceWhenTierPriceEqualZero()
142+
{
143+
$product = $this->productRepository->get('simple-2');
144+
$collection = Bootstrap::getObjectManager()->create(Collection::class);
145+
$collection->addIdFilter($product->getId());
146+
$collection->addPriceData(0);
147+
$collection->load();
148+
$product = $collection->getFirstItem();
149+
$this->assertEquals(0, $product->getData('tier_price'));
150+
$this->assertEquals(0, $product->getData('min_price'));
151+
}
136152
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductTierPriceExtension;
9+
use Magento\Catalog\Api\Data\ProductTierPriceInterface;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Store\Api\WebsiteRepositoryInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
14+
15+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_without_custom_options.php');
16+
17+
$objectManager = Bootstrap::getObjectManager();
18+
19+
$adminWebsite = $objectManager->get(WebsiteRepositoryInterface::class)
20+
->get('admin');
21+
$tierPriceExtensionAttributes = $objectManager->create(ProductTierPriceExtension::class)
22+
->setWebsiteId($adminWebsite->getId());
23+
$tierPrices = [];
24+
$tierPrice = $objectManager->create(ProductTierPriceInterface::class)
25+
->setCustomerGroupId(0)
26+
->setQty(1)
27+
->setValue(0)
28+
->setExtensionAttributes($tierPriceExtensionAttributes);
29+
$tierPrices[] = $tierPrice;
30+
31+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
32+
$product = $productRepository->get('simple-2', false, null, true);
33+
$product->setTierPrices($tierPrices);
34+
$productRepository->save($product);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
9+
10+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_without_custom_options_rollback.php');

0 commit comments

Comments
 (0)