Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Limiting "New Products" Items


zalik22

Recommended Posts

Hi,

 

I am trying to limit the "new products" so that only products with pictures show up on the main page. I went to: catalog/includes/modules/new_products.php and changed the following block of code (the bold part is what I added):

 

// start random new products

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' and p.products_image!= 'noimage1.gif' and p.products_image != 'NULL' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);

// end random new products

 

This still does not work? Can anybody help me out? It's driving me crazy!

 

Thanks!

Link to comment
Share on other sites

please try this:

 

// start random new products
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' and p.products_image<> 'noimage1.gif' and p.products_image is not null and p.products_image <> '' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
} else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' and p.products_image<> 'noimage1.gif' and p.products_image is not null and p.products_image <> '' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products

I wasn't sure if the no image rule applies to the boxes shown on subcategories too, so I changed both queries. The top query is the one that is used on your home page ...

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

please try this:

 

// start random new products
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' and p.products_image<> 'noimage1.gif' and p.products_image is not null and p.products_image <> '' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
} else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' and p.products_image<> 'noimage1.gif' and p.products_image is not null and p.products_image <> '' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products

I wasn't sure if the no image rule applies to the boxes shown on subcategories too, so I changed both queries. The top query is the one that is used on your home page ...

 

Hi Monika,

 

I copied your code but it did not work. Does it matter where the pictures are located? I have mine in a folder within the images folder. Thanks for your help! This is driving me crazy.

Link to comment
Share on other sites

Hi Monika,

 

I copied your code but it did not work. Does it matter where the pictures are located? I have mine in a folder within the images folder. Thanks for your help! This is driving me crazy.

 

can you show me where it should work and what the results are? and please show me a typical line from the database with no pic

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

can you show me where it should work and what the results are? and please show me a typical line from the database with no pic

 

I want this to work on the main page. When people go to my website, there is a "New Products for February." Some of my products have pixelated images, others have a "No image available" picture, and I think some are blank. The names of these pictures are noimage1.gif and trans_pix.gif. If I keep refreshing the website, the new products keep changing, and sometimes they don't have a picture associated with them. It looks unprofession and not very pleasing.

 

I will respond to the post later once I have access to the database. I will show you the line from the database.

 

Thanks!

Link to comment
Share on other sites

Just to put a slight variation on this, I'm trying to take this idea and incorporate into my contrib "Random New Products Shows Specials inc. Subcats".

 

I have the added problem that all my thumbnails use an on-the-fly thumbnailer so that my noimage.jpg is actually (put as code to show it in full): -

 

http://mydomain.com/product_thumb.php?img=images/noimage.jpg&w=80&h=80

 

Here's the code snippet I think is relevant: -

 

// start random new products
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
} else {   // in a category

$cats[] = $new_products_category_id; // current catID as starting value
// put cat-IDs of all cats nested in current branch into $cats array, go through all subbranches
for($i=0;$i<count($cats);$i++) {
$categorie_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$cats[$i] . "'"); 
while ($categorie = tep_db_fetch_array($categorie_query)) {
$cats[] = $categorie['categories_id'];
}
$cats=array_unique($cats); // sort out doubles
}

$num = (int) MAX_DISPLAY_NEW_PRODUCTS;
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id in (".implode(', ', $cats).") and p.products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products

 

I basically want to add code to check if the products image contains "noimage.jpg", or ends in "noimage.jpg&w=80&h=80", and if so skip this product.

 

I know what I want to do, and where I should be doing it, but I just don't know how. Perhaps you could help Monika?

 

P.S. Aplogies if this confuses your topic, zalik22, but hopefully any answer will point the other in the right direction!

Link to comment
Share on other sites

No problem, Marc J. Seems like our problems are similar, but yours is a bit more complex.

 

Monika, here is the row from the products database and my comment from above:

 

products_id products_quantity products_model

38466 10 F-402990

products_image products_msrp products_price products_date_added

images/fragrancex/noimage1.gif 55.0000 13.4000 2006-02-08 20:08:09

products_last_modified products_date_available products_weight

2006-02-08 20:08:09 NULL 0.00

products_status products_tax_class_id manufacturers_id products_ordered

1 0 218 0

 

