Change fields shown for serials on front end vendor view

  • Posts: 128
  • Thank you received: 2
8 years 1 month ago #251649

-- HikaShop version -- : 2.6.4
-- HikaSerial version -- : 1.10.4
-- Joomla version -- : 3.6.0
-- PHP version -- : 5.5

Hi there,

I'm trying to change the fields that are shown in the views stats.php and export.php whithin hikaserial/serialsmarket

By default this fields are shown for each row:

["serial_data"]=> string(12) "fEwjmVJV5VVB" ["serial_status"]=> string(8) "assigned" ["user_email"]=> string(21) "mail@mail.com" ["order_number"]=> string(4) "B3S9"

I want to remove ["user_email"] and add two order custom fields I have created “order_cust1” and “order_cust2”.

I can do this with a view override but the problem is that I need to do a database query per row/serial. So if I had 1,000 serials there would be 1,000 database queries which I think it is not ideal.

I can see the query performed is the following:
SELECT serial.serial_data,serial.serial_status,hk_user.user_email,hk_order.order_number FROM #__hikaserial_serial AS serial INNER JOIN #__hikashop_order AS hk_order ON serial.serial_order_id = hk_order.order_parent_id INNER JOIN #__hikashop_order_product AS hk_order_product ON (hk_order_product.order_product_id = serial.serial_order_product_id AND hk_order_product.order_id = hk_order.order_parent_id) LEFT JOIN #__hikashop_user AS hk_user ON hk_order.order_user_id = hk_user.user_id WHERE (serial.serial_pack_id = 2) AND (hk_order.order_type = 'subsale') AND (hk_order.order_vendor_id = 2) AND (hk_order_product.product_id = 3)

Is there a way I can modify the query via a plugin event?

Many thanks

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 1 month ago #251654

Hi,

It is something we can add into the next HikaSerial release.
In the "serialmarket/view.html.php" file, at the end of the export function, just before the query is made, it it possible to add such content

JPluginHelper::importPlugin('hikashop');
JPluginHelper::importPlugin('hikaserial');
JPluginHelper::importPlugin('hikamarket');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onBeforeMarketSerialExport', array($pack_id, $product_id, $target_vendor_id, &$select, &$tables, &$filters));
So you will have a trigger that you can use in a plugin.

Please note that it will also require some modifications int the function to provide "named" array.
Like replacing
$select = array(
	'serial.serial_data',
	'serial.serial_status'
);
By
$select = array(
	'serial_data' => 'serial.serial_data',
	'serial_status' => 'serial.serial_status'
);
So in the plugin you check easily the different elements, knowing which table is already link, etc.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 128
  • Thank you received: 2
8 years 1 month ago #251691

Thank you very much, the trigger is enough for now since I know the order of the field I want to swap and then add some additional ones.

This sorts me out for export.php but, would it be possible to do something similar for stats.php? I need to get a couple of custom fields from the hk_order table for each of the serials.

So when looping through

foreach ($this->serials as $serial)

I would have access to
$serial->order_custom1
$serial->order_custom2

from the override file for stats.php

Would this be possible with another trigger? where would it go?

Many thanks!

Last edit: 8 years 1 month ago by sabroso.

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 1 month ago #251704

Hi,

In the stats view, you have access to " $this->orders ".
That is how the order number can be displayed

$this->orders[ (int)$serial->order_id ]->order_number
You can load your custom field directly in a local variable
$query = 'SELECT hk_order.order_id, hk_order.order_custom1, hk_order.order_custom2 FROM '.hikaserial::table('shop.order').' AS hk_order WHERE hk_order.order_id IN ('.implode(',', array_keys($this->orders)).')';
$this->db->setQuery($query);
$my_orders = $this->db->loadObjectList('order_id');
Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 128
  • Thank you received: 2
8 years 1 month ago #251755

Brilliant, thank you very much.

Please add the previously discussed event trigger into view.html.php in the export function for the next Hikaserial version.

Cheers!

Last edit: 8 years 1 month ago by sabroso.

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 1 month ago #251767

Hi,

Sure, the patch for trigger has been already committed yesterday.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Moderators: Obsidev
Time to create page: 0.062 seconds
Powered by Kunena Forum