Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Limiting the number of featured products displayed and randomising

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 11-30-2007, 03:24 AM
  wardworth's Avatar 
wardworth wardworth is offline
 

Advanced Member
  
Join Date: Sep 2007
Posts: 78
 

Default Limiting the number of featured products displayed and randomising

Hi,

I would like to limit the number of featured products displayed on a subcategory and then randomise this limit so that different featured products (from that category) are displayed per refresh.

For example, I would like only 6 featured products to show but have a different 6 featured products displaying on each refresh.

Any ideas?
__________________
:: Wardworth Ltd
:: X-Cart 4.1.8
Reply With Quote
  #2  
Old 01-25-2008, 10:05 AM
  SpinyMan's Avatar 
SpinyMan SpinyMan is offline
 

Advanced Member
  
Join Date: Jan 2008
Posts: 30
 

Default Re: Limiting the number of featured products displayed and randomising

Quote:
Originally Posted by wardworth
I would like to limit the number of featured products displayed on a subcategory and then randomise this limit so that different featured products (from that category) are displayed per refresh.

For example, I would like only 6 featured products to show but have a different 6 featured products displaying on each refresh.

Any ideas?

Hi,

open "featured_products.php" and add 2 lines of code
Quote:
$search_data["products"]["sort_condition"] = "RAND() DESC";
$objects_per_page = 6;
before a line
Quote:
$REQUEST_METHOD = "GET";

it will show 6 random products with the pages to other featured products (if more exists).
If this variant doesn't meen your wish try this one:

put this code
Quote:
shuffle($products);
array_splice($products,6);
before this line:
Quote:
$smarty->assign("f_products",$products);
__________________
Regards,
SpinyMan

X-Cart Templates Store -
http://www.x-cart-customization.com/shop/

X-Cart Customization Services -
http://www.x-cart-customization.com/
Reply With Quote

The following user thanks SpinyMan for this useful post:
sales@weddingaccents.com (05-12-2010)
  #3  
Old 01-27-2008, 11:42 PM
  wardworth's Avatar 
wardworth wardworth is offline
 

Advanced Member
  
Join Date: Sep 2007
Posts: 78
 

Default Re: Limiting the number of featured products displayed and randomising

That works a charm. Excellent! Thank you very much Spinyman
__________________
:: Wardworth Ltd
:: X-Cart 4.1.8
Reply With Quote
  #4  
Old 02-12-2008, 06:31 AM
  yamiya's Avatar 
yamiya yamiya is offline
 

Member
  
Join Date: Aug 2007
Posts: 24
 

Default Re: Limiting the number of featured products displayed and randomising

lovely code. but what if i only want to show one page and remove subsequent page links?
__________________
Yamiya Yam
http://www.yamiya.com.my
---------------------------------------
X-Cart Gold v4.1.8 (UNIX)
Reply With Quote
  #5  
Old 02-12-2008, 06:49 AM
  SpinyMan's Avatar 
SpinyMan SpinyMan is offline
 

Advanced Member
  
Join Date: Jan 2008
Posts: 30
 

Default Re: Limiting the number of featured products displayed and randomising

Quote:
Originally Posted by yamiya
lovely code. but what if i only want to show one page and remove subsequent page links?
Hi,
Code:
shuffle($products); array_splice($products,$config["Appearance"]["products_per_page"]);
this will trim array to number of products per page defined in config and subsequent page links will not appear.
__________________
Regards,
SpinyMan

X-Cart Templates Store -
http://www.x-cart-customization.com/shop/

X-Cart Customization Services -
http://www.x-cart-customization.com/
Reply With Quote
  #6  
Old 02-13-2008, 07:15 AM
  yamiya's Avatar 
yamiya yamiya is offline
 

Member
  
Join Date: Aug 2007
Posts: 24
 

Default Re: Limiting the number of featured products displayed and randomising

Code is not working.

http://www.yamiya.com.my/

I am trying to get rid of

Result pages: 1 2 3 >

in Featured Products only.
__________________
Yamiya Yam
http://www.yamiya.com.my
---------------------------------------
X-Cart Gold v4.1.8 (UNIX)
Reply With Quote
  #7  
Old 02-13-2008, 07:37 AM
  SpinyMan's Avatar 
SpinyMan SpinyMan is offline
 

Advanced Member
  
Join Date: Jan 2008
Posts: 30
 

Default Re: Limiting the number of featured products displayed and randomising

