예제 #1
0
 protected function getResponserParams()
 {
     $params = parent::getResponserParams();
     if (!is_null($this->account)) {
         $params['account_id'] = $this->account->getId();
     }
     return $params;
 }
예제 #2
0
 private function processAccount(\Ess\M2ePro\Model\Account $account)
 {
     $collection = $this->activeRecordFactory->getObject('Ebay\\Listing\\Product\\PickupStore')->getCollection();
     $collection->addFieldToFilter('is_process_required', 1);
     $collection->getSelect()->limit(self::MAX_AFFECTED_ITEMS_COUNT);
     $pickupStoreTable = $this->activeRecordFactory->getObject('Ebay\\Account\\PickupStore')->getResource()->getMainTable();
     $collection->getSelect()->joinLeft(array('eaps' => $pickupStoreTable), 'eaps.id = main_table.account_pickup_store_id', array('account_id'));
     $collection->addFieldToFilter('eaps.account_id', $account->getId());
     $listingProductIds = $collection->getColumnValues('listing_product_id');
     if (empty($listingProductIds)) {
         return;
     }
     $listingProductIds = array_unique($listingProductIds);
     $affectedItemsCount = 0;
     foreach ($listingProductIds as $listingProductId) {
         /** @var \Ess\M2ePro\Model\Listing\Product $listingProduct */
         $listingProduct = $this->ebayFactory->getObjectLoaded('Listing\\Product', $listingProductId);
         $pickupStoreStateUpdater = $this->modelFactory->getObject('Ebay\\Listing\\Product\\PickupStore\\State\\Updater');
         $pickupStoreStateUpdater->setListingProduct($listingProduct);
         $affectedItemsCount += $pickupStoreStateUpdater->process();
         if ($affectedItemsCount >= self::MAX_AFFECTED_ITEMS_COUNT) {
             break;
         }
     }
 }
예제 #3
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Other $otherListing
  */
 protected function setAccountByOtherListingProduct(\Ess\M2ePro\Model\Listing\Other $otherListing)
 {
     if (!is_null($this->account) && $this->account->getId() == $otherListing->getAccountId()) {
         return;
     }
     $this->account = $this->amazonFactory->getCachedObjectLoaded('Account', $otherListing->getAccountId());
 }
예제 #4
0
 private function isLockedAccount(\Ess\M2ePro\Model\Account $account)
 {
     /** @var $lockItem \Ess\M2ePro\Model\LockItem */
     $lockItem = $this->activeRecordFactory->getObject('LockItem');
     $lockItem->setNick(Blocked\ProcessingRunner::LOCK_ITEM_PREFIX . '_' . $account->getId());
     $lockItem->setMaxInactiveTime(Runner::MAX_LIFETIME);
     return $lockItem->isExist();
 }
 /**
  * @param $account \Ess\M2ePro\Model\Account
  * @param $syncDate \Datetime|String
  */
 private function setLastUpdateDate(\Ess\M2ePro\Model\Account $account, $syncDate)
 {
     $accountId = $account->getId();
     /** @var $accountRepricingModel \Ess\M2ePro\Model\Amazon\Account\Repricing */
     $accountRepricingModel = $this->activeRecordFactory->getObjectLoaded('Amazon\\Account\\Repricing', $accountId);
     $accountRepricingModel->setData('last_checked_listing_product_update_date', $syncDate);
     $accountRepricingModel->save();
 }
예제 #6
0
 private function getOrdersForRelease(\Ess\M2ePro\Model\Account $account)
 {
     /** @var \Ess\M2ePro\Model\ResourceModel\Order\Collection $collection */
     $collection = $this->amazonFactory->getObject('Order')->getCollection()->addFieldToFilter('account_id', $account->getId())->addFieldToFilter('reservation_state', \Ess\M2ePro\Model\Order\Reserve::STATE_PLACED);
     $reservationDays = (int) $account->getChildObject()->getQtyReservationDays();
     $minReservationStartDate = new \DateTime($this->getHelper('Data')->getCurrentGmtDate(), new \DateTimeZone('UTC'));
     $minReservationStartDate->modify('- ' . $reservationDays . ' days');
     $minReservationStartDate = $minReservationStartDate->format('Y-m-d H:i');
     $collection->addFieldToFilter('reservation_start_date', array('lteq' => $minReservationStartDate));
     return $collection->getItems();
 }
