Skip to content

Commit

Permalink
Merge pull request #6 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored May 27, 2020
2 parents 5587cac + b33b3fa commit ab6f358
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 31 deletions.
21 changes: 1 addition & 20 deletions Block/Cart/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,11 +45,6 @@ class Button extends Template
*/
protected $checkoutSession;

/**
* @var Currency
*/
protected $_currency;

/**
* @var ProductRepository
*/
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
*
Expand Down Expand Up @@ -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);
}

/**
Expand Down
17 changes: 13 additions & 4 deletions Block/Cart/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,6 +60,11 @@ class Items extends Template
*/
protected $configurable;

/**
* @var Data
*/
protected $helper;

/**
* Items constructor.
*
Expand All @@ -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(
Expand All @@ -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);
}

/**
Expand Down
48 changes: 48 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -32,6 +36,30 @@ class Data extends AbstractData
const CONFIG_MODULE_PATH = 'sharecart';
const BUSINESS_CONFIG_PATH = 'business_information';

/**
* @var PriceCurrencyInterface
*/
protected $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
*/
Expand Down Expand Up @@ -109,4 +137,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);
}
}
7 changes: 5 additions & 2 deletions Helper/PrintProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -107,7 +110,7 @@ public function __construct(
$this->timezone = $timezone;
$this->templateProcessor = $templateProcessor;

parent::__construct($context, $objectManager, $storeManager);
parent::__construct($context, $objectManager, $storeManager, $priceCurrency);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<item name="components" xsi:type="array">
<item name="minicart_content" xsi:type="array">
<item name="children" xsi:type="array">
<item name="promotion" xsi:type="array">
<item name="extra_info" xsi:type="array">
<item name="children" xsi:type="array">
<item name="mp_sharecart" xsi:type="array">
<item name="component" xsi:type="string">Mageplaza_ShareCart/js/view/minicart</item>
Expand Down
6 changes: 6 additions & 0 deletions view/frontend/web/js/view/minicart.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ define([
this.customer = customerData.get('cart');
},

moveShareCart: function(){
$(document).ready(function () {
$('.secondary.sharecart').appendTo($('.action.viewcart').parent());
});
},

getQuoteId: function () {
return customerData.get('cart')().quote_url;
},
Expand Down
4 changes: 1 addition & 3 deletions view/frontend/web/template/minicart.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
*/
-->
<!--ko if: isDisplay() -->
<div class="actions">
<div class="secondary sharecart" style="text-align: center">
<div class="secondary sharecart" style="text-align: center" afterRender="moveShareCart()">
<a class="action sharecart mp-sharecart-minicart" data-bind="click: copyQuote, event: {mouseleave: leaveQuote}"
style="cursor: pointer">
<span data-bind="i18n: 'Share Cart'"></span>
</a>
</div>
</div>
<!-- /ko -->

0 comments on commit ab6f358

Please sign in to comment.