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

问题描述 投票:0回答:2

我的网站使用私人电子商务系统,不幸的是,虽然他们的支持团队非常有帮助,但他们并不特别支持“自定义代码”,例如我需要的代码。

我正在尝试配置一个“启动”页面(在用户完成订单之前弹出),该页面为用户提供半价购买我们的一件 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>

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

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

不幸的是,这一切都不起作用,并且由于我无法完全(或轻松)访问我需要的所有文件,我真的很感谢任何帮助解决这个问题的帮助!

提前致谢, 丹

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

如果您想通过 javascript 进行更多控制,您可以使用我们在 javascript 中提供的核心 Cart 对象。它可以通过(私人电子商务系统)命名空间访问,并且在 事实上,如果您在(私人电子商务系统)站点中打开控制台并输入(私人 > 电子商务系统)并按 Enter 键,它将向您返回一个对象,其中显示我们在到目前为止,(这将增加 时间也)。 (私人电子商务系统).Cart 对象有一个可以在此处使用的子 addItem() 方法/函数。

您可以将产品 ID 传递给它以将其添加到购物车:(例如添加 ID 为 #52 的产品) 购物车.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;
});
});
php html e-commerce
2个回答
1
投票

如果您更换 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;"

0
投票

请让您的开发团队解决此问题,或向我们提供不同的函数来调用“添加到购物车”按钮。

© www.soinside.com 2019 - 2024. All rights reserved.