0

I have a custom input on the product view page just below the options. This is visible for all products.

I want to show the contents of that input on the cart page in the list of product variants, shown below:

Cart

I know I could create a product option but I don't want to have to apply this option to every single product individually.

Is there a way to get this done and if so, how would I go about it?

If anyone needs any more information, please let me know.

0

Here is the good example how to do this:

Four Ways to Customize a Cart Item

Or Create a new module and Add Following Event in Config.xml

<sales_quote_collect_totals_before>
<observers>
<hackathon_presentation>
<type>singleton</type>
<class>modulename/observer</class>
<method>salesQuoteAddressCollectTotalsBefore</method>
</hackathon_presentation>
</observers>
</sales_quote_collect_totals_before>

In Observer.php add following Method

   public function salesQuoteAddressCollectTotalsBefore($observer)
    {
        $quote = $observer->getQuote();
        $quote_items = $quote->getItemsCollection();
        foreach ($quote_items as $item) {
            $additionalOptions = array(
                array(
                    'code'  => 'my_code',
                    'label' => 'This text is displayed through additional options',
                    'value' => 'ID is ' . $item->getProductId() . ' and SKU is ' . $item->getSku()
                )
            );
            $item->addOption(
                array(
                     'code'  => 'additional_options',
                     'value' => serialize($additionalOptions),
                )
            );
        }
    }

Here is more about this topic:

Click Here for More.

Also see here.

| improve this answer | |
  • Thank you for your answer. I may not have been completely clear in my question but each item will have different text. The methods you have provided seem to change all of the items in the cart. I only want to change the one that is currently being added. – Wildcard27 May 27 '16 at 4:53
  • It's do the same as you want you can modify code according to your need in observe method, I have done this before. – Arunendra May 27 '16 at 4:56
  • What would I use to refer to the item being added? and how do I get that value in the observer? – Wildcard27 May 27 '16 at 4:58
  • Have you read the given solution ?In salesQuoteAddressCollectTotalsBefore this function i am getting items you can get all the product value here but you have to work patiently – Arunendra May 27 '16 at 5:02
  • Thank you for this. The 'Also see here' link worked for me! I would up vote your answer but don't have enough rep yet – Wildcard27 May 30 '16 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.