/** * Update and insert data in entity table. * * @param array $entityRowsIn Row for insert * @param array $entityRowsUp Row for update * @return $this */ protected function _saveProductEntity(array $entityRowsIn, array $entityRowsUp) { static $entityTable = null; $this->countItemsCreated += count($entityRowsIn); $this->countItemsUpdated += count($entityRowsUp); if (!$entityTable) { $entityTable = $this->_resourceFactory->create()->getEntityTable(); } if ($entityRowsUp) { $this->_connection->insertOnDuplicate($entityTable, $entityRowsUp, ['updated_at']); } if ($entityRowsIn) { $this->_connection->insertMultiple($entityTable, $entityRowsIn); $newProducts = $this->_connection->fetchPairs($this->_connection->select()->from($entityTable, ['sku', 'entity_id'])->where('sku IN (?)', array_keys($entityRowsIn))); foreach ($newProducts as $sku => $newId) { // fill up entity_id for new products $this->skuProcessor->setNewSkuData($sku, 'entity_id', $newId); } } return $this; }
/** * Update and insert data in entity table. * * @param array $entityRowsIn Row for insert * @param array $entityRowsUp Row for update * @return $this */ public function saveProductEntity(array $entityRowsIn, array $entityRowsUp) { static $entityTable = null; $this->countItemsCreated += count($entityRowsIn); $this->countItemsUpdated += count($entityRowsUp); if (!$entityTable) { $entityTable = $this->_resourceFactory->create()->getEntityTable(); } if ($entityRowsUp) { $this->_connection->insertOnDuplicate($entityTable, $entityRowsUp, ['updated_at']); } if ($entityRowsIn) { $this->_connection->insertMultiple($entityTable, $entityRowsIn); $select = $this->_connection->select()->from($entityTable, $this->getNewSkuFieldsForSelect())->where('sku IN (?)', array_keys($entityRowsIn)); $newProducts = $this->_connection->fetchAll($select); foreach ($newProducts as $data) { $sku = $data['sku']; unset($data['sku']); foreach ($data as $key => $value) { $this->skuProcessor->setNewSkuData($sku, $key, $value); } } } return $this; }