14
14
use Magento \Catalog \Model \Product \Gallery \ReadHandler as GalleryReadHandler ;
15
15
use Magento \ConfigurableProduct \Model \Product \Type \Collection \SalableProcessor ;
16
16
use Magento \Framework \App \ObjectManager ;
17
+ use Magento \Framework \App \State as AppState ;
17
18
use Magento \Framework \EntityManager \MetadataPool ;
18
19
19
20
/**
@@ -194,6 +195,11 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
194
195
*/
195
196
private $ salableProcessor ;
196
197
198
+ /**
199
+ * @var AppState
200
+ */
201
+ private $ appState ;
202
+
197
203
/**
198
204
* @codingStandardsIgnoreStart/End
199
205
*
@@ -217,6 +223,7 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
217
223
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
218
224
* @param ProductInterfaceFactory $productFactory
219
225
* @param SalableProcessor $salableProcessor
226
+ * @param AppState|null $appState
220
227
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
221
228
*/
222
229
public function __construct (
@@ -241,7 +248,8 @@ public function __construct(
241
248
\Magento \Customer \Model \Session $ customerSession = null ,
242
249
\Magento \Framework \Serialize \Serializer \Json $ serializer = null ,
243
250
ProductInterfaceFactory $ productFactory = null ,
244
- SalableProcessor $ salableProcessor = null
251
+ SalableProcessor $ salableProcessor = null ,
252
+ AppState $ appState = null
245
253
) {
246
254
$ this ->typeConfigurableFactory = $ typeConfigurableFactory ;
247
255
$ this ->_eavAttributeFactory = $ eavAttributeFactory ;
@@ -256,6 +264,7 @@ public function __construct(
256
264
$ this ->productFactory = $ productFactory ?: ObjectManager::getInstance ()
257
265
->get (ProductInterfaceFactory::class);
258
266
$ this ->salableProcessor = $ salableProcessor ?: ObjectManager::getInstance ()->get (SalableProcessor::class);
267
+ $ this ->appState = $ appState ?? ObjectManager::getInstance ()->get (AppState::class);
259
268
parent ::__construct (
260
269
$ catalogProductOption ,
261
270
$ eavConfig ,
@@ -1232,23 +1241,25 @@ public function isPossibleBuyFromList($product)
1232
1241
/**
1233
1242
* Returns array of sub-products for specified configurable product
1234
1243
*
1235
- * $requiredAttributeIds - one dimensional array, if provided
1236
1244
* Result array contains all children for specified configurable product
1237
1245
*
1238
- * @param \Magento\Catalog\Model\Product $product
1239
- * @param array $requiredAttributeIds
1246
+ * @param \Magento\Catalog\Model\Product $product
1247
+ * @param array $requiredAttributeIds
1240
1248
* @return ProductInterface[]
1241
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
1242
1249
*/
1243
1250
public function getUsedProducts ($ product , $ requiredAttributeIds = null )
1244
1251
{
1245
- if (!$ product ->hasData ($ this ->_usedProducts )) {
1246
- $ collection = $ this ->getConfiguredUsedProductCollection ($ product , false );
1247
- $ usedProducts = array_values ($ collection ->getItems ());
1248
- $ product ->setData ($ this ->_usedProducts , $ usedProducts );
1249
- }
1250
-
1251
- return $ product ->getData ($ this ->_usedProducts );
1252
+ $ metadata = $ this ->getMetadataPool ()->getMetadata (ProductInterface::class);
1253
+ $ keyParts = [
1254
+ __METHOD__ ,
1255
+ $ product ->getData ($ metadata ->getLinkField ()),
1256
+ $ product ->getStoreId (),
1257
+ $ this ->getCustomerSession ()->getCustomerGroupId (),
1258
+ $ this ->appState ->getAreaCode (),
1259
+ $ requiredAttributeIds
1260
+ ];
1261
+ $ cacheKey = $ this ->getUsedProductsCacheKey ($ keyParts );
1262
+ return $ this ->loadUsedProducts ($ product , $ cacheKey );
1252
1263
}
1253
1264
1254
1265
/**
0 commit comments