Skip to main content

Cart sorting by product code

More
11 years 6 months ago #194720 by GunnarB
-- 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.

More
11 years 6 months ago - 11 years 6 months ago #194756 by nicolas
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: 11 years 6 months ago by nicolas.

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

More
11 years 6 months ago #194822 by GunnarB
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.

More
11 years 6 months ago #194824 by nicolas
For the cart, you can change the line:
Code:
$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:
Code:
$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.

More
11 years 6 months ago #194857 by GunnarB
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)
Code:
function cmp_product_code($a, $b) { return strcmp($a->product_code, $b->product_code); }

Then in around line 400
Code:
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.

More
11 years 6 months ago #194874 by Jerome
Replied by Jerome on topic Cart sorting by product code
Hi,

I think that Nicolas wanted to write
Code:
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.

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

Time to create page: 0.179 seconds
Powered by Kunena Forum