Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento新购物车属性_Magento_Module_Attributes_Shopping Cart - Fatal编程技术网

Magento新购物车属性

Magento新购物车属性,magento,module,attributes,shopping-cart,Magento,Module,Attributes,Shopping Cart,嗨,我面临的问题起初看起来很简单,但现在变成了一场真正的噩梦 我被要求添加一个属性(即点)到所有的产品(这是非常简单的使用管理面板),并有它的总作为一个购物车属性的规则可以设置 我非常肯定,购物车属性定义在: class Mage_SalesRule_Model_Rule_Condition_Address extends Mage_Rule_Model_Condition_Abstract { public function loadAttributeOptions() { $attr

嗨,我面临的问题起初看起来很简单,但现在变成了一场真正的噩梦

我被要求添加一个属性(即点)到所有的产品(这是非常简单的使用管理面板),并有它的总作为一个购物车属性的规则可以设置

我非常肯定,购物车属性定义在:

class Mage_SalesRule_Model_Rule_Condition_Address extends Mage_Rule_Model_Condition_Abstract
{
public function loadAttributeOptions()
{
    $attributes = array(
        'base_subtotal' => Mage::helper('salesrule')->__('Subtotal'),
        'total_qty' => Mage::helper('salesrule')->__('Total Items Quantity'),
        'weight' => Mage::helper('salesrule')->__('Total Weight'),
        'payment_method' => Mage::helper('salesrule')->__('Payment Method'),
        'shipping_method' => Mage::helper('salesrule')->__('Shipping Method'),
        'postcode' => Mage::helper('salesrule')->__('Shipping Postcode'),
        'region' => Mage::helper('salesrule')->__('Shipping Region'),
        'region_id' => Mage::helper('salesrule')->__('Shipping State/Province'),
        'country_id' => Mage::helper('salesrule')->__('Shipping Country'),
    );

    $this->setAttributeOption($attributes);

    return $this;
}
<...>
class Mage\u SalesRule\u Model\u Rule\u Condition\u Address扩展Mage\u Rule\u Model\u Condition\u抽象
{
公共函数loadAttributeOptions()
{
$attributes=数组(
'base_subtotal'=>Mage::helper('salesrule')->,
“总数量”=>Mage::helper('salesrule')->(“总项目数量”),
'weight'=>Mage::helper('salesrule')->\uuuu('Total weight'),
“付款方式”=>Mage::helper('salesrule')->(“付款方式”),
'shipping_method'=>Mage::helper('salesrule')->uuu('shipping method'),
'postcode'=>Mage::helper('salesrule')->\uuuu('Shipping postcode'),
'region'=>Mage::helper('salesrule')->,
'region_id'=>Mage::helper('salesrule')->\uu('Shipping State/Province'),
'country_id'=>Mage::helper('salesrule')->\uuu('Shipping country'),
);
$this->setAttributeOption($attributes);
退还$this;
}
因此,如果我覆盖此模型并将一个项目添加到该数组中,我将获得规则定义管理面板中显示的属性。似乎所有这些属性在sales\u flat\u quote\u address表中都有一个匹配列,除了total\u qty和payment\u method

现在的问题是,我应该怎么做才能在规则处理中计算和评估我的新属性?我应该向该表添加一列并在购物车更改时更新其值吗


任何关于如何做到这一点的见解都非常有价值,谢谢。

我终于完成了任务,我在这里解释了这个过程,仅供将来参考

问题中提到的类(即:Mage\u SalesRule\u Model\u Rule\u Condition\u Address)是问题的关键。我不得不重写它,由于一些奇怪的原因,我无法通过扩展它来获得所需的内容,因此我的类扩展了它的父类(即:Mage\u Rule\u Model\u Condition\u Abstract)

正如我所说,我将我的属性添加到$attributes中,如下所示:

'net_score' => Mage::helper('mymodule')->__('Net Score')
我还修改了getInputType()方法,并将属性声明为numeric

现在关键在于validate()方法:

正如您所见,它准备了一个Mage_Sales_Model_Quote_Address的实例,并将其发送到其父验证方法。您可以看到,此对象($Address)默认情况下没有payment_方法,因此此方法创建一个并将其分配给它。因此,我也做了同样的事情,只是在返回之前添加了以下代码:

if ('net_score' == $this->getAttribute() && ! $address->hasNetScore()) {
    $address->setNetScore( /*the logic for retrieving the value*/);
}
现在我可以在这个属性上设置规则了

希望这些信息能在将来节省一些人的时间

if ('net_score' == $this->getAttribute() && ! $address->hasNetScore()) {
    $address->setNetScore( /*the logic for retrieving the value*/);
}