Reputation: 81
My Magento version -> 1.6.2
I am using an external php file that receives the $product_id
and $my_price
parameter via jQuery post.
var priceNewValue = XX; // My custom price value
var product_id = optionsPrice.productId; // Product id
jQuery.post("http://flyingcakes.in/eshop/ajaxPriceCal.php", { price: priceNewValue, pid: product_id });
On my "ajaxPriceCal.php" page, I catch the values:
$product_id = $_POST['pid'];
$my_price = $_POST['price'];
Now I want Magento to set the price of this product ($product_id
) equal to $my_price
.
So that:
How should I do this?
Upvotes: 1
Views: 2412
Reputation: 8050
You have to build an observer that catches the add-to-cart event sales_quote_add_item and then you can do the php-stuff in the observer to change the price for only this product with $observer->getEvent()->getQuoteItem()->setOriginalCustomPrice([your price]).
Its explained in more detail on this page: Changing the price in quote while adding product to cart: magento.
This worked for me...
Upvotes: 2
Reputation: 563
You need to load the product as -
$_product=Mage::getModel('catalog/product')->load($product_id);
$_product->setPrice($my_price);
$_product-Save();
Hope this will help you.
Upvotes: 0