- Posts: 21
- Thank you received: 0
Cart sorting by product code
11 years 6 months ago #194720
by GunnarB
Cart sorting by product code was created 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.
-- 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.
11 years 6 months ago - 11 years 6 months ago #194756
by nicolas
Replied by nicolas on topic Cart sorting by product code
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 ?
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.
11 years 6 months ago #194822
by GunnarB
Replied by GunnarB on topic Cart sorting by product code
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.
11 years 6 months ago #194824
by nicolas
Replied by nicolas on topic Cart sorting by product code
For the cart, you can change the line:
in the file administrator/components/com_hikashop/classes/cart.php to something like this:
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.
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';
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.
11 years 6 months ago #194857
by GunnarB
Replied by GunnarB on topic Cart sorting by product code
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)
Then in around line 400
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).
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.
11 years 6 months ago #194874
by Jerome
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Replied by Jerome on topic Cart sorting by product code
Hi,
I think that Nicolas wanted to write
Because the product_code value is in the product table.
Regards,
I think that Nicolas wanted to write
Code:
ORDER BY c.product_code ASC
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.167 seconds