Jump to content

get static token in module


Recommended Posts

Hi,

 

 Normally in product category page I have list of all products. When I click on add to cart page it just adds product to the cart. When I looked close to the html markup I got the link as 



<a title="Add to cart" href="http://localhost/Prestashop/index.php?controller=cart&add=1&id_product=1&token=e4d41a5870a82b183fd62ec4ef762ee2" rel="ajax_id_product_1" class="button ajax_add_to_cart_button exclusive"><span></span>Add to cart</a>


 

Now I just made my own module and in that module I got product names . In that I just added the above html markup by calling the id_product from the database where needed and made my code same like this (made hardcode token by using those numbers)



<a title="Add to cart" href="http://localhost/Prestashop/index.php?controller=cart&add=1&id_product=1&token=e4d41a5870a82b183fd62ec4ef762ee2" rel="ajax_id_product_1" class="button ajax_add_to_cart_button exclusive"><span></span>Add to cart</a>


 

Now when I click on add to cart it does not add products to the cart.

 

When I checked the code in themes/default/product-list.tpl I saw there is $static_token has been used and in my module code I have only used the code, not used the $static_token. So can someone tell me how to get the $static_token value in my module? Any help will be appreciable. Thanks

Link to comment
Share on other sites

 

you can pass variable with token to your smarty array

'token' => Tools::getToken(false)

Hi,

I have my hookLeftColumn code goes like this

 
 public function hookLeftColumn($params) {
    global $cookie, $smarty;
    
    $this->context->controller->addCSS(($this->_path).'css/styles.css', 'all');
    $this->context->smarty->assign(
        array(
          'my_module_name' => Configuration::get('mymodule'),
          'my_module_link' => $this->context->link->getModuleLink('mymodule', 'searchdisplay')
        )
    );
    $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
    $smarty->assign('defaultLanguage', $defaultLanguage);
    $this->_hookCommon($params);


    return $this->display(__FILE__, 'display.tpl');
  }

then how to pass the value to smarty ? Can I do like this?

 
public function hookLeftColumn($params) {
    global $cookie, $smarty;
    $this->context->controller->addCSS(($this->_path).'css/styles.css', 'all');
    $this->context->smarty->assign(
        array(
          'my_module_name' => Configuration::get('mymodule'),
          'my_module_link' => $this->context->link->getModuleLink('mymodule', 'searchdisplay'),
          'token' => Tools::getToken(false)
        )
    );
    $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
    $smarty->assign('defaultLanguage', $defaultLanguage);
    $this->_hookCommon($params);


    return $this->display(__FILE__, 'display.tpl');
  }
Edited by prestashop_newuser (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...