Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do I edit a product attribute durring a Magento cart checkout?

Posted on 2011-03-11
2
951 Views
Last Modified: 2013-11-18
I have a two part question about customizing my Magento store.

When someone buys a downloadable product, I want to generate a licence code and include it in the invoice.

I have added a product attribute called ‘license_code’ to my product’s default attribute set and I want to set its value with php when a customer checks out.

Which event do I need to observe to let me access the products in the cart just after they are purchased but before the invoice is created?

Also, what script do I use to set a product’s attribute value durring that event?

Thank you for your help!
0
Comment
Question by:Michael_at_Popcap
2 Comments
 
LVL 12

Accepted Solution

by:
miked2004 earned 125 total points
ID: 35129029
Hey CHeck out the Downloadable modules code.

in /app/code/core/mage/Downloadable/etc/config.xml you will see the events that it listens to.
These events cover order save, order_item_save. They are the events that you would need to use. If you need to do something before the order is saved, I believe that "sales_order_save_before" is the event.
<events>            
            <sales_order_item_save_after>
                <observers>
                    <downloadable_observer>
                        <class>downloadable/observer</class>
                        <method>saveDownloadableOrderItem</method>
                    </downloadable_observer>
                </observers>
            </sales_order_item_save_after>
            <sales_order_save_after>
                <observers>
                    <downloadable_observer>
                        <class>downloadable/observer</class>
                        <method>setLinkStatus</method>
                    </downloadable_observer>
                </observers>
            </sales_order_save_after>
        </events>

Open in new window



What is the licence code's purpose? Could you not use the hash that is created for every downloadable link?
0
 

Author Closing Comment

by:Michael_at_Popcap
ID: 35133750
I had to observe the sales_order_item_save_after event and then use the following functions to save the unlock code:

$orderItem = $observer->getEvent()->getItem();
$options = $orderItem->getProductOptions();
 $options['licence_code'] = 'unlock_for_item_'.$orderItem->getProductId();
$orderItem->setProductOptions($options);

I couldn't just use the hash for the download link because our game unlock codes have to be backward compatible with our old ecomm system.

Thank you for your help!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How important is it to take extra precautions to protect your online business? These are some steps you can take to make sure you're free of any cyber crime.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question