Jump to content

voucher code in order list(admin)


mayna

Recommended Posts

hy there,

i'm using prestashop 1.5.3.1 and i'm trying to show in the admin orders list a column with the vouched info used in the order(name or code or description) but i can't seem to figure this one out in the order controller.i'm trying to do this in the adminorderscontroller with $this->fields_list

PLEASE HELP

post-990100-0-02501600-1429255441_thumb.png

post-990100-0-34774200-1429255443_thumb.png

post-990100-0-44836700-1429255557_thumb.png

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

Hi Mayna,

 

You were on the right way :-)

 

Edit, (or even better, override ) file  /controllers/admin/AdminOrdersController.php    (Make backup!!)

 

In function __construct, add the red code:   (Sample code from PS 1.5.4.1, will be very similar to your version)

 

 

public function __construct()
{
  $this->table = 'order';
  $this->className = 'Order';
  $this->lang = false;
  $this->addRowAction('view');
  $this->explicitSelect = true;
  $this->allow_export = true;
  $this->deleted = false;
  $this->context = Context::getContext();
 
  $this->_select = '
      a.id_currency,
      a.id_order AS id_pdf,
      CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
      (SELECT GROUP_CONCAT(`name` separator ", ") FROM `'._DB_PREFIX_.'order_cart_rule` ocrt WHERE a.id_order = ocrt.id_order) as `voucher`,
      osl.`name` AS `osname`,
      os.`color`,
      IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new';
 
  $this->_join = '
      LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)
      LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = a.`current_state`)
      LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND       osl.`id_lang` = '.(int)$this->context->language->id.')';
      $this->_orderBy = 'id_order';
      $this->_orderWay = 'DESC';
     ...
 
  $this->fields_list = array(
      'id_order' => array(
          'title' => $this->l('ID'),
          'align' => 'center',
          'width' => 25
      ),
      'reference' => array(
          'title' => $this->l('Reference'),
          'align' => 'center',
          'width' => 65
      ),
      'voucher' => array(
          'title' => $this->l('Voucher(s)'),
          'align' => 'center',
          'width' => 65
      ),
      'new' => array(
     ...
 
 
 
Result:
post-455771-0-47855700-1429389593_thumb.png
 
 
If your customers have used more than one voucher per order, they will all be shown (the row will expand in height automatically, to make place for them)
 
Result (Sorry, little cheating, image from PS 1.6.0.14, as I was lazy to make new cart rules + orders. Code is exactly the same for PS 1.6, though)
post-455771-0-90845300-1429389827_thumb.png
 
 
Hope this is what you needed,
pascal
 
Link to comment
Share on other sites

  • 8 months later...

 

Hi Mayna,

 

You were on the right way :-)

 

Edit, (or even better, override ) file  /controllers/admin/AdminOrdersController.php    (Make backup!!)

 

In function __construct, add the red code:   (Sample code from PS 1.5.4.1, will be very similar to your version)

 

 

public function __construct()
{
  $this->table = 'order';
  $this->className = 'Order';
  $this->lang = false;
  $this->addRowAction('view');
  $this->explicitSelect = true;
  $this->allow_export = true;
  $this->deleted = false;
  $this->context = Context::getContext();
 
  $this->_select = '
      a.id_currency,
      a.id_order AS id_pdf,
      CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
      (SELECT GROUP_CONCAT(`name` separator ", ") FROM `'._DB_PREFIX_.'order_cart_rule` ocrt WHERE a.id_order = ocrt.id_order) as `voucher`,
      osl.`name` AS `osname`,
      os.`color`,
      IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new';
 
  $this->_join = '
      LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)
      LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = a.`current_state`)
      LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND       osl.`id_lang` = '.(int)$this->context->language->id.')';
      $this->_orderBy = 'id_order';
      $this->_orderWay = 'DESC';
     ...
 
  $this->fields_list = array(
      'id_order' => array(
          'title' => $this->l('ID'),
          'align' => 'center',
          'width' => 25
      ),
      'reference' => array(
          'title' => $this->l('Reference'),
          'align' => 'center',
          'width' => 65
      ),
      'voucher' => array(
          'title' => $this->l('Voucher(s)'),
          'align' => 'center',
          'width' => 65
      ),
      'new' => array(
     ...
 
 
 
Result:
 
 
If your customers have used more than one voucher per order, they will all be shown (the row will expand in height automatically, to make place for them)
 
Result (Sorry, little cheating, image from PS 1.6.0.14, as I was lazy to make new cart rules + orders. Code is exactly the same for PS 1.6, though)
 
 
Hope this is what you needed,
pascal

 

 

Thx. 

When I want to show the code with cart_rule. I used something like this:

...
	a.id_currency,
		a.id_order AS id_pdf,
		CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
		(SELECT GROUP_CONCAT(`code` separator ", ") FROM `'._DB_PREFIX_.'cart_rule` ocrt WHERE a.id_cart_rule = ocrt.id_cart_rule) as `voucher`,
		osl.`name` AS `osname`,
		os.`color`,
		IF((SELECT so.id_order FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer AND so.id_order < a.id_order LIMIT 1) > 0, 0, 1) as new,
		country_lang.name as cname,
		IF(a.valid, 1, 0) badge_success';
...

And this doesn't work :/ Can you help you ?

Link to comment
Share on other sites

  • 2 months later...
  • 3 years later...
On 2/24/2016 at 10:50 AM, hammerleit said:

@PascalVG

btw: is there any possibility to Show the voucher code instead of the voucher name?

In PS 1.6, the used cart rule / voucher ID associated to an order is saved on the table order_cart_rule, but in this table is stored only the voucher name, not the voucher code. The code is stored on table cart_rule, so you need to obtain first the cart rule ID associated with the order, and go to the cart_rule table and look for the code asociated with that ID.

I've added a column with the voucher code used in admin order list using overrides, that is recommended, so the code changes (actually the way in which it is implemented), with respect to the initial examples of this thread:
 

class AdminOrdersController extends AdminOrdersControllerCore
{

    public function __construct() {

        parent::__construct();

		$this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'order_cart_rule` ocrt ON (ocrt.`id_order` = a.`id_order`)';
        $this->_select = 'ocrt.`id_cart_rule` AS `coupon_id`,'.$this->_select;

        $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'cart_rule` cr ON (cr.`id_cart_rule` = ocrt.`id_cart_rule`)';
        $this->_select = 'cr.`code` AS `voucher_code`,'.$this->_select;

		$this->fields_list['voucher_code'] = array('title' => 'Voucher Code', 'align' => 'center', 'width' => 65, 'havingFilter' => true );

	}

}

 

It should be placed on a new file called AdminOrdersControllers.php, in folder /override/controllers/admin


Regards,
Daniel

Edited by DannetStudio (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...