Ejemplo n.º 1
0
 /**
  * Display ajax content (this function is called instead of classic display, in ajax mode)
  */
 public function displayAjax()
 {
     // Add or remove product with Ajax
     if (Tools::getValue('ajax') && Tools::getValue('id_product') && Tools::getValue('action')) {
         if (Tools::getValue('action') == 'add') {
             $id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare : false;
             if (CompareProduct::getNumberProducts($id_compare) < Configuration::get('PS_COMPARATOR_MAX_ITEM')) {
                 CompareProduct::addCompareProduct($id_compare, (int) Tools::getValue('id_product'));
             } else {
                 die('0');
             }
         } else {
             if (Tools::getValue('action') == 'remove') {
                 if (isset($this->context->cookie->id_compare)) {
                     CompareProduct::removeCompareProduct((int) $this->context->cookie->id_compare, (int) Tools::getValue('id_product'));
                 } else {
                     die('0');
                 }
             } else {
                 die('0');
             }
         }
         die('1');
     }
 }
 public function preProcess()
 {
     parent::preProcess();
     //Add or remove product with Ajax
     if (Tools::getValue('ajax') and Tools::getValue('id_product') and Tools::getValue('action')) {
         if (Tools::getValue('action') == 'add') {
             $id_compare = isset(self::$cookie->id_compare) ? self::$cookie->id_compare : false;
             if (CompareProduct::getNumberProducts($id_compare) < Configuration::get('PS_COMPARATOR_MAX_ITEM')) {
                 CompareProduct::addCompareProduct($id_compare, (int) Tools::getValue('id_product'));
             } else {
                 die('0');
             }
         } elseif (Tools::getValue('action') == 'remove') {
             if (isset(self::$cookie->id_compare)) {
                 CompareProduct::removeCompareProduct((int) self::$cookie->id_compare, (int) Tools::getValue('id_product'));
             } else {
                 die('0');
             }
         } else {
             die('0');
         }
         die('1');
     }
 }