############ POINTS AND REWARDS Phoenix Cart #############
/*
  Compatibility:
  Phoenix Cart 1.0.8.4-1.0.8.5
  Use a PHP version supported by your Phoenix Cart release.
  Addon syntax and isolated regression checks: PHP 7.3.9 and PHP 8.5.1.
  Tested with Phoenix 1.0.8.5
  
  Version: 4.1
  updated for Phoenix Cart by @raiwa Rainer Schmied

   originally coded by Ben Zukrel 
   Improved and converted for osC Bootstrap by
   @Tsimi
   and
   @raiwa Rainer Schmied / info@oscaddons.com  / www.oscaddons.com

   Additional credits to @LeeFoster for bug reports and fixes
   German translation by @Tsimi
   German revision by @raiwa
   Spanish translation by @TITO4
   Spanish revision by @PiLLaO 

  Copyright (c) 2021 Rainer Schmied

  Released under commercial License

  Please read and follow the Commercial License rules.

##################################################

What does this addon do?
------------------------------------
This is a Points and Rewards system, aimed to generate additional sales or at least motivate customers to spend more money at your store. 
The Points and Rewards system awards shopping points to customers for the amount they spend or for writing reviews or for referring new customers.
Points are considered as cash when redeemed. Customers can then use those points to pay for their orders during the checkout process.

Change log

-----------

Version 4.1 - 14 September 2026 (backport)

 - Backported the 4.1 fixes while preserving this package's Phoenix APIs and Bootstrap templates.
 - PHP syntax and isolated regression checks passed on PHP 7.3.9 and PHP 8.5.1.
   Use a PHP version supported by the installed Phoenix core.
 - Added server-side validation of redeemed points against the available balance,
   order value, and configured redemption restrictions at confirmation and checkout.
 - Clear the points selection when the redemption checkbox is unticked.
 - Fixed points-only payment eligibility to compare currency amounts without
   rounding away cents, include shipping tax, and reject unpaid order balances.
 - Fixed product and category restrictions to account for all eligible products,
   including quantities, attribute prices, and tax; results no longer depend on
   the order of products in the cart.
 - Award review points after a successful review submission instead of when the
   review form is opened. Added a check for an existing customer/product reward.
 - Enforced form-token validation for admin actions that change points.
 - Prevent repeated admin confirmation from crediting the same record twice.
   Credit the stored points amount and confirm the record in one database statement.
 - Fixed PHP compilation errors in German points help and Spanish pending/referral
   language files. Corrected the points/value order in the maximum-redemption FAQ.
 - Store a zero balance when all points are redeemed and allow the balance lookup
   used for redemption processing to work without the customer's active session.
 - Hide the checkout redemption section when no points can be redeemed, while
   preserving the referral section when applicable.
 - Updated version references to 4.1.

Version 3.3.3.

 - Fixed not working sort order in admin pages
 - Fixed typo in ESQL code for guest support
 - Fixed and simplified code for product and category restrictions

Version 3.2.1.

 - Updated for Phoenix 1.0.8.4+


Version 3.2.0.

 - Updated for Phoenix 1.0.8.0+
 - Moved admin all point notification mails into a new notification module 
 - Moved all point and reward template  files into override template
 - Fixed some minor errors in the admin files
 - Fixed point payment module to not show to unqualified carts if product or category restriction is used.
 - Added session points reset in shopping cart to avoid cart content manipulation to unqualify and keep redemptions applied to order.
 - Replaced alternative shopping cart box and navbar module by override tempalte files. 
 - Replaced modified info box and footer module by override language files.
 - Updated all files to match actual core code.
 - Updated deprecated core functions.

Version 3.1.0.

 - Updated for Phoenix 1.0.7.9+
 - No more core file modifications
 - Deprecated Header Tag Module and moved all configuration entries into Order Total Module
 - Merged all Shop Hooks into one SiteWide hook
 - Replaced checkout payment content module with form hook
 - Bootstrapped Admin pages
 - removed alternative info footer and box module and provided modified language files instead
 - moved the reviews point info message module to product info page
 - updated all modules to abstract_executable_module
 - updated coding to match Phoenix 1.0.7.8 standards
 - added product info pi system modules
 - Integrated PayPal Standard IPN support into siteWide hook

Version 3.0.2.

 - Removed unused configuration entry and language definitions for auto expire remind. Thanks to @cdetdi for pointing this out
 - Added support for paypal standard ipn. Thanks to @cdetdi for sponsoring

Version 3.0.1.

 - Fix for shipping tax to be included in points calculation. Thanks to @MITCH70 for the report
 - Added note for content module call if already present in checkout_payment.php

Version 3.0.0.

 - Updated for Phoenix 1.0.3.0.
 - Added siteWide hook for checkout_payment.php
 - Code cleanup (indents, version references)

Version 2.0.2.

 - Fix for wrong order total calculation for secondary currencies. Thanks to @winfm for the report and testing.

Version 2.0.1.

 - Fix for missing language definitions in shopping cart module
 - Fix for font awesome 5 icon update in shopping cart module

 Version 2.0

 - Updated for 2.3.4.1. CE Frozen
 - Replaced checkout payment hook by content module
 - Moved checkout payment output from functions/redemptions.php into new content module
 - Updated installation scripts for 2.3.4.1 CE Frozen and checkout payment content module
 - Updated template naming and auto inclusion in all content modules
 - Added support for core modular product info
 - Added support for Modular Checkout
 - Replaced modified core template files by complete alternative box and footer content modules

Version 1.2

 - added points redeem shopping cart module which allows using points with PayPal express checkout button
 - fixed ot module wrong order total calculation if total amount is paid by points
 - selected redeem and referral option will be stored now in session. If ticked or filled in in shopping cart it will be also ticked and filled in on checkout payment and applied on checkout confirmation. (this is required for PyaPal express to work) 
 
Version 1.1

 - Added PWA Guest Checkout support
 - Added Order Editor support to points payment module
 - Added SWC (Sloppy Words Cleaner) support by renaming function names and converted functions to private (HT module) 
 - Added auto tick checkbox by order status feature (multiple choices possible, use comma to spearate ID numbers)
 - Bug fix for wrong order total calculation when product value is over $1000
 

Admin features
------------------------------------

* Enable/Disable the Points System. 
* Enable/Disable the Redemptions System.(maybe you would like to offer a gift and not money back). 
* Set the number of points awarded for evry $1.00 spent(or whatever based on your currency system). 
* Set the value of each point(based on your currency system). 
* Set Points Decimal Places
* Enable Auto Credit Pending Points and set a days period before the reward points will actually added to customers account. 
* Enable Auto Expires points and set a month period before points will auto Expires. 
* Enable Points Expires Auto Reminder and set the numbers of days prior points expiration for the script to run. 
* Set order status ID for auto tick Validate checkbox feature in orders.php page. For multiple status IDs separate with comma.
* Enable/Disable points awarded for shipping fees. 
* Enable/Disable points awarded for taxes. 
* Enable/Disable points awarded for discounded products. 
* Enable/Disable points awarded for order with redeemed points. 
* Enable/Disable points awarded for Reviews. 
* Enable/Disable points awarded for Referral. 
* Enable/Disable Products Restriction. 
* Set the Products Id allowed when Products Restriction enabled.(unlimited products) 
* Set the Categories ID allowed When Products Restriction enabled.(unlimited categories path) 
* Enable/Disable Products Price Restriction. 
* Enable/Disable points Limitation. and set the number. of points needed before they can be redeemed. 
* Set the maximum points allowed to be redeemed per order. 
* Limit Points Redemptions to exact amount. 
* Restrict Points Redemption For Minimum Purchase Amount. 
* Enable/Disable Points credit information. shown in products info page. 
* Enable/Disable Welcome points and set the points amount to be auto-credited for new signed up customers. 
* Set the numbers of records to show per page at my_points.php page. 
* Enable/Disable Keeping records of redeemed points.

Customers features
------------------------------------
* New signup customers can be awarded with welcome points.
* Customers can earn points(cash back) for an item purchased at the store.
* Customers can earn points for writing reviews.
* Customers can earn referral points.
* Customers can view their current shopping points balance.


******************* MAKE SURE TO BACKUP YOUR FILES BEFORE ***********************
This package is for Phoenix Cart 1.0.8.4-1.0.8.5.
Choose the package matching your installed Phoenix version.

Please use it at your own risk.
------------------------------------------------------------------------------------------

####### STEP BY STEP INSTALLATION ################

A. ADDING NEW FILES.
B. INSTALL REQUIRED MODULES
C. INSTALL OPTIONAL MODULES

A. ADDING NEW FILES.
For an existing installation, follow "update from previous versions.txt" instead.
For a fresh installation, copy the contents of new_files/catalog/ to the shop root.
Map its admin/ folder to your renamed admin directory, if applicable.
Copy all supplied files, including notification modules and each language you use.
Merge custom changes in template and language overrides before replacing them.
The lists below are a guide; the complete new_files/catalog/ tree is authoritative.

-- Add this to catalog section --------------

    catalog/includes/functions/redemptions.php
    catalog/includes/hooks/admin/orders/points.php
    catalog/templates/override/includes/hooks/shop/siteWide/pointsRewards.php
    catalog/includes/languages/english/my_points.php
    catalog/includes/languages/english/my_points_help.php
    catalog/includes/languages/english/hooks/admin/orders/points.php
    catalog/includes/languages/english/hooks/shop/siteWide/pointsRewards.php
    catalog/includes/languages/english/modules/content/account/cm_account_points.php
    catalog/includes/languages/english/modules/content/product_info/cm_pi_points.php
    catalog/includes/languages/english/modules/content/product_info/cm_pi_reviews_points.php
    catalog/includes/languages/english/modules/pi/product_info/pi_points.php
    catalog/includes/languages/english/modules/pi/product_info/pi_reviews_points.php
    catalog/includes/languages/english/modules/content/shopping_cart/cm_sc_points_redeem.php
    catalog/includes/languages/english/modules/order_total/ot_redemptions.php
    catalog/includes/languages/english/modules/payment/points.php	
    catalog/includes/modules/content/account/cm_account_points.php
    catalog/includes/modules/content/product_info/cm_pi_points.php
    catalog/includes/modules/content/product_info/templates/tpl_cm_pi_points.php
    catalog/includes/modules/content/product_info/cm_pi_reviews_points.php
    catalog/includes/modules/content/product_info/templates/tpl_cm_pi_reviews_points.php
    catalog/includes/modules/content/shopping_cart/cm_sc_points_redeem.php
    catalog/includes/modules/content/shopping_cart/templates/tpl_cm_sc_points_redeem.php
    catalog/includes/modules/order_total/ot_redemptions.php
    catalog/includes/modules/payment/points.php
    catalog/includes/modules/pi/product_info/templates/tpl_pi_points.php
    catalog/includes/modules/pi/product_info/templates/tpl_pi_reviews_points.php
    catalog/includes/modules/pi/product_info/pi_points.php
    catalog/includes/modules/pi/product_info/pi_reviews_points.php
    catalog/templates/override/includes/hooks/shop/siteWide/pointsRewards.php
    catalog/templates/override/includes/languages/english/modules/boxes/bm_information.php
    catalog/templates/override/includes/languages/english/modules/content/footer/cm_footer_information_links.php
    catalog/templates/override/includes/modules/boxes/tpl_bm_shopping_cart.php
    catalog/templates/override/includes/modules/navbar/tpl_nb_shopping_cart.php
    catalog/templates/override/includes/pages/my_points.php
    catalog/templates/override/includes/pages/my_points_help.php
   	catalog/my_points.php
    catalog/my_points_help.php

      
      
====DONE====

-- Add this to admin section --------------

    admin/customers_points.php
    admin/customers_points_pending.php
    admin/customers_points_referral.php
    admin/includes/boxes/points_rewards.php
    admin/includes/languages/english/modules/boxes/points_rewards.php
    admin/includes/languages/english/customers_points.php
    admin/includes/languages/english/customers_points_pending.php
    admin/includes/languages/english/customers_points_referral.php
	
====DONE====


******************************************************************************************
B. INSTALL REQUIRED MODULES

0.)
Make sure you are using the "override" template and have it selected in:
Admin : Configuration : My Store : Template Selection

Otherwise you must copy all content from:
  templates/override/includes/
TO:
  templates/YOUR SELECTED TEMPLATE/includes/


1.)
Access your admin area and install the "Points Redemptions" order total module. (Modules -> Order Total)
This option must appear after "Sub-Total", "Shipping", and "Tax", and before "Total". 
When you first install "Points Redemptions" the sort order no is set at a default of 35.
If you have an older Phoenix version, YOU MUST change your value for "Total" sort order to any number higher then 35 (e.g. 40).

Installing the module will add all necessary database tables and entries to your database.

2.)
Access your admin area and install the "Points" payment method module. (Modules -> Payment)

3.)
Access your admin area and install the "My Points and Redemptions" module. (Modules -> Content[account])
This will show the My Points and Redemptions block on the My Account page.

4.)
Access your admin area and install the "Update Points Account" module. (Modules -> Notifications)
This will allow to send a e-mail notification when the Points Account is updated.


C. INSTALL OPTIONAL MODULES

1.)
Access your admin area and install the "Product Points" products_info content module. (Modules -> Content[product_info])
This will add the points credit information on the product info page.

OR if you are using the pi system product info modules:

Access your admin area and install the "Review Points" products_info pi module. (Layout Modules -> Product Info)
This will add the points credit information on the product info page.

2.)
Access your admin area and install the "Product Points" products_info content module. (Modules -> Content[product_info])
This will add the points credit information on the product info page.

OR if you are using the pi system product info modules:

Access your admin area and install the "Review Points" products_info pi module. (Layout Modules -> Product Info])
This will add the points credit information on the product info page.

3.)
Access your admin area and install the "Shopping Cart with Points" box module. (Modules -> Boxes)
This will display points info inside the shopping cart box.(customers must login).
This will only show up when a customer points is bigger then 0

!PLEASE NOTE! This optional module requires previous installation of:

Ship In Cart Phoenix Cart

Make sure you install that first and then the "Points Redeem" module.



***************************************************************
THAT'S IT!
***************************************************************