Exemplo n.º 1
0
 public function handle(Ess_M2ePro_Model_Order $order, Mage_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 = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_ebay_order/view', array('id' => $order->getId()));
     $startLink = '<a href="' . $url . '" target="_blank">';
     $endLink = '</a>';
     $message = Mage::helper('M2ePro')->__('Payment Status for eBay Order was not updated. View %sorder log%s for more details.', $startLink, $endLink);
     Mage::getSingleton('adminhtml/session')->addError($message);
 }
Exemplo n.º 3
0
 private function addSessionErrorMessage(Ess_M2ePro_Model_Order $order)
 {
     $url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_common_log/order', 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 = Mage::helper('M2ePro')->__('Cancel for Amazon Order was not performed.' . ' View <a href="%url% target="_blank" >order log</a>' . ' for more details.', $url);
     Mage::getSingleton('adminhtml/session')->addError($message);
 }
Exemplo n.º 4
0
 private function addSessionErrorMessage(Ess_M2ePro_Model_Order $order)
 {
     $url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_ebay_log/order', 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 = Mage::helper('M2ePro')->__('Payment Status for %chanel_title% Order was not updated.' . ' View <a href="%url%" target="_blank">Order Log</a> for more details.', $channelTitle, $url);
     Mage::getSingleton('adminhtml/session')->addError($message);
 }
Exemplo n.º 5
0
 private function addSessionErrorMessage(Ess_M2ePro_Model_Order $order)
 {
     if ($order->isComponentModeEbay()) {
         $url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_ebay_log/order', array('order_id' => $order->getId()));
     } else {
         $url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_common_log/order', array('order_id' => $order->getId()));
     }
     $startLink = '<a href="' . $url . '" target="_blank">';
     $endLink = '</a>';
     $channel = $order->getComponentTitle();
     $message = Mage::helper('M2ePro')->__('Shipping Status for %s Order was not updated. View %sorder log%s for more details.', $channel, $startLink, $endLink);
     Mage::getSingleton('adminhtml/session')->addError($message);
 }
Exemplo n.º 6
0
 /**
  * @param Ess_M2ePro_Model_Order          $order
  * @param Mage_Sales_Model_Order_Shipment $shipment
  *
  * @return Ess_M2ePro_Model_Order_Item[]
  */
 private function getItemsToShip(Ess_M2ePro_Model_Order $order, Mage_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'][0]['order_item_id'])) {
             continue;
         }
         $id = $additionalData[$orderItemDataIdentifier]['items'][0]['order_item_id'];
         $item = $order->getItemsCollection()->getItemByColumnValue('play_order_item_id', $id);
         if (is_null($item)) {
             continue;
         }
         $items[] = $item;
     }
     return $items;
 }
Exemplo n.º 7
0
 private function getItemsToShip(Ess_M2ePro_Model_Order $order, Mage_Sales_Model_Order_Shipment $shipment)
 {
     $productTypesNotAllowedByDefault = array(Mage_Catalog_Model_Product_Type::TYPE_BUNDLE, Mage_Catalog_Model_Product_Type::TYPE_GROUPED);
     $items = array();
     $allowedItems = array();
     foreach ($shipment->getAllItems() as $shipmentItem) {
         /** @var $shipmentItem Mage_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 = Mage::helper('M2ePro/Component_Ebay')->getCollection('Order_Item')->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.º 8
0
 public function getOrdersContainingItemsFromOrder(Ess_M2ePro_Model_Order $order)
 {
     // Prepare item_id-transaction_id pairs for sql
     // -------------
     $readConnection = $this->getReadConnection();
     $whereSql = array();
     foreach ($order->getItemsCollection()->getItems() as $orderItem) {
         $itemIdSql = $readConnection->quoteInto('?', $orderItem->getData('item_id'));
         $transactionIdSql = $readConnection->quoteInto('?', $orderItem->getData('transaction_id'));
         $whereSql[] = "(item_id = {$itemIdSql} AND transaction_id = {$transactionIdSql})";
     }
     $whereSql = implode(' OR ', $whereSql);
     // -------------
     // Find orders which contains at least one order item from current order
     // -------------
     /** @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
     $collection = Mage::helper('M2ePro/Component_Ebay')->getCollection('Order');
     $collection->getSelect()->distinct(true)->join(array('moi' => Mage::getResourceModel('M2ePro/Order_Item')->getMainTable()), '(`moi`.`order_id` = `main_table`.`id`)', array())->join(array('meoi' => Mage::getResourceModel('M2ePro/Ebay_Order_Item')->getMainTable()), '(`meoi`.`order_item_id` = `moi`.`id`)', array())->where($whereSql)->where('`main_table`.`id` != ?', $order->getId())->where('`main_table`.`account_id` = ?', $order->getAccountId())->order(array('main_table.id ASC'));
     // -------------
     return $collection->getItems();
 }
Exemplo n.º 9
0
 /**
  * @param Ess_M2ePro_Model_Order          $order
  * @param Mage_Sales_Model_Order_Shipment $shipment
  *
  * @return null|Ess_M2ePro_Model_Order_Item
  */
 private function getItemToShip(Ess_M2ePro_Model_Order $order, Mage_Sales_Model_Order_Shipment $shipment)
 {
     if ($order->isSingle()) {
         return null;
     }
     $shipmentItems = $shipment->getAllItems();
     if (count($shipmentItems) != 1) {
         return null;
     }
     /** @var $shipmentItem Mage_Sales_Model_Order_Shipment_Item */
     $shipmentItem = reset($shipmentItems);
     $additionalData = $shipmentItem->getOrderItem()->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)) {
         return null;
     }
     $item = Mage::helper('M2ePro/Component_Ebay')->getCollection('Order_Item')->addFieldToFilter('order_id', $order->getId())->addFieldToFilter('item_id', $itemId)->addFieldToFilter('transaction_id', $transactionId)->getFirstItem();
     return $item->getId() ? $item : null;
 }
