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 #2
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) {
             $actionTitle = Ess_M2ePro_Model_Connector_Server_Ebay_OtherItem_Dispatcher::getActionTitle($action);
             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
                     //-----------------------------
                     $statusProductsIds = array();
                     foreach ($itemsForStep as $item) {
                         $statusProductsIds[] = $item->getData('product_id');
                     }
                     $statusIdsString = Mage::helper('M2ePro')->__('product(s) with id(s)') . ' "' . implode('", "', $statusProductsIds) . '".';
                     $lockItem->setStatus($actionTitle . ' ' . $statusIdsString . ' ' . $waitMessage);
                     //-----------------------------
                     $tempResult = Mage::getModel('M2ePro/Connector_Server_Ebay_OtherItem_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_OtherItem_Abstract::getMainStatus($results);
 }