/** * @return array */ protected function _prepareOrderAddresses() { /** @var Mage_Sales_Model_Order_Address[] $addresses */ $addresses = $this->_order->getAddressesCollection(); $data = array(); if ($addresses) { foreach ($addresses as $address) { $address_data = array_filter(array('store_address_id' => $address->getCustomerAddressId(), 'type' => $address->getAddressType(), 'title' => '', 'prefix' => $address->getPrefix(), 'suffix' => $address->getSuffix(), 'first_name' => $address->getFirstname(), 'middle_name' => $address->getMiddlename(), 'last_name' => $address->getLastname(), 'company_name' => $address->getCompany(), 'street_address_1' => $address->getStreet1(), 'street_address_2' => $address->getStreet2(), 'street_address_3' => $address->getStreet3(), 'street_address_4' => $address->getStreet4(), 'city' => $address->getCity(), 'country_code' => $address->getCountry(), 'state' => '', 'region' => $address->getRegion(), 'region_code' => $address->getRegionCode(), 'zip_code' => $address->getPostcode(), 'telephone1' => $address->getTelephone(), 'telephone2' => '', 'telephone3' => '', 'fax' => $address->getFax(), 'vat_number' => $address->getData('vat_id'))); $data[] = $address_data; unset($address); } } return $data; }
/** * After save order billing address process * * @param Mage_Sales_Model_Order $object * @return Mage_Sales_Model_Entity_Order_Attribute_Backend_Billing */ public function afterSave($object) { $billingAddressId = false; foreach ($object->getAddressesCollection() as $address) { /* @var $address Mage_Sales_Model_Order_Address */ if ('billing' == $address->getAddressType()) { $billingAddressId = $address->getId(); } } if ($billingAddressId) { $object->setBillingAddressId($billingAddressId); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getAttributeCode()); } return $this; }
/** * Creates new customer from order, adds order addresses as customer addresses * * @param Mage_Sales_Model_Order|bool $order * @return Mage_Customer_Model_Customer */ protected function _createCustomerFromOrder($order) { if (!$order instanceof Mage_Sales_Model_Order) { return false; } // Check if customer with email address exists $existingCustomer = Mage::getResourceModel('customer/customer_collection')->addFieldToFilter('email', $order->getCustomerEmail()); if (Mage::getSingleton('customer/config_share')->isWebsiteScope()) { $existingCustomer->addFieldToFilter('website_id', $order->getWebsiteId()); } $existingCustomer = $existingCustomer->getFirstItem(); if (!$existingCustomer instanceof Mage_Customer_Model_Customer || !$existingCustomer->getId()) { return Mage::getModel('customer/customer'); } // Create customer /** @var Mage_Customer_Model_Customer $customer */ $customer = Mage::getModel('customer/customer')->setEmail($order->getCustomerEmail())->setStoreId($order->getStoreId())->setPrefix($order->getCustomerPrefix())->setFirstname($order->getCustomerFirstname())->setLastname($order->getCustomerLastname()); $customer->save(); // Create customer addresses foreach ($order->getAddressesCollection() as $orderAddress) { /** @var Mage_Sales_Model_Order_Address $orderAddress */ /** @var Mage_Customer_Model_Address $address */ $address = Mage::getModel('customer/address')->setParentId($customer->getEntityId())->setCustomerId($customer->getEntityId())->setIsActive(true)->setPrefix($orderAddress->getPrefix())->setFirstname($orderAddress->getFirstname())->setMiddlename($orderAddress->getMiddlename())->setLastname($orderAddress->getLastname())->setSuffix($orderAddress->getSuffix())->setStreet($orderAddress->getStreet())->setCity($orderAddress->getCity())->setPostcode($orderAddress->getPostcode())->setCountryId($orderAddress->getCountryId())->setTelephone($orderAddress->getTelephone())->setCompany($orderAddress->getCompany())->setRegion($orderAddress->getRegion())->setRegionId($orderAddress->getRegionId()); $address->save(); // Save default billing and shipping if ($orderAddress->getAddressType() == 'billing') { $customer->setDefaultBilling($address->getEntityId()); } elseif ($orderAddress->getAddressType() == 'shipping') { $customer->setDefaultShipping($address->getEntityId()); } } // Force confirmation $customer->setConfirmation($customer->getRandomConfirmationKey()); $customer->save(); return $customer; }
/** * 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; }
/** * Gets a PakjeGemak address for either a quote or an order object. * * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object * * @return false|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|TIG_MyParcel2014_Model_Shipment */ public function getPgAddress($object) { /** * Get all addresses for the specified object. */ if ($object instanceof Mage_Sales_Model_Quote) { $addressCollection = $object->getAllAddresses(); } elseif ($object instanceof Mage_Sales_Model_Order) { $addressCollection = $object->getAddressesCollection(); } elseif ($object instanceof TIG_MyParcel2014_Model_Shipment) { $order = $object->getOrder(); if (!$order) { return false; } $addressCollection = $order->getAddressesCollection(); } else { return false; } /** * Go through each address and check if it's a PakjeGemak address. * * @var Mage_Sales_Model_Quote_Address|Mage_Sales_Model_Order_Address $address */ $pgAddress = false; foreach ($addressCollection as $address) { if ($address->getAddressType() == self::PG_ADDRESS_TYPE) { $pgAddress = $address; break; } } /** * Return the PakjeGemak address or false if none was found. */ return $pgAddress; }
/** * get shipping address with the highest subtotal amount. * * @param Mage_Sales_Model_Order * @return Mage_Sales_Model_Order_Address|null */ protected function getPrimaryShippingAddress(Mage_Sales_Model_Order $order) { $collection = $order->getAddressesCollection(); $address = $collection->getItemByColumnValue('quote_address_id', $this->getQuotePrimaryShippingAddressId($order->getQuote())); return $address; }
* 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(); }