############ POINTS AND REWARDS Phoenix Cart #############
/*
  Compatibility:
  Phoenix Cart 1.1.0.0+
  Use a PHP version supported by your Phoenix Cart release.
  Tested with Phoenix Cart 1.1.0.7 and PHP 8.5.1
  
  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 / raiwa@phoenixcartaddons.com  / www.phoenixcartaddons.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 - 11 September 2026

 - Tested with Phoenix Cart 1.1.0.7 and PHP 8.5.1.
 - 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.
 - Restored 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 4.0

 - Updated for compatibility with Phoenix 1.1.0.0+ and Bootstrap 5
 - Tested with Phoenix 1.1.0.0 and PHP 8.3
 - fixed error when deleting customer points in admin
 - modified code on my  points page to show the points history even customer has no actual points
 
 -----------
Version 3.3.5.

 - Updated template width class for compatibility with Phoenix 1.0.9.4+
 - Tested with Phoenix 1.0.9.4 and PHP 8.3

-----------
Version 3.3.4.

 - Fixed TypeError in admin/includes/actions/customers_points/infoboxes/default.php under PHP 8.2
 - Tested with Phoenix 1.0.8.21 and PHP 8.2

-----------
Version 3.3.3.

 - Fixed typo in ESQL code for guest support
 - Fixed and simplified code for product and category restrictions

Version 3.3.2.

 - Error fixes on admin side

Version 3.3.1.

 - Notice and Warning Error fixes

Version 3.3.0.

 - Updated for Phoenix 1.0.8.6+
 - Modularized admin pages

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 automatic credit of shopping points during checkout processing, or confirm pending points manually in admin.
* Enable Auto Expires points and set a month period before points will auto Expires. 
* 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. 
* 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.


Installation
------------------------------------
This package is for Phoenix Cart 1.1.0.0+. Version 4.1 was tested with
Phoenix Cart 1.1.0.7 and PHP 8.5.1.

Back up your store files and database before installation or upgrading.
For an existing installation, see "update from previous versions.txt".

A. UPLOAD THE FILES

Upload the contents of the supplied "new_files" folder to your store root,
keeping the directory structure. Merge the folders and preserve any customizations.
If your admin folder has a different name, upload new_files/admin/ to that folder.

Include all supplied PHP files, templates, admin actions, notification files,
and the English, German, and Spanish language files. Do not upload "new_files"
as a subfolder of your store.

The addon includes template and language overrides; no core PHP edits are needed.
If you use a template other than "override", merge the supplied files from
new_files/templates/override/includes/ into templates/YOUR_TEMPLATE/includes/.
Check the selected template under Admin > Configuration > My Store > Template Selection.

B. INSTALL AND CONFIGURE THE MODULES

1. Under Admin > Modules > Order Total, install the Points Redemptions module
   (ot_redemptions). Configure the points value, earning rules, redemption limits,
   expiry, and automatic or manual crediting.

   Place it after Sub-Total, Shipping, and Tax, and before Total.
   The default sort order is 35; Total must have a higher sort order, for example 40.
   Installing this module creates the required database table and columns.

2. Under Admin > Modules > Payment, install and enable "Points".
   This payment method is available only when eligible points cover the full order.
   Partial redemption uses another payment method for the remaining amount.

3. Under Admin > Modules > Content, in the account group, install
   "My Points and Redemptions" to add the points link to My Account.

4. Under Admin > Modules > Notifications, install "Update Points Account"
   to enable customer notification emails from the admin points pages.

C. OPTIONAL DISPLAY MODULES

1. Product points information:
   - Standard content layout: Modules > Content > product_info > "Product Points".
   - PI layout: Layout Modules > Product Info > "Product Points".
   Use the module appropriate to your product-page layout.

2. Review reward information:
   - Standard content layout: Modules > Content > product_info > "Review Points".
   - PI layout: Layout Modules > Product Info > "Review Points".
   This displays the review reward information; configure the reward amount in
   the Points Redemptions order-total module.

3. Shopping-cart redemption:
   Under Modules > Content > shopping_cart, install "Points Redemptions"
   (cm_sc_points_redeem). This requires Ship In Cart to provide the order estimate
   used for calculating the redeemable points. Install Ship In Cart first.

4. Shopping-cart balance display:
   The supplied template overrides add points information to the existing Shopping
   Cart box and navbar modules. There is no separate "Shopping Cart with Points"
   box module to install. Enable the standard cart modules if you use these displays.

D. CHECK THE INSTALLATION

- Check the My Account points link and points-help page in your installed languages.
- Check that a zero balance does not display a redemption offer at checkout.
- Test partial redemption and a points-only order with a suitable test account.
- Check product/category restrictions and the configured redemption limits.
- Submit a test review and verify that opening its form alone does not award points.
- Confirm pending points in admin and check notification emails if enabled.

