diff --git a/Block/Adminhtml/System/Config/Field/Disable.php b/Block/Adminhtml/System/Config/Field/Disable.php
index 4b4ce3b..9296010 100644
--- a/Block/Adminhtml/System/Config/Field/Disable.php
+++ b/Block/Adminhtml/System/Config/Field/Disable.php
@@ -2,12 +2,22 @@
/**
* MagePrince
- * Copyright (C) 2020 Mageprince
*
- * @package Mageprince_BuyNow
- * @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/)
- * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0)
- * @author MagePrince
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the mageprince.com license that is
+ * available through the world-wide-web at this URL:
+ * https://mageprince.com/end-user-license-agreement
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade this extension to newer
+ * version in the future.
+ *
+ * @category MagePrince
+ * @package Mageprince_BuyNow
+ * @copyright Copyright (c) MagePrince (https://mageprince.com/)
+ * @license https://mageprince.com/end-user-license-agreement
*/
namespace Mageprince\BuyNow\Block\Adminhtml\System\Config\Field;
@@ -18,6 +28,8 @@
class Disable extends Field
{
/**
+ * Disable element
+ *
* @param AbstractElement $element
* @return string
*/
diff --git a/Block/Product/ListProduct.php b/Block/Product/ListProduct.php
index 59833c4..b2f1923 100755
--- a/Block/Product/ListProduct.php
+++ b/Block/Product/ListProduct.php
@@ -2,12 +2,22 @@
/**
* MagePrince
- * Copyright (C) 2020 Mageprince
*
- * @package Mageprince_BuyNow
- * @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/)
- * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0)
- * @author MagePrince
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the mageprince.com license that is
+ * available through the world-wide-web at this URL:
+ * https://mageprince.com/end-user-license-agreement
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade this extension to newer
+ * version in the future.
+ *
+ * @category MagePrince
+ * @package Mageprince_BuyNow
+ * @copyright Copyright (c) MagePrince (https://mageprince.com/)
+ * @license https://mageprince.com/end-user-license-agreement
*/
namespace Mageprince\BuyNow\Block\Product;
@@ -47,7 +57,11 @@ public function __construct(
*/
public function getAddToCartPostParams(\Magento\Catalog\Model\Product $product)
{
- $url = $this->getAddToCartUrl($product);
+ $url = str_replace(
+ 'checkout/cart/add',
+ 'buynow/cart/add',
+ $this->getAddToCartUrl($product)
+ );
return [
'action' => $url,
'data' => [
diff --git a/Controller/Cart/Add.php b/Controller/Cart/Add.php
index ad86f03..c0557e0 100755
--- a/Controller/Cart/Add.php
+++ b/Controller/Cart/Add.php
@@ -2,16 +2,29 @@
/**
* MagePrince
- * Copyright (C) 2020 Mageprince
*
- * @package Mageprince_BuyNow
- * @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/)
- * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0)
- * @author MagePrince
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the mageprince.com license that is
+ * available through the world-wide-web at this URL:
+ * https://mageprince.com/end-user-license-agreement
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade this extension to newer
+ * version in the future.
+ *
+ * @category MagePrince
+ * @package Mageprince_BuyNow
+ * @copyright Copyright (c) MagePrince (https://mageprince.com/)
+ * @license https://mageprince.com/end-user-license-agreement
*/
namespace Mageprince\BuyNow\Controller\Cart;
+use Magento\Framework\Filter\LocalizedToNormalized;
+use Mageprince\BuyNow\ViewModel\BuyNow as BuyNowViewModel;
+
class Add extends \Magento\Checkout\Controller\Cart\Add
{
/**
@@ -33,7 +46,7 @@ public function execute()
try {
if (isset($params['qty'])) {
- $filter = new \Zend_Filter_LocalizedToNormalized(
+ $filter = new LocalizedToNormalized(
['locale' => $this->_objectManager->get(
\Magento\Framework\Locale\ResolverInterface::class
)->getLocale()]
@@ -51,7 +64,7 @@ public function execute()
return $this->goBack();
}
- $buyNowHelper = $this->_objectManager->create(\Mageprince\BuyNow\Helper\Data::class);
+ $buyNowHelper = $this->_objectManager->create(BuyNowViewModel::class);
$cartProducts = $buyNowHelper->keepCartProducts();
if (!$cartProducts) {
$this->cart->truncate(); //remove all products from cart
@@ -61,7 +74,6 @@ public function execute()
if (!empty($related)) {
$this->cart->addProductsByIds(explode(',', $related));
}
-
$this->cart->save();
/**
@@ -96,7 +108,10 @@ public function execute()
}
return $this->goBack($url);
} catch (\Exception $e) {
- $this->messageManager->addException($e, __('We can\'t add this item to your shopping cart right now.'));
+ $this->messageManager->addExceptionMessage(
+ $e,
+ __('We can\'t add this item to your shopping cart right now.')
+ );
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
return $this->goBack();
}
diff --git a/Helper/Data.php b/Helper/Data.php
deleted file mode 100755
index 2bedcb3..0000000
--- a/Helper/Data.php
+++ /dev/null
@@ -1,83 +0,0 @@
-
- *
- * @package Mageprince_BuyNow
- * @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/)
- * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0)
- * @author MagePrince
- */
-
-namespace Mageprince\BuyNow\Helper;
-
-class Data extends \Magento\Framework\App\Helper\AbstractHelper
-{
- /**
- * Buynow button title path
- */
- const BUYNOW_BUTTON_TITLE_PATH = 'buynow/general/button_title';
-
- /**
- * Buynow button title
- */
- const BUYNOW_BUTTON_TITLE = 'Buy Now';
-
- /**
- * Addtocart button form id path
- */
- const ADDTOCART_FORM_ID_PATH = 'buynow/general/addtocart_id';
-
- /**
- * Addtocart button form id
- */
- const ADDTOCART_FORM_ID = 'product_addtocart_form';
-
- /**
- * Keep cart products path
- */
- const KEEP_CART_PRODUCTS_PATH = 'buynow/general/keep_cart_products';
-
- /**
- * Retrieve config value
- *
- * @return string
- */
- public function getConfig($config)
- {
- return $this->scopeConfig->getValue(
- $config,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
- );
- }
-
- /**
- * Get button title
- * @return string
- */
- public function getButtonTitle()
- {
- $btnTitle = $this->getConfig(self::BUYNOW_BUTTON_TITLE_PATH);
- return $btnTitle ? $btnTitle : self::BUYNOW_BUTTON_TITLE;
- }
-
- /**
- * Get addtocart form id
- * @return string
- */
- public function getAddToCartFormId()
- {
- $addToCartFormId = $this->getConfig(self::ADDTOCART_FORM_ID_PATH);
- return $addToCartFormId ? $addToCartFormId : self::ADDTOCART_FORM_ID;
- }
-
- /**
- * Check if keep cart products
- * @return string
- */
- public function keepCartProducts()
- {
- return $this->getConfig(self::KEEP_CART_PRODUCTS_PATH);
- }
-}
diff --git a/README.md b/README.md
index d6ee6f2..72d42b8 100755
--- a/README.md
+++ b/README.md
@@ -1,38 +1,55 @@
-# Magento 2 BuyNow
+[![Latest Stable Version](https://poser.pugx.org/mageprince/module-buynow/v)](//packagist.org/packages/mageprince/module-buynow)
+[![Total Downloads](https://poser.pugx.org/mageprince/module-buynow/downloads)](//packagist.org/packages/mageprince/module-buynow)
+[![Monthly Downloads](https://poser.pugx.org/mageprince/module-buynow/d/monthly)](//packagist.org/packages/mageprince/module-buynow)
+[![License](https://poser.pugx.org/mageprince/module-buynow/license)](//packagist.org/packages/mageprince/module-buynow)
+[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mageprince/magento2-buynow/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mageprince/magento2-FAQ/?branch=master)
+[![Code Intelligence Status](https://scrutinizer-ci.com/g/mageprince/magento2-buynow/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence)
-This module add "BuyNow" button on product view page and list page to process directly checkout.
+# Magento 2 Buy Now
-BuyNow Configuration: Stores->Configuration->MagePrince->Buy Now
+The Buy Now extension for Magento 2 enhances the shopping experience by allowing customers to make instant purchases with a single click. It adds a "Buy Now" button to product pages, enabling customers to bypass the cart and proceed directly to the checkout page.
+
+Admin Configuration: `Admin > Stores > Configuration > MagePrince > Buy Now`
+
+# How to install
+
+### 1. Install via composer (packagist.org)
+
+Run the following command in the Magento 2 root folder:
+
+ composer require mageprince/module-buynow
+ php bin/magento setup:upgrade
+ php bin/magento setup:di:compile
+ php bin/magento setup:static-content:deploy
+
+### 2. Install manually (Not recommended)
+
+Copy the content of the repo to the app/code/Mageprince/BuyNow folder and run the following command in the Magento 2 root folder:
+
+ php bin/magento setup:upgrade
+ php bin/magento setup:di:compile
+ php bin/magento setup:static-content:deploy
# Notice
-We don't support Buy Now button on related, upsell, wishlist or any other places because it needs override core phtml files which is not the recommended solution. Please keep in note that most of the paid or free version of the Buy Now module overrides the core phtml files.
+We do not provide support for placing the Buy Now button on related, upsell, wishlist, or any other locations, as it requires overriding core phtml files, which isn't a good idea for an extension. Please be aware that many paid or free versions of the Buy Now module override these core files. Instead, use this piece of code to add the Buy Now button to custom product templates.
-# Copy below code to add Buy Now button in custom product sliders, widget, static blocks etc.
+ $buyNowBtnHtml = $this->getLayout()
+ ->createBlock(\Mageprince\BuyNow\Block\Product\ListProduct::class)
+ ->setProduct($_item)
+ ->setButtonTitle('Buy Now')
+ ->setTemplate('Mageprince_BuyNow::buynow.phtml')
+ ->toHtml();
+ echo $buyNowBtnHtml;
-``````
-$buyNowHtml = $this->getLayout()
- ->createBlock('Mageprince\BuyNow\Block\Product\ListProduct')
- ->setProduct($_item)
- ->setTemplate('Mageprince_BuyNow::buynow-list.phtml')
- ->toHtml();
-echo $buyNowHtml;
-``````
Change `$_item` to current product object.
-You can use above code where you want to show buy now button in product. Please make sure don't copy this code to addtocart or any other form. Put this code after any ``. Here is the screenshot of sample code of usage
-
-
+You can use the code above to display the Buy Now button wherever you want on your product page. Just remember not to paste this code into the add to cart form or any other form. Put the code after `` tag. Below is a screenshot showing how to use the code.
+**Sample template:** _vendor/magento/module-catalog/view/frontend/templates/product/list/items.phtml_
-# Installation Instruction
+
-* Copy the content of the repo to the app/code/Mageprince/BuyNow folder
-* Run command:
-php bin/magento setup:upgrade
-* Run Command:
-php bin/magento setup:static-content:deploy
-* Now Flush Cache: php bin/magento cache:flush
# Contribution
@@ -42,16 +59,19 @@ Want to contribute to this extension? The quickest way is to open an issue on GitHub.
-PRODUCT VIEW PAGE
+# Screenshots
+
+### Product view page
+
+
+
+### Product list page
-
+
-PRODUCT LIST PAGE
+### Custom product template with buy now code
-
+
-# How To Find Addtocart Form Id - Useful For Custom Theme
-Go to product view page and right click on addtocart button and click on inspect element. Then scroll up and find addtocart form id.
-
diff --git a/ViewModel/BuyNow.php b/ViewModel/BuyNow.php
new file mode 100644
index 0000000..b68154f
--- /dev/null
+++ b/ViewModel/BuyNow.php
@@ -0,0 +1,57 @@
+scopeConfig = $scopeConfig;
+ }
+
+ /**
+ * Retrieve button title
+ *
+ * @return string
+ */
+ public function getButtonTitle()
+ {
+ return $this->scopeConfig->getValue(
+ self::BUYNOW_BUTTON_TITLE_PATH,
+ ScopeInterface::SCOPE_STORE
+ );
+ }
+
+ /**
+ * Check if keep cart products
+ *
+ * @return string
+ */
+ public function keepCartProducts()
+ {
+ return $this->scopeConfig->isSetFlag(
+ self::KEEP_CART_PRODUCTS_PATH,
+ ScopeInterface::SCOPE_STORE
+ );
+ }
+}
diff --git a/composer.json b/composer.json
index d91e810..ee69465 100755
--- a/composer.json
+++ b/composer.json
@@ -3,7 +3,7 @@
"description": "Magento2 Buy Now Module",
"homepage": "https://github.com/mageprince/magento2-buynow",
"type": "magento2-module",
- "version": "1.3.0",
+ "version": "1.4.0",
"license": "GPL-3.0-or-later",
"authors": [
{
diff --git a/etc/acl.xml b/etc/acl.xml
index 1a8c13a..9161f35 100644
--- a/etc/acl.xml
+++ b/etc/acl.xml
@@ -2,12 +2,22 @@
@@ -17,7 +27,7 @@
-
+
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 50342a0..7814da4 100755
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -2,12 +2,22 @@
@@ -22,38 +32,35 @@
Mageprince_BuyNow::config
-
-
- Magento\Config\Model\Config\Source\Yesno
- Keep Other Cart Item(s) When Click Buy Now
-
-
+ Magento\Config\Model\Config\Source\Yesno
-
+ Magento\Config\Model\Config\Source\Yesno
-
+ Magento\Config\Model\Config\Source\Yesno
-
+ Magento\Config\Model\Config\Source\Yesno
-
+
+ required-entry
-
-
- Enter addtocart form id for product view page(Ex. product_addtocart_form). Check readme for more details.
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ Keep other item(s) in the cart on buy now.
-
+ Mageprince\BuyNow\Block\Adminhtml\System\Config\Field\Disable
- $_item to current product object. This code generates buy now button with new form so make sure don't copy this code into any other form.]]>
+ $_item with the current product object. This code creates a new form for the buy now button, so ensure that you do not insert this code into any other form.]]>
diff --git a/etc/config.xml b/etc/config.xml
index 33d5e02..3020ffe 100755
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -2,31 +2,41 @@
- 1
+ 01111
- product_addtocart_formBuy Now
- getLayout()
- ->createBlock('Mageprince\BuyNow\Block\Product\ListProduct')
+ getLayout()
+ ->createBlock(\Mageprince\BuyNow\Block\Product\ListProduct::class)
->setProduct($_item)
- ->setTemplate('Mageprince_BuyNow::buynow-list.phtml')
+ ->setButtonTitle('Buy Now')
+ ->setTemplate('Mageprince_BuyNow::buynow.phtml')
->toHtml();
-echo $buyNowHtml;]]>
+echo $buyNowBtnHtml;]]>
diff --git a/etc/frontend/routes.xml b/etc/frontend/routes.xml
index 50297d0..bd88d3e 100755
--- a/etc/frontend/routes.xml
+++ b/etc/frontend/routes.xml
@@ -2,12 +2,22 @@
-
\ No newline at end of file
+
diff --git a/etc/frontend/sections.xml b/etc/frontend/sections.xml
index 2433bf1..d0736ba 100755
--- a/etc/frontend/sections.xml
+++ b/etc/frontend/sections.xml
@@ -2,12 +2,22 @@
-
\ No newline at end of file
+
diff --git a/etc/module.xml b/etc/module.xml
index fdc6dce..f49a58f 100755
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -2,18 +2,28 @@
-
+
-
\ No newline at end of file
+
diff --git a/view/frontend/layout/catalog_category_view.xml b/view/frontend/layout/catalog_category_view.xml
index ac1a231..f435112 100644
--- a/view/frontend/layout/catalog_category_view.xml
+++ b/view/frontend/layout/catalog_category_view.xml
@@ -2,21 +2,33 @@
-
+
+
+ Mageprince\BuyNow\ViewModel\BuyNow
+
+
+
-
\ No newline at end of file
+
diff --git a/view/frontend/layout/catalog_product_view.xml b/view/frontend/layout/catalog_product_view.xml
index 52503ac..0e6e567 100755
--- a/view/frontend/layout/catalog_product_view.xml
+++ b/view/frontend/layout/catalog_product_view.xml
@@ -2,27 +2,39 @@
-
+
+
+ Mageprince\BuyNow\ViewModel\BuyNow
+
+
-
+
+
+ Mageprince\BuyNow\ViewModel\BuyNow
+
+
-
\ No newline at end of file
+
diff --git a/view/frontend/layout/catalog_product_view_type_bundle.xml b/view/frontend/layout/catalog_product_view_type_bundle.xml
index a97c4f9..d503bec 100755
--- a/view/frontend/layout/catalog_product_view_type_bundle.xml
+++ b/view/frontend/layout/catalog_product_view_type_bundle.xml
@@ -2,21 +2,32 @@
-
+
+
+ Mageprince\BuyNow\ViewModel\BuyNow
+
+
diff --git a/view/frontend/layout/catalogsearch_advanced_result.xml b/view/frontend/layout/catalogsearch_advanced_result.xml
index 319353c..7c0461e 100755
--- a/view/frontend/layout/catalogsearch_advanced_result.xml
+++ b/view/frontend/layout/catalogsearch_advanced_result.xml
@@ -2,22 +2,33 @@
-
+
+
+ Mageprince\BuyNow\ViewModel\BuyNow
+
+
diff --git a/view/frontend/layout/catalogsearch_result_index.xml b/view/frontend/layout/catalogsearch_result_index.xml
index 01d7a72..7bd6489 100755
--- a/view/frontend/layout/catalogsearch_result_index.xml
+++ b/view/frontend/layout/catalogsearch_result_index.xml
@@ -2,22 +2,33 @@
-
+
+
+ Mageprince\BuyNow\ViewModel\BuyNow
+
+
diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js
new file mode 100644
index 0000000..7c14f74
--- /dev/null
+++ b/view/frontend/requirejs-config.js
@@ -0,0 +1,9 @@
+var config = {
+ config: {
+ mixins: {
+ 'Magento_Catalog/js/catalog-add-to-cart': {
+ 'Mageprince_BuyNow/js/catalog-add-to-cart-mixin': true
+ },
+ }
+ }
+};
diff --git a/view/frontend/templates/buynow-list.phtml b/view/frontend/templates/buynow-list.phtml
index c9297da..c155491 100755
--- a/view/frontend/templates/buynow-list.phtml
+++ b/view/frontend/templates/buynow-list.phtml
@@ -1,45 +1,36 @@
*
- * @package Mageprince_BuyNow
- * @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/)
- * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0)
- * @author MagePrince
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the mageprince.com license that is
+ * available through the world-wide-web at this URL:
+ * https://mageprince.com/end-user-license-agreement
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade this extension to newer
+ * version in the future.
+ *
+ * @category MagePrince
+ * @package Mageprince_BuyNow
+ * @copyright Copyright (c) MagePrince (https://mageprince.com/)
+ * @license https://mageprince.com/end-user-license-agreement
*/
?>
getProduct();
+/**
+ * @var \Mageprince\BuyNow\Block\Product\ListProduct $block
+ * @var \Mageprince\BuyNow\ViewModel\BuyNow $viewModel
+ */
+$viewModel = $block->getViewModel();
+$buttonTitle = $viewModel->getButtonTitle();
?>
-helper(\Mageprince\BuyNow\Helper\Data::class); ?>
-getButtonTitle() ?>
-isSaleable()): ?>
- getAddToCartPostParams($product); ?>
-
-
-
-
+
+
+
diff --git a/view/frontend/templates/buynow-view.phtml b/view/frontend/templates/buynow-view.phtml
index b7c3f8a..a65bc48 100755
--- a/view/frontend/templates/buynow-view.phtml
+++ b/view/frontend/templates/buynow-view.phtml
@@ -1,30 +1,37 @@
*
- * @package Mageprince_BuyNow
- * @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/)
- * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0)
- * @author MagePrince
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the mageprince.com license that is
+ * available through the world-wide-web at this URL:
+ * https://mageprince.com/end-user-license-agreement
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade this extension to newer
+ * version in the future.
+ *
+ * @category MagePrince
+ * @package Mageprince_BuyNow
+ * @copyright Copyright (c) MagePrince (https://mageprince.com/)
+ * @license https://mageprince.com/end-user-license-agreement
+ */
+?>
+getViewModel();
+$buttonTitle = $viewModel->getButtonTitle();
?>
-
-helper(\Mageprince\BuyNow\Helper\Data::class); ?>
-getAddToCartFormId(); ?>
-getButtonTitle() ?>
-