Reputation: 7056
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!
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.
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.
Upvotes: 0
Views: 3196
Reputation: 7056
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:
Upvotes: 1
Reputation: 3054
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
Upvotes: 0