Sort by product code

  • Posts: 45
  • Thank you received: 0
9 years 9 months ago #221649

-- HikaShop version -- : 2.6.0. Business

Hi,

I have set a menu to show the products and sort them by product_code. However this results in sorting like:

1
100
1000
1001
105
106
2

Where I would like it to sort numeric like:
1
2
100
105
106
1000
1001

How can I change this?

Thanks!

Last edit: 9 years 9 months ago by Squashtoppertje.

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

  • Posts: 84306
  • Thank you received: 13701
  • MODERATOR
9 years 9 months ago #221655

Hi,

As the product_code is a text field, the sorting is done alphabetically, character by character and thus 100 comes before 2.
Either add trailing zeros so that all the product_codes have the same number of characters, or change the product_code column type to integer in the hikashop_product table of your database via your phpmyadmin and that will do what you want.

The following user(s) said Thank You: Squashtoppertje

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

  • Posts: 45
  • Thank you received: 0
9 years 9 months ago #221813

Hi Nicolas,

Well, changing it to "integer" seemed the easiest solution, but this wasn't the case. I found out that if you duplicate a product the product_code gets some text attached, xxx-copyxxx. Because this field is an integer now, the data can not be stored, which results in removal of both products! Auch... :(

Is there a way to get around this?

(If I use trailing zero's then I need to remove all products before importing, because the poduct_code is needed to match the import with the product. I'd rather not delete all products).

Thanks.

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

  • Posts: 84306
  • Thank you received: 13701
  • MODERATOR
9 years 9 months ago #221825

Hi,

You can change the line:
$newProduct->product_code = $this->template->product_code.'_copy'.rand();
to:
$newProduct->product_code = $this->template->product_code.rand();
in the file administrator/components/com_hikashop/helpers/import.php and that will allow you to copy the products even if the product_code is an integer.

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

Time to create page: 0.059 seconds
Powered by Kunena Forum