Jump to content



Latest News: (loading..)

* * * * * 2 votes

Product listing sort order


  • Please log in to reply
177 replies to this topic

#161   oxwivi

oxwivi
  • Members
  • 250 posts
  • Real Name:Oxwivi Oxwil

Posted 13 March 2012 - 08:42 AM

Sorry for the late response (was already night the last I replied). So I did this to product_listing.php:
	  <span><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></span>
	</div>
echo '<hr>' . $listing_sql . '<hr>';
<?php
  }
?>
  </div>
I included a few lines of code before and after the line you told me to add to give you an idea.

Anyway, I don't think it worked as expected since this was the result:

Quote

echo '
' . $listing_sql . '
';


#162   spooks

spooks
  • Members
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 13 March 2012 - 10:00 AM

@oxwivi

That line is php, so must go inside the php tags, not outside, which is why I said just before the last ?> which is a php closing tag
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#163   oxwivi

oxwivi
  • Members
  • 250 posts
  • Real Name:Oxwivi Oxwil

Posted 13 March 2012 - 10:46 AM

Oops, got confused by the question mark of the <?php there. So this time:
<?php
  }
  echo '<hr>' . $listing_sql . '<hr>';
?>

And the result:

Quote

select p.products_image, p.products_model, p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from products_description pd, products p left join manufacturers m on p.manufacturers_id = m.manufacturers_id left join specials s on p.products_id = s.products_id, products_to_categories p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '1' and p2c.categories_id = '4' order by p.products_date_added DESC, p.products_model

Edited by oxwivi, 13 March 2012 - 10:47 AM.


#164   spooks

spooks
  • Members
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 13 March 2012 - 09:59 PM

Sorry, did'nt spot for looking before, i think the query your wanting is:

order by p.products_date_added DESC, p.products_model DESC

Edited by spooks, 13 March 2012 - 10:01 PM.

Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#165   oxwivi

oxwivi
  • Members
  • 250 posts
  • Real Name:Oxwivi Oxwil

Posted 14 March 2012 - 09:03 AM

Excellente! It's working as I wanted! Does the DESC thingmajigger imply sort by descending?

Thanks for all the help!

Edited by oxwivi, 14 March 2012 - 09:03 AM.


#166   spooks

spooks
  • Members
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 14 March 2012 - 01:41 PM

Exactly :)
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#167   dolphspeed99

dolphspeed99
  • Members
  • 3 posts
  • Real Name:Bogdan

Posted 02 April 2012 - 09:13 PM

Hello,

I read all this topic and other just like it and I still didn't find the answer to my problem, I hope someone can help me.

On osCommerce 2.2 I need to display the products in the following order: first, in alphabetical order, all the products that have stock quantity more than zero, and then, in alphabetical order, all the product with stock zero.

Can anyone help me with the code that I need to insert in the php files?

Thanks!

PS: I need to mention that I have a private work done on my site and a sort of a watermark automatically appears when a product's stock reaches zero. When I change that quantity to a value higher then zero the watermark automatically disappears. I just need all the products with zero stock to be listed last in the respective type of view (category view, manufacturer view, new products view, specials view, x-sales view)

#168   spooks

spooks
  • Members
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 03 April 2012 - 04:45 PM

You would need to modify index.php to present your first query result to the product_listing.php module (as it does currently) then create a second and represent, it may need a number of alterations due to all the filter options on that page.

Edited by spooks, 03 April 2012 - 04:45 PM.

Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#169   dolphspeed99

dolphspeed99
  • Members
  • 3 posts
  • Real Name:Bogdan

Posted 05 April 2012 - 06:13 AM

I'm not sure what you just said, but I'll give it a try. :)

#170   dolphspeed99

dolphspeed99
  • Members
  • 3 posts
  • Real Name:Bogdan

Posted 28 April 2012 - 08:28 PM

I couldn't do it so I hired a programmer to do this for me

#171   oxwivi

oxwivi
  • Members
  • 250 posts
  • Real Name:Oxwivi Oxwil

Posted 01 May 2012 - 01:50 PM

View Postspooks, on 13 March 2012 - 09:59 PM, said:

order by p.products_date_added DESC, p.products_model DESC

I'm getting back to you about it late, very late, but there's an issue. On the first pages of any category, everything works fine, But going to the subsequent pages would show this top of the list:

Quote

Deprecated: Function ereg() is deprecated in /home/hijabi6/public_html/index.php on line159


#172   bruyndoncx

bruyndoncx

    Problem Thinker

  • Members
  • 2,691 posts
  • Real Name:Carine Bruyndoncx
  • Gender:Female
  • Location:Belgium/ Antwerp/ Turnhout/ Arendonk

