Prestashop 1.7 Accesories/Related 项目挂钩

Prestashop 1.7 Accesories/Related items hook

我是 Prestashop 的新手,我正在尝试创建一个模块,以便您可以将商品直接放入购物车而不是打开快速查看。但是我很难找到合适的钩子,有什么想法吗?

此致

编辑// 好的,所以我想出了代码:

{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}

它需要在位于 templates/catalog/_partials/miniature

的 product.tpl 文件中

首先,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);
    });
}
});

希望这对某人有所帮助!