【发布时间】:2014-10-19 17:31:48
【问题描述】:
我遇到了无法解决的问题。部分原因是我无法用正确的术语来解释它。我是新手,很抱歉这个笨拙的问题。
您可以在下面看到我的目标概览。
我正在使用 Magento CE 1.7.0.2。
管理面板 -> 促销 -> 购物车价格规则 -> 添加新规则 -> 操作(选项卡)
在使用以下信息更新价格对于应用下拉菜单,我想添加我的自定义选项。
我该怎么做。
如何在不影响核心功能的情况下做到这一点...
我对此进行了一些研究,但从未找到任何关于覆盖促销的文章。
开始覆盖核心文件,我发现我应该覆盖以下内容。
- /app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php
- /app/code/core/Mage/SalesRule/Model/Rule.php
- /app/code/core/Mage/SalesRule/Model/Validator.php
在我的本地代码池中创建了类似Mage1/AdminhtmlMage1/SalesRule
我的新模块文件夹结构
- /app/code/local/Mage1/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php
- /app/code/local/Mage1/SalesRule/Model/Rule.php
- /app/code/local/Mage1/SalesRule/Model/Validator.php
Mage1/Adminhtml/etc/config.xml
<config>
<modules>
<Mage1_Adminhtml>
<version>1.0.0</version>
</Mage1_Adminhtml>
</modules>
<global>
<models>
<adminhtml>
<rewrite>
<rule>Mage1_SalesRule_Model_Rule</rule>
</rewrite>
</adminhtml>
</models>
<blocks>
<adminhtml>
<rewrite>
<promo_quote_edit_tab_actions>Mage1_Adminhtml_Block_Promo_Quote_Edit_Tab_Actions</promo_quote_edit_tab_actions>
</rewrite>
</adminhtml>
</blocks>
<helpers>
<adminhtml>
<class>Mage1_Adminhtml_Helper</class>
</adminhtml>
</helpers>
</global>
</config>
Mage1/SalesRule/etc/config.xml
<config>
<modules>
<Mage1_SalesRule>
<version>1.0.0</version>
</Mage1_SalesRule>
</modules>
<global>
<models>
<salesrule>
<rewrite>
<validator>Mage1_SalesRule_Model_Validator</validator>
</rewrite>
</salesrule>
</models>
<helpers>
<salesrule>
<class>Mage1_SalesRule_Helper</class>
</salesrule>
</helpers>
</global>
</config>
Actions.php
protected function _prepareForm() {
$model = Mage::registry('current_promo_quote_rule');
$form = new Varien_Data_Form();
$form->setHtmlIdPrefix('rule_');
$fieldset = $form->addFieldset('action_fieldset', array('legend'=>Mage::helper('salesrule')->__('Update prices using the following information')));
$fieldset->addField('simple_action', 'select', array(
'label' => Mage::helper('salesrule')->__('Apply'),
'name' => 'simple_action',
'options' => array(
Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION => Mage::helper('salesrule')->__('Percent of product price discount'),
Mage_SalesRule_Model_Rule::BY_FIXED_ACTION => Mage::helper('salesrule')->__('Fixed amount discount'),
Mage_SalesRule_Model_Rule::CART_FIXED_ACTION => Mage::helper('salesrule')->__('Fixed amount discount for whole cart'),
Mage_SalesRule_Model_Rule::BUY_X_GET_Y_ACTION => Mage::helper('salesrule')->__('Buy X get Y free (discount amount is Y)'),
Mage_SalesRule_Model_Rule::GET_PERCENT_X_MAX_Y_ACTION => Mage::helper('salesrule')->__('Percent of total cart Max discount'),
),
));
$fieldset->addField('discount_amount', 'text', array(
'name' => 'discount_amount',
'required' => true,
'class' => 'validate-not-negative-number',
'label' => Mage::helper('salesrule')->__('Discount Amount'),
));
$model->setDiscountAmount($model->getDiscountAmount()*1);
$fieldset->addField('discount_qty', 'text', array(
'name' => 'discount_qty',
'label' => Mage::helper('salesrule')->__('Maximum Qty Discount is Applied To'),
));
$model->setDiscountQty($model->getDiscountQty()*1);
$fieldset->addField('discount_step', 'text', array(
'name' => 'discount_step',
'label' => Mage::helper('salesrule')->__('Discount Qty Step (Buy X)'),
));
$fieldset->addField('apply_to_shipping', 'select', array(
'label' => Mage::helper('salesrule')->__('Apply to Shipping Amount'),
'title' => Mage::helper('salesrule')->__('Apply to Shipping Amount'),
'name' => 'apply_to_shipping',
'values' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray(),
));
$fieldset->addField('simple_free_shipping', 'select', array(
'label' => Mage::helper('salesrule')->__('Free Shipping'),
'title' => Mage::helper('salesrule')->__('Free Shipping'),
'name' => 'simple_free_shipping',
'options' => array(
0 => Mage::helper('salesrule')->__('No'),
Mage_SalesRule_Model_Rule::FREE_SHIPPING_ITEM => Mage::helper('salesrule')->__('For matching items only'),
Mage_SalesRule_Model_Rule::FREE_SHIPPING_ADDRESS => Mage::helper('salesrule')->__('For shipment with matching items'),
),
));
$fieldset->addField('stop_rules_processing', 'select', array(
'label' => Mage::helper('salesrule')->__('Stop Further Rules Processing'),
'title' => Mage::helper('salesrule')->__('Stop Further Rules Processing'),
'name' => 'stop_rules_processing',
'options' => array(
'1' => Mage::helper('salesrule')->__('Yes'),
'0' => Mage::helper('salesrule')->__('No'),
),
));
$renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
->setTemplate('promo/fieldset.phtml')
->setNewChildUrl($this->getUrl('*/promo_quote/newActionHtml/form/rule_actions_fieldset'));
$fieldset = $form->addFieldset('actions_fieldset', array(
'legend'=>Mage::helper('salesrule')->__('Apply the rule only to cart items matching the following conditions (leave blank for all items)')
))->setRenderer($renderer);
$fieldset->addField('actions', 'text', array(
'name' => 'actions',
'label' => Mage::helper('salesrule')->__('Apply To'),
'title' => Mage::helper('salesrule')->__('Apply To'),
'required' => true,
))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/actions'));
Mage::dispatchEvent('adminhtml_block_salesrule_actions_prepareform', array('form' => $form));
$form->setValues($model->getData());
if ($model->isReadonly()) {
foreach ($fieldset->getElements() as $element) {
$element->setReadonly(true, true);
}
}
$this->setForm($form);
return parent::_prepareForm();
}
Rule.php
const TO_PERCENT_ACTION = 'to_percent';
const BY_PERCENT_ACTION = 'by_percent';
const TO_FIXED_ACTION = 'to_fixed';
const BY_FIXED_ACTION = 'by_fixed';
const CART_FIXED_ACTION = 'cart_fixed';
const BUY_X_GET_Y_ACTION = 'buy_x_get_y';
const GET_PERCENT_X_MAX_Y_ACTION = 'get_x_max_y';
Validator.php
public function process(Mage_Sales_Model_Quote_Item_Abstract $item) {
Mage::log('I'm Inside Process Function');
switch ($rule->getSimpleAction()) {
case Mage_SalesRule_Model_Rule::GET_PERCENT_X_MAX_Y_ACTION:
Mage::log('Helllll..');
break;
}
}
由于 Actions.php 和 Rule.php 文件编辑,我应该在下拉菜单中获得一个新选项,但我什么也没得到。我在这里做错了什么。
我希望 XML 文件中缺少一些东西。
有什么想法吗?
请帮帮我...
【问题讨论】: