0

Magento how to update billing/shipping order before place order for guest.

I know what observer event I need to use and familiar with it. What I want to know is how to get billing/shipping or and what code write to update it. I've only found information about how to update a address of already placed order.

2 Answers 2

0

I did not try this code so you should refine it on your own: you need to have an observer that has a function to update the billing and shipping address, here is what you need to do in your xml:

<sales_order_save_before>
    <observers>
        <custom_observer>
            <type>singleton</type>
            <class>Custom_Module_Model_Observer</class>
            <method>updateaddress</method>
        </custom_observer>
    </observers>
</sales_order_save_before>

then in your observer you need to check if the account is a guest account and then update their quote:

public function updateaddress(Varien_Event_Observer $observer) {
    $session = $observer->getEvent()->getCheckoutSession();
    $sessionCustomer = Mage::getSingleton("customer/session");
    $quote = $this->_quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId())->load($session->getQuoteId());
    $address = $quote->getShippingAddress();
    if (!$sessionCustomer->isLoggedIn()) {
        $address->setData($reset);
        $quote->setShippingAddress($address);
        $quote->setBillingAddress($address);
        $quote->collectTotals()->save();
    }
}
0

you need to add code in sales_order_place_before event

public function orderPlaceBefore($observer) {

    $order = $observer->getEvent()->getOrder();
    $billing_address = $order->getBillingAddress();
    $shippingAddress = Mage::getModel('sales/order_address')
        ->setCustomerId($billing_address->getCustomerId())
        ->setCustomerAddressId($billing_address->getCustomerAddressId())
        ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
        ->setFirstname($billing_address->getFirstname())
        ->setMiddlename($billing_address->getMiddlename())
        ->setLastname($billing_address->getLastname())
        ->setSuffix($billing_address->getSuffix())
        ->setCompany($billing_address->getCompany())
        ->setStreet($billing_address->getStreet())
        ->setCity($billing_address->getCity())
        ->setCountry_id($billing_address->getCountryId())
        ->setRegion($billing_address->getRegion())
        ->setRegion_id($billing_address->getRegionId())
        ->setPostcode($billing_address->getPostcode())
        ->setTelephone($billing_address->getTelephone())
        ->setFax($billing_address->getFax());

    $order->setShippingAddress($shippingAddress);
    $order->save();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.