Esempio n. 1
0
 public function __construct(array $params = array(), array $listingsProducts)
 {
     $defaultParams = array('status_changer' => Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_UNKNOWN);
     $params = array_merge($defaultParams, $params);
     if (isset($params['logs_action_id'])) {
         $this->logsActionId = (int) $params['logs_action_id'];
         unset($params['logs_action_id']);
     } else {
         $this->logsActionId = Mage::getModel('M2ePro/Listing_Log')->getNextActionId();
     }
     if (count($listingsProducts) == 0) {
         throw new Exception('Product connector has received empty array');
     }
     foreach ($listingsProducts as $listingProduct) {
         if (!$listingProduct instanceof Ess_M2ePro_Model_Listing_Product) {
             throw new Exception('Product connector has received invalid product data type');
         }
     }
     $accountObj = $listingsProducts[0]->getListing()->getAccount();
     foreach ($listingsProducts as $listingProduct) {
         /** @var $listingProduct Ess_M2ePro_Model_Listing_Product */
         if ($accountObj->getId() != $listingProduct->getListing()->getAccountId()) {
             throw new Exception('Product connector has received products from different accounts');
         }
     }
     parent::__construct($params, $accountObj);
     $listingsProducts = $this->filterLockedListingsProducts($listingsProducts);
     $listingsProducts = $this->prepareListingsProducts($listingsProducts);
     $this->listingsProducts = array_values($listingsProducts);
 }
Esempio n. 2
0
 /**
  * @param array $params
  * @param Ess_M2ePro_Model_Listing_Product[] $listingsProducts
  * @throws Exception
  */
 public function __construct(array $params = array(), array $listingsProducts)
 {
     if (!isset($params['logs_action_id']) || !isset($params['status_changer'])) {
         throw new Exception('Product Connector has not received some params');
     }
     if (empty($listingsProducts)) {
         throw new Exception('Product Connector has received empty array');
     }
     /** @var Ess_M2ePro_Model_Account $account */
     $account = reset($listingsProducts)->getListing()->getAccount();
     $listingProductIds = array();
     foreach ($listingsProducts as $listingProduct) {
         if (!$listingProduct instanceof Ess_M2ePro_Model_Listing_Product) {
             throw new Exception('Product Connector has received invalid Product data type');
         }
         if ($account->getId() != $listingProduct->getListing()->getAccountId()) {
             throw new Exception('Product Connector has received Products from different Accounts');
         }
         $listingProductIds[] = $listingProduct->getId();
     }
     /** @var Ess_M2ePro_Model_Mysql4_Listing_Product_Collection $listingProductCollection */
     $listingProductCollection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
     $listingProductCollection->addFieldToFilter('id', array('in' => array_unique($listingProductIds)));
     $actualListingsProducts = $listingProductCollection->getItems();
     if (empty($actualListingsProducts)) {
         throw new Exception('All products were removed before connector processing');
     }
     $this->listingsProducts = $actualListingsProducts;
     parent::__construct($params, $account);
 }