--------------------------------------------------
Discount Codes 6.4 Addon for Phoenix Cart v1.1.0.0+.+
by @raiwa
  raiwa@phoenixcartaddons.com
  www.phoenixcartaddons.com

Compatibility:
Phoenix 1.1.0.0+
Tested with Phoenix 1.1.0.7
Tested Stripe SCA 3.0
PHP 7.0-8.5

Based on Discount Codes BS 3.x and 4.x by @Tsimi and @raiwa
Based on the Discount Code for osCommerce 2.3.1 addon by high-quality-php-coding.com 

Versions and updates:
----------------------
Version 6.4       Updated for PHP 8.5 and tested with Phoenixcart 1.1.0.7
Version 6.3       Improved javascript stability with mobile key events
Version 6.2       Fixed tax calculation to use tax decimal places
                  Tested with Phoenix 1.1.0.6
Version 6.1       Fixed typo in login text constant
                  Updated module width configuration in shopping cart module
                  Tested with Phoenix 1.1.0.2
Version 6.0       Updated fro Phoenix 1.14.0.1+ and Bottstrap 5
                  Updated jquery to native javascript
                  Updated validation icons to native bootstrap 5 validation classes
Version 5.8.2.    Updated expiry date input to html5 date input like core 1.0.8.21+.
Version 5.8.1.    Removed "Remove Button" definition from cm_sc_discount_code.php language files.
Version 5.8.0.    Remade all discount option checks and optimized them
                  Added support for guests/not registered customers and number of use check
                  Added back customers_to_discount_codes table for accurate number of use check if code is linked to customers
                  Fixed remove discount code action in shopping cart to remove immediately the discount code from ship in cart order totals module
                  Fixed error in admin: Discount Codes if no customer exists
                  Tested with Phoenix 1.0.8.16 and PHP 8.0

Version 5.7.4.    Fixed customer id check error introduced in Version 5.7.2. Thanks to @radhavallabh for the report
Version 5.7.3.    Removed obsolete discount to customers table queries. Thanks to @Luckypiedro for the report
Version 5.7.2.    Fixed broken discount to customers. Thanks to @Luckypiedro for the report
                  Fixed customer display in admin/discount codes/infobox
Version 5.7.1.    Fixed bug in ot_discount.php: update removed format_raw method to core $GLOBALS['currencies']->format_raw. Thanks to @ecartz for the advise
                  Updated some missing code to match actual core code. Thanks to @ecartz
Version 5.7.0.    Updated for Phoenix 1.0.8.6+
                  Updated all codign to match actual core code
                  Modularized admin page
                  Added "Apply" and "Remove" buttons to shopping cart module also if ship in cart is not installed. 
                    - This ensures compatibility with PayPal Express Checkout button. Tanks to @MyGamesShop for the report and suggestion
                  Fixed calculation errors for:
                    - Shipping and subtotal discount, ot_shipping below tax, Display Prices with tax = false
                    - other currency than default
                  Replaced custom format_raw function by core method
Version 5.6.2.    Fixed sql errors if used together with PWA Guest Checkout. Thanks to @gabbysplaza for the report
Version 5.6.1.    Added missing $db global in order total install/uninstall functions. Thanks to @gsmiley for the report
Version 5.6.0.    Updated for Phoenix Cart 1.0.8.2+
                  Modernized code to match actual core standards.
                  Updated references to Phoenix Cart Forum
Version 5.5.1.    Changed hook to redirect to fix possible error in checkout_payment.php. Thanks to @plamastus for the report
                  Made the discount code input fields readonly once the discount code has been applied.
Version 5.5.0.    Add remove buttons to shopping cart module and checkout payment hook. Thanks to @gsmiley007 for the suggestion
                  Made the discount code input fields readonly once the discount code has been applied.
Version 5.4.2.    Fixed notice error and not applying discount on the shopping cart page for guests/not logged in customers. Thanks to @gsmiley007 to point it out
                  Fixed notice error in shopping cart if no shipping is available.
                  More code modernization to match core standards.
Version 5.4.1.    Tested with Phoenix Cart 1.0.8.0
                  Fixed wrong database Field type from "int" to "text" for categories, products. manufacturers, excluded products and customers. Thanks to @vmn to point it out
                  Modified installation script to fix these wrong types on installation/update.
                  Fixed javascript in admin/discount_codes.php to keep excluded product list enabled if categories or manufacturers are selected.