예제 #7
0
 public function remove(Account $account, array $skus = array())
 {
     $listingProductCollection = $this->amazonFactory->getObject('Listing\\Product')->getCollection();
     $listingProductCollection->getSelect()->join(array('l' => $this->getTable('m2epro_listing')), 'l.id = main_table.listing_id', array());
     $listingProductCollection->getSelect()->where('l.account_id = ?', $account->getId());
     if (!empty($skus)) {
         $listingProductCollection->addFieldToFilter('sku', array('in' => array_unique($skus)));
     }
     $listingProductCollection->getSelect()->reset(\Zend_Db_Select::COLUMNS);
     $listingProductCollection->getSelect()->columns(array('id' => 'main_table.id'));
     $listingProductIds = $listingProductCollection->getColumnValues('id');
     if (empty($listingProductIds)) {
         return;
     }
     $this->getConnection()->delete($this->getMainTable(), array('listing_product_id IN (?)' => $listingProductIds));
 }
예제 #8
0
 private function processAccount(\Ess\M2ePro\Model\Account $account)
 {
     $collection = $this->activeRecordFactory->getObject('Ebay\\Account\\PickupStore\\State')->getCollection();
     $collection->getSelect()->where('(is_deleted = 1) OR (target_qty != online_qty)');
     $collection->addFieldToFilter('is_in_processing', 0);
     $pickupStoreTable = $this->activeRecordFactory->getObject('Ebay\\Account\\PickupStore')->getResource()->getMainTable();
     $collection->getSelect()->joinLeft(array('eaps' => $pickupStoreTable), 'eaps.id = main_table.account_pickup_store_id', array('account_id'));
     $collection->addFieldToFilter('eaps.account_id', $account->getId());
     $collection->getSelect()->limit(self::MAX_ITEMS_COUNT);
     $pickupStoreStateItems = $collection->getItems();
     if (empty($pickupStoreStateItems)) {
         return;
     }
     $dispatcher = $this->modelFactory->getObject('Ebay\\Connector\\Dispatcher');
     /** @var \Ess\M2ePro\Model\Ebay\Connector\AccountPickupStore\Synchronize\ProductsRequester $connector */
     $connector = $dispatcher->getConnector('accountPickupStore', 'synchronize', 'productsRequester', array(), NULL, $account);
     $connector->setPickupStoreStateItems($pickupStoreStateItems);
     $dispatcher->process($connector);
 }
예제 #9
0
 public function removeRepricing(Account $account, array $skus = array())
 {
     if (empty($skus)) {
         $this->getConnection()->update($this->getMainTable(), array('is_repricing' => 0, 'is_repricing_disabled' => 0));
         return;
     }
     $listingOtherCollection = $this->amazonFactory->getObject('Listing\\Other')->getCollection();
     $listingOtherCollection->addFieldToFilter('account_id', $account->getId());
     $listingOtherCollection->addFieldToFilter('is_repricing', 1);
     if (!empty($skus)) {
         $listingOtherCollection->addFieldToFilter('sku', array('in' => array_unique($skus)));
     }
     $listingOtherCollection->getSelect()->reset(\Zend_Db_Select::COLUMNS);
     $listingOtherCollection->getSelect()->columns(array('id' => 'main_table.id'));
     $listingOtherIds = $listingOtherCollection->getColumnValues('id');
     if (empty($listingOtherIds)) {
         return;
     }
     $this->getConnection()->update($this->getMainTable(), array('is_repricing' => 0, 'is_repricing_disabled' => 0), array('listing_other_id IN (?)' => $listingOtherIds));
 }
 /**
  * @param $account \Ess\M2ePro\Model\Account
  * @return \Ess\M2ePro\Model\Amazon\Listing\Product\Repricing[]
  */
 private function getProcessRequiredListingsProductsRepricing(\Ess\M2ePro\Model\Account $account)
 {
     $listingProductCollection = $this->activeRecordFactory->getObject('Listing\\Product')->getCollection();
     $listingProductCollection->getSelect()->joinLeft(array('l' => $this->resource->getTableName('m2epro_listing')), 'l.id=main_table.listing_id', array());
     $listingProductCollection->getSelect()->joinInner(array('alpr' => $this->resource->getTableName('m2epro_amazon_listing_product_repricing')), 'alpr.listing_product_id=main_table.id', array());
     $listingProductCollection->addFieldToFilter('l.account_id', $account->getId());
     $listingProductCollection->addFieldToFilter('status', array('in' => array(\Ess\M2ePro\Model\Listing\Product::STATUS_LISTED, \Ess\M2ePro\Model\Listing\Product::STATUS_UNKNOWN)));
     $listingProductCollection->addFieldToFilter('alpr.is_process_required', true);
     $listingProductCollection->getSelect()->limit(self::MAX_ITEMS_COUNT_PER_REQUEST);
     /** @var \Ess\M2ePro\Model\Listing\Product[] $listingsProducts */
     $listingsProducts = $listingProductCollection->getItems();
     if (empty($listingsProducts)) {
         return array();
     }
     $listingProductRepricingCollection = $this->activeRecordFactory->getObject('Amazon\\Listing\\Product\\Repricing')->getCollection();
     $listingProductRepricingCollection->addFieldToFilter('listing_product_id', array('in' => $listingProductCollection->getColumnValues('id')));
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Repricing[] $listingsProductsRepricing */
     $listingsProductsRepricing = $listingProductRepricingCollection->getItems();
     foreach ($listingsProductsRepricing as $listingProductRepricing) {
         $listingProductRepricing->setListingProduct($listingProductCollection->getItemById($listingProductRepricing->getListingProductId()));
     }
     return $listingsProductsRepricing;
 }
