diff --git a/ViewModel/Cart/ProgressBar.php b/ViewModel/Cart/ProgressBar.php index f2bae45..3aafea7 100644 --- a/ViewModel/Cart/ProgressBar.php +++ b/ViewModel/Cart/ProgressBar.php @@ -9,7 +9,6 @@ use Magento\Checkout\Model\Session; use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Framework\DataObject; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Pricing\PriceCurrencyInterface; @@ -17,7 +16,7 @@ use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Model\Quote; -class ProgressBar extends DataObject implements ArgumentInterface +class ProgressBar implements ArgumentInterface { /** * System XML config path for ChrisMallory_FreeShippingBanner - Uses default checkout cart section @@ -50,41 +49,15 @@ class ProgressBar extends DataObject implements ArgumentInterface * @param ScopeConfigInterface $scopeConfig * @param Session $session * @param PriceCurrencyInterface $priceCurrency - * @param array $data */ public function __construct( ScopeConfigInterface $scopeConfig, Session $session, - PriceCurrencyInterface $priceCurrency, - array $data = [] + PriceCurrencyInterface $priceCurrency ) { $this->scopeConfig = $scopeConfig; $this->session = $session; $this->priceCurrency = $priceCurrency; - parent::__construct($data); - } - - /** - * Check if free shipping countdown is enabled - * - * @return bool - */ - public function isEnabled(): bool - { - return (bool)$this->scopeConfig->getValue(self::CHECKOUT_CART_XML_CONFIG_PATH - . 'freeshipping_progress_enable'); - } - - /** - * Get Cart/Quote - * - * @return CartInterface|Quote - * @throws LocalizedException - * @throws NoSuchEntityException - */ - public function getQuote() - { - return $this->session->getQuote(); } /** @@ -121,9 +94,7 @@ public function getFreeShippingMethodMinValue(): float */ public function getCurrentTotal(): float { - $quote = $this->session->getQuote(); - - return (float)$quote->getSubtotalWithDiscount(); + return (float)$this->session->getQuote()->getSubtotalWithDiscount(); } /** @@ -156,9 +127,7 @@ public function isFreeShippingEligible(): bool */ public function getFreeShippingDifference(): float { - $currentTotal = $this->getCurrentTotal(); - - return $this->getFreeShippingMinValue() - $currentTotal; + return $this->getFreeShippingMinValue() - $this->getCurrentTotal(); } /** diff --git a/composer.json b/composer.json index 0297952..aea067c 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,10 @@ } ], "minimum-stability": "dev", - "require": {}, + "require": { + "magento/module-quote": "*", + "magento/module-checkout": "*" + }, "autoload": { "files": [ "registration.php" diff --git a/etc/acl.xml b/etc/acl.xml index 78bdd0b..a63725e 100644 --- a/etc/acl.xml +++ b/etc/acl.xml @@ -1,16 +1,22 @@ + - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 4cc11df..a72dcbc 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,4 +1,10 @@ +
diff --git a/etc/config.xml b/etc/config.xml index 0da1419..f69711a 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -1,11 +1,17 @@ + - - - + + + 0 1 - - - + + + diff --git a/etc/module.xml b/etc/module.xml index 447f725..84df3d9 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,15 @@ - - + + + + + + + diff --git a/registration.php b/registration.php index 63af3b1..b8b315f 100644 --- a/registration.php +++ b/registration.php @@ -3,6 +3,8 @@ * Copyright © Chris Mallory All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + use Magento\Framework\Component\ComponentRegistrar; ComponentRegistrar::register(ComponentRegistrar::MODULE, 'ChrisMallory_FreeShippingProgressBar', __DIR__); diff --git a/view/frontend/layout/checkout_cart_index.xml b/view/frontend/layout/checkout_cart_index.xml index 05d56b1..de3ce3d 100755 --- a/view/frontend/layout/checkout_cart_index.xml +++ b/view/frontend/layout/checkout_cart_index.xml @@ -1,10 +1,20 @@ + + - + ChrisMallory\FreeShippingProgressBar\ViewModel\Cart\ProgressBar diff --git a/view/frontend/templates/cart/freeshipping_progress_bar.phtml b/view/frontend/templates/cart/freeshipping_progress_bar.phtml index 0747863..30d5d64 100755 --- a/view/frontend/templates/cart/freeshipping_progress_bar.phtml +++ b/view/frontend/templates/cart/freeshipping_progress_bar.phtml @@ -1,4 +1,9 @@ getData('viewModel'); +$shippingLabel = 'FREE SHIPPING'; + ?> -isEnabled()): ?> -
- isFreeShippingEligible()): ?> - getFreeShippingCompletionPercent(); - $background = "background: linear-gradient(to right, #00b052 0%, #00b052 " - . $freeshippingProgress . "%, lightgreen);"; - if ($freeshippingProgress > 90) { - $background = "background: linear-gradient(to right, #00b052 0%, #00b052 95%, lightgreen);"; - } - ?> -

Add - - getFormattedPrice($viewModel->getFreeShippingDifference()) ?> - - more to get - FREE SHIPPING! -

-
- getFormattedPrice(0, 0) ?> -
-
-
-
+
+ isFreeShippingEligible()): ?> + getFreeShippingCompletionPercent(); + $background = "background: linear-gradient(to right, #00b052 0%, #00b052 " + . $freeshippingProgress . "%, lightgreen);"; + if ($freeshippingProgress > 90) { + $background = "background: linear-gradient(to right, #00b052 0%, #00b052 95%, lightgreen);"; + } + ?> +

+ %1 more to get %2!', + $viewModel->getFormattedPrice($viewModel->getFreeShippingDifference()), + $shippingLabel + ) ?> +

+
+ getFormattedPrice(0, 0) ?> +
+
+
- - getFormattedPrice($viewModel->getFreeShippingMinValue(), 0) ?> -
- -
-

Your Order Is Eligible for FREE SHIPPING!

-
- -
- + + getFormattedPrice($viewModel->getFreeShippingMinValue(), 0) ?> + +
+ +
+

+ %1!', + $shippingLabel + ) ?> +

+
+ +