[英]Virtuemart 2 - Add the product image to the “add to cart”-popup
[英]Virtuemart 2 - How i can add item into cart session with virtuemart_product_id?
我的示例代码可尝试使用产品ID自动添加到购物车。 我知道我也需要数量,但是我不知道确切的代码。 用此代码不起作用。
$array = unserialize($_SESSION['__vm']['vmcart']); //read the cart session
$products = $array->products; //list the products
if (array_key_exists('53', $products)) { //if productID 53 then
$cart = VirtueMartCart::getCart();
$quantityPost= 1; //set quantity on 1
$virtuemart_product_id = 1; //set product id on 1
$cart->add(array(1)); //add into cart product with id 1
//$tmpProduct = $this->getProduct((int) $virtuemart_product_id,$quantityPost); //?
echo "Article added!"; } //echo Message
else {
echo "Nothing added!"; } //echo Message
将商品添加到购物车的确切方法类似于遵循其ajax调用功能。
var data = "quantity[]="+qty+"&virtuemart_product_id[]="+pid
//data = encodeURIComponent(data);
jQuery.ajax({
type: "GET",
dataType: 'json',
url: "index.php?option=com_virtuemart&nosef=1&view=cart&task=addJS",
data: data,
success: function(data) {
alert(data);
}
});
如果要从php部分执行此操作,请转到购物车控制器文件并检查功能addJS,然后将相应的参数传递给该功能。
希望这对您有帮助。
请使用VirtueMart API正确处理购物车。 http://forum.virtuemart.net/index.php?topic=125870.msg431290#msg431290
简而言之,默认情况下,VirtueMart使用通过jQuery.getJSON完成的调用,这是Ajax函数的简写。 因此,以上所有这些都是不必要的。 毫无疑问,它也不安全。 您应该使用VM API来检索和存储购物车对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.