WKoppel WKoppel - 1 year ago 331
Smarty Question

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. But I have hard time finding the right hook for it, any ideas?

Best regards

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>

It needs to be on the product.tpl file located at : templates/catalog/_partials/miniature

Answer Source

First of all, how the hell PrestaShop has so poor documentation? Hard to understand the fundementals for developing modules. But I found my way to solve my problem.

My module main .php file :

public function install()
  if (Shop::isFeatureActive())

  return parent::install() 
    && $this->registerHook('displayHeader')

public function hookDisplayHeader($params)

And the JS file that makes the magic happens:

$( 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"){
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>

Hope this helps someone out!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download