php - 如何在购物车价格规则中添加自定义标签

标签 php magento

我正在尝试在 magento 支持的促销/购物车价格规则中添加自定义标签。我需要的是当我选择任何规则时,自定义选项卡显示在“管理优惠券代码”下方,当我单击自定义选项卡时,我必须获得一个带有保存和保存并继续编辑按钮的网格表。谁能建议我正确的方法来做到这一点?

这是我想在“管理优惠券代码”下方添加新自定义选项卡的窗口: http://awesomescreenshot.com/0d34u825af

最佳答案

有关完整说明,您可以引用此 http://www.newgenray.com/2015/04/22/creating-custom-tab-on-edit-page-in-an-existing-module-of-magento/

首先你需要创建一个模块,你必须定义两个东西,一个是布局和 block

<config>
<modules>
    <Newgenray_Coupon>
        <version>0.0.1</version>
    </Newgenray_Coupon>
 </modules>
 <adminhtml>
    <layout>
        <updates>
            <newgenray_coupon>
                <file>coupon.xml</file>
            </newgenray_coupon>
        </updates>
    </layout>
</adminhtml>
<global>
    <blocks>
        <newgenray_coupon>
            <class>Newgenray_Coupon_Block</class>
        </newgenray_coupon>
    </blocks>
</global>

然后在文件 app/code/local/Newgenray/Block/Adminhtml/Promo/Quote/Edit/Tab/Custom.php

class Newgenray_Coupon_Block_Adminhtml_Promo_Quote_Edit_Tab_Custom extends Mage_Adminhtml_Block_Widget_Form
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
/*public function __construct(){
    $this->setTemplate('newgenray_coupon/custom_tab.phtml');
}*/

/**
 * Mandatory to override as we are implementing Widget Tab interface
 * Return Tab Title
 *
 * @return string
 */
public function getTabTitle(){
    return Mage::helper('salesrule')->__('Custom Tab');
}

/**
 * Mandatory to override as we are implementing Widget Tab interface
 * Return Tab Label
 *
 * @return string
 */
public function getTabLabel(){
    return Mage::helper('salesrule')->__('Custom Tab');
}

/**
 * Mandatory to override as we are implementing Widget Tab interface
 * Can show tab in tabs
 * Here you can write condition when the tab should we shown or not. Like you see when we create shopping cart rule
 * Manage coupon tab doesn't come. If you want that then just make a function and check whether you have information
 * in registry or not
 *
 * @return boolean
 */
public function canShowTab(){
    return true;
}

/**
 * Mandatory to override as we are implementing Widget Tab interface
 * Tab is Hidden
 *
 * @return boolean
 */
public function isHidden(){
    return false;
}

/**
 * Defines after which tab this tab should come like you asked you need it below Manage Coupon codes
 *
 * @return string
 */
public function getAfter(){
    return 'coupons_section';
}

public function _prepareForm(){
     /* To set the data in the form you need to get the data in registry In my example
     * I don't have any registry so I am commenting it. My Form will be blank
     */
    //$model = Mage::registry('custom_tab_form_data');

    $form = new Varien_Data_Form();

    $form->setHtmlIdPrefix('rule_');

    $fieldset = $form->addFieldset('custom_fieldset', array(
        'legend'=>Mage::helper('salesrule')->__('Your Custom Field Set ')
    ));

    $fieldset->addField('name', 'text', array(
        'label'     => Mage::helper('salesrule')->__('Name'),
        'class'     => 'required-entry',
        'required'  => true,
        'name'      => 'name',
        'note'     => Mage::helper('salesrule')->__('The name of the example.'),
    ));

    $fieldset->addField('description', 'text', array(
        'label'     => Mage::helper('salesrule')->__('Description'),
        'class'     => 'required-entry',
        'required'  => true,
        'name'      => 'description',
    ));

    $fieldset->addField('other', 'text', array(
        'label'     => Mage::helper('salesrule')->__('Other'),
        'class'     => 'required-entry',
        'required'  => true,
        'name'      => 'other',
    ));


    //$form->setValues($model->getData());
    $this->setForm($form);

    return parent::_prepareForm();
}
}

然后在文件 app/app/design/adminhtml/default/default/layout/coupon.xml

<?xml version="1.0"?>
<layout version="0.1.0">
     <adminhtml_promo_quote_edit>
           <reference name="promo_quote_edit_tabs">
                <action method="addTab">
                     <name>promo_quote_edit_tab_custom</name>
                     <block>newgenray_coupon/adminhtml_promo_quote_edit_tab_custom</block>
                 </action>
            </reference>
      </adminhtml_promo_quote_edit>
  </layout>

最后一步是激活我们刚刚创建的模块

<?xml version="1.0"?>
<config>
<modules>
    <Newgenray_Coupon>
        <active>true</active>
        <codePool>local</codePool>
    </Newgenray_Coupon>
</modules>
</config>

关于php - 如何在购物车价格规则中添加自定义标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29746098/

相关文章:

php - 将文件名数据库与文件同步

php - 输出数组,因此它可以用作数据属性的值

php - Prestashop 1.6 中自定义模块的 URL 链接

php - Magento 客户模块覆盖不起作用

php - 区分具有相同 url 的页面

magento - 在 Magento2 中获取当前货币符号

javascript - 即使未经验证,表单也始终会提交

php - 我如何在 php 和 javascript 中获取 PST 中的当前时间?

jquery - 自定义添加的顶级菜单项的事件状态 [Magento topmenu]

magento - 我需要打开“管理库存”选项