Jump to content

Resolved - Multiple Featured Products


Guest

Recommended Posts

Hi Guys. Is there any easy way to produce two featured products on cubecart version 5?

Would appreciate help if anyone know how.

I think I've identified the file to be edited here:

includes/boxes/randomProd.inc.php

But not sure if there is some code already out there?

Thanks

Link to comment
Share on other sites

Thanks Mate. I've identified the function that is being used:


/**

* Display random products box

*/

private function _displayRandomProduct() {



   $where = $GLOBALS['catalogue']->outOfStockWhere(array('status' => '1'));

   

if (($query = $GLOBALS['db']->select('CubeCart_inventory', false, $where, 'RAND()', '1', false, false)) !== false) {



// try to make sure Random products have images

for($i=0, $max=count($query); $i<$max; $i++) {

$image = $this->getProductImage($query[$i]['product_id']);

$product = $query[$i];

if($image && !strpos($image,"noimage")) {

break;

}

}



$GLOBALS['language']->translateProduct($product);



$product['image'] = $image;



$product['ctrl_sale'] = (!$GLOBALS['tax']->salePrice($product['price'], $product['sale_price']) || !$GLOBALS['config']->get('config', 'catalogue_sale_mode')) ? false : true;





$GLOBALS['catalogue']->getProductPrice($product);

$sale = $GLOBALS['tax']->salePrice($product['price'], $product['sale_price']);

$product['price_unformatted'] = $product['price'];

$product['sale_price_unformatted'] = ($sale) ? $product['sale_price'] : null;

$product['price'] = $GLOBALS['tax']->priceFormat($product['price']);

$product['sale_price'] = ($sale) ? $GLOBALS['tax']->priceFormat($product['sale_price']) : null;



$product['ctrl_purchase'] = true;

if ($product['use_stock_level']) {

// Get Stock Level

$stock_level = $GLOBALS['catalogue']->getProductStock($product['product_id']);

if ((int)$stock_level <= 0) {

// Out of Stock

if (!$GLOBALS['config']->get('config', 'basket_out_of_stock_purchase')) {

// Not Allowed

$product['ctrl_purchase'] = false;

}

}

}

$product['url'] = $GLOBALS['seo']->buildURL('prod', $product['product_id']);

foreach ($GLOBALS['hooks']->load('class.gui.display_random_product') as $hook) include $hook;

$GLOBALS['smarty']->assign('featured', $product);

$content = $GLOBALS['smarty']->fetch('templates/box.featured.php');

$GLOBALS['smarty']->assign('RANDOM_PROD', $content);

}

}




What I thought I could do was to duplicate this function, and duplicate the featurebox php file. I tried the following code but it didn't work. Any help?







private function _displayRandomProducttwo() {



   $where = $GLOBALS['catalogue']->outOfStockWhere(array('status' => '1'));

   

if (($query = $GLOBALS['db']->select('CubeCart_inventory', false, $where, 'RAND()', '1', false, false)) !== false) {



// try to make sure Random products have images

for($i=0, $max=count($query); $i<$max; $i++) {

$image = $this->getProductImage($query[$i]['product_id']);

$product = $query[$i];

if($image && !strpos($image,"noimage")) {

break;

}

}



$GLOBALS['language']->translateProduct($product);



$product['image'] = $image;



$product['ctrl_sale'] = (!$GLOBALS['tax']->salePrice($product['price'], $product['sale_price']) || !$GLOBALS['config']->get('config', 'catalogue_sale_mode')) ? false : true;





$GLOBALS['catalogue']->getProductPrice($product);

$sale = $GLOBALS['tax']->salePrice($product['price'], $product['sale_price']);

$product['price_unformatted'] = $product['price'];

$product['sale_price_unformatted'] = ($sale) ? $product['sale_price'] : null;

$product['price'] = $GLOBALS['tax']->priceFormat($product['price']);

$product['sale_price'] = ($sale) ? $GLOBALS['tax']->priceFormat($product['sale_price']) : null;



$product['ctrl_purchase'] = true;

if ($product['use_stock_level']) {

// Get Stock Level

$stock_level = $GLOBALS['catalogue']->getProductStock($product['product_id']);

if ((int)$stock_level <= 0) {

// Out of Stock

if (!$GLOBALS['config']->get('config', 'basket_out_of_stock_purchase')) {

// Not Allowed

$product['ctrl_purchase'] = false;

}

}

}

$product['url'] = $GLOBALS['seo']->buildURL('prod', $product['product_id']);

foreach ($GLOBALS['hooks']->load('class.gui.display_random_producttwo') as $hook) include $hook;

$GLOBALS['smarty']->assign('featuredtwo', $product);

$content = $GLOBALS['smarty']->fetch('templates/box.featuredtwo.php');

$GLOBALS['smarty']->assign('RANDOM_PRODTWO', $content);

}

}




And have the following code in the box.featureboxtwophp file: 







<div id="featured_product">

  <h3>{$LANG.catalogue.title_feature}</h3>



  <p class="image">

<a href="{$featuredtwo.url}" title="{$featuredtwo.name}">

 <img src="{$featuredtwo.image}" alt="{$featuredtwo.name}" />

</a>

  </p>

  <p class="title"><a href="{$featuredtwo.url}" title="{$featured2.name}">{$featuredtwo.name}</a></p>





</div>

Would love some assistance if poss?

Link to comment
Share on other sites

Bad news is that function doesn't support multiple random products, so you'd have to try something else. Offhand, your best bet will be to try find wherever's calling the function: _displayRandomProduct() and see if you can just get it to run twice, possibly to a different box. Not going to be straightforward though unfortunately, so you might need to ask on the 3rd party forums for help

Link to comment
Share on other sites

Looks good to me. Keep in mind that the mere presence of a class method such as _displayRandomProducttwo() does not mean it will get executed as a matter of course. It needs to get called.

The place to call this new method (a function belonging to a class) is in the method displayCommon() found at about line 271 in the gui.class.php file. After $this->_displayRandomProduct();, add $this->_displayRandomProducttwo();.

Then, in your skin's main.php file, you will need to add {RANDOMPROD_TWO} to the HTML in the layout where you want it to appear.

Then clear the skin cache and try it.

On the other hand, I can see a small hack that adds a question to the General Settings admin page, "How many Featured Products to display?" That number is then sent as $this->_displayRandomProduct($count);. In this method, the count would be used in the query and the rest of the code adjusted to cycle through the number of rows returned.

This would put the (reasonable number of) random products in the same box, but they would be there.

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