From 8901400c0e64d0b86993a9bd266824260952a19e Mon Sep 17 00:00:00 2001 From: Luong Date: Thu, 18 Oct 2018 13:27:10 +0700 Subject: [PATCH 01/14] button share cart --- Controller/Index/Index.php | 99 ++++++++++++++++++++++++ Helper/Data.php | 32 ++++++++ Plugin/CustomerData/Cart.php | 74 ++++++++++++++++++ etc/acl.xml | 37 +++++++++ etc/adminhtml/routes.xml | 29 +++++++ etc/adminhtml/system.xml | 39 ++++++++++ etc/config.xml | 31 ++++++++ etc/frontend/di.xml | 27 +++++++ etc/frontend/routes.xml | 29 +++++++ view/frontend/layout/default.xml | 48 ++++++++++++ view/frontend/web/js/view/minicart.js | 42 ++++++++++ view/frontend/web/template/minicart.html | 32 ++++++++ 12 files changed, 519 insertions(+) create mode 100644 Controller/Index/Index.php create mode 100644 Helper/Data.php create mode 100644 Plugin/CustomerData/Cart.php create mode 100644 etc/acl.xml create mode 100644 etc/adminhtml/routes.xml create mode 100644 etc/adminhtml/system.xml create mode 100644 etc/config.xml create mode 100644 etc/frontend/di.xml create mode 100644 etc/frontend/routes.xml create mode 100644 view/frontend/layout/default.xml create mode 100644 view/frontend/web/js/view/minicart.js create mode 100644 view/frontend/web/template/minicart.html diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php new file mode 100644 index 0000000..5390554 --- /dev/null +++ b/Controller/Index/Index.php @@ -0,0 +1,99 @@ +_pageFactory = $pageFactory; + $this->cartRepository = $cartRepository; + $this->cart = $cart; + $this->_productRepository = $productRepository; + return parent::__construct($context); + } + + public function execute() + { + $quoteId = base64_decode($this->getRequest()->getParam('quote_id'), true); + $quote = $this->cartRepository->get($quoteId); + + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $items = $quote->getItemsCollection(); + + foreach ($items as $item) { + if (!$item->getParentItemId()) { + $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct()); + $info = $options['info_buyRequest']; + if($item->getProductType() == 'configurable') { + $product = $this->_productRepository->get($item->getSku()); + $this->cart->addProduct($product, $info); + }else if($item->getProductType() == 'bundle'){ + $this->cart->addProduct($item->getProduct(), $info); + }else{ + $this->cart->addProduct($item->getProduct(), $item->getQty()); + } + } + + } + $this->cart->save(); + + return $resultRedirect->setPath('checkout/cart'); + } +} \ No newline at end of file diff --git a/Helper/Data.php b/Helper/Data.php new file mode 100644 index 0000000..f64d632 --- /dev/null +++ b/Helper/Data.php @@ -0,0 +1,32 @@ +checkoutSession =$checkoutSession; + $this->helperData = $helperData; + $this->_urlBuilder = $urlBuilder; + } + + /** + * Add Url data to result + * + * @param \Magento\Checkout\CustomerData\Cart $subject + * @param $result + * @return mixed + */ + public function afterGetSectionData(\Magento\Checkout\CustomerData\Cart $subject, $result) + { + if (null === $this->quoteId) { + $this->quoteId = $this->checkoutSession->getQuote()->getId(); + } + $result['quote_url'] = $this->_urlBuilder->getUrl('sharecart/index/index',['quote_id'=> base64_encode($this->quoteId)]); + return $result; + } +} diff --git a/etc/acl.xml b/etc/acl.xml new file mode 100644 index 0000000..723130b --- /dev/null +++ b/etc/acl.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/etc/adminhtml/routes.xml b/etc/adminhtml/routes.xml new file mode 100644 index 0000000..b58378f --- /dev/null +++ b/etc/adminhtml/routes.xml @@ -0,0 +1,29 @@ + + + + + + + + + \ No newline at end of file diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml new file mode 100644 index 0000000..0aeb861 --- /dev/null +++ b/etc/adminhtml/system.xml @@ -0,0 +1,39 @@ + + + + +
+ + mageplaza + Mageplaza_ShareCart::configuration + + + + + Yes to enable the module.]]> + Magento\Config\Model\Config\Source\Yesno + + +
+
+
diff --git a/etc/config.xml b/etc/config.xml new file mode 100644 index 0000000..95771d6 --- /dev/null +++ b/etc/config.xml @@ -0,0 +1,31 @@ + + + + + + + 1 + + + + \ No newline at end of file diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml new file mode 100644 index 0000000..4e53bf3 --- /dev/null +++ b/etc/frontend/di.xml @@ -0,0 +1,27 @@ + + + + + + + diff --git a/etc/frontend/routes.xml b/etc/frontend/routes.xml new file mode 100644 index 0000000..5d838a0 --- /dev/null +++ b/etc/frontend/routes.xml @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/view/frontend/layout/default.xml b/view/frontend/layout/default.xml new file mode 100644 index 0000000..1b7fb9a --- /dev/null +++ b/view/frontend/layout/default.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + Mageplaza_ShareCart/js/view/minicart + + + + + + + + + + + + + + diff --git a/view/frontend/web/js/view/minicart.js b/view/frontend/web/js/view/minicart.js new file mode 100644 index 0000000..0c091ce --- /dev/null +++ b/view/frontend/web/js/view/minicart.js @@ -0,0 +1,42 @@ +/** + * 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([ + 'uiComponent', + 'Magento_Customer/js/customer-data' +], function (Component,customerData) { + 'use strict'; + + return Component.extend({ + defaults: { + template: 'Mageplaza_ShareCart/minicart' + }, + + getQuoteId: function (){ + return customerData.get('cart')().quote_url; + }, + + copyQuote: function(){ + var quoteId=document.getElementById("mpQuote"); + quoteId.select(); + document.execCommand("copy") + + }, + }); +}); diff --git a/view/frontend/web/template/minicart.html b/view/frontend/web/template/minicart.html new file mode 100644 index 0000000..2679e04 --- /dev/null +++ b/view/frontend/web/template/minicart.html @@ -0,0 +1,32 @@ + + + + + + + + + + +getItems() as $item): ?> + getProductType() == 'configurable'):?> +
  • getQty().'X'.$block->getNameConfigurable($item).'-'.$item->getBasePriceInclTax().$block->getCurrentCurrencySymbol() ?>
  • + + + getParentItemId() && $block->checkConfigurableProduct($item)):?> + + + getProductType() != 'configurable'):?> +
  • getQty().'X'.$item->getName().'-'.$item->getBasePriceInclTax().$block->getCurrentCurrencySymbol() ?>
  • + + + testBlock() ?> + + diff --git a/view/frontend/web/js/view/minicart.js b/view/frontend/web/js/view/minicart.js index 8559508..65c530a 100644 --- a/view/frontend/web/js/view/minicart.js +++ b/view/frontend/web/js/view/minicart.js @@ -29,19 +29,16 @@ define([ }, getQuoteId: function (){ - return customerData.get('cart')().quote_url; }, copyQuote: function(){ - var quoteId=document.getElementById("mpQuote"); - - /* Select the text field */ - quoteId.select(); - - /* Copy the text inside the text field */ - document.execCommand("copy") - console.log('copied'); + const quoteUrl = document.createElement('textarea'); + quoteUrl.value = customerData.get('cart')().quote_url; + document.body.appendChild(quoteUrl); + quoteUrl.select(); + document.execCommand('copy'); + document.body.removeChild(quoteUrl); }, isDisplay: function(){ diff --git a/view/frontend/web/template/minicart.html b/view/frontend/web/template/minicart.html index bea7091..298368e 100644 --- a/view/frontend/web/template/minicart.html +++ b/view/frontend/web/template/minicart.html @@ -33,12 +33,8 @@ /> - \ No newline at end of file diff --git a/view/frontend/layout/checkout_cart_index.xml b/view/frontend/layout/checkout_cart_index.xml index cb65ddc..f0005ff 100644 --- a/view/frontend/layout/checkout_cart_index.xml +++ b/view/frontend/layout/checkout_cart_index.xml @@ -15,7 +15,7 @@ * version in the future. * * @category Mageplaza - * @package ShareCart + * @package Mageplaza_ShareCart * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ diff --git a/view/frontend/layout/default.xml b/view/frontend/layout/default.xml index c20c5dd..b64716f 100644 --- a/view/frontend/layout/default.xml +++ b/view/frontend/layout/default.xml @@ -21,6 +21,9 @@ */ --> + + + diff --git a/view/frontend/layout/sharecart_index_download.xml b/view/frontend/layout/sharecart_index_download.xml new file mode 100644 index 0000000..14cfafe --- /dev/null +++ b/view/frontend/layout/sharecart_index_download.xml @@ -0,0 +1,27 @@ + + + + + + + diff --git a/view/frontend/templates/cart/button.phtml b/view/frontend/templates/cart/button.phtml index 1dd9e66..d28cd09 100644 --- a/view/frontend/templates/cart/button.phtml +++ b/view/frontend/templates/cart/button.phtml @@ -1,5 +1,27 @@ + + helper('Mageplaza\ShareCart\Helper\Data')->isEnabled()):?> -
    +
    - @@ -21,39 +45,27 @@ class="download cart"> - -getItems() as $item): ?> - getProductType() == 'configurable'):?> -
  • getQty().'X'.$block->getNameConfigurable($item).'-'.$item->getBasePriceInclTax().$block->getCurrentCurrencySymbol() ?>
  • - - - getParentItemId() && $block->checkConfigurableProduct($item)):?> - - - getProductType() != 'configurable'):?> -
  • getQty().'X'.$item->getName().'-'.$item->getBasePriceInclTax().$block->getCurrentCurrencySymbol() ?>
  • - - - testBlock() ?> - + } + ); + + diff --git a/view/frontend/templates/cart/items.phtml b/view/frontend/templates/cart/items.phtml index 203cf35..02e37ad 100644 --- a/view/frontend/templates/cart/items.phtml +++ b/view/frontend/templates/cart/items.phtml @@ -19,7 +19,6 @@ * @license https://www.mageplaza.com/LICENSE.txt */ - ?> @@ -30,33 +29,33 @@ getItems() as $item): ?> - getProductType() == 'configurable'):?> - - - - - - - - - getParentItemId() && $block->checkConfigurableProduct($item)):?> + getProductType() == 'configurable'): ?> + + + + + + + + + getParentItemId() && $block->checkConfigurableProduct($item)): ?> - getProductType() != 'configurable'):?> + getProductType() != 'configurable'): ?> - - + + - - + + - + - +
    getQty()?>getSku()?>getNameConfigurable($item) ?>getCurrentCurrencySymbol().$item->getBasePriceInclTax() ?>getCurrentCurrencySymbol().$item->getBaseRowTotalInclTax() ?>
    getQty() ?>getSku() ?>getNameConfigurable($item) ?>getCurrentCurrencySymbol() . $item->getBasePriceInclTax() ?>getCurrentCurrencySymbol() . $item->getBaseRowTotalInclTax() ?>
    getQty()?>getSku()?>getQty() ?>getSku() ?> getName() ?>getCurrentCurrencySymbol().$item->getBasePriceInclTax() ?>getCurrentCurrencySymbol().$item->getBaseRowTotalInclTax() ?>getCurrentCurrencySymbol() . $item->getBasePriceInclTax() ?>getCurrentCurrencySymbol() . $item->getBaseRowTotalInclTax() ?>
    getCurrentCurrencySymbol().$block->getBaseSubtotal() ?>getCurrentCurrencySymbol() . $block->getBaseSubtotal() ?>
    \ No newline at end of file diff --git a/view/frontend/web/css/style.css b/view/frontend/web/css/style.css index 6f24324..720c04b 100644 --- a/view/frontend/web/css/style.css +++ b/view/frontend/web/css/style.css @@ -17,7 +17,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ -.actions .primary.sharecart{ +.actions .primary.sharecart { margin: 0 10px 15px; } @@ -27,7 +27,7 @@ button.action.primary.sharecart { line-height: 2.2rem; padding: 14px 17px; font-size: 1.8rem; - margin:unset; + margin: unset; } .mp-sharecart-popup .modal-inner-wrap { @@ -35,9 +35,9 @@ button.action.primary.sharecart { } .mp-popup-cart { - display:none; + display: none; } -#mp_show_download_share{ - display:inline-block; +#mp_show_download_share { + display: inline-block; } \ No newline at end of file diff --git a/view/frontend/web/js/view/minicart.js b/view/frontend/web/js/view/minicart.js index d9bd1c8..a64026e 100644 --- a/view/frontend/web/js/view/minicart.js +++ b/view/frontend/web/js/view/minicart.js @@ -3,7 +3,7 @@ * * NOTICE OF LICENSE * - * This source file is subject to the mageplaza.com license that is + * 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 * @@ -20,10 +20,10 @@ define([ 'uiComponent', 'Magento_Customer/js/customer-data' -], function (Component,customerData) { +], function (Component, customerData) { 'use strict'; - var isReload =true; + var isReload = true; return Component.extend({ defaults: { template: 'Mageplaza_ShareCart/minicart' @@ -39,12 +39,11 @@ define([ this.customer = customerData.get('cart'); }, - - getQuoteId: function (){ + getQuoteId: function () { return customerData.get('cart')().quote_url; }, - copyQuote: function(){ + copyQuote: function () { const quoteUrl = document.createElement('textarea'); quoteUrl.value = customerData.get('cart')().quote_url; document.body.appendChild(quoteUrl); @@ -53,7 +52,7 @@ define([ document.body.removeChild(quoteUrl); }, - isDisplay: function(){ + 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 e4bd219..9d805e9 100644 --- a/view/frontend/web/template/minicart.html +++ b/view/frontend/web/template/minicart.html @@ -15,7 +15,7 @@ * * @category Mageplaza * @package Mageplaza_ShareCart - * @copyright Copyright (c) 2018 Mageplaza (http://www.mageplaza.com/) + * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ --> @@ -24,11 +24,7 @@
    From cfffc61789a2bb69017870febd76194d10e55f67 Mon Sep 17 00:00:00 2001 From: haitv282 Date: Wed, 31 Oct 2018 15:40:25 +0700 Subject: [PATCH 10/14] Improve code quality & fixed bug still show button on empty cart --- Block/Cart/Button.php | 145 ++++++------------ Block/Cart/Items.php | 104 ------------- CHANGELOG | 2 +- Controller/Index/Download.php | 23 +-- Controller/Index/Index.php | 8 +- Helper/PrintProcess.php | 27 ---- Plugin/CustomerData/Cart.php | 4 +- composer.json | 1 + etc/adminhtml/system.xml | 48 +++--- .../layout/sharecart_index_download.xml | 2 +- view/frontend/templates/cart/button.phtml | 91 +++++++---- view/frontend/templates/cart/items.phtml | 10 +- view/frontend/web/css/style.css | 59 +++++++ view/frontend/web/js/view/minicart.js | 16 +- view/frontend/web/template/minicart.html | 10 +- 15 files changed, 215 insertions(+), 335 deletions(-) diff --git a/Block/Cart/Button.php b/Block/Cart/Button.php index 9ba1708..a5867a4 100644 --- a/Block/Cart/Button.php +++ b/Block/Cart/Button.php @@ -25,11 +25,11 @@ use Magento\Checkout\Model\Session; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; use Magento\Directory\Model\Currency; +use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Framework\UrlInterface; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; -use Magento\Quote\Api\CartRepositoryInterface; -use Magento\Store\Model\StoreManagerInterface; +use Magento\Quote\Model\Quote; /** * Class Button @@ -37,21 +37,11 @@ */ class Button extends Template { - /** - * @var CartRepositoryInterface - */ - protected $cartRepository; - /** * @var \Magento\Customer\Model\Session */ protected $checkoutSession; - /** - * @var StoreManagerInterface - */ - protected $_storeManager; - /** * @var Currency */ @@ -72,99 +62,47 @@ class Button extends Template */ protected $_urlBuilder; + /** + * @var PriceCurrencyInterface + */ + protected $priceCurrency; + + /** + * @var Quote + */ + protected $_quote; + /** * Button constructor. * @param Context $context - * @param CartRepositoryInterface $cartRepository * @param Session $checkoutSession - * @param StoreManagerInterface $storeManager * @param Currency $currency * @param ProductRepository $productRepository * @param Configurable $configurable * @param UrlInterface $urlBuilder + * @param PriceCurrencyInterface $priceCurrency * @param array $data */ public function __construct( Context $context, - CartRepositoryInterface $cartRepository, Session $checkoutSession, - StoreManagerInterface $storeManager, Currency $currency, ProductRepository $productRepository, Configurable $configurable, UrlInterface $urlBuilder, + PriceCurrencyInterface $priceCurrency, array $data = []) { - $this->_storeManager = $storeManager; $this->_currency = $currency; - $this->cartRepository = $cartRepository; $this->checkoutSession = $checkoutSession; $this->_productRepository = $productRepository; $this->configurable = $configurable; $this->_urlBuilder = $urlBuilder; + $this->priceCurrency = $priceCurrency; parent::__construct($context, $data); } - /** - * Get store base currency code - * - * @return string - */ - public function getBaseCurrencyCode() - { - return $this->_storeManager->getStore()->getBaseCurrencyCode(); - } - - /** - * Get current store currency code - * - * @return string - */ - public function getCurrentCurrencyCode() - { - return $this->_storeManager->getStore()->getCurrentCurrencyCode(); - } - - /** - * Get default store currency code - * - * @return string - */ - public function getDefaultCurrencyCode() - { - return $this->_storeManager->getStore()->getDefaultCurrencyCode(); - } - - /** - * @param bool $skipBaseNotAllowed - * @return mixed - */ - public function getAvailableCurrencyCodes($skipBaseNotAllowed = false) - { - return $this->_storeManager->getStore()->getAvailableCurrencyCodes($skipBaseNotAllowed); - } - - /** - * Get array of installed currencies for the scope - * - * @return array - */ - public function getAllowedCurrencies() - { - return $this->_storeManager->getStore()->getAllowedCurrencies(); - } - - /** - * Get current currency rate - * - * @return float - */ - public function getCurrentCurrencyRate() - { - return $this->_storeManager->getStore()->getCurrentCurrencyRate(); - } - /** * Get currency symbol for current locale and currency code * @@ -185,18 +123,11 @@ public function getItems() /** * @param $item - * @return null|string - * @throws \Magento\Framework\Exception\NoSuchEntityException + * @return array */ - public function getItemName($item) + public function checkConfigurableProduct($item) { - if ($item->getHasChildren()) { - $product = $this->_productRepository->get($item->getSku()); - - return $product->getName(); - } else { - return $item->getName(); - } + return $this->configurable->getParentIdsByChild($item->getProductId()); } /** @@ -204,36 +135,48 @@ public function getItemName($item) * @return null|string * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function getParentProductType($item) + public function getNameConfigurable($item) { - return $this->_productRepository->get($item->getSku())->getTypeId(); + return $this->_productRepository->get($item->getSku())->getName(); } /** - * @param $item - * @return array + * @param $price + * @return float */ - public function checkConfigurableProduct($item) + public function formatPrice($price) { - return $this->configurable->getParentIdsByChild($item->getProductId()); + return $this->priceCurrency->format($price, false); } /** - * @param $item - * @return null|string - * @throws \Magento\Framework\Exception\NoSuchEntityException + * @return float */ - public function getNameConfigurable($item) + public function getBaseSubtotal() { - return $this->_productRepository->get($item->getSku())->getName(); + return $this->formatPrice($this->checkoutSession->getQuote()->getBaseSubtotal()); } /** - * @return float + * @codeCoverageIgnore + * @return int */ - public function getBaseSubtotal() + public function getItemsCount() + { + return $this->getQuote()->getItemsCount(); + } + + /** + * Get active quote + * + * @return Quote + */ + public function getQuote() { - return $this->checkoutSession->getQuote()->getBaseSubtotal(); + if (null === $this->_quote) { + $this->_quote = $this->checkoutSession->getQuote(); + } + return $this->_quote; } /** diff --git a/Block/Cart/Items.php b/Block/Cart/Items.php index 1acfb70..fbad25d 100644 --- a/Block/Cart/Items.php +++ b/Block/Cart/Items.php @@ -36,19 +36,11 @@ */ class Items extends Template { - /** @var $cartepository */ - protected $cartRepository; - /** * @var \Magento\Customer\Model\Session */ protected $checkoutSession; - /** - * @var StoreManagerInterface - */ - protected $_storeManager; - /** * @var Currency */ @@ -67,9 +59,7 @@ class Items extends Template /** * Items constructor. * @param Context $context - * @param CartRepositoryInterface $cartRepository * @param Session $checkoutSession - * @param StoreManagerInterface $storeManager * @param Currency $currency * @param ProductRepository $productRepository * @param Configurable $configurable @@ -77,17 +67,13 @@ class Items extends Template */ public function __construct( Context $context, - CartRepositoryInterface $cartRepository, Session $checkoutSession, - StoreManagerInterface $storeManager, Currency $currency, ProductRepository $productRepository, Configurable $configurable, array $data = []) { - $this->_storeManager = $storeManager; $this->_currency = $currency; - $this->cartRepository = $cartRepository; $this->checkoutSession = $checkoutSession; $this->_productRepository = $productRepository; $this->configurable = $configurable; @@ -95,70 +81,6 @@ public function __construct( parent::__construct($context, $data); } - /** - * Get store base currency code - * - * @return string - */ - public function getBaseCurrencyCode() - { - return $this->_storeManager->getStore()->getBaseCurrencyCode(); - } - - /** - * Get current store currency code - * - * @return string - */ - public function getCurrentCurrencyCode() - { - return $this->_storeManager->getStore()->getCurrentCurrencyCode(); - } - - /** - * Get default store currency code - * - * @return string - */ - public function getDefaultCurrencyCode() - { - return $this->_storeManager->getStore()->getDefaultCurrencyCode(); - } - - /** - * Get allowed store currency codes - * - * If base currency is not allowed in current website config scope, - * then it can be disabled with $skipBaseNotAllowed - * - * @param bool $skipBaseNotAllowed - * @return array - */ - public function getAvailableCurrencyCodes($skipBaseNotAllowed = false) - { - return $this->_storeManager->getStore()->getAvailableCurrencyCodes($skipBaseNotAllowed); - } - - /** - * Get array of installed currencies for the scope - * - * @return array - */ - public function getAllowedCurrencies() - { - return $this->_storeManager->getStore()->getAllowedCurrencies(); - } - - /** - * Get current currency rate - * - * @return float - */ - public function getCurrentCurrencyRate() - { - return $this->_storeManager->getStore()->getCurrentCurrencyRate(); - } - /** * Get currency symbol for current locale and currency code * @@ -177,32 +99,6 @@ public function getItems() return $this->checkoutSession->getQuote()->getItemsCollection(); } - /** - * @param $item - * @return null|string - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - public function getItemName($item) - { - if ($item->getHasChildren()) { - $product = $this->_productRepository->get($item->getSku()); - - return $product->getName(); - } else { - return $item->getName(); - } - } - - /** - * @param $item - * @return null|string - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - public function getParentProductType($item) - { - return $this->_productRepository->get($item->getSku())->getTypeId(); - } - /** * @param $item * @return array diff --git a/CHANGELOG b/CHANGELOG index 8913233..c28e1e9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1 +1 @@ -CHANGELOG: https://www.mageplaza.com/releases/share-cart.txt \ No newline at end of file +CHANGELOG: https://www.mageplaza.com/releases/share-cart/ \ No newline at end of file diff --git a/Controller/Index/Download.php b/Controller/Index/Download.php index 0cfc365..47deadd 100644 --- a/Controller/Index/Download.php +++ b/Controller/Index/Download.php @@ -25,8 +25,6 @@ use Magento\Checkout\Model\Session; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; -use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Store\Model\StoreManagerInterface; use Mageplaza\ShareCart\Helper\PrintProcess; use Mageplaza\ShareCart\Model\Template\Processor; use Mpdf\Mpdf; @@ -47,21 +45,6 @@ class Download extends Action */ protected $checkoutSession; - /** - * @var Data - */ - protected $helper; - - /** - * @var StoreManagerInterface - */ - protected $storeManager; - - /** - * @var DirectoryList - */ - protected $directoryList; - /** * @var PrintProcess */ @@ -71,19 +54,17 @@ class Download extends Action * Download constructor. * @param Context $context * @param Session $checkoutSession - * @param StoreManagerInterface $storeManager * @param Processor $templateProcessor * @param PrintProcess $printProcess */ public function __construct( Context $context, Session $checkoutSession, - StoreManagerInterface $storeManager, Processor $templateProcessor, - PrintProcess $printProcess) + PrintProcess $printProcess + ) { $this->checkoutSession = $checkoutSession; - $this->storeManager = $storeManager; $this->templateProcessor = $templateProcessor; $this->printProcess = $printProcess; diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php index a4bc705..cd80471 100644 --- a/Controller/Index/Index.php +++ b/Controller/Index/Index.php @@ -48,11 +48,6 @@ class Index extends Action */ protected $cartRepository; - /** - * @var PageFactory - */ - protected $_pageFactory; - /** * @var Cart */ @@ -88,7 +83,6 @@ public function __construct( Data $helper ) { - $this->_pageFactory = $pageFactory; $this->cartRepository = $cartRepository; $this->cart = $cart; $this->_productRepository = $productRepository; @@ -108,7 +102,7 @@ public function execute() /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($this->helper->isEnabled()) { - $quoteId = base64_decode($this->getRequest()->getParam('quote_id'), true); + $quoteId = base64_decode($this->getRequest()->getParam('key'), true); if ($quoteId) { $quote = $this->cartRepository->get($quoteId); diff --git a/Helper/PrintProcess.php b/Helper/PrintProcess.php index 0770079..f45d012 100644 --- a/Helper/PrintProcess.php +++ b/Helper/PrintProcess.php @@ -54,11 +54,6 @@ class PrintProcess extends AbstractData */ protected $directoryList; - /** - * @var HelperData - */ - protected $helperData; - /** * @var \Magento\Framework\Filesystem */ @@ -69,11 +64,6 @@ class PrintProcess extends AbstractData */ protected $templateVars; - /** - * @var \Magento\Framework\App\State - */ - protected $state; - /** * @var Data */ @@ -92,7 +82,6 @@ class PrintProcess extends AbstractData /** * PrintProcess constructor. * @param Context $context - * @param State $state * @param Filesystem $fileSystem * @param DirectoryList $directoryList * @param StoreManagerInterface $storeManager @@ -104,7 +93,6 @@ class PrintProcess extends AbstractData */ public function __construct( Context $context, - State $state, Filesystem $fileSystem, DirectoryList $directoryList, StoreManagerInterface $storeManager, @@ -116,7 +104,6 @@ public function __construct( ) { $this->checkoutSession = $checkoutSession; - $this->state = $state; $this->fileSystem = $fileSystem; $this->directoryList = $directoryList; $this->helper = $helper; @@ -138,20 +125,6 @@ public function readFile($relativePath) return $rootDirectory->readFile($relativePath); } - /** - * @param $storeId - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function checkStoreId($storeId) - { - if ($this->state->getAreaCode() == Area::AREA_FRONTEND) { - $storeId = $this->storeManager->getStore()->getId(); - } - - return $storeId; - } - /** * @param $storeId * @return mixed diff --git a/Plugin/CustomerData/Cart.php b/Plugin/CustomerData/Cart.php index 99a3460..3fb5e06 100644 --- a/Plugin/CustomerData/Cart.php +++ b/Plugin/CustomerData/Cart.php @@ -27,7 +27,7 @@ /** * Class Cart - * @package Mageplaza\RewardPoints\Plugin\CustomerData + * @package Mageplaza\ShareCart\Plugin\CustomerData */ class Cart { @@ -82,7 +82,7 @@ public function afterGetSectionData(\Magento\Checkout\CustomerData\Cart $subject if (null === $this->quoteId) { $this->quoteId = $this->checkoutSession->getQuoteId(); } - $result['quote_url'] = $this->_urlBuilder->getUrl('sharecart/index/index', ['quote_id' => base64_encode($this->quoteId)]); + $result['quote_url'] = $this->_urlBuilder->getUrl('sharecart', ['key' => base64_encode($this->quoteId)]); return $result; } diff --git a/composer.json b/composer.json index d276a7d..4ebd47d 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "mageplaza/module-share-cart", "description": "Magento 2 Share Cart extension", "type": "magento2-module", + "version": "1.0.0", "license": "proprietary", "authors": [ { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index a9f2859..17b395a 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -33,30 +33,30 @@ Magento\Config\Model\Config\Source\Yesno Yes to enable the module.]]> - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/view/frontend/layout/sharecart_index_download.xml b/view/frontend/layout/sharecart_index_download.xml index f68b496..5cdacdf 100644 --- a/view/frontend/layout/sharecart_index_download.xml +++ b/view/frontend/layout/sharecart_index_download.xml @@ -22,6 +22,6 @@ --> - + diff --git a/view/frontend/templates/cart/button.phtml b/view/frontend/templates/cart/button.phtml index 8683a4c..ed5e974 100644 --- a/view/frontend/templates/cart/button.phtml +++ b/view/frontend/templates/cart/button.phtml @@ -20,15 +20,14 @@ */ ?> -helper('Mageplaza\ShareCart\Helper\Data')->isEnabled()): ?> -
    +helper('Mageplaza\ShareCart\Helper\Data')->isEnabled() && $block->getItemsCount()): ?> + + diff --git a/view/frontend/templates/cart/items.phtml b/view/frontend/templates/cart/items.phtml index 02e37ad..6432e5f 100644 --- a/view/frontend/templates/cart/items.phtml +++ b/view/frontend/templates/cart/items.phtml @@ -34,8 +34,8 @@ getQty() ?> getSku() ?> getNameConfigurable($item) ?> - getCurrentCurrencySymbol() . $item->getBasePriceInclTax() ?> - getCurrentCurrencySymbol() . $item->getBaseRowTotalInclTax() ?> + formatPrice($item->getBasePriceInclTax()) ?> + formatPrice($item->getBaseRowTotalInclTax()) ?> getParentItemId() && $block->checkConfigurableProduct($item)): ?> @@ -46,8 +46,8 @@ getQty() ?> getSku() ?> getName() ?> - getCurrentCurrencySymbol() . $item->getBasePriceInclTax() ?> - getCurrentCurrencySymbol() . $item->getBaseRowTotalInclTax() ?> + formatPrice($item->getBasePriceInclTax()) ?> + formatPrice($item->getBaseRowTotalInclTax()) ?> @@ -56,6 +56,6 @@ - getCurrentCurrencySymbol() . $block->getBaseSubtotal() ?> + getBaseSubtotal() ?> \ No newline at end of file diff --git a/view/frontend/web/css/style.css b/view/frontend/web/css/style.css index 720c04b..46997a8 100644 --- a/view/frontend/web/css/style.css +++ b/view/frontend/web/css/style.css @@ -30,6 +30,11 @@ button.action.primary.sharecart { margin: unset; } +.mp-sharecart-popup .modal-title { + border: none; + padding-bottom: 25px; +} + .mp-sharecart-popup .modal-inner-wrap { width: 600px; } @@ -40,4 +45,58 @@ button.action.primary.sharecart { #mp_show_download_share { display: inline-block; +} + +.mp-tooltipped { + position: relative; +} + +.mp-tooltipped:before { + position: absolute; + z-index: 1000001; + display: none; + width: 0; + height: 0; + color: rgba(0, 0, 0, .8); + pointer-events: none; + content: ""; + border: 5px solid transparent; + top: auto; + right: 50%; + bottom: -5px; + margin-right: -5px; + border-bottom-color: rgba(0, 0, 0, .8) +} + +.mp-tooltipped:after { + position: absolute; + z-index: 1000000; + display: none; + padding: 5px 8px; + font: normal normal 11px/1.5 Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol"; + color: #fff; + text-align: center; + text-decoration: none; + text-shadow: none; + text-transform: none; + letter-spacing: normal; + word-wrap: break-word; + white-space: pre; + pointer-events: none; + content: attr(aria-label); + background: rgba(0, 0, 0, .8); + border-radius: 3px; + -webkit-font-smoothing: subpixel-antialiased; + top: 100%; + right: 50%; + margin-top: 5px; + -webkit-transform: translateX(50%); + -ms-transform: translateX(50%); + transform: translateX(50%) +} + +.mp-tooltipped:hover:before, .mp-tooltipped:active:before, .mp-tooltipped:focus:before, +.mp-tooltipped:hover:after, .mp-tooltipped:active:after, .mp-tooltipped:focus:after { + display: inline-block; + text-decoration: none } \ No newline at end of file diff --git a/view/frontend/web/js/view/minicart.js b/view/frontend/web/js/view/minicart.js index a64026e..992fc80 100644 --- a/view/frontend/web/js/view/minicart.js +++ b/view/frontend/web/js/view/minicart.js @@ -18,9 +18,11 @@ * @license https://www.mageplaza.com/LICENSE.txt */ define([ + 'jquery', 'uiComponent', - 'Magento_Customer/js/customer-data' -], function (Component, customerData) { + 'Magento_Customer/js/customer-data', + 'mage/translate' +], function ($, Component, customerData, $t) { 'use strict'; var isReload = true; @@ -43,13 +45,21 @@ define([ return customerData.get('cart')().quote_url; }, - copyQuote: function () { + copyQuote: function (object, e) { const 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 () { diff --git a/view/frontend/web/template/minicart.html b/view/frontend/web/template/minicart.html index 9d805e9..4d58cdb 100644 --- a/view/frontend/web/template/minicart.html +++ b/view/frontend/web/template/minicart.html @@ -21,12 +21,10 @@ -->
    -
    -
    From 24ab169011406c8fb8b55fdd7f7abc422b142e5d Mon Sep 17 00:00:00 2001 From: haitv282 Date: Wed, 31 Oct 2018 16:15:44 +0700 Subject: [PATCH 11/14] Add tmpDir to solve error file permission --- Controller/Index/Download.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Controller/Index/Download.php b/Controller/Index/Download.php index 47deadd..6cf935b 100644 --- a/Controller/Index/Download.php +++ b/Controller/Index/Download.php @@ -74,11 +74,12 @@ public function __construct( /** * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void * @throws \Magento\Framework\Exception\FileSystemException + * @throws \Mpdf\MpdfException */ public function execute() { $html = $this->printProcess->readFile($this->printProcess->getBaseTemplatePath() . 'template.html'); - $mpdf = new Mpdf(); + $mpdf = new Mpdf(['tempDir' => BP . '/var/tmp']); $storeId = $this->checkoutSession->getQuote()->getStoreId(); $processor = $this->templateProcessor->setVariable( From a30dc25f6cc2d0c9348041fa10d1876d7abfcc58 Mon Sep 17 00:00:00 2001 From: haitv282 Date: Wed, 31 Oct 2018 16:30:02 +0700 Subject: [PATCH 12/14] Admin can change file name --- Controller/Index/Download.php | 2 +- Helper/PrintProcess.php | 23 ++++++++++++++--------- etc/adminhtml/system.xml | 7 +++++++ etc/config.xml | 2 ++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Controller/Index/Download.php b/Controller/Index/Download.php index 6cf935b..3297ff4 100644 --- a/Controller/Index/Download.php +++ b/Controller/Index/Download.php @@ -89,6 +89,6 @@ public function execute() $processor->setStore($storeId); $html = $processor->processTemplate(); $mpdf->WriteHTML($html); - $mpdf->Output('cart.pdf', 'D'); + $mpdf->Output($this->printProcess->getFileName(), 'D'); } } \ No newline at end of file diff --git a/Helper/PrintProcess.php b/Helper/PrintProcess.php index f45d012..1480542 100644 --- a/Helper/PrintProcess.php +++ b/Helper/PrintProcess.php @@ -22,28 +22,20 @@ namespace Mageplaza\ShareCart\Helper; use Magento\Checkout\Model\Session; -use Magento\Framework\App\Area; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Helper\Context; -use Magento\Framework\App\State; use Magento\Framework\Filesystem; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Framework\Stdlib\DateTime\TimeZone; use Magento\Store\Model\StoreManagerInterface; -use Mageplaza\Core\Helper\AbstractData; /** * Class PrintProcess * @package Mageplaza\PdfInvoice\Helper */ -class PrintProcess extends AbstractData +class PrintProcess extends Data { - /** - * Save pdf file location - */ - const MAGEPLAZA_DIR = 'var/mageplaza'; - /** * @var DateTime */ @@ -125,6 +117,19 @@ public function readFile($relativePath) return $rootDirectory->readFile($relativePath); } + /** + * @return string + */ + public function getFileName() + { + $name = $this->getConfigGeneral('file_name') ?: 'cart'; + if ($this->getConfigGeneral('timestamp')) { + $name .= ' ' . $this->dateTime->date('Y-m-d H.i'); + } + + return $name . '.pdf'; + } + /** * @param $storeId * @return mixed diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 17b395a..7e54fa0 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -33,6 +33,13 @@ Magento\Config\Model\Config\Source\Yesno Yes to enable the module.]]> + + + + + + Magento\Config\Model\Config\Source\Yesno + diff --git a/etc/config.xml b/etc/config.xml index 95771d6..ff3c29e 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -25,6 +25,8 @@ 1 + GlobalData Pricelist made + 1 From fd502f67890cce9ac375d0f8e1d641bac7443dcf Mon Sep 17 00:00:00 2001 From: Luong Date: Wed, 28 Nov 2018 17:26:51 +0700 Subject: [PATCH 13/14] change style table --- view/base/templates/template.html | 44 ++++-------------------- view/frontend/templates/cart/items.phtml | 5 +-- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/view/base/templates/template.html b/view/base/templates/template.html index c5368f0..21e01bc 100644 --- a/view/base/templates/template.html +++ b/view/base/templates/template.html @@ -40,27 +40,10 @@ width: 100%; } - table tr th, - table tr td { + table, th, td { border: 1px solid black; } - - table tr:first-child { - border-bottom: 2px solid black; - } - - table tr th { - border-top: none; - } - - table tr th:nth-child(1) { - border-left: none; - } - - table tr th:last-child { - border-right: none; - } - + td.qty { text-align: center; } @@ -82,30 +65,17 @@ text-align: right; } - table tr th:nth-child(5), - table tr td:nth-child(5) { - border-left: 2px solid black; - } - table tr:last-child td:not(:nth-child(5)) { border: none; } - table tr.tr1 td.td1, - table tr.tr1 td.td2, - table tr.tr1 td.td3, - table tr.tr1 td.td4 { - border: none; - } - - table tr td.td5, - table tr th.th5 { - border-right: none; + table tr.tr1 td.td1 + { + font-weight: bold; + text-align: center; } - table tr:last-child td:nth-child(5) { - border-bottom: 2px solid black; - } + tr {background-color: #FFEBCD;} .mark { font-weight: 600; diff --git a/view/frontend/templates/cart/items.phtml b/view/frontend/templates/cart/items.phtml index 6432e5f..789222d 100644 --- a/view/frontend/templates/cart/items.phtml +++ b/view/frontend/templates/cart/items.phtml @@ -52,10 +52,7 @@ - - - - + getBaseSubtotal() ?> \ No newline at end of file From 7510cf45ee8e7f0c6679805f04f15c63b199a724 Mon Sep 17 00:00:00 2001 From: Luong Date: Wed, 28 Nov 2018 17:28:49 +0700 Subject: [PATCH 14/14] change small --- Helper/PrintProcess.php | 2 +- view/base/templates/template.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/PrintProcess.php b/Helper/PrintProcess.php index 1480542..11338b1 100644 --- a/Helper/PrintProcess.php +++ b/Helper/PrintProcess.php @@ -14,7 +14,7 @@ * version in the future. * * @category Mageplaza - * @package Mageplaza_PdfInvoice + * @package Mageplaza_ShareCart * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ diff --git a/view/base/templates/template.html b/view/base/templates/template.html index 21e01bc..6fe0004 100644 --- a/view/base/templates/template.html +++ b/view/base/templates/template.html @@ -43,7 +43,7 @@ table, th, td { border: 1px solid black; } - + td.qty { text-align: center; }