Checkout with custom Address attributes in Magento
I have a ”District” attribute created to my Customer_Address because my shipping is calculated base on it. This attribute shows perfectly well in my checkout and the user can select from a couple of options with no problem.
However when it checksout, the collectRates() method in my class receives a ”Mage_Shipping_Model_Rate_Request” with some information about the options selected by the user to checkout. At this point, I need to have a way to get whatever the us开发者_开发百科er has set as the District value to calculate the shipping cost based on that, but I can’t seem to get the information from Mage_Shipping_Model_Rate_Request.
Is there a way I can add the attribute to that class to retrieve it later? or Should I be looking to get that value in some other way?
Whatever help you can give me will be very useful!
Thanks.
I think you solved this already...
Anyway, I had the same problem and solved it this way:
Rewrite Mage_Sales_Model_Quote_Address
and Mage_Shipping_Model_Shipping
, these are the classes that do $request = Mage::getModel('shipping/rate_request');
So it looks like:
class MyCompany_MyModule_Model_Quote_Address extends Mage_Sales_Model_Quote_Address{
public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null)
{
/** @var $request Mage_Shipping_Model_Rate_Request */
$request = Mage::getModel('shipping/rate_request');
// add custom attribute
$request->setDestCustom($this->getCustomAddressAttribute());
...
}
}
and
class MyCompany_MyModule_Model_Shipping extends Mage_Shipping_Model_Shipping{
public function collectRatesByAddress(Varien_Object $address, $limitCarrier = null)
{
/** @var $request Mage_Shipping_Model_Rate_Request */
$request = Mage::getModel('shipping/rate_request');
...
// add custom attribute
$request->setDestCustom($address->getCustomAddressAttribute());
}
}
精彩评论