Solved

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

Posted on 2011-03-11
2
950 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn about the eCommerce marketing trends for the year ahead.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

770 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