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)
-   -   Latest products block (https://forum.x-cart.com/showthread.php?t=56298)

stuartn 10-30-2010 05:19 PM

Latest products block
 
1 Attachment(s)
Okay

I'm working on a small project with some bespoke elements and one was to add a block that listed the last 4 new products the same as the featured block when using the multi column format.

So, looking at the system it didn't provide such a feature but it did provide the 'Featured Block', so I decided to replicate the code and add some tweaks to get it to work showing the latest products as a new block.

Having looked around the forum, it would seem a few have wanted this but either ended up buying in a bolt on or not getting resolved.

So.......

1. Create a new .php file in a text editor call it latest_products.php and put in web root.

Place in it.....

PHP Code:

if ( !defined('XCART_START') ) { header("Location: home.php"); die("Access denied"); }

/**
 * Select from products table
 */

$user_account['membershipid'] = max(0intval($user_account['membershipid']));

$old_search_data = @$search_data['products'];

if (!empty(
$mode)) {

    
$old_mode $mode;

}

/**
 * latest products are shown without pagging navigation
 */
$do_not_use_navigation false;

$search_data['products'] = array();
$search_data['products']['forsale'] = 'Y';
$search_data['products']['sort_condition'] = "$sql_tbl[products].productid DESC";
$objects_per_page 4;  /* how many products do you want listed */
$search_data['products']['_']['inner_joins']['products_categories'] = array(
    
'on' => "$sql_tbl[products].productid=$sql_tbl[products_categories].productid AND $sql_tbl[products_categories].avail='Y' AND $sql_tbl[products_categories].categoryid='" intval($cat) . "'");

$REQUEST_METHOD 'GET';

$mode 'search';

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

$search_data['products'] = $old_search_data;

if (isset(
$old_mode)) {

    
$mode $old_mode;

}

unset(
$old_search_data$old_mode);

if (!empty(
$active_modules['Subscriptions'])) {

    include 
$xcart_dir '/modules/Subscriptions/subscription.php';

}

$do_not_use_navigation false;

if (
$total_items 0) {


    
$smarty->assign('l_products'$l_products);

}
?> 


2. in home.php around line 126 add below featured_products req the additional one for latest_products.

PHP Code:

include './featured_products.php';
// Mod for latest products
include './latest_products.php'



3. In home_main.tpl line 66 include the l_products=$l_products behind the f_products (/skin/common_files/customer/home_main.tpl)

Quote:

{include file="customer/main/welcome.tpl" f_products=$f_products l_products=$l_products}

4. Now we create copies of the featured templates and modify them

template 1 called "latest2.tpl"

Quote:

{*
$Id: latest2.tpl,v 1.1 2010/05/21 08:32:04 joy Exp $
vim: set ts=2 sw=2 sts=2 et:
*}
{if $products ne ""}
{capture name=dialog}
{include file="customer/main/latesthp.tpl" $products=$l_products}
{/capture}
{include file="customer/dialog.tpl" title=$lng.lbl_latest content=$smarty.capture.dialog sort=true additional_class="products-dialog dialog-featured-list" sort=false}
{/if}

template 2 called latesthp.tpl

Quote:

{*
$Id: latesthp.tpl,v 1.4 2010/07/14 05:35:30 igoryan Exp $
vim: set ts=2 sw=2 sts=2 et:
*}
{if $products}
{if $config.General.ajax_add2cart eq 'Y' and $config.General.redirect_to_cart ne 'Y'}
{include file="customer/ajax.add2cart.tpl" _include_once=1}
{/if}

{if $active_modules.Customer_Reviews and $config.Customer_Reviews.ajax_rating eq 'Y'}
{include file="modules/Customer_Reviews/ajax.rating.tpl" _include_once=1}
{/if}

{if $active_modules.Feature_Comparison and not $printable and $products_has_fclasses}
{include file="modules/Feature_Comparison/compare_selected_button.tpl"}
{/if}

{if $config.Appearance.products_per_row gt 1 and ($featured eq "Y" or $config.Appearance.featured_only_multicolumn eq "N")}

{include file="customer/main/products_t.tpl"}

{else}

{include file="customer/main/products_t.tpl"}

{/if}

{if $active_modules.Feature_Comparison and not $printable and $products_has_fclasses}
{include file="modules/Feature_Comparison/compare_selected_button.tpl"}
{/if}

{/if}

These both go into /skin/common_files/customer/main/ directory

5. Finally the welcome template /skin/common_files/customer/main/welcome.tpl

add in the new template under the featured.....

Quote:

{include file="customer/main/featured.tpl"}

{include file="customer/main/latest2.tpl" l_products=$l_products}

All should be done and if like mine looks like the attachment.

Duramax 6.6L 11-03-2010 04:20 PM

Re: Latest products block
 
In the attached thumbnail, the mod that puts the available stock into a colored bar. Could someone explain how to do this, or where to purchase that mod..

stuartn 11-03-2010 04:35 PM

Re: Latest products block
 
In your products_t.tpl

PHP Code:

{*
$Idproducts_t.tpl,v 1.4 2010/08/02 11:04:36 igoryan Exp $
vimset ts=2 sw=2 sts=2 et:
*}
{
list2matrix assign="products_matrix" assign_width="cell_width" list=$products row_length=$config.Appearance.products_per_row}
{
assign var="is_matrix_view" value=true}
{if 
$products_matrix}
  <
table cellspacing="3" class="products products-table width-100" summary="{$lng.lbl_products_list|escape}">
    {foreach 
from=$products_matrix item=row name=products_matrix}
      <
tr{interline name=products_matrix additional_class="product-name-row"}>
        {foreach 
from=$row item=product name=products}
          {if 
$product}
            <
td{interline name=products additional_class="product-cell"style="width: {$cell_width}%;">
<
script type="text/javascript">
//<![CDATA[
products_data[{$product.productid}] = {ldelim}{rdelim};
//]]>
</script>
              <
a href="{$product.alt_url|default:$product.page_url|amp}class="product-title">{$product.product}</a>
            </
td>
          {/if}
        {/foreach}
      </
tr>
      {if 
$config.Appearance.display_productcode_in_list eq "Y"}
        <
tr{interline name=products_matrix}>
          {foreach 
from=$row item=product name=products}
            {if 
$product}
              <
td{interline name=products additional_class="product-cell"}>
                {if 
$product.productcode}
                  <
div class="sku">{$lng.lbl_sku}: {$product.productcode|escape}</div>
                {else}
                    &
nbsp;
                {/if}
              </
td>
            {/if}
          {/foreach}
        </
tr>
      {/if}
      <
tr{interline name=products_matrix}>
        {foreach 
from=$row item=product name=products}
          {if 
$product}
            <
td{interline name=products additional_class="product-cell"}>
              <
div class="image">
                <
a href="{$product.alt_url|default:$product.page_url|amp}">{include file="product_thumbnail.tpl" productid=$product.productid image_x=$product.tmbn_x image_y=$product.tmbn_y product=$product.product tmbn_url=$product.tmbn_url}</a>
                {if 
$active_modules.Special_Offers and $product.have_offers}
                  {include 
file="modules/Special_Offers/customer/product_offer_thumb.tpl"}
                {/if}
              </
div>
            </
td>
          {/if}
        {/foreach}
      </
tr>
      {if 
$active_modules.Customer_Reviews and $rating_data_exists}
      <
tr{interline name=products_matrix}>
        {foreach 
from=$row item=product name=products}
          {if 
$product}
            <
td{interline name=products additional_class="product-cell"}>
              {if 
$product.rating_data}
                {include 
file="modules/Customer_Reviews/vote_bar.tpl" rating=$product.rating_data productid=$product.productid}
              {/if}
            </
td>
  
          {/if}
        {/foreach}
      </
tr>
      {/if}
      <
tr{interline name=products_matrix}>
        {foreach 
from=$row item=product name=products}
          {if 
$product}
            <
td{interline name=products additional_class="product-cell product-cell-price"}>
              {if 
$product.product_type ne "C"}
                {if 
$active_modules.Subscriptions ne "" and $product.catalogprice}
                  {include 
file="modules/Subscriptions/subscription_info_inlist.tpl"}
                {elseif 
$product.appearance.is_auction}
                  <
span class="price">{$lng.lbl_enter_your_price}</span><br />
                  {
$lng.lbl_enter_your_price_note}
                {else}
                  {if 
$product.appearance.has_price}
                        {if 
$product.appearance.has_market_price and $product.appearance.market_price_discount gt 0}
                      <
div class="market-price">
                      <
span class="market-price-value">{include file="currency.tpl" value=$product.list_price}</span>|<span class="price-value">{include file="currency.tpl" value=$product.taxed_price}</span>
                 <
div class="price-row">
                     
                      <
span class="market-price">{include file="customer/main/alter_currency_value.tpl" alter_currency_value=$product.taxed_price}</span>
                      {if 
$product.appearance.market_price_discount gt 0}
                          {if 
$config.General.alter_currency_symbol ne ""}, {/if}
                          <
span class="price-save">( {$product.appearance.market_price_discount}% {$lng.lbl_save_price})</span>
                        {/if}
                    </
div>
                
                                          
                                          
                                          
                      </
div>
                        {/if}
                    {if 
$product.taxes}
                      <
div class="taxes">{include file="customer/main/taxed_price.tpl" taxes=$product.taxes is_subtax=true}</div>
                    {/if}
                  {/if}   
          {if 
$product.avail gt 0 and $product.avail lt 5}
{
$lng.lbl_in_stock}:<img src="../skin/common_files/images/nostock.gif" align="absmiddle" alt="Out of Stock">
{elseif 
$product.avail gt 5 and $product.avail lt 10}
{
$lng.lbl_in_stock}: <img src="../skin/common_files/images/lowstock.gif" align="absmiddle" alt="Low Stock">
{elseif 
$product.avail gt 9}
{
$lng.lbl_in_stock}:<img src="../skin/common_files/images/normalstock.gif" align="absmiddle" alt="In Stock">
{/if}                            
                  {if 
$active_modules.Special_Offers and $product.use_special_price}
                    {include 
file="modules/Special_Offers/customer/product_special_price.tpl"}
                  {/if}
                {/if}
              {else}
                &
nbsp;
              {/if}
            </
td>
          {/if}
           
        {/foreach}
      </
tr>
     
     <
tr{interline name=products_matrix}>
        {foreach 
from=$row item=product name=products}
          {if 
$product && $login ne ""}
            <
td{interline name=products additional_class="product-cell product-cell-buynow"}>
                {if 
$active_modules.Product_Configurator and $is_pconf and $current_product}
                  {include 
file="modules/Product_Configurator/pconf_add_form.tpl"}
                {elseif 
$config.Appearance.buynow_button_enabled eq "Y" and $product.product_type ne "C"}
                  {include 
file="customer/main/buy_now.tpl"}
                {else}
                &
nbsp;
                  {/if}
                </
td>
          {/if}
        {/foreach}
      </
tr>
             
      {if 
$active_modules.Feature_Comparison}
      <
tr{interline name=products_matrix}>
        {foreach 
from=$row item=product name=products}
          {if 
$product}
            <
td{interline name=products additional_class="product-cell"}>
              {if 
$product.fclassid gt 0}
                <
div>{include file="modules/Feature_Comparison/compare_checkbox.tpl" id=$product.productid}</div>
              {/if}
            </
td>
          {/if}
        {/foreach}
      </
tr>
      {/if}
      {if 
not $smarty.foreach.products_matrix.last}
        <
tr class="separator">
          <
td colspan="{$config.Appearance.products_per_row|default:1}">&nbsp;</td>
        </
tr>
      {/if}
    {/foreach}
  </
table>
{/if} 



Quote:

{if $product.avail gt 0 and $product.avail lt 5}
{$lng.lbl_in_stock}:<img src="../skin/common_files/images/nostock.gif" align="absmiddle" alt="Out of Stock">
{elseif $product.avail gt 5 and $product.avail lt 10}
{$lng.lbl_in_stock}: <img src="../skin/common_files/images/lowstock.gif" align="absmiddle" alt="Low Stock">
{elseif $product.avail gt 9}
{$lng.lbl_in_stock}:<img src="../skin/common_files/images/normalstock.gif" align="absmiddle" alt="In Stock">
{/if}

I've set it so that as soon as 5 items shows as a minimum it goes to red - but people can still buy till it fully empties....though we don't forsee it ever getting to this point.

sinobest 11-04-2010 01:07 AM

Re: Latest products block
 
What does step 3 mean, please? I do not understand.

stuartn 11-04-2010 05:13 AM

Re: Latest products block
 
If you look in the home_main.tpl you should find around line 66

{include file="customer/main/welcome.tpl" f_products=$f_products}

what you need to do is to add in the smarty assignment for the latest products, so we add it into the line to make it.....

{include file="customer/main/welcome.tpl" f_products=$f_products l_products=$l_products}

sinobest 11-04-2010 06:40 AM

Re: Latest products block
 
my x-cart 4.4.1 home_main.tpl code is:
{*
$Id: home_main.tpl,v 1.1 2010/05/21 08:32:02 joy Exp $
vim: set ts=2 sw=2 sts=2 et:
*}
{if $smarty.get.mode eq "subscribed"}
{include file="customer/main/subscribe_confirmation.tpl"}
{elseif $smarty.get.mode eq "unsubscribed"}
{include file="customer/main/unsubscribe_confirmation.tpl"}
{elseif $main eq "returns"}
{include file="modules/RMA/customer/common.tpl"}
{elseif $main eq "register"}
{include file="customer/main/register.tpl"}
{elseif $main eq "profile_delete"}
{include file="customer/main/profile_delete_confirmation.tpl"}
{elseif $main eq "download"}
{include file="modules/Egoods/main.tpl"}
{elseif $main eq "send_to_friend"}
{include file="customer/main/send_to_friend.tpl"}
{elseif $main eq "pages"}
{include file="customer/main/pages.tpl"}
{elseif $main eq "manufacturers_list"}
{include file="modules/Manufacturers/customer_manufacturers_list.tpl"}
{elseif $main eq "manufacturer_products"}
{include file="modules/Manufacturers/customer_manufacturer_products.tpl"}
{elseif $main eq "search" or $main eq "advanced_search"}
{include file="customer/main/search_result.tpl"}
{elseif $main eq "cart"}
{include file="customer/main/cart.tpl"}
{elseif ($main eq "comparison" or $main eq 'choosing') and $active_modules.Feature_Comparison}
{include file="modules/Feature_Comparison/common.tpl"}
{elseif $main eq "wishlist" and $active_modules.Wishlist}
{include file="modules/Wishlist/wishlist.tpl"}
{elseif $main eq "order_message"}
{include file="customer/main/order_message.tpl"}
{elseif $main eq "orders"}
{include file="customer/main/search_orders.tpl"}
{elseif $main eq "history_order"}
{include file="customer/main/history_order.tpl"}
{elseif $main eq "product"}
{include file="customer/main/product.tpl"}
{elseif $main eq "giftcert"}
{include file="modules/Gift_Certificates/customer/giftcert.tpl"}
{elseif $main eq "subscriptions"}
{include file="modules/Subscriptions/subscriptions.tpl"}
{elseif $main eq "catalog" and $current_category.category eq ""}
{include file="customer/main/welcome.tpl"}
{elseif $main eq "catalog"}
{include file="customer/main/subcategories.tpl"}
{elseif $active_modules.Gift_Registry ne "" and $main eq "giftreg"}
{include file="modules/Gift_Registry/giftreg_common.tpl"}
{elseif $main eq "product_configurator"}
{include file="modules/Product_Configurator/pconf_common.tpl"}
{elseif $main eq "change_password"}
{include file="customer/main/change_password.tpl"}
{elseif $main eq "customer_offers"}
{include file="modules/Special_Offers/customer/offers.tpl"}
{elseif $main eq "customer_bonuses"}
{include file="modules/Special_Offers/customer/bonuses.tpl"}
{elseif $main eq "survey"}
{include file="modules/Survey/customer_survey.tpl"}
{elseif $main eq "surveys"}
{include file="modules/Survey/customer_surveys.tpl"}
{elseif $main eq "view_message"}
{include file="modules/Survey/customer_view_message.tpl"}
{elseif $main eq "view_results"}
{include file="modules/Survey/customer_view_results.tpl"}
{elseif $main eq "help"}
{if $help_section eq "Password_Recovery"}
{include file="customer/help/Password_Recovery.tpl"}
{elseif $help_section eq "Password_Recovery_message"}
{include file="customer/help/Password_Recovery_message.tpl"}
{elseif $help_section eq "Password_Recovery_error"}
{include file="customer/help/Password_Recovery.tpl"}
{elseif $help_section eq "FAQ"}
{include file="customer/help/FAQ_HTML.tpl"}
{elseif $help_section eq "contactus"}
{include file="customer/help/contactus.tpl"}
{elseif $help_section eq "about"}
{include file="customer/help/about.tpl"}
{elseif $help_section eq "business"}
{include file="customer/help/business.tpl"}
{elseif $help_section eq "conditions"}
{include file="customer/help/conditions_customers.tpl"}
{elseif $help_section eq "publicity"}
{include file="customer/help/publicity.tpl"}
{else}
{include file="customer/help/general.tpl"}
{/if}
{elseif $main eq "news_archive"}
{include file="modules/News_Management/customer/news_archive.tpl"}
{elseif $main eq "news_lists"}
{include file="modules/News_Management/customer/news_lists.tpl"}
{elseif $main eq "pages"}
{include file="customer/main/pages.tpl"}
{elseif $main eq "address_book"}
{include file="customer/main/address_book.tpl"}
{elseif $main eq "profile_delete"}
{include file="customer/main/profile_delete_confirmation.tpl"}
{elseif $main eq "profile_notdelete"}
{include file="customer/main/profile_notdelete_message.tpl"}
{elseif $main eq "cart_locked"}
{include file="customer/main/error_cart_locked.tpl"}
{elseif $main eq "giftreg_is_private"}
{include file="modules/Gift_Registry/error_giftreg_is_private.tpl"}
{elseif $main eq "error_no_shipping"}
{include file="customer/main/error_no_shipping.tpl"}
{elseif $main eq "delivery_error"}
{include file="customer/main/error_delivery.tpl"}
{elseif $main eq "error_ccprocessor_unavailable"}
{include file="customer/main/error_ccprocessor_unavail.tpl"}
{elseif $main eq "error_cmpi_error"}
{include file="customer/main/error_cmpi_error.tpl"}
{elseif $main eq "error_ccprocessor_error"}
{include file="customer/main/error_ccprocessor_error.tpl"}
{elseif $main eq "error_max_items"}
{include file="customer/main/error_max_items.tpl"}
{elseif $main eq "error_min_order"}
{include file="customer/main/error_min_order.tpl"}
{elseif $main eq "error_max_order"}
{include file="customer/main/error_max_order.tpl"}
{elseif $main eq "subscribe_bad_email"}
{include file="modules/News_Management/subscribe_bad_email.tpl"}
{elseif $main eq "disabled_cookies"}
{include file="customer/main/error_disabled_cookies.tpl"}
{elseif $main eq "403"}
{include file="customer/main/403.tpl"}
{elseif $main eq "authentication"}
{include file="customer/main/authentication.tpl" is_remember="Y"}
{else}
{include file="common_templates.tpl"}
{/if}

stuartn 11-04-2010 07:18 AM

Re: Latest products block
 
{include file="customer/main/welcome.tpl"}

change too

{include file="customer/main/welcome.tpl" l_products=$l_products }

I use the pro version your on a gold version by the looks of things...

sinobest 11-04-2010 07:55 AM

Re: Latest products block
 
how can i set latest products from admin panel, just as featured products?

sinobest 11-04-2010 08:08 AM

Re: Latest products block
 
how to let latest products show as Featured products done? i mean how we can choose the procucts from admin panel for latest product also.

jason.zhang 11-19-2010 04:35 PM

Re: Latest products block
 
does it works on 4.4.1 pro?


All times are GMT -8. The time now is 07:22 AM.

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