I want to calculate a price based on the dimensions of a product. Customers can set these dimensions in a custom option field. The price is set per cm2.

When a customer is adding a product to the shopping cart, the price is calculated with the following code. This is working.

    public function changingPrice(Varien_Event_Observer $observer){

        $event = $observer->getEvent();
        $quote_item = $event->getQuoteItem();
        $product = $quote_item->getProduct();
        $quantity = $product->getQty();
        $options = $this->getProductOptions($quote_item);

        if(sizeof($options) > 0)
            foreach($options as $option)
                if($option['label'] == 'Hoogte in cm')
                    $heightVal =  $option['value'];
                if($option['label'] == 'Breedte in cm')
                    $widthVal =  $option['value'];

            $meter = ($heightVal*$widthVal)*$product->getPrice();
            $new_price = $meter*$quantity;

I'm wondering how to calculate the price live on input change?

  • You will need to use Javascript to accomplish this. – Renon Stewart Jul 8 '15 at 14:56
  • Yes, i know. There is a function named Product.Config(). Do I have to do this with this function? Or with (for example) jquery, outside the Magento javascript? – Royw Jul 9 '15 at 7:19