private function processAccount(Ess_M2ePro_Model_Account $account, $percentsForAccount) { //--------------------------- $this->_profiler->addEol(); $this->_profiler->addTitle('Starting account "' . $account->getTitle() . '"'); // ->__('Task "%s" for eBay account: "%s" is started. Please wait...') $status = 'Task "%s" for eBay account: "%s" is started. Please wait...'; $status = Mage::helper('M2ePro')->__($status, $this->name, $account->getTitle()); $this->_lockItem->setStatus($status); $currentPercent = $this->_lockItem->getPercents(); //--------------------------- $collection = Mage::helper('M2ePro/Component_Ebay')->getCollection('Order')->addFieldToFilter('account_id', $account->getId())->addFieldToFilter('reservation_state', Ess_M2ePro_Model_Order_Reserve::STATE_PLACED); $reservationDays = (int) $account->getChildObject()->getQtyReservationDays(); if ($reservationDays > 0) { $minReservationStartDate = new DateTime(Mage::helper('M2ePro')->getCurrentGmtDate(), new DateTimeZone('UTC')); $minReservationStartDate->modify('- ' . $reservationDays . ' days'); $minReservationStartDate = $minReservationStartDate->format('Y-m-d H:i'); $collection->addFieldToFilter('reservation_start_date', array('lteq' => $minReservationStartDate)); } /** @var $reservedOrders Ess_M2ePro_Model_Order[] */ $reservedOrders = $collection->getItems(); //--------------------------- $this->_profiler->addEol(); $this->_profiler->addTitle('Total orders with expired reservation: ' . count($reservedOrders)); $currentPercent = $currentPercent + $percentsForAccount * 0.1; $this->_lockItem->setPercents($currentPercent); $this->_lockItem->activate(); //--------------------------- if (count($reservedOrders) == 0) { return; } //--------------------------- $this->_profiler->addTimePoint(__METHOD__ . 'process' . $account->getId(), 'Release qty for expired reservation'); $status = 'Task "%s" for eBay account: "%s" is in data processing state. Please wait...'; $status = Mage::helper('M2ePro')->__($status, $account->getTitle()); $this->_lockItem->setStatus($status); //--------------------------- $percentPerOrder = ($percentsForAccount - $currentPercent) / count($reservedOrders); $tempPercent = 0; foreach ($reservedOrders as $order) { $order->getReserve()->release(); $tempPercent += $percentPerOrder; if (floor($tempPercent) > 0) { $currentPercent += floor($tempPercent); $tempPercent -= floor($tempPercent); $this->_lockItem->setPercents($currentPercent); $this->_lockItem->activate(); } } //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'process' . $account->getId()); $this->_profiler->addEol(); $this->_profiler->addTitle('End account "' . $account->getTitle() . '"'); //--------------------------- }
private function processAccount(Ess_M2ePro_Model_Account $account) { $this->getActualOperationHistory()->addTimePoint(__METHOD__ . 'get' . $account->getId(), 'Get and process links on products for Account ' . $account->getTitle()); if (!$this->isPossibleProcessAccount($account)) { return; } $this->isNeedGettingLinksByPages($account) ? $this->updateLinksByPages($account) : $this->updateLinksByListingsIds($account); $this->getActualOperationHistory()->saveTimePoint(__METHOD__ . 'get' . $account->getId()); }
private function processAccountInventory(Ess_M2ePro_Model_Account $account) { $this->getActualOperationHistory()->addText('Starting Account "' . $account->getTitle() . '"'); // M2ePro_TRANSLATIONS // The "3rd Party Listings" Action for Rakuten.com Account: "%account_title%" is started. Please wait... $status = 'The "3rd Party Listings" Action for Rakuten.com Account: "%account_title%" is started.'; $status .= ' Please wait...'; $this->getActualLockItem()->setStatus(Mage::helper('M2ePro')->__($status, $account->getTitle())); if (!$this->isLockedAccount($account)) { $this->getActualOperationHistory()->addTimePoint(__METHOD__ . 'process' . $account->getId(), 'Process Account ' . $account->getTitle()); $dispatcherObject = Mage::getModel('M2ePro/Connector_Buy_Dispatcher'); $connectorObj = $dispatcherObject->getConnector('otherListings', 'update', 'requester', array(), $account, 'Ess_M2ePro_Model_Buy_Synchronization'); $dispatcherObject->process($connectorObj); $this->getActualOperationHistory()->saveTimePoint(__METHOD__ . 'process' . $account->getId()); } // M2ePro_TRANSLATIONS // The "3rd Party Listings" Action for Rakuten.com Account: "%account_title%" is finished. Please wait... $status = 'The "3rd Party Listings" Action for Rakuten.com Account: "%account_title%" is finished.'; $status .= ' Please wait...'; $this->getActualLockItem()->setStatus(Mage::helper('M2ePro')->__($status, $account->getTitle())); }
private function processAccount(Ess_M2ePro_Model_Account $account) { $title = 'Starting account "%s"'; $title = sprintf($title, $account->getTitle()); $this->_profiler->addTitle($title); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $account->getId(), 'Get orders from Play'); $status = 'Task "%s" for Play.com "%s" Account is started. Please wait...'; $status = Mage::helper('M2ePro')->__($status, $this->name, $account->getTitle()); $this->_lockItem->setStatus($status); //------------------------------ $fromDate = $this->prepareFromDate($account->getData('orders_last_synchronization')); $params = array('from_date' => $fromDate); if (is_null($account->getData('orders_last_synchronization'))) { $account->setData('orders_last_synchronization', $fromDate)->save(); } //------------------------------ // Get open orders from Play.com for account //--------------------------- /** @var $dispatcherObject Ess_M2ePro_Model_Connector_Play_Dispatcher */ $dispatcherObject = Mage::getModel('M2ePro/Connector_Play_Dispatcher'); $prefix = 'Ess_M2ePro_Model_Play_Synchronization'; $dispatcherObject->processConnector('tasks', 'orders_receive', 'requester', $params, $account, $prefix); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $account->getId()); $this->_profiler->addEol(); }
private function processAccount(Ess_M2ePro_Model_Account $account) { $title = 'Starting account "%s"'; $title = sprintf($title, $account->getTitle()); $this->_profiler->addTitle($title); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $account->getId(), 'Update orders on Rakuten.com'); $status = 'Task "%s" for Rakuten.com "%s" Account is started. Please wait...'; $status = Mage::helper('M2ePro')->__($status, $this->name, $account->getTitle()); $this->_lockItem->setStatus($status); $changesCollection = Mage::getModel('M2ePro/Order_Change')->getCollection(); $changesCollection->addAccountFilter($account->getId()); $changesCollection->addProcessingAttemptDateFilter(); $changesCollection->addFieldToFilter('component', Ess_M2ePro_Helper_Component_Buy::NICK); $changesCollection->addFieldToFilter('action', Ess_M2ePro_Model_Order_Change::ACTION_UPDATE_SHIPPING); $changesCollection->getSelect()->group(array('order_id')); if ($changesCollection->getSize() == 0) { return; } // Update orders shipping status on Rakuten.com //--------------------------- $params = array(); foreach ($changesCollection as $change) { $changeParams = $change->getParams(); $params[] = array('change_id' => $change->getId(), 'order_id' => $change->getOrderId(), 'buy_order_id' => $changeParams['buy_order_id'], 'buy_order_item_id' => $changeParams['buy_order_item_id'], 'qty' => $changeParams['qty'], 'tracking_type' => $changeParams['tracking_type'], 'tracking_number' => $changeParams['tracking_number'], 'ship_date' => $changeParams['ship_date']); } if (count($params) == 0) { return; } Mage::getResourceModel('M2ePro/Order_Change')->incrementAttemptCount($changesCollection->getAllIds()); $entity = 'orders'; $type = 'update'; $name = 'shipping'; /** @var $dispatcherObject Ess_M2ePro_Model_Connector_Buy_Dispatcher */ $dispatcherObject = Mage::getModel('M2ePro/Connector_Buy_Dispatcher'); $dispatcherObject->processConnector($entity, $type, $name, $params, $account); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $account->getId()); $this->_profiler->addEol(); }
private function processAccountMarketplaceInventoryTitle(Ess_M2ePro_Model_Account $accountObj, Ess_M2ePro_Model_Marketplace $marketplaceObj) { $firstSynchronizationTime = $accountObj->getChildObject()->getOtherListingsFirstSynchronization(); if (is_null($firstSynchronizationTime) || strtotime($firstSynchronizationTime) + 3 * 3600 > Mage::helper('M2ePro')->getCurrentGmtDate(true)) { return; } $this->_profiler->addTitle('Starting account "' . $accountObj->getTitle() . '" and marketplace "' . $marketplaceObj->getTitle() . '"'); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $accountObj->getId(), 'Get inventory from Buy'); $tempString = Mage::helper('M2ePro')->__('Task "3rd Party Listings Synchronization" for Rakuten.com account: '); $tempString .= Mage::helper('M2ePro')->__('"%s" and marketplace "%s" is started. Please wait...', $accountObj->getTitle(), Mage::helper('M2ePro')->__($marketplaceObj->getTitle())); $this->_lockItem->setStatus($tempString); $updateByPagesSettings = $accountObj->getChildObject()->getDecodedOtherListingsUpdateTitlesSettings(); if (is_null($updateByPagesSettings) || (int) $updateByPagesSettings['next_status'] <= 2 && (int) $updateByPagesSettings['next_page'] < 10000) { $this->updateInventoryTitlesByPages($accountObj, $marketplaceObj); } else { $this->updateInventoryTitlesBySkus($accountObj, $marketplaceObj); } $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $accountObj->getId()); $this->_profiler->addEol(); }
private function processAccountMarketplace(Ess_M2ePro_Model_Account $account, Ess_M2ePro_Model_Marketplace $marketplace) { $title = 'Starting account "' . $account->getTitle() . '" and marketplace "' . $marketplace->getTitle() . '"'; $this->_profiler->addTitle($title); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $account->getId(), 'Get orders from Buy'); $status = 'Task "%s" for Rakuten.com "%s" Account and "%s" marketplace is started. Please wait...'; $status = Mage::helper('M2ePro')->__($status, $this->name, $account->getTitle(), $marketplace->getTitle()); $this->_lockItem->setStatus($status); // Get open orders from Rakuten.com for account //--------------------------- $entity = 'tasks'; $type = 'orders_receive'; $name = 'requester'; $prefix = 'Ess_M2ePro_Model_Buy_Synchronization'; /** @var $dispatcherObject Ess_M2ePro_Model_Connector_Server_Buy_Dispatcher */ $dispatcherObject = Mage::getModel('M2ePro/Connector_Server_Buy_Dispatcher'); $dispatcherObject->processConnector($entity, $type, $name, array(), $marketplace, $account, $prefix); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $account->getId()); $this->_profiler->addEol(); }
private function updateAccount(Ess_M2ePro_Model_Account $account) { $this->_profiler->addTitle('Starting account "' . $account->getTitle() . '"'); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $account->getId(), 'Get orders from Amazon'); //->__('Task "%s" for Amazon account: "%s" is started. Please wait...') $status = 'Task "%s" for Amazon account: "%s" is started. Please wait...'; $status = Mage::helper('M2ePro')->__($status, $this->name, $account->getTitle()); $this->_lockItem->setStatus($status); // Get orders from Amazon for account //--------------------------- $fromDate = $this->prepareFromDate($account->getData('orders_last_synchronization')); $params = array('from_date' => $fromDate); if (is_null($account->getData('orders_last_synchronization'))) { $account->setData('orders_last_synchronization', $fromDate)->save(); } $entity = 'tasks'; $type = 'orders'; $name = 'requester'; $prefix = 'Ess_M2ePro_Model_Amazon_Synchronization'; $dispatcherObject = Mage::getModel('M2ePro/Connector_Amazon_Dispatcher'); $dispatcherObject->processConnector($entity, $type, $name, $params, $account, $prefix); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $account->getId()); $this->_profiler->addEol(); }
private function processAccount(Ess_M2ePro_Model_Account $account) { $title = 'Starting account "%s"'; $title = sprintf($title, $account->getTitle()); $this->_profiler->addTitle($title); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $account->getId(), 'Update orders on eBay'); $status = 'Task "%s" for eBay "%s" Account is started. Please wait...'; $status = Mage::helper('M2ePro')->__($status, $this->name, $account->getTitle()); $this->_lockItem->setStatus($status); $changesCollection = Mage::getModel('M2ePro/Order_Change')->getCollection(); $changesCollection->addAccountFilter($account->getId()); $changesCollection->addProcessingAttemptDateFilter(); $changesCollection->setPageSize(200); $changesCollection->getSelect()->group(array('order_id')); if ($changesCollection->getSize() == 0) { return; } // Update orders status on eBay //--------------------------- foreach ($changesCollection as $change) { Mage::getResourceModel('M2ePro/Order_Change')->incrementAttemptCount(array($change->getId())); $this->processChange($change); } //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $account->getId()); $this->_profiler->addEol(); }
private function processAccountMarketplace(Ess_M2ePro_Model_Account $account, Ess_M2ePro_Model_Marketplace $marketplace) { $title = 'Starting account "' . $account->getTitle() . '" and marketplace "' . $marketplace->getTitle() . '"'; $this->_profiler->addTitle($title); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $account->getId(), 'Update orders on Buy'); $statusString = 'Task "Orders Update Synchronization" for Rakuten.com "%s" Account and "%s" marketplace '; $statusString .= 'is started. Please wait...'; $status = Mage::helper('M2ePro')->__($statusString, $account->getTitle(), $marketplace->getTitle()); $this->_lockItem->setStatus($status); $changesCollection = Mage::getModel('M2ePro/Order_Change')->getCollection(); $changesCollection->addAccountFilter($account->getId()); $changesCollection->addFieldToFilter('action', Ess_M2ePro_Model_Order_Change::ACTION_UPDATE_SHIPPING); if ($changesCollection->getSize() == 0) { return; } // Update orders shipping status on Rakuten.com //--------------------------- $params = array(); foreach ($changesCollection as $change) { $changeParams = $change->getParams(); $params[] = array('order_id' => $change->getOrderId(), 'buy_order_id' => $changeParams['buy_order_id'], 'buy_order_item_id' => $changeParams['buy_order_item_id'], 'qty' => $changeParams['qty'], 'tracking_type' => $changeParams['tracking_type'], 'tracking_number' => $changeParams['tracking_number'], 'ship_date' => $changeParams['ship_date']); } /** @var $dispatcherObject Ess_M2ePro_Model_Connector_Server_Buy_Dispatcher */ $dispatcherObject = Mage::getModel('M2ePro/Buy_Connector')->getDispatcher(); $dispatcherObject->processConnector('orders', 'update', 'shipping', $params, $marketplace, $account); $changesCollection->walk('delete'); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $account->getId()); $this->_profiler->addEol(); }
private function updateAccount(Ess_M2ePro_Model_Account $accountObj) { $this->_profiler->addTitle('Starting account "' . $accountObj->getTitle() . '"'); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $accountObj->getId(), 'Get inventory from Play'); $tempString = Mage::helper('M2ePro')->__('Task "3rd Party Listings Synchronization" for Play.com account: '); $tempString .= Mage::helper('M2ePro')->__('"%s" is started. Please wait...', $accountObj->getTitle()); $this->_lockItem->setStatus($tempString); // Get all changes on Play for account //--------------------------- $dispatcherObject = Mage::getModel('M2ePro/Connector_Play_Dispatcher'); $dispatcherObject->processConnector('tasks', 'otherListings', 'requester', array(), $accountObj, 'Ess_M2ePro_Model_Play_Synchronization'); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $accountObj->getId()); $this->_profiler->addEol(); }
private function processAccountMarketplaceLinks(Ess_M2ePro_Model_Account $accountObj, Ess_M2ePro_Model_Marketplace $marketplaceObj) { $config = Mage::helper('M2ePro/Module')->getSynchronizationConfig(); $syncGroup = '/other_listings/'; $playSyncGroup = '/play/other_listings/'; $isGlobalSyncEnabled = (bool) $config->getGroupValue($syncGroup, 'mode'); $isPlaySyncEnabled = (bool) $config->getGroupValue($playSyncGroup, 'mode'); $firstOtherListingsSyncTime = $accountObj->getChildObject()->getOtherListingsFirstSynchronization(); $currentGmtDate = Mage::helper('M2ePro')->getCurrentGmtDate(true); $accountCreateDate = $accountObj->getData('create_date'); if ($isGlobalSyncEnabled && $isPlaySyncEnabled && strtotime($accountCreateDate) + 24 * 3600 > $currentGmtDate && (is_null($firstOtherListingsSyncTime) || strtotime($firstOtherListingsSyncTime) + 3 * 3600 > $currentGmtDate)) { return; } $this->_profiler->addTitle('Starting account "' . $accountObj->getTitle() . '" and marketplace "' . $marketplaceObj->getTitle() . '"'); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $accountObj->getId(), 'Get Product Links from Play'); $status = 'Task "Getting Products Links" for Play.com account: "%s" and marketplace "%s" '; $status .= 'is started. Please wait...'; $this->_lockItem->setStatus(Mage::helper('M2ePro')->__($status, $accountObj->getTitle(), $marketplaceObj->getTitle())); $updateByPagesSettings = $accountObj->getChildObject()->getDecodedListingsUpdateLinksSettings(); if (is_null($updateByPagesSettings) || (int) $updateByPagesSettings['next_status'] <= 3 && (int) $updateByPagesSettings['next_page'] < 10000) { $this->updateInventoryLinksByPages($accountObj, $marketplaceObj); } else { $this->updateInventoryLinksByListingsIds($accountObj, $marketplaceObj); } $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $accountObj->getId()); $this->_profiler->addEol(); }
private function processAccount(Ess_M2ePro_Model_Account $account) { $title = 'Starting account "' . $account->getTitle() . '"'; $this->_profiler->addTitle($title); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $account->getId(), 'Update orders on Amazon'); $status = 'Task "%s" for Amazon "%s" Account is started. Please wait...'; $status = Mage::helper('M2ePro')->__($status, $this->name, $account->getTitle()); $this->_lockItem->setStatus($status); $changesCollection = Mage::getModel('M2ePro/Order_Change')->getCollection(); $changesCollection->addAccountFilter($account->getId()); $changesCollection->addProcessingAttemptDateFilter(); $changesCollection->addFieldToFilter('component', Ess_M2ePro_Helper_Component_Amazon::NICK); $changesCollection->addFieldToFilter('action', Ess_M2ePro_Model_Order_Change::ACTION_UPDATE_SHIPPING); $changesCollection->setPageSize(self::MAX_UPDATES_PER_TIME); $changesCollection->getSelect()->group(array('order_id')); if ($changesCollection->getSize() == 0) { return; } // Update orders shipping status on Rakuten.com //--------------------------- $items = array(); foreach ($changesCollection as $change) { $changeParams = $change->getParams(); $items[] = array('order_id' => $change->getOrderId(), 'change_id' => $change->getId(), 'amazon_order_id' => $changeParams['amazon_order_id'], 'tracking_number' => $changeParams['tracking_number'], 'carrier_name' => $changeParams['carrier_name'], 'fulfillment_date' => $changeParams['fulfillment_date'], 'shipping_method' => isset($changeParams['shipping_method']) ? $changeParams['shipping_method'] : null, 'items' => $changeParams['items']); } if (count($items) == 0) { return; } Mage::getResourceModel('M2ePro/Order_Change')->incrementAttemptCount($changesCollection->getAllIds()); /** @var $dispatcherObject Ess_M2ePro_Model_Connector_Amazon_Dispatcher */ $dispatcherObject = Mage::getModel('M2ePro/Connector_Amazon_Dispatcher'); $dispatcherObject->processConnector('orders', 'update', 'items', array('items' => $items), $account); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $account->getId()); $this->_profiler->addEol(); }
protected function processAccount(Ess_M2ePro_Model_Account $account, $percentsForAccount) { $this->_profiler->addEol(); $this->_profiler->addTitle('Starting account "' . $account->getTitle() . '"'); $this->_profiler->addEol(); $this->_profiler->addTimePoint(__METHOD__ . 'get' . $account->getId(), 'Get orders from eBay'); // ->__('Task "Orders Synchronization" for eBay account: "%s" is started. Please wait...') $status = 'Task "Orders Synchronization" for eBay account: "%s" is started. Please wait...'; $tempString = Mage::helper('M2ePro')->__($status, $account->getTitle()); $this->_lockItem->setStatus($tempString); $currentPercent = $this->_lockItem->getPercents(); // Get from time //--------------------------- $fromTime = $this->prepareSinceTime($account->getData('orders_last_synchronization')); //--------------------------- // Get orders from eBay //--------------------------- $request = array('last_update' => $fromTime); if (is_null($account->getData('orders_last_synchronization'))) { $account->setData('orders_last_synchronization', $fromTime)->save(); } $response = Mage::getModel('M2ePro/Connector_Server_Ebay_Dispatcher')->processVirtualAbstract('sales', 'get', 'list', $request, NULL, NULL, $account, NULL); $ebayOrders = array(); $toTime = $fromTime; if (isset($response['orders']) && isset($response['updated_to'])) { $ebayOrders = $response['orders']; $toTime = $response['updated_to']; } if (count($ebayOrders) == 0) { return; } //--------------------------- $currentPercent = $currentPercent + $percentsForAccount * 0.15; $this->_lockItem->setPercents($currentPercent); $this->_lockItem->activate(); $this->_profiler->saveTimePoint(__METHOD__ . 'get' . $account->getId()); $this->_profiler->addTitle('Total count orders received from eBay: ' . count($ebayOrders)); $this->_profiler->addTimePoint(__METHOD__ . 'process' . $account->getId(), 'Processing received orders from eBay'); // ->__('Task "Orders Synchronization" for eBay account: "%acc%" is in data processing state. Please wait...') $status = 'Task "Orders Synchronization" for eBay account: "%s" is in data processing state. Please wait...'; $tempString = Mage::helper('M2ePro')->__($status, $account->getTitle()); $this->_lockItem->setStatus($tempString); // Save eBay orders //--------------------------- $orders = array(); foreach ($ebayOrders as $ebayOrderData) { /** @var $ebayOrder Ess_M2ePro_Model_Ebay_Order_Builder */ $ebayOrder = Mage::getModel('M2ePro/Ebay_Order_Builder'); $ebayOrder->initialize($account, $ebayOrderData); $orders[] = $ebayOrder->process(); } //--------------------------- $account->setData('orders_last_synchronization', $toTime)->save(); /** @var $orders Ess_M2ePro_Model_Order[] */ $orders = array_filter($orders); if (count($orders) == 0) { return; } $currentPercent = $currentPercent + $percentsForAccount * 0.05; $this->_lockItem->setPercents($currentPercent); $this->_lockItem->activate(); $this->_profiler->saveTimePoint(__METHOD__ . 'process' . $account->getId()); $this->_profiler->addEol(); $this->_profiler->addTimePoint(__METHOD__ . 'magento_orders_process' . $account->getId(), 'Creating magento orders'); // ->__('Task "Orders Synchronization" for eBay account: "%s" is in order creation state.. Please wait...') $status = 'Task "Orders Synchronization" for eBay account: "%s" is in order creation state.. Please wait...'; $tempString = Mage::helper('M2ePro')->__($status, $account->getTitle()); $this->_lockItem->setStatus($tempString); // Create magento orders //--------------------------- $magentoOrders = $paymentTransactions = $invoices = $shipments = $tracks = 0; $percentPerOrder = ($percentsForAccount - $currentPercent) / count($orders); $tempPercent = 0; foreach ($orders as $order) { /** @var $order Ess_M2ePro_Model_Order */ if ($order->canCreateMagentoOrder()) { try { $order->createMagentoOrder(); $magentoOrders++; } catch (Exception $e) { Mage::helper('M2ePro/Exception')->process($e, true); } } if ($order->getChildObject()->canCreatePaymentTransaction()) { $order->getChildObject()->createPaymentTransactions() && $paymentTransactions++; } if ($order->getChildObject()->canCreateInvoice()) { $order->createInvoice() && $invoices++; } if ($order->getChildObject()->canCreateShipment()) { $order->createShipment() && $shipments++; } if ($order->getChildObject()->canCreateTracks()) { $order->getChildObject()->createTracks() && $tracks++; } if ($order->getStatusUpdateRequired()) { $order->updateMagentoOrderStatus(); } $tempPercent += $percentPerOrder; if (floor($tempPercent) > 0) { $currentPercent += floor($tempPercent); $tempPercent -= floor($tempPercent); $this->_lockItem->setPercents($currentPercent); $this->_lockItem->activate(); } } //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'magento_orders_process' . $account->getId()); $this->_profiler->addTitle('Total count magento orders created: ' . $magentoOrders); $this->_profiler->addTitle('Total count payment transactions created: ' . $paymentTransactions); $this->_profiler->addTitle('Total count invoices created: ' . $invoices); $this->_profiler->addTitle('Total count shipments created: ' . $shipments); $this->_profiler->addEol(); $this->_profiler->addTitle('End account "' . $account->getTitle() . '"'); }
private function updateAccountMarketplace(Ess_M2ePro_Model_Account $accountObj, Ess_M2ePro_Model_Marketplace $marketplaceObj) { $this->_profiler->addTitle('Starting account "' . $accountObj->getTitle() . '" and marketplace "' . $marketplaceObj->getTitle() . '"'); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $accountObj->getId(), 'Get orders from Amazon'); //->__('Task "Orders Synchronization" for Amazon account: "%s" and marketplace "%s" is started. Please wait...') $tempString = 'Task "Orders Synchronization" for Amazon account: '; $tempString .= '"%s" and marketplace "%s" is started. Please wait...'; $this->_lockItem->setStatus(Mage::helper('M2ePro')->__($tempString, $accountObj->getTitle(), $marketplaceObj->getTitle())); // Get orders from Amazon for account //--------------------------- $fromDate = $this->prepareFromDate($accountObj->getData('orders_last_synchronization')); $params = array('from_date' => $fromDate); if (is_null($accountObj->getData('orders_last_synchronization'))) { $accountObj->setData('orders_last_synchronization', $fromDate)->save(); } $dispatcherObject = Mage::getModel('M2ePro/Amazon_Connector')->getDispatcher(); $dispatcherObject->processConnector('tasks', 'orders', 'requester', $params, $marketplaceObj, $accountObj, 'Ess_M2ePro_Model_Amazon_Synchronization'); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $accountObj->getId()); $this->_profiler->addEol(); }
private function processAccount(Ess_M2ePro_Model_Account $account) { $title = 'Starting account "%s"'; $title = sprintf($title, $account->getTitle()); $this->_profiler->addTitle($title); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $account->getId(), 'Update orders on Play'); $status = 'Task "%s" for Play.com "%s" Account is started. Please wait...'; $status = Mage::helper('M2ePro')->__($status, $this->name, $account->getTitle()); $this->_lockItem->setStatus($status); Mage::getResourceModel('M2ePro/Order_Change')->deleteByProcessingAttemptCount(Ess_M2ePro_Model_Order_Change::MAX_ALLOWED_PROCESSING_ATTEMPTS); $changesCollection = Mage::getModel('M2ePro/Order_Change')->getCollection(); $changesCollection->addAccountFilter($account->getId()); $changesCollection->addProcessingAttemptDateFilter(); $changesCollection->addFieldToFilter('action', Ess_M2ePro_Model_Order_Change::ACTION_UPDATE_SHIPPING); $changesCollection->getSelect()->group(array('order_id')); if ($changesCollection->getSize() == 0) { return; } Mage::getResourceModel('M2ePro/Order_Change')->incrementAttemptCount($changesCollection->getAllIds()); // Update orders shipping status on Rakuten.com //--------------------------- $params = array(); foreach ($changesCollection as $change) { $changeParams = $change->getParams(); $params[] = array('change_id' => $change->getId(), 'order_id' => $change->getOrderId(), 'play_order_id' => $changeParams['play_order_id'], 'carrier_name' => $changeParams['carrier_name'], 'tracking_number' => $changeParams['tracking_number']); } /** @var $dispatcherObject Ess_M2ePro_Model_Connector_Play_Dispatcher */ $dispatcherObject = Mage::getModel('M2ePro/Connector_Play_Dispatcher'); $dispatcherObject->processConnector('orders', 'update', 'shipping', $params, $account); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $account->getId()); $this->_profiler->addEol(); }
private function updateAccount(Ess_M2ePro_Model_Account $accountObj) { $this->_profiler->addTitle('Starting account "' . $accountObj->getTitle() . '"'); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $accountObj->getId(), 'Get inventory from Amazon'); $status = 'Task "Update Listings Products" for Amazon account: "%s" is started. Please wait...'; $this->_lockItem->setStatus(Mage::helper('M2ePro')->__($status, $accountObj->getTitle())); // Get all changes on Amazon for account //--------------------------- $dispatcherObject = Mage::getModel('M2ePro/Connector_Amazon_Dispatcher'); $dispatcherObject->processConnector('defaults', 'updateListingsProducts', 'requester', array(), $accountObj, 'Ess_M2ePro_Model_Amazon_Synchronization_Tasks'); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $accountObj->getId()); $this->_profiler->addEol(); }
private function processAccountInventoryTitle(Ess_M2ePro_Model_Account $account) { $this->getActualOperationHistory()->addTimePoint(__METHOD__ . 'get' . $account->getId(), 'Get and process Titles for Account ' . $account->getTitle()); if (!$this->isPossibleProcessAccountTitles($account)) { return; } $this->isNeedUpdateTitlesByPages($account) ? $this->updateTitlesByPages($account) : $this->updateTitlesBySkus($account); $this->getActualOperationHistory()->saveTimePoint(__METHOD__ . 'get' . $account->getId()); }
private function processAccount(Ess_M2ePro_Model_Account $account, $percentsForAccount) { //--------------------------- $this->_profiler->addEol(); $this->_profiler->addTitle('Starting account "' . $account->getTitle() . '"'); // ->__('Task "Orders Cancellation Synchronization" for eBay account: "%s" is started. Please wait...') $status = 'Task "Orders Cancellation Synchronization" for eBay account: "%s" is started. Please wait...'; $tempString = Mage::helper('M2ePro')->__($status, $account->getTitle()); $this->_lockItem->setStatus($tempString); $currentPercent = $this->_lockItem->getPercents(); //--------------------------- if (!$account->getChildObject()->shouldCreateMagentoOrderImmediately() || $account->getChildObject()->getMagentoOrdersReservationDays() <= 0) { return; } $data = $this->getUnpaidOrdersUpdates($account); //--------------------------- $this->_profiler->addEol(); $this->_profiler->addTimePoint(__METHOD__ . 'get' . $account->getId(), 'Get unpaid orders to process'); $this->_profiler->addTitle('Total unpaid orders updates: ' . count($data)); $currentPercent = $currentPercent + $percentsForAccount * 0.1; $this->_lockItem->setPercents($currentPercent); $this->_lockItem->activate(); //--------------------------- if (count($data) == 0) { return; } //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'get' . $account->getId()); $this->_profiler->addTimePoint(__METHOD__ . 'process' . $account->getId(), 'Processing unpaid orders'); $status = 'Task "Orders Synchronization" for eBay account: '; $status .= '"%s" is in data processing state. Please wait...'; $tempString = Mage::helper('M2ePro')->__($status, $account->getTitle()); $this->_lockItem->setStatus($tempString); //--------------------------- /** @var $cancellationCandidates Ess_M2ePro_Model_Order[] */ $cancellationCandidates = array(); foreach ($data as $orderData) { $cancellationCandidates[] = $this->associateAndUpdateOrder($account, $orderData); } //--------------------------- $this->_profiler->addEol(); $this->_profiler->addTimePoint(__METHOD__ . 'get' . $account->getId(), 'Update unpaid orders with data from eBay'); $currentPercent = $currentPercent + $percentsForAccount * 0.1; $this->_lockItem->setPercents($currentPercent); $this->_lockItem->activate(); //--------------------------- $cancellationCandidates = array_filter($cancellationCandidates); if (count($cancellationCandidates) == 0) { return; } //--------------------------- $this->totalOpenedUnpaidItemProcesses = 0; $this->totalCanceledMagentoOrders = 0; $percentPerOrder = ($percentsForAccount - $currentPercent) / count($cancellationCandidates); $tempPercent = 0; //--------------------------- foreach ($cancellationCandidates as $order) { $this->processOrder($order); //--------------------------- $tempPercent += $percentPerOrder; if (floor($tempPercent) > 0) { $currentPercent += floor($tempPercent); $tempPercent -= floor($tempPercent); $this->_lockItem->setPercents($currentPercent); $this->_lockItem->activate(); } //--------------------------- } //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'cancellation_process' . $account->getId()); $this->_profiler->addTitle('Total count unpaid item processes opened: ' . $this->totalOpenedUnpaidItemProcesses); $this->_profiler->addTitle('Total count magento orders canceled: ' . $this->totalCanceledMagentoOrders); $this->_profiler->addEol(); $this->_profiler->addTitle('End account "' . $account->getTitle() . '"'); //--------------------------- }
private function updateAccountMarketplace(Ess_M2ePro_Model_Account $accountObj, Ess_M2ePro_Model_Marketplace $marketplaceObj) { $this->_profiler->addTitle('Starting account "' . $accountObj->getTitle() . '" and marketplace "' . $marketplaceObj->getTitle() . '"'); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $accountObj->getId(), 'Get inventory from Amazon'); $tempString = 'Task "3rd Party Listings Synchronization" for Amazon account: '; $tempString .= '"%s" and marketplace "%s" is started. Please wait...'; $this->_lockItem->setStatus(Mage::helper('M2ePro')->__($tempString, $accountObj->getTitle(), $marketplaceObj->getTitle())); // Get all changes on Amazon for account //--------------------------- $dispatcherObject = Mage::getModel('M2ePro/Connector_Server_Amazon_Dispatcher'); $dispatcherObject->processConnector('tasks', 'otherListings', 'requester', array(), $marketplaceObj, $accountObj, 'Ess_M2ePro_Model_Amazon_Synchronization'); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $accountObj->getId()); $this->_profiler->addEol(); }
private function updateAccountMarketplace(Ess_M2ePro_Model_Account $accountObj, Ess_M2ePro_Model_Marketplace $marketplaceObj) { $this->_profiler->addTitle('Starting account "' . $accountObj->getTitle() . '" and marketplace "' . $marketplaceObj->getTitle() . '"'); $this->_profiler->addTimePoint(__METHOD__ . 'send' . $accountObj->getId(), 'Get inventory from Buy'); $status = 'Task "Update Listings Products" for Rakuten.com account: "%s" and marketplace "%s" '; $status .= 'is started. Please wait...'; $this->_lockItem->setStatus(Mage::helper('M2ePro')->__($status, $accountObj->getTitle(), $marketplaceObj->getTitle())); // Get all changes on Buy for account //--------------------------- $dispatcherObject = Mage::getModel('M2ePro/Buy_Connector')->getDispatcher(); $dispatcherObject->processConnector('defaults', 'updateListingsProducts', 'requester', array(), $marketplaceObj, $accountObj, 'Ess_M2ePro_Model_Buy_Synchronization_Tasks'); //--------------------------- $this->_profiler->saveTimePoint(__METHOD__ . 'send' . $accountObj->getId()); $this->_profiler->addEol(); }