Jump to content

Edit History

Janett

Janett

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');
            }
        }
    }
}

 

Janett

Janett

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 a 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');
            }
        }
    }
}

 

×
×
  • Create New...