@@ -165,12 +165,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
165
165
/**
166
166
* @var CategoryLinkManagementInterface
167
167
*/
168
- private $ categoryLinkManagement ;
169
-
170
- /**
171
- * @var AssignProductToCategories
172
- */
173
- private $ assignProductToCategories = false ;
168
+ private $ linkManagement ;
174
169
175
170
/**
176
171
* ProductRepository constructor.
@@ -227,7 +222,7 @@ public function __construct(
227
222
\Magento \Framework \Serialize \Serializer \Json $ serializer = null ,
228
223
$ cacheLimit = 1000 ,
229
224
ReadExtensions $ readExtensions = null ,
230
- CategoryLinkManagementInterface $ categoryLinkManagement = null
225
+ CategoryLinkManagementInterface $ linkManagement = null
231
226
) {
232
227
$ this ->productFactory = $ productFactory ;
233
228
$ this ->collectionFactory = $ collectionFactory ;
@@ -252,7 +247,7 @@ public function __construct(
252
247
$ this ->cacheLimit = (int )$ cacheLimit ;
253
248
$ this ->readExtensions = $ readExtensions ?: \Magento \Framework \App \ObjectManager::getInstance ()
254
249
->get (ReadExtensions::class);
255
- $ this ->categoryLinkManagement = $ categoryLinkManagement ?:\Magento \Framework \App \ObjectManager::getInstance ()
250
+ $ this ->linkManagement = $ linkManagement ?:\Magento \Framework \App \ObjectManager::getInstance ()
256
251
->get (CategoryLinkManagementInterface::class);
257
252
}
258
253
@@ -587,6 +582,7 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
587
582
*/
588
583
public function save (ProductInterface $ product , $ saveOptions = false )
589
584
{
585
+ $ assignToCategories = false ;
590
586
$ tierPrices = $ product ->getData ('tier_price ' );
591
587
592
588
try {
@@ -604,7 +600,7 @@ public function save(ProductInterface $product, $saveOptions = false)
604
600
$ extensionAttributes = $ product ->getExtensionAttributes ();
605
601
if (empty ($ extensionAttributes ->__toArray ())) {
606
602
$ product ->setExtensionAttributes ($ existingProduct ->getExtensionAttributes ());
607
- $ this -> assignProductToCategories = true ;
603
+ $ assignToCategories = true ;
608
604
}
609
605
} catch (NoSuchEntityException $ e ) {
610
606
$ existingProduct = null ;
@@ -642,8 +638,8 @@ public function save(ProductInterface $product, $saveOptions = false)
642
638
}
643
639
644
640
$ this ->saveProduct ($ product );
645
- if ($ this -> assignProductToCategories === true ) {
646
- $ this ->categoryLinkManagement ->assignProductToCategories (
641
+ if ($ assignToCategories === true ) {
642
+ $ this ->linkManagement ->assignProductToCategories (
647
643
$ product ->getSku (),
648
644
$ product ->getCategoryIds ()
649
645
);
0 commit comments