-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from mageprince/develop-1.4.0
Develop 1.4.0
- Loading branch information
Showing
27 changed files
with
635 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,22 @@ | |
|
||
/** | ||
* MagePrince | ||
* Copyright (C) 2020 Mageprince <[email protected]> | ||
* | ||
* @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 <[email protected]> | ||
* 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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,22 @@ | |
|
||
/** | ||
* MagePrince | ||
* Copyright (C) 2020 Mageprince <[email protected]> | ||
* | ||
* @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 <[email protected]> | ||
* 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' => [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,29 @@ | |
|
||
/** | ||
* MagePrince | ||
* Copyright (C) 2020 Mageprince <[email protected]> | ||
* | ||
* @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 <[email protected]> | ||
* 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(); | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Mageprince\BuyNow\ViewModel; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\View\Element\Block\ArgumentInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
class BuyNow implements ArgumentInterface | ||
{ | ||
/** | ||
* Buynow config paths | ||
*/ | ||
public const BUYNOW_BUTTON_TITLE_PATH = 'buynow/general/button_title'; | ||
public const KEEP_CART_PRODUCTS_PATH = 'buynow/general/keep_cart_products'; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
protected $scopeConfig; | ||
|
||
/** | ||
* BuyNow constructor. | ||
* @param ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $scopeConfig | ||
) { | ||
$this->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 | ||
); | ||
} | ||
} |
Oops, something went wrong.