dqyin0101 2015-07-10 06:24
浏览 22

Magento隐藏运输方法或通过观察者更改其价格

I have created a Magento module with an Observer that should hide a certain shipping method, but I can't get it to work.

class Company_Modulename_Model_Observer
{
    public function hideShippingMethods(Varien_Event_Observer $observer)
    {
        if (Mage::getDesign()->getArea() === Mage_Core_Model_App_Area::AREA_FRONTEND) {
            $quote = $observer->getEvent()->getQuote();
            $store = Mage::app()->getStore($quote->getStoreId());
            $carriers = Mage::getStoreConfig('carriers', $store);
            $newPrice = 10;

            foreach ($carriers as $carrierCode => $carrierConfig) {
                if ($carrierCode == 'flatrate') {
                    $store->setConfig('carriers/flatrate/price', $newPrice);
                    $store->setConfig('carriers/flatrate/showmethod', '0');
                    $store->setConfig('carriers/flatrate/active', '0');
                    $store->setConfig('carriers/flatrate/title', 'Test title');
                }
            }
        }
    }
}

Of all the setConfig settings only the $store->setConfig('carriers/flatrate/title', 'Test title'); works.

So the title of the delivery method gets changed in the checkout, but the price doesn't change and it is still shown.

How can I hide or change the price of a certain shippig method?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 linux驱动,linux应用,多线程