[英]Prestashop 1.7 Accesories/Related items hook
I am new to Prestashop and I am trying to create a module so you can put items directly into shopping cart rather than opening quickview. 我是Prestashop的新手,我正在尝试创建一个模块,以便您可以将商品直接放入购物车中,而不用打开quickview。 But I have hard time finding the right hook for it, any ideas?
但是我很难找到合适的方法,有什么想法吗?
Best regards 最好的祝福
edit// Okay, so I figured out the code : 编辑//好的,所以我找出了代码:
{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}
It needs to be on the product.tpl file located at : templates/catalog/_partials/miniature 它必须位于位于以下位置的product.tpl文件中:templates / catalog / _partials / miniature
First of all, how the hell PrestaShop has so poor documentation? 首先,PrestaShop到底有多么糟糕的文档? Hard to understand the fundementals for developing modules.
难以理解开发模块的基本原理。 But I found my way to solve my problem.
但是我找到了解决问题的方法。
My module main .php file : 我的模块主.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');
}
And the JS file that makes the magic happens: 而使神奇的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);
});
}
});
Hope this helps someone out! 希望这可以帮助某人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.