From a565a8780bf20a71578227c26dc4de182c87b354 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 21 Jun 2021 15:32:59 +0200 Subject: [PATCH 1/4] Enable usage of coupon for free shipping --- .../Order/Create/WidgetConfigProvider.php | 14 ++++++++++++ Model/Checkout/WidgetConfigProvider.php | 22 +++++++++++++++++++ Model/Config.php | 20 +++++++++++++++++ etc/adminhtml/system.xml | 15 +++++++++++-- 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Model/Admin/Order/Create/WidgetConfigProvider.php b/Model/Admin/Order/Create/WidgetConfigProvider.php index 07ddd85..586a159 100755 --- a/Model/Admin/Order/Create/WidgetConfigProvider.php +++ b/Model/Admin/Order/Create/WidgetConfigProvider.php @@ -169,6 +169,10 @@ public function getConfig() "initialPickupLocations" => $this->getInitialPickupLocations() ]; + if ($this->isFreeShippingEnabled() && $shippingAddress->getFreeShipping()) { + $config['shipmentParameters']['startMatrix'] = $this->getFreeShippingMatrixLetter(); + } + $config = array_merge($config, $this->languageProvider->getConfig()); $this->generalHelper->addTolog('config', $config); @@ -403,4 +407,14 @@ protected function validateDeliveryMatrixCode(string $value) return count($matches) === 1; } + + /** + * Check if free shipping enabled in store config + * + * @return bool + */ + protected function isFreeShippingEnabled() + { + return $this->scopeConfig->isFreeShippingEnabled($this->getQuote()->getStoreId()); + } } diff --git a/Model/Checkout/WidgetConfigProvider.php b/Model/Checkout/WidgetConfigProvider.php index 9ef5bf7..76e3ce7 100644 --- a/Model/Checkout/WidgetConfigProvider.php +++ b/Model/Checkout/WidgetConfigProvider.php @@ -185,6 +185,10 @@ public function getConfig() "initialPickupLocations" => $this->getInitialPickupLocations() ]; + if ($this->isFreeShippingEnabled() && $shippingAddress->getFreeShipping()) { + $config['shipmentParameters']['startMatrix'] = $this->getFreeShippingMatrixLetter(); + } + $config = array_merge($config, $this->languageProvider->getConfig()); $this->generalHelper->addTolog('request', $config); @@ -397,6 +401,14 @@ public function isEnabled() return $this->scopeConfig->isEnabled(); } + /** + * @return mixed + */ + public function getFreeShippingMatrixLetter() + { + return $this->scopeConfig->getFreeShippingMatrixLetter($this->getQuote()->getStoreId()); + } + /** * Gets delivery matrix from product * @@ -433,4 +445,14 @@ protected function validateDeliveryMatrixCode(string $value) return count($matches) === 1; } + + /** + * Check if free shipping enabled in store config + * + * @return bool + */ + protected function isFreeShippingEnabled() + { + return $this->scopeConfig->isFreeShippingEnabled($this->getQuote()->getStoreId()); + } } diff --git a/Model/Config.php b/Model/Config.php index faadf6b..04ea2bc 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -293,6 +293,26 @@ public function isCarrierActive($store = null) in_array($this->getValue('carriers/' . Paazlshipping::CODE . '/active', $store), [1, 'true']); } + /** + * @param null|Store|int|string $store + * + * @return string + */ + public function getFreeShippingMatrixLetter($store = null) + { + return (string)$this->getValue(self::API_CONFIG_PATH . '/freeshipping_matrix_letter', $store); + } + + /** + * @param null|Store|int|string $store + * + * @return mixed + */ + public function isFreeShippingEnabled($store = null) + { + return $this->getValue(self::API_CONFIG_PATH . '/freeshipping_enabled', $store); + } + /** * @param null|Store|int|string $store * diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 86ea690..399a20d 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -251,7 +251,18 @@ Google Account]]> - + + + Magento\Config\Model\Config\Source\Yesno + + + + + 1 + + + + Magento\Config\Model\Config\Source\Yesno Write API calls to var/log/paazl.log. Not recommended in Paazl's production environment for performance reasons. @@ -268,4 +279,4 @@ - \ No newline at end of file + From fb24409303ed1a72034037f169b25e0974101cde Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 21 Jun 2021 15:35:39 +0200 Subject: [PATCH 2/4] Set default country ID if not set in quote #56 --- Plugin/Quote/AfterAddProduct.php | 84 ++++++++++++++++++++++++++++++++ etc/di.xml | 5 ++ 2 files changed, 89 insertions(+) create mode 100644 Plugin/Quote/AfterAddProduct.php diff --git a/Plugin/Quote/AfterAddProduct.php b/Plugin/Quote/AfterAddProduct.php new file mode 100644 index 0000000..c417fbe --- /dev/null +++ b/Plugin/Quote/AfterAddProduct.php @@ -0,0 +1,84 @@ +scopeConfig = $scopeConfig; + $this->quoteRepository = $quoteRepository; + $this->config = $config; + } + + /** + * Fire event after item was added to the cart (only after post request) + * + * @param QuoteModel $subject + * @param Item $result + * @param Product $product + * + * @return Item + * @throws Exception + */ + public function afterAddProduct( + QuoteModel $subject, + $result, + Product $product + ) { + $shippingAddress = $subject->getShippingAddress(); + if (!$shippingAddress->getCountryId() && $this->config->isEnabled()) { + $origin = $this->scopeConfig->getValue(self::ORIGIN); + $shippingAddress = $subject->getShippingAddress(); + $billingAddress = $subject->getBillingAddress(); + $billingAddress->setCountryId($origin); + $shippingAddress->setCountryId($origin); + $subject->setShippingAddress($shippingAddress); + $subject->setBillingAddress($billingAddress); + $this->quoteRepository->save($subject); + } + return $result; + } +} diff --git a/etc/di.xml b/etc/di.xml index 81cef32..71784a3 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -25,6 +25,11 @@ sortOrder="70"/> + + + + From fc68608036565607b6796c09056dc20128b7bfaa Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 21 Jun 2021 15:36:11 +0200 Subject: [PATCH 3/4] Add new Checkout Widget preset: Minimal --- Model/System/Config/Source/WidgetTheme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/System/Config/Source/WidgetTheme.php b/Model/System/Config/Source/WidgetTheme.php index 864f5d6..732389a 100755 --- a/Model/System/Config/Source/WidgetTheme.php +++ b/Model/System/Config/Source/WidgetTheme.php @@ -29,6 +29,7 @@ public function toOptionArray() if (!$this->options) { $this->options = [ ['value' => 'DEFAULT', 'label' => __('Default')], + ['value' => 'MINIMAL', 'label' => __('Minimal')], ['value' => 'GREEN', 'label' => __('Green')], ['value' => 'LIGHT-GREEN', 'label' => __('Light Green')], ['value' => 'BROWN', 'label' => __('Brown')], @@ -37,7 +38,6 @@ public function toOptionArray() ['value' => 'CUSTOM', 'label' => __('Custom')], ]; } - return $this->options; } } From a7e4b300790357028b866c6730a8c6bfbc377761 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 21 Jun 2021 15:36:32 +0200 Subject: [PATCH 4/4] Version bump --- composer.json | 2 +- etc/config.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 6f5f7af..a89a25c 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "paazl/magento2-checkout-widget", "description": "Paazl checkoutWidget for Magento 2", "type": "magento2-module", - "version": "1.6.1", + "version": "1.7.0", "keywords": [ "Paazl", "Magento 2", diff --git a/etc/config.xml b/etc/config.xml index 03568e1..fb6a023 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -8,7 +8,7 @@ - v1.6.1 + v1.7.0 0 0 0