0

I have a custom table with columns :

enter image description here

And My product csv file has SKUs

SKU (product_id from backend)

OUTIPCAM11 (98)

OUTIPCAM12 (99)

OUTIPCAM13 (100)

OUTIPCAM14 (101)

OUTIPCAM15 (102)

OUTIPCAM16 (103)

OUTIPCAM17 (104)

OUTIPCAM18 (105)

Now in Magento\CatalogImportExport\Model\Import\Product.php

  protected function _saveProducts()
{
    //$this->_init('Vendor\Module\Model\ResourceModel\Queue');
    $priceIsGlobal = $this->_catalogData->isPriceGlobal();
    $productLimit = null;
    $productsQty = null;

    while ($bunch = $this->_dataSourceModel->getNextBunch()) {
        $entityRowsIn = [];
        $entityRowsUp = [];
        $attributes = [];
        $this->websitesCache = [];
        $this->categoriesCache = [];
        $tierPrices = [];
        $mediaGallery = [];
        $uploadedImages = [];
        $previousType = null;
        $prevAttributeSet = null;
        $existingImages = $this->getExistingImages($bunch);

        //custom code

        //$tableName = $this->_resourceFactory->create()->getTable('tgs_queue');
            $tagmodel =  $this->_objectManager->create('Vendor\Module\Model\Queue');                


        foreach ($bunch as $rowNum => $rowData) {
            if (!$this->validateRow($rowData, $rowNum)) {
                continue;
            }
            if ($this->getErrorAggregator()->hasToBeTerminated()) {
                $this->getErrorAggregator()->addRowToSkip($rowNum);
                continue;
            }
            $rowScope = $this->getRowScope($rowData);

            $rowSku = $rowData[self::COL_SKU];

            if (null === $rowSku) {
                $this->getErrorAggregator()->addRowToSkip($rowNum);
                continue;
            } elseif (self::SCOPE_STORE == $rowScope) {
                // set necessary data from SCOPE_DEFAULT row
                $rowData[self::COL_TYPE] = $this->skuProcessor->getNewSku($rowSku)['type_id'];
                $rowData['attribute_set_id'] = $this->skuProcessor->getNewSku($rowSku)['attr_set_id'];
                $rowData[self::COL_ATTR_SET] = $this->skuProcessor->getNewSku($rowSku)['attr_set_code'];


            }

            $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/_saveProducts.log');
            $logger = new \Zend\Log\Logger();
            $logger->addWriter($writer);
            $logger->info("Product_ids: [ ".$this->skuProcessor->getNewSku($rowSku)['entity_id']." ] ");
            //custom line
            $tagProductId = $this->skuProcessor->getNewSku($rowSku)['entity_id'];
            /* $getId =  $tagmodel->getCollection()
                                ->addFieldToFilter('entity_id',['in' => $tagProductId]); */

             $getId=$tagmodel->load($tagProductId);
                    //$logger->info("Tag Collection : [ ".$tagmodel->load($tagProductId)." ] ");

            if(!$getId->getId()) {                  
                $tagmodel->setEntityId($tagProductId); 
                $tagmodel->save();
            }

         ....Rest is the core code....

Now im updating a single product sku say of the product id 98... When i import the csv, All the SKU product_ids are getting saved(see the snap in entity_id column) even though i dint make any change to other products.

I want the id to be saved only for that product which i updated in csv.

Whats wrong in the custom code?

Sushivam
  • 2,629
  • 3
  • 36
  • 88

0 Answers0