/**
  * 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;
 }