Esempio n. 1
0
 protected function processResponseInfo($responseInfo)
 {
     try {
         parent::processResponseInfo($responseInfo);
     } catch (Exception $exception) {
         $message = array(parent::MESSAGE_TYPE_KEY => parent::MESSAGE_TYPE_ERROR, parent::MESSAGE_TEXT_KEY => $exception->getMessage());
         $this->addListingsProductsLogsMessage($this->listingProduct, $message, Ess_M2ePro_Model_Log_Abstract::PRIORITY_HIGH);
         throw $exception;
     }
 }
Esempio n. 2
0
 public function process()
 {
     $result = parent::process();
     foreach ($this->messages as $message) {
         $priorityMessage = Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM;
         if ($message[parent::MESSAGE_TYPE_KEY] == parent::MESSAGE_TYPE_ERROR) {
             $priorityMessage = Ess_M2ePro_Model_Log_Abstract::PRIORITY_HIGH;
         }
         $this->addListingsProductsLogsMessage($this->listingProduct, $message, $priorityMessage);
     }
     return $result;
 }
Esempio n. 3
0
 public function process()
 {
     $result = parent::process();
     foreach ($this->messages as $message) {
         $priorityMessage = Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM;
         if ($message[parent::MESSAGE_TYPE_KEY] == parent::MESSAGE_TYPE_ERROR) {
             $priorityMessage = Ess_M2ePro_Model_Log_Abstract::PRIORITY_HIGH;
         }
         $this->addListingsLogsMessage($message, $priorityMessage);
     }
     if (isset($result['result'])) {
         foreach ($result['result'] as $tempIdProduct => $tempResultProduct) {
             if (!isset($tempResultProduct['messages'])) {
                 continue;
             }
             $listingProductInArray = NULL;
             foreach ($this->listingsProducts as $listingProduct) {
                 if ($tempIdProduct == $listingProduct->getId()) {
                     $listingProductInArray = $listingProduct;
                     break;
                 }
             }
             if (is_null($listingProductInArray)) {
                 continue;
             }
             foreach ($tempResultProduct['messages'] as $message) {
                 $priorityMessage = Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM;
                 if ($message[parent::MESSAGE_TYPE_KEY] == parent::MESSAGE_TYPE_ERROR) {
                     $priorityMessage = Ess_M2ePro_Model_Log_Abstract::PRIORITY_HIGH;
                 }
                 $this->addListingsProductsLogsMessage($listingProductInArray, $message, $priorityMessage);
             }
         }
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * @param int $listingId
  * @param array $products
  * @param string $connectorNameSingle
  * @param string|null $connectorNameMultiple
  * @param array $params
  * @return int
  */
 protected function processProducts($listingId, array $products, $connectorNameSingle, $connectorNameMultiple = NULL, array $params = array())
 {
     try {
         if (count($products) > 1) {
             if (is_null($connectorNameMultiple)) {
                 $results = array();
                 foreach ($products as $product) {
                     $results[] = $this->processProducts($listingId, array($product), $connectorNameSingle, $connectorNameMultiple, $params);
                 }
                 return Ess_M2ePro_Model_Connector_Server_Ebay_Item_Abstract::getMainStatus($results);
             } else {
                 $productsInstances = array();
                 foreach ($products as $product) {
                     $productsInstances[] = $product;
                 }
                 $connector = new $connectorNameMultiple($params, $productsInstances);
             }
         } else {
             $productInstance = $products[0];
             $connector = new $connectorNameSingle($params, $productInstance);
         }
         $connector->process();
         return $connector->getStatus();
     } catch (Exception $exception) {
         Mage::helper('M2ePro/Exception')->process($exception, true);
         $logModel = Mage::getModel('M2ePro/Listing_Log');
         $logModel->setComponentMode(Ess_M2ePro_Helper_Component_Ebay::NICK);
         $logModel->addListingMessage($listingId, Ess_M2ePro_Model_Log_Abstract::INITIATOR_UNKNOWN, $this->logsActionId, Ess_M2ePro_Model_Listing_Log::ACTION_UNKNOWN, $exception->getMessage(), Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR, Ess_M2ePro_Model_Log_Abstract::PRIORITY_HIGH);
         return Ess_M2ePro_Model_Connector_Server_Ebay_Item_Abstract::STATUS_ERROR;
     }
 }
Esempio n. 5
0
 public function execute(Ess_M2ePro_Model_Synchronization_LockItem $lockItem, $percentsFrom, $percentsTo)
 {
     $lockItem->activate();
     $lockItem->setPercents($percentsFrom);
     $lockItem->setStatus(Mage::helper('M2ePro')->__('Communication with eBay is started. Please wait...'));
     // Get prepared for actions array
     //----------------------------
     $actions = $this->makeActionsForExecute();
     //----------------------------
     // Calculate total count items
     //----------------------------
     $totalCount = 0;
     foreach ($actions as $combinations) {
         foreach ($combinations as $combination) {
             $totalCount += count($combination['items']);
         }
     }
     //----------------------------
     $results = array();
     if ($totalCount == 0) {
         $results[] = Ess_M2ePro_Model_Connector_Server_Ebay_Item_Abstract::STATUS_SUCCESS;
     } else {
         // Execute eBay actions
         //----------------------------
         $countProcessedItems = 0;
         $percentsOneProduct = ($percentsTo - $percentsFrom) / $totalCount;
         $waitMessage = Mage::helper('M2ePro')->__('Please wait...');
         foreach ($actions as $action => $combinations) {
             foreach ($combinations as $combination) {
                 $tempCount = count($combination['items']);
                 $maxCountPerStep = 10;
                 $tempCount <= 25 && ($maxCountPerStep = 5);
                 $tempCount <= 15 && ($maxCountPerStep = 3);
                 $tempCount <= 8 && ($maxCountPerStep = 2);
                 $tempCount <= 4 && ($maxCountPerStep = 1);
                 for ($i = 0; $i < count($combination['items']); $i += $maxCountPerStep) {
                     $itemsForStep = array_slice($combination['items'], $i, $maxCountPerStep);
                     $countProcessedItems += count($itemsForStep);
                     // Set status for progress bar
                     //-----------------------------
                     $actionTitle = Ess_M2ePro_Model_Connector_Server_Ebay_Item_Dispatcher::getActionTitle($action);
                     $statusProductsIds = array();
                     foreach ($itemsForStep as $item) {
                         $statusProductsIds[] = $item->getData('product_id');
                     }
                     if (count($statusProductsIds) > 10) {
                         $statusIdsString = count($statusProductsIds) . ' ' . Mage::helper('M2ePro')->__('product(s)') . '.';
                     } else {
                         $statusIdsString = Mage::helper('M2ePro')->__('product(s) with id(s)') . ' "' . implode('", "', $statusProductsIds) . '".';
                     }
                     $lockItem->setStatus($actionTitle . ' ' . $statusIdsString . ' ' . $waitMessage);
                     //-----------------------------
                     $tempResult = Mage::getModel('M2ePro/Connector_Server_Ebay_Item_Dispatcher')->process($action, $itemsForStep, $combination['params']);
                     $results = array_merge($results, array($tempResult));
                     // Set percents for progress bar
                     //-----------------------------
                     $tempPercents = $percentsFrom + $countProcessedItems * $percentsOneProduct;
                     $lockItem->setPercents($tempPercents > $percentsTo ? $percentsTo : $tempPercents);
                     //-----------------------------
                     $lockItem->activate();
                 }
             }
         }
         //----------------------------
     }
     $lockItem->setStatus(Mage::helper('M2ePro')->__('Communication with eBay is finished. Please wait...'));
     $lockItem->setPercents($percentsTo);
     $lockItem->activate();
     return Ess_M2ePro_Model_Connector_Server_Ebay_Item_Abstract::getMainStatus($results);
 }