Skip to content

Commit 70d5021

Browse files
committed
MC-42243: Sorting by price is incorrect if price for shared catalog is 0
1 parent 929f264 commit 70d5021

File tree

1 file changed

+41
-8
lines changed
  • dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product

1 file changed

+41
-8
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,26 +206,23 @@ public function testGetProductsWithTierPrice()
206206
/**
207207
* Test addAttributeToSort() with attribute 'is_saleable' works properly on frontend.
208208
*
209-
* @dataProvider addAttributeToSortDataProvider
209+
* @dataProvider addIsSaleableAttributeToSortDataProvider
210210
* @magentoDataFixture Magento/Catalog/_files/multiple_products_with_non_saleable_product.php
211211
* @magentoConfigFixture current_store cataloginventory/options/show_out_of_stock 1
212212
* @magentoAppIsolation enabled
213213
* @magentoAppArea frontend
214214
*/
215-
public function testAddAttributeToSort(string $productSku, string $order)
215+
public function testAddIsSaleableAttributeToSort(string $productSku, string $order)
216216
{
217-
/** @var Collection $productCollection */
218217
$this->collection->addAttributeToSort('is_saleable', $order);
219-
self::assertEquals(2, $this->collection->count());
220-
self::assertSame($productSku, $this->collection->getFirstItem()->getSku());
218+
$this->assertEquals(2, $this->collection->count());
219+
$this->assertEquals($productSku, $this->collection->getFirstItem()->getSku());
221220
}
222221

223222
/**
224-
* Provide test data for testAddAttributeToSort().
225-
*
226223
* @return array
227224
*/
228-
public function addAttributeToSortDataProvider()
225+
public function addIsSaleableAttributeToSortDataProvider(): array
229226
{
230227
return [
231228
[
@@ -239,6 +236,42 @@ public function addAttributeToSortDataProvider()
239236
];
240237
}
241238

239+
/**
240+
* Test addAttributeToSort() with attribute 'price' works properly on frontend.
241+
*
242+
* @dataProvider addPriceAttributeToSortDataProvider
243+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
244+
* @magentoDataFixture Magento/Catalog/_files/simple_product_with_tier_price_equal_zero.php
245+
* @magentoAppIsolation enabled
246+
* @magentoDbIsolation disabled
247+
* @magentoAppArea frontend
248+
*/
249+
public function testAddPriceAttributeToSort(string $productSku, string $order)
250+
{
251+
$this->processor->getIndexer()->reindexAll();
252+
$this->collection->setStoreId(1);
253+
$this->collection->addAttributeToSort('price', $order);
254+
$this->assertEquals(2, $this->collection->count());
255+
$this->assertEquals($productSku, $this->collection->getFirstItem()->getSku());
256+
}
257+
258+
/**
259+
* @return array
260+
*/
261+
public function addPriceAttributeToSortDataProvider(): array
262+
{
263+
return [
264+
[
265+
'product_sku' => 'simple',
266+
'order' => Collection::SORT_ORDER_DESC,
267+
],
268+
[
269+
'product_sku' => 'simple-2',
270+
'order' => Collection::SORT_ORDER_ASC,
271+
]
272+
];
273+
}
274+
242275
/**
243276
* Checks a case if table for join specified as an array.
244277
*

0 commit comments

Comments
 (0)