Version 5.4.0.    Updated for Phoenix 1.0.7.14.+
                  Modernized all code to match actual core coding
                  Moved shop hook into override template
                  removed obsolete PayPal standard ip and stripe support
                  changed code to allow to remove already applied discount code using invalid discount code 
Version 5.3.2.    Updated instructions.
                  Moved shop hook to templates
                  updated hook check in ot module
Version 5.3.1.    Added missing checkout module.
Version 5.3.0.    Updated order total module to abstract_module.
                  Updated shopping cart content module to abstract_executable_module.
                  Fixed some minor order total calcultion errors. Thanks to @yahalimu for the report ans sponsoring
                  Changed checkout payment content module to hook and new page layout.
                  Changed checkout process hook to checkout module.
                  Switched off error reporting in discount.php to stabilize ajax processing if error reporting is on.
                  Added accidentally removed "Include in order info" setting in admin/discount_codes.php.
Version 5.2.1.    Fixed undefined errors in admin/discount_codes.php. Thanks to @hungryfrank
                  Fixed PayPal standard support errors. Thanks to @ecartz
                  Fixed Stripe support error.
Version 5.2.0.    Added Discount code description for internal use in Admin.
                  Bootstrapped Admin page.
                  Added alert on Admin Discount Codes Page if order total module is not installed or not enabled.
                  Modified Order Total Module to be main switch. Content modules will not show if Order Total Module is disbled/not installed.
                  Modified Database tables entries from text to varchar(128).
                  Added modified Stripe CA3 module
                  Updated PayPal standard Modules to Phoenix 1.0.5.5 version.
Version 5.1.2.    Fix for wrong order total showing when no tax is applied. Thanks to @bnguru for the report and testing
                  Added support for stripe sca 3.0 payment module. Thanks to @peterespana for testing
                  Fixed several minor errors in instructions, ot module and admin page. Thanks to @Demitry
Version 5.1.1.    Fix for negative order total showing if fixed amount discount is bigger than order subtotal. Thanks to @Omar_one for the report and testing
Version 5.1.0     Phoenix: Removed support for earlier EDGE versions
                  Fix for discount not showing on first page load in ship in cart order total module in shopping cart, disable "Apply" button until code is validated.
                  Added sitewide hook for session unregister of discount code on logoff
Version 5.0.0 BS: Added support for EDGE BS4
                  Removed ht-Module
                  Moved validation script from ht to content modules
                  Moved code from application_top.php into discount_code.php
                  Added checkout payment content module to replace code injection in HT module
                  Added install warning for required OT module to content modules
                  Added condition to show "Apply" button in shopping cart module only if "Ship in Cart" Order Totals Module is present.
                  Updated template names to actual naming standard
                  Updated template calls in content modules to actual auto inclusion
                  Moved html output to content module template files 
                  Normalized True/False typo in OT module
                  Hooked modifications in checkout_process.php and paypal standard files.

Version 4.4.2 BS: Fixed support for paypal standard discount order count. Thanks to @sinopia for the report and testing.
                  Added support for paypal standard ipn discount order count
                  Fixed error for order total discount if "Base discount tax on prices excl." was set to "true" and "Display prices with tax" was set to "true".
Version 4.4.1 BS: (unreleased version) 
                  Fix for discount formatting if other than default currency is used. Thanks to @mattsc for the report and testing.
Version 4.4.0 BS: Added the possibility to exclude specials on order subtotal discounts.
                  Added support to place ot discount module before ot subtotal module and show subtotal with discount amount substracted.
Version 4.3.2 BS: Fixed several undefined warnings in ot module.
Version 4.3.1 BS: Fixed manufacturers query syntax in admin/discount_code.php. 
                  Fixed undefined $shipping_tax warning in ot module.
Version 4.3 BS: Recoded discount calculation for show price with tax and mixed tax rates in cart. 
                Only affects displayed ot tax. Optional setting to base discount tax calculation on prices excl or incl tax.
                Added option to show shipping fee discounted if discount is displayed before shipping.
Version 4.2 BS: Recoded shipping discount calculation for all possible tax settings.
                Added support for alternative sort order, dot discount below ot shipping.
                Removed $_GET from globals list in ht discount module.
                thanks to @nbkvh1i for the reports and testing and @tsimi for testing
Version 4.1 BS: Replaced DIR_ instances.
                Added option Applies only to customer subscribed to newsletters
                Added option Applies only to Order Nº
                Added PWA Guest Order support to count also guest orders for Order Nº discounts
                Added option to show discount code input field in shopping cart module to guests
                Added spanish and german language files to store
