hryvinskyi / magento2-gdpr-sales
Orders as an entity of the Magento 2 data-subject requests: export a subject's orders and anonymise them, never delete them, prove a guest's claim to an order, and tell how long a guest has been inactive
Package info
github.com/hryvinskyi/magento2-gdpr-sales
Type:magento2-module
pkg:composer/hryvinskyi/magento2-gdpr-sales
Requires
- php: ~8.3.0||~8.4.0||~8.5.0
- hryvinskyi/magento2-gdpr: ^1.0
- hryvinskyi/magento2-gdpr-api: ^1.0
- magento/framework: *
- magento/module-quote: *
- magento/module-sales: *
- magento/module-store: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Adds orders and shopping carts to the data-subject requests of hryvinskyi/magento2-gdpr, and the two things a store needs around them: a guest's proof that an order is theirs, and the guests whose latest order is old enough to clean up. It contributes through di.xml only. The engine never names this package.
What it does for a store
- Orders are anonymised, never deleted. The
orderentity has no deleter. An erase or an anonymise request replaces the shopper's fields in the order, its addresses, its payment (card holder, account holder, free-form details), the comments of its status history and of its invoices, shipments and credit memos, and in the sales grids the admin lists show. Every amount, tax, currency, SKU, product name, quantity, status, store, date, country, region and payment method stays, so the totals and the admin order view keep working. - Which orders a subject covers. A customer subject covers the orders of its account, in every store. A guest subject covers the orders of its e-mail address (any letter case) in its website that no account holds: guest orders, and the orders of a deleted account, which keep the address and lose the account. An order whose store view was deleted has no store any more and belongs to the guest of its address on every website, for the export, the erasure, the guest's proof, the inactivity and the age-based anonymisation alike. A guest order that carries an account's address is not the account's.
- The payment information is anonymised key by key. The gateway information of an order's payment and of its transactions, and of a cart's payment (
additional_information), is rewritten at any depth: a value under a known personal key is replaced by the strategy of the key's field type, and every other key and the stored form stay. A value that does not decode as stored information is left unchanged. - Exports. An order is exported with its totals, payment method and every personal field the order and its payment hold (the personal keys of the payment information as one JSON text), its items, its addresses with every personal field, and the comments written on it and on its invoices, shipments and credit memos. A cart is exported the same way, with its items and addresses.
- Carts. The
quoteentity covers the carts of a customer's account, active or not, and for a guest the carts in its website that no account holds and that carry its e-mail address on the cart or on one of its addresses (a guest checkout keeps the address on the cart's addresses until the order is placed). It exports each cart with its dates, state, store, totals and currency, and its items. A cart is deleted by default, and the database removes its items, addresses and guest mask with it. An erasure rule can anonymise carts instead. - Orders are anonymised by age. With age-based anonymisation on and
retention_monthsset fororder, a scheduled job anonymises orders older than that, whoever placed them, in batches. Each order it has handled is recorded, so the next batch takes the next orders whichever fields the rule names, and an order is handled once. - A guest proves an order. A claim matches when the order number, the e-mail address and the billing lastname or postcode all match an order of the website that no account holds. The number is compared without surrounding spaces and one leading
#, the address and lastname without case, the postcode without spaces or case, and a blank lastname or postcode matches nothing. The comparison is timing-safe. An order whose store view was deleted is matched on whichever website the claim is made. - Inactive guests. A guest whose latest order is older than the inactivity period is proposed to the inactive-subject clean-up, and every subject's latest order counts as its last activity. An address in the reserved
.invaliddomain is never proposed, nor is an address no subject can hold.
Requirements
- Magento Open Source or Adobe Commerce 2.4.8 or 2.4.9, PHP 8.3 to 8.5.
hryvinskyi/magento2-gdpr-api^1.0 andhryvinskyi/magento2-gdpr^1.0.- The platform's Store, Sales and Quote modules.
Installation
Run from the Magento root. hryvinskyi/magento2-gdpr-pack installs this package with the rest of the suite.
composer require hryvinskyi/magento2-gdpr-sales
bin/magento module:enable Hryvinskyi_GdprApi Hryvinskyi_Clock Hryvinskyi_RateLimit Hryvinskyi_DocumentExport Hryvinskyi_Logger Hryvinskyi_Gdpr Hryvinskyi_GdprSales
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
Verify with a dry-run plan for a customer who has orders. It changes nothing.
bin/magento gdpr:erase --customer-id=<customer_id> --dry-run
The output lists quote (delete) and order (anonymise) with the number of records the subject holds.
Configuration
This package has no settings of its own. It reads the erasure rules of the core, hryvinskyi_gdpr/erasure/rules, for the entity codes order and quote, and the age-based anonymisation switch hryvinskyi_gdpr/retention/enabled. The rules and their format are in the README of hryvinskyi/magento2-gdpr.
| Entity | Default method | Fields an anonymisation can replace |
|---|---|---|
order |
anonymise (it cannot be deleted) |
customer_email, customer_prefix, customer_firstname, customer_middlename, customer_lastname, customer_suffix, customer_dob, customer_taxvat, customer_note, remote_ip, x_forwarded_for, and in the order's addresses email, prefix, firstname, middlename, lastname, suffix, company, street, city, postcode, telephone, fax, vat_id, and cc_owner, echeck_account_name, additional_data, comment and payment_additional_information |
quote |
delete |
customer_email, customer_prefix, customer_firstname, customer_middlename, customer_lastname, customer_suffix, customer_dob, customer_taxvat, customer_note, remote_ip, and in the cart's addresses customer_notes, email, prefix, firstname, middlename, lastname, suffix, company, street, city, postcode, telephone, fax, vat_id, and cc_owner and payment_additional_information of its payment |
A rule that names no fields uses all of them. A rule may name retention_months for order, the age in months after which orders are anonymised for everyone.
Stored data
The package creates one table, hryvinskyi_gdpr_sales_aged_order: the id of each order the age-based anonymisation has handled (order_id, removed with its order) and the moment it was recorded (anonymised_at). It reads and writes these tables of the platform:
| Entity | Tables |
|---|---|
order |
sales_order, sales_order_address, sales_order_payment and sales_payment_transaction (the payment information), sales_order_status_history, the comment tables of invoices, shipments and credit memos, and the grids sales_order_grid, sales_invoice_grid, sales_shipment_grid and sales_creditmemo_grid. |
quote |
quote, quote_address, quote_item and quote_payment; the guest mask quote_id_mask goes with the cart it belongs to. |
An anonymised value is deterministic for the request, the entity, the record and the field, so a repeated run writes the same values.
Limits
- An order is never deleted. An erase request anonymises it.
- A payment method that keeps personal data under a key this package does not know keeps it. Add the key (below).
- A document that was already printed or e-mailed (an invoice PDF, for example) is outside the store's data and stays as it is.
- Rows tied only to an e-mail address are the guest's, not the customer's: a customer's request does not reach a guest order that carries the account's address. An operator makes a guest request for that address.
Registrations
| Where | What |
|---|---|
providers of Hryvinskyi\Gdpr\Model\Entity\EntityProviderPool |
order, Hryvinskyi\GdprSales\Model\Provider\Order\OrderProvider; quote, Hryvinskyi\GdprSales\Model\Provider\Quote\QuoteProvider |
verifiers of Hryvinskyi\Gdpr\Model\Guest\GuestOwnership |
order, Hryvinskyi\GdprSales\Model\Guest\GuestOrderOwnershipVerifier |
sources of Hryvinskyi\Gdpr\Model\Inactivity\InactiveSubjects |
guest_order, Hryvinskyi\GdprSales\Model\Inactivity\GuestOrderInactiveSource |
activities of Hryvinskyi\Gdpr\Model\Inactivity\InactiveSubjects |
order, Hryvinskyi\GdprSales\Model\Inactivity\OrderActivity |
grids of Hryvinskyi\GdprSales\Model\Provider\Order\OrderGrids |
the order, invoice, shipment and credit memo grids |
paymentInformationKeys of Hryvinskyi\GdprSales\Model\Provider\Payment\PaymentInformationKeys |
the personal keys of the payment information and their field types |
The package registers no route, command, cron job, event or plugin.
Extension points
Payment information keys
A payment gateway that stores a name, an address or a phone number in the payment information adds its keys. The keys serve orders and carts alike, and the export lists the values under them. The item name is the key (compared without case, at any depth), and the value is a field type of the core: email, name, phone, address, ip, free_text or date_of_birth.
<type name="Hryvinskyi\GdprSales\Model\Provider\Payment\PaymentInformationKeys"> <arguments> <argument name="paymentInformationKeys" xsi:type="array"> <item name="payer_given_name" xsi:type="string">name</item> <item name="payer_home_phone" xsi:type="string">phone</item> </argument> </arguments> </type>
The keys the package ships are email, payer_email, customer_email, paypal_payer_email, buyer_email, name, payer_name, cc_owner, card_holder, cardholder_name, firstname, lastname, paypal_payer_name, address, street, city, postcode, zip, billing_address, shipping_address, phone, telephone, ip, ip_address, remote_ip and customer_ip.
Sales grids
A grid the platform or a module keeps for orders is rebuilt after an order is anonymised, so it never shows a name the order no longer has. A store adds a grid of its own. The item name is <table>.<column holding the order id> of the grid's main table, and the value is the grid's Magento\Sales\Model\ResourceModel\GridInterface.
<type name="Hryvinskyi\GdprSales\Model\Provider\Order\OrderGrids"> <arguments> <argument name="grids" xsi:type="array"> <item name="vendor_order_report.order_id" xsi:type="object">Vendor\Module\Model\ResourceModel\OrderReportGrid</item> </argument> </arguments> </type>
Tests
Run from the Magento root.
- Unit:
vendor/bin/phpunit -c app/code/Hryvinskyi/GdprSales/phpunit.xml.dist. The package's rules are proved against a real database, so the unit suite holds no test. - Integration: the platform's harness in
dev/tests/integration, against its own database, one run at a time.cd dev/tests/integration && php -d memory_limit=4G ../../../vendor/bin/phpunit -c phpunit.xml ../../../app/code/Hryvinskyi/GdprSales/Test/Integration. - Static analysis: PHPStan 2.x at level 10 with the package's
phpstan.neon.dist(phpstan analyse -c app/code/Hryvinskyi/GdprSales/phpstan.neon.dist --level=10), andvendor/bin/phpcs --standard=app/code/Hryvinskyi/GdprSales/phpcs.xml.dist app/code/Hryvinskyi/GdprSales.
Translations
The labels the package shows in the admin and in exports ship in en_US and 25 more locales: the official languages of the European Union, Norwegian Bokmål and Ukrainian. The translations are machine-made; have them read by a native speaker before a store relies on them, and override a phrase in a theme or a language pack.