Jump to content

Feature Needed - Drop down choice filter module (search)


Recommended Posts

  • 3 weeks later...

lol

i buyed that one to spare me some time, but the hell in there made me loose a lot more.
As it is really badly programmed, heavy and even a bit buggy I had to recode a new one, wich now works flawlessly.

So try to avoid it :)

Link to comment
Share on other sites

  • 3 months later...

hello
it is not available as i don't have time to make a proper release but the main concept behind it is to make a new gette class for products wich take into account the url parameters.
You'll have to modifiy every call a a product listing to use the new and filterable way to gets products :

first i would use something like this

   function     __construct()
   {
       $this->name = 'GetProducts';
       $this->args = $this->genArgsTab();
   }

   function    genArgsTab()
   {
       $args = array();

       $args['id_category'] = intval(Tools::getValue('id_category'));        
       $args['id_manufacturer'] = intval(Tools::getValue('id_manufacturer'));
       // TODO manage taxes properly
       $args['price_min'] = intval(Tools::getValue('price_min') / 1.196);
       $args['price_max'] = intval(Tools::getValue('price_max') / 1.196);
       $args['condition'] = (Tools::getValue('condition') == 'used') ? 'used' : 'new';

       // here i have more filters like features & attributes

       $args['subcat'] = array();
       $subcats = Tools::getValue('subcat');
       if ($subcats != '')
           foreach ($subcats as $ks => $vs)
               if ($vs != '')
                   $args['subcat'][intval($ks)] = intval($vs);

       return $args;
   }



then listing products with something like

$join = '';
       $c_cats = '';
       $currentDate = date('Y-m-d H:m:i');
       $c_new = '';
       $c_price_drop = '';
       if ($this->args['id_category'])
       {
               $c_cats = ($this->args['id_category']) ? "AND cp.id_category = '".intval($this->args['id_category'])."'" : '';
               $join .= 'LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`';
       }
       if (is_array($this->args['subcat']))
       {
           foreach ($this->args['subcat'] as $ks => $subcat)
           {
               $ks = intval($ks);
               $join .= 'INNER JOIN `'._DB_PREFIX_.'category_product` cps'.$ks.' ON (p.`id_product` = cps'.$ks.'.`id_product` 
               AND cps'.$ks.'.id_category = \''.intval($subcat).'\')';
           }
       }
       if (isset($this->args['price_drop']) && $this->args['price_drop'] == 1)
       {
           $c_price_drop = 'AND (p.`reduction_price` > 0 OR p.`reduction_percent` > 0)
           AND (p.`reduction_from` = p.`reduction_to` OR (p.`reduction_from` <= \''.pSQL($currentDate).'\' AND p.`reduction_to` >= \''.pSQL($currentDate).'\'))';

       }
       if (isset($this->args['new']) && $this->args['new'] == 1)
       {
           $c_new = 'AND DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0';
       }
       if (isset($this->args['sales']) && $this->args['sales'] == 1)
       {
           $join .= ' INNER JOIN `'._DB_PREFIX_.'product_sale` psale ON (psale.id_product = p.id_product)';
           $orderBy = 'sale_nbr';
           $orderByPrefix = 'psale';
       }

               $c_manufacturer = ($this->args['id_manufacturer']) ? "AND p.id_manufacturer = '".intval($this->args['id_manufacturer'])."'" : '';
       $c_price_min = ($this->args['price_min']) ? "AND p.price >= '".intval($this->args['price_min'])."'" : '';
       $c_price_max = ($this->args['price_max']) ? "AND p.price <= '".intval($this->args['price_max'])."'" : '';


       $sql = '
           SELECT DISTINCT p.`id_product`
           FROM `'._DB_PREFIX_.'product` p
           '.$join.'
           WHERE 1=1

           '.$c_cats.'
           '.$c_manufacturer.'
           '.$c_price_min.'
           '.$c_price_max.'
           '.$c_price_drop.'
           '.$c_new.'
           '.($active ? ' AND p.`active` = 1' : '').'
           AND p.quantity > 0
           AND p.`id_product` IN (
               SELECT cp.`id_product`
               FROM `'._DB_PREFIX_.'category_group` cg
               LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
               WHERE cg.`id_group` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').'
           )';
       $result = Db::getInstance()->ExecuteS($sql);



I know it is not a full working code i am giving you but has i run an heavily modified prestashop i would make no sense to give the complete files.

There is more : this could not be implemented as a module and must override prestashop core. This would a great thing to integrate natively !!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...