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

How to list all products in specific category in a box on the homepage?

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 04-01-2008, 03:23 AM
 
ben@lrb.co.uk ben@lrb.co.uk is offline
 

Member
  
Join Date: Feb 2006
Posts: 29
 

Default How to list all products in specific category in a box on the homepage?

Our bestsellers list is manually configured, because it is based on data from our "real-world" store as well as our online shop. The results are put in a specific category, updated fortnightly.

I'd like to display this information also in a box on the homepage (preferably in two columns in the central content area), and am wondering if there is a way to do this automatically? At the moment I'm making a manual copy which is a bit of a pain.

EDIT:
I found this thread:
http://forum.x-cart.com/showpost.php?p=209436&postcount=3

which shows something like the effect I'm looking for; however, I want this just in a box on the homepage, for one specific category, not on the detailed product page for any category.

Advice on how to modify this mod would be very much appreciated!

Many thanks,

Rachael
__________________
--
X-cart Version 4.1.9

Last edited by ben@lrb.co.uk : 04-01-2008 at 03:32 AM. Reason: Found a thread elsewhere on the forum that may do the trick...
Reply With Quote
  #2  
Old 04-02-2008, 12:24 AM
  Yurij's Avatar 
Yurij Yurij is offline
Banned
 

X-Adept
  
Join Date: Jan 2008
Posts: 486
 

Default Re: How to list all products in specific category in a box on the homepage?

For version 4.1.9, I would have done so:

In the file "home.php" insert the following lines (before - "# Assign Smarty variables and show template"):