예제 #11
0
 /**
  * @param \Ess\M2ePro\Model\Account $account
  * @return \Ess\M2ePro\Model\Order\Change
  */
 private function getRelatedChanges(\Ess\M2ePro\Model\Account $account)
 {
     /** @var \Ess\M2ePro\Model\ResourceModel\Order\Change\Collection $changesCollection */
     $changesCollection = $this->activeRecordFactory->getObject('Order\\Change')->getCollection();
     $changesCollection->addAccountFilter($account->getId());
     $changesCollection->addProcessingAttemptDateFilter(10);
     $changesCollection->addFieldToFilter('component', \Ess\M2ePro\Helper\Component\Amazon::NICK);
     $changesCollection->addFieldToFilter('action', \Ess\M2ePro\Model\Order\Change::ACTION_REFUND);
     $changesCollection->getSelect()->group(array('order_id'));
     return $changesCollection->getItems();
 }
예제 #12
0
 private function executeNotProcessedActions(Account $account, $maxActionsCount = NULL)
 {
     $processingActionCollection = $this->activeRecordFactory->getObject('Ebay\\Processing\\Action')->getCollection();
     $processingActionCollection->addFieldToFilter('account_id', $account->getId());
     !is_null($maxActionsCount) && $processingActionCollection->getSelect()->limit($maxActionsCount);
     /** @var Action[] $processingActions */
     $processingActions = $processingActionCollection->getItems();
     if (empty($processingActions)) {
         return;
     }
     foreach ($processingActions as $processingAction) {
         $this->getLockItem()->activate();
         if ($this->isActionTypeSingle($processingAction->getType())) {
             $this->executeSingleAction($processingAction);
         } else {
             $this->executeMultipleAction($processingAction);
         }
     }
 }
예제 #13
0
 private function associateAndUpdateOrder(\Ess\M2ePro\Model\Account $account, array $orderData)
 {
     /** @var $order \Ess\M2ePro\Model\Order */
     $order = $this->ebayFactory->getObject('Order')->getCollection()->addFieldToFilter('account_id', $account->getId())->addFieldToFilter('ebay_order_id', $orderData['ebay_order_id'])->getFirstItem();
     if (!$order->getId()) {
         return null;
     }
     $order->setAccount($account);
     $checkoutStatus = $this->getCheckoutStatus($orderData);
     $paymentStatus = $this->getPaymentStatus($orderData);
     $shippingStatus = $this->getShippingStatus($orderData);
     if ($paymentStatus == \Ess\M2ePro\Model\Ebay\Order::PAYMENT_STATUS_COMPLETED) {
         $paymentDetails = $orderData['payment'];
         unset($paymentDetails['external_transactions']);
         $paymentDetails['method'] = $this->orderHelper->getPaymentMethodNameByCode($paymentDetails['method'], $order->getMarketplaceId());
         $order->setData('payment_details', json_encode($paymentDetails));
         $order->setData('payment_status', $paymentStatus);
     }
     if (!$order->getChildObject()->isCheckoutCompleted() && $checkoutStatus == \Ess\M2ePro\Model\Ebay\Order::CHECKOUT_STATUS_COMPLETED) {
         $shippingDetails = $orderData['shipping'];
         $shippingDetails['service'] = $this->orderHelper->getShippingServiceNameByCode($shippingDetails['service'], $order->getMarketplaceId());
         $order->setData('shipping_details', json_encode($shippingDetails));
         $order->setData('shipping_status', $shippingStatus);
         $order->setData('tax_details', json_encode($orderData['tax_details']));
     }
     $order->save();
     return $order;
 }
