Jump to content

Randomizing The Latest Products


Guest dtmswebmaster

Recommended Posts

Guest dtmswebmaster

I tried looking for the same code as in the CCv3 fix.. but didn't find it.. perhaps because this one is coded differently? :) Has anyone found the fix in the v4 edition? I'd be greatful if you could point me in the right direction with this. Thanks in advanced.

Link to comment
Share on other sites

Guest dtmswebmaster

OK... I think I've found the fix for it.... This is what I did:

Open /yourstore/includes/content/index.inc.php and look around line 54 for:

$cache = new cache('content.LatestProds');

$latestProducts = $cache->readCache();



if (!$cache->cacheStatus) {

	$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY productId DESC LIMIT ".$config['noLatestProds']);

	$cache->writeCache($latestProducts);

}




and change it to:


$cache = new cache('content.LatestProds');



	$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY RAND(".$seed.") DESC LIMIT ".$config['noLatestProds']);

Then save and upload to your store.

This will randomize the Latest Products on the homepage.

Link to comment
Share on other sites

Guest Mikes Web Dot Org

OK... I think I've found the fix for it.... This is what I did:

Open /yourstore/includes/content/index.inc.php and look around line 54 for:

$cache = new cache('content.LatestProds');

$latestProducts = $cache->readCache();



if (!$cache->cacheStatus) {

	$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY productId DESC LIMIT ".$config['noLatestProds']);

	$cache->writeCache($latestProducts);

}




and change it to:


$cache = new cache('content.LatestProds');



	$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY RAND(".$seed.") DESC LIMIT ".$config['noLatestProds']);

Then save and upload to your store.

This will randomize the Latest Products on the homepage.

AWESOME!!! IT WORK FOR ME!!! THANKS A MILLION... But

Can I do the same thing for the Sale items?

MWDOLLC

bestfilipinostore.com = CC4 (Secure)

Link to comment
Share on other sites

Guest topdotter

Yes, using RAND() and a seed value will work. The only caveat in CC4 is that you have to have "Caching Enabled" in your Admin panel set to "No". If not it will still show the same products. The only problem with this is that it turns off caching for the entire store whcih will slow it down. A fix for this is to go to includes/content/index.inc.php and find the lines that say:

if (!$cache->cacheStatus) {

	$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY RAND() LIMIT ".$config['noLatestProds']);

	$cache->writeCache($latestProducts);

}




Replace them with




//if (!$cache->cacheStatus) {

	$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY RAND() LIMIT ".$config['noLatestProds']);

//	$cache->writeCache($latestProducts);

//}

I realize that this isn't the most ideal solution since it's still making a call to the database every time. I'm going to work on code that adjusts the function to pull randomly from cached products.

Link to comment
Share on other sites

Guest Mikes Web Dot Org

Topdotter,

I can't tr that code becuase I altered that for dtsm webmaster and random featured. Thanks though Someone else might use the tip!

Oh and for the record... The other PHP didn't make me have to adjust the cache in gen set.

MWDOLLC

Bestfilipinostore.com CC4 (Secure)

Yes, using RAND() and a seed value will work. The only caveat in CC4 is that you have to have "Caching Enabled" in your Admin panel set to "No". If not it will still show the same products. The only problem with this is that it turns off caching for the entire store whcih will slow it down. A fix for this is to go to includes/content/index.inc.php and find the lines that say:

if (!$cache->cacheStatus) {

	$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY RAND() LIMIT ".$config['noLatestProds']);

	$cache->writeCache($latestProducts);

}




Replace them with




//if (!$cache->cacheStatus) {

	$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY RAND() LIMIT ".$config['noLatestProds']);

//	$cache->writeCache($latestProducts);

//}

I realize that this isn't the most ideal solution since it's still making a call to the server. I'm going to work on code that adjusts the function to pull randomly from cached products.

Link to comment
Share on other sites

Guest dtmswebmaster

The thing that I did was removed the parts in red from the code:

------------------Code--------------------------

$cache = new cache('content.LatestProds');

$latestProducts = $cache->readCache();

if (!$cache->cacheStatus) {

$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY RAND(".$seed.") DESC LIMIT ".$config['noLatestProds']);

$cache->writeCache($latestProducts);

}

------------------End Code-----------------------

I didn't have to make any changes in the admin panel for it to work either.

Link to comment
Share on other sites

Guest Mikes Web Dot Org

