Solved

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

Posted on 2011-03-11
2
953 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
[X]
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
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Difference between PHPClasse.php and SimplXLS.php 5 47
Can't Find the Homepage on my site 4 47
phpmyadmin memory error 55 96
Load string Array from file 23 42
Are you using email marketing software? If not, you're missing out on effortless marketing and the reaching of desired conversion rates through email marketing software.
Learn about the eCommerce marketing trends for the year ahead.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

710 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