繁体   English   中英

为什么我的“添加到购物车”按钮不起作用?

[英]Why does my “add to cart” button not work?

我的网站使用私人电子商务系统,很遗憾,尽管他们的支持团队非常乐于助人,但他们并不特别支持“自定义代码”(例如我需要的代码)。

我正在尝试配置一个“初始”页面(在用户完成订购之前弹出),该页面为用户提供了以半价购买我们的一件T恤的机会,并带有“添加到购物车”允许他们添加它从初始页面添加到他们的购物车。

我曾尝试从标准产品页面复制代码,但是不幸的是,该按钮无法正常工作,而是简单地链接到“#”(可以在下面的代码中看到)。

<form action="includes/cart/add_to_cart.inc.php" method="get" name="addcartform" id="addcartform" onsubmit="return false;">   
<!-- Important hidden inputs -->
<input type="hidden" id="js" name="js" value="false" />
<input type="hidden" id="product_id" name="product_id" value="{product:id}" />
<a id="add_to_cart" style="display:none;" href="#" onclick="{product:add_to_cart_js}" class="generated_button" title="Add To Cart" >
<img src="images/icons/cart_add.png" align="absmiddle" />
<span> Add To Cart </span> </a>
<noscript>
<!-- non javascript -->
<input class="generated_button"  type="submit" value="Add To Cart" name="submit" id="cart_submit" />
</noscript>

放入代码后,我将链接的“显示”更改为“ inline-block”(以便显示),并且我还尝试在此处放入希望用户添加到购物车中的产品ID:

id="product_id" name="product_id" value="{product:id}"

不幸的是,这些都不起作用,并且由于我无法完全(或轻松)访问所需的所有文件,因此,我非常感谢您为解决该问题提供的帮助!

预先感谢,丹

更新:此后,我们电子商务系统的支持团队已向我发送了这段代码来提供帮助,但我不确定如何使用它:

如果您希望通过JavaScript进行更多控制,则可以使用我们在JavaScript中提供>的核心Cart对象。 可以通过(Private eCommerce System)命名空间访问它,实际上,如果您在(Private eCommerce System)站点中打开控制台并键入(Private> eCommerce System),然后按Enter,它将向您返回对象的哪个部分到目前为止,我们已经在javascript中为您提供了核心>系统(这也会随着时间而增加)。 (私人电子商务系统).Cart对象具有子addItem()方法/函数,可在此处使用。

您可以向其传递产品ID以将其添加到购物车:(例如,添加ID为52的产品)Cart.addItem(52); 或者,您可以像这样传递这些完整选项:

Cart.addItem({
productId: 52,
qty: 1,
options: {},
wishlistId: 0,
extraData: "Some detail i want to show to the user"
}, function () {
console.log('This is the callback for when its complete!');
});

因此,如果他们添加按钮或链接,则可以使用jQuery设置该按钮的单击以运行该代码,例如

jQuery(function ($) {
$('.some-button').on('click', function () {
    Cart.addItem(52);
    return false;
});
});

如果换出Javascript按钮并将其替换为无脚本输入字段怎么办?

<form action="includes/cart/add_to_cart.inc.php" method="get" name="addcartform" id="addcartform" onsubmit="return false;">   
<!-- Important hidden inputs -->
<input type="hidden" id="js" name="js" value="false" />
<input type="hidden" id="product_id" name="product_id" value="{product:id}" />
<input class="generated_button"  type="submit" value="Add To Cart" name="submit" id="cart_submit" />
<img src="images/icons/cart_add.png" align="absmiddle" />
<span> Add To Cart </span>
</form>

您可能需要重新设置表单字段的样式和<span>的样式,使其显示“添加到购物车”,以使其看起来正确...

更新:

根据支持团队提供的信息,请尝试将其放在“初始页面”中,而不是上面的表格中。

<div>
<script>
function addTshirtToCart(){
    /* Swap out the 34 for the actual product ID of the tshirt you want to
       add to the basket */
    Cart.addItem(34);
    // You might also want some code here to close the "splash page"
    return false;
}
</script>
<a href="#" id="add_to_cart" onclick="return addTshirtToCart();">
    <img src="images/icons/cart_add.png" align="absmiddle" />
    <span> Add To Cart </span>
</a>
</div>

更新2:

从第二个答案中替换现有的div ,并用适合我的这个替换:

<form action="includes/cart/add_to_cart.inc.php" method="get" name="addcartform" id="addcartform" onsubmit="return false;">
    <input type="hidden" id="js" name="js" value="false">
    <input type="hidden" id="product_id" name="product_id" value="1618">

    <a id="add_to_cart" style="" href="#" onclick="update_cart_content(); return false;" class="generated_button" title="Add To Cart">
    <img src="images/icons/cart_add.png" align="absmiddle">
    <span> Add To Cart </span> </a>
    <noscript>
        <input class="generated_button" type="submit" value="Add To Cart" name="submit" id="cart_submit"/>
    </noscript>
</form>

更新3

要在将T恤添加到购物车时关闭弹出窗口,请尝试将其放在上面的a元素中:

onclick="update_cart_content(); spashBox.close(); return false;"

暂无
暂无

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

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