Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Easy Discount


boxtel

Recommended Posts

Hello Amanda and all others who use Easy Discount,

 

I wonder if you could possibly help me with a few pointers as to where to start with the logic required to give the discount I need on my store.

 

The case is this:

 

Have installed Happy Hour Specials mod which allows an item to be discounted by setting a specials price on a timed schedule. I am going to load the HHS table with 313 items, each to be discounted for 24 hrs (48 in the case of a weekend). The site will then set the "Design of the Day" as a Special, automatically discounted by £2. All our products have a base price of £15, with ordinary osC modifiers for variations in price.

 

What I also require is that if a customer buys the "Design of the Day" (valid only on that day of course) they get another £2 off 1 other item added to their cart.

 

Reading through this thread I feel that the logic would be along the lines below but how to start writing the code for it? I apologise, but I'm not a programmer, I'm a script butcher! I can cut 'n paste with the best of them!

 

Logic:

 

1) Check if there's anything in the cart.

2) See if what is in the cart is a "Special" - read from HHS Table and checked for date - set a variable saying "DOTD Purchased" = True

3) Check for other items in cart - "If $cart count > 1"

4) Apply £2 Discount via ED to subtotal. "If DOTD Purchased" = True then apply discount.

 

I would also assume that I need the code for steps 1, 2 & 3 in application_top so it's always evaluated, since they can add the Special to the cart at any time during their visit, then the code for step 4 in Shopping_Cart.php to apply the discount.

 

Am I on the right lines for this and where do I start??

 

We show all prices including Tax so Tax calculation not required.

We offer free shipping within the UK, and fixed price shipping addition to ROTW so that is not an issue either.

 

We also offer Volume discount and Customer Loyalty discount but since the discount I want to offer is a fixed £2 and not a percentage, that shouldn't be an issue either.

 

Any help much appreciated.

 

Simon

Link to comment
Share on other sites

  • 1 month later...

I read/searched through this whole thread and even though there a lot of shipping questions/answers I cannot find what I need.

 

I want to be able to give the customer 50% off their shipping cost upon checkout.

 

Any help would be greatly appreciated.

Samuel Mateo, Jr.

osC 2.2 MS2

Installed Mods:

WYSIWYG HTMLArea 1.7 | Basic Template System 1.0 | osC-Affiliate | OSC-SupportTicket

Featured Products 1.3 | LoginBox 5.2 | LatestNews 1.1.3 | Extras for IE

Link to comment
Share on other sites

Actually it's supposed to be 50% off USPS First Class and Priority Mail Only there are other options that cannot be discounted.

Samuel Mateo, Jr.

osC 2.2 MS2

Installed Mods:

WYSIWYG HTMLArea 1.7 | Basic Template System 1.0 | osC-Affiliate | OSC-SupportTicket

Featured Products 1.3 | LoginBox 5.2 | LatestNews 1.1.3 | Extras for IE

Link to comment
Share on other sites

Does this look right? I don't want to make it go live and break the site. There are people always on it.

 

// 50% discount on USPS First Class and Priority Shipping
if ($cart->delivery(First Class, Priority)) {
$easy_discount->add('HalfShip','50% off Shipping',$cart->show_total()*0.5);
} else {
$easy_discount->remove('HalfShip');
}

Samuel Mateo, Jr.

osC 2.2 MS2

Installed Mods:

WYSIWYG HTMLArea 1.7 | Basic Template System 1.0 | osC-Affiliate | OSC-SupportTicket

Featured Products 1.3 | LoginBox 5.2 | LatestNews 1.1.3 | Extras for IE

Link to comment
Share on other sites

OK, I have this working on our shopping cart so that when a customer orders 6 items or more, they get 10% off.

 

I've used Dales S's solution at post #509 (with modified %) and then hit the issue of the tax @17.5% being applied on the full amount still, so I then applied Amanda's post #515 for the tax correction.

 

I'm still left with the discount being applied to the pre-tax figure though so that a £100 would only get a £8.51 discount rather than the full £10 off. As a workaround, I've modified the figure in application_top.php to 0.1175 rather than 0.1 for the 10% discount. Is there a neater way that works correctly?

Link to comment
Share on other sites

Sorry, can I also add another request? We would ideally like to add a coupon type of discount (again at 10%) but only as an alternative, i.e. we don't want customers ordering 6 or more and getting 10% off then entering the coupon code and getting another 10% off.

 

We would like to be able to change the code from time to time so that the offer only applies for a limited time.

 

Any step-by-step guide to modifying the shopping cart and Easy Discount to accomplish this?

Link to comment
Share on other sites

Me again! Actually, I've noticed that the methodology to do the 10% for six or more only applies on a per item basis. Is there a way to get it to simply count the number of items ordered and apply a 10% discount if that item count exceeds 6?

 

Here's the code I'm using for the 6 items:

