PDA

View Full Version : Random products in any part of your site...


Bluesplayer
08-11-08, 14:32
Pretty easy to accomplish. All you have to do is download the product.php file and rename it to something else. I called mine productreviews.php. Alter the file to this:

<?php
/**
*
* ShopWindow Toolset
*
* Copyright (C) 2007 Digital Window Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/


require_once('global.inc.php');

require_once('includes'.DIRECTORY_SEPARATOR.'class es'.DIRECTORY_SEPARATOR.'class.page_product.php');

require_once('includes'.DIRECTORY_SEPARATOR.'class es'.DIRECTORY_SEPARATOR.'class.smarty_sw.php');



$oPage = new pageProduct();

$oSmarty= new Smarty_SW();


$oSmarty->assign('sBreadCrumbText', $oPage->getBreadCrumb(false));
$oSmarty->assign('sBreadCrumbHtml', $oPage->getBreadCrumb());


# PAGE INCLUDES


include_once('includes'.DIRECTORY_SEPARATOR.'eleme nts'.DIRECTORY_SEPARATOR.'search_box.php');

include_once('includes'.DIRECTORY_SEPARATOR.'eleme nts'.DIRECTORY_SEPARATOR.'product_display.php');


$oSmarty->display('productreviews.tpl');


?>

As you can see it is referring to a new file - productreviews.tpl. To create this file download your template product.tpl file and rename it to the file name you want to use. You will have to edit this file as you will need to remove any shopwindow template references. My own is like this:

<div id="crumb" style="padding-top: 10px;">{$sBreadCrumbHtml|replace:"&":"&amp;"}</div>
<div id="item">
<div align="center" style="padding-bottom: 10px;">
{include file="elements`$DIRECTORY_SEPARATOR`search_box.tpl"}</div>
{include file="elements`$DIRECTORY_SEPARATOR`product_display.tpl"}
</div>

Whether you want to include the search box is upto you.

The above is referring to the product_display.tpl file. This again will need to be adjusted or copy it and rename it to something else and then redesign it as you want. Upload this new file and alter the product.tpl file to include it. My own looks like this:

<div style="float: left; padding-right: 10px; width: 210px;"><a target="_blank" href="{$sProductLink|replace:"&":"&amp;"}"><img alt="{$sProductName|replace:"&":"&amp;"}" class="sw_productphoto" src="{$sProductImageUrl|default:$noImage}" /></a></div>
<div style="float: right;"><img class="sw_productlogo" alt="" src="{$sMerchantLogoUrl|default:$noLogo}" /></div>
<div><font size="4">{$sProductName|replace:"& ":"&amp; "} for {#currencySign#}{$fSearchPrice|number_format:2}</font></div>
<br />
<p>{$sProductDesc}</p>
<p>{$sProductPromo}</p>
<div align="right" style="text-align: right;">
Item found in category: <a href="{$sProductCategoryLink|replace:"&":"&amp;"}">{$sProductCategoryName|replace:"& ":"&amp; "}</a>
<br />
Price: <a target="_blank" href="{$sProductLink|replace:"&":"&amp;"}">{#currencySign#}{$fSearchPrice|number_format:2}</a> |
<a target="_blank" href="{$sProductLink|replace:"&":"&amp;"}">More Information</a> | <a target="_blank" href="{$sProductLink|replace:"&":"&amp;"}">Visit Site</a></div>

Once you have completed the above you can test it. Open any product in your shopwindow. Alter the product part of the url to use your newly created file - mine as mentioned above is productreviews.php. If you have carried out the above correctly it should work. See my own here:

http://ukshopping-4u.com/shopwindow/productreviews.php?p=33205023&c=240

As you can see it lacks any styling.

You can include this new file into another part of your site in a number of ways but I have used random ajaxinclude code which can be acquired from Dynamic Drive. The styling will be related to wherever you insert this new file.

View my own site to see it in action (random ajaxinclude used). On my own site reloading the homepage will reload a different product.

To create the random display you first of all need some code that can work off urls such as this code from dynamic drive:

http://dynamicdrive.com/dynamicindex17/ajaxrotate.htm

Not at all hard to get the above code in place (read the instructions). The trick to getting it to display your newly created product page is to alter the var includefiles references from ajaxfiles/file.htm - ajaxfiles/file1.htm and so on to an url of a product you want to show. Visit your shopwindow and find a nice product that you want to show. Copy the url and alter it to use your newly created file above. Use these urls instead of ajaxfiles/file4.htm etc. You can then show as many products randomly as you want. No need to use the full urls. You can dispense with the domain part of it. Make sure you get the paths right.

All the best
Bluesplayer