public function updateOrder(ShopgateOrder $order) { $shopgateOrder = PSShopgateOrder::instanceByOrderNumber($order->getOrderNumber()); if (!Validate::isLoadedObject($shopgateOrder)) { throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_ORDER_NOT_FOUND, 'Order not found', true); } $order_states = array(); if ($order->getUpdatePayment() && $order->getIsPaid()) { array_push($order_states, $this->getOrderStateId('PS_OS_PAYMENT')); } if ($order->getUpdateShipping() && !$order->getIsShippingBlocked()) { array_push($order_states, $this->getOrderStateId('PS_OS_PREPARATION')); } if (count($order_states)) { $ps_order = new Order($shopgateOrder->id_order); foreach ($order_states as $id_order_state) { if (version_compare(_PS_VERSION_, '1.4.1.0', '<')) { $history = new OrderHistory(); $history->id_order = (int) $shopgateOrder->id_order; $history->changeIdOrderState((int) $id_order_state, (int) $shopgateOrder->id_order); } else { $ps_order->setCurrentState($id_order_state); } } } return array('external_order_id' => $shopgateOrder->id_order, 'external_order_number' => $shopgateOrder->id_order); }
/** * @param Mage_Sales_Model_Order $magentoOrder * @param ShopgateOrder $shopgateOrder * @param Shopgate_Framework_Model_Shopgate_Order $magentoShopgateOrder * * @return Mage_Sales_Model_Order */ protected function _setShopgateOrder($magentoOrder, $shopgateOrder, $magentoShopgateOrder = null) { if ($magentoShopgateOrder) { if ($shopgateOrder->getUpdatePayment()) { $magentoShopgateOrder->setIsPaid($shopgateOrder->getIsPaid()); } if ($shopgateOrder->getUpdateShipping()) { $magentoShopgateOrder->setIsShippingBlocked($shopgateOrder->getIsShippingBlocked()); } } else { $magentoShopgateOrder = Mage::getModel("shopgate/shopgate_order")->setOrderId($magentoOrder->getId())->setStoreId($this->_getConfig()->getStoreViewId())->setShopgateOrderNumber($shopgateOrder->getOrderNumber())->setIsShippingBlocked($shopgateOrder->getIsShippingBlocked())->setIsPaid($shopgateOrder->getIsPaid())->setIsTest($shopgateOrder->getIsTest())->setIsCustomerInvoiceBlocked($shopgateOrder->getIsCustomerInvoiceBlocked()); } $magentoShopgateOrder->setReceivedData(serialize($shopgateOrder)); $magentoShopgateOrder->save(); return $magentoOrder; }