我想添加一个按钮"添加到购物车"在我的Prestashop 1.6模块中。
请问怎么做?
谢谢:)
答案 0 :(得分:0)
您可以使用以下代码添加添加到购物车的按钮:
<form action="{$urls.pages.cart}" method="post" id="add-to-cart-or-refresh">
<!-- hidden -->
<input type="hidden" name="token" value="{$static_token}">
<input type="hidden" name="id_product" value="{$product.id}" id="product_page_product_id">
<!-- variants, only use if you plan to have variants -->
{include file="catalog/_partials/product-variants.tpl"}
<!-- qty -->
<input
type="text"
name="qty"
id="quantity_wanted"
value="1"
class="input-group"
min="1"
max="9"
aria-label="{l s='Quantity' d='Shop.Theme.Actions'}"
>
<!-- submit -->
<button
class="btn btn-main add-to-cart"
data-button-action="add-to-cart"
type="submit"
>
Add to cart
</button>
</form>
单击此按钮将自动触发ajax调用,以使用输入name="id_product"
表示的产品和输入name="qty"
中的数量更新购物车。
static_token
来自'static_token' => Tools::getToken(false),
,此处https://github.com/PrestaShop/PrestaShop/blob/master/classes/controller/FrontController.php#L512
catalog/_partials/product-variants.tpl