Jump to content

Randomise Latest Product


keat

Recommended Posts

My boss wants the homepage to include all latest products, which is straight forward enough.

However, I've complained that it looks diluted, cluttered and quite frankly amateurish.

Is there a way to maybe display only 6 latest products, but have these appear randomly.

I found a thread whereby the OP achieved this with a mod in includes/content/index.inc.php, but this was for V3.

In V6 I'm guessing its in cubecart.class.php ??

 

if ($GLOBALS['config']->get('config', 'catalogue_latest_products')) {
            $latestProducts = $GLOBALS['db']->select('CubeCart_inventory', false, $where, array('date_added' => 'DESC', 'product_id' => 'DESC'), (int)$GLOBALS['config']->get('config', 'catalogue_latest_products_count'));
            if ($latestProducts) {
                foreach ($latestProducts as $product) {
                    $category_data = $GLOBALS['catalogue']->getCategoryStatusByProductID($product['product_id']);
                    $category_status = false;
                    if (is_array($category_data)) {
                        foreach ($category_data as $trash => $data) {
                            if ($data['status'] == 1) {
                                $category_status = true;

 

Rather than a full blown mod, could this be achieved with a small code change?

Link to comment
Share on other sites

You can very easily achieve that using one part of our Enhanced Sorting plugin https://www.cubecart.com/extensions/plugins/enhanced-sorting which allows you to choose exactly which products you want to display and in what order.  Which products are chosen in what order can easily be changed by a simple drag and drop so can be changed whenever you want

In addition you will get a lot of other sorting functionality that comes with the plugin

Ian

Link to comment
Share on other sites

I found this which I'm toying with.

 

 

in classes/cubecart.class.php changing

$GLOBALS['smarty']->assign('LATEST_PRODUCTS', $products);

To:
$lp_rand_keys = array_rand($products, 6); // Make sure there are 3 or more 'featured' products
foreach ($lp_rand_keys as $rand_key) $lp_rand_products[$rand_key] = $products[$rand_key];
$products = $lp_rand_products;
$GLOBALS['smarty']->assign('LATEST_PRODUCTS', $products);

 

Seems to do exactly what I wanted to achieve, now I just need to demo this to the team.

What's betting they make me roll back ??

Link to comment
Share on other sites

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...