Exemplo n.º 1
0
 public function handle(\Ess\M2ePro\Model\Order $order, \Magento\Sales\Model\Order\Shipment $shipment)
 {
     $trackingDetails = $this->getTrackingDetails($shipment);
     if (!$order->getChildObject()->canUpdateShippingStatus($trackingDetails)) {
         return self::HANDLE_RESULT_SKIPPED;
     }
     return $order->getChildObject()->updateShippingStatus($trackingDetails) ? self::HANDLE_RESULT_SUCCEEDED : self::HANDLE_RESULT_FAILED;
 }
Exemplo n.º 2
0
 private function addSessionErrorMessage(\Ess\M2ePro\Model\Order $order)
 {
     $url = $this->urlBuilder->getUrl('*/ebay_order_log/index', array('order_id' => $order->getId()));
     $channelTitle = $order->getComponentTitle();
     // M2ePro\TRANSLATIONS
     // Payment Status for %chanel_title% Order was not updated. View <a href="%url%" target="_blank">Order Log</a> for more details.
     $message = $this->getHelper('Module\\Translation')->__('Payment Status for %chanel_title% Order was not updated.' . ' View <a href="%url%" target="_blank">Order Log</a> for more details.', $channelTitle, $url);
     $this->messageManager->addError($message);
 }
Exemplo n.º 3
0
 public function hasCurrencyConversionRate()
 {
     $store = $this->getStore();
     if (is_null($store)) {
         return true;
     }
     return $this->modelFactory->getObject('Currency')->getConvertRateFromBase($this->order->getChildObject()->getCurrency(), $store) != 0;
 }
Exemplo n.º 4
0
 private function getItemsToShip(\Ess\M2ePro\Model\Order $order, \Magento\Sales\Model\Order\Shipment $shipment)
 {
     $productTypesNotAllowedByDefault = array(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE, \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE);
     $items = array();
     $allowedItems = array();
     foreach ($shipment->getAllItems() as $shipmentItem) {
         /** @var $shipmentItem \Magento\Sales\Model\Order\Shipment\Item */
         $orderItem = $shipmentItem->getOrderItem();
         $parentOrderItemId = $orderItem->getParentItemId();
         if (!is_null($parentOrderItemId)) {
             !in_array($parentOrderItemId, $allowedItems) && ($allowedItems[] = $parentOrderItemId);
             continue;
         }
         if (!in_array($orderItem->getProductType(), $productTypesNotAllowedByDefault)) {
             $allowedItems[] = $orderItem->getId();
         }
         $additionalData = $orderItem->getAdditionalData();
         $additionalData = is_string($additionalData) ? @unserialize($additionalData) : array();
         $itemId = $transactionId = null;
         $orderItemDataIdentifier = \Ess\M2ePro\Helper\Data::CUSTOM_IDENTIFIER;
         if (isset($additionalData['ebay_item_id']) && isset($additionalData['ebay_transaction_id'])) {
             // backward compatibility with versions 5.0.4 or less
             $itemId = $additionalData['ebay_item_id'];
             $transactionId = $additionalData['ebay_transaction_id'];
         } elseif (isset($additionalData[$orderItemDataIdentifier]['items'])) {
             if (!is_array($additionalData[$orderItemDataIdentifier]['items']) || count($additionalData[$orderItemDataIdentifier]['items']) != 1) {
                 return null;
             }
             if (isset($additionalData[$orderItemDataIdentifier]['items'][0]['item_id'])) {
                 $itemId = $additionalData[$orderItemDataIdentifier]['items'][0]['item_id'];
             }
             if (isset($additionalData[$orderItemDataIdentifier]['items'][0]['transaction_id'])) {
                 $transactionId = $additionalData[$orderItemDataIdentifier]['items'][0]['transaction_id'];
             }
         }
         if (is_null($itemId) || is_null($transactionId)) {
             continue;
         }
         $item = $this->ebayFactory->getObject('Order\\Item')->getCollection()->addFieldToFilter('order_id', $order->getId())->addFieldToFilter('item_id', $itemId)->addFieldToFilter('transaction_id', $transactionId)->getFirstItem();
         if (!$item->getId()) {
             continue;
         }
         $items[$orderItem->getId()] = $item;
     }
     $resultItems = array();
     foreach ($items as $orderItemId => $item) {
         if (!in_array($orderItemId, $allowedItems)) {
             continue;
         }
         $resultItems[] = $item;
     }
     return $resultItems;
 }
