X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Special Offers Module (https://forum.x-cart.com/showthread.php?t=1144)

funkydunk 01-09-2003 08:06 AM

Special Offers Module
 
I have now completed a special offers part to show them on the home page. the code is as follows:

First create a specials.php file in xcart/customer this selects 6 items at random that are marked as discounted from the main/market price.

Code:

<?

// the database query
$query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid AND discount > 0 ORDER BY RAND() LIMIT 6 ";

// give the product array to smarty to make it available sitewide.
$specials = func_query($query);
$smarty->assign("specials",$specials);
?>


Then add the following line into customer/home.php after the require featured proudcts bit.
Code:

require "./specials.php";

Then amend welcome.tpl to add the following code to where you want it to appear:
Code:

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

Then amend skin1/customer/home_main.tpl to:
Code:

{if $smarty.get.mode eq "subscribed"}
{include file="main/subscribe_confirmation.tpl"}

{elseif $smarty.get.mode eq "unsubscribed"}
{include file="main/unsubscribe_confirmation.tpl"}

{elseif $main eq "search"}
{include file="customer/main/search_result.tpl"}

{elseif $main eq "advanced_search"}
{include file="customer/main/advanced_search.tpl"}

{elseif $main eq "cart"}
{include file="customer/main/cart.tpl"}

{elseif $main eq "wishlist"}
{if $active_modules.Wishlist ne ""}
{include file="modules/Wishlist/wishlist.tpl"}
{/if}

{elseif $main eq "anonymous_checkout"}
{include file="customer/main/anonymous_checkout.tpl"}

{elseif $main eq "order_message"}
{include file="customer/main/order_message.tpl"}

{elseif $main eq "checkout"}
{include file="customer/main/checkout.tpl"}

{elseif $main eq "product"}
{include file="customer/main/product.tpl" product=$product}

{elseif $main eq "giftcert"}
{include file="modules/Gift_Certificates/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" f_products=$f_products specials=$specials}

{elseif $main eq "catalog"}
{include file="customer/main/subcategories.tpl" cat=$cat}

{else}
{include file="common_templates.tpl"}
{/if}


Then and we are nearly there now !! :wink: create a special.tpl in skin1/customer/main as follows:
Code:

{capture name=dialog}
{if $specials ne ""}
{include file="customer/main/products.tpl" products=$specials}
{else}
{$lng.txt_no_specials}
{/if}
{/capture}
{include file="dialog.tpl" title=$lng.lbl_special_offers content=$smarty.capture.dialog extra="width=100%"}


You will see that I have added two extra fields into the languages, one to display if there are no special offers and one for the title to the main box.

Enjoy.

Funkydunk

shan 01-09-2003 02:11 PM

Well done mate,

Your coming up with some great addons of late.

Hats off to you :-)

funkydunk 01-09-2003 10:49 PM

Necessity is the father of invention. :wink:

Just had a client who needed these bits so I put them together.

Thanks for the feedback.

There's more coming!

FishBookStore 01-10-2003 09:11 AM

Hmmm...
 
I was thinking of doing something like this but I wanted it to be something like Bargain of the Day or Week.

I wanted to give everything a Bargain Price. The script would randomly pick an item for the time period. It would just need to check against a timestamp to see if it needed to generate a new bargain or run a cron job.

I would also want it to show the Bargain Price on the product page.


The one problem I see with yours is couldn't a customer simply continue to reload the page until it loaded the item they wanted to get the discount?

shan 01-10-2003 09:34 AM

It doesnt matter i suppose as all the items that will show up are chosen from the list of products that you have set as discounted.

This just puts a few on the front page to show them off

funkydunk 01-10-2003 10:22 AM

Shan,

Bang on.

If you haven't selected a discount it wont pick it..simple as that.

Now getting the system to do a discount automatically, now that is another thing, not sure how that would work. :?

shan 02-07-2003 05:17 PM

Anyone created this as a side menu like the bestsellers has ?

funkydunk 02-07-2003 10:58 PM

Shan,

Yep - Am building a site at the moment with this in a lhs menu.

