From 17cc8a77d4ab87f53a166d20d0256e3aee90cff8 Mon Sep 17 00:00:00 2001 From: Ngo Doan Luong Date: Fri, 10 Apr 2020 11:51:11 +0700 Subject: [PATCH 1/5] compatible with M234 --- view/frontend/layout/default.xml | 102 +++++++-------- view/frontend/web/js/view/minicart.js | 150 ++++++++++++----------- view/frontend/web/template/minicart.html | 60 +++++---- 3 files changed, 159 insertions(+), 153 deletions(-) diff --git a/view/frontend/layout/default.xml b/view/frontend/layout/default.xml index 680da4b..12a3cfd 100644 --- a/view/frontend/layout/default.xml +++ b/view/frontend/layout/default.xml @@ -1,51 +1,51 @@ - - - - - - - - - - - - - - - - - Mageplaza_ShareCart/js/view/minicart - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + Mageplaza_ShareCart/js/view/minicart + + + + + + + + + + + + + + diff --git a/view/frontend/web/js/view/minicart.js b/view/frontend/web/js/view/minicart.js index d373c63..ebd9bcc 100644 --- a/view/frontend/web/js/view/minicart.js +++ b/view/frontend/web/js/view/minicart.js @@ -1,71 +1,79 @@ -/** - * Mageplaza - * - * NOTICE OF LICENSE - * - * This source file is subject to the Mageplaza.com license that is - * available through the world-wide-web at this URL: - * https://www.mageplaza.com/LICENSE.txt - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this extension to newer - * version in the future. - * - * @category Mageplaza - * @package Mageplaza_ShareCart - * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) - * @license https://www.mageplaza.com/LICENSE.txt - */ -define([ - 'jquery', - 'uiComponent', - 'Magento_Customer/js/customer-data', - 'mage/translate' -], function ($, Component, customerData, $t) { - 'use strict'; - - var isReload = true; - - return Component.extend({ - defaults: { - template: 'Mageplaza_ShareCart/minicart' - }, - - initialize: function () { - this._super(); - - if (isReload) { - customerData.reload(['cart'], false); - isReload = false; - } - this.customer = customerData.get('cart'); - }, - - getQuoteId: function () { - return customerData.get('cart')().quote_url; - }, - - copyQuote: function (object, e) { - var quoteUrl = document.createElement('textarea'); - - quoteUrl.value = customerData.get('cart')().quote_url; - document.body.appendChild(quoteUrl); - quoteUrl.select(); - document.execCommand('copy'); - document.body.removeChild(quoteUrl); - - e.currentTarget.setAttribute('class', 'mp-tooltipped'); - e.currentTarget.setAttribute('aria-label', $t('Copied!')); - }, - - leaveQuote: function (object, e) { - e.currentTarget.removeAttribute('class'); - e.currentTarget.removeAttribute('aria-label'); - }, - - isDisplay: function () { - return customerData.get('cart')().summary_count; - } - }); -}); +/** + * Mageplaza + * + * NOTICE OF LICENSE + * + * This source file is subject to the Mageplaza.com license that is + * available through the world-wide-web at this URL: + * https://www.mageplaza.com/LICENSE.txt + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this extension to newer + * version in the future. + * + * @category Mageplaza + * @package Mageplaza_ShareCart + * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) + * @license https://www.mageplaza.com/LICENSE.txt + */ +define([ + 'jquery', + 'uiComponent', + 'Magento_Customer/js/customer-data', + 'mage/translate', + 'rjsResolver' +], function ($, Component, customerData, $t, resolver) { + 'use strict'; + + var isReload = true; + + return Component.extend({ + defaults: { + template: 'Mageplaza_ShareCart/minicart' + }, + + initialize: function () { + this._super(); + + if (isReload) { + customerData.reload(['cart'], false); + isReload = false; + } + this.customer = customerData.get('cart'); + resolver(this.afterResolveDocument.bind(this)); + }, + + afterResolveDocument: function () { + $(document).ready(function () { + $('.secondary.sharecart').appendTo($('.action.viewcart').parent()); + }); + }, + + getQuoteId: function () { + return customerData.get('cart')().quote_url; + }, + + copyQuote: function (object, e) { + var quoteUrl = document.createElement('textarea'); + + quoteUrl.value = customerData.get('cart')().quote_url; + document.body.appendChild(quoteUrl); + quoteUrl.select(); + document.execCommand('copy'); + document.body.removeChild(quoteUrl); + + e.currentTarget.setAttribute('class', 'mp-tooltipped'); + e.currentTarget.setAttribute('aria-label', $t('Copied!')); + }, + + leaveQuote: function (object, e) { + e.currentTarget.removeAttribute('class'); + e.currentTarget.removeAttribute('aria-label'); + }, + + isDisplay: function () { + return customerData.get('cart')().summary_count; + } + }); +}); diff --git a/view/frontend/web/template/minicart.html b/view/frontend/web/template/minicart.html index a96a13a..80cb4ba 100644 --- a/view/frontend/web/template/minicart.html +++ b/view/frontend/web/template/minicart.html @@ -1,31 +1,29 @@ - - -
-
- - - -
-
- + + +
+ + + +
+ From eb7b6003ca42a121b0695d3df367de849da8e248 Mon Sep 17 00:00:00 2001 From: Ngo Doan Luong Date: Fri, 10 Apr 2020 15:53:45 +0700 Subject: [PATCH 2/5] bug with currency --- Block/Cart/Button.php | 21 +------------------ Block/Cart/Items.php | 17 ++++++++++++---- Helper/Data.php | 47 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/Block/Cart/Button.php b/Block/Cart/Button.php index 379a427..7a606fb 100644 --- a/Block/Cart/Button.php +++ b/Block/Cart/Button.php @@ -24,7 +24,6 @@ use Magento\Catalog\Model\ProductRepository; use Magento\Checkout\Model\Session; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; -use Magento\Directory\Model\Currency; use Magento\Eav\Model\Entity\Collection\AbstractCollection; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; @@ -46,11 +45,6 @@ class Button extends Template */ protected $checkoutSession; - /** - * @var Currency - */ - protected $_currency; - /** * @var ProductRepository */ @@ -81,7 +75,6 @@ class Button extends Template * * @param Context $context * @param Session $checkoutSession - * @param Currency $currency * @param ProductRepository $productRepository * @param Configurable $configurable * @param PriceCurrencyInterface $priceCurrency @@ -91,14 +84,12 @@ class Button extends Template public function __construct( Context $context, Session $checkoutSession, - Currency $currency, ProductRepository $productRepository, Configurable $configurable, PriceCurrencyInterface $priceCurrency, Data $helper, array $data = [] ) { - $this->_currency = $currency; $this->checkoutSession = $checkoutSession; $this->_productRepository = $productRepository; $this->configurable = $configurable; @@ -108,16 +99,6 @@ public function __construct( parent::__construct($context, $data); } - /** - * Get currency symbol for current locale and currency code - * - * @return string - */ - public function getCurrentCurrencySymbol() - { - return $this->_currency->getCurrencySymbol(); - } - /** * @param Quote|null $quote * @@ -171,7 +152,7 @@ public function getNameConfigurable($item) */ public function formatPrice($price) { - return $this->priceCurrency->format($price, false); + return $this->helper->convertPrice($price, true, false); } /** diff --git a/Block/Cart/Items.php b/Block/Cart/Items.php index cc32e8f..fc1347a 100644 --- a/Block/Cart/Items.php +++ b/Block/Cart/Items.php @@ -32,6 +32,7 @@ use Magento\Framework\View\Element\Template\Context; use Magento\Quote\Model\Quote; use Magento\Quote\Model\Quote\Item; +use Mageplaza\ShareCart\Helper\Data; /** * Class Items @@ -59,6 +60,11 @@ class Items extends Template */ protected $configurable; + /** + * @var Data + */ + protected $helper; + /** * Items constructor. * @@ -67,6 +73,7 @@ class Items extends Template * @param Currency $currency * @param ProductRepository $productRepository * @param Configurable $configurable + * @param Data $helper * @param array $data */ public function __construct( @@ -75,24 +82,26 @@ public function __construct( Currency $currency, ProductRepository $productRepository, Configurable $configurable, + Data $helper, array $data = [] ) { $this->_currency = $currency; $this->checkoutSession = $checkoutSession; $this->_productRepository = $productRepository; $this->configurable = $configurable; + $this->helper = $helper; parent::__construct($context, $data); } /** - * Get currency symbol for current locale and currency code + * @param float $price * - * @return string + * @return float */ - public function getCurrentCurrencySymbol() + public function formatPrice($price) { - return $this->_currency->getCurrencySymbol(); + return $this->helper->convertPrice($price, true, false); } /** diff --git a/Helper/Data.php b/Helper/Data.php index ee3247c..97a3272 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -21,6 +21,10 @@ namespace Mageplaza\ShareCart\Helper; +use Magento\Framework\App\Helper\Context; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Store\Model\StoreManagerInterface; use Mageplaza\Core\Helper\AbstractData; /** @@ -31,6 +35,29 @@ class Data extends AbstractData { const CONFIG_MODULE_PATH = 'sharecart'; const BUSINESS_CONFIG_PATH = 'business_information'; + /** + * @var PriceCurrencyInterface + */ + private $priceCurrency; + + /** + * Data constructor. + * + * @param Context $context + * @param ObjectManagerInterface $objectManager + * @param StoreManagerInterface $storeManager + * @param PriceCurrencyInterface $priceCurrency + */ + public function __construct( + Context $context, + ObjectManagerInterface $objectManager, + StoreManagerInterface $storeManager, + PriceCurrencyInterface $priceCurrency + ) { + $this->priceCurrency = $priceCurrency; + + parent::__construct($context, $objectManager, $storeManager); + } /** * @return bool @@ -109,4 +136,24 @@ public function getWarningMessage($storeId = null) { return $this->getModuleConfig(self::BUSINESS_CONFIG_PATH . '/message', $storeId); } + + /** + * @param float $amount + * @param bool $format + * @param bool $includeContainer + * @param null $scope + * + * @return float|string + */ + public function convertPrice($amount, $format = true, $includeContainer = true, $scope = null) + { + return $format + ? $this->priceCurrency->convertAndFormat( + $amount, + $includeContainer, + PriceCurrencyInterface::DEFAULT_PRECISION, + $scope + ) + : $this->priceCurrency->convert($amount, $scope); + } } From c7c8b94866be78297677e5d672d8ebd69631f2ee Mon Sep 17 00:00:00 2001 From: Ngo Doan Luong Date: Fri, 10 Apr 2020 16:12:00 +0700 Subject: [PATCH 3/5] bug when share cart --- Helper/Data.php | 2 +- Helper/PrintProcess.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 97a3272..5b9feed 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -38,7 +38,7 @@ class Data extends AbstractData /** * @var PriceCurrencyInterface */ - private $priceCurrency; + protected $priceCurrency; /** * Data constructor. diff --git a/Helper/PrintProcess.php b/Helper/PrintProcess.php index 0cb51cf..443ca23 100644 --- a/Helper/PrintProcess.php +++ b/Helper/PrintProcess.php @@ -34,6 +34,7 @@ use Mageplaza\ShareCart\Model\Template\Processor; use Mpdf\Mpdf; use Mpdf\MpdfException; +use Magento\Framework\Pricing\PriceCurrencyInterface; /** * Class PrintProcess @@ -88,6 +89,7 @@ class PrintProcess extends Data * @param DateTime $dateTime * @param TimeZone $timezone * @param Processor $templateProcessor + * @param PriceCurrencyInterface $priceCurrency */ public function __construct( Context $context, @@ -98,7 +100,8 @@ public function __construct( Data $helper, DateTime $dateTime, TimeZone $timezone, - Processor $templateProcessor + Processor $templateProcessor, + PriceCurrencyInterface $priceCurrency ) { $this->fileSystem = $fileSystem; $this->directoryList = $directoryList; @@ -107,7 +110,7 @@ public function __construct( $this->timezone = $timezone; $this->templateProcessor = $templateProcessor; - parent::__construct($context, $objectManager, $storeManager); + parent::__construct($context, $objectManager, $storeManager, $priceCurrency); } /** From f2ea588c6c199c1180dfc9c0a9a0848cff1c2be4 Mon Sep 17 00:00:00 2001 From: Ngo Doan Luong Date: Wed, 27 May 2020 11:00:22 +0700 Subject: [PATCH 4/5] move share cart in minicart --- view/frontend/web/js/view/minicart.js | 8 +++----- view/frontend/web/template/minicart.html | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/view/frontend/web/js/view/minicart.js b/view/frontend/web/js/view/minicart.js index ebd9bcc..3b16403 100644 --- a/view/frontend/web/js/view/minicart.js +++ b/view/frontend/web/js/view/minicart.js @@ -21,9 +21,8 @@ define([ 'jquery', 'uiComponent', 'Magento_Customer/js/customer-data', - 'mage/translate', - 'rjsResolver' -], function ($, Component, customerData, $t, resolver) { + 'mage/translate' +], function ($, Component, customerData, $t) { 'use strict'; var isReload = true; @@ -41,10 +40,9 @@ define([ isReload = false; } this.customer = customerData.get('cart'); - resolver(this.afterResolveDocument.bind(this)); }, - afterResolveDocument: function () { + moveShareCart: function(){ $(document).ready(function () { $('.secondary.sharecart').appendTo($('.action.viewcart').parent()); }); diff --git a/view/frontend/web/template/minicart.html b/view/frontend/web/template/minicart.html index 80cb4ba..3312bde 100644 --- a/view/frontend/web/template/minicart.html +++ b/view/frontend/web/template/minicart.html @@ -20,7 +20,7 @@ */ --> -
+
From b33b3fa1e7965f6201979a8b31024b2d457ad9d8 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 27 May 2020 11:16:36 +0700 Subject: [PATCH 5/5] Clean code --- Helper/Data.php | 1 + Helper/PrintProcess.php | 2 +- composer.json | 2 +- view/frontend/layout/default.xml | 102 +++++++-------- view/frontend/web/js/view/minicart.js | 154 +++++++++++------------ view/frontend/web/template/minicart.html | 58 ++++----- 6 files changed, 160 insertions(+), 159 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 5b9feed..0002a76 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -35,6 +35,7 @@ class Data extends AbstractData { const CONFIG_MODULE_PATH = 'sharecart'; const BUSINESS_CONFIG_PATH = 'business_information'; + /** * @var PriceCurrencyInterface */ diff --git a/Helper/PrintProcess.php b/Helper/PrintProcess.php index 443ca23..9529d36 100644 --- a/Helper/PrintProcess.php +++ b/Helper/PrintProcess.php @@ -27,6 +27,7 @@ use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem; use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Framework\Stdlib\DateTime\TimeZone; use Magento\Quote\Model\Quote; @@ -34,7 +35,6 @@ use Mageplaza\ShareCart\Model\Template\Processor; use Mpdf\Mpdf; use Mpdf\MpdfException; -use Magento\Framework\Pricing\PriceCurrencyInterface; /** * Class PrintProcess diff --git a/composer.json b/composer.json index 4f9b926..87907f6 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "mageplaza/module-core": "^1.4.5", "mpdf/mpdf": "^7.1.0" }, - "version": "1.1.0", + "version": "1.1.1", "license": "proprietary", "authors": [ { diff --git a/view/frontend/layout/default.xml b/view/frontend/layout/default.xml index 12a3cfd..157cc19 100644 --- a/view/frontend/layout/default.xml +++ b/view/frontend/layout/default.xml @@ -1,51 +1,51 @@ - - - - - - - - - - - - - - - - - Mageplaza_ShareCart/js/view/minicart - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + Mageplaza_ShareCart/js/view/minicart + + + + + + + + + + + + + + diff --git a/view/frontend/web/js/view/minicart.js b/view/frontend/web/js/view/minicart.js index 3b16403..36dedce 100644 --- a/view/frontend/web/js/view/minicart.js +++ b/view/frontend/web/js/view/minicart.js @@ -1,77 +1,77 @@ -/** - * Mageplaza - * - * NOTICE OF LICENSE - * - * This source file is subject to the Mageplaza.com license that is - * available through the world-wide-web at this URL: - * https://www.mageplaza.com/LICENSE.txt - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this extension to newer - * version in the future. - * - * @category Mageplaza - * @package Mageplaza_ShareCart - * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) - * @license https://www.mageplaza.com/LICENSE.txt - */ -define([ - 'jquery', - 'uiComponent', - 'Magento_Customer/js/customer-data', - 'mage/translate' -], function ($, Component, customerData, $t) { - 'use strict'; - - var isReload = true; - - return Component.extend({ - defaults: { - template: 'Mageplaza_ShareCart/minicart' - }, - - initialize: function () { - this._super(); - - if (isReload) { - customerData.reload(['cart'], false); - isReload = false; - } - this.customer = customerData.get('cart'); - }, - - moveShareCart: function(){ - $(document).ready(function () { - $('.secondary.sharecart').appendTo($('.action.viewcart').parent()); - }); - }, - - getQuoteId: function () { - return customerData.get('cart')().quote_url; - }, - - copyQuote: function (object, e) { - var quoteUrl = document.createElement('textarea'); - - quoteUrl.value = customerData.get('cart')().quote_url; - document.body.appendChild(quoteUrl); - quoteUrl.select(); - document.execCommand('copy'); - document.body.removeChild(quoteUrl); - - e.currentTarget.setAttribute('class', 'mp-tooltipped'); - e.currentTarget.setAttribute('aria-label', $t('Copied!')); - }, - - leaveQuote: function (object, e) { - e.currentTarget.removeAttribute('class'); - e.currentTarget.removeAttribute('aria-label'); - }, - - isDisplay: function () { - return customerData.get('cart')().summary_count; - } - }); -}); +/** + * Mageplaza + * + * NOTICE OF LICENSE + * + * This source file is subject to the Mageplaza.com license that is + * available through the world-wide-web at this URL: + * https://www.mageplaza.com/LICENSE.txt + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this extension to newer + * version in the future. + * + * @category Mageplaza + * @package Mageplaza_ShareCart + * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) + * @license https://www.mageplaza.com/LICENSE.txt + */ +define([ + 'jquery', + 'uiComponent', + 'Magento_Customer/js/customer-data', + 'mage/translate' +], function ($, Component, customerData, $t) { + 'use strict'; + + var isReload = true; + + return Component.extend({ + defaults: { + template: 'Mageplaza_ShareCart/minicart' + }, + + initialize: function () { + this._super(); + + if (isReload) { + customerData.reload(['cart'], false); + isReload = false; + } + this.customer = customerData.get('cart'); + }, + + moveShareCart: function(){ + $(document).ready(function () { + $('.secondary.sharecart').appendTo($('.action.viewcart').parent()); + }); + }, + + getQuoteId: function () { + return customerData.get('cart')().quote_url; + }, + + copyQuote: function (object, e) { + var quoteUrl = document.createElement('textarea'); + + quoteUrl.value = customerData.get('cart')().quote_url; + document.body.appendChild(quoteUrl); + quoteUrl.select(); + document.execCommand('copy'); + document.body.removeChild(quoteUrl); + + e.currentTarget.setAttribute('class', 'mp-tooltipped'); + e.currentTarget.setAttribute('aria-label', $t('Copied!')); + }, + + leaveQuote: function (object, e) { + e.currentTarget.removeAttribute('class'); + e.currentTarget.removeAttribute('aria-label'); + }, + + isDisplay: function () { + return customerData.get('cart')().summary_count; + } + }); +}); diff --git a/view/frontend/web/template/minicart.html b/view/frontend/web/template/minicart.html index 3312bde..c7d69e3 100644 --- a/view/frontend/web/template/minicart.html +++ b/view/frontend/web/template/minicart.html @@ -1,29 +1,29 @@ - - - - + + +
+ + + +
+