Exemplo n.º 5
0
 /**
  * @param \Ess\M2ePro\Model\Order          $order
  * @param \Magento\Sales\Model\Order\Shipment $shipment
  *
  * @throws \LogicException
  *
  * @return array
  */
 private function getItemsToShip(\Ess\M2ePro\Model\Order $order, \Magento\Sales\Model\Order\Shipment $shipment)
 {
     $shipmentItems = $shipment->getAllItems();
     $orderItemDataIdentifier = \Ess\M2ePro\Helper\Data::CUSTOM_IDENTIFIER;
     $items = array();
     foreach ($shipmentItems as $shipmentItem) {
         $additionalData = $shipmentItem->getOrderItem()->getAdditionalData();
         $additionalData = is_string($additionalData) ? @unserialize($additionalData) : array();
         if (!isset($additionalData[$orderItemDataIdentifier]['items'])) {
             continue;
         }
         if (!is_array($additionalData[$orderItemDataIdentifier]['items'])) {
             continue;
         }
         $qtyAvailable = (int) $shipmentItem->getQty();
         foreach ($additionalData[$orderItemDataIdentifier]['items'] as $data) {
             if ($qtyAvailable <= 0) {
                 continue;
             }
             if (!isset($data['order_item_id'])) {
                 continue;
             }
             $item = $order->getItemsCollection()->getItemByColumnValue('amazon_order_item_id', $data['order_item_id']);
             if (is_null($item)) {
                 continue;
             }
             $qty = $item->getChildObject()->getQtyPurchased();
             if ($qty > $qtyAvailable) {
                 $qty = $qtyAvailable;
             }
             $items[] = array('qty' => $qty, 'amazon_order_item_id' => $data['order_item_id']);
             $qtyAvailable -= $qty;
         }
     }
     return $items;
 }
Exemplo n.º 6
0
 private function changeProductQty(\Ess\M2ePro\Model\Magento\Product $magentoProduct, \Ess\M2ePro\Model\Magento\Product\StockItem $magentoStockItem, $action, $qty)
 {
     $result = true;
     switch ($action) {
         case self::ACTION_ADD:
             $magentoStockItem->addQty($qty, false);
             break;
         case self::ACTION_SUB:
             try {
                 $magentoStockItem->subtractQty($qty, false);
             } catch (\Exception $e) {
                 $result = false;
                 $this->order->addErrorLog('QTY for Product "%name%" cannot be reserved. Reason: %msg%', array('!name' => $magentoProduct->getName(), 'msg' => $e->getMessage()));
             }
             break;
     }
     return $result;
 }
Exemplo n.º 7
0
 private function getOrderItemsForUnpaidItemProcess(\Ess\M2ePro\Model\Order $order)
 {
     /** @var \Ess\M2ePro\Model\ResourceModel\Order\Item\Collection $collection */
     $collection = $this->ebayFactory->getObject('Order\\Item')->getCollection();
     $collection->addFieldToFilter('order_id', $order->getId());
     $collection->addFieldToFilter('unpaid_item_process_state', \Ess\M2ePro\Model\Ebay\Order\Item::UNPAID_ITEM_PROCESS_NOT_OPENED);
     return $collection->getItems();
 }
Exemplo n.º 8
0
 public function setOrder(\Ess\M2ePro\Model\Order $order)
 {
     $this->order = $order;
     $this->account = $order->getAccount();
     return $this;
 }
Exemplo n.º 9
0
 private function addSessionErrorMessage(\Ess\M2ePro\Model\Order $order)
 {
     $url = $this->urlBuilder->getUrl('M2ePro/adminhtml_amazon_order_log/index', array('order_id' => $order->getId()));
     // M2ePro\TRANSLATIONS
     // Cancel for Amazon Order was not performed. View <a href="%url%" target="_blank" >order log</a> for more details.
     $message = $this->getHelper('Module\\Translation')->__('Cancel for Amazon Order was not performed.' . ' View <a href="%url% target="_blank" >order log</a>' . ' for more details.', $url);
     $this->messageManager->addError($message);
 }