Jump to content

Voucher Column Filterable in the Order Listing


morgue86

Recommended Posts

Hi to all,

i've created a module that add a voucher column in the admin order listing. The voucher is displayed correctly but if I want to filter the results the filter doesn't work.
I added filter_key but with no results.
Can you help me? thanks a lot

This is my module code

 

    public function hookActionAdminOrdersListingFieldsModifier($params)
    {
        if( isset( $params['select'] ) ){
            $params['join'] .= ' LEFT JOIN `'._DB_PREFIX_.'order_cart_rule` AS ocr ON (ocr.`id_order` = a.`id_order`) LEFT JOIN `'._DB_PREFIX_.'cart_rule` AS cr ON (ocr.`id_cart_rule` = cr.`id_cart_rule`) ';
            $params['select'] .= ', GROUP_CONCAT(DISTINCT cr.`code` SEPARATOR \'\n\') AS voucher';
            $params['group_by'] .= ' GROUP BY a.`id_order` ';
           
            $voucher = array(
                'title' => $this->l('Voucher'),
                'filter_key' => 'ps_cart_rule!code'
            );
            $params['fields'] = self::array_insert( $params['fields'], [ 'voucher' => $voucher ], 'cname', 'after' );

            unset( $params['fields']['payment'] );
            unset( $params['fields']['company'] );
        }
    }

 

protected static function array_insert( $array, $pairs, $key, $position = 'after' ) {
        $key_pos = array_search( $key, array_keys( $array ) );
        if ( 'after' == $position )
            $key_pos++;
        if ( false !== $key_pos ) {
            $result = array_slice( $array, 0, $key_pos );
            $result = array_merge( $result, $pairs );
            $result = array_merge( $result, array_slice( $array, $key_pos ) );
        }
        else {
            $result = array_merge( $array, $pairs );
        }
        return $result;
    }

 

Link to comment
Share on other sites

  • 1 year later...

This might help you... https://dev.to/kpodemski/display-extra-column-in-the-prestashop-grid-157j

Except the more I read on the subject, it appears the back office orders in Prestashop have not been updated to use symphony, so the "grid" filtering does not work yet: https://stackoverflow.com/questions/63637435/hook-action-order-grid-not-work-in-prestashop-1-7

Which means... there's no obvious answer right now

Edited by squivo (see edit history)
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...