diff --git a/.travis.yml b/.travis.yml index cbc76a8..296ecdd 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: php php: -- 5.6 -- 7.0 - 7.1 - 7.2 +- 7.3 +- 7.4 sudo: false diff --git a/Model/Admin/Order/Create/LanguageProvider.php b/Model/Admin/Order/Create/LanguageProvider.php index 6834efe..ef65cec 100755 --- a/Model/Admin/Order/Create/LanguageProvider.php +++ b/Model/Admin/Order/Create/LanguageProvider.php @@ -21,6 +21,13 @@ class LanguageProvider implements ConfigProviderInterface */ private $resolver; + private $allowedCodes = [ + 'en' => 'eng', + 'nl' => 'nld', + 'de' => 'deu', + 'pl' => 'pol' + ]; + /** * LanguageProvider constructor. * @@ -39,10 +46,13 @@ public function __construct( */ public function getConfig() { - $languageCode = 'en'; + $languageCode = 'eng'; if ($this->resolver->getLocale()) { $locale = $this->resolver->getLocale(); $languageCode = explode('_', $locale)[0]; + if (isset($this->allowedCodes[$languageCode])) { + $languageCode = $this->allowedCodes[$languageCode]; + } } return [ diff --git a/Model/Admin/Order/Create/WidgetConfigProvider.php b/Model/Admin/Order/Create/WidgetConfigProvider.php index 9db1600..07ddd85 100755 --- a/Model/Admin/Order/Create/WidgetConfigProvider.php +++ b/Model/Admin/Order/Create/WidgetConfigProvider.php @@ -7,13 +7,13 @@ namespace Paazl\CheckoutWidget\Model\Admin\Order\Create; use Magento\Backend\Model\Session\Quote as SessionQuote; +use Magento\Catalog\Model\ProductRepository; use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Model\Quote; use Magento\Quote\Model\Quote\Item\AbstractItem; use Magento\Sales\Model\OrderFactory; -use Magento\Catalog\Model\ProductRepository; -use Magento\Framework\Exception\NoSuchEntityException; use Paazl\CheckoutWidget\Helper\General as GeneralHelper; use Paazl\CheckoutWidget\Model\Config; use Paazl\CheckoutWidget\Model\TokenRetriever; @@ -137,6 +137,7 @@ public function getConfig() "loadPaazlBasedData" => true, "loadCarrierBasedData" => true, "availableTabs" => $this->getAvailableTabs(), + "headerTabType" => $this->getWidgetSectionToggle(), "defaultTab" => $this->getDefaultTab(), "style" => $this->getWidgetTheme(), "nominatedDateEnabled" => $this->getNominatedDateEnabled(), @@ -240,6 +241,14 @@ public function getAvailableTabs() return $this->scopeConfig->getAvailableTabs($this->getQuote()->getStoreId()); } + /** + * @return mixed + */ + public function getWidgetSectionToggle() + { + return $this->scopeConfig->getWidgetSectionToggle($this->getQuote()->getStoreId()); + } + /** * @return mixed */ diff --git a/Model/Api/Builder/Order.php b/Model/Api/Builder/Order.php index 7a3d918..5be6699 100755 --- a/Model/Api/Builder/Order.php +++ b/Model/Api/Builder/Order.php @@ -104,9 +104,10 @@ public function getCreateOrderData(OrderInterface $order) $shippingAddress = $order->getBillingAddress(); } $address = $this->parseAddress($shippingAddress); + $defaultHouseNumber = $this->config->getHouseNumberDefaultOption() ? 0 : ''; $result = [ - 'additionalInstruction' => $order->getCustomerNote(), + 'additionalInstruction' => '', 'consignee' => [ 'email' => $order->getCustomerEmail(), 'name' => $shippingAddress->getName(), @@ -117,8 +118,8 @@ public function getCreateOrderData(OrderInterface $order) 'country' => $shippingAddress->getCountryId(), 'postalCode' => $shippingAddress->getPostcode(), 'province' => $shippingAddress->getRegionCode(), - 'street' => $address['street'], - 'houseNumber' => $address['houseNumber'], + 'street' => $address['street'] ?? '', + 'houseNumber' => $address['houseNumber'] ?? $defaultHouseNumber, 'houseNumberExtension' => $address['houseNumberExtension'] ?? '', ] ], @@ -176,10 +177,19 @@ public function getCreateOrderData(OrderInterface $order) * @param Address $shippingAddress * * @return array + * @throws LocalizedException */ public function parseAddress(Address $shippingAddress) { - $street = implode(' ', $shippingAddress->getStreet()); + $street = $shippingAddress->getStreet(); + if ($this->config->housenumberExtensionOnThirdStreet()) { + return [ + 'street' => trim($street[0] ?? null), + 'houseNumber' => trim(isset($street[1]) ? $street[1] : null), + 'houseNumberExtension' => trim(isset($street[2]) ? $street[2] : null), + ]; + } + $street = implode(' ', $street); $street = trim(str_replace("\t", ' ', $street)); $houseExtensionPattern = '(?\d{1,5})[[:punct:]\-\/\s]*(?[^[:space:]]{1,2})?'; $streetPattern = '(?.+)'; @@ -197,9 +207,9 @@ public function parseAddress(Address $shippingAddress) } return [ - 'street' => trim($matches['street'] ?? ''), - 'houseNumber' => trim($matches['houseNumber'] ?? ''), - 'houseNumberExtension' => trim($matches['houseNumberExtension'] ?? ''), + 'street' => trim($matches['street'] ?? null), + 'houseNumber' => trim($matches['houseNumber'] ?? null), + 'houseNumberExtension' => trim($matches['houseNumberExtension'] ?? null), ]; } @@ -252,15 +262,17 @@ public function parseAddress(Address $shippingAddress) return $probably; } - /** - * Fallback to full address on street and housenumber set to 0 - * This is a new requirement from Paazl API. - */ - return [ - 'street' => $street, - 'houseNumber' => 0, - 'houseNumberExtension' => null, - ]; + if ($this->config->getHouseNumberDefaultOption()) { + return [ + 'street' => $street, + 'houseNumber' => null, + 'houseNumberExtension' => null, + ]; + } else { + throw new LocalizedException( + __('This order cannot be committed to Paazl, please make sure the address has a valid housenumber.') + ); + } } /** diff --git a/Model/Checkout/LanguageProvider.php b/Model/Checkout/LanguageProvider.php index b267bf3..83d9bc3 100644 --- a/Model/Checkout/LanguageProvider.php +++ b/Model/Checkout/LanguageProvider.php @@ -21,6 +21,13 @@ class LanguageProvider implements ConfigProviderInterface */ private $resolver; + private $allowedCodes = [ + 'en' => 'eng', + 'nl' => 'nld', + 'de' => 'deu', + 'pl' => 'pol' + ]; + /** * LanguageProvider constructor. * @@ -39,10 +46,13 @@ public function __construct( */ public function getConfig() { - $languageCode = 'en'; + $languageCode = 'eng'; if ($this->resolver->getLocale()) { $locale = $this->resolver->getLocale(); $languageCode = explode('_', $locale)[0]; + if (isset($this->allowedCodes[$languageCode])) { + $languageCode = $this->allowedCodes[$languageCode]; + } } return [ diff --git a/Model/Checkout/WidgetConfigProvider.php b/Model/Checkout/WidgetConfigProvider.php index 572e4c0..22e262c 100644 --- a/Model/Checkout/WidgetConfigProvider.php +++ b/Model/Checkout/WidgetConfigProvider.php @@ -6,15 +6,14 @@ namespace Paazl\CheckoutWidget\Model\Checkout; +use Magento\Catalog\Model\ProductRepository; use Magento\Checkout\Helper\Data; use Magento\Checkout\Model\ConfigProviderInterface; -use Magento\Directory\Model\Currency; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Model\Quote; use Magento\Quote\Model\Quote\Item\AbstractItem; use Magento\Sales\Model\OrderFactory; -use Magento\Catalog\Model\ProductRepository; -use Magento\Framework\Exception\NoSuchEntityException; use Paazl\CheckoutWidget\Helper\General as GeneralHelper; use Paazl\CheckoutWidget\Model\Config; use Paazl\CheckoutWidget\Model\Handler\Item as ItemHandler; @@ -149,6 +148,7 @@ public function getConfig() "loadPaazlBasedData" => true, "loadCarrierBasedData" => true, "availableTabs" => $this->getAvailableTabs(), + "headerTabType" => $this->getWidgetSectionToggle(), "defaultTab" => $this->getDefaultTab(), "style" => $this->getWidgetTheme(), "nominatedDateEnabled" => $this->getNominatedDateEnabled(), @@ -252,6 +252,14 @@ public function getAvailableTabs() return $this->scopeConfig->getAvailableTabs(); } + /** + * @return mixed + */ + public function getWidgetSectionToggle() + { + return $this->scopeConfig->getWidgetSectionToggle(); + } + /** * @return mixed */ diff --git a/Model/Config.php b/Model/Config.php index e0aa64d..faadf6b 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -179,6 +179,16 @@ public function getNominatedDateEnabled($store = null) ); } + /** + * @param null|Store|int|string $store + * + * @return mixed + */ + public function getWidgetSectionToggle($store = null) + { + return $this->getValue(self::API_CONFIG_PATH . '/widget_section_mode', $store); + } + /** * @param null|Store|int|string $store * @@ -310,6 +320,10 @@ public function housenumberOnSecondStreet($store = null) */ public function housenumberExtensionOnThirdStreet($store = null) { + if (!$this->housenumberOnSecondStreet($store)) { + return false; + } + return (bool)$this->getValue(self::API_CONFIG_PATH . '/housenumber_extension_third_street', $store); } @@ -468,4 +482,13 @@ public function getInsuranceValue($store = null) { return abs((float)$this->getValue(self::API_CONFIG_PATH . '/insurance_value', $store)); } + + /** + * @param null|Store|int|string $store + * @return bool + */ + public function getHouseNumberDefaultOption($store = null) + { + return !!$this->getValue(self::API_CONFIG_PATH . '/housenumber_default_value', $store); + } } diff --git a/Model/ExtInfoHandler.php b/Model/ExtInfoHandler.php index 3311fc5..f05a6ff 100755 --- a/Model/ExtInfoHandler.php +++ b/Model/ExtInfoHandler.php @@ -108,6 +108,9 @@ public function getInfoFromQuote(Quote $quote) } $info = $reference->getExtShippingInfo(); + if (empty($info)) { + return null; + } /** @var ShippingInfo $shippingInfo */ $shippingInfo = $this->shippingInfoFactory->create(); diff --git a/Model/Quote/Totals/AppendShippingMethods.php b/Model/Quote/Totals/AppendShippingMethods.php new file mode 100644 index 0000000..ab4f5fd --- /dev/null +++ b/Model/Quote/Totals/AppendShippingMethods.php @@ -0,0 +1,76 @@ +shippingMethodManagement = $shippingMethodManagement; + $this->totalsExtensionFactory = $totalsExtensionFactory; + $this->cartRepository = $cartRepository; + } + + /** + * @param TotalsInterface $totals + * @param int $cartId + * @throws NoSuchEntityException + * @throws StateException + */ + public function append(TotalsInterface $totals, $cartId) + { + $quote = $this->cartRepository->get($cartId); + if (!$quote || $quote->getIsVirtual()) { + return; + } + + // Adding the list of shipping methods to output + $methods = $this->shippingMethodManagement->getList($quote->getId()); + + /** @var TotalsExtensionInterface|null $extension */ + $extension = $totals->getExtensionAttributes(); + if (!$extension) { + $extension = $this->totalsExtensionFactory->create(); + } + $extension->setShippingMethods($methods); + $totals->setExtensionAttributes($extension); + } +} diff --git a/Model/System/Config/Source/WidgetSections.php b/Model/System/Config/Source/WidgetSections.php new file mode 100644 index 0000000..cb30ba8 --- /dev/null +++ b/Model/System/Config/Source/WidgetSections.php @@ -0,0 +1,36 @@ +options) { + $this->options = [ + ['value' => 'TAB', 'label' => __('Tab')], + ['value' => 'BUTTON', 'label' => __('Button')] + ]; + } + + return $this->options; + } +} diff --git a/Plugin/Checkout/ShippingInformationManagementPlugin.php b/Plugin/Checkout/ShippingInformationManagementPlugin.php index 3a40ce0..45df435 100755 --- a/Plugin/Checkout/ShippingInformationManagementPlugin.php +++ b/Plugin/Checkout/ShippingInformationManagementPlugin.php @@ -6,19 +6,16 @@ namespace Paazl\CheckoutWidget\Plugin\Checkout; -use Magento\Quote\Api\Data\TotalsExtensionFactory; -use Magento\Quote\Api\Data\TotalsExtensionInterface; -use Magento\Quote\Api\Data\TotalsInterface; use Magento\Checkout\Api\Data\PaymentDetailsInterface; use Magento\Checkout\Api\Data\ShippingInformationInterface; use Magento\Checkout\Model\ShippingInformationManagement; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Exception\StateException; use Magento\Framework\Stdlib\ArrayManager; use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Api\ShipmentEstimationInterface; -use Magento\Quote\Api\ShippingMethodManagementInterface; use Paazl\CheckoutWidget\Model\Api\Builder\Reference; use Paazl\CheckoutWidget\Model\Api\PaazlApi; use Paazl\CheckoutWidget\Model\Api\PaazlApiFactory; @@ -26,6 +23,7 @@ use Paazl\CheckoutWidget\Model\Carrier\Paazlshipping; use Paazl\CheckoutWidget\Model\Api\ApiException; use Paazl\CheckoutWidget\Model\Api\Field\DeliveryType; +use Paazl\CheckoutWidget\Model\Quote\Totals\AppendShippingMethods; /** * Class ShippingInformationManagementPlugin @@ -60,24 +58,14 @@ class ShippingInformationManagementPlugin private $shipmentEstimation; /** - * @var CartInterface|null - */ - private $quote; - - /** - * @var ShippingMethodManagementInterface - */ - private $shippingMethodManagement; - - /** - * @var TotalsExtensionFactory + * @var ArrayManager */ - private $totalsExtensionFactory; + private $arrayManager; /** - * @var ArrayManager + * @var AppendShippingMethods */ - private $arrayManager; + private $appendShippingMethods; /** * ShippingInformationManagementPlugin constructor. @@ -87,9 +75,8 @@ class ShippingInformationManagementPlugin * @param CartRepositoryInterface $quoteRepository * @param CheckoutInfoToQuote $checkoutInfoToQuote * @param ShipmentEstimationInterface $shipmentEstimation - * @param ShippingMethodManagementInterface $shippingMethodManagement - * @param TotalsExtensionFactory $totalsExtensionFactory * @param ArrayManager $arrayManager + * @param AppendShippingMethods $appendShippingMethods */ public function __construct( PaazlApiFactory $paazlApiFactory, @@ -97,18 +84,16 @@ public function __construct( CartRepositoryInterface $quoteRepository, CheckoutInfoToQuote $checkoutInfoToQuote, ShipmentEstimationInterface $shipmentEstimation, - ShippingMethodManagementInterface $shippingMethodManagement, - TotalsExtensionFactory $totalsExtensionFactory, - ArrayManager $arrayManager + ArrayManager $arrayManager, + AppendShippingMethods $appendShippingMethods ) { $this->paazlApiFactory = $paazlApiFactory; $this->referenceBuilder = $referenceBuilder; $this->quoteRepository = $quoteRepository; $this->checkoutInfoToQuote = $checkoutInfoToQuote; $this->shipmentEstimation = $shipmentEstimation; - $this->shippingMethodManagement = $shippingMethodManagement; - $this->totalsExtensionFactory = $totalsExtensionFactory; $this->arrayManager = $arrayManager; + $this->appendShippingMethods = $appendShippingMethods; } /** @@ -168,7 +153,6 @@ public function beforeSaveAddressInformation( } $this->checkoutInfoToQuote->process($quote); - $this->quote = $quote; } // Calling the observed method @@ -178,42 +162,17 @@ public function beforeSaveAddressInformation( /** * @param ShippingInformationManagement $subject * @param PaymentDetailsInterface $paymentDetails - * + * @param int $cartId * @return PaymentDetailsInterface * @throws NoSuchEntityException - * @throws \Magento\Framework\Exception\StateException + * @throws StateException */ public function afterSaveAddressInformation( ShippingInformationManagement $subject, - PaymentDetailsInterface $paymentDetails + PaymentDetailsInterface $paymentDetails, + $cartId ) { - if ($this->quote && (!$this->quote->getIsVirtual())) { - // Adding the list of shipping methods to output - $methods = $this->shippingMethodManagement->getList($this->quote->getId()); - - $isPaazlShippingFlag = false; - - foreach ($methods as $method) { - if ($method->getCarrierCode() === Paazlshipping::CODE) { - $isPaazlShippingFlag = true; - } - } - - if (!$isPaazlShippingFlag) { - return $paymentDetails; - } - - /** @var TotalsInterface $totals */ - $totals = $paymentDetails->getTotals(); - - /** @var TotalsExtensionInterface|null $extension */ - $extension = $totals->getExtensionAttributes(); - if (!$extension) { - $extension = $this->totalsExtensionFactory->create(); - } - $extension->setShippingMethods($methods); - $totals->setExtensionAttributes($extension); - } + $this->appendShippingMethods->append($paymentDetails->getTotals(), $cartId); return $paymentDetails; } diff --git a/Plugin/Quote/CartTotalRepositoryPlugin.php b/Plugin/Quote/CartTotalRepositoryPlugin.php new file mode 100644 index 0000000..6a9e868 --- /dev/null +++ b/Plugin/Quote/CartTotalRepositoryPlugin.php @@ -0,0 +1,51 @@ +appendShippingMethods = $appendShippingMethods; + } + + /** + * @param CartTotalRepositoryInterface $subject + * @param TotalsInterface $totals + * @param int $cartId + * @return TotalsInterface + * @throws NoSuchEntityException + * @throws StateException + */ + public function afterGet( + CartTotalRepositoryInterface $subject, + TotalsInterface $totals, + $cartId + ) { + $this->appendShippingMethods->append($totals, $cartId); + + return $totals; + } +} diff --git a/composer.json b/composer.json index 04b761c..92e9b7f 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.3.0", + "version": "1.4.0", "keywords": [ "Paazl", "Magento 2", diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 9686652..86ea690 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -58,6 +58,11 @@ Select the widget tabs that you want to display. required-entry + + + Paazl\CheckoutWidget\Model\System\Config\Source\WidgetSections + Select sections toggle appearance for the Paazl widget. + Paazl\CheckoutWidget\Model\System\Config\Source\AvailableTabs @@ -123,12 +128,12 @@ 1 - + Magento\Config\Model\Config\Source\Yesno - + 1 @@ -153,6 +158,14 @@ Fill in the insurance amount as a number. + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + Paazl\CheckoutWidget\Block\Adminhtml\Paazl\Heading diff --git a/etc/config.xml b/etc/config.xml index c1b77dd..3aee724 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -8,7 +8,7 @@ - v1.3.0 + v1.4.0 0 0 0 @@ -25,12 +25,14 @@ This shipping method is not available. To use this shipping method, please contact us. DELIVERY,STORE,PICKUP 1 + TAB DELIVERY 5 5 30 5 0 + 1 diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml new file mode 100644 index 0000000..989487b --- /dev/null +++ b/etc/csp_whitelist.xml @@ -0,0 +1,21 @@ + + + + + + https://widget-acc.paazl.com + + + + + https://widget-acc.paazl.com + + + + + https://widget-acc.paazl.com + + + + \ No newline at end of file diff --git a/etc/webapi_rest/di.xml b/etc/webapi_rest/di.xml index 2844e29..3f41b77 100755 --- a/etc/webapi_rest/di.xml +++ b/etc/webapi_rest/di.xml @@ -13,4 +13,9 @@ + + + + diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js index 7849f83..179c019 100755 --- a/view/frontend/requirejs-config.js +++ b/view/frontend/requirejs-config.js @@ -12,6 +12,15 @@ var config = { 'Magento_Checkout/js/model/checkout-data-resolver': { 'Paazl_CheckoutWidget/js/checkout/model/checkout-data-resolver-mixin': true }, + 'Magento_Checkout/js/model/shipping-rate-service': { + 'Paazl_CheckoutWidget/js/checkout/model/shipping-rate-service-mixin': true + }, + 'Magento_Checkout/js/model/shipping-rate-processor/new-address': { + 'Paazl_CheckoutWidget/js/checkout/model/shipping-rate-processor/processor-mixin': true + }, + 'Magento_Checkout/js/model/shipping-rate-processor/customer-address': { + 'Paazl_CheckoutWidget/js/checkout/model/shipping-rate-processor/processor-mixin': true + }, 'Magento_Checkout/js/view/summary/abstract-total': { 'Paazl_CheckoutWidget/js/checkout/view/summary/abstract-total-mixin': true }, diff --git a/view/frontend/web/js/checkout/model/shipping-rate-processor/processor-mixin.js b/view/frontend/web/js/checkout/model/shipping-rate-processor/processor-mixin.js new file mode 100644 index 0000000..c21c6dd --- /dev/null +++ b/view/frontend/web/js/checkout/model/shipping-rate-processor/processor-mixin.js @@ -0,0 +1,10 @@ +define( + [ + './processor-wrapper' + ], + function (wrapper) { + return function (target) { + return wrapper(target); + }; + } +); \ No newline at end of file diff --git a/view/frontend/web/js/checkout/model/shipping-rate-processor/processor-wrapper.js b/view/frontend/web/js/checkout/model/shipping-rate-processor/processor-wrapper.js new file mode 100644 index 0000000..fd894ae --- /dev/null +++ b/view/frontend/web/js/checkout/model/shipping-rate-processor/processor-wrapper.js @@ -0,0 +1,17 @@ +define( + [ + 'widgetConfig', + 'mage/utils/wrapper' + ], + function (widgetConfig, wrapper) { + return function (target) { + target.getRates = wrapper.wrap(target.getRates, function(orig) { + if (!widgetConfig.prototype.isLocked()) { + return orig(); + } + }); + + return target; + }; + } +); \ No newline at end of file diff --git a/view/frontend/web/js/checkout/model/shipping-rate-service-mixin.js b/view/frontend/web/js/checkout/model/shipping-rate-service-mixin.js new file mode 100644 index 0000000..0ca60ec --- /dev/null +++ b/view/frontend/web/js/checkout/model/shipping-rate-service-mixin.js @@ -0,0 +1,18 @@ +define( + [ + './shipping-rate-processor/processor-wrapper', + 'mage/utils/wrapper' + ], + function (wrapper, utilsWrapper) { + return function (target) { + target.registerProcessor = utilsWrapper.wrap( + target.registerProcessor, + function (orig, type, processor) { + orig(type, wrapper(processor)); + } + ); + + return target; + }; + } +); \ No newline at end of file diff --git a/view/frontend/web/js/checkout/view/shipping-mixin.js b/view/frontend/web/js/checkout/view/shipping-mixin.js index 0b5f8e4..f85b1b0 100755 --- a/view/frontend/web/js/checkout/view/shipping-mixin.js +++ b/view/frontend/web/js/checkout/view/shipping-mixin.js @@ -69,6 +69,12 @@ define([ isPaazlOnly: function () { var rates = this.rates(); return (rates.length === 1 && rates[0].carrier_code === 'paazlshipping'); + }, + + setShippingInformation: function () { + widgetConfig.prototype.lock(); + this._super(); + widgetConfig.prototype.unlock(); } }); } diff --git a/view/frontend/web/js/checkout/view/widget-config.js b/view/frontend/web/js/checkout/view/widget-config.js index e4a3f65..8775da1 100755 --- a/view/frontend/web/js/checkout/view/widget-config.js +++ b/view/frontend/web/js/checkout/view/widget-config.js @@ -69,8 +69,9 @@ define([ } return Component.extend({ - configJson: ko.observable(), + configJson: {}, customerAddressId: null, + locked: false, state: { postcode: null, country: null @@ -82,7 +83,7 @@ define([ }, initWidget: function () { - this.configJson(window.checkoutConfig.paazlshipping.widgetConfig); + this.configJson = widgetConfig || {}; this.initMap(); }, @@ -105,8 +106,19 @@ define([ } }, - getConfigJson: function (data) { - this.configJson(data); + lock: function() { + this.locked = true; + }, + + unlock: function() { + this.locked = false; + }, + + /** + * @return {boolean} + */ + isLocked: function() { + return this.locked; }, isHideOtherMethods: function () { @@ -138,7 +150,7 @@ define([ loadWidget: function (postcode, country) { this.initWidget(); - var data = this.configJson(), + var data = this.configJson, self = this; if (!data) { diff --git a/view/frontend/web/js/mixins/Magento_Checkout/view/summary/shipping.js b/view/frontend/web/js/mixins/Magento_Checkout/view/summary/shipping.js index 1c6e5a2..ad1af82 100755 --- a/view/frontend/web/js/mixins/Magento_Checkout/view/summary/shipping.js +++ b/view/frontend/web/js/mixins/Magento_Checkout/view/summary/shipping.js @@ -19,6 +19,14 @@ define([], function () { && totals['extension_attributes']['shipping_methods'][0]['carrier_code'] === 'paazlshipping' ) { let shippingMethod = totals['extension_attributes']['shipping_methods'][0]; + if (window.checkoutConfig.totalsData.extension_attributes) { + window.checkoutConfig.totalsData.extension_attributes[0] + = totals['extension_attributes']['shipping_methods'][0] + } + return shippingMethod['carrier_title'] + ' - ' + shippingMethod['method_title']; + } else if (window.checkoutConfig.totalsData.extension_attributes + && window.checkoutConfig.totalsData.extension_attributes[0]) { + let shippingMethod = window.checkoutConfig.totalsData.extension_attributes[0]; return shippingMethod['carrier_title'] + ' - ' + shippingMethod['method_title']; }