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)
-   -   Buy $xxx get product X for free Coupon (https://forum.x-cart.com/showthread.php?t=2456)

adpboss 04-25-2003 02:12 PM

Buy $xxx get product X for free Coupon
 
I would love a coupon that allows me to specify a free product if the sale is over X amount. The link would have to be based on ProductID or SKU if possible. I certainly wouldn't want to lose realtime inventory tracking.

An option for whether shipping is applicable on that free product or not would be useful to some.

A customer meeting the coupon amount would apply the code and the product would appear in the cart at a price of $0. If they remove items from the cart, the free product would disappear if the cart total drops below the coupon threshold.

This would be a great addition to the X-Cart arsenal! The most important thing is to treat your customers well, have the email templates explain what you need them to, and the opportunity to market/sell/promote be everywhere.

:)

amy2203 11-10-2004 04:14 AM

This would be great!

I'm just searching the archives for a way to do just this (looks like not possible)

I would also like to be able to offer a discount on a certain product if the total order is over a set amount, eg order over бё15 get product X for half price...

i wish i wish i wish...

cotc2001 12-17-2004 04:25 AM

Im after something similair for 4.0.5

Our supplier has sent us 45 bottles of shower foam to give away to our customer , which we want to do if they order 3 items of anything or spend over a certain amount (havent decided which yet).

So what i'm looking to do is add the item as a product but not make it visible on the shop and give it a 0.00 price.

Then somehow be able to automatically add it to the basket if the order is over say бё30.00 or total item quantity is > 3

Looks like it might be a mod job but wallet is looking a little thin these days so it might have to wait.

kpayne 12-17-2004 06:33 AM

I've actually done this mod before. It was quite complex because it affected the big hairy functions in func.php that create the cart object & your order totals, etc. That means that your upgradability goes right out the window.

We had done just what cotc said, add a product to the cart, but we let it be visible. If you used a certain coupon code it would add the product to the cart automatically and set the value of the coupon to the price of the product. If you removed the coupon, or didn't qualify anymore (because you removed something from the cart, etc.) then the product would just be full price and still in your cart.

Sadly, the mod was done for 3.3.4 and would have to be recreated for a current version of the cart. And, again, because it touches some of the sensitive parts of the cart, I don't want to code it, release it, support it, and follow x-cart's upgrades with it and I wouldn't expect any of the other devs to want to do that either.

One solution I have seen, though, is to just add an option to a product. Put in the description that this product comes with a free t-shirt, then put "Free Shirt Color" as a product option and make sure the people packing your orders know to include a free shirt!

That approach is very safe, but also very limited.

cotc2001 12-17-2004 06:53 AM

My site is sooo mod'ed simple upgradeing is straight out the window anyway.

The mod you created seems quite different in what I had in mind, you describe it as having to enter a code for getting the free productr, what I was thinking was more automatic (your mod sounded good though), so the customer didnt have to do anything extra to get their free gift.

I think the option for the moment is just to mention the promotion quite visually on the home page and just word it as "buy 3 items and we'll pop this in the bag for you as well" and not to bother to actually list it in the invoice....... well do that for the moment anyway until I have time to get my head around creating a proper brief for the mod.

kpayne 12-17-2004 07:00 AM

Not having that "free" product on the invoice -- that gonna mess up your books?

cotc2001 12-17-2004 07:05 AM

No coz they were free to us, our supplier has given them away to us for nothing to use as incentives i.e the more our customers buy, the more we need to order from our supplier :D

shan 12-17-2004 07:15 AM

im sure something like this in in the pipeline from xcart from the bits of code i see in latest upgrades. could be wrong though

cotc2001 12-17-2004 07:22 AM

I don't think i'll be upgrading now until it hit's stable , i've got it pretty much working the way I want to without any major problems and to upgrade now would just be for the sake of it.

shan 12-17-2004 07:26 AM

i assume it will be a add on / paid for mod like x-aom.

again just guessing

delphi 01-10-2005 01:05 PM

I am looking for exact mod like this for my store. I would be nice if this mod is done.

What I did was, create a Coupon code, to give 100% off on a certain product. But this runs into problem if that product is added more than once. Then I got all of them off.

Any other solution?

delphi 01-20-2005 01:47 PM

I have a way to work around this issue and it gives me what I need, however, I am stuck on the last puzzle.

To accomplish this task, this is what I do:

My Needs:
If subtotal is equal or over $100 then customer can get a free DVD (productid = 28)

