BigCommerce - Hosted Ecommerce Software by Interspire

Interspire Forum

 
Go Back   Interspire Forum > Interspire Shopping Cart Community Forum > Customization and Integration > Code Modification and Addon Releases

Reply
 
Thread Tools Display Modes
  #1  
Old 11-20-2009, 06:44 PM
johnnybegood + johnnybegood is offline
Interspire Customer
 
Join Date: Jun 2008
Posts: 219
Default Discount Module: Category Discount when order value over $x or product X in cart

Module Revised 22/11/2009 - Added many additional features, including:
  • Ability to apply discounts storewide
  • New condition to apply discount only when there are x quantity of items in the cart
  • Sub condition of point 2 - only count items if they are present in the selected categories
  • Due to the coupon system screwing everything up if a coupon is applied now then this discount module will automatically remove any discounts
Here is a screenshot of how the admin looks with this module


Ok, here is the third discount module I'm providing here free. Out of all the discount modules I've created I think this one has the most depth and flexiblity; from a marketing point of view. People don't generally like being told what they can and can't have and this discount module attempts to deal with this. Essentially this module allows customers to choose their discounted item when they have either a specific product (and quantity) in their cart or when their order value is above $x

This module replaces the existing category discount module, however it does not eliminate any of the functionality previously available on this module. This module grew quite large very quickly and currently incorporates 12 different messages which are displayed to the customer depending on the combination of variables. For example, if trigger item in cart && if trigger item has sufficient quantity && if item from discounted category is in cart && if order value > $x etc etc ... I went a bit nuts getting my head around all these variations!

Before implementing this mod I recommend you rename the /modules/rule/"percentoffitemsincat" folder to something like "percentoffitemsincat (old)".

Once you've done that simply extract the folder in the attached zip and upload to /modules/rule/

As per my previous two discount modules you will need to make the following changes for this module to work.

Open "includes/classes/class.cart.php" and find this section:
PHP Code:
foreach ($discountMessages as $message) {
                
$GLOBALS['CartRuleMessage'] .= '<p class="InfoMessage">' GetLang('DiscountCongratulations') . ' ';
                
$GLOBALS['CartRuleMessage'] .= $message;
                
$GLOBALS['CartRuleMessage'] .= '</p>';
            } 
Just below this section add this:
PHP Code:
$discountMessages $this->api->Get('DISCOUNT_MESSAGES2');

            if (!
is_array($discountMessages)) {
                
$discountMessages = array();
            }

            foreach (
$discountMessages as $message) {
                
$GLOBALS['CartRuleMessage'] .= '<p class="InfoMessage">';
                
$GLOBALS['CartRuleMessage'] .= $message;
                
$GLOBALS['CartRuleMessage'] .= '</p>';
            } 
Next open "includes/classes/class.cart.api.php" and find this line:
PHP Code:
$this->cartSession['DISCOUNT_MESSAGES'] = null
and just below this add:
PHP Code:
$this->cartSession['DISCOUNT_MESSAGES2'] = null
Also, if you haven't done this already I highly recommend making the following change if you use the suggestive cart feature:

Open "templates/_master/suggestive_cart.html" and add this:
HTML Code:
%%Panel.CartRuleMessage%%
just after:
HTML Code:
%%Panel.CartFreeShipping%%
This basically allows discount messages to be displayed to customers when they view the suggestive cart page.
Attached Images
File Type: gif discount2.gif (29.1 KB, 77 views)
File Type: gif discount3.gif (43.0 KB, 73 views)
File Type: gif discount4.gif (58.8 KB, 70 views)
Attached Files
File Type: zip percentoffitemsincat.zip (7.3 KB, 125 views)

Last edited by johnnybegood; 11-22-2009 at 07:26 AM..
Reply With Quote
  #2  
Old 11-20-2009, 09:16 PM
hgmobile + hgmobile is offline
Interspire Customer
 
Join Date: Feb 2009
Posts: 87
Default

What happens if the customer happens to put the "discounted" item in the shopping cart before reaching a "trigger" amount. Will the cart automatically give them the discount and display the message? Or do they have to remove the item and add it back?
Reply With Quote
  #3  
Old 11-21-2009, 01:58 AM
johnnybegood + johnnybegood is offline
Interspire Customer
 
Join Date: Jun 2008
Posts: 219
Default

