【问题标题】:Magento: Creating own Shipping Method with additional attributeMagento:使用附加属性创建自己的运输方法
【发布时间】:2012-11-27 09:57:58
【问题描述】:

我创建了一个模块,它为 magento 实现了一种新的运输方法。目前该模块运行良好。

单页结帐中显示了送货方式。

class Tigerbytes_Barverkauf_Model_Carrier_Selbstabholung extends Mage_Shipping_Model_Carrier_Abstract

现在我想扩展功能。新的运输模块不应再在前端可见。因此,我为我的模块添加了一个新属性。 (show_frontend)

config.xml

<default>
        <carriers>
            <selbstabholung>
                <active>1</active>
                <allowed_methods>selbstabholung</allowed_methods>
                <methods>selbstabholung</methods>
                <sallowspecific>0</sallowspecific>
                <model>Tigerbytes_Barverkauf_Model_Carrier_Selbstabholung</model>
                <name>Selbstabholung</name>
                <title>Selbstabholung</title>
                <specificerrmsg>Zur Zeit ist die Versandmethode nicht verfuegbar</specificerrmsg>
                <handling>0</handling>
                <handling_type>F</handling_type>
                <show_frontend>0</show_frontend>
            </selbstabholung>
        </carriers>

    system.xml
<show_frontend translate="label">
                            <label>zeige im Frontend?</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </show_frontend>

属性show_frontend显示在后端,也保存在core_config_data表中。

现在最大的问题是在获取单页结帐的送货方式以供用户选择时,对象中没有 show_frontend 属性。

我认为用于运输方式列表的对象是

Mage_Sales_Model_Quote_Address_Rate

那么我必须扩展什么,让 rate 对象知道 show_frontend 属性?

【问题讨论】:

    标签: php magento magento-1.4


    【解决方案1】:

    你正在做所有你的模块,对吗?

    去做吧:

    在您的 collectRates() 方法中,您输入了以下代码:

    if(!Mage::getStoreConfig('carrier/selbstabholung/show_frontend'))
        return false;
    

    这段代码应该可以完成这项工作。

    美好的一天。

    【讨论】:

    • 该死,你说得对!谢谢。我想完成。 :-)
    • 是的,有时 magento 也可以很简单。 ;) 请将答案标记为正确。 ~^
    【解决方案2】:

    附件:

    我只想允许在前端显示运输方式。我想在后端订单的后端显示它。

    所以在 collectRates() 方法中,我实现了以下条件。

    if(Mage::getDesign()->getArea() === Mage_Core_Model_App_Area::AREA_FRONTEND &&
            !Mage::getStoreConfig('carriers/'.$this->_code.'/show_frontend')){
    
            return false;
        }
    

    现在它的工作完美!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-20
      • 2013-06-19
      • 2010-10-17
      • 2011-01-11
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多