【问题标题】:If condition to add link magento?如果条件添加链接magento?
【发布时间】:2015-10-30 16:08:07
【问题描述】:

我的xml代码:

<customer_account>
    <reference name="example_link">
        <action method="addLink" module="example" ifconfig="example/general/enable"><name>my_review</name><path>example/account/list/</path><label>My Review</label></action>
    </reference>
</customer_account>

我正在客户帐户中创建新导航现在我想在该导航中添加一个链接但我想检查客户是否批准为卖方如果它不批准而不是我不想在该导航中添加链接怎么能我这样做

【问题讨论】:

    标签: xml magento


    【解决方案1】:

    您可以在 customer_account_navigation 中添加一个块,如果满足您的条件,则在该块中添加指向父块的链接。

    所以在你的布局中是这样的:

    <customer_account>
        <reference name="example_link">
            <block type="[module]/customer_link" as="[module]_customer_link" name="[module]_customer_link">
                <action method="addLinkToParentBlock" />
            </block>
        </reference>
    </customer_account>
    

    你的块类应该是这样的:

    class [Namespace]_[Module]_Block_Customer_Link extends Mage_Core_Block_Abstract 
    {
        public function addLinkToParentBlock() 
        {
            $parent = $this->getParentBlock();
            if ($parent) {
                if (your condition goes here) {
                    $parent->addLink(
                        'Label goes here',
                        'Url goes here',
                        'title goes here',
                    );
    
                }
            } 
        }
    }
    

    这样,您的块将被实例化。它不会有输出,但会调用方法addLinkToParentBlock

    参考 Marius 答案:https://magento.stackexchange.com/a/42547/18722

    【讨论】:

    • 好方法!但我可以修改自定义链接的顺序吗?我希望将它放在父级中的特定链接之前
    【解决方案2】:

    使用处理程序并由观察者更新.. 活动将是

       <controller_action_layout_load_before>
                    <observers>
                        <add_link_indashboard>
                            <type>singleton</type>
                            <class>seller/observer</class>
                            <method>addCustomLink</method>
                        </add_link_indashboard>
                    </observers>
                </controller_action_layout_load_before>
    

    比观察者方法

    public function addCustomLink(Varien_Event_Observer $observer){
    
            if(Check customer condition ){        
                         Mage::app()->getLayout()->getUpdate()->addHandle('customer_link');        
            } 
    
        }
    

    并在您的 xml 中定义链接

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 2016-07-24
      • 2012-09-16
      • 2015-11-27
      相关资源
      最近更新 更多