protected function _shipOrder(Mage_Sales_Model_Order $order) { $itemQty = $order->getItemsCollection()->count(); $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty); $shipment = new Mage_Sales_Model_Order_Shipment_Api(); $shipmentId = $shipment->create($order->getIncrementId()); }
/** * Re-añade los productos comprados a carrito nuevamente * * @param Mage_Sales_Model_Order $order * @return $this */ protected function _resuscitateCartItems(Mage_Sales_Model_Order $order, Mage_Core_Controller_Front_Action $action = null) { foreach ($order->getItemsCollection() as $orderItem) { try { $this->getCart()->addOrderItem($orderItem); } catch (Mage_Core_Exception $e) { /** @var Mage_Checkout_Model_Session $session */ $session = Mage::getSingleton('checkout/session'); if ($session->getUseNotice(true)) { $session->addNotice($e->getMessage()); } else { $session->addError($e->getMessage()); } if ($action) { $action->setRedirectWithCookieCheck('checkout/cart'); } } catch (Exception $e) { /** @var Mage_Checkout_Model_Session $session */ $session = Mage::getSingleton('checkout/session'); $session->addNotice($e->getMessage()); $session->addException($e, Mage::helper('checkout')->__('Cannot add the item to shopping cart.')); if ($action) { $action->setRedirectWithCookieCheck('checkout/cart'); } } } $this->getCart()->save(); return $this; }
/** * Re-añade los productos comprados a carrito nuevamente * * @param Mage_Sales_Model_Order $order * @return $this */ protected function _resuscitateCartItems(Mage_Sales_Model_Order $order) { foreach ($order->getItemsCollection() as $orderItem) { $this->getCart()->addOrderItem($orderItem); } $this->getCart()->save(); return $this; }
public function getNetWeight(Mage_Sales_Model_Order $order) { $netWeight = 0; foreach ($order->getItemsCollection() as $item) { $productNetWeight = $item->getProduct()->getData($this->getNetWeightAttributeCode()); $netWeight += $productNetWeight * $item->getQtyOrdered(); } return $netWeight; }
/** * Returns the total quantity of ordered items of the given order. * * @param Mage_Sales_Model_Order $order The order to return info from * @return int The total quantity of ordered items */ function getTotalQtyItemsOrdered($order) { $qty = 0; $orderedItems = $order->getItemsCollection(); foreach ($orderedItems as $item) { if (!$item->isDummy()) { $qty += (int) $item->getQtyOrdered(); } } return $qty; }
/** * @return array quantity of each item to be returned */ protected function _refundLineItems() { $data = []; $qtys = $this->_clearReturnQtys(); if ($this->_payload->isReturn()) { $items = $this->_order->getItemsCollection(); foreach ($this->_payload->getOrderItems() as $orderItem) { $qtys = $this->_appendToQtyArray($orderItem, $items, $qtys); } } $data['qtys'] = $qtys; return $data; }
/** * When getting items for an address, only items that should be included * in the order create request should be returned. */ public function testGetItemsForAddressFiltering() { // Create an item that is exptected to be excluded from the OCR and // an items that should be included. $excludedItem = Mage::getModel('sales/order_item', ['order_address_id' => $this->_shipAddressId]); $includedItem = Mage::getModel('sales/order_item', ['order_address_id' => $this->_shipAddressId]); $this->_order->addItem($excludedItem)->addItem($includedItem); // Stubs $api = $this->_httpApi; $config = $this->getModelMock('eb2ccore/config_registry'); $payload = $this->getMock('\\eBayEnterprise\\RetailOrderManagement\\Payload\\Order\\IOrderCreateRequest'); $constructorArgs = ['api' => $api, 'config' => $config, 'order' => $this->_order, 'payload' => $payload, 'item_selection' => $this->_itemSelection]; $create = Mage::getModel('ebayenterprise_order/create', $constructorArgs); // Mock the item selection helper such that if given the array of items // that belong to the address - excluded and included items - that only // the items that should be included are returned. $this->_itemSelection->expects($this->any())->method('selectFrom')->with($this->identicalTo([$excludedItem, $includedItem]))->will($this->returnValue([$includedItem])); $itemsForAddress = EcomDev_Utils_Reflection::invokeRestrictedMethod($create, '_getItemsForAddress', [$this->_shipAddress, $this->_order->getItemsCollection()]); $this->assertCount(1, $itemsForAddress); $this->assertSame($includedItem, $itemsForAddress[0]); }
protected function _getOrderItemQtys(SimpleXMLElement $xmlItems, Mage_Sales_Model_Order $order) { $shipAll = !count((array) $xmlItems); /* @var $items Mage_Sales_Model_Mysql4_Order_Item_Collection */ $items = $order->getItemsCollection(); $qtys = array(); $childs = array(); /* @var $item Mage_Sales_Model_Order_Item */ foreach ($items as $item) { /* collect all items qtys if shipall flag is true */ if ($shipAll) { if ($item->getParentItemId()) { $qtys[$item->getParentItemId()] = $item->getQtyOrdered(); } else { $qtys[$item->getId()] = $item->getQtyOrdered(); } continue; } // search for item by SKU @(list($xmlItem) = $xmlItems->xpath(sprintf('//Item/SKU[text()="%s"]/..', addslashes($item->getSku())))); if ($xmlItem) { // store quantity by order item ID, not by SKU $qtys[$item->getId()] = (double) $xmlItem->Quantity; } } //Add child products into the shipments $intImportChildProducts = Mage::getStoreConfig('auctaneapi/general/import_child_products'); if ($intImportChildProducts == 2) { $orderItems = $order->getAllItems(); foreach ($orderItems as $objItem) { if ($objItem->getParentItemId()) { //set parent item if not set if (!$objItem->getParentItem()) { $objItem->setParentItem(Mage::getModel('sales/order_item')->load($objItem->getParentItemId())); } if ($objItem->getParentItem()) { //check for the bundle product type if ($objItem->getParentItem()->getProductType() === 'bundle') { $qtys[$objItem->getItemId()] = $qtys[$objItem->getParentItemId()]; } } } } } return $qtys; }
/** * refill cart * * @param Mage_Sales_Model_Order $order * * @return void */ public function refillCart($order) { // add items $cart = Mage::getSingleton('checkout/cart'); foreach ($order->getItemsCollection() as $item) { try { $cart->addOrderItem($item); } catch (Exception $e) { Mage::log($e->getMessage()); } } $cart->save(); // add coupon code $coupon = $order->getCouponCode(); $session = Mage::getSingleton('checkout/session'); if (false == is_null($coupon)) { $session->getQuote()->setCouponCode($coupon)->save(); } }
/** * Add ship groups to the request. For each address in the order, dispatch * an event for handling ship group destinations. For each ship group * destination added, trigger additional events for each item in the ship * group. * * @param Mage_Sales_Model_Order * @param IOrderCreateRequest * @return self */ protected function _setShipGroups(Mage_Sales_Model_Order $order, IOrderCreateRequest $request) { $shipGroups = $request->getShipGroups(); $orderItems = $request->getOrderItems(); $destinations = $request->getDestinations(); $itemCollection = $order->getItemsCollection(); foreach ($order->getAddressesCollection() as $address) { $items = $this->_getItemsForAddress($address, $itemCollection); if ($items) { $shipGroups->offsetSet($this->_buildShipGroupForAddress($address, $items, $order, $shipGroups, $destinations, $orderItems)); } } return $this; }
/** * @param Mage_Sales_Model_Order $order * * @return array */ public function buildPlanItemsForSubscription($order) { $list = []; $orderItems = $order->getItemsCollection(); $orderSubtotal = $order->getQuote()->getSubtotal(); $orderDiscount = $order->getDiscountAmount() * -1; $discount = null; if (!empty($orderDiscount)) { $discountPercentage = $orderDiscount * 100 / $orderSubtotal; $discountPercentage = number_format(floor($discountPercentage * 100) / 100, 2); $discount = [['discount_type' => 'percentage', 'percentage' => $discountPercentage]]; } foreach ($orderItems as $item) { $product = Mage::getModel('catalog/product')->load($item->getProductId()); if ($product->getTypeID() !== 'subscription') { Mage::throwException("O produto {$item->getName()} não é uma assinatura."); return false; } $productVindiId = $this->findOrCreateProduct(array('sku' => $item->getSku(), 'name' => $item->getName())); for ($i = 1; $i <= $item->getQtyOrdered(); $i++) { $list[] = ['product_id' => $productVindiId, 'pricing_schema' => ['price' => $item->getPrice()], 'discounts' => $discount]; } } // Create product for shipping $productVindiId = $this->findOrCreateProduct(array('sku' => 'frete', 'name' => 'Frete')); $list[] = ['product_id' => $productVindiId, 'pricing_schema' => ['price' => $order->getShippingAmount()]]; return $list; }
/** * Initialize creation data from existing order * * @param Mage_Sales_Model_Order $order * @return unknown */ public function initFromOrder(Mage_Sales_Model_Order $order) { if (!$order->getReordered()) { $this->getSession()->setOrderId($order->getId()); } else { $this->getSession()->setReordered($order->getId()); } /** * Check if we edit quest order */ $this->getSession()->setCurrencyId($order->getOrderCurrencyCode()); if ($order->getCustomerId()) { $this->getSession()->setCustomerId($order->getCustomerId()); } else { $this->getSession()->setCustomerId(false); } $this->getSession()->setStoreId($order->getStoreId()); $this->getSession()->getStore(); //need for initializing store foreach ($order->getItemsCollection(Mage::helper('sarp')->getAllSubscriptionTypes(), true) as $orderItem) { /* @var $orderItem Mage_Sales_Model_Order_Item */ if (!$this->hasSubscriptionOptions($orderItem)) { continue; } if (is_array($this->getItemIdFilter()) && sizeof($this->getItemIdFilter())) { // If itemId filter is set - ignore not matching entries if (array_search($orderItem->getId(), $this->getItemIdFilter()) === false) { continue; } } if (!$orderItem->getParentItem()) { if ($order->getReordered()) { $qty = $orderItem->getQtyOrdered(); } else { $qty = $orderItem->getQtyOrdered() - $orderItem->getQtyShipped() - $orderItem->getQtyInvoiced(); } if ($qty > 0) { $item = $this->initFromOrderItem($orderItem, $qty); if (is_string($item)) { Mage::throwException($item); } } } } $this->_initBillingAddressFromOrder($order); $this->_initShippingAddressFromOrder($order); $this->setShippingMethod($order->getShippingMethod()); $this->getQuote()->getShippingAddress()->setShippingDescription($order->getShippingDescription()); $this->getQuote()->getBillingAddress()->setShippingDescription($order->getShippingDescription()); $this->getQuote()->getPayment()->addData($order->getPayment()->getData()); if ($order->getPayment()->getData('method') == 'ccsave') { $this->getQuote()->getPayment()->setAdditionalInformation('useccv', false); } $orderCouponCode = $order->getCouponCode(); if ($orderCouponCode) { $this->getQuote()->setCouponCode($orderCouponCode); } if ($this->getQuote()->getCouponCode()) { //$this->getQuote()->collectTotals(); } Mage::helper('core')->copyFieldset('sales_copy_order', 'to_edit', $order, $this->getQuote()); Mage::dispatchEvent('sales_convert_order_to_quote', array('order' => $order, 'quote' => $this->getQuote())); if (!$order->getCustomerId()) { $this->getQuote()->setCustomerIsGuest(true); } if ($this->getSession()->getUseOldShippingMethod(true)) { /* * if we are making reorder or editing old order * we need to show old shipping as preselected * so for this we need to collect shipping rates */ $this->collectShippingRates(); } else { /* * if we are creating new order then we don't need to collect * shipping rates before customer hit appropriate button */ $this->collectRates(); } $this->saveQuote(); // Make collect rates when user click "Get shipping methods and rates" in order creating // $this->getQuote()->getShippingAddress()->setCollectShippingRates(true); // $this->getQuote()->getShippingAddress()->collectShippingRates(); /** Check stock */ foreach ($this->getQuote()->getItemsCollection() as $item) { $this->checkQuoteItemQty($item); if ($item->getProduct()->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) { $item->setMessage(Mage::helper('adminhtml')->__('This product is currently disabled')); $item->setHasError(true); } if ($item->getHasError()) { throw new AW_Sarp_Exception($item->getMessage()); } } return $this; }
/** * Remove ids and foreign keys between order objects that failed to be * saved. * * @param Mage_Sales_Model_Order * @return self */ protected function _cleanupFailedOrder(Mage_Sales_Model_Order $order) { if (!$this->getCustomerSession()->isLoggedIn()) { // reset customer ID's on exception, because customer not saved $this->_quote->getCustomer()->setId(null); } //reset order id's on exception, because order not saved $order->setId(null); /** @var $item Mage_Sales_Model_Order_Item */ foreach ($order->getItemsCollection() as $item) { $item->setOrderId(null)->setItemId(null)->setOrderAddressId(null); } return $this; }
/** * Get all virtual gift card items from the collection of items in the * Magento order. * * @param Mage_Sales_Model_Order * @return Mage_Sales_Model_Order_Item[] */ protected function getOrderedVirtualGiftCards(Mage_Sales_Model_Order $order) { $virtualGiftCards = []; foreach ($order->getItemsCollection() as $item) { if ($item->getProductType() === 'giftcard' && $item->getIsVirtual()) { $virtualGiftCards[] = $item; } } return $virtualGiftCards; }
/** * refill cart * * @param Mage_Sales_Model_Order $order * * @return void */ public function refillCart($order) { // add items $cart = Mage::getSingleton('checkout/cart'); if (0 < $cart->getQuote()->getItemsCollection()->count()) { //cart is not empty, so refilling it is not required return; } foreach ($order->getItemsCollection() as $item) { try { $cart->addOrderItem($item); } catch (Exception $e) { Mage::logException($e); } } $cart->save(); // add coupon code $coupon = $order->getCouponCode(); $session = Mage::getSingleton('checkout/session'); if (false == is_null($coupon)) { $session->getQuote()->setCouponCode($coupon)->save(); } }
/** * @param Mage_Sales_Model_Order $order * @return string */ public function restoreCardWithOrder($order) { $this->clearCart(); /** @var Mage_Checkout_Model_Cart $cart */ $cart = Mage::getSingleton('checkout/cart'); $items = $order->getItemsCollection(); if ($items) { foreach ($items as $item) { try { $cart->addOrderItem($item); } catch (Exception $e) { $this->getLogger()->logError('Could not restore item in order: ' . $e->getMessage()); } } } $cart->save(); $this->getLogger()->logInfo('Restored order ' . $order->getId() . ' to cart'); }
/** * @param Mage_Sales_Model_Order $order * @param int $customerId * * @return bool */ protected function createSubscription($order, $customerId) { $orderItems = $order->getItemsCollection(); $item = $orderItems->getFirstItem(); $product = Mage::getModel('catalog/product')->load($item->getProductId()); $plan = $product->getData('vindi_subscription_plan'); $productItems = $this->api()->buildPlanItemsForSubscription($order); if (!$productItems) { return false; } $body = ['customer_id' => $customerId, 'payment_method_code' => $this->getPaymentMethodCode(), 'plan_id' => $plan, 'code' => 'mag-' . $order->getIncrementId() . '-' . time(), 'product_items' => $productItems]; $subscription = $this->api()->createSubscription($body); if (!isset($subscription['id']) || empty($subscription['id'])) { $message = sprintf('Pagamento Falhou. (%s)', $this->api()->lastError); $this->log(sprintf('Erro no pagamento do pedido %s.\\n%s', $order->getId(), $message)); Mage::throwException($message); // TODO update order status? return false; } $order->setVindiSubscriptionId($subscription['id']); $order->setVindiSubscriptionPeriod(1); $order->save(); return $subscription; }
* Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Magento * @package Mage_Sales * @subpackage integration_tests * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $addressData = array('region' => 'CA', 'postcode' => '11111', 'street' => 'street', 'city' => 'Los Angeles', 'telephone' => '11111111', 'country_id' => 'US'); $billingAddress = new Mage_Sales_Model_Order_Address($addressData); $shippingAddress = clone $billingAddress; $item = new Mage_Sales_Model_Order_Item(); $item->setOriginalPrice(100)->setPrice(100)->setQtyOrdered(1)->setRowTotal(100)->setSubtotal(100); $payment = new Mage_Sales_Model_Order_Payment(); $payment->setMethod('checkmo'); $order = new Mage_Sales_Model_Order(); $order->setBaseSubtotal(100)->setSubtotal(100)->setBaseGrandTotal(100)->setGrandTotal(100)->setTotalPaid(100)->setCustomerIsGuest(true)->setState(Mage_Sales_Model_Order::STATE_NEW, true)->setStoreId(Mage::app()->getStore()->getId()); for ($i = 1; $i <= 100000; $i++) { $billingAddress->setId(null)->setFirstname("Name {$i}")->setLastname("Lastname {$i}")->setEmail("customer{$i}@example.com"); $shippingAddress->setId(null)->setFirstname("Name {$i}")->setLastname("Lastname {$i}")->setEmail("customer{$i}@example.com"); $item->setId(null)->setSku("item{$i}"); $payment->setId(null); $order->setId(null); $order->getItemsCollection()->removeAllItems(); $order->getAddressesCollection()->removeAllItems(); $order->getPaymentsCollection()->removeAllItems(); $order->setIncrementId((string) (10000000 + $i))->setCreatedAt(date('Y-m-d H:i:s'))->setCustomerEmail("customer{$i}@example.com")->setBillingAddress($billingAddress)->setShippingAddress($shippingAddress)->addItem($item)->setPayment($payment); $order->save(); }
/** * Gets the total discount from $order * inkl. and excl. tax * Data is returned as a Varien_Object with these data-keys set: * - discount_incl_tax * - discount_excl_tax * * @param Mage_Sales_Model_Order $order * * @return Varien_Object */ public function getOrderDiscountData(Mage_Sales_Model_Order $order) { // if catalog-prices includes tax $CatPriceIncl = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $order->getStore()); $discountIncl = 0; $discountExcl = 0; // find discount on the items foreach ($order->getItemsCollection() as $item) { /** @var Mage_Sales_Model_Quote_Item $item */ if (!$CatPriceIncl) { $discountExcl += $item->getDiscountAmount(); $discountIncl += $item->getDiscountAmount() * ($item->getTaxPercent() / 100 + 1); } else { $discountExcl += $item->getDiscountAmount() / ($item->getTaxPercent() / 100 + 1); $discountIncl += $item->getDiscountAmount(); } } // find out tax-rate for the shipping if ((double) $order->getShippingInclTax() && (double) $order->getShippingAmount()) { $shippingTaxRate = $order->getShippingInclTax() / $order->getShippingAmount(); } else { $shippingTaxRate = 1; } // get discount amount for shipping $shippingDiscount = (double) $order->getShippingDiscountAmount(); // apply/remove tax to shipping-discount if (!$CatPriceIncl) { $discountIncl += $shippingDiscount * $shippingTaxRate; $discountExcl += $shippingDiscount; } else { $discountIncl += $shippingDiscount; $discountExcl += $shippingDiscount / $shippingTaxRate; } $return = new Varien_Object(); return $return->setDiscountInclTax($discountIncl)->setDiscountExclTax($discountExcl); }
/** * Enter description here... * * @param Mage_Sales_Model_Order $order * @return Mage_Sales_Model_Quote */ public function createFromOrder(Mage_Sales_Model_Order $order) { $this->setStoreId($order->getStoreId()); $this->setBillingAddress(Mage::getModel('sales/quote_address')->importOrderAddress($order->getBillingAddress())); $this->setShippingAddress(Mage::getModel('sales/quote_address')->importOrderAddress($order->getShippingAddress())); foreach ($order->getItemsCollection() as $item) { if ($item->getQtyToShip() > 0) { $this->addItem(Mage::getModel('sales/quote_item')->importOrderItem($item)); } } $this->getShippingAddress()->setCollectShippingRates(true); $this->getShippingAddress()->setShippingMethod($order->getShippingMethod()); $this->getPayment()->importOrderPayment($order->getPayment()); $this->setCouponCode($order->getCouponeCode()); return $this; }
/** * Initialize creation data from existing order * * @param Mage_Sales_Model_Order $order * @return unknown */ public function initFromOrder(Mage_Sales_Model_Order $order) { if (!$order->getReordered()) { $this->getSession()->setOrderId($order->getId()); } else { $this->getSession()->setReordered($order->getId()); } /** * Check if we edit quest order */ $this->getSession()->setCurrencyId($order->getOrderCurrencyCode()); if ($order->getCustomerId()) { $this->getSession()->setCustomerId($order->getCustomerId()); } else { $this->getSession()->setCustomerId(false); } $this->getSession()->setStoreId($order->getStoreId()); /** * Initialize catalog rule data with new session values */ $this->initRuleData(); foreach ($order->getItemsCollection(array_keys(Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()), true) as $orderItem) { /* @var $orderItem Mage_Sales_Model_Order_Item */ if (!$orderItem->getParentItem()) { if ($order->getReordered()) { $qty = $orderItem->getQtyOrdered(); } else { $qty = $orderItem->getQtyOrdered() - $orderItem->getQtyShipped() - $orderItem->getQtyInvoiced(); } if ($qty > 0) { $item = $this->initFromOrderItem($orderItem, $qty); if (is_string($item)) { Mage::throwException($item); } } } } $shippingAddress = $order->getShippingAddress(); if ($shippingAddress) { $addressDiff = array_diff_assoc($shippingAddress->getData(), $order->getBillingAddress()->getData()); unset($addressDiff['address_type'], $addressDiff['entity_id']); $shippingAddress->setSameAsBilling(empty($addressDiff)); } $this->_initBillingAddressFromOrder($order); $this->_initShippingAddressFromOrder($order); if (!$this->getQuote()->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) { $this->setShippingAsBilling(1); } $this->setShippingMethod($order->getShippingMethod()); $this->getQuote()->getShippingAddress()->setShippingDescription($order->getShippingDescription()); $this->getQuote()->getPayment()->addData($order->getPayment()->getData()); $orderCouponCode = $order->getCouponCode(); if ($orderCouponCode) { $this->getQuote()->setCouponCode($orderCouponCode); } if ($this->getQuote()->getCouponCode()) { $this->getQuote()->collectTotals(); } Mage::helper('core')->copyFieldset('sales_copy_order', 'to_edit', $order, $this->getQuote()); Mage::dispatchEvent('sales_convert_order_to_quote', array('order' => $order, 'quote' => $this->getQuote())); if (!$order->getCustomerId()) { $this->getQuote()->setCustomerIsGuest(true); } if ($this->getSession()->getUseOldShippingMethod(true)) { /* * if we are making reorder or editing old order * we need to show old shipping as preselected * so for this we need to collect shipping rates */ $this->collectShippingRates(); } else { /* * if we are creating new order then we don't need to collect * shipping rates before customer hit appropriate button */ $this->collectRates(); } // Make collect rates when user click "Get shipping methods and rates" in order creating // $this->getQuote()->getShippingAddress()->setCollectShippingRates(true); // $this->getQuote()->getShippingAddress()->collectShippingRates(); $this->getQuote()->save(); return $this; }
protected function _getOrderItemQtys(SimpleXMLElement $xmlItems, Mage_Sales_Model_Order $order) { $shipAll = !count((array) $xmlItems); /* @var $items Mage_Sales_Model_Mysql4_Order_Item_Collection */ $items = $order->getItemsCollection(); $qtys = array(); /* @var $item Mage_Sales_Model_Order_Item */ foreach ($items as $item) { /* collect all items qtys if shipall flag is true */ if ($shipAll) { if ($item->getParentItemId()) { $qtys[$item->getParentItemId()] = $item->getQtyOrdered(); } else { $qtys[$item->getId()] = $item->getQtyOrdered(); } continue; } // search for item by SKU @(list($xmlItem) = $xmlItems->xpath(sprintf('//Item/SKU[text()="%s"]/..', addslashes($item->getSku())))); if ($xmlItem) { // store quantity by order item ID, not by SKU $qtys[$item->getId()] = (double) $xmlItem->Quantity; } } return $qtys; }
/** * Taking a 'sales/order' instance and an instance of 'OrderEvents\IOrderShipped' as parameters and then adding * the shipment and tracking information to the 'sales/order' instance. Reconcile any discrepancies * by validating the expected shipment data is indeed in the Magento order; otherwise, log the * discrepancies. * @param Mage_Sales_Model_Order $order * @param OrderEvents\IOrderShipped $payload * @return self */ public function process(Mage_Sales_Model_Order $order, OrderEvents\IOrderShipped $payload) { $orderItems = $payload->getOrderItems(); $qtys = $this->_buildShipmentQtys($orderItems, $order->getItemsCollection()); if (!empty($qtys)) { $incrementId = $order->getIncrementId(); $shipmentId = $this->_getNewShipmentIncrementId($order); $shipment = $this->_addShipmentToOrder($qtys, $order)->setData('increment_id', $shipmentId); $this->_addTrackingToShipment($orderItems, $shipment)->_registerShipment($shipment, $incrementId)->_saveShipment($shipment, $incrementId)->_reconcileShipment($orderItems, $shipmentId, $incrementId); } return $this; }
protected function _getOrderProductIds(Mage_Sales_Model_Order $order) { return $order->getItemsCollection()->getColumnValues('product_id'); }