Exemple #1
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;
         }
     }
 }
Exemple #2
0
 protected function getResponserParams()
 {
     $params = parent::getResponserParams();
     if (!is_null($this->account)) {
         $params['account_id'] = $this->account->getId();
     }
     return $params;
 }
 /**
  * @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();
 }
Exemple #4
0
 public function getManagementUrl(Account $account)
 {
     /** @var AmazonAccount $amazonAccount */
     $amazonAccount = $account->getChildObject();
     if (!$amazonAccount->isRepricing()) {
         return false;
     }
     return $this->getBaseUrl() . self::COMMAND_GOTO_SERVICE . '?' . http_build_query(array('account_token' => $amazonAccount->getRepricing()->getToken()));
 }
Exemple #5
0
 protected function buildRequestInstance()
 {
     $request = parent::buildRequestInstance();
     $requestData = $request->getData();
     if (!is_null($this->account)) {
         $requestData['account'] = $this->account->getChildObject()->getServerHash();
     }
     $request->setData($requestData);
     return $request;
 }
 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();
 }
Exemple #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));
 }
Exemple #8
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());
 }
Exemple #9
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);
 }
Exemple #10
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));
 }
Exemple #11
0
 private function getLicenseMessage(\Ess\M2ePro\Model\Account $account)
 {
     try {
         $dispatcherObject = $this->modelFactory->getObject('Connector\\Dispatcher');
         $connectorObj = $dispatcherObject->getVirtualConnector('account', 'get', 'info', array('account' => $account->getChildObject()->getServerHash(), 'channel' => \Ess\M2ePro\Helper\Component\Amazon::NICK));
         $dispatcherObject->process($connectorObj);
         $response = $connectorObj->getResponseData();
     } catch (\Exception $e) {
         return '';
     }
     if (!isset($response['info']['status']) || empty($response['info']['note'])) {
         return '';
     }
     $status = (bool) $response['info']['status'];
     $note = $response['info']['note'];
     if ($status) {
         return 'MagentoMessageObj.addNotice(\'' . $note . '\');';
     }
     $errorMessage = $this->__('Work with this Account is currently unavailable for the following reason: <br/> %error_message%', array('error_message' => $note));
     return 'MagentoMessageObj.addError(\'' . $errorMessage . '\');';
 }
 /**
  * @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;
 }
Exemple #13
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);
         }
     }
 }
Exemple #14
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();
 }
Exemple #15
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);
 }
Exemple #16
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();
 }
Exemple #17
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;
 }
Exemple #18
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 '';
 }
Exemple #19
0
 private function isLockedAccount(\Ess\M2ePro\Model\Account $account)
 {
     /** @var $lockItem \Ess\M2ePro\Model\LockItem */
     $lockItem = $this->activeRecordFactory->getObject('LockItem');
     $lockItem->setNick(Update\ProcessingRunner::LOCK_ITEM_PREFIX . '_' . $account->getId());
     $lockItem->setMaxInactiveTime(Runner::MAX_LIFETIME);
     return $lockItem->isExist();
 }
Exemple #20
0
 private function saveLastUpdateTime(\Ess\M2ePro\Model\Account $account, $lastUpdateTime)
 {
     /** @var \Ess\M2ePro\Model\Ebay\Account $ebayAccount */
     $ebayAccount = $account->getChildObject();
     $ebayAccount->setData('orders_last_synchronization', $lastUpdateTime)->save();
 }
Exemple #21
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;
 }
 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;
 }
Exemple #23
0
 private function processAccount(\Ess\M2ePro\Model\Account $account)
 {
     $fromDate = $this->prepareFromDate($account->getChildObject()->getData('orders_last_synchronization'));
     $toDate = $this->prepareToDate();
     if (strtotime($fromDate) >= strtotime($toDate)) {
         $fromDate = new \DateTime($toDate, new \DateTimeZone('UTC'));
         $fromDate->modify('- 5 minutes');
         $fromDate = $fromDate->format('Y-m-d H:i:s');
     }
     $params = array('from_date' => $fromDate, 'to_date' => $toDate);
     /** @var \Ess\M2ePro\Model\Amazon\Account $amazonAccount */
     $amazonAccount = $account->getChildObject();
     if (is_null($amazonAccount->getData('orders_last_synchronization'))) {
         $amazonAccount->setData('orders_last_synchronization', $fromDate)->save();
     }
     $dispatcherObject = $this->modelFactory->getObject('Amazon\\Connector\\Dispatcher');
     $connectorObj = $dispatcherObject->getCustomConnector('Amazon\\Synchronization\\Orders\\Receive\\Requester', $params, $account);
     $dispatcherObject->process($connectorObj);
 }
Exemple #24
0
 public function setAccountFilter(\Ess\M2ePro\Model\Account $account)
 {
     $this->joinActionData();
     $this->addFieldToFilter('mapa.account_id', (int) $account->getId());
     return $this;
 }
Exemple #25
0
 private function isFullItemsDataAlreadyReceived(\Ess\M2ePro\Model\Account $account)
 {
     $additionalData = (array) json_decode($account->getAdditionalData(), true);
     return !empty($additionalData['is_amazon_other_listings_full_items_data_already_received']);
 }
Exemple #26
0
 private function isLockedAccountInterval(\Ess\M2ePro\Model\Account $account)
 {
     if ($this->getInitiator() == \Ess\M2ePro\Helper\Data::INITIATOR_USER || $this->getInitiator() == \Ess\M2ePro\Helper\Data::INITIATOR_DEVELOPER) {
         return false;
     }
     $additionalData = json_decode($account->getAdditionalData(), true);
     if (!empty($additionalData['last_other_listing_products_synchronization'])) {
         return strtotime($additionalData['last_other_listing_products_synchronization']) + 86400 > $this->getHelper('Data')->getCurrentGmtDate(true);
     }
     return false;
 }