Example #1
0
 /**
  * @param array $products
  * @param string $connectorNameSingle
  * @param array $params
  * @return int
  */
 protected function processProducts(array $products, $connectorNameSingle, array $params = array())
 {
     $results = array();
     if (count($products) == 0) {
         return Ess_M2ePro_Model_Connectors_Ebay_Item_Abstract::getMainStatus($results);
     }
     if (!class_exists($connectorNameSingle)) {
         return Ess_M2ePro_Model_Connectors_Ebay_Item_Abstract::getMainStatus($results);
     }
     $needRemoveLockItem = false;
     $lockItem = Mage::getModel('M2ePro/ListingsLockItem', array('id' => 'listingsEbay'));
     if (!$lockItem->isExist()) {
         $lockItem->create();
         $lockItem->makeShutdownFunction();
         $needRemoveLockItem = true;
     }
     try {
         foreach ($products as $product) {
             $connector = new $connectorNameSingle($params, $product);
             $connector->process();
             $results[] = $connector->getStatus();
         }
     } catch (Exception $exception) {
         try {
             Mage::helper('M2ePro/Exception')->process($exception, true);
         } catch (Exception $exceptionTemp) {
         }
         Mage::getModel('M2ePro/EbayListingsLogs')->addGlobalMessage(Ess_M2ePro_Model_LogsBase::INITIATOR_UNKNOWN, $this->logsActionId, Ess_M2ePro_Model_EbayListingsLogs::ACTION_UNKNOWN, Mage::helper('M2ePro')->__($exception->getMessage()), Ess_M2ePro_Model_EbayListingsLogs::TYPE_ERROR, Ess_M2ePro_Model_EbayListingsLogs::PRIORITY_HIGH);
         $results[] = Ess_M2ePro_Model_Connectors_Ebay_Item_Abstract::STATUS_ERROR;
     }
     $lockItem->isExist() && $needRemoveLockItem && $lockItem->remove();
     return Ess_M2ePro_Model_Connectors_Ebay_Item_Abstract::getMainStatus($results);
 }
Example #2
0
 public function process()
 {
     $result = parent::process();
     foreach ($this->messages as $message) {
         $priorityMessage = Ess_M2ePro_Model_ListingsLogs::PRIORITY_MEDIUM;
         if ($message[parent::MESSAGE_TYPE_KEY] == parent::MESSAGE_TYPE_ERROR) {
             $priorityMessage = Ess_M2ePro_Model_ListingsLogs::PRIORITY_HIGH;
         }
         $this->addListingsProductsLogsMessage($this->listingProduct, $message, $priorityMessage);
     }
     return $result;
 }
 public function process()
 {
     $result = parent::process();
     foreach ($this->messages as $message) {
         $priorityMessage = Ess_M2ePro_Model_ListingsLogs::PRIORITY_MEDIUM;
         if ($message[parent::MESSAGE_TYPE_KEY] == parent::MESSAGE_TYPE_ERROR) {
             $priorityMessage = Ess_M2ePro_Model_ListingsLogs::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_ListingsLogs::PRIORITY_MEDIUM;
                 if ($message[parent::MESSAGE_TYPE_KEY] == parent::MESSAGE_TYPE_ERROR) {
                     $priorityMessage = Ess_M2ePro_Model_ListingsLogs::PRIORITY_HIGH;
                 }
                 $this->addListingsProductsLogsMessage($listingProductInArray, $message, $priorityMessage);
             }
         }
     }
     return $result;
 }
 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']);
         }
     }
     if ($totalCount == 0) {
         return Ess_M2ePro_Model_Connectors_Ebay_Item_Abstract::STATUS_SUCCESS;
     }
     //----------------------------
     // Execute ebay actions
     //----------------------------
     $results = array();
     $percentsOneProduct = ($percentsTo - $percentsFrom) / $totalCount;
     foreach ($actions as $action => $combinations) {
         foreach ($combinations as $combination) {
             $currentCount = count($combination['items']);
             $maxCountPerStep = 10;
             $currentCount <= 25 && ($maxCountPerStep = 5);
             $currentCount <= 15 && ($maxCountPerStep = 3);
             $currentCount <= 8 && ($maxCountPerStep = 2);
             $currentCount <= 4 && ($maxCountPerStep = 1);
             $percentsCurrentInterval = $percentsOneProduct * $currentCount;
             $percentsByStep = $percentsCurrentInterval / ceil($currentCount / $maxCountPerStep);
             for ($i = 0; $i < count($combination['items']); $i += $maxCountPerStep) {
                 $itemsForStep = array_slice($combination['items'], $i, $maxCountPerStep);
                 // Set status for progress bar
                 //-----------------------------
                 $statusActionTitle = Ess_M2ePro_Model_Connectors_Ebay_Item_Dispatcher::getActionTitle($action);
                 $statusProductsIds = array();
                 foreach ($itemsForStep as $item) {
                     $statusProductsIds[] = $item->getData('product_id');
                 }
                 $lockItem->setStatus($statusActionTitle . ' "' . implode('", "', $statusProductsIds) . '" ' . Mage::helper('M2ePro')->__('product(s). Please wait...'));
                 //-----------------------------
                 $tempResult = Mage::getModel('M2ePro/Connectors_Ebay_Item_Dispatcher')->process($action, $itemsForStep, $combination['params']);
                 $results = array_merge($results, array($tempResult));
                 // Set percents for progress bar
                 //-----------------------------
                 $percentsStep = (int) $lockItem->getPercents() + $percentsByStep;
                 if ($percentsStep > $percentsTo) {
                     $percentsStep = $percentsTo;
                 }
                 $lockItem->setPercents($percentsStep);
                 //-----------------------------
                 $lockItem->activate();
             }
         }
     }
     //----------------------------
     $lockItem->setStatus(Mage::helper('M2ePro')->__('Communication with eBay is finished. Please wait...'));
     $lockItem->setPercents($percentsTo);
     $lockItem->activate();
     return Ess_M2ePro_Model_Connectors_Ebay_Item_Abstract::getMainStatus($results);
 }
Example #5
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_Connectors_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) {
         try {
             Mage::helper('M2ePro/Exception')->process($exception, true);
         } catch (Exception $exceptionTemp) {
         }
         Mage::getModel('M2ePro/ListingsLogs')->addListingMessage($listingId, Ess_M2ePro_Model_LogsBase::INITIATOR_UNKNOWN, $this->logsActionId, Ess_M2ePro_Model_ListingsLogs::ACTION_UNKNOWN, $exception->getMessage(), Ess_M2ePro_Model_ListingsLogs::TYPE_ERROR, Ess_M2ePro_Model_ListingsLogs::PRIORITY_HIGH);
         return Ess_M2ePro_Model_Connectors_Ebay_Item_Abstract::STATUS_ERROR;
     }
 }