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)
-   -   How to list all products in specific category in a box on the homepage? (https://forum.x-cart.com/showthread.php?t=38735)

ben@lrb.co.uk 04-01-2008 03:23 AM

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

Yurij 04-02-2008 12:24 AM

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%"'


ben@lrb.co.uk 04-02-2008 08:24 AM

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

Yurij 04-03-2008 12:06 AM

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.

yamiya 04-20-2008 03:08 AM

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. O:)

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.


Yurij 04-21-2008 06:29 AM

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. O:)


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



Yurij 04-21-2008 07:21 AM

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. O:)


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.


All times are GMT -8. The time now is 05:36 AM.

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