ordering products on listing page

  • Posts: 155
  • Thank you received: 4
9 years 6 months ago #234238

-- HikaShop version -- : latest
-- Joomla version -- : 3.5

Hallo.

I want to order my products on the product listing page by:

1st criteria
product_created (first the newest product) --- Does not work because when i modify an old product i puts on first place

2nd criteria
product_quantity is not 0 --- if there is no item on stock i need on after all available products (i want them to be still in the listing but in the end)

is there a solution ?

Thanks for your reply

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

  • Posts: 13201
  • Thank you received: 2322
9 years 6 months ago #234257

Hi,

You can potentially set the menu/module ordering option on "product_created" field and set an ascendant ordering.
Then use this kind of code to put the products with a 0 quantity at the end of the listing:

$emptyRows = array();
foreach($this->rows as $k => $row){
	if($row->product_quantity == '0'){
		$emptyRows[$k] = $row;
		unset($this->rows[$k]);
	}
}
foreach($emptyRows as $emptyRow){
	array_push($this->rows, $emptyRow);
}

This can be placed in the view "product / listing_div" or another one based on your settings. And this have to be put before the "foreach" listing the products, this one:
foreach($this->rows as $row){

But this solution will work if all the products are displayed in one page, else it will just order them by pages.

So if you have many pages in your listings, it will potentially require to create a plugin to change the ordering of the products.
A plugin based on the trigger: onBeforeProductListingLoad
www.hikashop.com/support/documentation/6...reProductListingLoad

The following user(s) said Thank You: Cattelan

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 6 months ago #234262

Hi,

There is no multiple criteria ordering in HikaShop but there is a solution.

First, regarding the product_created column, I don't see why that would happen. It definitely doesn't on our end. It's the product_modified column which is updated when you update the product information.

For the product_quantity, what you can do is create a mass action with a cron trigger (like every hour) via the menu System>Mass actions with a filter on the product_quantity column equal to 0 and an action "update the values" on the "product_created" column equal to 999999999 so that the products would be moved to the end of the listing when the quantity would reach 0 within the hour.

The following user(s) said Thank You: Cattelan

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

  • Posts: 155
  • Thank you received: 4
9 years 6 months ago #234296

Thanks for your quick and detailed answer.
I will try your solution and come back to give detailed feedback.

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

  • Posts: 155
  • Thank you received: 4
9 years 6 months ago #234297

Thanks for your quick reply and for the solution i will try it and get back to give feedback.

nicolas wrote: Hi,

First, regarding the product_created column, I don't see why that would happen. It definitely doesn't on our end. It's the product_modified column which is updated when you update the product information.


I understand your point. I would like to understand why when i modify a product this happens. My setting in the configuration is "product_created" .

You can check it here ilmondodiwit.com/shop/gioielli/13-anelli.html .

when you hover the images you can see the product id from the new ones is above number 15000. There are some product with update images or details which have the id 1951. i stop editing this category until monday so you can check. it's the third item from the left.

what can this cause ?

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 6 months ago #234308

Hi,

I don't know. But what I can say is that I don't see the product_created value change when I modify the product through the product edition interface
Do you ? I don't think it will do it on your website either.

Updating the products with a CSV with the product_created value provided could change it because of the CSV, or a mass action could be there changing the product_created value for some reason, or a 3rd party plugin.

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

  • Posts: 193
  • Thank you received: 76
9 years 6 months ago #234337

nicolas wrote: Hi,
First, regarding the product_created column, I don't see why that would happen. It definitely doesn't on our end. It's the product_modified column which is updated when you update the product information.

As far as I remember, product_created column is updated by product import and Product Cron Update plugin.

@Cattelan
I created a custom field date_created_order containing product_created value prefixed with 9 or 8 (product out of stock) and set menu item to order products by this field.

1. Create custom field as at picture 1
2. Create mass action as at picture 2
Value for operation in Actions section is:
CONCAT(IF(`product_quantity`=0 ,'8','9'), CAST(product_created AS CHAR))
3. click Process button to update custom field for all products
4. set ordering in menu to date_created_order at Products Options tab

If you have a lot of products and you know how, consider adding index to date_created_order column or convert this column to VARCHAR

Attachments:
Last edit: 9 years 6 months ago by korzo.
The following user(s) said Thank You: Cattelan

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

Time to create page: 0.094 seconds
Powered by Kunena Forum