Solved

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

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate PDF's using TCPDF - Initial Set Up 9 29
MySQL-Design Help 12 38
[form-control] Retain values after a POST action 21 31
php hashing methods 3 9
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to dynamically set the form action using jQuery.

713 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