smarty - Prestashop: how to display messages in the cart -
i'm working in quota module prestashop 1.6 , in 1 of features need display message in cart's page , in modal opens when add item cart home page.
i'm working hookcart
hook function, public function hookcart($params)
, in module's class. can instance of controller $this->context->controller
my question how display messages in these 2 views? tried adding them errors
array. can see message not way i'm supposed display. display in alert classes bootstrap.
can me?
to display message on checkout page can use whatever front controller hook want. guess 1 makes sense displaytop
. won't outputting html top add message controller's errors array.
public function hookdisplaytop() { $controller = $this->context->controller; if ($controller->php_self != 'order' && $controller->php_self != 'order-opc') { return false; } /* can custom logic here if want display message on conditions or on specific step of checkout */ $controller->errors[] = $this->l('some message'); return false; }
for popup things messy because:
- popup doesn't have error display area
- blockcart ajax uses weird logic calls cartcontroller includes blockcart-ajax.php loads blockcart module method loads json template file output data (???)
one way use hook actioncartsave
. hook gets executed on pretty cart operations, need make sure adding our message when product added cart, uses ajax etc.
public function hookactioncartsave() { // if cart doesn't exist or product not being added cart in ajax mode - nothing if (!$this->context->cart || !tools::getvalue('id_product) || !tools::getvalue('add') || !tools::getvalue('ajax')) { return false; } /* can custom logic here if want display message on conditions */ $this->context->smarty->assign('mycartpopupmessage', $this->l('message'); return false; }
then have modify themes/default-bootstrap/modules/blockcart/blockcart-json.tpl file add message json template.
... "wrappingcost": {$wrapping_cost|json_encode}, "nbtotalproducts": {$nb_total_products|intval}, "total": {$total|json_encode}, {if isset($mycartpopupmessage)} "mycartpopupmessage": {$mycartpopupmessage|json_encode}, {/if} ....
then need modify themes/default-bootstrap/js/modules/blockcart/ajax-cart.js , add following
if (jsondata.mycartpopupmessage) { $('#layer_cart .alert-message').html(jsondata.mycartpopupmessage); $('#layer_cart .alert').removeclass('hidden'); } else { $('#layer_cart .alert').addclass('hidden'); }
and @ last modify themes/default-bootstrap/modules/blockcart/blockcart.tpl , add alert div
<div class="alert alert-danger hidden"> <button data-dismiss="alert" type="button" class="close">×</button> <p>{l s='there 1 error' mod='mymodule'}</p> <ol> <li class="alert-message"></li> </ol> </div>
now should getting bootstrap alert inside popup.
quite native prestashop modules haven't been (i guess) updated in years lot of them candidates extensive rework or @ least compliant mvc workflow make modifications yours more simple.
Comments
Post a Comment