我打算建立一个像购物车,价格规则或目录价格规则这样的扩展程序。
我已经尝试从现有的Magento代码中学到一些东西,你可以看到:
app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Conditions.php
要显示条件规则字段,我尝试添加此脚本,但它无法正常运行
$fieldset->addField('conditions', 'text', array(
'name' => 'conditions',
'label' => Mage::helper('salesrule')->__('Conditions'),
'title' => Mage::helper('salesrule')->__('Conditions'),
))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
问题是:
提前致谢。
更新, 看看我的截图
https://docs.google.com/file/d/0BwLN4KpQhoGbU181R0ZKanJSdVE/edit?usp=drivesdk
这是我的form.php:
<?php
class KS_Kscoba_Block_Adminhtml_Tcoba_Edit_Tab_Form
extends Mage_Adminhtml_Block_Widget_Form
/*
extends Mage_Adminhtml_Block_Widget_Form
implements Mage_Adminhtml_Block_Widget_Tab_Interface
*/
{
protected function _prepareForm()
{
$model = Mage::registry('current_promo_quote_rule');
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset("kscoba_form", array("legend"=>Mage::helper("kscoba")->__("Item information")));
$fieldset->addField("kolom1", "text", array(
"label" => Mage::helper("kscoba")->__("Kolom 1"),
"name" => "kolom1",
));
$fieldset->addField('kolom2', 'select', array(
'label' => Mage::helper('kscoba')->__('Kolom 2'),
'values' => KS_Kscoba_Block_Adminhtml_Tcoba_Grid::getValueArray1(),
'name' => 'kolom2',
));
/*
problem start here
*/
$renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
->setTemplate('promo/fieldset.phtml')
->setNewChildUrl($this->getUrl('*/promo_quote/newConditionHtml/form/rule_conditions_fieldset'));
$fieldset = $form->addFieldset('conditions_fieldset', array(
'legend'=>Mage::helper('salesrule')->__('Apply the rule only if the following conditions are met (leave blank for all products)')
))->setRenderer($renderer);
$fieldset->addField('conditions', 'text', array(
'name' => 'conditions',
'label' => Mage::helper('salesrule')->__('Conditions'),
'title' => Mage::helper('salesrule')->__('Conditions'),
))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
if (Mage::getSingleton("adminhtml/session")->getTcobaData())
{
$form->setValues(Mage::getSingleton("adminhtml/session")->getTcobaData());
Mage::getSingleton("adminhtml/session")->setTcobaData(null);
}
elseif(Mage::registry("tcoba_data")) {
$form->setValues(Mage::registry("tcoba_data")->getData());
}
return parent::_prepareForm();
}
}
我错过了什么吗?
答案 0 :(得分:0)
<强> 1。条件字段
我可能会忽略另一个问题,但是当我测试了您的form.php
时,由于Mage::registry('current_promo_quote_rule')
未定义,因此缺少条件字段。在我使用$model
对象填充Mage_SalesRule_Model_Rule
后,页面上出现条件字段。
Magento 1.8在current_promo_quote_rule
_initRule()
和editAction()
Mage_Adminhtml_Promo_QuoteController
注册了app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php
。
<强> 2。前端强>
以购物车价格规则为例,折扣价格通过结账模块应用于前端。
Mage/Checkout/controllers/CartController.php
具有couponPostAction()
功能,当用户从购物车或结帐页面提交优惠券代码时,系统会调用该功能。此功能获取购物车的Mage_Sales_Model_Quote
对象,在该对象上设置优惠券代码,并使用collectTotals()
Mage_Sales_Model_Quote
函数刷新每个项目的总计。
引用对象的collectTotals()
获取相关的Mage_Sales_Model_Quote_Address
个对象并调用其collectTotals()
函数。这些函数获取与地址关联的每个收集器对象,并调用其collect()
方法。
其中一个收集器对象是Mage_SalesRule_Model_Quote_Discount
,其collect()
方法会将每个Mage_Sales_Model_Quote_Item
与此地址相关联,然后使用Mage_SalesRule_Model_Validator
计算并存储其折扣。< / p>
条件中的特定逻辑将被读取并在SalesRule模块中更深入地应用。