I need to dynamically add option choices to the cart items at the time a product is added to the cart. The choices presented to the shopper can change from product to product, so it is necessary that they are dynamic. However, the options will always be the same. For example “Option 1” might have values “a, b, c” for one product and “x, y, z” for another product. I do not need the options saved into the product, only the cart. The selections need to be displayed in the cart and in the order administration, receipt, etc.
I learned from this answer that I can use $cart->addProduct($product, $params) in order to set custom options to the cart item.
I found that I can override the Cart controller at this blog post. I was able to dynamically add the product to the cart. However, I am stuck on how to add dynamic attribute values to the product. I tried setting ‘options’ and ‘super_attribute’ in $params before calling $cart->addProduct($product, $params) but it’s not saving the values to the cart item.
Finally, some of the option choices would need to affect the product price. I am not sure how to account for this either.
Thanks in advance for any help!
In the past I have use a combination of text field and drop-down option (for options which affect price) along with custom javascript and hidden field to solve this issue. Take a look at the example below, as you change the different cabinet width the total dimension and price will be updated. This information will also be add to cart/admin order
see example @ http://www.contempospace.com/bedroom-furniture/wardrobe-closets/custom-closet-systems/isa-custom-closet-4-module/isa-closet-system-xl-maximize-large-closet-drawers-shelves-hanging.html
Assuming that you are using simple product.
To add additional_options see Magento – Quote/order product item attribute based on user input
To change product price see Changing the price in quote while adding product to cart: magento