在 Magento 中使用自定义地址属性结账

发布于 2024-12-01 05:11:07 字数 372 浏览 0 评论 0原文

我为我的 Customer_Address 创建了一个“地区”属性,因为我的运费是根据它计算的。 此属性在我的结帐中显示得非常好,用户可以毫无问题地从几个选项中进行选择。

然而,当结帐时,我的类中的collectRates()方法会收到一个“Mage_Shipping_Model_Rate_Request”,其中包含有关用户选择结帐的选项的一些信息。 此时,我需要有一种方法来获取用户设置为 District 值的任何内容,以根据该值计算运费,但我似乎无法从 Mage_Shipping_Model_Rate_Request 获取信息。

有没有办法将属性添加到该类以便稍后检索它? 或者 我应该寻求以其他方式获得该价值吗?

您能给我的任何帮助都会非常有用!

谢谢。

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 user 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷情 2024-12-08 05:11:07

我认为你已经解决了这个问题......

无论如何,我遇到了同样的问题并以这种方式解决了它:

重写 Mage_Sales_Model_Quote_AddressMage_Shipping_Model_Shipping,这些是执行 的类$request = Mage::getModel('shipping/rate_request');

所以它看起来像

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());
    ...
}
}

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());
     }
}

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());
     }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文