Limited it to show 3 products though cos of space.

jgkiefer 04-14-2003 06:34 AM

Quote:

Originally Posted by funkydunk
Limited it to show 3 products though cos of space.


How about one random discounted product or the option for more?

funkydunk 04-14-2003 10:55 AM

I look forward to seeing the code :wink:

Haven't got time to amend this myself at the moment - clients come first - , but feel free to amend away and post your results.

jgkiefer 06-16-2003 05:59 AM

Quote:

Originally Posted by funkydunk
Shan,

Yep - Am building a site at the moment with this in a lhs menu.

Limited it to show 3 products though cos of space.


How is this coming along?

funkydunk 06-16-2003 06:40 AM

This has been done.

lhs menu shows a selection of three products that have a discount applied then a link to a special offers page that lists all products with the normal navigation through the pages.

jgkiefer 06-16-2003 07:03 AM

How much is 120L in dollars?

funkydunk 06-16-2003 07:28 AM

120 what?

jgkiefer 06-16-2003 11:11 AM

Your site says that that mod costs 120L.

funkydunk 06-16-2003 11:42 AM

sorry - you lost me then... the L is actually a бё GBP

if you pm me I can confirm details of costings etc.

enge919 05-29-2004 04:40 AM

Does anyone know if this works in 3.5.x?

I need this for a client with 3.5.4 but we want to modify it to just randomly pull 6 items from the database to display without being dependent on the item being marked down. In other word he does not show marked down items but want the home page to always be fresh.

UPDATED: See my fix below to use this with or without discounted products in 3.5.x!

jeeya 05-29-2004 04:19 PM

I am getting this error after I add - specials.php in home.php



INVALID SQL: 1054 : Unknown column 'discount' in 'where clause'
SQL QUERY FAILURE: SELECT * FROM xcart_products,xcart_pricing WHERE forsale='Y' AND avail>0 AND xcart_products.productid=xcart_pricing.productid AND discount > 0 ORDER BY RAND() LIMIT 6


Version 3.4.0

enge919 05-30-2004 12:37 AM

just change the following code in specials.php

Code:

<?

// the database query
$query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid AND discount > 0 ORDER BY RAND() LIMIT 6 ";

// give the product array to smarty to make it available sitewide.
$specials = func_query($query);
$smarty->assign("specials",$specials);
?>


to

Code:

<?

// the database query
$query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid ORDER BY RAND() LIMIT 6 ";

// give the product array to smarty to make it available sitewide.
$specials = func_query($query);
$smarty->assign("specials",$specials);
?>


This will just randomly pull products from the database regardless of any discounts.

And if you only want to show products you have discounted from the list price use this:

Code:

<?

// the database query
$query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid AND price < list_price ORDER BY RAND() LIMIT 4 ";

// give the product array to smarty to make it available sitewide.
$specials = func_query($query);
$smarty->assign("specials",$specials);
?>


Change LIMIT 6 to any number of products you want to show in the specials.tpl

Also be sure to name the specials template specials.tpl. I noticed in the original code it was named special.tpl.

I have tested this in 3.5.4 and works like a charm :D

hth

jeeya 05-30-2004 02:27 AM

Great Thanks Works Perfect.

Also Is there anyway to modify this to be shown on help section page - like about us page.

enge919 05-30-2004 10:06 AM

No problem.......

If you want to add this to other pages just add the include, in the case of the about us page add the include to skin1/help/about.tpl where you want it to appear:

Code:

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

You also need to add the require to the appropiate .php script, in this case it would be xcart/customer/help.php. Just add the require below the last require in that script:

Code:

require "./specials.php";



Enjoy!

jeeya 05-30-2004 03:28 PM

great, I will set it up somewhere where it will show more products on about.tpl instead of 4, i will put about 12.

Thanks.

enge919 06-21-2004 11:13 PM

I have a client that wants this mod to show the newest products only in the last 60 days. Can anyone tell me what argument to use?

I suppose it would tie to the add_date timestamp in the xcart_products database, something to the effect of "AND < 60" where 60 is the number of days from the current day we want to show the newest products, I just need to know what the proper format would be for the unix timestamp and how to show only products "less than 60 day old".