Version 4.0 BS: Bug fix, tax part wasn't discounted for the attribute price / Many thanks to f.figue for the fix.  
Version 3.9 BS: Replaced FILENAME_ instances 
				        Replaced TABLE_ instances
				        Replaced $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS instances with $_GET, $_POST, $_SERVER. 
				        Added Italian language pack. Many thanks to Umberto (aka. Umb) for the translation!
Version 3.8 BS: Minor code improvements and added percentatge amount to the discount title so that customers can see how many % they get in the order confirmation page. (August 2016) / Thx raiwa!
Version 3.7 BS: Code improvements, reducing core code changes. Added shipping discount feature. (July 2016) / 
                Special thanks to katapofatico, raiwa and greasemonkey for their help and input.
Version 3.6 BS Reloaded: added module files to fit in Modular Shopping Cart BS
Version 3.6 BS: another calculation fix (April 2016) / ...and once more THANK YOU raiwa!
Version 3.5 BS: bracket fix by raiwa (April 2016) / and once more THANK YOU raiwa!
Version 3.4 BS: calculation fix by raiwa (April 2016) / again THANK YOU raiwa!
Version 3.3 BS: Tax calculation and larger discount than subtotal bug fixes by raiwa (April 2016) / THANK YOU raiwa!
Version 3.2 BS: Updated for osC 2.3.4 BS by Tsimi (April 2016)

Always BACKUP your data before installing Addons! (... and don't forget the database!)

/********************************/
/* INSTALL                      */
/********************************/  
*Database changes will be done automatically.

1. Copy the new files to your osCommerce shop, preserving the directory structure.
Folder "upload"
admin/discount_codes.php
admin/includes/actions/discount_codes/[all included files and folders]
admin/includes/languages/english/discount_codes.php
admin/includes/boxes/catalog_dc_content.php
admin/includes/languages/english/modules/boxes/catalog_dc_content.php
discount_code.php
includes/languages/english/hooks/shop/siteWide/discountCode.php
includes/languages/english/modules/order_total/ot_discount.php
includes/modules/order_total/ot_discount.php
templates/override[YOUR SELECTED TEMPLATE]/includes/hooks/shop/siteWide/discountCode.php


*OPTIONAL for the shopping cart Discount Codes Module 
(requires Ship in Cart Addon):
includes/languages/english/modules/content/shopping_cart/cm_sc_discount_code.php
includes/modules/content/shopping_cart/templates/tpl_cm_sc_discount_code.php
includes/modules/content/shopping_cart/cm_sc_discount_code.php


/********************************/
NOTE: Make sure you are using the "override" template and have it selected in:
Admin : Configuration : My Store : Template Selection
Otherwise you must copy:
  templates/override/includes/hooks/shop/siteWide/discountCode.php
TO:
  templates/YOUR SELECTED TEMPLATE/includes/hooks/shop/siteWide/discountCode.php
/********************************/

      
      
/********************************/
/* SETUP/CONFIGURATION          */
/********************************/  

4.1. Install the Order Total module under Administration -> Modules -> Order Total -> Install Module -> Discount Code -> Install Module.
     Set the sort order of the order total modules like in the examples below under point 5
   
*OPTIONAL if using Ship in cart add-on (required)
4.2.   Install the Content module under Administration -> Modules -> Content -> Install Module -> Discount Code[shopping_cart] -> Install Module.

5. Set the sort order for order total modules under Administration -> Modules -> Order Total.

Possibility A
Modules       Sort Order
Discount Code 15
Shipping      20
Sub-Total     10
Tax           30
Total         40

Possibility B
Modules       Sort Order
Discount Code 25
Shipping      20
Sub-Total     10
Tax           30
Total         40

Possibility C
Modules       Sort Order
Discount Code 5
Shipping      20
Sub-Total     10
Tax           30
Total         40

Possibility D
Modules       Sort Order
Discount Code 5
Shipping      10
Sub-Total     20
Tax           30
Total         40


NOTE: If Discount Code is placed before Subtotal, shipping discount will also be substracted from Subtotal.

Create a discount code under Administration -> Catalog -> Discount Codes.

Done!

NOTE: If you are using this PWA Guest Checkout add-on:
https://phoenixcart.org/forum/app.php/addons/free_addon/purchase_without_account/
Guest orders will be taken in consideration for Order Nº Discounts validation.

If you have an older version and want to upgrade please read the upgrade manual provided with this addon.
Support topic: https://phoenixcart.org/forum/app.php/addons/free_addon/discount_codes/support