RANDOM PRODUCT FROM YOUR OSCOMMERCE IN A GEEKLOG BLOCK
Posted: Sat Dec 05, 2009 2:51 pm
****************************
DISPLAY A RANDOM PRODUCT FROM YOUR OSCOMMERCE CATALOG IN A BLOCK IN GEEKLOG
****************************
Original code by Patrick Veverka (oscommerce contribution).
Modified for geeklog use by StevynProthero@ironfeather.com
version 2.0 changes: now price is formatted and only current products "in stock" picked.
product status code fix from thomask@rainbowcomputers.ca contribution on oscommerce.
See it in work at http://lansingsucks.com
it pulls from my catalog at http://globalgoodys.com
Discussion on this code are at:
http://ironfeather.com/cgi-bin/bbs/ikon ... T&f=20&t=6
This is how I show a random product from a oscommerce catalog in a geeklog block...
1. Enter into your ADMIN area of geeklog, enter into the Block Manager and then click on "New Block". Input title & name and then select "PHP Block" from the option box. Input "phpblock_randomshop" in the Block Function field. Click SAVE.
2. edit and add the following code to your lib-custom.php file located in the geeklog/system directory.
things you need to edit:
"host", "username", "password", "catalogname",
"globalgoodys.com/catalog" to be the url of your oscommerce catalog.
//here is the code to insert into lib-custom.php
DISPLAY A RANDOM PRODUCT FROM YOUR OSCOMMERCE CATALOG IN A BLOCK IN GEEKLOG
****************************
Original code by Patrick Veverka (oscommerce contribution).
Modified for geeklog use by StevynProthero@ironfeather.com
version 2.0 changes: now price is formatted and only current products "in stock" picked.
product status code fix from thomask@rainbowcomputers.ca contribution on oscommerce.
See it in work at http://lansingsucks.com
it pulls from my catalog at http://globalgoodys.com
Discussion on this code are at:
http://ironfeather.com/cgi-bin/bbs/ikon ... T&f=20&t=6
This is how I show a random product from a oscommerce catalog in a geeklog block...
1. Enter into your ADMIN area of geeklog, enter into the Block Manager and then click on "New Block". Input title & name and then select "PHP Block" from the option box. Input "phpblock_randomshop" in the Block Function field. Click SAVE.
2. edit and add the following code to your lib-custom.php file located in the geeklog/system directory.
things you need to edit:
"host", "username", "password", "catalogname",
"globalgoodys.com/catalog" to be the url of your oscommerce catalog.
//here is the code to insert into lib-custom.php
Code: Select all
function phpblock_randomshop() {
//Original code by Patrick Veverka.
//Modified for geeklog use by Stevyn Prothero. version 2.0
$connection = mysql_connect("host","username","password")
or die("Couldn't make connection.");
$db = mysql_select_db("catalogname", $connection)
or die("Couldn't select database.");
$sql = "SELECT * FROM `products` where products_status = '1' ORDER BY RAND() LIMIT 1";
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute quasery.");
$row = mysql_fetch_array($sql_result);
$products_id = $row["products_id"];
$products_price = $row["products_price"];
$products_model = $row["products_model"];
$products_image = $row["products_image"];
$sql2 = "SELECT `products_name` FROM `products_description` WHERE products_id = '$products_id' LIMIT 1";
$sql2_result = mysql_query($sql2,$connection)
or die("Couldn't execute query.");
$row2 = mysql_fetch_array($sql2_result);
$products_name = $row2["products_name"];
$products_image_replace = str_replace("./", "/", $products_image);
$products_price_replace = str_replace(".0000", "", $products_price);
$products_price_replace = sprintf("%0.2f",$products_price_replace);
$retval =
"<center><a href=\"http://globalgoodys.com/catalog/product_info.php?products_id=$products_id\">";
$retval .= "<img src=\"http://globalgoodys.com/catalog/images/$products_image_replace\" width=\"100\" border=\"0\"><br>";
$retval .= "$products_name \$$products_price_replace</a></center> ";
return $retval;
mysql_free_result($sql_result);
mysql_close($connection);
}