objSkuSourceCodes = $objSkuSourceCodes; } protected function getEntityCode() { return 'stock_sources'; } private function getAffectedSourcesBySku($arrData) { $arrSkus = []; foreach ($arrData as $arrStockSource) { if (isset($arrStockSource['sku'])) { $arrSkus[$arrStockSource['sku']][] = $arrStockSource['source_code']; } } return $arrSkus; } public function processImport($arrData, $options = array()) { $arrSkuSources = $this->getAffectedSourcesBySku($arrData); $arrSourceCodes = $this->objSkuSourceCodes->execute(array_keys($arrSkuSources)); $arrDelete = []; foreach ($arrSkuSources as $strSku => $arrSources) { $arrSources[] = 'default'; $arrSources = array_diff($arrSourceCodes, $arrSources); foreach ($arrSources as $strSource) { $arrDelete[] = ['sku' =>(string) $strSku, 'source_code' => $strSource, 'quantity' => 0, 'status' => 0]; } } if ($arrDelete) { $import = \Magento\Framework\App\ObjectManager::getInstance()->create('saws\sawsconnector\Model\Importer'); $import->setEntityCode($this->getEntityCode()); $import->setBehavior('delete'); $import->processImport($arrDelete); } $import = \Magento\Framework\App\ObjectManager::getInstance()->create('saws\sawsconnector\Model\Importer'); $import->setEntityCode($this->getEntityCode()); $import->setBehavior('replace'); $import->processImport($arrData); } }