File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed
app/code/Magento/ConfigurableProduct
dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 12
12
</type >
13
13
<type name =" Magento\ConfigurableProduct\Model\Product\Type\Configurable" >
14
14
<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" />
15
16
</type >
16
17
</config >
Original file line number Diff line number Diff line change 19
19
use Magento \Framework \ObjectManagerInterface ;
20
20
use Magento \Framework \Serialize \SerializerInterface ;
21
21
use Magento \Framework \View \LayoutInterface ;
22
+ use Magento \Store \Api \WebsiteRepositoryInterface ;
23
+ use Magento \Store \Model \StoreManagerInterface ;
22
24
use Magento \TestFramework \Helper \Bootstrap ;
23
25
use PHPUnit \Framework \TestCase ;
24
26
@@ -126,6 +128,29 @@ public function testGetAllowProducts(): void
126
128
}
127
129
}
128
130
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
+
129
154
/**
130
155
* @return void
131
156
*/
You can’t perform that action at this time.
0 commit comments