Jump to content

1.6.1.17 Tri BO par poids du produit


Recommended Posts

Bonjour,

j'aurai souhaité savoir si il existe une manière de trier son catalogue de produits par poids dans le back office, tout comme on peut le faire avec la position, le nom, la référence etc ..

Par avance , merci.

EDIT : Prestashop 1.6.1.17

Xavier

Link to comment
Share on other sites

  • 4 weeks later...

Oui avec un module c'est possible via les hooks actionAdminProductsListingFieldsModifier et actionAdminProductsListingResultsModifier par contre selon votre version de Prestashop, le code a écrire est différent, c'est donc une information importante que vous n'avez pas précisé.

Link to comment
Share on other sites

  • 2 weeks later...

Oui avec un petit module genre

modules/displayproductweight/displayproductweight.php

<?php

if (!defined('_PS_VERSION_')) {
    exit;
}

class DisplayProductWeight extends Module
{
    /**
     * @var array List of hooks used
     */
    public $hooks = [
        'actionAdminProductsListingFieldsModifier',
        'actionAdminProductsListingResultsModifier',
    ];

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->name = 'displayproductweight';
        $this->tab = 'administration';
        $this->version = '1.0.0';
        $this->author = 'Janett';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = [
            'min' => '1.6.1.0',
            'max' => '1.6.99.99', // Because product page has been migrated on 1.7
        ];

        parent::__construct();

        $this->displayName = $this->l('Display product weight');
        $this->description = $this->l('Adds product weight on product listing');
    }

    /**
     * Install Module
     *
     * @return bool
     */
    public function install()
    {
        return parent::install()
            && $this->registerHook($this->hooks); // Yes we can use an array of hook names
    }

    /**
     * Manage the list of fields available in the Product listing.
     *
     * @param array $params
     */
    public function hookActionAdminProductsListingFieldsModifier(array $params)
    {
        // If hook is called in AdminController::processFilter() we have to check existence
        if (isset($params['select'])) {
            $params['select'] .= ', a.weight';
        }

        $params['fields']['weight'] = [
            'title' => $this->l('Weight'),
            'align' => 'text-center',
            'class' => 'fixed-width-xs',
        ];
    }

    /**
     * Manage the display of fields available in the Product listing.
     *
     * @param array $params
     */
    public function hookActionAdminProductsListingResultsModifier(array $params)
    {
        foreach ($params['list'] as $key => $fields) {
            if (isset($fields['weight'])) {
                $params['list'][$key]['weight'] = sprintf('%.3f', $fields['weight'])
                    . ' '
                    . Configuration::get('PS_WEIGHT_UNIT');
            }
        }
    }
}

 

Edited by Janett (see edit history)
Link to comment
Share on other sites

merci pour la réponse rapide. j'ai crée le dossier displayproductweight ansi que le fichier .php sous Filezilla dans le dossier modules mais je ne vois aucun changement même après avoir vider le cache.

Link to comment
Share on other sites

ah oui, en effet, j'avais oublié cette étape .... 

un grand merci, c(est exactement ce que je cherchais ...

merci pour votre aide ainsi que pour votre réactivité.

sinon, une dernière chose, si vous avez une idée, je rencontre également un autre soucis posté ici

https://www.prestashop.com/forums/topic/988113-suppression-fichiers-inutiles/?tab=comments#comment-3118727

Par avance, merci.

Xavier

Link to comment
Share on other sites

  • 4 years later...

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...