Posted 01 May 2012 - 06:09 PM

View Postoxwivi, on 01 May 2012 - 01:50 PM, said:

I'm getting back to you about it late, very late, but there's an issue. On the first pages of any category, everything works fine, But going to the subsequent pages would show this top of the list:

The fix for just this
http://www.oscommerce.com/community/contributions,7394
or migrate to 2.3.1 and fix this and other issues along the way ...
Hava a nice day !
Carine Bruyndoncx


PS frustraded by the lack of feedback
<!--
Did you know 99% of all people benefiting from my posts, won't bother to repay the favor.
Wouldn't it be great if you are part of that exclusive 1% ?
post your findings in my responsive liive shop review thread ?
-->

#173   oxwivi

oxwivi
  • Members
  • 250 posts
  • Real Name:Oxwivi Oxwil

Posted 01 May 2012 - 07:45 PM

View Postbruyndoncx, on 01 May 2012 - 06:09 PM, said:

or migrate to 2.3.1 and fix this and other issues along the way ...

I'm already using osC 2.3.1. I think this issue appeared after using sorting code recommended in this thread. You can check the last two pages for the code I was told to use, if interested.

#174   bruyndoncx

bruyndoncx

    Problem Thinker

  • Members
  • 2,691 posts
  • Real Name:Carine Bruyndoncx
  • Gender:Female
  • Location:Belgium/ Antwerp/ Turnhout/ Arendonk

Posted 01 May 2012 - 09:29 PM

I'm not an ereg / preg expert, I just know it was fixed in 2.3.1, if you find line 159 in index.php on your site, i would expect it to become clearer.
in the source of 2.3.1. you have lots of replacements, so i'd expect you'd find some example of how to change things.

here is some thread  from the forum that might be helpful
http://forums.oscommerce.com/topic/341737-function-ereg-replace-is-deprecated/
Hava a nice day !
Carine Bruyndoncx


PS frustraded by the lack of feedback
<!--
Did you know 99% of all people benefiting from my posts, won't bother to repay the favor.
Wouldn't it be great if you are part of that exclusive 1% ?
post your findings in my responsive liive shop review thread ?
-->

#175   oxwivi

oxwivi
  • Members
  • 250 posts
  • Real Name:Oxwivi Oxwil

Posted 02 May 2012 - 06:15 AM

Well, the changed sort order indeed used ereg:
	if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('^[1-8][ad]$', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
				 $HTTP_GET_VARS['sort'] = 0 . 'd';
				 $listing_sql .=  " order by p.products_date_added DESC, pd.products_name DESC";

However, changing it to !preg and going to next pages (as I described the issue first) does not load the list or the boxes and shows this error:

Quote

Fatal error: Call to undefined function preg() in /home/hijabi6/public_html/index.php on line159

Edited by oxwivi, 02 May 2012 - 06:16 AM.


#176   spooks

spooks
  • Members
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 11 May 2012 - 11:19 PM

@oxwivi

Your mistaken, this thread refers to code that appeared in osC2.2 in order to locate the area that requires alteration, it did not call for the code to be changed,

ie 2.2 has the line:


if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('^[1-8][ad]$', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {

which was unchanged by this mod.

but in 2.3 that line became
 if ( (!isset($HTTP_GET_VARS['sort'])) || (!preg_match('/^[1-8][ad]$/', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {

which should also be left un-changed, what you did was replace the new 2.3 code with old 2.2 code un-neccesarily

Also as the page Bruyndoncx pointed states, you cannot simply replace ereg with preg, you must use the appropriate replacement function and modify the regex.
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#177   oxwivi

oxwivi
  • Members
  • 250 posts
  • Real Name:Oxwivi Oxwil

Posted 12 May 2012 - 06:54 AM

Huh. Admittedly, I didn't read the first post all that carefully. I found that the line you mentioned fit the pattern, hence I went about replacing those. This calls for a review.

Edited by oxwivi, 12 May 2012 - 06:55 AM.


#178   Duroniel

Duroniel
  • Members
  • 45 posts
  • Real Name:Emelie
  • Gender:Female

Posted 04 October 2012 - 09:19 AM

I have read through the thread, but can't seem to find any solution to showing products by latest added first. I have tried all the things I have seen here (and because the first post had some now obsolete code, I tried to just remove the lines removed, etc) So is there anyway to show latest added product first in the product listing? The best I could get was showing the first one added as the first item, but when I switched the page number it went back to alphabetically again.. =/ I have the latest version of osc.