My solution:
First: add a product free DVD in which I had its productid=28. Make this product hidden but available to sale and give its price is $0.00

Second: Now you need to modify some code.

Open you cart_totals.tpl, add following code at the end of the code:
Code:

{if $cart.display_subtotal >="100"}
Promotion: Your subtotal is $100 or more, you are qualified to receive a FREE DVD. To receive FREE DVD, please click here to add to your cart.
{/if}

With the code above, when you customer view cart, if suborder is over or equal $100, then above message will display. If it is display, you customer need to click on this link to add free DVD to cart.


Now open you product.tpl, modify your code so that productid=28 display price is FREE, and quantity you can make it hidden to value 1. So when you customer click on add to cart for this product, it will add to the cart with quantity is 1 and price is $0.00.

Now open you cart.tpl and modify it so that you won't let your customer change the quantity of productid=28.

This should give you what you need for if buy x$x.xx then get y item forfree. However, when I got to this step, I got stuck ont he last step, that if customer decides to change the quantity of items in the cart to less than $100, then the free DVD is still in the cart.

Does any know show to solve this? If I could code to make the page automatically remove free DVD item out of the cart as soon as subtotal is less than $100. Then my whole puzzle is completed.

ian_fs 01-21-2005 01:51 AM

I think you need to do something along the lines of how the DVD got added.

For it to say if the total is less than 100 to delete the DVD from the Cart.

How you would implement this, you will have to look at the functions that take place you manually delete a product from the Cart.

Well that's how I'd start to work it out. It does sound as though it should be fairly simple to do.

Hope it helps.

balinor 01-25-2005 10:41 AM

I'm guessing that unless you are having a third party shipping this stuff out for you, you will catch it if a customer is trying to fleece you (i.e. adding multiple free products to the cart, dropping their order total to less than $100, etc). Since the free item isn't affecting the total cost, you can just make sure you only add one item to their shipment. Seems to be the easiest fix until X-Cart (or an eager pro) comes up with a mod.

MonkeyClan 02-10-2005 11:55 AM

One Solution
 
see my next post

MonkeyClan 02-10-2005 12:48 PM

One Solution
 
I have managed to get this to work for our store... It requires a lot of modifications and we've already done so many to other parts of our site that it's going to be difficult to explain exactly where the modifications should be made but anyone with a little experience modding X-Cart should be able to figure it out... We haven't fully beta-tested it yet, but so far it seems to be working fine...

Keep in mind that the Free Gifts you add should have a price of 0.00, be available for sale, and be in a category that can't be accessed via normal browsing of the site. This was easy to accomplish with our site design but it may or may not be so simple with yours.


STEP 1
--------
Add a "Free Gifts" menu item (or whatever you want to call it) to the admin menu under "Inventory". We put it just under "Coupons".
In /skin1/provider/menu.tpl, add:
Code:

{if $active_modules.Discount_Coupons ne ""}
Coupons

{/if}
Free Gifts



STEP 2
--------
Create the Free Gifts table in the database. We called it "xcart_freegifts" and it has the following structure:
Code:

CREATE TABLE `xcart_freegifts` (
  `id` int(11) NOT NULL auto_increment,
  `productid` int(11) NOT NULL default '0',
  `minimum_price` decimal(12,2) NOT NULL default '0.00',
  `active` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;



STEP 3
--------
Create a bunch of functions in func.php for handling the Free Gifts. Some of the function might be reduntant but I just made what I needed and didn't think too much about it.

Code:

function func_get_free_gifts($onlyActive = false) {
        $query = "SELECT id, productid, minimum_price, active FROM xcart_freegifts";
        if ($onlyActive) { $query .= " WHERE active = 1"; }
        $query .= " ORDER BY minimum_price";
        $freeGifts = func_query($query);
        if (!is_array($freeGifts)) { $freeGifts = array(); }
        return $freeGifts;
}

function func_free_gift_of_price_exists($minimum_price) {
        $query = "SELECT id FROM xcart_freegifts WHERE minimum_price = " . $minimum_price;
        $freegift = func_query_first($query);
        return count($freegift);
}

function func_free_gift_of_product_exists($productid) {
        $query = "SELECT id FROM xcart_freegifts WHERE productid = " . $productid;
        $freegift = func_query_first($query);
        return count($freegift);
}

function func_add_free_gift($productid, $minimum_price, $active) {
        $query = "INSERT INTO xcart_freegifts (productid, minimum_price, active) VALUES(" . $productid . ", " . $minimum_price . ", " . $active . ")";
        db_query($query);
        return mysql_affected_rows();
}

function func_update_free_gift_price($id, $minimum_price) {
        $query = "UPDATE xcart_freegifts SET minimum_price = " . $minimum_price . " WHERE id = " . $id;
        db_query($query);
        return mysql_affected_rows();
}

function func_activate_free_gift($id) {
        $query = "UPDATE xcart_freegifts SET active = 1 WHERE id = " . $id;
        db_query($query);
        return mysql_affected_rows();
}

function func_deactivate_free_gift($id) {
        $query = "UPDATE xcart_freegifts SET active = 0 WHERE id = " . $id;
        db_query($query);
        return mysql_affected_rows();
}

function func_delete_free_gift($id) {
        $query = "DELETE FROM xcart_freegifts WHERE id = " . $id;
        db_query($query);
        return mysql_affected_rows();
}

function func_product_exists_is_avail($productid) {
        $query = "SELECT * FROM xcart_products WHERE productid = " . $productid . " AND forsale = 'Y'";
        return count(func_query_first($query));
}

function func_get_product_name($productid) {
        $query = "SELECT product FROM xcart_products WHERE productid = " . $productid;
        $product = func_query_first($query);
        return $product["product"];
}



STEP 4
--------
Create provider/freegifts.php for handling all the admin modifications to the Free Gifts. Here's the code for that page:
Code:

<?
require "../smarty.php";
require "../config.php";
require "./auth.php";
require "../include/security.php";

$actionMsg = "";

if ($mode == "add") {
        if (isset($_REQUEST["productid"]) && isset($_REQUEST["minimum_price"]) && ($_REQUEST["productid"] != "") && ($_REQUEST["minimum_price"] != "")) {
                if (func_product_exists_is_avail($_REQUEST["productid"])) {
                        if (!func_free_gift_of_product_exists($_REQUEST["productid"])) {
                                $minimumPrice = floatval($_REQUEST["minimum_price"]);
                                if (!func_free_gift_of_price_exists($minimumPrice)) {
                                        if ($minimumPrice > 0) {
                                                $active = (isset($_REQUEST["active"]) && ($_REQUEST["active"] == "1")) ? "1" : "0";
                                                func_add_free_gift($_REQUEST["productid"], $minimumPrice, $active);
                                        } else {
                                                $actionMsg = "The minimum price is invalid.";
                                        }
                                } else {
                                        $actionMsg = "That minimum price has already been used.";
                                }
                        } else {
                                $actionMsg = "That product has already been used.";
                        }
                } else {
                        $actionMsg = "Product does not exist or is not available for sale.";
                }
        }

} else if ($mode == "delete") {
        if (isset($_REQUEST["id"]) && ($_REQUEST["id"] != "")) {
                func_delete_free_gift($_REQUEST["id"]);
        }
       
} else if ($mode == "update") {
        if (isset($_REQUEST["id"]) && ($_REQUEST["id"] != "")) {
                if ($_REQUEST["minimum_price_" . $_REQUEST["id"]] != $_REQUEST["old_minimum_price_" . $_REQUEST["id"]]) {
                        if (isset($_REQUEST["minimum_price_" . $_REQUEST["id"]]) && ($_REQUEST["minimum_price_" . $_REQUEST["id"]] != "")) {
                                $minimumPrice = floatval($_REQUEST["minimum_price_" . $_REQUEST["id"]]);
                                if (!func_free_gift_of_price_exists($minimumPrice)) {
                                        if ($minimumPrice > 0) {
                                                func_update_free_gift_price($_REQUEST["id"], $minimumPrice);
                                        } else {
                                                $actionMsg = "The minimum price is invalid.";
                                        }
                                } else {
                                        $actionMsg = "That minimum price has already been used.";
                                }
                        } else {
                                $actionMsg = "The minimum price is invalid.";
                        }
                }
                if (isset($_REQUEST["active_" . $_REQUEST["id"]]) && ($_REQUEST["active_" . $_REQUEST["id"]] == "1")) {
                        func_activate_free_gift($_REQUEST["id"]);
                } else {
                        func_deactivate_free_gift($_REQUEST["id"]);
                }
        }
}



$freegifts = func_get_free_gifts();


$smarty->assign("freegifts",$freegifts);
$smarty->assign("freegifts_actionmsg",$actionMsg);
$smarty->assign("main","freegifts");

@include "../modules/gold_display.php";
$smarty->display("provider/home.tpl");
?>



STEP 5
--------
Add the redirect call in skin1/single/home.tpl just below Coupons for consistency.
Code:

{elseif $main eq "coupons"}
{include file="modules/Discount_Coupons/coupons.tpl"}

{elseif $main eq "freegifts"}
{include file="provider/main/freegifts.tpl"}



STEP 6
--------
Create skin1/provider/main/freegifts.tpl. The code is as follows:
Code:

{include file="location.tpl" last_location="Free Gifts"}

This page allows you to define free gifts that will be offered to customers if they spend a minimum amount that you specify.  The free gifts should have their price set to 0 and be available for sale but should not be accessible via normal browsing of the site.



When a customer spends equal to or more than the minimum amount they will be notified of the promotion and will need to click on the link provided to add the item to their cart.  If they remove items from their cart such that the cart total drops below the minimum price the item will be removed from their cart.




{capture name=dialog}
<table border="0">

{if $freegifts_actionmsg ne ""}
<tr><td colspan=5 class=AdminTitle>{$freegifts_actionmsg}</td></tr>
<tr><td colspan=5></td></tr>
{/if}

<form action="freegifts.php" method="POST">
<input type=hidden name="mode" value="add">
<input type=hidden name="id" value="">

<tr class=TableHead><TD>Active</TD><td>Product ID</td><td>Minimum Price</td><td></td></tr>

{section name=whichFreeGift loop=$freegifts}
<input type=hidden name="old_minimum_price_{$freegifts[whichFreeGift].id}" value="{$freegifts[whichFreeGift].minimum_price}">
<tr>
        <td align=center><input type=checkbox name="active_{$freegifts[whichFreeGift].id}" value=1{if $freegifts[whichFreeGift].active eq 1} checked{/if}></td>
        <td>{$freegifts[whichFreeGift].productid}</td>
        <td><input type=text name="minimum_price_{$freegifts[whichFreeGift].id}" size=10 value="{$freegifts[whichFreeGift].minimum_price}"></td>
        <td>
                <input type="button" value="Update" onClick="this.form.mode.value='update'; this.form.id.value='{$freegifts[whichFreeGift].id}'; this.form.submit();">
                <input type="button" value="Delete" onClick="this.form.mode.value='delete'; this.form.id.value='{$freegifts[whichFreeGift].id}'; this.form.submit();">
        </td>
</tr>
{/section}

{if $smarty.section.whichFreeGift.total}
<tr><td colspan=5></td></tr>
{/if}

<tr><td colspan=5 class=AdminTitle>Add a new Free Gift</td></tr>
<tr>
        <td align=center><input type=checkbox name="active" value=1></td>
        <td><input type=text name=productid size=10 value=""></td>
        <td><input type=text name=minimum_price size=10 value="0.00"></td>
        <td><input type="submit" value="Add Free Gift"></td>
</tr>

</form>

</table>
{/capture}
{include file="dialog.tpl" title="EDIT FREE GIFTS" content=$smarty.capture.dialog extra="width=100%"}



STEP 7
--------
Add the promotion text somewhere at the bottom of skin1/customer/main/cart_totals.tpl. The code below is just a generic version. Modify it to fit your site design.
Code:

{section name=ofg loop=$offerFreeGifts}
        {if $smarty.section.ofg.index eq 0}
       

        Congratulations!  You qualify for a free promotion.  To claim your free gift, please choose from:

        {/if}
        Your subtotal is ${$offerFreeGifts[ofg].minimum_price} or more.  To receive a free {$offerFreeGifts[ofg].product}, click here

{/section}



STEP 8
--------
Add the following code to customer/cart.php. Somewhere at the top, maybe after "$intershipper_recalc = 'Y'", put:
Code:

#
# GET ACTIVE FREE GIFTS
#
$activeFreeGifts = func_get_free_gifts(true);


After the code that checks if the cart is empty and includes the Discount Coupons module if it's active, below "$smarty->assign('cart', $cart);", and above the Redirect code put the code below. Keep in mind that it's very important that this code be put in the right place otherwise your additions and removals from your cart won't work properly.
Code:

#
# UPDATE CART BASED ON FREE GIFTS
#
$offerFreeGifts = array();
foreach ($activeFreeGifts as $freeGift) {
        $foundFreeGift = false;
        if ($freeGift["minimum_price"] > $cart["total_cost"]) {
                foreach ($cart["products"] as $checkFreeGiftProduct) {
                        if ($checkFreeGiftProduct["productid"] == $freeGift["productid"]) {
                                $foundFreeGift = true;
                        }       
                }
                if ($foundFreeGift) {
                        // Remove free gift
                        $tempProducts = array();
                        foreach ($cart["products"] as $checkProductForRemove) { if ($checkProductForRemove["productid"] != $freeGift["productid"]) { $tempProducts[] = $checkProductForRemove; } }
                        $cart["products"] = $tempProducts;
                        func_header_location("cart.php");
                }
        } else {
                foreach ($cart["products"] as $checkFreeGiftProduct) {
                        if ($checkFreeGiftProduct["productid"] == $freeGift["productid"]) {
                                $foundFreeGift = true;
                        }       
                }
                if (!$foundFreeGift) {
                        // Offer the free gift
                        $offerFreeGifts[] = array(        "minimum_price" => $freeGift["minimum_price"],
                                                        "productid" => $freeGift["productid"],
                                                        "product" => func_get_product_name($freeGift["productid"]));
                }
        }
}


Lastly, send the two arrays to the smarty templating engine:
Code:

$smarty->assign("activeFreeGifts", $activeFreeGifts);
$smarty->assign("offerFreeGifts", $offerFreeGifts);



STEP 9
--------
In skin1/customer/main/product.tpl you'll have to change the code that prints the price of the item. Our product.tpl is heavily modified so all I can say is that instead of showing a text input field when the price is 0.00 you should put text that says "FREE!" or something like that. For us, it looks something like this:
Code:

        <td>{if $product.price ne 0}<font class=ProductDetailsTitle>{include file="currency.tpl" value=$product.price}</font>{else}<font class=ProductDetailsTitle>FREE!</font>{/if}</td>


STEP 10
----------
In skin1/customer/main/cart.tpl or skin1/customer/main/cart_contents.tpl (depending on your setup) you have to do something along these lines so that the quantity input field doesn't show up if it's a free gift:
Code:

        {assign var="isFreeGift" value="0"}
        {section name=afg loop=$activeFreeGifts}
                {if $activeFreeGifts[afg].productid eq $products[product].productid}
                        {assign var="isFreeGift" value="1"}
                {/if}
        {/section}
        {if $isFreeGift eq "1"}
1
        {else}
       
{if $products[product].distribution}1<input type=hidden{else}<input type=text size=3{/if} name="productindexes[{$smarty.section.product.index}]" value="{$products[product].amount}">
        {/if}



That's all of it... If anyone needs any help let me know!

Atul

MonkeyClan 04-04-2005 12:23 PM

Update to my solution...
 
The original mod I posted was based on a modded Version 3.4.14 installation. I recently got it to work on a Version 4.0.12 installation. I also added a feature called Notification Price that tells the customer that if they spend $XX more they'll get a free gift. Here are the differences and modifications.


STEP 1
--------
This step should be as follows:
Code:

{if $active_modules.Discount_Coupons ne ""}
{$lng.lbl_coupons}

{/if}
Free Gifts



STEP 2
--------
The "xcart_freegifts" table now has the following structure:
Code:

REATE TABLE `xcart_freegifts` (
  `id` int(11) NOT NULL auto_increment,
  `productid` int(11) NOT NULL default '0',
  `minimum_price` decimal(12,2) NOT NULL default '0.00',
  `notification_price` decimal(12,2) default NULL,
  `active` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;



STEP 3
--------
The following functions were either modified or added:
Code:

function func_get_free_gifts($onlyActive = false) {
  $query = "SELECT fg.id, fg.productid, p.product, fg.minimum_price, fg.notification_price, fg.active FROM xcart_freegifts fg LEFT JOIN xcart_products p ON fg.productid = p.productid";
  if ($onlyActive) { $query .= " WHERE active = 1"; }
  $query .= " ORDER BY minimum_price";
  $freeGifts = func_query($query);
  if (!is_array($freeGifts)) { $freeGifts = array(); }
  return $freeGifts;
}

function func_add_free_gift($productid, $minimum_price, $notification_price, $active) {
  $notificationPriceStr = ($notification_price) ? $notification_price : "NULL";
  $query = "INSERT INTO xcart_freegifts (productid, minimum_price, notification_price, active) VALUES(" . $productid . ", " . $minimum_price . ", " . $notificationPriceStr . ", " . $active . ")";
  db_query($query);
  return mysql_affected_rows();
}

function func_update_free_gift_notification_price($id, $notification_price) {
  $notificationPriceStr = ($notification_price) ? $notification_price : "NULL";
  $query = "UPDATE xcart_freegifts SET notification_price = " . $notificationPriceStr . " WHERE id = " . $id;
  db_query($query);
  return mysql_affected_rows();
}



STEP 4
--------
provider/freegifts.php is also different:
Code:

<?
require "./auth.php";
require $xcart_dir."/include/security.php";
include $xcart_dir."/include/categories.php";

$actionMsg = "";

if ($mode == "add") {
  if (isset($fg_productid) && isset($fg_minimum_price) && ($fg_productid != "") && ($fg_minimum_price != "")) {
      if (func_product_exists_is_avail($fg_productid)) {
        if (!func_free_gift_of_product_exists($fg_productid)) {
            $minimumPrice = floatval($fg_minimum_price);
            $notificationPrice = ($fg_notification_price) ? floatval($fg_notification_price) : "";
            if (!func_free_gift_of_price_exists($minimumPrice)) {
              if ($minimumPrice > 0) {
                  if (($notificationPrice == "") || ($notificationPrice < $minimumPrice)) {
                    $active = (isset($fg_active) && ($fg_active == "1")) ? "1" : "0";
                    func_add_free_gift($fg_productid, $minimumPrice, $notificationPrice, $active);
                  } else {
                    $actionMsg = "The notification price must be less than the minimum price.";
                  }
              } else {
                  $actionMsg = "The minimum price is invalid.";
              }
            } else {
              $actionMsg = "That minimum price has already been used.";
            }
        } else {
            $actionMsg = "That product has already been used.";
        }
      } else {
        $actionMsg = "Product does not exist or is not available for sale.";
      }
  }

} else if ($mode == "delete") {
  if (isset($fg_id) && ($fg_id != "")) {
      func_delete_free_gift($fg_id);
  }

} else if ($mode == "update") {
  if (isset($fg_id) && ($fg_id != "")) {
      $minimumPriceVar = "fg_minimum_price_" . $fg_id;
      $oldMinimumPriceVar = "fg_old_minimum_price_" . $fg_id;
      $notificationPriceVar = "fg_notification_price_" . $fg_id;
      $activeVar = "fg_active_" . $fg_id;
      if ($$minimumPriceVar != $$oldMinimumPriceVar) {
        if (isset($$minimumPriceVar) && ($$minimumPriceVar != "")) {
            $minimumPrice = floatval($$minimumPriceVar);
            if (!func_free_gift_of_price_exists($minimumPrice)) {
              if ($minimumPrice > 0) {
                  func_update_free_gift_minimum_price($fg_id, $minimumPrice);
              } else {
                  $actionMsg = "The minimum price is invalid.";
              }
            } else {
              $actionMsg = "That minimum price has already been used.";
            }
        } else {
            $actionMsg = "The minimum price is invalid.";
        }
      }
      if (isset($$notificationPriceVar)) {
        $notificationPrice = ($$notificationPriceVar) ? floatval($$notificationPriceVar) : "";
        func_update_free_gift_notification_price($fg_id, $notificationPrice);
      }
      if (isset($$activeVar) && ($$activeVar == "1")) {
        func_activate_free_gift($fg_id);
      } else {
        func_deactivate_free_gift($fg_id);
      }
  }
}

$freegifts = func_get_free_gifts();

$smarty->assign("freegifts",$freegifts);
$smarty->assign("freegifts_actionmsg",$actionMsg);
$smarty->assign("main","freegifts");

@include $xcart_dir."/modules/gold_display.php";
func_display("provider/home.tpl",$smarty);
?>



STEP 5
--------
No changes to this step...


STEP 6
--------
skin1/provider/main/freegifts.tpl is also different:
Code:

{include file="location.tpl" last_location="Free Gifts"}

This page allows you to define free gifts that will be offered to customers if they spend a minimum amount that you specify.  The free gifts should have their price set to 0 and be available for sale but should not be accessible via normal browsing of the site.



When a customer spends equal to or more than the minimum amount they will be notified of the promotion and will need to click on the link provided to add the item to their cart.  If they remove items from their cart such that the cart total drops below the minimum price the item will be removed from their cart.




{capture name=dialog}
<table border="0">

{if $freegifts_actionmsg ne ""}
<tr><td colspan=5 class=AdminTitle>{$freegifts_actionmsg}</td></tr>
<tr><td colspan=5></td></tr>
{/if}

<form action="freegifts.php" method="POST">
<input type=hidden name="mode" value="add">
<input type=hidden name="fg_id" value="">

<tr class=TableHead><TD>Active</TD><td>Product ID</td><td>Minimum Price</td><td>Notification Price</td><td></td></tr>

{section name=whichFreeGift loop=$freegifts}
<input type=hidden name="fg_old_minimum_price_{$freegifts[whichFreeGift].id}" value="{$freegifts[whichFreeGift].minimum_price}">
<tr>
  <td align=center><input type=checkbox name="fg_active_{$freegifts[whichFreeGift].id}" value=1{if $freegifts[whichFreeGift].active eq 1} checked{/if}></td>
  <td>{$freegifts[whichFreeGift].productid} ({$freegifts[whichFreeGift].product})</td>
  <td><input type=text name="fg_minimum_price_{$freegifts[whichFreeGift].id}" size=10 value="{$freegifts[whichFreeGift].minimum_price}"></td>
  <td><input type=text name="fg_notification_price_{$freegifts[whichFreeGift].id}" size=10 value="{$freegifts[whichFreeGift].notification_price}"></td>
  <td>
      <input type="button" value="Update" onClick="this.form.mode.value='update'; this.form.fg_id.value='{$freegifts[whichFreeGift].id}'; this.form.submit();">
      <input type="button" value="Delete" onClick="this.form.mode.value='delete'; this.form.fg_id.value='{$freegifts[whichFreeGift].id}'; this.form.submit();">
  </td>
</tr>
{/section}

{if $smarty.section.whichFreeGift.total}
<tr><td colspan=5></td></tr>
{/if}

<tr><td colspan=5 class=AdminTitle>Add a new Free Gift</td></tr>
<tr>
  <td align=center><input type=checkbox name="fg_active" value=1></td>
  <td><input type=text name=fg_productid size=10 value=""></td>
  <td><input type=text name=fg_minimum_price size=10 value="0.00"></td>
  <td><input type=text name=fg_notification_price size=10 value=""></td>
  <td><input type="submit" value="Add Free Gift"></td>
</tr>

</form>

</table>
{/capture}
{include file="dialog.tpl" title="EDIT FREE GIFTS" content=$smarty.capture.dialog extra="width=100%"}



STEP 7
--------
skin1/customer/main/cart_totals.tpl is also different:
Code:

{section name=nfg loop=$notifyFreeGifts}
  {if $smarty.section.nfg.index eq 0}
     

  {/if}
  Spend ${$notifyFreeGifts[nfg].spend_more_amount} more and get a free {$notifyFreeGifts[nfg].product}!

{/section}

{section name=ofg loop=$offerFreeGifts}
  {if $smarty.section.ofg.index eq 0}
     

      Congratulations!  You qualify for {if $smarty.section.ofg.total > 1}some{else}a{/if} free promotion{if $smarty.section.ofg.total > 1}s{/if}.{if $smarty.section.ofg.total > 1}  To claim your free gifts, please choose from:{/if}

  {/if}
  Your subtotal is ${$offerFreeGifts[ofg].minimum_price} or more.  To receive a free {$offerFreeGifts[ofg].product}, click here

{/section}



STEP 8
--------
Instead of modifying customer/cart.php, you have to modify cart.php in the root directory of your store. The top section which gets the active free gifts stays the same, but the other sections are modified as follows:

Code:

#
# UPDATE CART BASED ON FREE GIFTS
#
$offerFreeGifts = array();
$notifyFreeGifts = array();
foreach ($activeFreeGifts as $freeGift) {
  $foundFreeGift = false;
  if ($freeGift["minimum_price"] > $cart["total_cost"]) {
      if (isset($cart["products"]) && is_array($cart["products"])) {
        foreach ($cart["products"] as $checkFreeGiftProduct) {
            if ($checkFreeGiftProduct["productid"] == $freeGift["productid"]) {
              $foundFreeGift = true;
            } 
        }
      }
      if ($foundFreeGift) {
        // Remove free gift
        $tempProducts = array();
        foreach ($cart["products"] as $checkProductForRemove) { if ($checkProductForRemove["productid"] != $freeGift["productid"]) { $tempProducts[] = $checkProductForRemove; } }
        $cart["products"] = $tempProducts;
        func_header_location("cart.php");
      } else if ($freeGift["notification_price"] && ($freeGift["notification_price"] <= $cart["total_cost"])) {
        // Notify of the free gift
        $notifyFreeGifts[] = array("notification_price" => $freeGift["notification_price"],
                                    "spend_more_amount" => sprintf("%0.2f", ($freeGift["minimum_price"] - $cart["total_cost"])),
                                    "productid" => $freeGift["productid"],
                                    "product" => func_get_product_name($freeGift["productid"]));
      }
  } else {
      foreach ($cart["products"] as $checkFreeGiftProduct) {
        if ($checkFreeGiftProduct["productid"] == $freeGift["productid"]) {
            $foundFreeGift = true;
        } 
      }
      if (!$foundFreeGift) {
        // Offer the free gift
        $offerFreeGifts[] = array("minimum_price" => $freeGift["minimum_price"],
                                  "productid" => $freeGift["productid"],
                                  "product" => func_get_product_name($freeGift["productid"]));
      }
  }
}


Code:

$smarty->assign("activeFreeGifts", $activeFreeGifts);
$smarty->assign("offerFreeGifts", $offerFreeGifts);
$smarty->assign("notifyFreeGifts", $notifyFreeGifts);



STEP 9
--------
I also noticed you have to modify skin1/customer/main/product.tpl so that the customer cannot select more than 1 free item at a time. So in addition to the other changes, do something like the following in the section where it prints the quantity select box:
Code:

{if $product.distribution eq ""}
{if $product.taxed_price eq 0}
<FONT class="ProductDetailsTitle">1</FONT><INPUT type="hidden" name="amount" value="1">
{else}
{if $product.min_amount le 1}
{assign var="start_quantity" value=1}
{else}
{assign var="start_quantity" value=$product.min_amount}
{/if}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var min_avail = {$start_quantity|default:1};
var avail = {$mq|default:1}-1;
var product_avail = {$product.avail|default:"0"};
</SCRIPT>
<SELECT id="product_avail" name="amount"{if $active_modules.Product_Options ne ''} onchange="check_wholesale(this.value);"{/if}>
{section name=quantity loop=$mq start=$start_quantity}
<OPTION value="{%quantity.index%}" {if $smarty.get.quantity eq %quantity.index%}selected{/if}>{%quantity.index%}</OPTION>
{/section}
</SELECT>
{/if}
{else}
<FONT class="ProductDetailsTitle">1</FONT><INPUT type="hidden" name="amount" value="1"> {$lng.txt_product_downloadable}
{/if}



STEP 10
---------
No changes to this step...


I hope all of that makes sense...

Atul

balinor 04-05-2005 07:30 AM

Hey Atul, great mod, works great! You might want to re-post this as a new thread in the Custom Mods section, as it gets rather lost in this thread.

DataViking 03-09-2007 02:04 PM

Re: Buy $xxx get product X for free Coupon
 
i'm looking for somehting similar for version 4.1.6

buy 3 dvds and get a free gisft bag

any ideas

balinor 03-09-2007 02:55 PM

Re: Buy $xxx get product X for free Coupon
 
Take a look at the Special Offers mod available at X-Cart.com

carpeperdiem 03-09-2007 05:04 PM

Re: Buy $xxx get product X for free Coupon
 
The more I look at X-SO, the more i come to the realization that someone will make a killing if they build a better mousetrap.

X-SO is quite simply, a mess. TERRIBLE user interface - breaks every usability convention.

I was a moment away from buying it this morning... but after reading 100 or so posts, and making my own requests for the past few days, and not a single person had anything nice to say about it -- and then I found a few dozen sites that had it installed -- and without wasting too much of their bandwidth, I concluded that not one of these sites using X-SO, effectively encouraged the customer to buy anything... It was like "hey, we're real geeky - check out all the software we have on our site". This isn't meant to be a rant... just an observation.

Maybe X-SO could be hacked into something good. but out of the box - I'm not going to spend a moment on it. The entire flowchart of the shopping transaction and user experience must be evaluated. And the mod needs to do some very common special offers, such as:

"free gift with purchase"
buy x get y free,
buy minimum qty of X get anything from category Z
spend X get % discount

AND MOST IMPORTANT -- it must auto populate the cart with the offer, once the threshold is met. The customer shouldn't have to do anything. AND - it should allow an incoming link to target the offer... so an inbound URL makes the offer work -- all others don't et the special, But I am way off-topic now.

wites 03-15-2007 02:45 AM

Re: Buy $xxx get product X for free Coupon
 
hi MonkeyClan great job on the mod.

Anyway, my question is that, does it always have to loop the free gifts?

In your mod the output is this

1. order subtotal = $50.00
customer gets free gift 1

2. order subtotal = $100.00
customer gets free gift 1
customer gets free gift 2

what i have in mind is something like

1. order subtotal = $50.00
customer gets free gift 1

2. order subtotal = $100.00
customer gets free gift 2 (not showing free gift 1)


All times are GMT -8. The time now is 11:12 PM.

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