public function setUp() { parent::setUp(); $this->_store = $this->getModelMockBuilder('core/store')->disableOriginalConstructor()->setMethods(array('getId'))->getMock(); $this->_store->expects($this->any())->method('getId')->will($this->returnValue(0)); $this->_stores = array(0 => $this->_store); $this->_collection = $this->getResourceModelMock('catalog/product_collection', array('load', 'addFieldToFilter')); $this->_batchContainer = $this->getModelMock('ebayenterprise_catalog/pim_batch_container', array('addBatch')); $this->_langHelper = $this->getHelperMock('eb2ccore/languages', array('getStores')); $this->_langHelper->expects($this->any())->method('getStores')->will($this->returnValue($this->_stores)); $this->_prodHelper = $this->getHelperMock('ebayenterprise_catalog/data', array('getDefaultStoreViewId')); $this->_prodHelper->expects($this->any())->method('getDefaultStoreViewId')->will($this->returnValue(0)); }
/** * @see EbayEnterprise_Catalog_Model_Error_IConfirmations::addErrorConfirmation() */ public function addErrorConfirmation($sku) { $this->queueConfirmation[] = sprintf("%s\n%s\n%s", $this->helper->mapPattern(['sku' => $sku], self::XML_ERRCONFIRMATION_OPEN_NODE), implode("\n", $this->queueError), self::XML_ERRCONFIRMATION_CLOSE_NODE); // reset error queue $this->queueError = []; return $this; }
/** * Map an array of website ids the product should be linked to, based upon * the item's client id, catalog id and/or store id. * * @param DOMNodeList * @param Mage_Catalog_Model_Product * @return array */ public function extractWebsiteIds(DOMNodeList $nodes, Mage_Catalog_Model_Product $product) { $websiteIds = $product->getWebsiteIds(); $itemNode = $nodes->item(0); // If there's no node to get data from, just let website ids remain // what it is. if (!$itemNode) { return $websiteIds; } $clientId = $itemNode->getAttribute('gsi_client_id'); $catalogId = $itemNode->getAttribute('catalog_id'); $storeId = $itemNode->getAttribute('gsi_store_id'); $websites = $this->catalogHelper->loadWebsiteFilters(); foreach ($websites as $websiteFilter) { $websiteId = $websiteFilter['mage_website_id']; // Assume no value in feed is a wildcard. $matches = !$catalogId || $catalogId === $websiteFilter['catalog_id']; $matches = $matches && (!$clientId || $clientId === $websiteFilter['client_id']); $matches = $matches && (!$storeId || $storeId === $websiteFilter['store_id']); // Just add any matched websites to the list, ignoring that this // might end up with dupes, list will be made unique when returned. if ($matches) { $websiteIds[] = $websiteId; } } return array_unique($websiteIds); }
/** * Create feed data set from product collection. * Create XML from feed data. * Write out file. * Return path to file created. */ public function testBuildFeed() { $pathToFile = $this->_outboundPath . DS . $this->_tmpFileName; $this->_prodHelper->expects($this->once())->method('generateFileName')->will($this->returnValue($this->_tmpFileName)); $this->_pimProductCollection->expects($this->once())->method('count')->will($this->returnValue(1)); $this->_coreFeed->expects($this->any())->method('getLocalDirectory')->will($this->returnValue($this->_outboundPath)); $pim = $this->getModelMockBuilder('ebayenterprise_catalog/pim')->setMethods(array('_createFeedDataSet', '_createDomFromFeedData'))->getMock(); $pim->expects($this->any())->method('_createFeedDataSet')->will($this->returnValue($this->_pimProductCollection)); $pim->expects($this->any())->method('_createDomFromFeedData')->will($this->returnValueMap(array(array($this->_pimProductCollection, $this->_docMock)))); $this->_docMock->expects($this->once())->method('save')->with($this->identicalTo($pathToFile))->will($this->returnValue(12)); // inject mocks $this->replaceByMock('helper', 'ebayenterprise_catalog', $this->_prodHelper); EcomDev_Utils_Reflection::setRestrictedPropertyValue($pim, '_coreFeed', $this->_coreFeed); EcomDev_Utils_Reflection::setRestrictedPropertyValue($pim, '_batch', $this->_batch); $this->assertSame($pathToFile, $pim->buildFeed($this->_batch)); }
/** * Update a single product with data from the feed. Should check for the * product to already exist in the collection and when it does, update the * product in the collection. When the product doesn't exist yet, it should * create a new product, set the extracted data on it and add it to the * collection. * * @param DOMXPath $feedXPath * @param DOMNode $itemNode * @param Varien_Data_Collection $itemCollection * @param int $storeId * @param array $cfgData * @param EbayEnterprise_Catalog_Interface_Import_Items $items * @return self */ protected function _updateItem(DOMXPath $feedXPath, DOMNode $itemNode, Varien_Data_Collection $itemCollection, $storeId, array $cfgData, EbayEnterprise_Catalog_Interface_Import_Items $items) { $extractor = Mage::getSingleton('ebayenterprise_catalog/feed_extractor'); $sku = $this->_helper->normalizeSku($extractor->extractSku($feedXPath, $itemNode, $cfgData['extractor_sku_xpath']), $this->_coreHelper->getConfigModel()->catalogId); $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId(); $item = $itemCollection->getItemById($sku); if (is_null($item)) { $item = $items->createNewItem($sku); $item->setWebsiteIds(array($websiteId)); $itemCollection->addItem($item); } elseif ($cfgData['feed_type'] === 'product') { $item->setUrlKey(false); } $item->setStoreId($storeId); $webSiteIds = array_unique(array_merge($item->getWebsiteIds(), array($websiteId))); $item->setWebsiteIds($webSiteIds); $item->addData($extractor->extractItem($feedXPath, $itemNode, $item, $cfgData)); return $this; }
/** * Simple product that needs to be added as a configuration to a configurable product. * @param Mage_Catalog_Model_Product $product Simple product used to configure a configurable product. * @return $this object */ protected function _addToConfigurableProduct(Mage_Catalog_Model_Product $product) { $configurableProduct = null; $styleId = $this->_helper->normalizeSku($product->getStyleId(), $this->_config->catalogId); foreach ($this->_products as $collectionProduct) { if ($collectionProduct->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $collectionProduct->getSku() === $styleId) { $configurableProduct = $collectionProduct; break; } } if ($configurableProduct) { $usedProductIds = $configurableProduct->getTypeInstance()->getUsedProductIds(); $usedProductIds[] = $product->getId(); // save the configurable product links Mage::getResourceModel('catalog/product_type_configurable')->saveProducts($configurableProduct, array_unique($usedProductIds)); $configurableProduct->setData(self::USED_PRODUCT_IDS_PROPERTY, $usedProductIds)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); } else { // @todo put in error confirmation feed $logData = ['style_id' => $product->getStyleId(), 'sku' => $product->getSku()]; $logMessage = 'No configurable product with SKU "{style_id}" found for used product with SKU "{sku}".'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); } return $this; }
/** * @return array */ protected function getDefaultStockMap() { return $this->stockMap ?: (array) $this->catalogHelper->getConfigModel()->getConfigData(self::STOCK_CONFIG_PATH); }
/** * generate image feed file name * @param string $storeId * @return string */ protected function _generateFilePath($storeId) { $coreFeed = $this->_getFeedCore(); return $coreFeed->getLocalDirectory() . DS . str_replace(self::ID_PLACE_HOLDER, $storeId, $this->_catalogHelper->generateFileName($this->_config->imageFeedEventType, $this->_config->imageExportFilenameFormat)); }