Skip to content

Commit edecfad

Browse files
committed
Merge remote-tracking branch 'origin/develop' into MC-32651
2 parents 2ef8843 + c918fcb commit edecfad

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed

app/code/Magento/PageBuilder/Ui/DataProvider/Product/ProductCollection.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ public function setVisibility($visibility)
2929

3030
return $this;
3131
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function _productLimitationJoinPrice()
37+
{
38+
$this->_productLimitationFilters->setUsePriceIndex($this->getStoreId() !== Store::DEFAULT_STORE_ID);
39+
return $this->_productLimitationPrice(false);
40+
}
3241
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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+
namespace Magento\PageBuilder\CatalogWidget\Block\Product;
9+
10+
use Magento\CatalogWidget\Block\Product\ProductsList;
11+
use Magento\Store\Model\Store;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Test catalog products list widget block with page builder
17+
*/
18+
class ProductListTest extends TestCase
19+
{
20+
/**
21+
* @var ProductsList
22+
*/
23+
private $block;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
protected function setUp(): void
29+
{
30+
parent::setUp();
31+
$objectManager = Bootstrap::getObjectManager();
32+
$this->block = $objectManager->create(ProductsList::class);
33+
}
34+
35+
/**
36+
* Test that sorting by price works correctly
37+
*
38+
* @magentoDbIsolation disabled
39+
* @magentoConfigFixture default_store catalog/price/scope 1
40+
* @magentoDataFixture Magento/Catalog/_files/category_with_different_price_products.php
41+
* @param string $order
42+
* @param array $skus
43+
* @dataProvider priceSortDataProvider
44+
*/
45+
public function testPriceSort(string $order, array $skus)
46+
{
47+
$encodedConditions = '^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,
48+
`aggregator`:`all`,`value`:`1`,`new_child`:``^],
49+
`1--1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Product`,
50+
`attribute`:`sku`,`operator`:`()`,`value`:`simple1000,simple1001`^]^]';
51+
52+
$this->block->setData('sort_order', $order);
53+
$this->block->setData('conditions_encoded', $encodedConditions);
54+
$this->block->setStoreId(Store::DEFAULT_STORE_ID);
55+
$productCollection = $this->block->createCollection();
56+
$productCollection->load();
57+
$this->assertEquals($skus, $productCollection->getColumnValues('sku'));
58+
}
59+
60+
/**
61+
* Test that filtering by price works correctly
62+
*
63+
* @magentoDbIsolation disabled
64+
* @magentoConfigFixture default_store catalog/price/scope 1
65+
* @magentoDataFixture Magento/Catalog/_files/category_with_different_price_products.php
66+
* @param string $operator
67+
* @param int $value
68+
* @param array $matches
69+
* @dataProvider priceFilterDataProvider
70+
*/
71+
public function testPriceFilter(string $operator, int $value, array $matches)
72+
{
73+
$encodedConditions = '^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,
74+
`aggregator`:`all`,`value`:`1`,`new_child`:``^],
75+
`1--1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Product`,
76+
`attribute`:`sku`,`operator`:`()`,`value`:`simple1000,simple1001`^],
77+
`1--2`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Product`,
78+
`attribute`:`price`,`operator`:`' . $operator . '`,`value`:`' . $value . '`^]^]';
79+
80+
$this->block->setData('conditions_encoded', $encodedConditions);
81+
$this->block->setStoreId(Store::DEFAULT_STORE_ID);
82+
$productCollection = $this->block->createCollection();
83+
$productCollection->load();
84+
$this->assertEqualsCanonicalizing($matches, $productCollection->getColumnValues('sku'));
85+
}
86+
87+
/**
88+
* Test product list widget with product that has different price on each website
89+
*
90+
* @magentoDbIsolation disabled
91+
* @magentoConfigFixture default_store catalog/price/scope 1
92+
* @magentoDataFixture Magento/Catalog/_files/product_with_price_on_second_website.php
93+
*/
94+
public function testProductWithDifferentPriceOnEachWebsite(): void
95+
{
96+
$sku = 'second-website-price-product';
97+
$encodedConditions = '^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,
98+
`aggregator`:`all`,`value`:`1`,`new_child`:``^],
99+
`1--1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Product`,
100+
`attribute`:`sku`,`operator`:`==`,`value`:`' . $sku . '`^]^]';
101+
102+
$this->block->setData('conditions_encoded', $encodedConditions);
103+
$this->block->setStoreId(Store::DEFAULT_STORE_ID);
104+
$productCollection = $this->block->createCollection();
105+
$productCollection->load();
106+
$this->assertEquals([$sku], $productCollection->getColumnValues('sku'));
107+
}
108+
109+
/**
110+
* @return array
111+
*/
112+
public function priceFilterDataProvider(): array
113+
{
114+
return [
115+
[
116+
'>',
117+
10,
118+
[
119+
'simple1001',
120+
]
121+
],
122+
[
123+
'>=',
124+
10,
125+
[
126+
'simple1000',
127+
'simple1001',
128+
]
129+
],
130+
[
131+
'<',
132+
10,
133+
[]
134+
],
135+
[
136+
'<',
137+
20,
138+
[
139+
'simple1000',
140+
]
141+
],
142+
];
143+
}
144+
145+
/**
146+
* @return array
147+
*/
148+
public function priceSortDataProvider(): array
149+
{
150+
return [
151+
[
152+
'price_low_to_high',
153+
[
154+
'simple1000',
155+
'simple1001',
156+
]
157+
],
158+
[
159+
'price_high_to_low',
160+
[
161+
'simple1001',
162+
'simple1000',
163+
]
164+
],
165+
];
166+
}
167+
}

0 commit comments

Comments
 (0)