Solved

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

Posted on 2011-03-11
2
947 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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Every business owner understands the significance of online customer reviews and the impact it can have on sales and revenues. With technology advancing at such a rapid pace, getting online reviews has never been easier, especially when many regions…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now