Quote:
Originally Posted by yamiya
Code is not working.
I am trying to get rid of
Result pages: 1 2 3 >
in Featured Products only.
Hi, yamiya
Could u gimme a code of your featured_products.php?
I think u made a little mistake there (maybe u put the code in wrong place)... because everything must working well...
__________________
Regards,
SpinyMan

X-Cart Templates Store -
http://www.x-cart-customization.com/shop/

X-Cart Customization Services -
http://www.x-cart-customization.com/
Reply With Quote
  #8  
Old 02-13-2008, 05:53 PM
  yamiya's Avatar 
yamiya yamiya is offline
 

Member
  
Join Date: Aug 2007
Posts: 24
 

Default Re: Limiting the number of featured products displayed and randomising

if ( !defined('XCART_START') ) { header("Location: home.php"); die("Access denied"); }

#
# Select from featured products table
#

$user_account['membershipid'] = !empty($user_account['membershipid'])?$user_account['membershipid']:0;

$old_search_data = $search_data["products"];
$old_mode = $mode;
$old_page = $page;

$search_data["products"] = array();
$search_data["products"]["forsale"] = "Y";
$search_data["products"]["sort_condition"] = "$sql_tbl[featured_products].product_order";
$search_data["products"]['_']['inner_joins']['featured_products'] = array(
"on" => "$sql_tbl[products].productid=$sql_tbl[featured_products].productid AND $sql_tbl[featured_products].avail='Y' AND $sql_tbl[featured_products].categoryid='".intval($cat)."'"
);

$REQUEST_METHOD = "GET";
$mode = "search";
include $xcart_dir."/include/search.php";

$search_data["products"] = $old_search_data;
x_session_save("search_data");
$mode = $old_mode;
$page = $old_page;
unset($old_search_data, $old_mode, $old_page);

if (!empty($active_modules["Subscriptions"])) {
include_once $xcart_dir."/modules/Subscriptions/subscription.php";
}
$smarty->clear_assign("products");

$smarty->assign("navigation_script","home.php?cat=$cat&sor t=$sort&sort_direction=$sort_direction");

#Randomize featured products
shuffle($products);
array_splice($products,$config["Appearance"]["products_per_page"]);

$smarty->assign("f_products",$products);
$search_data = '';
$products = array();
unset($search_data, $products);
?>
__________________
Yamiya Yam
http://www.yamiya.com.my
---------------------------------------
X-Cart Gold v4.1.8 (UNIX)
Reply With Quote
  #9  
Old 06-13-2008, 06:15 AM
  wardworth's Avatar 
wardworth wardworth is offline
 

Advanced Member
  
Join Date: Sep 2007
Posts: 78
 

Default Re: Limiting the number of featured products displayed and randomising

Hi,

The code is working fine, but I'm getting the following warnings -

Warning: shuffle() expects parameter 1 to be array, null given in featured_products.php on line 91
Warning: array_splice(): The first argument should be an array in featured_products.php on line 92

anyone know why? I'm not that php literate.
__________________
:: Wardworth Ltd
:: X-Cart 4.1.8
Reply With Quote
  #10  
Old 06-20-2008, 03:04 AM
  phicaloma's Avatar 
phicaloma phicaloma is offline
 

Advanced Member
  
Join Date: Nov 2007
Location: Paris - France
Posts: 34
 

Default Re: Limiting the number of featured products displayed and randomising

Quote:
Originally Posted by wardworth
Hi,

The code is working fine, but I'm getting the following warnings -

Warning: shuffle() expects parameter 1 to be array, null given in featured_products.php on line 91
Warning: array_splice(): The first argument should be an array in featured_products.php on line 92

anyone know why? I'm not that php literate.

Hello Wardworth,
It does this only if there is no featured products for the category.

Solution ?
- Check every category for featured products (and select featured products for the categories that do not have them)
- Add an "if" line of code...that I am not able even to imagine, being quite a rookie in PHP.

Anybody wanting to help us on this one ?

Cheers,

Philippe
__________________
X-Cart Gold 4.1.9 - 4.2.0 - 4.2.2
Telafirma: Dynamic Images, Narrow by Manufacturer, Product Page manufacturer, Static Pages Categories, Multicolumn Recommends
Firetank Software: Featured Products, Feed Manager, Newest Products, Sitemap Pro, Marketing Manager
Xcartmods: Ultimate Minicart, 4 Level Horizontal (and Vcal) Flyout

BCSE: Reviews Edit, Multiple Upselling
MagenticOne: Tag Cloud, Store Manager, Custom Data Feed
Websitecm: Xnews, Xnews SEO, CDSEO Pro
Jon Langevin: Gone With The Wind !
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:30 AM.

   

 
X-Cart forums © 2001-2020