2

[CE 1.8] We have a bundled product that contains simple products that can be ordered by the foot (qty 1 = 1 foot). Weight for this bundled product is dynamic; the greater the lengths of the components the customer orders, the higher the bundled product's overall weight will be. We want to be able to prevent a customer from adding a bundle configuration that exceeds a certain weight to their cart with an error message returned along the lines of "Product configuration exceeds weight limit".

We could place a quantity limit on each simple product component of the bundled product, but this will not work for us as the components can be ordered individually as simple products and by themselves would not have the same limit as they would grouped in a bundle where weights of each product would be added together.

How might this be accomplished?

1 Answer 1

1

You could write an observer for the event catalog_product_type_prepare_full_options which is the last event in the add to cart process before the product is actually added to the cart and after the bundle options are prepared.

If you throw an exception there, the user will get a message as you desire.

In the observer you have the following parameters available:

  • transport: Transport object for all custom options (but not the bundle options), so you can change tehem in the observer.
  • buy_request: The buyRequest object, you can read it here and still modify it as well. It's a Varien_Object that contains the following relevant attributes:

    • options: Array with the selected options in the form option_id => selection_id[]
    • bundle_option_qty: Array with quantities of the selected options in the form: option_id => qty
  • product: The bundle product

Source and more info: info_buyRequest reference

From the data in $observer->getBuyRequest()->getOptions() and $observer->getProduct() you should be able to derive the total weight and throw an exception accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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