Cart sorting by product code

  • Posts: 21
  • Thank you received: 0
10 years 2 months ago #194720

-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.0

For us it would make sense to order the cart items by product_code. Is this option implemented?

If not I'd appreciate a hint for php change.

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

  • Posts: 83832
  • Thank you received: 13572
  • MODERATOR
10 years 2 months ago #194756

Hi,

There is no options for that, but it's potentially possible with some code change. But on which page do you want that ?
The cart module ? The cart on the checkout ? The order details page in the backend ? the invoice in the backend ? the order details page on the frontend ? the invoice on the frontend ? The email notifications ?

Last edit: 10 years 2 months ago by nicolas.

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

  • Posts: 21
  • Thank you received: 0
10 years 2 months ago #194822

Yes, to be consistent on all mentioned lists: Priority would be cart module and checkout, than email. Than the others.

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

  • Posts: 83832
  • Thank you received: 13572
  • MODERATOR
10 years 2 months ago #194824

For the cart, you can change the line:

$query='SELECT a.*,b.*,c.* FROM '.hikashop_table('cart').' AS a LEFT JOIN '.hikashop_table('cart_product').' AS b ON a.cart_id = b.cart_id LEFT JOIN '.hikashop_table('product').' AS c ON b.product_id=c.product_id WHERE '.implode(' AND ',$filters).' ORDER BY b.cart_product_modified ASC';
in the file administrator/components/com_hikashop/classes/cart.php to something like this:
$query='SELECT a.*,b.*,c.* FROM '.hikashop_table('cart').' AS a LEFT JOIN '.hikashop_table('cart_product').' AS b ON a.cart_id = b.cart_id LEFT JOIN '.hikashop_table('product').' AS c ON b.product_id=c.product_id WHERE '.implode(' AND ',$filters).' ORDER BY b.cart_product_code ASC';

For the orders, it's the line:
$query = 'SELECT a.* FROM '.hikashop_table('order_product').' AS a WHERE a.order_id = '.(int)$order->order_id;
of the file administrator/components/com_hikashop/classes/order.php that you want to change to something like this:
$query = 'SELECT a.* FROM '.hikashop_table('order_product').' AS a WHERE a.order_id = '.(int)$order->order_id.' ORDER BY order_product_code ASC';

Please note that we cannot guarantee the proper functioning of HikaShop with these modifications and you might have some surprises as the system wasn't designed to work like that. Note also that you'll loose your changes when you update HikaShop.

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

  • Posts: 21
  • Thank you received: 0
10 years 2 months ago #194857

Hi Nicolas,

I tried it, but this solution does not work, the table hikashop_cart_product does not carry the field cart_product_code.

I found a different solution:
I copied components\com_hikashop\views\product\tmpl\cart.php into my template folder templates\favourite\html\com_hikashop\product so it will also work after an update.

Then I added at the beginning of the file (line 11)

function cmp_product_code($a, $b)
{
	return strcmp($a->product_code, $b->product_code);
}

Then in around line 400
usort($this->rows, "cmp_product_code"); // added sort
					foreach($this->rows as $i => $row){ // original code

This works for the cart. I was thinking to maybe modify the table hikashop_cart_product, add a new field cart_product_order and insert the product_code there (or any other field to sort by).

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

  • Posts: 26235
  • Thank you received: 4036
  • MODERATOR
10 years 2 months ago #194874

Hi,

I think that Nicolas wanted to write

ORDER BY c.product_code ASC
Because the product_code value is in the product table.

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.

Time to create page: 0.062 seconds
Powered by Kunena Forum