コード例 #1
0
 /**
  * Create the DOMDocument representing the feed. Should initialize (add root
  * node and message header) the DOMDocument, build out and append fragments
  * for each item to be included, and validate the resulting DOM.
  */
 public function testCreateDomFromFeedData()
 {
     $itemNode = 'Item';
     $isValidate = 'true';
     $this->_doc->loadXML('<root></root>');
     $itemFragment = $this->_doc->createDocumentFragment();
     $itemFragment->appendChild($this->_doc->createElement('Item'));
     $pimProduct = $this->getModelMockBuilder('ebayenterprise_catalog/pim_product')->disableOriginalConstructor()->getMock();
     $this->replaceByMock('helper', 'eb2ccore', $this->_coreHelper);
     $this->_coreHelper->expects($this->once())->method('parseBool')->with($this->identicalTo($isValidate))->will($this->returnValue(true));
     $this->_pimProductCollection->expects($this->once())->method('getItems')->will($this->returnValue(array($pimProduct)));
     $pim = $this->getModelMockBuilder('ebayenterprise_catalog/pim')->disableOriginalConstructor()->setMethods(array('_buildItemNode', '_startDocument', '_validateDocument', '_getFeedConfig'))->getMock();
     $pim->expects($this->once())->method('_startDocument')->will($this->returnSelf());
     $pim->expects($this->once())->method('_buildItemNode')->with($this->identicalTo($pimProduct), $this->identicalTo($itemNode))->will($this->returnValue($itemFragment));
     $pim->expects($this->once())->method('_validateDocument')->will($this->returnSelf());
     $pim->expects($this->once())->method('_getFeedConfig')->will($this->returnValue($this->_feedTypeConfig));
     EcomDev_Utils_Reflection::setRestrictedPropertyValue($pim, '_doc', $this->_doc);
     $this->assertSame($this->_doc, EcomDev_Utils_Reflection::invokeRestrictedMethod($pim, '_createDomFromFeedData', array($this->_pimProductCollection, $this->_feedTypeConfig)));
     $this->assertSame('<root><Item></Item></root>', $this->_doc->C14N());
 }
コード例 #2
0
 /**
  * Process all of the products within a given store.
  *
  * @param  Mage_Catalog_Model_Resource_Product_Collection $products products for a specific store
  * @param  EbayEnterprise_Catalog_Model_Pim_Product_Collection $pimProducts collection of PIM Product instances
  * @param  string $key
  * @param array $productIds
  * @return EbayEnterprise_Catalog_Model_Pim_Product_Collection $pimProducts collection of PIM Product instances
  */
 protected function _processProductCollection(Mage_Catalog_Model_Resource_Product_Collection $products, EbayEnterprise_Catalog_Model_Pim_Product_Collection $pimProducts, array &$productIds = null)
 {
     $excludedProductIds = array();
     $currentStoreId = $products->getStoreId();
     $config = Mage::helper('eb2ccore')->getConfigModel($currentStoreId);
     $clientId = $config->clientId;
     $catalogId = $config->catalogId;
     foreach ($products->getItems() as $product) {
         $product->setStoreId($currentStoreId);
         $pimProduct = $pimProducts->getItemForProduct($product);
         if (!$pimProduct) {
             $pimProduct = Mage::getModel('ebayenterprise_catalog/pim_product', array('client_id' => $clientId, 'catalog_id' => $catalogId, 'sku' => $product->getSku()));
             $pimProducts->addItem($pimProduct);
         }
         try {
             $pimProduct->loadPimAttributesByProduct($product, $this->_doc, $this->_getFeedConfig(), $this->_getFeedAttributes($currentStoreId));
         } catch (EbayEnterprise_Catalog_Model_Pim_Product_Validation_Exception $e) {
             $logData = ['sku' => $pimProduct->getSku()];
             $logMessage = 'Product "{sku}" excluded from export.';
             $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
             $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
             $excludedProductIds[] = $product->getId();
             $pimProducts->deleteItem($pimProduct);
         }
     }
     if ($productIds) {
         $productIds = array_diff($productIds, $excludedProductIds);
     }
     return $pimProducts;
 }