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.
<?php
//error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
require_once('/var/www/Staging/public_html/app/Mage.php');
umask(0);
Mage::app();
//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;
$product->setPrice($price);
//var_dump($product->debug());
//echo ('success');
?>