private function processAccount(Ess_M2ePro_Model_Account $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(); } $dispatcherObject = Mage::getModel('M2ePro/Connector_Amazon_Dispatcher'); $connectorObj = $dispatcherObject->getConnector('orders', 'receive', 'requester', $params, $account, 'Ess_M2ePro_Model_Amazon_Synchronization'); $dispatcherObject->process($connectorObj); }
private function processAccount(Ess_M2ePro_Model_Account $account) { $sinceTime = $this->prepareSinceTime($account->getData('defaults_last_synchronization')); $changesByAccount = $this->getChangesByAccount($account, $sinceTime); if (!isset($changesByAccount['items']) || !isset($changesByAccount['to_time'])) { return; } $account->getChildObject()->setData('defaults_last_synchronization', $changesByAccount['to_time'])->save(); Mage::helper('M2ePro/Data_Cache_Session')->setValue('item_get_changes_data_' . $account->getId(), $changesByAccount); foreach ($changesByAccount['items'] as $change) { /* @var $listingProduct Ess_M2ePro_Model_Listing_Product */ $listingProduct = Mage::helper('M2ePro/Component_Ebay')->getListingProductByEbayItem($change['id'], $account->getId()); if (is_null($listingProduct)) { continue; } // Listing product isn't listed and it child must have another item_id if ($listingProduct->getStatus() != Ess_M2ePro_Model_Listing_Product::STATUS_LISTED && $listingProduct->getStatus() != Ess_M2ePro_Model_Listing_Product::STATUS_HIDDEN) { continue; } $this->processListingProduct($listingProduct, $change); if (empty($change['variations'])) { continue; } $variations = $listingProduct->getVariations(true); if (count($variations) <= 0) { continue; } $variationsSnapshot = $this->getVariationsSnapshot($variations); if (count($variationsSnapshot) <= 0) { return; } $this->processListingProductVariation($variationsSnapshot, $change['variations'], $listingProduct); } }
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) { $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 = 'orders'; $type = 'receive'; $name = 'requester'; $prefix = 'Ess_M2ePro_Model_Amazon_Synchronization'; $dispatcherObject = Mage::getModel('M2ePro/Connector_Amazon_Dispatcher'); $dispatcherObject->processConnector($entity, $type, $name, $params, $account, $prefix); }
private function isPossibleProcessAccount(Ess_M2ePro_Model_Account $account) { if (!$this->getConfigValue('/play/other_listings/', 'mode')) { return true; } $currentGmtDate = Mage::helper('M2ePro')->getCurrentGmtDate(true); if (strtotime($account->getData('create_date')) + 24 * 3600 < $currentGmtDate) { return true; } $firstOtherListingsSyncTime = $account->getChildObject()->getOtherListingsFirstSynchronization(); if (!is_null($firstOtherListingsSyncTime) && strtotime($firstOtherListingsSyncTime) + 3 * 3600 < $currentGmtDate) { return true; } return false; }
private function processPlayOrders($response, Ess_M2ePro_Model_Account $account) { $ordersLastSynchronization = $account->getData('orders_last_synchronization'); $orders = array(); foreach ($response as $orderData) { $currentOrderDate = $orderData['purchase_create_date']; if (strtotime($currentOrderDate) > strtotime($ordersLastSynchronization)) { $ordersLastSynchronization = $currentOrderDate; } /** @var $orderBuilder Ess_M2ePro_Model_Play_Order_Builder */ $orderBuilder = Mage::getModel('M2ePro/Play_Order_Builder'); $orderBuilder->initialize($account, $orderData); $order = $orderBuilder->process(); $orders[] = $order; } $account->setData('orders_last_synchronization', $ordersLastSynchronization)->save(); return $orders; }
private function executeUpdateInventoryDataAccount(Ess_M2ePro_Model_Account $account) { $sinceTime = $account->getData('other_listings_last_synchronization'); if (empty($sinceTime)) { $marketplaceCollection = Mage::helper('M2ePro/Component_Ebay')->getCollection('Marketplace'); $marketplaceCollection->addFieldToFilter('status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE); $marketplace = $marketplaceCollection->getFirstItem(); if (!$marketplace->getId()) { $marketplace = Ess_M2ePro_Helper_Component_Ebay::MARKETPLACE_US; } $dispatcherObject = Mage::getModel('M2ePro/Connector_Ebay_Dispatcher'); $connectorObj = $dispatcherObject->getConnector('otherListings', 'update', 'requester', array(), $marketplace, $account, NULL, 'Ess_M2ePro_Model_Ebay_Synchronization'); $dispatcherObject->process($connectorObj); return; } $sinceTime = $this->prepareSinceTime($sinceTime); $changes = $this->getChangesByAccount($account, $sinceTime); /** @var $updatingModel Ess_M2ePro_Model_Ebay_Listing_Other_Updating */ $updatingModel = Mage::getModel('M2ePro/Ebay_Listing_Other_Updating'); $updatingModel->initialize($account); $updatingModel->processResponseData($changes); }
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 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 getSinceTimeByAccount(Ess_M2ePro_Model_Account $account) { return $account->getData('other_listings_last_synchronization'); }
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 prepareFromTime(Ess_M2ePro_Model_Account $account) { $lastSynchronizationDate = $account->getData('orders_last_synchronization'); if (is_null($lastSynchronizationDate)) { $sinceTime = new DateTime('now', new DateTimeZone('UTC')); $sinceTime = Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($sinceTime); $this->saveLastUpdateTime($account, $sinceTime); return $sinceTime; } $sinceTime = new DateTime($lastSynchronizationDate, new DateTimeZone('UTC')); // Get min date for synch //------------------------ $minDate = new DateTime('now', new DateTimeZone('UTC')); $minDate->modify('-90 days'); //------------------------ // Prepare last date //------------------------ if ((int) $sinceTime->format('U') < (int) $minDate->format('U')) { $sinceTime = $minDate; } //------------------------ return Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($sinceTime); }
private function processAccountInventorySku(Ess_M2ePro_Model_Account $account) { $this->_profiler->addTitle('Starting account "' . $account->getData('title') . '"'); /** @var $listingOtherCollection Mage_Core_Model_Mysql4_Collection_Abstract */ $listingOtherCollection = Mage::helper('M2ePro/Component_Ebay')->getCollection('Listing_Other'); $listingOtherCollection->addFieldToFilter('`main_table`.account_id', (int) $account->getId()); $listingOtherCollection->getSelect()->where('`second_table`.`sku` IS NULL'); $listingOtherCollection->getSelect()->order('second_table.start_date ASC'); $listingOtherCollection->getSelect()->limit(200); if (!$listingOtherCollection->getSize()) { $this->_profiler->addEol(); return; } /** @var $tempListingOther Ess_M2ePro_Model_Listing_Other */ $tempListingOther = $listingOtherCollection->getFirstItem(); $sinceTime = new DateTime($tempListingOther->getData('start_date'), new DateTimeZone('UTC')); $sinceTime->modify('-5 minutes'); $sinceTime = $sinceTime->format('Y-m-d H:i:s'); $inputData = array('since_time' => $sinceTime, 'getting_inventory_part' => true, 'only_one_page' => true); $responseData = Mage::getModel('M2ePro/Connector_Server_Ebay_Dispatcher')->processVirtualAbstract('item', 'get', 'all', $inputData, NULL, NULL, $account->getId(), NULL); if (!isset($responseData['items']) || !is_array($responseData['items'])) { $this->_profiler->addEol(); return; } if (count($responseData['items']) <= 0) { foreach ($listingOtherCollection->getItems() as $listingOther) { $listingOther->getChildObject()->setData('sku', new Zend_Db_Expr("''"))->save(); } $this->_profiler->addEol(); return; } /** @var $mappingModel Ess_M2ePro_Model_Ebay_Listing_Other_Mapping */ $mappingModel = Mage::getModel('M2ePro/Ebay_Listing_Other_Mapping'); foreach ($responseData['items'] as $receivedItem) { foreach ($listingOtherCollection->getItems() as $listingOther) { /** @var $listingOther Ess_M2ePro_Model_Listing_Other */ if ((double) $listingOther->getData('item_id') != $receivedItem['id']) { continue; } if ($receivedItem['sku'] == '') { $listingOther->getChildObject()->setData('sku', new Zend_Db_Expr("''"))->save(); } else { $listingOther->getChildObject()->setData('sku', (string) $receivedItem['sku'])->save(); } if ($account->getChildObject()->isOtherListingsMappingEnabled()) { $mappingModel->initialize($account); $mappingModel->autoMapOtherListingProduct($listingOther); } break; } } $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 prepareFromTime(Ess_M2ePro_Model_Account $account) { $lastSynchronizationDate = $account->getData('orders_last_synchronization'); if (is_null($lastSynchronizationDate)) { $sinceTime = new DateTime('now', new DateTimeZone('UTC')); $sinceTime = Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($sinceTime); $this->saveLastUpdateTime($account, $sinceTime); return $sinceTime; } $sinceTime = new DateTime($lastSynchronizationDate, new DateTimeZone('UTC')); return Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($sinceTime); }