简体   繁体   English

Virtuemart呼叫添加到购物车功能

[英]Virtuemart call add to cart function

I'm new to Virtuemart development. 我是Virtuemart开发的新手。 I have my own template for the product details page: 我在商品详细信息页面上有自己的模板:

templates/myTemplate/html/com_virtuemart/productdetails/myProductDetails.php

I also added a custom field (string) for the product (I will have only one product that can be configured). 我还为产品添加了一个自定义字段(字符串)(我将只能配置一个产品)。 The configuration for that product will be done on the product details page. 该产品的配置将在“产品详细信息”页面上完成。 I have developed a configuration process using jQuery. 我已经开发了使用jQuery的配置过程。

I also added the virtuemart "Add to cart"-Button using the following code: 我还使用以下代码添加了constancemart“添加到购物车” -Button:

echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$this-    
>product));

If the user clicks the "Add to cart"-Button i have to check the configuration. 如果用户单击“添加到购物车”按钮,我必须检查配置。 If the configuration is valid then it should be stored in the custom field i have created for the product. 如果配置有效,则应将其存储在我为产品创建的自定义字段中。 I'd like to store the data to the custom field as a JSON-string. 我想将数据作为JSON字符串存储到自定义字段。 After the data has been saved to the custom field, I'd like to add the product to the cart. 数据保存到自定义字段后,我想将产品添加到购物车。 Then the usual popup dialog should be shown. 然后应显示通常的弹出对话框。 The custom field value should be shown as cart attribute. 自定义字段值应显示为购物车属性。 If the configuration is not valid then there should be some sort of an error output. 如果配置无效,则应该输出某种错误。 The product should not be added to the cart. 该产品不应添加到购物车中。

How can i use the virtuemart "Add to cart" functionality to do this? 我该如何使用constancemart的“添加到购物车”功能来做到这一点?

I also have to check the submitted data in the custom field on the server side. 我还必须在服务器端的自定义字段中检查提交的数据。 What is the best approach to do this? 最好的方法是什么? (Maybe using the checkout page?) (也许使用结帐页面?)

I found the solution to add Items to cart and check the configuration: 我找到了将项目添加到购物车并检查配置的解决方案:

$('#myaddtocart').click(function() {

  var data = "quantity[]="+20+"&virtuemart_product_id[]="+1;

  $.ajax({               

    type: "GET",
    dataType: 'json',
    url: "index.php?option=com_virtuemart&nosef=1&view=cart&task=addJS",
    data: data,
    success: function(data) {

    }

  });

});

This snippet calls the addJS() function located in /com_virtuemart/controllers/cart.php - only quantity and product id must be provided. 此代码段调用/com_virtuemart/controllers/cart.php中的addJS()函数-仅提供数量和产品ID。 Also I used my own button (#myaddtocart) to trigger the click event and add the item to the cart. 另外,我使用了自己的按钮(#myaddtocart)来触发click事件,并将该商品添加到购物车中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM