0
我試圖在Prestashop 1.4.9中檢索購物車模塊中的購物車Id,ajax-cart.js。如何在ajax-cart.js(prestashop模塊)中獲取購物車ID
我找不到任何好的方法來做它,因爲它不存儲在餅乾中。
我試圖在Prestashop 1.4.9中檢索購物車模塊中的購物車Id,ajax-cart.js。如何在ajax-cart.js(prestashop模塊)中獲取購物車ID
我找不到任何好的方法來做它,因爲它不存儲在餅乾中。
您有幾種方法可以從當前訪問者檢索Cart ID,最簡單的方法就是使用Context。
步驟1:打開/modules/blockcart/ajax-cart.js,尋找
$(document).ready(function(){
以下地址:
$.ajax({
type: 'GET',
url: baseDir + 'modules/blockcart/ajax.php' + '?retrieve_cart_id=1',
success: function(result_cart_id)
{
alert(result_cart_id);
/* my_id_cart = parseInt(result_cart_id); Uncomment this line to store the value into a JS variable */
}
});
第2步:創建一個ajax.php文件命名in/modules/blockcart/
以下代碼在裏面
<?php
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../init.php');
$context = Context::getContext();
if (Tools::getValue('retrieve_cart_id') == 1)
echo isset($context->cookie->id_cart) ? (int)$context->cookie->id_cart : 0;
就是這樣!
另外,您可能想要考慮這樣一個事實,即通過在Javascript中檢索此值將由訪問者公開知道。取決於您的代碼和支付模塊的安全性,這可能是一個問題。
事實上,它的工作,但它很麻煩。不管怎麼說,還是要謝謝你!很高興找到它由Prestashop創始人回答:) –