Skip to content

Commit 0eb8848

Browse files
committed
MC-34444: Configurable shows simple products which are no longer assigned to the website
1 parent c03bde6 commit 0eb8848

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
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+
namespace Magento\ConfigurableProduct\Model\Plugin\Frontend;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
12+
13+
/**
14+
* Filter configurable options by current store plugin.
15+
*/
16+
class UsedProductsWebsiteFilter
17+
{
18+
/**
19+
* Filter configurable options not assigned to current website.
20+
*
21+
* @param Configurable $subject
22+
* @param ProductInterface $product
23+
* @param array|null $requiredAttributeIds
24+
* @return void
25+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
26+
*/
27+
public function beforeGetUsedProducts(
28+
Configurable $subject,
29+
ProductInterface $product,
30+
array $requiredAttributeIds = null
31+
): void {
32+
$subject->setStoreFilter($product->getStore(), $product);
33+
}
34+
}

app/code/Magento/ConfigurableProduct/etc/frontend/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
</type>
1313
<type name="Magento\ConfigurableProduct\Model\Product\Type\Configurable">
1414
<plugin name="used_products_cache" type="Magento\ConfigurableProduct\Model\Plugin\Frontend\UsedProductsCache" />
15+
<plugin name="used_products_website_filter" type="Magento\ConfigurableProduct\Model\Plugin\Frontend\UsedProductsWebsiteFilter" />
1516
</type>
1617
</config>

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type/ConfigurableTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Magento\Framework\ObjectManagerInterface;
2020
use Magento\Framework\Serialize\SerializerInterface;
2121
use Magento\Framework\View\LayoutInterface;
22+
use Magento\Store\Api\WebsiteRepositoryInterface;
23+
use Magento\Store\Model\StoreManagerInterface;
2224
use Magento\TestFramework\Helper\Bootstrap;
2325
use PHPUnit\Framework\TestCase;
2426

@@ -126,6 +128,29 @@ public function testGetAllowProducts(): void
126128
}
127129
}
128130

131+
/**
132+
* Verify configurable option not assigned to current website won't be visible.
133+
*
134+
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_two_websites.php
135+
* @magentoDbIsolation disabled
136+
* @magentoAppArea frontend
137+
*
138+
* @return void
139+
*/
140+
public function testGetAllowProductsNonDefaultWebsite(): void
141+
{
142+
// Set current website to non-default.
143+
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
144+
$storeManager->setCurrentStore('fixture_second_store');
145+
// Un-assign simple product from non-default website.
146+
$simple = $this->productRepository->get('simple_Option_1');
147+
$simple->setWebsiteIds([1]);
148+
$this->productRepository->save($simple);
149+
// Verify only one configurable option will be visible.
150+
$products = $this->block->getAllowProducts();
151+
$this->assertEquals(1, count($products));
152+
}
153+
129154
/**
130155
* @return void
131156
*/

0 commit comments

Comments
 (0)