public function testGetMediaGalleryAttributeIdIfNotSetYet() { // reset possible existing id $this->setPropertyValue($this->importProduct, '_mediaGalleryAttributeId', null); $expectedId = '100'; $attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->setMethods(['getId'])->getMockForAbstractClass(); $attribute->expects($this->once())->method('getId')->willReturn($expectedId); $resource = $this->getMockBuilder('\\Magento\\CatalogImportExport\\Model\\Import\\Proxy\\Product\\Resource')->disableOriginalConstructor()->setMethods(['getAttribute'])->getMock(); $resource->expects($this->once())->method('getAttribute')->willReturn($attribute); $this->_resourceFactory->expects($this->once())->method('create')->willReturn($resource); $result = $this->importProduct->getMediaGalleryAttributeId(); $this->assertEquals($expectedId, $result); }
/** * 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 = []; foreach ($priceData as $sku => $priceRows) { $productId = $this->_oldSkus[$sku]; foreach ($priceRows as $row) { $row['entity_id'] = $productId; $priceIn[] = $row; } } if ($priceIn) { $this->_connection->insertOnDuplicate($tableName, $priceIn, ['value']); } } return $this; }
/** * Save product websites. * * @param array $websiteData * @return $this */ protected function _saveProductWebsites(array $websiteData) { static $tableName = null; if (!$tableName) { $tableName = $this->_resourceFactory->create()->getProductWebsiteTable(); } if ($websiteData) { $websitesData = array(); $delProductId = array(); foreach ($websiteData as $delSku => $websites) { $productId = $this->_newSku[$delSku]['entity_id']; $delProductId[] = $productId; foreach (array_keys($websites) as $websiteId) { $websitesData[] = array('product_id' => $productId, 'website_id' => $websiteId); } } if (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND != $this->getBehavior()) { $this->_connection->delete($tableName, $this->_connection->quoteInto('product_id IN (?)', $delProductId)); } if ($websitesData) { $this->_connection->insertOnDuplicate($tableName, $websitesData); } } return $this; }