0

The need is that I have a guest count on a product (product A) that changes the qty of the ordered amount. What I have done is set up a bunch of custom options for the questions based on the guest for that particular product programmatically when the product (product A) is added to the cart.

Currently it is saving the options to the product (product A) and this is working, but there has to be a better way. Here is what I want to do better on. As you add a guest there are a set of questions for that guest of the product. So as I add an order, this product (product A) get a custom option guest_1_menu=>'some text' is saved to the product (product A) and you can see this new option on the back when editing the product (product A) . Now when I make another order the product (product A) this time was added to the cart with 2 guests which have there options, so guest_1_menu=>'some text new value' and guest_2_menu=>'some text'. Now when you go to look at the product in the back end you have 2 custom options.

This all works like I said, but lets say over many order someone get to 10 guests when they check out, that product (product A) would have 10 custom options. Here is a more visual representation of what I'm doing now

Order #0001
***(product A)***
    \___ guest 1
            \___ menu
             \___ gift

The product on the back now has 2 custom options,

- guest_1_menu
- guest_1_gift

Now we take a second order

Order #0002
***(product A)***
    \___ guest 1
            \___ menu
             \___ gift
    \___ guest 2
            \___ menu
             \___ gift

The product on the back now has 4 custom options,

- guest_1_menu
- guest_1_gift
- guest_2_menu
- guest_2_gift

Now we take a third order

Order #0003
***(product A)***
    \___ guest 1
            \___ menu
             \___ gift
    \___ guest 2
            \___ menu
             \___ gift
    \___ guest 3
            \___ menu
             \___ gift

The product on the back now has 6 custom options,

- guest_1_menu
- guest_1_gift
- guest_2_menu
- guest_2_gift
- guest_3_menu
- guest_3_gift

So just to be clear, if the number of custom options are a high water mark basically. (one last order example)

Order #0004
***(product A)***
    \___ guest 1
            \___ menu
             \___ gift

The product on the back still has 6 custom options as order 3 pushed it up there,

- guest_1_menu
- guest_1_gift
- guest_2_menu
- guest_2_gift
- guest_3_menu
- guest_3_gift

SO again this works, but you can see how messy this gets, so is there a better way to attach data to an order that will show from cart to invoice? Happy to add classes or blocks that will help, but I really don't want to have it something that can get edited from the product in the admin. I hope this was clear.

0

I think you need to set the custom options to the Quote Item and not to the product. Check this method:

\Mage_Sales_Model_Quote_Item::addOption

It will be shown on the cart if you add it with the array code: additional_options

But you need to make sure that you are not overwriting the options that are already there. Check this answer from Vinai on how to add options to the quote item and persist them: https://stackoverflow.com/a/9496266

  • And that will show in the cart? – jeremy.bass Jul 29 '14 at 21:40
  • Edited my answer please check – Behnam Shayani Jul 29 '14 at 22:07

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.