Quote:
Originally Posted by hgmobile View Post
What happens if the customer happens to put the "discounted" item in the shopping cart before reaching a "trigger" amount. Will the cart automatically give them the discount and display the message? Or do they have to remove the item and add it back?
NO, they wouldn't get the discount as this would defeat the purpose of this module!!! Depending on what the trigger is and if the condition on that trigger has been met, the message will display accordingly. All the language variables are editable via the included language file if you need to tweak the phrasing. Also, you can stop messages displaying when an item from the discounted category isn't present in the cart. Look at the first image post #1 in this thread and you'll see an option to choose whether you want these messages displayed or not.

To give you an idea of just how much work went into the messages; below is all the different clauses to display messages:
PHP Code:
//Run messages when no clause is set
        
        //Message 1 - Clause = 0 [+] discount category item in cart = NO [+] forced discount message = YES
        
if ($this->clause == && $discountcatitems == && $this->forcediscountmessage == 1) {    
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES2'sprintf(GetLang($this->getName().'DiscountMessage1'), $this->amount$catlink$discountexcludes));
            
        
//Message 2 - Clause = 0 [+] discount category item in cart = YES
        
} elseif ($this->clause == && $discountcatitems == 1) {
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES'sprintf(GetLang($this->getName().'DiscountMessage2'), $this->amount$catlink$discountexcludes));        
            
        
        
//Run messages for the product in cart clause
        
        //Message 3 - Clause = 1 [+] trigger item in cart = NO [+] discount category item in cart = NO [+] forced discount message = YES
        
} elseif ($this->clause == && $productincart == && $discountcatitems == && $this->forcediscountmessage == 1) {    
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES2'sprintf(GetLang($this->getName().'DiscountMessage3'), $this->triggerproductqty$triggeritemlink$this->triggerproduct$this->amount$catlink$triggeritemaddlink, ($this->triggerproductqty $setquantity), $this->triggerproduct$discountexcludes));
            
        
//Message 4 - Clause = 1 [+] trigger item in cart = NO [+] discount category item in cart = YES
        
} elseif ($this->clause == && $productincart == && $discountcatitems == 1) {
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES2'sprintf(GetLang($this->getName().'DiscountMessage4'), $this->triggerproductqty$triggeritemlink$this->triggerproduct$this->amount$catlink$triggeritemaddlink, ($this->triggerproductqty $setquantity), $this->triggerproduct$discountexcludes));
        
        
//Message 5 - Clause = 1 [+] trigger item in cart = YES [+] trigger item has sufficient quantity = NO [+] discount category item in cart = NO [+] forced discount message = YES
        
} elseif ($this->clause == && $productincart == && $triggerproductactive == && $discountcatitems == && $this->forcediscountmessage == 1) {
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES2'sprintf(GetLang($this->getName().'DiscountMessage5'), ($this->triggerproductqty $setquantity), $triggeritemlink$this->triggerproduct$this->amount$catlink$triggeritemaddlink, ($this->triggerproductqty $setquantity), $this->triggerproduct$discountexcludes));
            
        
//Message 6 - Clause = 1 [+] trigger item in cart = YES [+] trigger item has sufficient quantity = YES [+] discount category item in cart = NO [+] forced discount message = YES
        
} elseif ($this->clause == && $productincart == && $triggerproductactive == && $discountcatitems == && $this->forcediscountmessage == 1) {
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES2'sprintf(GetLang($this->getName().'DiscountMessage6'), $catlink$this->amount$discountexcludes));    
            
        
//Message 7 - Clause = 1 [+] trigger item in cart = YES [+] trigger item has sufficient quantity = NO [+] discount category item in cart = YES
        
} elseif ($this->clause == && $productincart == && $triggerproductactive == && $discountcatitems == 1) {
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES2'sprintf(GetLang($this->getName().'DiscountMessage7'), ($this->triggerproductqty $setquantity), $triggeritemlink$this->triggerproduct$this->amount$catlink$triggeritemaddlink, ($this->triggerproductqty $setquantity), $this->triggerproduct$discountexcludes$discountexcludes));
        
        
//Message 8 - Clause = 1 [+] trigger item in cart = YES [+] trigger item has sufficient quantity = YES [+] discount category item in cart = YES
        
} elseif ($this->clause == && $productincart == && $triggerproductactive == && $discountcatitems == 1) {
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES'sprintf(GetLang($this->getName().'DiscountMessage8'), $this->amount$catlink$discountexcludes));
        
        
        
//Run messages for the order minimum clause
        
        //Message 9 - Clause = 2 [+] sufficient order amount = NO [+] discount category item in cart = NO [+] forced discount message = YES
        
} elseif ($this->clause == && $cartTotal $this->minimumorder && $discountcatitems == && $this->forcediscountmessage == 1) {    
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES2'sprintf(GetLang($this->getName().'DiscountMessage9'), $minimumordertext$this->amount$catlink$spendtoqualifytext$discountexcludes));
        
        
//Message 10 - Clause = 2 [+] sufficient order amount = NO [+] discount category item in cart = YES
        
} elseif ($this->clause == && $cartTotal $this->minimumorder && $discountcatitems == 1) {    
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES2'sprintf(GetLang($this->getName().'DiscountMessage10'), $minimumordertext$this->amount$catlink$spendtoqualifytext$discountexcludes));
            
        
//Message 11 - Clause = 2 [+] sufficient order amount = YES [+] discount category item in cart = NO [+] forced discount message = YES
        
} elseif ($this->clause == && $cartTotal >= $this->minimumorder && $discountcatitems == && $this->forcediscountmessage == 1) {    
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES2'sprintf(GetLang($this->getName().'DiscountMessage11'), $catlink$this->amount$discountexcludes));
        
        
//Message 12 - Clause = 2 [+] sufficient order amount = YES [+] discount category item in cart = YES
        
} elseif ($this->clause == && $cartTotal >= $this->minimumorder && $discountcatitems == 1) {    
            
$GLOBALS['ISC_CLASS_CART']->api->SetArrayPush('DISCOUNT_MESSAGES'sprintf(GetLang($this->getName().'DiscountMessage12'), $this->amount$catlink$discountexcludes));
        
        } 
