pixelperfectat / magento2-module-discount-lines-mageplaza-giftcard
Mageplaza Gift Card adapter for the Discount Lines module: masked, contract-conformant gift card lines on every surface
Package info
github.com/pixelperfectat/magento2-module-discount-lines-mageplaza-giftcard
Type:magento2-module
pkg:composer/pixelperfectat/magento2-module-discount-lines-mageplaza-giftcard
Requires
- php: ^8.3
- magento/framework: ^103.0
- magento/module-quote: ^101.0
- magento/module-sales: ^103.0
- pixelperfectat/magento2-module-discount-lines: ^1.0
Requires (Dev)
- infection/infection: ^0.35
- phpunit/phpunit: ^9.6
- pixelperfectat/coding-standard: ^0.2.1
Suggests
- mageplaza/module-gift-card: Mageplaza Gift Card (commercial); the adapter reads only stored data and needs no class of it
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-01 15:41:46 UTC
README
Adapter for pixelperfectat/magento2-module-discount-lines:
redeemed Mageplaza Gift Card codes appear as masked gift card
lines ("Gift card ••••1234") on the cart, in the checkout, on the order and in the sales emails and documents, one
line per redeemed card.
Requirements
pixelperfectat/magento2-module-discount-lines- Mageplaza Gift Card (
mageplaza/module-gift-card, commercial; not a hard dependency of this package, the module is sequenced afterMageplaza_GiftCardand reads only stored data)
Tested with mageplaza/module-gift-card 4.4.2. On Mage-OS 3.x with Symfony 7 and recent PHP, that vendor package needs
small patches (console command return types); this package does not ship such patches.
Installation
composer require pixelperfectat/magento2-module-discount-lines-mageplaza-giftcard bin/magento setup:upgrade
How it works
Mageplaza books gift cards as its own gift_card totals segment, not as a sales rule discount, so the base module's
discount segment and its sum invariant are not touched. This adapter works on the gift card segment only:
- A plugin on the cart totals adds the masked lines (
extension_attributes.discount_lines, kindgift_card) to thegift_cardsegment and replaces its title ("Gift card ••••1234" or "Gift cards (••••1111, ••••2222)"). The redeemed amount per card comes from Mageplaza's stored map (mp_gift_cards). The base-currency amount is the amount Mageplaza collected on the quote address (base_gift_card_amount); only if that is missing it is derived from the quote's base-to-quote rate. - A plugin on the order totals block (order, invoice and credit memo, so emails, My Account and the admin) replaces Mageplaza's gift card row by one masked row per card, following the totals-row contract of the base module. For invoices and credit memos the card shares of the order are scaled to the document's gift card amount.
- A PDF total model prints the same masked lines in invoice and credit memo PDFs.
- Masking (
CodeMasker): the last 4 characters stay visible, shorter codes are masked completely. The visible length and mask character are constructor arguments, overridable indi.xml. - The module also registers a totals position (
sales/totals_sort/gift_card, 50) because Mageplaza registers none.
Configuration
Uses the base package settings under Stores > Configuration > Sales > Discount Lines (store-view scope): the master
switch pp_discount_lines/general/enabled (default 1) turns the masked lines off. See the
base README for the full table.
Contract
The lines follow the
contract of the base README
(kind gift_card, rule_id null, masked code).
Known limits
- Mageplaza's own
gift_cardsJSON (the cart totals extension, the coupon box, the gift card list) shows codes according to Mageplaza's hidden-code setting. It lists codes the customer entered or owns and is outside the scope of this adapter, which covers the totals, emails, PDFs and order views. - Codes of 5 to 7 characters still reveal their last 4 characters with the default masking; raise the minimum with the
CodeMaskerconstructor arguments if that matters. - Stores that override
sales/totals_sortmust addgift_cardto their sort order. - Invoices and credit memos get the order's card shares scaled to the document amount, so per-card amounts there can differ by a cent from the order.
- See the base README for the complete list of known limits.
Screenshots
Placeholder data only, in docs/screenshots/:
Development
composer install composer check
composer check runs composer validate, PHP lint, PHP_CodeSniffer, PHPStan, PHPUnit and Infection mutation testing
(fails below MSI 85 or covered-code MSI 90). Infection needs a coverage driver: enable pcov, or Xdebug with
XDEBUG_MODE=coverage. composer infection runs the mutation tests on their own.
License
MIT, see LICENSE.