I currently have a pricing calculation logic being applied when the sales_quote_collect_totals_before event is fired to modify the price depending on options and a few other things. The issue is that right now the price isn't shown to the customer until the item is added to cart (because of the event handler the code is in) but I would like to be able to get the value through an AJAX call from the product page (possibly adding a 'Calculate Pricing' button that would fire the event) and I'm not sure what is the best way to handle this.

My calculation needs all the customisable options selected by the customer in order to properly calculate the price, so an ajax call to a script would work as long as I have access to the choices made by the customer. As a reference, I now have the following bit of code that has all the info I need:

$quote = $observer->getQuote();
foreach ($quote->getAllItems() as $quoteItem) {
    $product = $quoteItem->getProduct();
    $options = $product->getTypeInstance(true)->getOrderOptions($product);

Basically everything from $quoteItem which is a Mage_Sales_Model_Quote_Item object, which also includes the quantity.

Hopefully I'm making the situation clear enough. As a summary this is what I need:

  • Customer selects a few options on a configurable product
  • Customer clicks 'Calculate Price' button
  • AJAX call to a script that receives the product info, including the quantity and all the configurable options selected by the customer
  • Script calculates the price and returns it to be displayed


1 Answer 1


Since you are calculating the price with different options when adding to cart, you might as well make this ready for different combinations on the Front-end for the user.

N × N × ... (R times) = N^R

N being the options. R being how many options chosen.

Depending on how many combinations of options you have for each product. This way you will have the price ready for the user to add to cart, instead of waiting for him to make an extra click for the price to show. which is better for conversions.

For the Magento part, if AJAX is needed:

  1. Create a new extension.
  2. Include a controller and the action to call.
  3. Call it as any other URL.

Following is a reference: http://blog.baobaz.com/en/blog/magento-module-create-your-own-controller

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.