【问题标题】:Magento Custom Pricing / Attributes on a Quote ItemMagento 自定义定价/报价项目的属性
【发布时间】:2012-04-10 11:37:22
【问题描述】:

我在checkout_cart_product_add_after Observer 方法中创建了直接保存到引用项的属性,因为它似乎在 Observer 退出后恢复了,所以不会保留该值。

请参阅下面的代码示例:

config.xml (sn-p):

<checkout_cart_product_add_after>
    <observers>
      <module>
        <type>model</type>
        <class>NativeRemedies_OrderGroove_Model_Observer</class>
        <method>productAddAfter</method>
      </module>
    </observers>
  </checkout_cart_product_add_after>

Observer.php (sn-p):

public function handleOrderGroove()
{       
    foreach($this->og->products as $_product){
        if($_product->every>0){
            foreach($this->_quote->getAllVisibleItems() as $_item){
                //if sku is in the active list of recurring products selected add quote item id to array
                if($_item->getSku()==$_product->id){
                    Mage::helper('nrordergroove')->setRecurringItem($_item->getItemId());
                    $_item->setOrdergrooveActive(true)->save();
                    $_item->getProduct()->setPrice(2);
                    $_item->setCustomPrice(2);
                    $_item->setOriginalCustomPrice(2);
                    $_item->getProduct()->setIsSuperMode(true);
                }
            }
        } // else, do nothing
    }

此示例中的 $_item 对象未提供将属性保持为设置状态的功能 - 即使在调用 -&gt;save() 时也是如此。

提前感谢您的帮助。我已经看过所有关于设置自定义价格和属性的教程 - 似乎没有任何解决办法!

编辑 1

我开始觉得这是 1.6+ 中的一个错误。我在 >=1.4 中看到了很多关于这个工作的讨论。

编辑 2

绝对清楚,这里的问题是自定义定价属性被 Product 模型或 collectTotals 方法有效地覆盖。我需要一个解决方法。

【问题讨论】:

  • 你在 sales_flat_quote tale 中创建了字段吗?
  • 是的,在表 sales_flat_quote_item 中,因为这是 quote_item 的 entity_type。
  • 从 1.4 开始,报价存储在 sales_flat_quote 中,如果您添加任何内容,请将它们作为字段添加到将存储它们的表中。
  • 我会继续尝试,是的,但这是针对 quote_item... 因此在 sales_flat_quote_item 中。我对这个过程非常熟悉......定价定制是不正常的。
  • 好吧,如果它是一个项目,请原谅我混淆了这个

标签: php magento


【解决方案1】:

事实上,我的工作代码确实有效。与 Amasty 的特别促销的扩展冲突导致自定义定价未设置。经测试可与以下 Magento 版本一起使用:

  • 1.5 社区
  • 1.6.1 社区
  • 1.11.1.1 企业版

【讨论】:

    【解决方案2】:

    这是您问题的答案,是的,这是在 Magento 1.5+ 的较新版本中:

    结帐时,商品会从报价转换为订单,此时您的属性将丢失。

    您需要添加与此观察者类似的内容,以便在结帐时保留您的属性:

    <sales_convert_quote_item_to_order_item>
        <observers>
            <extra_options>
                <type>model</type>
                <class>extra_options/observer</class>
                <method>salesConvertQuoteItemToOrderItem</method>
            </extra_options>
        </observers>
    </sales_convert_quote_item_to_order_item>
    

    这里我们将选项从报价项移至订单项。

    public function salesConvertQuoteItemToOrderItem(Varien_Event_Observer $observer)
    {
        $quoteItem = $observer->getItem();
        if ($additionalOptions = $quoteItem->getOptionByCode('additional_options')) {
            $orderItem = $observer->getOrderItem();
            $options = $orderItem->getProductOptions();
            $options['additional_options'] = unserialize($additionalOptions->getValue());
            $orderItem->setProductOptions($options);
        }
    }
    

    查看此处了解更多详情: Magento - Quote/order product item attribute based on user input

    【讨论】:

    • 感谢您使用其他选项来劫持它 - 但目前的问题是购物车中显示的实际价格。不在转换为订单商品中。
    • 是的,这是我发送的链接中的一个示例,但问题非常相似,自从 1.5 以来,信息在从报价到订单的转换过程中丢失了。
    • salesConvertQuoteItemToOrderItem 未调用。我在 sales_quote_collect_totals_before 中设置我的自定义选项,它是可配置的产品
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多