Exemplo n.º 10
0
 /**
  * @param Ess_M2ePro_Model_Order          $order
  * @param Mage_Sales_Model_Order_Shipment $shipment
  *
  * @throws LogicException
  *
  * @return array
  */
 private function getItemsToShip(Ess_M2ePro_Model_Order $order, Mage_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.º 11
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.º 12
0
 private function openUnpaidItemProcess(Ess_M2ePro_Model_Order $order)
 {
     $collection = Mage::helper('M2ePro/Component_Ebay')->getCollection('Order_Item');
     $collection->addFieldToFilter('order_id', $order->getId());
     $collection->addFieldToFilter('unpaid_item_process_state', Ess_M2ePro_Model_Ebay_Order_Item::UNPAID_ITEM_PROCESS_NOT_OPENED);
     $items = $collection->getItems();
     if (count($items) == 0) {
         return;
     }
     $action = Ess_M2ePro_Model_Connector_Server_Ebay_OrderItem_Dispatcher::ACTION_ADD_DISPUTE;
     $params = array('explanation' => Ess_M2ePro_Model_Ebay_Order_Item::DISPUTE_EXPLANATION_BUYER_HAS_NOT_PAID, 'reason' => Ess_M2ePro_Model_Ebay_Order_Item::DISPUTE_REASON_BUYER_HAS_NOT_PAID);
     /** @var $dispatcher Ess_M2ePro_Model_Connector_Server_Ebay_OrderItem_Dispatcher */
     $dispatcher = Mage::getModel('M2ePro/Connector_Server_Ebay_OrderItem_Dispatcher');
     $dispatcher->process($action, $items, $params);
     $this->totalOpenedUnpaidItemProcesses += count($items);
 }
Exemplo n.º 13
0
 public function afterCreateMagentoOrder()
 {
     parent::afterCreateMagentoOrder();
     Mage::dispatchEvent('wyomind_advancedinventory_m2epro_order_place_success', array('order' => $this->getMagentoOrder()));
 }
 private function getOrderItemsForUnpaidItemProcess(Ess_M2ePro_Model_Order $order)
 {
     /** @var Ess_M2ePro_Model_Mysql4_Order_Item_Collection $collection */
     $collection = Mage::helper('M2ePro/Component_Ebay')->getCollection('Order_Item');
     $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.º 15
0
 public function __construct(array $params = array(), Ess_M2ePro_Model_Order $order, $action = NULL)
 {
     $this->order = $order;
     $this->action = $action;
     parent::__construct($params, NULL, $order->getAccount());
 }
Exemplo n.º 16
0
 /**
  * @return Ess_M2ePro_Model_Amazon_Order
  */
 public function getAmazonOrder()
 {
     return $this->order->getChildObject();
 }