예제 #14
0
 function __construct(\Ess\M2ePro\Helper\Factory $helperFactory, \Ess\M2ePro\Model\Factory $modelFactory, \Ess\M2ePro\Model\Account $account, array $params)
 {
     $this->account = !is_null($account->getId()) ? $account : NULL;
     parent::__construct($helperFactory, $modelFactory, $params);
 }
예제 #15
0
 private function getRelatedChanges(\Ess\M2ePro\Model\Account $account)
 {
     /** @var \Ess\M2ePro\Model\ResourceModel\Order\Change\Collection $changesCollection */
     $changesCollection = $this->activeRecordFactory->getObject('Order\\Change')->getCollection();
     $changesCollection->addAccountFilter($account->getId());
     $changesCollection->addProcessingAttemptDateFilter();
     $changesCollection->setPageSize(self::MAX_UPDATES_PER_TIME);
     $changesCollection->getSelect()->group(array('order_id'));
     return $changesCollection->getItems();
 }
예제 #16
0
 protected function receiveFromEbay(\Ess\M2ePro\Model\Account $account, array $paramsConnector = array())
 {
     $dispatcherObj = $this->modelFactory->getObject('Ebay\\Connector\\Dispatcher');
     $connectorObj = $dispatcherObj->getVirtualConnector('feedback', 'get', 'entity', $paramsConnector, 'feedbacks', NULL, $account->getId());
     $dispatcherObj->process($connectorObj);
     $feedbacks = $connectorObj->getResponseData();
     $this->processResponseMessages($connectorObj->getResponseMessages());
     is_null($feedbacks) && ($feedbacks = array());
     $countNewFeedbacks = 0;
     foreach ($feedbacks as $feedback) {
         $dbFeedback = array('account_id' => $account->getId(), 'ebay_item_id' => $feedback['item_id'], 'ebay_transaction_id' => $feedback['transaction_id']);
         if ($feedback['item_title'] != '') {
             $dbFeedback['ebay_item_title'] = $feedback['item_title'];
         }
         if ($feedback['from_role'] == \Ess\M2ePro\Model\Ebay\Feedback::ROLE_BUYER) {
             $dbFeedback['buyer_name'] = $feedback['user_sender'];
             $dbFeedback['buyer_feedback_id'] = $feedback['id'];
             $dbFeedback['buyer_feedback_text'] = $feedback['info']['text'];
             $dbFeedback['buyer_feedback_date'] = $feedback['info']['date'];
             $dbFeedback['buyer_feedback_type'] = $feedback['info']['type'];
         } else {
             $dbFeedback['seller_feedback_id'] = $feedback['id'];
             $dbFeedback['seller_feedback_text'] = $feedback['info']['text'];
             $dbFeedback['seller_feedback_date'] = $feedback['info']['date'];
             $dbFeedback['seller_feedback_type'] = $feedback['info']['type'];
         }
         $existFeedback = $this->activeRecordFactory->getObject('Ebay\\Feedback')->getCollection()->addFieldToFilter('account_id', $account->getId())->addFieldToFilter('ebay_item_id', $feedback['item_id'])->addFieldToFilter('ebay_transaction_id', $feedback['transaction_id'])->getFirstItem();
         if (!is_null($existFeedback->getId())) {
             if ($feedback['from_role'] == \Ess\M2ePro\Model\Ebay\Feedback::ROLE_BUYER && !$existFeedback->getData('buyer_feedback_id')) {
                 $countNewFeedbacks++;
             }
             if ($feedback['from_role'] == \Ess\M2ePro\Model\Ebay\Feedback::ROLE_SELLER && !$existFeedback->getData('seller_feedback_id')) {
                 $countNewFeedbacks++;
             }
         } else {
             $countNewFeedbacks++;
         }
         $existFeedback->addData($dbFeedback)->save();
     }
     return array('total' => count($feedbacks), 'new' => $countNewFeedbacks);
 }
