/** * Count existing prices * * @param array $prices * @param string $table * @return $this */ protected function processCountExistingPrices($prices, $table) { $tableName = $this->_resourceFactory->create()->getTable($table); $productEntityLinkField = $this->getProductEntityLinkField(); $existingPrices = $this->_connection->fetchAssoc($this->_connection->select()->from($tableName, ['value_id', $productEntityLinkField, 'all_groups', 'customer_group_id'])); $oldSkus = $this->retrieveOldSkus(); foreach ($existingPrices as $existingPrice) { foreach ($oldSkus as $sku => $productId) { if ($existingPrice[$productEntityLinkField] == $productId && isset($prices[$sku])) { $this->incrementCounterUpdated($prices[$sku], $existingPrice); } } } return $this; }
/** * Save product prices. * * @param array $priceData * @param string $table * @return $this */ protected function saveProductPrices(array $priceData, $table) { if ($priceData) { $tableName = $this->_resourceFactory->create()->getTable($table); $priceIn = []; $entityIds = []; foreach ($priceData as $sku => $priceRows) { if (isset($this->_oldSkus[$sku])) { $productId = $this->_oldSkus[$sku]; foreach ($priceRows as $row) { $row['entity_id'] = $productId; $priceIn[] = $row; $entityIds[] = $productId; } } } if ($priceIn) { $this->_connection->insertOnDuplicate($tableName, $priceIn, ['value']); } } return $this; }
/** * Retrieve attribute by code * * @param string $attrCode * @return mixed */ public function retrieveAttributeByCode($attrCode) { if (!$this->_resource) { $this->_resource = $this->_resourceFactory->create(); } if (!isset($this->_attributeCache[$attrCode])) { $this->_attributeCache[$attrCode] = $this->_resource->getAttribute($attrCode); } return $this->_attributeCache[$attrCode]; }
/** * @return Proxy\Product\ResourceModel */ protected function getResource() { if (!$this->_resource) { $this->_resource = $this->_resourceFactory->create(); } return $this->_resource; }