0

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!

Community
  • 1
  • 1
sagescrub
  • 549
  • 1
  • 8
  • 20

1 Answers1

1

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

Community
  • 1
  • 1
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
  • It's a nice website. I am able to create a new – sagescrub Oct 03 '12 at 04:27
  • 1
    Take a look at this post http://stackoverflow.com/questions/9412074/magento-quote-order-product-item-attribute-based-on-user-input/9496266#9496266 (for adding product options)... http://bit.ly/dby1mw (for changing price) – MagePal Extensions Oct 03 '12 at 12:50
  • Thank you for pointing me to this! I tried the solution in the first link for adding product options. It works very well. However in the second link for changing prices, they mention at the top of the page that it doesn't work in versions 1.6.2 or later. Do you know of another solution for this? – sagescrub Oct 04 '12 at 03:42
  • 1
    Take a look at these http://stackoverflow.com/questions/9721583/changing-the-price-in-quote-while-adding-product-to-cart-magento http://stackoverflow.com/questions/5104482/programmatically-add-product-to-cart-with-price-change or http://stackoverflow.com/questions/2798069/creating-a-shopping-cart-price-rule-in-magento-automatically/2798457#2798457 . Please let me know which one work. – MagePal Extensions Oct 04 '12 at 04:58
  • The first link was exactly what I needed. Thanks so much for the help R.S! – sagescrub Oct 05 '12 at 02:08