Jump to content
Farris27

Résolu - Tri hors de la configuration pour une catégorie

Recommended Posts

Bonjour à tous, 

Ma cliente demanderais que pour une certaines catégorie et uniquement celle là. Elle veut que j'applique le tri par position tandis que sur les autres pages, je dois laisser par dates de sortie.... 

Mon prestashop est 1.7.4.4 , mysql 5.6 , php 7.1. 

Dans ma configuration j'ai bien entendu mis par date de sortie. Comment pourrais je faire pour son exception ? Quelqu'un a une piste ou je devrais allez modifier ? Merci d'avance 

Edited by Farris27 (see edit history)

Share this post


Link to post
Share on other sites

Pour ceux qui ont le même soucis que moi, voici une solution temporaire . 

Allez dans Tools.php

 public static function getProductsOrder($type, $value = null, $prefix = false)
    {

        switch ($type) {
            case 'by':
                $list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference');
                $value = (is_null($value) || $value === false || $value === '') ? (int)Configuration::get('PS_PRODUCTS_ORDER_BY') : $value;
                $value = (isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'position');
                $order_by_prefix = '';

                if ($prefix) {
                    if ($value == 'id_product' || $value == 'date_add' || $value == 'date_upd' || $value == 'price') {
                        $order_by_prefix = 'p.';
                    } elseif ($value == 'name') {
                        $order_by_prefix = 'pl.';
                    } elseif ($value == 'manufacturer_name' && $prefix) {
                        $order_by_prefix = 'm.';
                        $value = 'name';
                    } elseif ($value == 'position' || empty($value)) {
                        $order_by_prefix = 'cp.';
                    }
                }

                return $order_by_prefix.$value;
                break;

            case 'way':
                $value = (is_null($value) || $value === false || $value === '') ? (int)Configuration::get('PS_PRODUCTS_ORDER_WAY') : $value;
                $list = array(0 => 'asc', 1 => 'desc');

                return ((isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'asc'));
                break;

            case 'customPosition':
                $list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference');
                $value=4;
                $value = (isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'position');
                $order_by_prefix = '';
                if ($prefix) {
                    if ($value == 'id_product' || $value == 'date_add' || $value == 'date_upd' || $value == 'price') {
                        $order_by_prefix = 'p.';
                    } elseif ($value == 'name') {
                        $order_by_prefix = 'pl.';
                    } elseif ($value == 'manufacturer_name' && $prefix) {
                        $order_by_prefix = 'm.';
                        $value = 'name';
                    } elseif ($value == 'position' || empty($value)) {
                        $order_by_prefix = 'cp.';
                    }
                }
                return $order_by_prefix.$value;

            case 'customPosition2':
                $value = 0;
                $list = array(0 => 'asc', 1 => 'desc');

                return ((isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'asc'));
                break;
        }
    }

et dans CategoryController.php : 

  protected function getProductSearchQuery()
    {
        $query = new ProductSearchQuery();
        if($this->category->id ===55){
            $query
                ->setIdCategory($this->category->id)
                ->setSortOrder(new SortOrder('product', Tools::getProductsOrder('customPosition'), Tools::getProductsOrder('customPosition2')))
            ;
        }else{
            $query
                ->setIdCategory($this->category->id)
                ->setSortOrder(new SortOrder('product', Tools::getProductsOrder('by'), Tools::getProductsOrder('way')))
            ; 
        }
      
        
        return $query;
    }

 

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More