diff --git a/classes/Customer.php b/classes/Customer.php index 1ea25ad1d..fd1c47089 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -104,6 +104,9 @@ class CustomerCore extends ObjectModel /** @var boolean is the customer logged in */ public $logged = 0; + /** @var int id_guest meaning the guest table, not the guest customer */ + public $id_guest; + protected $tables = array ('customer'); protected $fieldsRequired = array('lastname', 'passwd', 'firstname', 'email'); diff --git a/classes/Dispatcher.php b/classes/Dispatcher.php index e4107f8c4..06f5de8da 100644 --- a/classes/Dispatcher.php +++ b/classes/Dispatcher.php @@ -186,7 +186,6 @@ class DispatcherCore $_GET['isolang'] = $m[1]; $this->requestURI = substr($this->requestURI, 3); } - // Get and instantiate controller $this->getController(); $controllers = Dispatcher::getControllers(); @@ -376,6 +375,7 @@ class DispatcherCore return $this->controller; $controller = Tools::getValue('controller'); + if (isset($controller) && preg_match('/^([0-9a-z_-]+)\?(.*)=(.*)$/Ui', $controller, $m)) { $controller = $m[1]; diff --git a/controllers/CategoryController.php b/controllers/CategoryController.php index 9c6bf8690..0f42eac80 100644 --- a/controllers/CategoryController.php +++ b/controllers/CategoryController.php @@ -150,10 +150,10 @@ class CategoryControllerCore extends FrontController 'homeSize' => Image::getSize('home') )); - if (isset(self::$cookie->id_customer)) - self::$smarty->assign('compareProducts', CompareProduct::getCustomerCompareProducts((int)self::$cookie->id_customer)); - elseif (isset(self::$cookie->id_guest)) - self::$smarty->assign('compareProducts', CompareProduct::getGuestCompareProducts((int)self::$cookie->id_guest)); + if (isset($this->context->customer->id)) + $this->context->smarty->assign('compareProducts', CompareProduct::getCustomerCompareProducts($this->context->customer->id)); + elseif (isset($this->context->customer->id_guest)) + $this->context->smarty->assign('compareProducts', CompareProduct::getGuestCompareProducts($this->context->customer->id_guest)); } } diff --git a/controllers/CompareController.php b/controllers/CompareController.php index 5cf637970..2fddb3215 100644 --- a/controllers/CompareController.php +++ b/controllers/CompareController.php @@ -47,27 +47,27 @@ class CompareControllerCore extends FrontController { if (Tools::getValue('action') == 'add') { - if (isset(self::$cookie->id_customer)) + if (isset($this->context->customer->id)) { - if(CompareProduct::getCustomerNumberProducts(self::$cookie->id_customer) < Configuration::get('PS_COMPARATOR_MAX_ITEM')) - CompareProduct::addCustomerCompareProduct((int)self::$cookie->id_customer, (int)Tools::getValue('id_product')); + if(CompareProduct::getCustomerNumberProducts($this->context->customer->id) < Configuration::get('PS_COMPARATOR_MAX_ITEM')) + CompareProduct::addCustomerCompareProduct((int)$this->context->customer->id, (int)Tools::getValue('id_product')); else die('0'); } else { - if ((isset(self::$cookie->id_guest) AND CompareProduct::getGuestNumberProducts(self::$cookie->id_guest) < Configuration::get('PS_COMPARATOR_MAX_ITEM'))) - CompareProduct::addGuestCompareProduct((int)self::$cookie->id_guest, (int)Tools::getValue('id_product')); + if ((isset($this->context->customer->id_guest) AND CompareProduct::getGuestNumberProducts($this->context->customer->id_guest) < Configuration::get('PS_COMPARATOR_MAX_ITEM'))) + CompareProduct::addGuestCompareProduct((int)$this->context->customer->id_guest, (int)Tools::getValue('id_product')); else die('0'); } } elseif (Tools::getValue('action') == 'remove') { - if (isset(self::$cookie->id_customer)) - CompareProduct::removeCustomerCompareProduct((int)self::$cookie->id_customer, (int)Tools::getValue('id_product')); - elseif (isset(self::$cookie->id_guest)) - CompareProduct::removeGuestCompareProduct((int)self::$cookie->id_guest, (int)Tools::getValue('id_product')); + if (isset($this->context->customer->id)) + CompareProduct::removeCustomerCompareProduct((int)$this->context->customer->id, (int)Tools::getValue('id_product')); + elseif (isset($this->context->customer->id_guest)) + CompareProduct::removeGuestCompareProduct((int)$this->context->customer->id_guest, (int)Tools::getValue('id_product')); else die('0'); } @@ -92,10 +92,10 @@ class CompareControllerCore extends FrontController if ($product_list = Tools::getValue('compare_product_list') AND $postProducts = (isset($product_list) ? rtrim($product_list,'|') : '')) $ids = array_unique(explode('|', $postProducts)); - elseif (isset(self::$cookie->id_customer)) - $ids = CompareProduct::getCustomerCompareProducts(self::$cookie->id_customer); - elseif(isset(self::$cookie->id_guest)) - $ids = CompareProduct::getGuestCompareProducts(self::$cookie->id_guest); + elseif (isset($this->context->customer->id)) + $ids = CompareProduct::getCustomerCompareProducts($this->context->customer->id); + elseif(isset($this->context->customer->id_guest)) + $ids = CompareProduct::getGuestCompareProducts($this->context->customer->id_guest); else $ids = null; diff --git a/themes/prestashop/js/products-comparison.js b/themes/prestashop/js/products-comparison.js index 8f7e290dd..c9b3a78b5 100644 --- a/themes/prestashop/js/products-comparison.js +++ b/themes/prestashop/js/products-comparison.js @@ -30,7 +30,7 @@ $('document').ready(function(){ var idProduct = $(this).attr('rel').replace('ajax_id_product_', ''); $.ajax({ - url: 'products-comparison.php?ajax=1&action=remove&id_product=' + idProduct, + url: 'index.php?controller=products-comparison&ajax=1&action=remove&id_product=' + idProduct, async: false, success: function(){ return true; @@ -46,7 +46,7 @@ $('document').ready(function(){ if(checkbox.is(':checked')) { $.ajax({ - url: 'products-comparison.php?ajax=1&action=add&id_product=' + idProduct, + url: 'index.php?controller=products-comparison&ajax=1&action=add&id_product=' + idProduct, async: true, success: function(data){ if (data == '0') @@ -63,7 +63,7 @@ $('document').ready(function(){ else { $.ajax({ - url: 'products-comparison.php?ajax=1&action=remove&id_product=' + idProduct, + url: 'index.php?controller=products-comparison&ajax=1&action=remove&id_product=' + idProduct, async: true, success: function(data){ if (data == '0') diff --git a/themes/prestashop/product-compare.tpl b/themes/prestashop/product-compare.tpl index 15d028287..ac6c598c3 100644 --- a/themes/prestashop/product-compare.tpl +++ b/themes/prestashop/product-compare.tpl @@ -31,7 +31,7 @@ var max_item = "{l s='You cannot add more than' js=1} {$comparator_max_item} {l s='product(s) in the product comparator' js=1}"; //]]> -
+