saurabhg / module-buy-now
Buy Now button on product and listing pages that takes the customer straight to checkout.
Package info
github.com/saurabh20394/Saurabhg-BuyNow
Type:magento2-module
pkg:composer/saurabhg/module-buy-now
Requires
- php: ~8.1.0||~8.2.0||~8.3.0||~8.4.0||~8.5.0
- magento/framework: *
- magento/module-catalog: *
- magento/module-checkout: *
- magento/module-config: *
- magento/module-quote: *
- magento/module-store: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-18 14:56:33 UTC
README
Buy Now button for Magento 2.4 (Luma). Customers can buy a product straight from the product page or a product listing: one click adds it to the cart and opens checkout, so they skip the cart page.
Installation
bin/magento module:enable Saurabhg_BuyNow bin/magento setup:upgrade bin/magento setup:di:compile # production mode only bin/magento setup:static-content:deploy # production mode, and on Windows in any mode bin/magento cache:flush
The module adds no database tables.
Configuration
Stores → Configuration → Saurabh Extensions → Buy Now Button
| Option | Default | Description |
|---|---|---|
| Status | Yes | Shows or hides the Buy Now button on the storefront. |
| Button Title | Buy Now | Text on the button. Can be set per store view. |
| Show on Product Listing | Yes | Also shows the button on category, search result and advanced search pages. |
| Remove Other Cart Items | Yes | Yes: existing cart items are removed, so checkout contains only the product being bought. No: the product is added to the existing cart. |
You can set every option per website and store view. The ACL resource is Saurabhg_BuyNow::config.
Storefront behaviour
- Product page: the button sits next to Add to Cart. It works for simple, virtual, downloadable, configurable, bundle and grouped products. It uses the same product form, so the selected options, custom options and qty are validated exactly as they are for Add to Cart.
- Product listing: the button sits under Add to Cart and adds qty 1. If a product needs options first (a configurable with no swatch picked, a bundle, or required custom options), the customer is sent to the product page with a message, the same way as core Add to Cart.
- The button only shows on saleable products, so out-of-stock products get none.
- On success the customer is redirected to
/checkout/. Guest checkout settings still apply. - If the product can't be added (out of stock, missing options, qty errors), the error is shown and the customer's cart is left unchanged. The cart is only saved, and other items only removed, after the product has been added.
How it works
| Part | File |
|---|---|
Controller POST buynow/cart/add (form key check; JSON for AJAX, redirect otherwise) |
Controller/Cart/Add.php |
Cart logic: loads the product, normalises qty, optionally empties the cart, adds the product, saves the cart inside a quote lock (QuoteMutexInterface) |
Model/BuyNowService.php |
| Configuration reader | Model/Config.php |
| Data for the templates | ViewModel/BuyNow.php |
| Product page button | view/frontend/templates/product/view/buynow.phtml, view/frontend/web/js/buy-now.js |
| Listing button | view/frontend/templates/product/list/buynow.phtml, view/frontend/web/js/list-buy-now.js |
| Styles (49% width next to Add to Cart on desktop, full width on mobile) | view/frontend/web/css/source/_module.less |
The button reuses the core add-to-cart form. When it is clicked, the form's action is pointed at
buynow/cart/add, the form is submitted through the core catalogAddToCart widget, and the original action is
restored. Core templates are not overridden. The button is added as a child of product.info.addtocart,
product.info.addtocart.additional and product.info.addtocart.bundle. On listings it is added to every
[data-role=tocart-form] form.
After Buy Now, the cart customer-data section is refreshed (etc/frontend/sections.xml). The controller
dispatches the core checkout_cart_add_product_complete event, so observers that listen to Add to Cart
still run.
Compatibility
- Magento Open Source / Adobe Commerce 2.4.x, PHP 8.1 to 8.5.
- Luma, Blank and themes based on them. Hyvä themes need their own template and styles.
License
GPL-3.0-or-later. Copyright (C) 2026 Saurabh Gupta.