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

Random Image or Random Products - Category Specific

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #41  
Old 10-31-2011, 09:04 AM
 
nickff nickff is offline
 

Senior Member
  
Join Date: Aug 2010
Posts: 132
 

Default Re: Random Image or Random Products - Category Specific

I too would love to see this mod ported to 4.4.x...anyone?

__________________
nick hoag
looking forward to the future
http://thefutureforward.com
xcart versions 4.2.x, 4.3.x, 4.4.x
Reply With Quote
  #42  
Old 11-08-2011, 11:07 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Random Image or Random Products - Category Specific

Original instructions -> http://forum.x-cart.com/showpost.php?p=102302&postcount=1

The modified instructions (4.4.x):

Quote:
Within Patch/Upgrade section of X-Cart or within SQL Admin run this query:
Code:
INSERT INTO `xcart_modules` VALUES ( , 'Random_Products', 'This module displays random products', 'Y'); INSERT INTO `xcart_config` VALUES ('number_of_randomproducts', 'Number of Random Products to Display', '', 'Random_Products', '75', 'text', '3', '', '');

Next create a new directory under /modules/ named "Random_Products" and a directory under /skin/common_files/modules/ named "Random_Products".

Within /modules/Random_Products create a file named "random.php" with this content:

Code:
<?php # # $Id: random.php,v 1.00.0.0 0 TelaFirma $ # # Random Products # if (!defined('XCART_SESSION_START')) { header("Location: ../../"); die("Access denied"); } if (!is_numeric($config["Modules"]["number_of_randomproducts"])) $config["Modules"]["number_of_randomproducts"] = 0; # # Get products data for current category and store it in an array # $cat = intval($cat); if ($cat) { $category_data = func_query_first("SELECT parentid FROM $sql_tbl[categories] USE INDEX (PRIMARY) WHERE categoryid='$cat'"); $result = func_query("SELECT categoryid FROM $sql_tbl[categories] USE INDEX (parentid) WHERE parentid = '$category_data[parentid]' AND avail='Y'"); $cat_ids = array(); if (is_array($result)) { foreach($result as $k=>$v) { $cat_ids[] = $v["categoryid"]; } } else $cat_ids[] = $cat; $str = " AND $sql_tbl[products_categories].categoryid IN (".implode(",", $cat_ids).")"; } $order_by = "RAND()"; $search_query = $str; # # Search the products # $randoms = func_search_products($search_query, @$user_account["membership"], $order_by, $config["Modules"]["number_of_randomproducts"]); $smarty->assign("r_products",$randoms); ?>

Next create two files under /skin/common_files/modules/Random_Products/ named "random.tpl" and "random_image.tpl" with the contents as:

random.tpl
Code:
{capture name=dialog} {if $r_products ne ""} {include file="customer/main/products.tpl" products=$r_products} {/if} {/capture} {include file="dialog.tpl" content=$smarty.capture.dialog extra="width=100%"}

random_image.tpl
Code:
{assign var="rand" value="0"|mt_rand:"`$config.Modules.number_of_randomproducts-1`"} <a href=product.php?productid={$r_products[$rand].productid}>{include file="product_thumbnail.tpl" productid=$r_products[$rand].productid image_x=$config.Appearance.thumbnail_width product=$r_products[$rand].product tmbn_url=$r_products[$rand].tmbn_url}</a>

Now, edit your home.php file in root directory and add the following lines under the section that loads the Best Sellers module:

Code:
if($active_modules["Random_Products"]) include $xcart_dir."/modules/Random_Products/random.php";

** New Step **
This is a new step that you will need to do to make the single random image work on most systems (since that code is using a PHP modifier and not a Smarty modifier). If the single random image is working for you already then you do not need to perform this step.

Open the file /include/lib/smarty/Smarty.class.php for editing. On or around line 234 you will see the code:
Code:
'MODIFIER_FUNCS' => array('count'),

This need to be change to read
Code:
'MODIFIER_FUNCS' => array('count', 'mt_rand'),
** New Step End **

Now, where ever you want to display random products, just add this code in the template
Code:
{include file="modules/Random_Products/random.tpl"}
and where you want to display a random product image add this code
Code:
{include file="modules/Random_Products/random_image.tpl"}
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote

The following 3 users thank qualiteam for this useful post:
Acquamarina (12-12-2011), am2003 (05-31-2012), nickff (11-09-2011)
  #43  
Old 11-09-2011, 02:59 AM
 
nickff nickff is offline
 

Senior Member
  
Join Date: Aug 2010
Posts: 132
 

Default Re: Random Image or Random Products - Category Specific

Awesome. Thanks Alex!
__________________
nick hoag
looking forward to the future
http://thefutureforward.com
xcart versions 4.2.x, 4.3.x, 4.4.x
Reply With Quote
  #44  
Old 12-12-2011, 05:49 AM
 
Acquamarina Acquamarina is offline
 

X-Adept
  
Join Date: Aug 2006
Location: USA
Posts: 811
 