:( Confused.... All i know is it worked. thanks again.

The thing that I did was removed the parts in red from the code:

------------------Code--------------------------

$cache = new cache('content.LatestProds');

$latestProducts = $cache->readCache();

if (!$cache->cacheStatus) {

$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 AND cat_id > 0 ORDER BY RAND(".$seed.") DESC LIMIT ".$config['noLatestProds']);

$cache->writeCache($latestProducts);

}

------------------End Code-----------------------

I didn't have to make any changes in the admin panel for it to work either.

Link to comment
Share on other sites

Guest topdotter

Does this run the risk of pulling up the same item twice?

No. The SQL query gets each product only once.

Ideally, what I'd like to do is run a SQL query pull ALL the products that are supposed to be shown in the latest products, cache them all, and have the application then pull the correct number from cache randomly. Best of both worlds.

Link to comment
Share on other sites

Guest dtmswebmaster

Ok.. I was able to randomize the "Sale" Items box that is displayed on the homepage if you have items on a "Sale" price. The same trick can be applied here that was used for the "Latest Products".

Open /YourStore/includes/boxes/saleitems.inc.php

Find this line (around line 33):

## query database

$cache = new cache('boxes.saleItems');

$saleItems = $cache->readCache();



if (!$cache->cacheStatus) {

	$saleItems = $db->select("SELECT name, productId, price, sale_price, price - sale_price as saving FROM ".$glob['dbprefix']."CubeCart_inventory WHERE price > sale_price AND sale_price > 0 AND cat_id > 0 ORDER BY saving DESC",$config['noSaleBoxItems']);

	$cache->writeCache($saleItems);

}




And change it to show like this:




## query database

$cache = new cache('boxes.saleItems');



	$saleItems = $db->select("SELECT name, productId, price, sale_price, price - sale_price as saving FROM ".$glob['dbprefix']."CubeCart_inventory WHERE price > sale_price AND sale_price > 0 AND cat_id > 0 ORDER BY RAND(".$seed.") DESC",$config['noSaleBoxItems']);

Save and upload. That's it! :o Hope this works for ya.

P.S.: If anyone can get this to work with cache enabled, I'd be glad to hear your ideas.

Link to comment
Share on other sites

Guest Mikes Web Dot Org

DTMS,

You are the "MASTER"! It worked like a charm... Thanks so much!

Different subject but any progess on the "more than one word" search box problem?

Thanks again in advance! Maybe you should be on the develpoment team for CC.

Many Thanks

MWDOLLC

BestFilipinoStore

:o

Ok.. I was able to randomize the "Sale" Items box that is displayed on the homepage if you have items on a "Sale" price. The same trick can be applied here that was used for the "Latest Products".

Open /YourStore/includes/boxes/saleitems.inc.php

Find this line (around line 33):

## query database

$cache = new cache('boxes.saleItems');

$saleItems = $cache->readCache();



if (!$cache->cacheStatus) {

	$saleItems = $db->select("SELECT name, productId, price, sale_price, price - sale_price as saving FROM ".$glob['dbprefix']."CubeCart_inventory WHERE price > sale_price AND sale_price > 0 AND cat_id > 0 ORDER BY saving DESC",$config['noSaleBoxItems']);

	$cache->writeCache($saleItems);

}




And change it to show like this:




## query database

$cache = new cache('boxes.saleItems');



	$saleItems = $db->select("SELECT name, productId, price, sale_price, price - sale_price as saving FROM ".$glob['dbprefix']."CubeCart_inventory WHERE price > sale_price AND sale_price > 0 AND cat_id > 0 ORDER BY RAND(".$seed.") DESC",$config['noSaleBoxItems']);

Save and upload. That's it! :D Hope this works for ya.

P.S.: If anyone can get this to work with cache enabled, I'd be glad to hear your ideas.

Link to comment
Share on other sites

Guest dtmswebmaster

Thanks Mikes... never really thought about it though.. I'm good with making changes to current code :o.. not so good at developing it though. If I happen to get better with PHP and the dev team could use a hand.. I may see about joining the wagon, as it were :D

Link to comment
Share on other sites

  • 1 year later...
Guest Mikes Web Dot Org

:yeahhh:

Just want to thank all the CC Crew and Forums and Help I have received. I have closed the Best Filipino Store and opened VG Consoles. I applied the same code below to the newer updated version of CC 4 and it still works like a chram. Just FYI.

MWDO LLC

AKA VG Consoles

L8R

:D

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...