X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Limiting the number of featured products displayed and randomising (https://forum.x-cart.com/showthread.php?t=35813)

wardworth 11-30-2007 03:24 AM

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?

SpinyMan 01-25-2008 10:05 AM

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);


wardworth 01-27-2008 11:42 PM

Re: Limiting the number of featured products displayed and randomising
 
That works a charm. Excellent! Thank you very much Spinyman :)

yamiya 02-12-2008 06:31 AM

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?

SpinyMan 02-12-2008 06:49 AM

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.

yamiya 02-13-2008 07:15 AM

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.

SpinyMan 02-13-2008 07:37 AM

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

yamiya 02-13-2008 05:53 PM

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);
?>

wardworth 06-13-2008 06:15 AM

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.

phicaloma 06-20-2008 03:04 AM

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


All times are GMT -8. The time now is 05:02 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.