funkydunk 06-22-2004 01:00 AM

unix time is in seconds

therefore 60 days is 60*60*24*24

dvanhoos 09-08-2004 11:50 AM

Duplicate Entries
 
So I get duplicate entries in the Specials section frequently, and always if I only have one item on special. Am using the RAND function so can understand when more than 4 products on special, but it always shows two off the same item when it's only one product. You can see it at http://hydrangeasplus.com and hit refresh a couple of times and you'll see duplicates. Not a real big deal, but still curious. Any ideas?

enge919 09-08-2004 08:20 PM

Here's one for anyone running this with 4.0.3.

Using this mod it does not display the price, It displays this instead: "enter your price".

I am working on finding the fix for this but if anyone can help it would be greatly appreciated and it sure would help others that use this in 4.0.x branch of xcart.

Likewise, if/when I figure out a fix I will post it here.

markwhoo 09-12-2004 09:15 AM

Quote:

Originally Posted by enge919
Here's one for anyone running this with 4.0.3.

Using this mod it does not display the price, It displays this instead: "enter your price".

I am working on finding the fix for this but if anyone can help it would be greatly appreciated and it sure would help others that use this in 4.0.x branch of xcart.

Likewise, if/when I figure out a fix I will post it here.


Please do, I am currently upgrading a store to 4.03 and was wondering what changes may be required to get this workable for the newer version.

Thanks to those that may be of help

24md 09-15-2004 06:42 AM

What a great mod, thanks a lot, have been using it for a little while and its working a treat. 8)

funkydunk 09-19-2004 12:06 AM

Quote:

Originally Posted by 24md
What a great mod, thanks a lot, have been using it for a little while and its working a treat. 8)


thanx :)

enge919 09-19-2004 01:30 AM

funkydunk,

Quote:

Here's one for anyone running this with 4.0.3.

Using this mod it does not display the price, It displays this instead: "enter your price".

Have any idea what to change in the script to get it to work properly with 4.0.3?

I have not had time with my schedule to check into it yet.

BHMedia 09-29-2004 07:56 PM

sweet

finestshops 10-06-2004 07:30 AM

Quote:

Originally Posted by enge919
Have any idea what to change in the script to get it to work properly with 4.0.3?


Change specials.php to this one:

Code:

<?
#
# $Id: specials.php by FS based on featured_products.php,v 1.2.2.3 2004/09/09 12:12:41 max Exp $
# specials mod idea by funkydunk
# Get featured products data and store it into $specials array
#

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

#
# select from products table
#

$membership = !empty($user_account['membership'])?$user_account['membership']:"";
$f_cat = (empty ($cat) ? "0" : $cat);
if ($config["General"]["unlimited_products"]=="N" && $config["General"]["disable_outofstock_products"])
        $avail_condition = "($sql_tbl[products].avail>0 OR $sql_tbl[products].product_type='C') and ";
else
        $avail_condition = "";
$query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[pricing].productid=$sql_tbl[products].productid AND price < list_price ORDER BY RAND() LIMIT 6 ";
$specials = func_query($query);