This code above calls these language variables:
HTML Code:
PERCENTOFFITEMSINCATDiscountMessage1 = "<strong>Discount Offer Available</strong><br />%s%% off all items in the <em>%s</em>%s"

PERCENTOFFITEMSINCATDiscountMessage2 = " --- <strong>Discount offer now in effect!</strong><br />You have received %s%% off items you purchased in the <em>%s</em>%s"

PERCENTOFFITEMSINCATDiscountMessage3 = "<strong>Discount Offer Available</strong><br />If you purchase %s <a href="%s"><em>%s</em></a> you will receive %s%% off all items in the <em>%s</em><br /><br /><a href='%s'>Click here</a> to add %s <em>%s</em> to your shopping cart now%s"

PERCENTOFFITEMSINCATDiscountMessage4 = "<strong>Discount Offer Available</strong><br />If you purchase %s <a href="%s"><em>%s</em></a> you will receive %s%% off all items in the <em>%s</em><br /><br /><a href='%s'>Click here</a> to add %s <em>%s</em> to your shopping cart now%s"

PERCENTOFFITEMSINCATDiscountMessage5 = "<strong>Discount Offer Available</strong><br />If you purchase another %s <a href="%s"><em>%s</em></a> you will receive %s%% off all items in the <em>%s</em><br /><br /><a href='%s'>Click here</a> to add %s <em>%s</em> to your shopping cart now%s"

PERCENTOFFITEMSINCATDiscountMessage6 = "<strong>Your order has qualified for a discount offer</strong><br />All items purchaed from the <em>%s</em> will now be discounted by %s%%%s"

PERCENTOFFITEMSINCATDiscountMessage7 = "<strong>Discount Offer Available</strong><br />If you purchase another <strong>%s</strong> <a href="%s"><em>%s</em></a> you will receive %s%% off all items in the <em>%s</em><br /><br /><a href='%s'>Click here</a> to add %s <em>%s</em> to your shopping cart now%s"

PERCENTOFFITEMSINCATDiscountMessage8 = " --- <strong>Discount offer now in effect!</strong><br />You have received %s%% off items you purchased in the <em>%s</em>%s"

PERCENTOFFITEMSINCATDiscountMessage9 = "<strong>Discount Offer Available</strong><br />Orders over %s will receive %s%% off all items in the <em>%s</em><br /><br />To qualify for this discount offer you need to spend another %s%s"

PERCENTOFFITEMSINCATDiscountMessage10 = "<strong>Discount Offer Available</strong><br />Orders over %s will receive %s%% off all items in the <em>%s</em><br /><br />To qualify for this discount offer you need to spend another %s%s"