//set discount for individual items at 10 percent for 6 items or more
 $easy_discount->reset();
 $products = $cart->get_products();
 $n=sizeof($products);
 for ($i=0; $i<$n; $i++) {
 if (($products[$i]['quantity']) >= 6) {
 $easy_discount->set($products[$i]['id'],'Block Booking Discount ',$products[$i]['price']*$products[$i]['quantity']*0.1175);
 }
 else {
 $easy_discount->clear($products[$i]['id']);
 }
 }

Link to comment
Share on other sites

And again!

 

How would I change that code snippet to make it simply count items in the cart and then apply the 10% discount to the sub-total, e.g.:

 

Widgets 2@ £10 = £20.00

Grommets 4@ £7 = £48.00

Sub-Total £68.00

Order Discount £6.80

VAT: £9.11

Total Order Value: £61.20

 

6 items in total

Edited by CaptainBlue
Link to comment
Share on other sites

Here's the code I'm using for the 6 items:

//set discount for individual items at 10 percent for 6 items or more
 $easy_discount->reset();
 $products = $cart->get_products();
 $n=sizeof($products);
 for ($i=0; $i<$n; $i++) {
 if (($products[$i]['quantity']) >= 6) {
 $easy_discount->set($products[$i]['id'],'Block Booking Discount ',$products[$i]['price']*$products[$i]['quantity']*0.1175);
 }
 else {
 $easy_discount->clear($products[$i]['id']);
 }
 }

 

I tried switching it to this code:

//set discount for individual items at 10 percent for 6 items or more
if ($cart->count_contents() >= 6) {
// cart has contents
$discount_amount = 0;
// get the products from the cart
$cart_products = $cart->get_products();
// for each product
for ($i=0;$i<sizeof($cart_products);$i++) {
if ($cart_products[$i]['tax_class_id'] != 0) {
// product with tax so add products price to discount amount
$discount_amount =  $cart->show_total();
}
}
if ($discount_amount > 0) {
$easy_discount->set('Block','10% Block Booking Discount ',$discount_amount*0.1);
} else {
$easy_discount->clear('Block');
}
}

 

Which works fine for any 6 or more items. Trouble is when the number of items falls below 6, the last stated discount value remains in place...

Link to comment
Share on other sites

OK, I've now adjusted the code as follows:

//set discount for individual items at 10 percent for 6 items or more
if ($cart->count_contents() >= 6) {
// cart has contents
$discount_amount =  $cart->show_total();
$easy_discount->set('Block','10% Block Booking Discount ',$discount_amount*0.1);
} else {
$easy_discount->clear('Block');
}

 

This now seems to work for any 6 items in the basket.

Link to comment
Share on other sites

I'd like to use this contribution to apply a 15% discount when 12 or more regularly-priced items are purchased. Any sale items would be excluded from the count and from receiving the discount in the event there are 12+ regular items in the cart along with additional sale items. I'd also like to be able to exclude specific categories in the same fashion.

 

 

It seems like this should be relatively simple but i don't have much coding knowledge. Can anyone help with the code to do this?

 

Thanks,

Chris

Link to comment
Share on other sites

Hi,

 

Will this contribution do the following.

 

If the value of the cart goes above a set value (71.50) excluding delivery charges, a 30% discount needs to be applied.

 

Consequently, if the customer then removes an item, and the value of the cart goes below 71.50, the discount needs to be revoked.

 

If this contribution does not do this, do you know of any that will?

 

Cheers,

James

Link to comment
Share on other sites

Hi,

 

Will this contribution do the following.

 

If the value of the cart goes above a set value (71.50) excluding delivery charges, a 30% discount needs to be applied.

 

Consequently, if the customer then removes an item, and the value of the cart goes below 71.50, the discount needs to be revoked.

 

If this contribution does not do this, do you know of any that will?

 

Cheers,

James

Yes it does. Read through the rest of the thread and you should see something that you can modify to your

Samuel Mateo, Jr.

osC 2.2 MS2

Installed Mods:

WYSIWYG HTMLArea 1.7 | Basic Template System 1.0 | osC-Affiliate | OSC-SupportTicket

Featured Products 1.3 | LoginBox 5.2 | LatestNews 1.1.3 | Extras for IE

Link to comment
Share on other sites

Hi!

This is really GREAT contrib! Thanks!

Only this contrib was solved my problem.

I want to share with you this solution.

 

Problem:

We have products in different categories. For example in cat1 and cat1.

 

Products in cat1 have a discount depended from amount.

(For example(amount/percentage): 300:10,1000:15, ... 4500:50)

 

Products in cat2 have a DIFFERENT discount depended from amount.

(For example(amount/percentage): 700:10,1500:15,3000:20,7000:25,9000:30,12000:35,15000:40,20000:45,25000:50)

 

 

Solution:

