Guest Posted July 26, 2012 Share Posted July 26, 2012 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 Quote Link to comment Share on other sites More sharing options...
Toucan Web Design Posted July 26, 2012 Share Posted July 26, 2012 That file's not in CC5, so it's likely you have a different version. In general though, if you want to change the number of something limited showing, you'll need to change the SQL limit, which in this case would be looking for: LIMIT 1 and changing to LIMIT 2 Quote Link to comment Share on other sites More sharing options...
Guest Posted July 26, 2012 Share Posted July 26, 2012 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? Quote Link to comment Share on other sites More sharing options...
Toucan Web Design Posted July 26, 2012 Share Posted July 26, 2012 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 Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted July 26, 2012 Share Posted July 26, 2012 I don't know enough to know if these posts would be of any help to you or not. But just in case.... http://forums.cubecart.com/topic/45287-random-image-in-new-sidebox/page__view__findpost__p__184927__hl__%2Bfeatured+%2Bdirty+%2Bbutter__fromsearch__1 http://forums.cubeca...__fromsearch__1 Quote Link to comment Share on other sites More sharing options...
bsmither Posted July 26, 2012 Share Posted July 26, 2012 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. Quote Link to comment Share on other sites More sharing options...
Guest Posted July 30, 2012 Share Posted July 30, 2012 thank you bsmither. It was calling the function that I missed. Thank you for your support. Got it working now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.