2013-12-14 77 views
0

簡要說明:我在使用「Magestore giftvoucher」模塊,默認情況下,發貨地址沒有得到保存,當訂單(只有禮品卡產品)。由於禮券不是實物產品,因此未被運送。它通過電子郵件發送給收件人。但不知何故,我想使發貨地址類似於帳單地址。更新送貨地址與使用觀察員下訂單之前/之後的結算地址類似?

所以我曾嘗試: 下的應用程序/代碼/本地/ Magestore /心願單/型號/ Observer.php

在功能: - >orderSaveAfter我寫了下面的代碼,但沒有運氣這不是加工。

 $order = $observer->getEvent()->getOrder(); 
     $billing_address = $order->getBillingAddress(); 
     $shippingAddress = Mage::getModel('sales/order_address') 
     ->setCustomerId($billing_address->getCustomerId()) 
     ->setCustomerAddressId($billing_address->getCustomerAddressId()) 
     ->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 = Mage::getModel('sales/order')->load($order->getId()); 
     $order->setShippingAddress($shippingAddress); 
     $order->save(); 

請推薦這裏出了什麼問題! 感謝

+0

你檢查是否有錯誤?他們是什麼?你有沒有檢查過這段代碼是否運行? – randak

+0

沒有錯誤我得到,訂單放置成功,但送貨地址沒有保存該訂單! –

回答

1
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); 

... }

+0

謝謝Rajesh :)它適合我! –

相關問題