PHP Code:
if ((empty($cat))&&(empty($products)))
{
//number spec. cat :)))
    
$spec_cat 105
    
$allproduct = array();
    
$allproduct func_query ("SELECT * FROM $sql_tbl[products]$sql_tbl[products_categories] WHERE $sql_tbl[products].productid=$sql_tbl[products_categories].productid AND $sql_tbl[products].forsale='Y' $avail AND $sql_tbl[products_categories].categoryid='$spec_cat'");
    
$smarty->assign("allproduct"$allproduct);  


In the end file "skin1\customer\main\welcome.tpl" insert the following lines:
PHP Code:
{include file="customer/main/specat.tpl"

Create file "customer/main/specat.tpl", so the following code:
PHP Code:
<br>
{
capture name=dialog}
{
assign var="count_per_row" value=2}
<
table border=0 width=100%>
{
math equation="floor(100/x)" x=$count_per_row assign="width"}
{
section loop=$allproduct name=ind}

{if %
ind.indexis div by $count_per_row}
<
tr>
    {
assign var="cell_counter" value=0}
{/if}
    {
math equation="x+1" x=$cell_counter assign="cell_counter" }

<
td valign=top  align=center width={$width}%>
<
table border=0>
    <
tr>
        <
td align=center>

            {include 
file="product_thumbnail.tpl" productid=$allproduct[ind].productid image_x=$allproduct[ind].tmbn_x|default:$config.Appearance.thumbnail_width image_y=$allproduct[ind].tmbn_y product=$allproduct[ind].product tmbn_url=$allproduct[ind].tmbn_url}
        </
td>
    </
tr>
    <
tr>
        <
td>
            <
a href="product.php?productid={$allproduct[ind].productid}&amp;cat={$cat}class="ProductTitle">{$allproduct[ind].product}</a>
        </
td>
    </
tr>
</
table>

</
td>

{
capture name=prod_index}
    {
math equation="index+x+1" index=%ind.indexx=$count_per_row}
{/
capture}


{if 
$smarty.capture.prod_index is div by $count_per_row}
    </
tr>
{/if}
{/
section}

    {if 
$cell_counter lt $count_per_row}
    {
section name=rest_cells loop=$count_per_row start=$cell_counter}
        <
td class="SectionBox">&nbsp;</td>
    {/
section}
    {/if}
</
tr>
</
table>


{/
capture}
{include 
file="dialog.tpl" title="Cool products... or..." content=$smarty.capture.dialog extra='width="100%"'
Reply With Quote
  #3  
Old 04-02-2008, 08:24 AM
 
ben@lrb.co.uk ben@lrb.co.uk is offline
 

Member
  
Join Date: Feb 2006
Posts: 29
 

Default Re: How to list all products in specific category in a box on the homepage?

Hi Yurij,

Thanks very much - that's a great start!!

Ideally, I want to be able to style this independently of dialog.tpl, and also to have a solution that doesn't involve editing home.php, so I think I have a bit more tinkering ahead. But it's fantastic to know it can be done!

Thanks,

Rachael
__________________
--
X-cart Version 4.1.9
Reply With Quote
  #4  
Old 04-03-2008, 12:06 AM
  Yurij's Avatar 
Yurij Yurij is offline
Banned
 

X-Adept
  
Join Date: Jan 2008
Posts: 486
 

Default Re: How to list all products in specific category in a box on the homepage?

You should still have a list of products.
For the main page (the default), you do not have a list of desired products.
So if this will not be ( "home.php"), there will be another files.

I simply brought universal solution. Changing MYSQL query parameters can be obtained from other effects.
Reply With Quote
  #5  
Old 04-20-2008, 03:08 AM
  yamiya's Avatar 
yamiya yamiya is offline
 

Member
  
Join Date: Aug 2007
Posts: 24
 

Default Re: How to list all products in specific category in a box on the homepage?

Hi,

I love your code. But is there anyway to display the prices and SKU just as in Featured Product Box? Also how do I sort them according to Product Name?

Hope to get an answer for that.

Quote:
Originally Posted by Yurij
You should still have a list of products.
For the main page (the default), you do not have a list of desired products.
So if this will not be ( "home.php"), there will be another files.

I simply brought universal solution. Changing MYSQL query parameters can be obtained from other effects.
__________________
Yamiya Yam
http://www.yamiya.com.my
---------------------------------------
X-Cart Gold v4.1.8 (UNIX)
Reply With Quote
  #6  
Old 04-21-2008, 06:29 AM
  Yurij's Avatar 
Yurij Yurij is offline
Banned
 

X-Adept
  
Join Date: Jan 2008
Posts: 486
 

Default Re: How to list all products in specific category in a box on the homepage?

Quote:
Originally Posted by yamiya
Hi,

I love your code. But is there anyway to display the prices and SKU just as in Featured Product Box? Also how do I sort them according to Product Name?

Hope to get an answer for that.

For sorting by Product Name change:

PHP Code:
if ((empty($cat))&&(empty($products)))
{
//number spec. cat :)))
    
$spec_cat "2"
    
$allproduct = array();
    
$allproduct func_query ("SELECT * FROM $sql_tbl[products]$sql_tbl[products_categories] WHERE $sql_tbl[products].productid=$sql_tbl[products_categories].productid AND $sql_tbl[products].forsale='Y' $avail AND $sql_tbl[products_categories].categoryid='$spec_cat' ORDER BY $sql_tbl[products].product");
    
$smarty->assign("allproduct"$allproduct);  

Reply With Quote
  #7  
Old 04-21-2008, 07:21 AM
  Yurij's Avatar 
Yurij Yurij is offline
Banned
 

X-Adept
  
Join Date: Jan 2008
Posts: 486
 

Default Re: How to list all products in specific category in a box on the homepage?

Quote:
Originally Posted by yamiya
Hi,

I love your code. But is there anyway to display the prices and SKU just as in Featured Product Box? Also how do I sort them according to Product Name?

Hope to get an answer for that.

For display the price.... Need make next change as in Featured Product Box (or subcategories):

in home.php change last code by:
PHP Code:
if ((empty($cat))&&(empty($products)))
{
    
//number spec. cat 
    
$spec_cat "3"
    
$old_search_data $search_data["products"];
    
$old_mode $mode;
    
$old_page $page;

    
$search_data["products"] = array();
    
$search_data["products"]["categoryid"] = $spec_cat;
    
$search_data["products"]["search_in_subcategories"] = "";
    
$search_data["products"]["category_main"] = "Y";
    
$search_data["products"]["category_extra"] = "Y";
    
$search_data["products"]["forsale"] = "Y";

// sort field and order by....
    
if(!isset($sort)) $sort "title";
    if(!isset(
$sort_direction))    $sort_direction 0;

    
$mode "search";

    include 
$xcart_dir."/include/search.php";

    
$smarty->assign("allproduct"$products);  

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



File "customer/main/specat.tpl" change by this code:
PHP Code:
<br>
{
capture name=dialog}
{
assign var="count_per_row" value=2}
<
table border=0 width=100%>
{
math equation="floor(100/x)" x=$count_per_row assign="width"}
{
section loop=$allproduct name=ind}

{if %
ind.indexis div by $count_per_row}
<
tr>
    {
assign var="cell_counter" value=0}
{/if}
    {
math equation="x+1" x=$cell_counter assign="cell_counter" }

<
td valign=top  align=center width={$width}%>
<
table border=0>
    <
tr>
        <
td align=center>

            {include 
file="product_thumbnail.tpl" productid=$allproduct[ind].productid image_x=$allproduct[ind].tmbn_x|default:$config.Appearance.thumbnail_width image_y=$allproduct[ind].tmbn_y product=$allproduct[ind].product tmbn_url=$allproduct[ind].tmbn_url}
        </
td>
    </
tr>
    <
tr>
        <
td>
            <
a href="product.php?productid={$allproduct[ind].productid}&amp;cat={$cat}class="ProductTitle">{$allproduct[ind].product}</a>
        </
td>
    </
tr>
    
    {if 
$config.Appearance.display_productcode_in_list eq "Y" and $$allproduct[ind].productcode ne ""}
    <
tr>
        <
td>
        {
$lng.lbl_sku}: {$allproduct[ind].productcode}
        </
td>
    </
tr>
    {/if}
    <
tr>
        <
td>
            {
assign var="discount" value=0}
            {if 
$allproduct[ind].list_price gt 0 and $allproduct[ind].taxed_price lt $allproduct[ind].list_price}
                {
math equation="100-(price/lprice)*100" price=$allproduct[ind].taxed_price lprice=$allproduct[ind].list_price format="%3.0f" assign=discount}
                    {if 
$discount gt 0}
                        <
font class="MarketPrice">{$lng.lbl_market_price}: <s>
                            {include 
file="currency.tpl" value=$allproduct[ind].list_price}
                        </
s></font><br />
                    {/if}
            {/if}

            {if 
$active_modules.Special_Offers ne "" and $allproduct[ind].use_special_price ne ""}
                <
s>
            {/if}

            <
font class="ProductPrice">{$lng.lbl_our_price}: {include file="currency.tpl" value=$allproduct[ind].taxed_price}</font><font class="MarketPrice">{include file="customer/main/alter_currency_value.tpl" alter_currency_value=$allproduct[ind].taxed_price}</font>{if $discount gt 0}{if $config.General.alter_currency_symbol ne ""},{/if} {$lng.lbl_save_price} {$discount}%{/if}

            {if 
$active_modules.Special_Offers ne "" and $allproduct[ind].use_special_price ne ""}
                </
s>
            {/if}

            {if 
$allproduct[ind].taxes}
                <
br />
                <
div class="PListTaxBox">{include file="customer/main/taxed_price.tpl" taxes=$allproduct[ind].taxes}</div>
            {/if}

            {if 
$active_modules.Special_Offers ne "" and $allproduct[ind].use_special_price ne ""}
                {include 
file="modules/Special_Offers/customer/product_special_price.tpl" product=$allproduct[ind]}
            {/if}

        </
td>
    </
tr>
</
table>

</
td>

{
capture name=prod_index}
    {
math equation="index+x+1" index=%ind.indexx=$count_per_row}
{/
capture}


{if 
$smarty.capture.prod_index is div by $count_per_row}
    </
tr>
{/if}
{/
section}

    {if 
$cell_counter lt $count_per_row}
    {
section name=rest_cells loop=$count_per_row start=$cell_counter}
        <
td class="SectionBox">&nbsp;</td>
    {/
section}
    {/if}
</
tr>
</
table>


{/
capture}
{include 
file="dialog.tpl" title="Cool products... or..." content=$smarty.capture.dialog extra='width="100%"'


PS. Not much has changed the way you get the list of products.
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 02:16 AM.

   

 
X-Cart forums © 2001-2020