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
Thanks!