if(is_array($specials)){
    foreach($specials as $f_v => $f_k){
        $int_res = '';
        if(is_array($f_k)){
                        if(!empty($active_modules['Product_Options'])) {
                                $tmp_price = func_get_price_default_variant($specials[$f_v]['productid'], @$user_account['membership']);
                                if ($tmp_price)
                                        $specials[$f_v]["price"] = $tmp_price;
                        }

#
# Get thumbnail's URL (uses only if images stored in FS)

                        $specials[$f_v]["tmbn_url"] = func_get_thumbnail_url($specials[$f_v]["productid"]);
#
# Recalculate prices if VAT is enabled and prices do not includes VAT
#
                        $specials[$f_v]["taxes"] = func_get_product_taxes($specials[$f_v], $login);

#
# Check if product have product options
#
                        if(!empty($active_modules['Product_Options'])) {
                                $specials[$f_v]["product_options"] = func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[classes] WHERE productid='".$f_k["productid"]."'");
                        }

#
# Replace descr and fulldescr on international (if defined)
#
            $int_res = func_query_first("SELECT * FROM  $sql_tbl[products_lng] WHERE code='$store_language' AND productid='".$f_k['productid']."'");
                        if (!empty($int_res["product"])) {
                                $specials[$f_v]["product"] = stripslashes($int_res["product"]);
                    }   
                if (!empty($int_res["descr"])) {
                            $specials[$f_v]["descr"] = str_replace("\n","
", stripslashes($int_res["descr"]));
                    }   
                    if (!empty($int_res["full_descr"])) {
                        $specials[$f_v]["fulldescr"] = str_replace("\n","
", stripslashes($int_res["full_descr"]));
                    }

                        if ($specials[$f_v]["descr"] == strip_tags($specials[$f_v]["descr"]))
                                $specials[$f_v]["descr"] = str_replace("\n", "
", $specials[$f_v]["descr"]);

                        if ($specials[$f_v]["fulldescr"] == strip_tags($specials[$f_v]["fulldescr"]))
                                $specials[$f_v]["fulldescr"] = str_replace("\n", "
", $specials[$f_v]["fulldescr"]);

                }       
        }
}; 


if (!empty($active_modules["Subscriptions"])) {
    include_once $xcart_dir."/modules/Subscriptions/subscription.php";
}
       
$smarty->assign("specials",$specials);

?>


Example: http://www.shopping-carts-upgrades.com/

:wink:

Online Michael 07-02-2005 07:38 AM

Quote:

Originally Posted by shan
Anyone created this as a side menu like the bestsellers has ?


Your wish is my command.... :wink: Here is the code:

Replace the entire code in the specials.tpl with this:

Code:

{* $Id: specials.tpl,v 1.3.2.1 2004/11/16 11:15:01 max Exp $ *}
{if $specials ne ""}
{capture name=specials}
<TABLE cellpadding="0" cellspacing="2" border="0">
{section name=num loop=$specials}
<TR>
<TD width="30">
{include file="product_thumbnail.tpl" productid=$specials[num].productid image_x=25 product=$specials[num].product}
</TD>
<TD>
{$specials[num].product}

<S>{include file="currency.tpl" value=$specials[num].list_price}</S>
Now:{include file="currency.tpl" value=$specials[num].price}

</TD>
</TR>
{/section}
</TABLE>
{/capture}
{include file="menu.tpl" menu_title= "Hot Specials" menu_content=$smarty.capture.specials extra="width=100%"}
{/if}


Insert the following line of code where ever you want the specials to appear in the skin1/customer/home.tpl file:

Code:

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

That's about it...enjoy :D

Oh, and btw, this works fine on 4.0.13

torola 07-13-2005 04:02 PM

Hello,

I am kind of lost here, can somone please recap and put all mods together, and show final instructions exactly what needs to be done to get this mod to be working.

Thanks you,

torola 07-14-2005 06:26 AM

Hi, me again I figured it out, its working, great!

However is there a way to select a category or categories from which you only want to show the discouted products in the "Hot specials" list?

I mean I have 10 categories, but I only want to show products from 3 of them in the "Hot specials" list.

Thanks
Tom

chamberinternet 10-07-2005 09:12 AM

Hello ..

Will this mod work with v4.0.15 ?

Thanks & Regards

:sK

chamberinternet 10-09-2005 05:00 AM

Quote:

Originally Posted by chamberinternet
Will this mod work with v4.0.15 ?


Yup ... seems to ...

:sK

yages 10-17-2005 12:35 PM

How do you limit this mod to to show only one category

Online Michael 10-17-2005 05:00 PM

yages,

check out this Clearance mod if you just want one category limit:

http://forum.x-cart.com/viewtopic.php?t=20781&highlight=
Hope this helps :)

micromedia 11-13-2005 06:31 PM

Hello,

I am kind of lost here, can somone please recap and put all mods together, and show final instructions exactly what needs to be done to get this mod to be working.

Thanks you,


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

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