0

I have created attributes that save directly to a quote item in my checkout_cart_product_add_after Observer method will not persist the value as it seems to be reverted after the Observer exits.

See code samples below:

config.xml (snippet):

<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 (snippet):

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
    }

The $_item object in this example isn't providing the facility to retain the attribute as set - even when calling ->save().

Thank in advance for your help. I have seen all of the tutorials about setting custom prices and attributes - nothing seems to remedy the situation!

Edit 1

I'm starting to feel like this is a bug in 1.6+. I have seen much discussion on various boards about this working in >=1.4.

Edit 2

Just to be absolutely clear, the issue here is that the Custom Pricing attribute is being overwritten effectively by the Product model or the collectTotals methods. I need a workaround.

Community
  • 1
  • 1
philwinkle
  • 7,036
  • 3
  • 27
  • 46
  • have you created the fields in sales_flat_quote tale? – Anton S Apr 10 '12 at 12:07
  • Yes, in the table `sales_flat_quote_item` as this is an entity_type of quote_item. – philwinkle Apr 10 '12 at 12:08
  • since 1.4 the quote is stored in sales_flat_quote and if you add anything add them as fields to this table where they will be stored. – Anton S Apr 10 '12 at 12:14
  • I will go ahead and give that a try, yes, but this is for a *quote_item*... thus in sales_flat_quote_item. I am quite familiar with this process... pricing customization is what is not behaving. – philwinkle Apr 10 '12 at 12:16
  • 1
    well if it is for a item then pardon me for confusing this – Anton S Apr 10 '12 at 12:22

2 Answers2

1

As it happens my working code here did, in fact, work. An extension conflict with Amasty's Special Promotions was causing the custom pricing to be unset. This is tested as working with the following Magento versions:

  • 1.5 Community
  • 1.6.1 Community
  • 1.11.1.1 Enterprise
philwinkle
  • 7,036
  • 3
  • 27
  • 46
0

Here is the answer to your question, yes this is in the newer version of Magento 1.5+:

When checking out items get converted from a quote to a order at which point your attribute are being lost.

You would need to add something similar to this observer in order for your attributes to retain at checkout:

<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>

Here we move the option from the quote item to the 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);
    }
}

Take a look here for more details: Magento - Quote/order product item attribute based on user input

Community
  • 1
  • 1
Gershon Herczeg
  • 3,016
  • 23
  • 33
  • I appreciate your use of additional options to hijack it - but the issue here at hand is the actual price displayed in the cart. Not in the conversion to an order item. – philwinkle Apr 10 '12 at 13:34
  • Yes this an example from the link i had sent but the issue is very similar that ever since 1.5 information gets lost btw the conversion from a quote to a order. – Gershon Herczeg Apr 10 '12 at 16:01
  • salesConvertQuoteItemToOrderItem is not calling. I am setting my custom option in sales_quote_collect_totals_before and it is configurable product – Milople Inc Mar 08 '14 at 06:17