Skip to content

Commit dbaf68b

Browse files
committed
MC-5373: Product couldn't be pulled to CMS Page when it was assigned to a specific website
Remove temporal coupling by immediately setting store_id first on collection if it is available
1 parent 2ea72fb commit dbaf68b

File tree

3 files changed

+9
-121
lines changed

3 files changed

+9
-121
lines changed

app/code/Magento/PageBuilder/Plugin/CatalogWidget/Block/Product/ProductsListPlugin.php

Lines changed: 0 additions & 103 deletions
This file was deleted.

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,25 @@
77

88
namespace Magento\PageBuilder\Ui\DataProvider\Product;
99

10+
use Magento\Store\Model\Store;
11+
1012
/**
1113
* PageBuilder ProductCollection class for allowing store-agnostic collections
1214
*/
1315
class ProductCollection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
1416
{
15-
/**
16-
* Set store id even if it's equal to \Magento\Store\Model\Store::DEFAULT_STORE_ID to prevent inadvertent resetting
17-
* {@inheritdoc}
18-
*/
19-
public function addStoreFilter($store = null)
20-
{
21-
if ($store !== null && (int) $store === 0) {
22-
$this->setStoreId($store);
23-
}
24-
25-
return parent::addStoreFilter($store);
26-
}
27-
2817
/**
2918
* Prevent usage of catalog index for querying visibility, as it relies on a specific store id.
30-
* Visibility condition is to be added later in plugin.
31-
* @see \Magento\PageBuilder\Plugin\CatalogWidget\Block\Product\ProductsListPlugin::aroundGetData
32-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3319
* {@inheritdoc}
3420
*/
3521
public function setVisibility($visibility)
3622
{
23+
if ($this->getStoreId() === Store::DEFAULT_STORE_ID) {
24+
$this->addAttributeToFilter('visibility', $visibility);
25+
} else {
26+
parent::setVisibility($visibility);
27+
}
28+
3729
return $this;
3830
}
3931

@@ -43,7 +35,7 @@ public function setVisibility($visibility)
4335
*/
4436
protected function _productLimitationJoinPrice()
4537
{
46-
$this->_productLimitationFilters->setUsePriceIndex(false);
38+
$this->_productLimitationFilters->setUsePriceIndex($this->getStoreId() !== Store::DEFAULT_STORE_ID);
4739
return $this->_productLimitationPrice(false);
4840
}
4941
}

app/code/Magento/PageBuilder/etc/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@
556556
</arguments>
557557
</virtualType>
558558
<type name="Magento\CatalogWidget\Block\Product\ProductsList">
559-
<plugin name="website_agnostic" type="Magento\PageBuilder\Plugin\CatalogWidget\Block\Product\ProductsListPlugin"/>
560559
<arguments>
561560
<argument name="productCollectionFactory" xsi:type="object">pageBuilderProductCollectionFactory</argument>
562561
</arguments>

0 commit comments

Comments
 (0)