7
7
8
8
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
9
9
use Magento \Catalog \Api \Data \ProductInterface ;
10
+ use Magento \Catalog \Api \Data \ProductInterfaceFactory ;
10
11
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
12
use Magento \Catalog \Model \Config ;
12
13
use Magento \Framework \App \ObjectManager ;
@@ -163,6 +164,11 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
163
164
*/
164
165
private $ customerSession ;
165
166
167
+ /**
168
+ * @var ProductInterfaceFactory
169
+ */
170
+ private $ productFactory ;
171
+
166
172
/**
167
173
* @codingStandardsIgnoreStart/End
168
174
*
@@ -184,6 +190,7 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
184
190
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
185
191
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
186
192
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
193
+ * @param ProductInterfaceFactory $productFactory
187
194
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
188
195
*/
189
196
public function __construct (
@@ -206,7 +213,8 @@ public function __construct(
206
213
\Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface $ extensionAttributesJoinProcessor ,
207
214
\Magento \Framework \Cache \FrontendInterface $ cache = null ,
208
215
\Magento \Customer \Model \Session $ customerSession = null ,
209
- \Magento \Framework \Serialize \Serializer \Json $ serializer = null
216
+ \Magento \Framework \Serialize \Serializer \Json $ serializer = null ,
217
+ ProductInterfaceFactory $ productFactory = null
210
218
) {
211
219
$ this ->typeConfigurableFactory = $ typeConfigurableFactory ;
212
220
$ this ->_eavAttributeFactory = $ eavAttributeFactory ;
@@ -218,6 +226,8 @@ public function __construct(
218
226
$ this ->extensionAttributesJoinProcessor = $ extensionAttributesJoinProcessor ;
219
227
$ this ->cache = $ cache ;
220
228
$ this ->customerSession = $ customerSession ;
229
+ $ this ->productFactory = $ productFactory ?: ObjectManager::getInstance ()
230
+ ->get (ProductInterfaceFactory::class);
221
231
parent ::__construct (
222
232
$ catalogProductOption ,
223
233
$ eavConfig ,
@@ -529,15 +539,16 @@ public function getUsedProducts($product, $requiredAttributeIds = null)
529
539
]
530
540
)
531
541
);
532
- $ collection = $ this ->getUsedProductCollection ($ product );
533
542
$ data = $ this ->serializer ->unserialize ($ this ->getCache ()->load ($ key ));
534
543
if (!empty ($ data )) {
535
544
$ usedProducts = [];
536
545
foreach ($ data as $ item ) {
537
- $ productItem = $ collection ->getNewEmptyItem ()->setData ($ item );
546
+ $ productItem = $ this ->productFactory ->create ();
547
+ $ productItem ->setData ($ item );
538
548
$ usedProducts [] = $ productItem ;
539
549
}
540
550
} else {
551
+ $ collection = $ this ->getUsedProductCollection ($ product );
541
552
$ collection
542
553
->setFlag ('has_stock_status_filter ' , true )
543
554
->addAttributeToSelect ($ this ->getCatalogConfig ()->getProductAttributes ())
0 commit comments