我是Prestashop的新手,我正在尝试创建一个模块,以便您可以将项目直接放入购物车而不是打开quickview。但我很难找到合适的钩子,任何想法?
祝你好运
编辑// 好的,所以我想出了代码:
{if $page.page_name == 'product'}
<form action="{$urls.pages.cart}" method="post">
<input type="hidden" name="token" value="{$static_token}" />
<input type="hidden" value="{$product.id_product}" name="id_product" />
<input type="number" class="input-group form-control" name="qty" min="1"
value="1" />
<button data-button-action="add-to-cart" class="btn grid-cart-btn btn-
primary" {if $product.availability == 'unavailable'}disabled{/if}>
Add to cart</button>
</form>
{/if}
它需要位于product.tpl文件位于:templates / catalog / _partials / miniature
答案 0 :(得分:0)
首先,地狱PrestaShop如何拥有如此糟糕的文档?很难理解开发模块的基本原理。但我找到了解决问题的方法。
我的模块主.php文件:
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
return parent::install()
&& $this->registerHook('displayHeader')
;
}
public function hookDisplayHeader($params)
{
$this->context->controller->addJS(($this->_path).'js/quickbuy.js');
}
制造魔法的JS文件发生了:
$( document ).ready(function() {
var static_token = prestashop.static_token;
var static_url = prestashop.breadcrumb.links[0].url+"cart";
var page_loc = prestashop.page.page_name;
if(page_loc == "product"){
$('article.product-miniature.js-product-miniature').each(function(i,
data) {
var product_id = $(data).attr("data-id-product");
var custom_id = $(data).attr("data-id-product-attribute");
var html = "<form action='"+static_url+"' method='post'>";
html += "<input type='hidden' name='token' value='"+static_token+"'
/>";
html += "<input type='hidden' name='id_product'
value='"+product_id+"' id='product_page_product_id' />";
// html += "<input type='hidden' name='id_customization'
value='"+custom_id+"' id='product_customization_id'/>"; Makes it broken!
html += "<div class='product-quantity clearfix'><div class='qty'>
<input type='number' id='quantity_wanted' class='input-group form-control'
name='qty' min='1' value='1' /></div>";
html += "<div class='add'><button class='btn btn-primary add-to-
cart' data-button-action='add-to-cart' type='submit'>Add to cart</button>
</div></div></form>";
$(this).append(html);
});
}
});
希望这可以帮助别人!