This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magento_Customer::customer" title="Customers" translate="title">
<resource id="Esun_Reward::view" title="View Reward Points" translate="title" sortOrder="80"/>
<resource id="Esun_Reward::adjust" title="Adjust Reward Points" translate="title" sortOrder="90"/>
</resource>
<resource id="Magento_Backend::stores">
<resource id="Magento_Backend::stores_settings">
<resource id="Magento_Config::config">
<resource id="Esun_Reward::configuration" title="Reward Points Configuration" translate="title" sortOrder="90"/>
</resource>
</resource>
</resource>
</resource>
</resources>
</acl>
</config>
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin"><route id="esun_reward" frontName="esun_reward"><module name="Esun_Reward" before="Magento_Backend"/></route></router>
</config>
@@ -0,0 +1,49 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="esun_reward" translate="label" type="text" sortOrder="350"
showInDefault="1" showInWebsite="1" showInStore="1">
<label>Reward Points</label>
<tab>esun</tab>
<resource>Esun_Reward::configuration</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="earning" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Earning Rules</label>
<field id="items" translate="label comment" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Earning Rule Items</label>
<frontend_model>Esun\Reward\Block\Adminhtml\System\Config\Form\Field\EarningRuleItems</frontend_model>
<backend_model>Esun\Reward\Model\Config\Backend\EarningRuleItems</backend_model>
<comment>Select a supported trigger event and configure its reward value, customer-facing activity name and history reason. Adding a row does not create a new event type. For Paid Order, Reward Points means points per currency unit and %1 in Reason is replaced by the order number.</comment>
</field>
</group>
<group id="spending" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Spending Rules</label>
<field id="points_per_dollar" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"><label>Points Required per Currency Unit</label><validate>validate-number validate-greater-than-zero</validate></field>
<field id="max_checkout_points" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"><label>Maximum Checkout Points</label><validate>validate-number validate-zero-or-greater</validate></field>
</group>
<group id="tiers" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>VIP Tiers</label>
<field id="items" translate="label comment" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Tier Items</label>
<frontend_model>Esun\Reward\Block\Adminhtml\System\Config\Form\Field\TierItems</frontend_model>
<backend_model>Esun\Reward\Model\Config\Backend\TierItems</backend_model>
<comment>Set the lifetime spend threshold and points multiplier for each tier. Tiers are evaluated from the highest threshold down.</comment>
</field>
</group>
<group id="review" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Review Eligibility</label>
<field id="eligibility" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Customers Can Review After</label>
<source_model>Esun\Reward\Model\Config\Source\ReviewEligibility</source_model>
</field>
</group>
</section>
</system>
</config>
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default><esun_reward>
<general><enabled>1</enabled></general>
<earning>
<registration_points>100</registration_points><first_address_points>100</first_address_points>
<points_per_dollar>1</points_per_dollar><review_text_points>20</review_text_points>
<review_media_points>40</review_media_points><social_share_points>300</social_share_points>
</earning>
<spending><points_per_dollar>100</points_per_dollar><max_checkout_points>1500</max_checkout_points></spending>
<tiers>
<silver_threshold>3000</silver_threshold><silver_multiplier>1.2</silver_multiplier>
<gold_threshold>7000</gold_threshold><gold_multiplier>1.5</gold_multiplier>
</tiers>
<review><eligibility>payment_success</eligibility></review>
</esun_reward></default>
</config>
+89
View File
@@ -0,0 +1,89 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="esun_reward_account" resource="default" engine="innodb" comment="eSUN Reward Accounts">
<column xsi:type="int" name="account_id" unsigned="true" nullable="false" identity="true" comment="Account ID"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
<column xsi:type="smallint" name="website_id" unsigned="true" nullable="false" comment="Website ID"/>
<column xsi:type="int" name="balance" nullable="false" default="0" comment="Available Points"/>
<column xsi:type="int" name="pending_balance" nullable="false" default="0" comment="Pending Points"/>
<column xsi:type="int" name="lifetime_earned" unsigned="true" nullable="false" default="0" comment="Lifetime Earned Points"/>
<column xsi:type="decimal" name="lifetime_spend_base" scale="4" precision="20" nullable="false" default="0" comment="Lifetime Base Spend"/>
<column xsi:type="varchar" name="tier_code" nullable="false" length="32" default="bronze" comment="Tier Code"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
<column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="true" comment="Updated At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="account_id"/></constraint>
<constraint xsi:type="unique" referenceId="ESUN_REWARD_ACCOUNT_CUSTOMER_WEBSITE_UNQ">
<column name="customer_id"/><column name="website_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="ESUN_REWARD_ACCOUNT_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID"
table="esun_reward_account" column="customer_id" referenceTable="customer_entity"
referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
<table name="esun_reward_transaction" resource="default" engine="innodb" comment="eSUN Reward Transactions">
<column xsi:type="bigint" name="transaction_id" unsigned="true" nullable="false" identity="true" comment="Transaction ID"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
<column xsi:type="smallint" name="website_id" unsigned="true" nullable="false" comment="Website ID"/>
<column xsi:type="int" name="points_delta" nullable="false" comment="Points Delta"/>
<column xsi:type="int" name="balance_after" nullable="false" comment="Balance After"/>
<column xsi:type="varchar" name="type" nullable="false" length="64" comment="Transaction Type"/>
<column xsi:type="varchar" name="status" nullable="false" length="24" default="available" comment="Status"/>
<column xsi:type="varchar" name="reference_type" nullable="true" length="32" comment="Reference Type"/>
<column xsi:type="varchar" name="reference_id" nullable="true" length="64" comment="Reference ID"/>
<column xsi:type="varchar" name="unique_key" nullable="false" length="191" comment="Idempotency Key"/>
<column xsi:type="text" name="reason" nullable="true" comment="Reason"/>
<column xsi:type="int" name="admin_user_id" unsigned="true" nullable="true" comment="Admin User ID"/>
<column xsi:type="text" name="metadata" nullable="true" comment="JSON Metadata"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="transaction_id"/></constraint>
<constraint xsi:type="unique" referenceId="ESUN_REWARD_TRANSACTION_UNIQUE_KEY_UNQ"><column name="unique_key"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_REWARD_TRANSACTION_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID"
table="esun_reward_transaction" column="customer_id" referenceTable="customer_entity"
referenceColumn="entity_id" onDelete="CASCADE"/>
<index referenceId="ESUN_REWARD_TRANSACTION_CUSTOMER_CREATED" indexType="btree">
<column name="customer_id"/><column name="created_at"/>
</index>
</table>
<table name="esun_reward_reservation" resource="checkout" engine="innodb" comment="eSUN Reward Quote Reservations">
<column xsi:type="int" name="reservation_id" unsigned="true" nullable="false" identity="true" comment="Reservation ID"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
<column xsi:type="int" name="quote_id" unsigned="true" nullable="false" comment="Quote ID"/>
<column xsi:type="int" name="points" unsigned="true" nullable="false" comment="Reserved Points"/>
<column xsi:type="varchar" name="status" nullable="false" length="24" default="active" comment="Status"/>
<column xsi:type="timestamp" name="expires_at" nullable="true" comment="Expires At"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
<column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="true" comment="Updated At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="reservation_id"/></constraint>
<constraint xsi:type="unique" referenceId="ESUN_REWARD_RESERVATION_QUOTE_UNQ"><column name="quote_id"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_REWARD_RESERVATION_QUOTE_ID_QUOTE_ENTITY_ID"
table="esun_reward_reservation" column="quote_id" referenceTable="quote" referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
<table name="quote" resource="checkout" engine="innodb" comment="Sales Flat Quote">
<column xsi:type="int" name="reward_points_used" unsigned="true" nullable="false" default="0" comment="Reward Points Used"/>
<column xsi:type="decimal" name="reward_discount_amount" scale="4" precision="20" nullable="false" default="0" comment="Reward Discount"/>
<column xsi:type="decimal" name="base_reward_discount_amount" scale="4" precision="20" nullable="false" default="0" comment="Base Reward Discount"/>
<column xsi:type="int" name="reward_product_points" unsigned="true" nullable="false" default="0" comment="Reward Product Points"/>
</table>
<table name="quote_item" resource="checkout" engine="innodb" comment="Sales Flat Quote Item">
<column xsi:type="smallint" name="reward_redemption" unsigned="true" nullable="false" default="0" comment="Reward Redemption Item"/>
<column xsi:type="int" name="reward_points_cost" unsigned="true" nullable="false" default="0" comment="Reward Points Cost"/>
</table>
<table name="sales_order" resource="sales" engine="innodb" comment="Sales Flat Order">
<column xsi:type="int" name="reward_points_used" unsigned="true" nullable="false" default="0" comment="Reward Points Used"/>
<column xsi:type="int" name="reward_points_earned" unsigned="true" nullable="false" default="0" comment="Reward Points Earned"/>
<column xsi:type="decimal" name="reward_discount_amount" scale="4" precision="20" nullable="false" default="0" comment="Reward Discount"/>
<column xsi:type="decimal" name="base_reward_discount_amount" scale="4" precision="20" nullable="false" default="0" comment="Base Reward Discount"/>
<column xsi:type="varchar" name="reward_tier_code" nullable="true" length="32" comment="Reward Tier Snapshot"/>
<column xsi:type="decimal" name="reward_multiplier" scale="4" precision="12" nullable="false" default="1" comment="Reward Multiplier Snapshot"/>
<column xsi:type="int" name="reward_product_points" unsigned="true" nullable="false" default="0" comment="Reward Product Points"/>
<column xsi:type="int" name="reward_points_refunded" unsigned="true" nullable="false" default="0" comment="Reward Points Refunded"/>
<column xsi:type="int" name="reward_points_reversed" unsigned="true" nullable="false" default="0" comment="Earned Points Reversed"/>
</table>
<table name="sales_order_item" resource="sales" engine="innodb" comment="Sales Flat Order Item">
<column xsi:type="smallint" name="reward_redemption" unsigned="true" nullable="false" default="0" comment="Reward Redemption Item"/>
<column xsi:type="int" name="reward_points_cost" unsigned="true" nullable="false" default="0" comment="Reward Points Cost"/>
</table>
</schema>
@@ -0,0 +1,97 @@
{
"esun_reward_account": {
"column": {
"account_id": true,
"customer_id": true,
"website_id": true,
"balance": true,
"pending_balance": true,
"lifetime_earned": true,
"lifetime_spend_base": true,
"tier_code": true,
"created_at": true,
"updated_at": true
},
"constraint": {
"PRIMARY": true,
"ESUN_REWARD_ACCOUNT_CUSTOMER_ID_WEBSITE_ID": true,
"ESUN_REWARD_ACCOUNT_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID": true
}
},
"esun_reward_transaction": {
"column": {
"transaction_id": true,
"customer_id": true,
"website_id": true,
"points_delta": true,
"balance_after": true,
"type": true,
"status": true,
"reference_type": true,
"reference_id": true,
"unique_key": true,
"reason": true,
"admin_user_id": true,
"metadata": true,
"created_at": true
},
"index": {
"ESUN_REWARD_TRANSACTION_CUSTOMER_ID_CREATED_AT": true
},
"constraint": {
"PRIMARY": true,
"ESUN_REWARD_TRANSACTION_UNIQUE_KEY": true,
"ESUN_REWARD_TRANSACTION_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID": true
}
},
"esun_reward_reservation": {
"column": {
"reservation_id": true,
"customer_id": true,
"quote_id": true,
"points": true,
"status": true,
"expires_at": true,
"created_at": true,
"updated_at": true
},
"constraint": {
"PRIMARY": true,
"ESUN_REWARD_RESERVATION_QUOTE_ID": true,
"ESUN_REWARD_RESERVATION_QUOTE_ID_QUOTE_ENTITY_ID": true
}
},
"quote": {
"column": {
"reward_points_used": true,
"reward_discount_amount": true,
"base_reward_discount_amount": true,
"reward_product_points": true
}
},
"quote_item": {
"column": {
"reward_redemption": true,
"reward_points_cost": true
}
},
"sales_order": {
"column": {
"reward_points_used": true,
"reward_points_earned": true,
"reward_discount_amount": true,
"base_reward_discount_amount": true,
"reward_tier_code": true,
"reward_multiplier": true,
"reward_product_points": true,
"reward_points_refunded": true,
"reward_points_reversed": true
}
},
"sales_order_item": {
"column": {
"reward_redemption": true,
"reward_points_cost": true
}
}
}
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\ImportExport\Model\Import\SampleFileProvider">
<arguments>
<argument name="samples" xsi:type="array">
<item name="esun_reward" xsi:type="string">Esun_Reward</item>
</argument>
</arguments>
</type>
</config>
+29
View File
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="customer_register_success">
<observer name="esun_reward_registration" instance="Esun\Reward\Observer\AwardRegistrationPoints"/>
</event>
<event name="customer_address_save_after">
<observer name="esun_reward_first_address" instance="Esun\Reward\Observer\AwardFirstAddressPoints"/>
</event>
<event name="sales_order_invoice_pay">
<observer name="esun_reward_invoice_pay" instance="Esun\Reward\Observer\AwardInvoicePoints"/>
</event>
<event name="sales_order_creditmemo_refund">
<observer name="esun_reward_creditmemo_refund" instance="Esun\Reward\Observer\ReverseCreditmemoPoints"/>
</event>
<event name="review_save_after">
<observer name="esun_reward_review_approved" instance="Esun\Reward\Observer\AwardApprovedReviewPoints"/>
</event>
<event name="sales_model_service_quote_submit_before">
<observer name="esun_reward_copy_to_order" instance="Esun\Reward\Observer\CopyRewardToOrder"/>
</event>
<event name="sales_model_service_quote_submit_success">
<observer name="esun_reward_spend_order_points" instance="Esun\Reward\Observer\SpendOrderPoints"/>
</event>
<event name="order_cancel_after">
<observer name="esun_reward_refund_cancelled_points" instance="Esun\Reward\Observer\RefundCancelledOrderPoints"/>
</event>
<event name="checkout_cart_save_after"><observer name="esun_reward_recalculate_redemptions" instance="Esun\Reward\Observer\RecalculateRedemptionPoints"/></event>
</config>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global"><fieldset id="quote_convert_item">
<field name="reward_redemption"><aspect name="to_order_item"/></field>
<field name="reward_points_cost"><aspect name="to_order_item"/></field>
</fieldset></scope>
</config>
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Model\CompositeConfigProvider">
<arguments>
<argument name="configProviders" xsi:type="array">
<item name="esun_reward" xsi:type="object">Esun\Reward\Model\CheckoutConfigProvider</item>
</argument>
</arguments>
</type>
<type name="Magento\Checkout\CustomerData\Cart"><plugin name="esun_reward_cart_customer_data" type="Esun\Reward\Plugin\CustomerData\CartPlugin" sortOrder="200"/></type>
<type name="Amasty\CheckoutCore\Block\Onepage\LayoutProcessor">
<plugin name="esun_reward_checkout_summary_layout"
type="Esun\Reward\Plugin\Checkout\SummaryLayoutProcessorPlugin"
sortOrder="200"/>
</type>
</config>
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard"><route id="esun_reward" frontName="reward"><module name="Esun_Reward"/></route></router>
</config>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_ImportExport:etc/import.xsd">
<entity name="esun_reward" label="Customer Reward Points and Tier"
model="Esun\Reward\Model\Import\Reward"
behaviorModel="Magento\ImportExport\Model\Source\Import\Behavior\Basic"/>
</config>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Esun_Reward">
<sequence>
<module name="Magento_Customer"/>
<module name="Magento_ImportExport"/>
<module name="Magento_Sales"/>
<module name="Magento_Quote"/>
<module name="Magento_Checkout"/>
<module name="Magento_Review"/>
<module name="Amasty_CheckoutCore"/>
<module name="Esun_Cart"/>
<module name="Esun_Review"/>
</sequence>
</module>
</config>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
<section name="quote"><group name="totals"><item name="reward_discount" instance="Esun\Reward\Model\Total\Quote\RewardDiscount" sort_order="500"/></group></section>
</config>