예제 #17
0
 public function setAccountFilter(\Ess\M2ePro\Model\Account $account)
 {
     $this->joinActionData();
     $this->addFieldToFilter('mapa.account_id', (int) $account->getId());
     return $this;
 }
예제 #18
0
 private function receiveChangesFromEbay(\Ess\M2ePro\Model\Account $account, array $paramsConnector = array())
 {
     $dispatcherObj = $this->modelFactory->getObject('Ebay\\Connector\\Dispatcher');
     $connectorObj = $dispatcherObj->getVirtualConnector('item', 'get', 'changes', $paramsConnector, NULL, NULL, $account->getId());
     $dispatcherObj->process($connectorObj);
     $this->processResponseMessages($connectorObj->getResponseMessages());
     $responseData = $connectorObj->getResponseData();
     if (!isset($responseData['items']) || !isset($responseData['to_time'])) {
         return NULL;
     }
     return $responseData;
 }
예제 #19
0
 private function getResponseBody(\Ess\M2ePro\Model\Account $account)
 {
     if ($account->getChildObject()->isFeedbacksAutoResponseCycled()) {
         $lastUsedId = 0;
         if ($account->getChildObject()->getFeedbacksLastUsedId() != null) {
             $lastUsedId = (int) $account->getChildObject()->getFeedbacksLastUsedId();
         }
         $feedbackTemplatesIds = $this->activeRecordFactory->getObject('Ebay\\Feedback\\Template')->getCollection()->addFieldToFilter('account_id', $account->getId())->setOrder('id', 'ASC')->getAllIds();
         if (!count($feedbackTemplatesIds)) {
             return '';
         }
         $feedbackTemplate = $this->activeRecordFactory->getObject('Ebay\\Feedback\\Template');
         if (max($feedbackTemplatesIds) > $lastUsedId) {
             foreach ($feedbackTemplatesIds as $templateId) {
                 if ($templateId <= $lastUsedId) {
                     continue;
                 }
                 $feedbackTemplate->load($templateId);
                 break;
             }
         } else {
             $feedbackTemplate->load(min($feedbackTemplatesIds));
         }
         if (!$feedbackTemplate->getId()) {
             return '';
         }
         $account->setData('feedbacks_last_used_id', $feedbackTemplate->getId())->save();
         return $feedbackTemplate->getBody();
     }
     if ($account->getChildObject()->isFeedbacksAutoResponseRandom()) {
         $feedbackTemplatesIds = $this->activeRecordFactory->getObject('Ebay\\Feedback\\Template')->getCollection()->addFieldToFilter('account_id', $account->getId())->getAllIds();
         if (!count($feedbackTemplatesIds)) {
             return '';
         }
         $index = rand(0, count($feedbackTemplatesIds) - 1);
         $feedbackTemplate = $this->activeRecordFactory->getObject('Ebay\\Feedback\\Template')->load($feedbackTemplatesIds[$index]);
         if (!$feedbackTemplate->getId()) {
             return '';
         }
         return $feedbackTemplate->getBody();
     }
     return '';
 }
예제 #20
0
 private function receiveSkusFromEbay(\Ess\M2ePro\Model\Account $account, $sinceTime)
 {
     $sinceTime = new \DateTime($sinceTime, new \DateTimeZone('UTC'));
     $sinceTime->modify('-1 minute');
     $sinceTime = $sinceTime->format('Y-m-d H:i:s');
     $inputData = array('since_time' => $sinceTime, 'only_one_page' => true);
     $dispatcherObj = $this->modelFactory->getObject('Ebay\\Connector\\Dispatcher');
     $connectorObj = $dispatcherObj->getVirtualConnector('item', 'get', 'all', $inputData, NULL, NULL, $account->getId());
     $dispatcherObj->process($connectorObj);
     $responseData = $connectorObj->getResponseData();
     if (!isset($responseData['items']) || !is_array($responseData['items'])) {
         return array();
     }
     return $responseData;
 }