Coupon Checker¶
This extension is intended to alleviate load on the Miva store when traffic is heavy and many customer sessions are submitting coupons, particularly through the usage of deal finder extensions such as Honey, RetailMeNot, and Microsoft Edge's native deal-finder feature.
These services iterate through a known list of coupons associated with a given store in an attempt to find the best possible discount. As of the time this documentation was written (1/5/2022), Miva software runs miva_sleep() whenever an invalid coupon code is submitted through the ACPN action, which can cause negative impacts on the store's performance, and can potentially take the store down as we found happened on Plant Therapy.
This feature adds rate limiting to coupon submissions, reducing the server impact of subsequent submissions after the rate limit is hit by preventing the ACPN action from processing. In addition, prior to the rate limit being hit, submitted Coupon_Code
values are validated more efficiently by preventing the ACPN action on empty coupon code value submissions, and utilizing the Coupon_Load_Code()
mvt:do function to check if the coupon code even exists in the store, prior to running the ACPN action.
Installation¶
- Install the MVPS Global Logic Module.
- Updated Pre-Action Logic template with the template code listed below.
- Modify default configuration variables for rate limiting max attempts and cookie expiration time, if desired.
- Verify the desired error messages verbiage with the merchant, particularly the max attempts rate limit message.
Template¶
View template code in BitBucket.
<mvt:comment>
|
| Action Logic
|
</mvt:comment>
<mvt:if expr="l.settings:action EQ 'ACPN'">
<mvt:comment>
|
| Adding Coupon
| Criteria to Pass through to Miva's Action:
| - Attempts must be below threshold
| - Coupon Code must actually exist
|
</mvt:comment>
<mvt:comment>
|
| Configurable Settings
|
</mvt:comment>
<mvt:assign name="l.coupon_checker:max_attempts" value="30" />
<mvt:assign name="l.coupon_checker:expiration_minutes" value="5" />
<mvt:do file="g.Module_Library_Utilities" name="l.coupon_checker:store_code" value="AlphaNumericOnly( g.Store_Code )" />
<mvt:assign name="l.coupon_checker:coupon_code" value="trim( g.Coupon_Code )" />
<mvt:assign name="l.coupon_checker:cookie_name" value="'mm5-' $ l.coupon_checker:store_code $ '-mvca'" />
<mvt:assign name="l.coupon_checker:attempt" value="int( miva_variable_value( 'g.Request_Cookies:' $ l.coupon_checker:cookie_name ) )" />
<mvt:assign name="l.coupon_checker:expiration" value="s.dyn_time_t + 60 * l.coupon_checker:expiration_minutes" />
<mvt:assign name="l.coupon_checker:attempt" value="l.coupon_checker:attempt + 1" />
<mvt:do file="g.Module_Library_Utilities" name="l.success" value="SetCookie( g.Output_Cookies, l.coupon_checker:cookie_name, l.coupon_checker:attempt, g.cookiedomain, l.coupon_checker:expiration, g.cookiepath, 0 )" />
<mvt:do file="g.Module_Library_Utilities" name="l.success" value="OutputCookies( g.Output_Cookies )" />
<mvt:if expr="l.coupon_checker:attempt GE l.coupon_checker:max_attempts">
<mvt:do file="g.Module_Library_Utilities" name="l.success" value="Message_Error( 'You\'ve exceeded the maximum coupon submission attempts. Please contact customer service for assistance.' )" />
<mvt:assign name="l.settings:return_value" value="-1" />
<mvt:exit />
</mvt:if>
<mvt:if expr="ISNULL l.coupon_checker:coupon_code">
<mvt:do file="g.Module_Library_Utilities" name="l.success" value="Message_Error( 'Please enter a valid coupon code.' )" />
<mvt:assign name="l.settings:return_value" value="-1" />
<mvt:exit />
</mvt:if>
<mvt:do file="g.Module_Feature_PGR_DB" name="l.success" value="Coupon_Load_Code( l.coupon_checker:coupon_code, l.coupon_checker:coupon )" />
<mvt:if expr="NOT l.success">
<mvt:do file="g.Module_Library_Utilities" name="l.success" value="Message_Error( 'You have entered an invalid coupon code.' )" />
<mvt:assign name="l.settings:return_value" value="-1" />
<mvt:exit />
</mvt:if>
</mvt:if>