bredabeds / magento-hyva-affirm
Hyvä Theme compatibility for Affirm's Magento 2 extension (affirm/magento2): promotional messaging, banners, cart button and order-confirmed pixel
Package info
github.com/BredaBeds/magento-hyva-affirm
Type:magento2-module
pkg:composer/bredabeds/magento-hyva-affirm
Requires
- php: ^8.1
- affirm/magento2: ^4.0.11
- hyva-themes/magento2-compat-module-fallback: ^1.1.2
- hyva-themes/magento2-theme-module: ^1.3.11
- magento/framework: ^103.0
- magento/module-catalog: ^104.0
- magento/module-catalog-inventory: ^100.4
- magento/module-checkout: ^100.4
- magento/module-eav: ^102.1
- magento/module-payment: ^100.4
- magento/module-quote: ^101.2
- magento/module-sales: ^103.0
- magento/module-store: ^101.1
- magento/module-tax: ^100.4
Requires (Dev)
None
Suggests
- hyva-themes/magento2-hyva-checkout: The cart page 'Checkout with Affirm' button then opens Hyvä Checkout's payment step
Provides
None
Conflicts
None
Replaces
None
README
Makes Affirm's official Magento 2 extension (affirm/magento2, module
Astound_Affirm) work on the Hyvä theme: "as low as" messages, Affirm's banners, the cart's "Checkout with Affirm"
button and the order-confirmed pixel.
Affirm's extension is built for Luma and shows nothing on Hyvä. This module replaces its storefront templates with Hyvä templates, small Alpine.js components and one affirm.js loader. Settings, promo ids, availability rules, the payment gateway and the admin stay Affirm's, and Luma store views are not changed. affirm.js writes every amount and rate; the module never does.
To pay with Affirm in Hyvä Checkout, add
bredabeds/magento-hyva-checkout-affirm. Each module
works without the other.
Requirements
| Supported | Tested | |
|---|---|---|
| PHP | 8.1 – 8.5 | 8.5 |
| Magento Open Source | 2.4.6 – 2.4.9 | 2.4.9 |
| Affirm extension | affirm/magento2 ^4.0.11 |
4.0.11, US sandbox, USD |
| Hyvä theme module | ^1.3.11 (Tailwind 3 or 4) | 1.5.x with Tailwind 4 |
| Hyvä Checkout | optional (cart button only) | 3.0.2 (1.3.15 up to 0.1.2) |
The cart page message, banners and button target Hyvä's default PHP-rendered cart page; Hyvä's GraphQL cart is not supported. The minicart message needs the cart drawer of the Hyvä default theme 1.4 or later. Not yet tested in a browser: older Magento and PHP versions, Tailwind 3, CAD stores and a nonce-only storefront CSP.
Installation
composer require bredabeds/magento-hyva-affirm bin/magento module:enable Hyva_AstoundAffirm bin/magento setup:upgrade bin/magento hyva:config:generate
Then rebuild the CSS of each Hyvä theme (npm run build-prod in its web/tailwind folder). In production mode
also run setup:di:compile, setup:static-content:deploy and cache:flush.
If Composer cannot find the package:
composer config repositories.magento-hyva-affirm vcs https://github.com/BredaBeds/magento-hyva-affirm.
Configuration
The module has no settings of its own. It uses Affirm's (Stores > Configuration > Sales > Payment Methods > Affirm, and Affirm's promotional settings), and nothing shows until you switch it on there. Every placement needs:
- Affirm enabled, with a public API key for the current mode (the
_cakeys for CAD) - USD or CAD as both the base and the display currency
Messages show between $50 and $17,500 (Affirm's limits), narrowed by Minimum / Maximum Order Total. Which setting
drives what: docs/reference.md.
What appears where
| Placement | Where | Notes |
|---|---|---|
| Product page | next to the price | follows options and configurable or bundle selections; not for grouped products |
| Listings | under each price in category, search, sliders and widgets | static |
| Cart | below "Proceed to Checkout" | follows the cart total |
| Minicart | in the Hyvä cart drawer | affirm.js loads when the drawer opens |
| Banners | home, category, product and cart pages | buttons that open Affirm's modal |
| Cart button | next to the other checkout buttons | selects Affirm and opens the checkout (at its payment step when the cart's details are complete) |
| Pixel | success page | off in sandbox mode |
| CMS content | any page or block | Affirm's documented markup works |
affirm.js loads after the page is idle, and only on pages that have something to show. Messages reserve their height, so nothing shifts when they fill in.
After changing settings or promotions
affirm.js fetches the message text on every view, but the promo id and amount are part of the cached HTML. Listing
items update by themselves; full-page caches do not. After changing Affirm settings or category Affirm attributes,
and at the start and end of a dated promotion, run bin/magento cache:clean block_html full_page and purge Varnish
and any CDN that caches HTML. Details: Cache and promotion timing.
For developers
- To hide Affirm under your own rule, add an
afterplugin onHyva\AstoundAffirm\Model\Messaging\AvailabilityInterface::isAvailable(). It decides every placement. docs/reference.mdhas the rest: each placement, thewindow.hyvaAffirmloader, the other extension points, how the module differs from Affirm on Luma, known Affirm issues and CSP and accessibility.- Tests:
vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist vendor/bredabeds/magento-hyva-affirm/Test/Uniton a Magento install,node --test Test/js/*.test.mjsfor the JavaScript, andTest/ci/README.mdfor what CI runs without one.
Turning it off
- Everything, including new Affirm checkouts: set
payment/affirm_gateway/activeto 0. Existing orders can still be invoiced, refunded and voided. - Storefront content only: switch off the message, banner, checkout button and pixel settings.
- Then run
bin/magento cache:clean config block_html full_pageand purge Varnish and the CDN. - Remove the module:
module:disable Hyva_AstoundAffirm,composer remove bredabeds/magento-hyva-affirm,setup:upgrade,hyva:config:generate, rebuild the theme CSS. It creates no database tables.
Licence
MIT, see LICENSE. The licence does not cover the Affirm name, logo, banners, buttons or scripts; see
TRADEMARKS.md and NOTICE. Not affiliated with or endorsed by Affirm, Inc. or Hyvä
Themes B.V.