Default Re: Random Image or Random Products - Category Specific

Is it possible to use the tag inside a static page? For instance on the F.A.Q. page, have it display a random product image by entering the tag in the WYSIWYG code area?

Thanks for the new version. I have it on my 4.1.9 and want it for the 4.4.4 version.
__________________
Vera B
4.4.5
CFLSystems.com mods, Kosmos eBay Integration, Feed Manager Pro, custom mods, BCSEngineering Mods, CDSEO PRO
Hosting by EWDHosting - The best home for your x-cart.
Reply With Quote
  #45  
Old 12-12-2011, 11:24 AM
 
Acquamarina Acquamarina is offline
 

X-Adept
  
Join Date: Aug 2006
Location: USA
Posts: 811
 

Default Re: Random Image or Random Products - Category Specific

Hi, Alex,

Just tried the patch on 4.4.4 and got the following error:

SQL PATCH FAILED AT QUERY:
INSERT INTO `xcart_modules` VALUES ( , 'Random_Products', 'This module displays random products', 'Y')
__________________
Vera B
4.4.5
CFLSystems.com mods, Kosmos eBay Integration, Feed Manager Pro, custom mods, BCSEngineering Mods, CDSEO PRO
Hosting by EWDHosting - The best home for your x-cart.
Reply With Quote
  #46  
Old 12-16-2011, 12:36 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Random Image or Random Products - Category Specific

Acqua,

Have you tried running the patch through phpMyAdmin? Also try removing the ' around the table names. The patch is failing at the first query, is there an error message?
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote

The following user thanks totaltec for this useful post:
Acquamarina (12-16-2011)
  #47  
Old 12-16-2011, 05:58 AM
 
Acquamarina Acquamarina is offline
 

X-Adept
  
Join Date: Aug 2006
Location: USA
Posts: 811
 

Default Re: Random Image or Random Products - Category Specific

Hi, Mike, thanks for the reply.
__________________
Vera B
4.4.5
CFLSystems.com mods, Kosmos eBay Integration, Feed Manager Pro, custom mods, BCSEngineering Mods, CDSEO PRO
Hosting by EWDHosting - The best home for your x-cart.
Reply With Quote
  #48  
Old 10-24-2012, 04:21 AM
 
franki franki is offline
 

Member
  
Join Date: Aug 2005
Posts: 13
 

Default Re: Random Image or Random Products - Category Specific

the list of random products returned/displayed does not have it's URL, ie <a href=""> is returned.

Does anyone know how to fix this?
__________________
Version: 4.5.x
Reply With Quote
  #49  
Old 10-24-2012, 04:26 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Random Image or Random Products - Category Specific

Quote:
Originally Posted by franki
the list of random products returned/displayed does not have it's URL, ie <a href=""> is returned.

Does anyone know how to fix this?
Take a look at webmaster mode. See the smarty assign in random.php?
Code:
$smarty->assign("r_products",$randoms);

When you look at the variable in WM, what values are assigned to $r_products? That will tell us if the URL is getting pulled from the DB or not.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #50  
Old 10-24-2012, 05:19 PM
 
franki franki is offline
 

Member
  
Join Date: Aug 2005
Posts: 13
 

Default Re: Random Image or Random Products - Category Specific

Quote:
Originally Posted by totaltec
Take a look at webmaster mode. See the smarty assign in random.php?
Code:
$smarty->assign("r_products",$randoms);

When you look at the variable in WM, what values are assigned to $r_products? That will tell us if the URL is getting pulled from the DB or not.

Hi Totaltec, this is what's assigned:
Code:
Array (12) 0 => Array (22) productid => "525" provider => "1" productcode => "SKUFOR9" avail => "2" min_amount => "1" list_price => "20.03" distribution => "" product => "XYZ (product name)" price => 10 variantid => "0" weight => "0.13" is_product_options => "" is_variant => "" taxid => "1" taxed_price => "11.00" tmbn_url => "http://www.example.com/image..." image_x => "40" image_y => "150" tmbn_x => "40" tmbn_y => "150" price_deducted_tax => "Y" taxes => Array (1) GST => Array (16) taxid => "1" tax_name => "GST" formula => "DST+SH" address_type => "S" active => "Y" price_includes_tax => "Y" display_including_tax => "Y" display_info => "" regnumber => "" priority => "0" rate_value => 10 rate_type => "%" tax_display_name => "GST" tax_value_precise => 1 tax_value => 1 taxed_price => 11

Looks like no URL - looking at the sql query, should it query for the productid to be able to grab it's URL map?

Also, I think there's bug in the this code (random.php):
Code:
if (!is_numeric($config["Modules"]["number_of_randomproducts"])) $config["Modules"]["number_of_randomproducts"] = 0;

Should this be:
[code]

Code:
if (!is_numeric($config["Random_Products"]["number_of_randomproducts"])) $config["Random_Products"]["number_of_randomproducts"] = 0;
?
__________________
Version: 4.5.x
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 12:51 AM.

   

 
X-Cart forums © 2001-2020