I want this to work on the main page. When people go to my website, there is a "New Products for February." Some of my products have pixelated images, others have a "No image available" picture, and I think some are blank. The names of these pictures are noimage1.gif and trans_pix.gif. If I keep refreshing the website, the new products keep changing, and sometimes they don't have a picture associated with them. It looks unprofession and not very pleasing.

 

 

THANKS!!!!!!!!

Link to comment
Share on other sites

I sorted my problem, it turns out the on-the-fly thumbnailer doesn't complicate things at all, as it only deals with the HTML output, not the database.

 

So, all my "noimages" products do all have the same entry in the database for their image - 'noimage.jpg', I just modified Monika's query above to suit.

 

Yours is actually the more complex one, zalik22, as your entries vary. It's the subfolder inside /images that are your biggest problem, I think.

 

Wouldn't it be easier to standardise on a noimage image, as I have done, and keep that in /images ? That way all the database entries would be the same.

 

Otherwise, you need an operator for "includes" or "ends in" in the query, much like the solution I thought I needed at first...

Link to comment
Share on other sites

I sorted my problem, it turns out the on-the-fly thumbnailer doesn't complicate things at all, as it only deals with the HTML output, not the database.

 

So, all my "noimages" products do all have the same entry in the database for their image - 'noimage.jpg', I just modified Monika's query above to suit.

 

Yours is actually the more complex one, zalik22, as your entries vary. It's the subfolder inside /images that are your biggest problem, I think.

 

Wouldn't it be easier to standardise on a noimage image, as I have done, and keep that in /images ? That way all the database entries would be the same.

 

Otherwise, you need an operator for "includes" or "ends in" in the query, much like the solution I thought I needed at first...

 

Hi,

 

I will upload the new pictures tonight some time and name them noimage1.gif. Can I just use Monika's suggestion above to make it work? Thanks for the help.

Link to comment
Share on other sites

Hi,

 

I will upload the new pictures tonight some time and name them noimage1.gif. Can I just use Monika's suggestion above to make it work? Thanks for the help.

 

Use Monika's code, but only checking for noimage1.gif : -

 

// start random new products
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' and p.products_image <> 'noimage1.gif' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
} else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' and p.products_image <> 'noimage1.gif' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products

 

Hope this helps.

Link to comment
Share on other sites

Monika and Marc,

 

Thanks so much for all your help! I finally got it to work. I copied the blank image to the images folder and linked all the products with no images to this file in the catalog/images folder. I really appreciate your help. It was driving me crazy and I didn't know what to do.

 

Thanks again!

Link to comment
Share on other sites

All credit goes to Monika, I just kinda hijacked her help :)

 

You guys are cute! I wish I could help more, still feeling yucky (see my blog) and behind on my work ...

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

  • 2 weeks later...
You guys are cute! I wish I could help more, still feeling yucky (see my blog) and behind on my work ...

 

Hi guys,

 

Seems like the code did not filter all (but still reduced the number greatly) the products whose image is "noimage1.gif." Here is my code from the catalog/includes/modules/new_products.php file. Just to clarify, the "noimage1.gif" is located in my catalog/images folder.

 

// start random new products
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' and p.products_image <> 'noimage1.gif' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
} else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' and p.products_image <> 'noimage1.gif' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products [/b]
 }
// start random new products

 

Sorry for all the trouble. Please help!

Link to comment
Share on other sites

I can only imagine it being different entries for the noimage products.

 

If run a query in phpmyadmin you should see if there are typos. Sort by the products_image and check the area where the image name start with "no" (I guess that part was typed in correctly).

 

If you do not have many products, you could even go trough them manually.

 

If you have a ton of products with noimage, let me know and I'll write up some query.

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

I can only imagine it being different entries for the noimage products.

 

If run a query in phpmyadmin you should see if there are typos. Sort by the products_image and check the area where the image name start with "no" (I guess that part was typed in correctly).

 

If you do not have many products, you could even go trough them manually.

 

If you have a ton of products with noimage, let me know and I'll write up some query.

 

Monika, I think I finally got it working. I had to change the noimage1.gif to images/noimage1.gif. I also changed the <> to != , although I don't think this makes a difference. Once again, thanks for all your help and sorry to revisit this topic. THANKS!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...