I have a script that dynamically calculates price on the product detail page and then I need to save the price so that it is correct in the user's cart when checking out. I have the following in my ajax request but as you probably know it saves in the system as the configurable product price. Due to the possibility of many users adding the same product to cart at the same time, I need a better way to save this price. Any suggestions? Preferably save as per item price then calculate with quantity.

Or even BETTER idea... since the prices are based off vendors and tier prices, I could dynamically create a shopping cart discount and apply it.

//error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

//ensure that the value is legitimate
if($_POST && is_numeric($_POST['value'])){
    $price = $_POST['price'];

//pass this in your ajax call for the add button
if($_POST && is_numeric($_POST['product_id'])){
    $product_id = $_POST['product_id'];

$helper = Mage::helper('core'); //for translation

$block = new Mage_Catalog_Block_Product_View(); // not best practice, but neither are standalones
$product =  Mage::getModel('catalog/product')->load($product_id); // no need to use the _ here, it's not protected/private;


//echo ('success');

1 Answer 1


You don't need to save price for product.

Just pass your dynamic price with in post parameter and set your dynamic price for product in observer event.

You can use an observer class to listen to checkout_cart_product_add_after, and use a product’s “Super Mode” to set custom prices against the quote item.

In your /app/code/local/{namespace}/{yourmodule}/etc/config.xml:


And then create an Observer class at /app/code/local/{namespace}/{yourmodule}/Model/Observer.php

 class <namespace>_<modulename>_Model_Observer
    public function modifyPrice(Varien_Event_Observer $obs)
        // Get the quote item
        $item = $obs->getQuoteItem();
        // Ensure we have the parent item, if it has one
        $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
        // Load the custom price
        $price = "your custom price logic";
        // Set the custom price
        // Enable super mode on the product.


Your Answer

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

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