要在結帳頁面上顯示消息,您可以使用任何前端控制器鉤子。我想最有意義的將是displayTop
。我們不會輸出任何HTML到頂部,而只是向控制器的錯誤數組添加消息。
public function hookDisplayTop()
{
$controller = $this->context->controller;
if ($controller->php_self != 'order' && $controller->php_self != 'order-opc') {
return false;
}
/*
You can do custom logic here if you want to display message only
on some conditions or only on specific step of the checkout
*/
$controller->errors[] = $this->l('Some message');
return false;
}
對於彈出的事情變得複雜,因爲:
- 彈出沒有錯誤的顯示區域
- Blockcart使用AJAX調用CartController包括blockcart-ajax.php怪異的邏輯,其它加載一個JSON template文件到輸出數據(???)來做到這一點
單程的負載blockcart module method是使用噸他鉤了actionCartSave
。該鉤子被執行上幾乎所有車的操作,所以我們需要確保我們加入我們的信息當一個產品被添加到購物車,使用AJAX等
public function hookActionCartSave()
{
// If cart doesn't exist or product is not being added to cart in ajax mode - do nothing
if (!$this->context->cart || !Tools::getValue('id_product) || !Tools::getValue('add') || !Tools::getValue('ajax')) {
return false;
}
/*
You can do custom logic here if you want to display message only
on some conditions
*/
$this->context->smarty->assign('mycartpopupmessage', $this->l('Message');
return false;
}
然後,你將不得不修改themes/default-bootstrap/modules/blockcart/blockcart-json.tpl文件將您的消息添加到JSON模板中。
...
"wrappingCost": {$wrapping_cost|json_encode},
"nbTotalProducts": {$nb_total_products|intval},
"total": {$total|json_encode},
{if isset($mycartpopupmessage)}
"mycartpopupmessage": {$mycartpopupmessage|json_encode},
{/if}
....
然後,你需要修改themes/default-bootstrap/js/modules/blockcart/ajax-cart.js並添加以下
if (jsonData.mycartpopupmessage) {
$('#layer_cart .alert-message').html(jsonData.mycartpopupmessage);
$('#layer_cart .alert').removeClass('hidden');
}
else {
$('#layer_cart .alert').addClass('hidden');
}
,最後修改themes/default-bootstrap/modules/blockcart/blockcart.tpl 並添加警報DIV
<div class="alert alert-danger hidden">
<button data-dismiss="alert" type="button" class="close">×</button>
<p>{l s='There is 1 error' mod='mymodule'}</p>
<ol>
<li class="alert-message"></li>
</ol>
</div>
現在你應該在裏面得到一個引導警報一個彈出。
相當多的本地prestashop模塊並沒有(我想)在幾年內更新,因爲它們中的很多很適合大量返工,或至少符合MVC工作流程,這將使像您的修改更簡單。
你的意思是哪兩個意見?查看結帳的第一步以及彈出窗口,詢問您是否要繼續購物或結賬? – TheDrot
@TheDrot我剛剛在我的問題 –