//Vlad b EZ discount
//Discount for given category:
//Id's of categories which has a products with discount
//$categories_list=array('25', '24');
$categories_list=array('3', '4', '10');
if (count($categories_list)>0) {
$query="select products_id, categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . "
				where categories_id='".$categories_list[0]."'";
for( $it=1;$it<count($categories_list);$it++)	 $query.=" OR categories_id='".$categories_list[$it]."'";

$result=tep_db_query($query);
$total4discount_prod=0;
$products_in_cart=$cart->get_products();

//Make an array with products id's from specials categories:
while ($pr2cat = tep_db_fetch_array($result))	 $discount_products_list[]=$pr2cat['products_id'];
//var_dump($discount_products_list);
foreach ($products_in_cart as $cart_item) {
	if (in_array($cart_item['id'], $discount_products_list)) {
		$total4discount_prod+=$cart_item['price']*$cart_item['quantity'];
	} else	$total4discount_prod2+=$cart_item['price']*$cart_item['quantity'];
	//=========================================================
	//Calculate discount1:
	if ($total4discount_prod<300)   $discount_percent=0;
	elseif ($total4discount_prod<1000)   $discount_percent=10;
	elseif ($total4discount_prod<1500)   $discount_percent=15;
	elseif ($total4discount_prod<2000)   $discount_percent=20;
	elseif ($total4discount_prod<2500)   $discount_percent=25;
	elseif ($total4discount_prod<3000)   $discount_percent=30;
	elseif ($total4discount_prod<3500)   $discount_percent=35;
	elseif ($total4discount_prod<4000)   $discount_percent=40;
	elseif ($total4discount_prod<4500)   $discount_percent=45;
	else $discount_percent=50;
	//Calculate discount for total price of selected products:
	$easy_discount->set('D4M', '<abbr title="'.DISCOUNT_FOR_MAGAZINES_TEXT.'">-' . $discount_percent . '%</abbr>', (($total4discount_prod*$discount_percent)/100) );
	//=========================================================
	//Calculate discount2:
	if ($total4discount_prod2>=700)   $discount_percent=10;
	elseif ($total4discount_prod2>=1500)   $discount_percent=15;
	elseif ($total4discount_prod2>=3000)   $discount_percent=20;
	elseif ($total4discount_prod2>=7000)   $discount_percent=25;
	elseif ($total4discount_prod2>=9000)   $discount_percent=30;
	elseif ($total4discount_prod2>=12000)   $discount_percent=35;
	elseif ($total4discount_prod2>=15000)   $discount_percent=40;
	elseif ($total4discount_prod2>=20000)   $discount_percent=45;
	elseif ($total4discount_prod2>=25000)   $discount_percent=50;
	else $discount_percent=0;
	//Calculate discount for total price of selected products:
	$easy_discount->set('D4E', '<abbr title="'.DISCOUNT_FOR_EDITIONS_TEXT.'">-' . $discount_percent . '%</abbr>', (($total4discount_prod2*$discount_percent)/100) );
}
}
//Vlad e EZ discount

 

God bless you.

===============================

Never give up! Never give up! Never give up!

Link to comment
Share on other sites

Forgot to say:

all this code should be placed at the end of application_top.php.

 

Also if you want to use category with all subcategories use this:

$top_category_id=10;
$result=tep_db_query("select categories_id from " . TABLE_CATEGORIES." where parent_id='".$top_category_id."'");
while ($cat = tep_db_fetch_array($result))	 $categories_list[]=$cat['categories_id'];-

 

instead of:

$categories_list=array('3', '4', '10');

===============================

Never give up! Never give up! Never give up!

Link to comment
Share on other sites

Hello and happiness for your work. I am a beginner in Php and my English is not very good, sorry.

 

I have installed the version 3. 1, I have continued all the steps and reviewed many times, everything works well in the admin and I don't have error messages, but when I introduce some code it doesn't pass anything, it jumps to it paginates it following and he makes the normal process of purchase. He doesn't give message of incorrect code, neither of accepted code, neither he makes discount, anything.

 

I have looked all you paginate them but in English I don't understand a lot and at the end I am but confused that at the beginning.

 

I want to make a simple discount, I generate it with the admin and I send it to the clients that I am interested

 

After making all the steps of the installation it is necessary to make something but?Which the steps are?

 

I use translator, if somebody is so kind of please answering they don't use jargon.

Thank you

Link to comment
Share on other sites

I appologize for asking this as it has been beaten to death. My order total includes tax from the price before a discount is applied. I applied Amanda's spaghtetti patch and that corrected the tax amount display. however the total still reflects the wrong tax. How do I get the order total to add the corrected tax and not the per product tax? This is on my checkout pages.

 

Thank you,

lildog

Link to comment
Share on other sites

Hi Boxtel and friends,

 

I got the follow error:

 

Fatal error: Call to a member function on a non-object in /home/restricted/home2/indvd/public_html/loja/includes/modules/order_total/ot_easy_discount.php on line 17

 

Line 17 is = if ($easy_discount->count() > 0) {

 

Do you know what's happens?

 

Thanks

Link to comment
Share on other sites

Hi Boxtel and friends,

 

I got the follow error:

 

Fatal error: Call to a member function on a non-object in /home/restricted/home2/indvd/public_html/loja/includes/modules/order_total/ot_easy_discount.php on line 17

 

Line 17 is = if ($easy_discount->count() > 0) {

 

Do you know what's happens?

 

I forgot to say that this message appears in administration panel

 

Thanks

 

Hey guys, anyhelp? Please.

 

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...