我有一些代码计划添加到 Magento 商店中,一旦我让它在测试页面上工作,但不幸的是它在测试页面上不起作用。
Javascript如下:
function plusAddToCart(qty_textbox_id, prodID, highlight_div_id){
var qty = document.getElementById(qty_textbox_id).value;
qty = parseInt(qty) + 1;
document.getElementById(qty_textbox_id).value = qty;
if(qty==0){
$(highlight_div_id).style.backgroundColor = "#f7e9f4";
}else{
$(highlight_div_id).style.backgroundColor = "#ebcde5";
}
$.ajax({
url: "addtocart.php",
data: "prodID="+prodID,
type: "POST",
dataType: 'json',
success: function(data) {
alert("DONE");
}
});
}
</script>
<div style="width:70px; margin:9px auto 0 auto;">
<input type='button' name='plus' onclick='plusAddToCart("qty1", "693", "product_highlight_693");' id="plus" class="cart-plus-minus" value='+'/>
<input name="qty" type="text" id="qty0" readonly="readonly" maxlength="5" value="0" class="quantity-box" />
</div>
PHP:
header("Content-Type: text/html");
require_once 'app/Mage.php';
Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
$userData=Mage::helper('customer')->getCustomer()->getData();
$cart = Mage::getSingleton('checkout/cart');
$yourProId = $_POST['prodID'];
$qty=1;
$params = array( 'product' => $yourProId, 'related_product' => null, 'qty' => $qty );
$product = new Mage_Catalog_Model_Product();
$product->load($yourProId);
$cart->addProduct($product, $params);
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
$message = ('Your cart has been updated successfully.');
Mage::getSingleton('checkout/session')->addSuccess($message);
任何人都可以看到为什么这不起作用的原因吗?