PERCENTOFFITEMSINCATDiscountMessage11 = "<strong>Your order has qualified for a discount offer</strong><br />All items purchaed from the <em>%s</em> will now be discounted by %s%%%s"

PERCENTOFFITEMSINCATDiscountMessage12 = " --- <strong>Discount offer now in effect!</strong><br />You have received %s%% off items you purchased in the <em>%s</em>%s"

Last edited by johnnybegood; 11-21-2009 at 02:06 AM..
Reply With Quote
  #4  
Old 11-21-2009, 02:24 AM
hgmobile + hgmobile is offline
Interspire Customer
 
Join Date: Feb 2009
Posts: 87
Default

Thanks very much. Will be adding this for sure.

I am sure everyone here appreciates the tremendous amount of time and energy you have expended to provide these modules.
Reply With Quote
  #5  
Old 11-22-2009, 05:35 AM
johnnybegood + johnnybegood is offline
Interspire Customer
 
Join Date: Jun 2008
Posts: 219
Default

Phew, this module is out of control!!! This module is now like 10 separate modules in 1. I thought about separating out all the different rules but I think this would make the whole administration really awkward. At least this way you can see everything you need to do on the one screen.

This module allows for:
  1. Get x% off all items in one or more categories (as per original functionality)
  2. Get x% off all items storewide
  3. Get x% off all items in one or more categories when x quantity of product x are purchased
  4. Get x% off all items storewide when x quantity of product x are purchased
  5. Get x% off all items in one or more categories on orders over $x
  6. Get x% off all items storewide on orders over $x
  7. Get x% off all items in one or more categories when total quantity of cart items over x
  8. Get x% off all items in one or more categories when total quantity of cart items from the selected categories is over x
  9. Get x% off all items storewide when quantity of cart items over x
  10. Get x% off all items storewide when quantity of cart items from the selected categories is over x

I have no doubt there are bugs in this; particularly in the phrasing of messages. If you could let me know of any problems I'll fix them right away.

Last edited by johnnybegood; 11-22-2009 at 07:38 AM..
Reply With Quote
  #6  
Old 02-05-2010, 08:00 AM
jason3w + jason3w is offline
Interspire Customer
 
Join Date: Feb 2009
Posts: 185
Default

Would this work with the new version? Thanks
Jason
__________________
Idea
"Product Ratings/Reviews Made Easy"
Vote - Here
Reply With Quote
  #7  
Old 02-15-2010, 09:01 AM
mmamonster + mmamonster is offline
Interspire Customer
 
Join Date: Feb 2010
Posts: 6
Default

Has anyone used this with 5.0.6?

I'm getting a bunch of errors, such as:
Undefined property: RULE_PERCENTOFFITEMSINCAT::$forcediscountmessage in /home/<username>/public_html/modules/rule/percentoffitemsincat/module.percentoffitemsincat.php on line 155

When trying to set a store wide discount.

Chris

Last edited by mmamonster; 02-15-2010 at 09:05 AM..
Reply With Quote
  #8  
Old 02-15-2010, 09:40 AM
tonybarnes + tonybarnes is offline
Interspire Customer
 
Join Date: Dec 2008
Posts: 1,285
Default

Nice work - looks to be a pretty damn complete module! Very generous to share as you have.

Will have a word internally, but I think I might bob this on our site.
__________________
www.savant-health.com
Reply With Quote
  #9  
Old 02-19-2010, 02:25 PM
cupargarden + cupargarden is offline
Interspire Customer
 
Join Date: Nov 2009
Posts: 549
Default

I presume by the previous post saying this doesn't work in 5.0.6, means it won't work in 5.5.2? Can anyone confirm?

Thanks
Reply With Quote
  #10  
Old 02-19-2010, 02:44 PM
johnnybegood + johnnybegood is offline
Interspire Customer
 
Join Date: Jun 2008
Posts: 219
Default

All three discount mods I created were very rough hacks and while I have used all 3 successfully (if not slightly modified) on my website they are certainly not perfect. I only included them on these forums in the hope that Interspire would pick up where I left off and create more discounting modules that work perfectly.

I wouldn't hold my breath though because Interspire still haven't fixed the bloody stupid coupon code system! I am referring to the price discount coupon which deducts the dollar amount from EVERY product in the cart instead of from the order total...a very dangerous oversight that can easily result in your customers ordering products for $0!

Last edited by johnnybegood; 02-19-2010 at 02:48 PM..
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump