From ca0da41a68870d67563a9d1bbfc7439c13406205 Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Fri, 18 Mar 2022 08:32:06 +0100 Subject: [PATCH 01/36] POSTCODENL-362, POSTCODENL-364 Added files from temp_lucas branch --- Helper/TigFieldsHelper.php | 93 ++++++++++ Observer/SaveTigFieldsInOrder.php | 63 +++++++ .../Model/PaymentInformationManagement.php | 40 ++++ .../Quote/Model/BillingAddressManagement.php | 71 +++++++ Plugin/Quote/Model/Quote/Address.php | 68 +++++++ .../Quote/Model/ShippingAddressManagement.php | 69 +++++++ Setup/Patch/Data/AddTigEavAttributes.php | 174 ++++++++++++++++++ .../Schema/AddQuoteAddressAttributes.php | 114 ++++++++++++ etc/di.xml | 17 ++ etc/events.xml | 37 ++++ etc/extension_attributes.xml | 2 +- 11 files changed, 747 insertions(+), 1 deletion(-) create mode 100644 Helper/TigFieldsHelper.php create mode 100644 Observer/SaveTigFieldsInOrder.php create mode 100644 Plugin/Checkout/Model/PaymentInformationManagement.php create mode 100644 Plugin/Quote/Model/BillingAddressManagement.php create mode 100644 Plugin/Quote/Model/Quote/Address.php create mode 100644 Plugin/Quote/Model/ShippingAddressManagement.php create mode 100644 Setup/Patch/Data/AddTigEavAttributes.php create mode 100644 Setup/Patch/Schema/AddQuoteAddressAttributes.php create mode 100644 etc/events.xml diff --git a/Helper/TigFieldsHelper.php b/Helper/TigFieldsHelper.php new file mode 100644 index 0000000..3409124 --- /dev/null +++ b/Helper/TigFieldsHelper.php @@ -0,0 +1,93 @@ +logger = $logger; + } + + /** + * @param $extensionAttributes + * @param $object + */ + public function copyFieldsFromExtensionAttributesToObject($extensionAttributes, $object) { + if (empty($extensionAttributes)) { + return; + } + try { + $object->setTigHousenumber($extensionAttributes->getTigHousenumber()); + $object->setTigHousenumberAddition($extensionAttributes->getTigHousenumberAddition()); + $object->setTigStreet($extensionAttributes->getTigStreet()); + } catch (\Exception $e) { + $this->logger->critical($e->getMessage()); + } + } + + /** + * @param QuoteAddressInterface $quoteAddress + * @param CustomerAddressInterface $customerAddress + */ + public function copyFieldsFromQuoteAddressToCustomerAddress( + QuoteAddressInterface $quoteAddress, + CustomerAddressInterface $customerAddress + ) { + try { + foreach(self::TIG_FIELDS as $fieldName){ + $value = $quoteAddress->getData($fieldName); + $customerAddress->setCustomAttribute($fieldName, $value); + } + } catch (\Exception $e) { + $this->logger->critical($e->getMessage()); + } + } +} diff --git a/Observer/SaveTigFieldsInOrder.php b/Observer/SaveTigFieldsInOrder.php new file mode 100644 index 0000000..fd72b32 --- /dev/null +++ b/Observer/SaveTigFieldsInOrder.php @@ -0,0 +1,63 @@ +getEvent()->getOrder(); + $quote = $observer->getEvent()->getQuote(); + + if ($quote->getBillingAddress()) { + $order->getBillingAddress()->setTigStreet($quote->getBillingAddress()->getExtensionAttributes()->getTigStreet()); + $order->getBillingAddress()->setTigHousenumber($quote->getBillingAddress()->getExtensionAttributes()->getTigHousenumber()); + $order->getBillingAddress()->setTigHousenumberAddition($quote->getBillingAddress()->getExtensionAttributes()->getTigHousenumberAddition()); + } + + if (!$quote->isVirtual()) { + $order->getShippingAddress()->setTigStreet($quote->getShippingAddress()->getExtensionAttributes()->getTigStreet()); + $order->getShippingAddress()->setTigHousenumber($quote->getShippingAddress()->getExtensionAttributes()->getTigHousenumber()); + $order->getShippingAddress()->setTigHousenumberAddition($quote->getShippingAddress()->getExtensionAttributes()->getTigHousenumberAddition()); + } + return $this; + } +} diff --git a/Plugin/Checkout/Model/PaymentInformationManagement.php b/Plugin/Checkout/Model/PaymentInformationManagement.php new file mode 100644 index 0000000..c4c3d19 --- /dev/null +++ b/Plugin/Checkout/Model/PaymentInformationManagement.php @@ -0,0 +1,40 @@ +fieldsHelper = $fieldsHelper; + } + + /** + * @param \Magento\Checkout\Model\PaymentInformationManagement $subject + * @param $cartId + * @param PaymentInterface $paymentMethod + * @param AddressInterface $address + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function beforeSavePaymentInformation( + \Magento\Checkout\Model\PaymentInformationManagement $subject, + $cartId, + PaymentInterface $paymentMethod, + AddressInterface $address + ) { + $extAttributes = $address->getExtensionAttributes(); + $this->fieldsHelper->copyFieldsFromExtensionAttributesToObject($extAttributes, $address); + } +} diff --git a/Plugin/Quote/Model/BillingAddressManagement.php b/Plugin/Quote/Model/BillingAddressManagement.php new file mode 100644 index 0000000..b32090b --- /dev/null +++ b/Plugin/Quote/Model/BillingAddressManagement.php @@ -0,0 +1,71 @@ +fieldsHelper = $fieldsHelper; + } + + /** + * @param MagentoBillingAddressManagement $subject + * @param $cartId + * @param AddressInterface $address + * @param false $useForShipping + */ + public function beforeAssign( + MagentoBillingAddressManagement $subject, + $cartId, + AddressInterface $address, + $useForShipping = false + ) { + $extAttributes = $address->getExtensionAttributes(); + $this->fieldsHelper->copyFieldsFromExtensionAttributesToObject($extAttributes, $address); + } +} diff --git a/Plugin/Quote/Model/Quote/Address.php b/Plugin/Quote/Model/Quote/Address.php new file mode 100644 index 0000000..8165dfe --- /dev/null +++ b/Plugin/Quote/Model/Quote/Address.php @@ -0,0 +1,68 @@ +fieldsHelper = $fieldsHelper; + } + + /** + * @param QuoteAddressInterface $quoteAddress + * @param CustomerAddressInterface $customerAddress + * + * @return CustomerAddressInterface + */ + public function afterExportCustomerAddress( + QuoteAddressInterface $quoteAddress, + CustomerAddressInterface $customerAddress + ) { + $this->fieldsHelper->copyFieldsFromQuoteAddressToCustomerAddress($quoteAddress, $customerAddress); + + return $customerAddress; + } +} diff --git a/Plugin/Quote/Model/ShippingAddressManagement.php b/Plugin/Quote/Model/ShippingAddressManagement.php new file mode 100644 index 0000000..bfe1360 --- /dev/null +++ b/Plugin/Quote/Model/ShippingAddressManagement.php @@ -0,0 +1,69 @@ +fieldsHelper = $fieldsHelper; + } + + /** + * @param MagentoShippingAddressManagement $subject + * @param $cartId + * @param AddressInterface $address + */ + public function beforeAssign( + MagentoShippingAddressManagement $subject, + $cartId, + AddressInterface $address + ) { + $extAttributes = $address->getExtensionAttributes(); + $this->fieldsHelper->copyFieldsFromExtensionAttributesToObject($extAttributes, $address); + } +} diff --git a/Setup/Patch/Data/AddTigEavAttributes.php b/Setup/Patch/Data/AddTigEavAttributes.php new file mode 100644 index 0000000..984388b --- /dev/null +++ b/Setup/Patch/Data/AddTigEavAttributes.php @@ -0,0 +1,174 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + $this->eavConfig = $eavConfig; + $this->attributeRepository = $attributeRepository; + } + + /** + * @param string $entityType + * @param string $attribute + * @param string[] $forms + * + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\Framework\Exception\StateException + */ + private function addAttributeToForms( + $entityType, + $attribute, + $forms = [ + 'adminhtml_customer_address', + 'customer_address_edit', + 'customer_register_address', + 'customer_address' + ] + ) { + $attribute = $this->eavConfig->getAttribute($entityType, $attribute); + $attribute->addData([ + 'used_in_forms' => $forms + ]); + $this->attributeRepository->save($attribute); + } + + /** + * {@inheritDoc} + */ + public function apply() + { + $this->moduleDataSetup->getConnection()->startSetup(); + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + $eavSetup->addAttribute( + AttributeProvider::ENTITY, + 'tig_housenumber', + [ + 'type' => 'varchar', + 'input' => 'text', + 'label' => 'Housenumber', + 'visible' => true, + 'required' => false, + 'user_defined' => true, + 'system' => false, + 'group' => 'General', + 'sort_order' => 65, + 'global' => true, + 'visible_on_front' => true, + ] + ); + + $eavSetup->addAttribute( + AttributeProvider::ENTITY, + 'tig_housenumber_addition', + [ + 'type' => 'varchar', + 'input' => 'text', + 'label' => 'Housenumber Addition', + 'visible' => true, + 'required' => false, + 'user_defined' => true, + 'system' => false, + 'group' => 'General', + 'sort_order' => 66, + 'global' => true, + 'visible_on_front' => true, + ] + ); + + $eavSetup->addAttribute( + AttributeProvider::ENTITY, + 'tig_street', + [ + 'type' => 'varchar', + 'input' => 'text', + 'label' => 'Street', + 'visible' => true, + 'required' => false, + 'user_defined' => true, + 'system' => false, + 'group' => 'General', + 'sort_order' => 64, + 'global' => true, + 'visible_on_front' => true, + ] + ); + + $this->addAttributeToForms(AttributeProvider::ENTITY, 'tig_housenumber'); + $this->addAttributeToForms(AttributeProvider::ENTITY, 'tig_housenumber_addition'); + $this->addAttributeToForms(AttributeProvider::ENTITY, 'tig_street'); + + $this->moduleDataSetup->getConnection()->endSetup(); + } + + public function revert() + { + $this->moduleDataSetup->getConnection()->startSetup(); + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + $eavSetup->removeAttribute(AttributeProvider::ENTITY, 'tig_housenumber'); + $eavSetup->removeAttribute(AttributeProvider::ENTITY, 'tig_housenumber_addition'); + $eavSetup->removeAttribute(AttributeProvider::ENTITY, 'tig_street'); + $this->moduleDataSetup->getConnection()->endSetup(); + } + + /** + * {@inheritDoc} + */ + public static function getDependencies() + { + return []; + } + + /** + * {@inheritDoc} + */ + public function getAliases() + { + return []; + } +} diff --git a/Setup/Patch/Schema/AddQuoteAddressAttributes.php b/Setup/Patch/Schema/AddQuoteAddressAttributes.php new file mode 100644 index 0000000..b17e670 --- /dev/null +++ b/Setup/Patch/Schema/AddQuoteAddressAttributes.php @@ -0,0 +1,114 @@ +moduleDataSetup = $moduleDataSetup; + } + + + /** + * {@inheritDoc} + */ + public function apply() + { + $this->moduleDataSetup->startSetup(); + + $this->moduleDataSetup->getConnection()->addColumn( + $this->moduleDataSetup->getTable('quote_address'), + 'tig_street', + [ + 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'TIG Street' + ] + ); + + $this->moduleDataSetup->getConnection()->addColumn( + $this->moduleDataSetup->getTable('quote_address'), + 'tig_housenumber', + [ + 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'TIG Housenumber' + ] + ); + + $this->moduleDataSetup->getConnection()->addColumn( + $this->moduleDataSetup->getTable('quote_address'), + 'tig_housenumber_addition', + [ + 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'TIG Housenumber Addition' + ] + ); + + $this->moduleDataSetup->endSetup(); + } + + /** + * {@inheritDoc} + */ + public static function getDependencies() + { + return []; + } + + /** + * {@inheritDoc} + */ + public function getAliases() + { + return []; + } +} diff --git a/etc/di.xml b/etc/di.xml index 9285ce3..ecd611a 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -56,4 +56,21 @@ + + + + + + + + + + + + + + + + + diff --git a/etc/events.xml b/etc/events.xml new file mode 100644 index 0000000..00bb55c --- /dev/null +++ b/etc/events.xml @@ -0,0 +1,37 @@ + + + + + + diff --git a/etc/extension_attributes.xml b/etc/extension_attributes.xml index 2f62bf1..bf0760e 100644 --- a/etc/extension_attributes.xml +++ b/etc/extension_attributes.xml @@ -34,6 +34,6 @@ - + From 6e544d3af12dd34159a968e7eda581d646e61e2c Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Fri, 18 Mar 2022 09:04:19 +0100 Subject: [PATCH 02/36] POSTCODENL-363 Added LayoutProcessor and CountryCollection Plugin for exchanging data --- Plugin/Address/LayoutProcessor.php | 403 ------------------ .../Model/Checkout/LayoutProcessorPlugin.php | 202 +++++++++ .../Country/CollectionPlugin.php | 249 +++++++++++ etc/di.xml | 8 + 4 files changed, 459 insertions(+), 403 deletions(-) delete mode 100644 Plugin/Address/LayoutProcessor.php create mode 100644 Plugin/Model/Checkout/LayoutProcessorPlugin.php create mode 100644 Plugin/Model/ResourceModel/Country/CollectionPlugin.php diff --git a/Plugin/Address/LayoutProcessor.php b/Plugin/Address/LayoutProcessor.php deleted file mode 100644 index a4ac96d..0000000 --- a/Plugin/Address/LayoutProcessor.php +++ /dev/null @@ -1,403 +0,0 @@ -moduleConfiguration = $moduleConfiguration; - $this->scopeConfig = $scopeConfig; - $this->checkoutConfiguration = $checkoutConfiguration; - } - - /** - * @param $subject - * @param array $jsLayout - * - * @return array|mixed - */ - public function afterProcess($subject, array $jsLayout) - { - if ($this->moduleConfiguration->isModusOff()) { - return $jsLayout; - } - - if ($this->moduleConfiguration->getCheckoutCompatibility() != 'mageplaza' - && $this->moduleConfiguration->isBECheckEnabled()) { - $jsLayout = $this->processBeShippingFields($jsLayout); - $jsLayout = $this->processBeBillingFields($jsLayout); - } - - if ($this->moduleConfiguration->isNLCheckEnabled()) { - $jsLayout = $this->processShippingFields($jsLayout); - $jsLayout = $this->processBillingFields($jsLayout); - } - - return $jsLayout; - } - - /** - * @param $jsLayout - * - * @return mixed - */ - private function processBeShippingFields($jsLayout) - { - $shippingFields = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'] - ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']; - - $this->setFieldToAutocomplete($shippingFields); - if (!$this->moduleConfiguration->isNLCheckEnabled()) { - $shippingFields = $this->processBeAddress($shippingFields, 'shippingAddress', []); - } - - return $jsLayout; - } - - /** - * @param $jsLayout - * - * @return mixed - */ - private function processBeBillingFields($jsLayout) - { - $billingFields = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step'] - ['children']['payment']['children']['payments-list']['children']; - - foreach ($billingFields as $key => &$billingForm) { - if (strpos($key, '-form') === false) { - continue; - } - - $this->setFieldToAutocomplete($billingForm['children']['form-fields']['children']); - if (!$this->moduleConfiguration->isNLCheckEnabled()) { - $billingForm['children']['form-fields']['children'] = $this->processBeAddress( - $billingForm['children']['form-fields']['children'], - $billingForm['dataScopePrefix'], - [] - ); - } - } - - return $jsLayout; - } - - /** - * Hide the original postcode field and retrieve the postcode-field-group even when the NL check is off - * - * @param $fieldset - * @param $scope - * @param $deps - * - * @return mixed - */ - private function processBeAddress($fieldset, $scope, $deps) - { - $jsLayout = $this->processAddress($fieldset, $scope, $deps); - $jsLayout['postcode-field-group']['component'] = 'Magento_Ui/js/form/components/group'; - $jsLayout['postcode-field-group']['config']['template'] = 'TIG_Postcode/checkout/field-be-group'; - $this->setFieldToHide($jsLayout, 'postcode', true); - - return $jsLayout; - } - - /** - * @param $jsLayout - * - * @return mixed - */ - private function processShippingFields($jsLayout) - { - $shippingFields = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'] - ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']; - - $shippingFields = $this->processAddress($shippingFields, 'shippingAddress', []); - - $this->setFieldToHide($shippingFields, 'postcode', true); - $this->setFieldToHide($shippingFields, 'city'); - $this->setFieldToHide($shippingFields, 'street'); - - return $jsLayout; - } - - /** - * @param $jsLayout - * - * @return mixed - */ - private function processBillingFields($jsLayout) - { - $billingFields = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step'] - ['children']['payment']['children']['payments-list']['children']; - - if (!isset($billingFields) || !$this->isDisplayBillingOnPaymentMethodAvailable()) { - return $this->processSingleBillingForm($jsLayout) ?: $jsLayout; - } - - foreach ($billingFields as $key => &$billingForm) { - if (strpos($key, '-form') === false) { - continue; - } - - $billingForm['children']['form-fields']['children'] = $this->processAddress( - $billingForm['children']['form-fields']['children'], - isset($billingForm['dataScopePrefix']) ? $billingForm['dataScopePrefix'] : '', - [] - ); - - $this->setFieldToHide( - $billingForm['children']['form-fields']['children'], 'postcode', true - ); - $this->setFieldToHide($billingForm['children']['form-fields']['children'], 'city'); - $this->setFieldToHide($billingForm['children']['form-fields']['children'], 'street'); - } - - return $jsLayout; - } - - /** - * @param $jsLayout - * - * @return mixed - */ - private function processSingleBillingForm($jsLayout) - { - $billingFields = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step'] - ['children']['payment']['children']['afterMethods']['children']['billing-address-form']; - - if (!isset($billingFields)) { - return false; - } - - $billingFields['children']['form-fields']['children'] = $this->processAddress( - $billingFields['children']['form-fields']['children'], - isset($billingFields['dataScopePrefix']) ? $billingFields['dataScopePrefix'] : '', - [] - ); - - $this->setFieldToHide($billingFields['children']['form-fields']['children'], 'postcode', true); - $this->setFieldToHide($billingFields['children']['form-fields']['children'], 'city'); - $this->setFieldToHide($billingFields['children']['form-fields']['children'], 'street'); - - return $jsLayout; - } - - /** - * @param $fieldset - * @param $scope - * @param $deps - * - * @return mixed - */ - private function processAddress($fieldset, $scope, $deps) - { - $fieldset['postcode-field-group'] = [ - 'validation' => null, - 'component' => 'TIG_Postcode/js/view/form/fields', - 'type' => 'group', - 'provider' => 'checkoutProvider', - 'sortOrder' => $this->checkoutConfiguration->getPostcodeSortOrder(), - 'config' => [ - 'customScope' => $scope, - 'template' => 'TIG_Postcode/checkout/field-group', - 'additionalClasses' => $this->moduleConfiguration->getCheckoutCompatibility() - ], - 'deps' => $deps, - 'children' => [ - 'field-group' => [ - 'component' => 'uiComponent', - 'displayArea' => 'field-group', - 'children' => [ - 'postcode' => $fieldset['postcode'], - 'housenumber' => $this->getHouseNumberField($scope), - 'housenumber_addition' => $this->getHouseNumberAdditionField($scope) - ] - ] - ], - 'dataScope' => '', - 'visible' => true - ]; - $fieldset['country_id']['sortOrder'] = $this->checkoutConfiguration->getCountrySortOrder(); - $fieldset['city']['sortOrder'] = $this->checkoutConfiguration->getCitySortOrder(); - - return $fieldset; - } - - /** - * @param string $scope - * - * @return array - */ - private function getHouseNumberField($scope = 'shippingAddress') - { - return [ - 'component' => 'Magento_Ui/js/form/element/abstract', - 'config' => [ - 'customScope' => $scope . '.custom_attributes', - 'template' => 'ui/form/field', - 'elementTmpl' => 'TIG_Postcode/form/element/housenumber' - ], - 'provider' => 'checkoutProvider', - 'dataScope' => $scope . '.custom_attributes.tig_housenumber', - 'label' => __('House number'), - 'sortOrder' => '115', - 'validation' => [ - 'required-entry' => true, - ], - 'visible' => true - ]; - } - - /** - * @param string $scope - * - * @return array - */ - private function getHouseNumberAdditionField($scope = 'shippingAddress') - { - return [ - 'component' => 'Magento_Ui/js/form/element/abstract', - 'config' => [ - 'customScope' => $scope . '.custom_attributes', - 'template' => 'ui/form/field', - 'elementTmpl' => 'TIG_Postcode/form/element/addition' - ], - 'provider' => 'checkoutProvider', - 'dataScope' => $scope . '.custom_attributes.tig_housenumber_addition', - 'label' => __('Addition'), - 'sortOrder' => '120', - 'validation' => [ - 'required-entry' => false, - ], - 'visible' => true - ]; - } - - /** - * Sets visible on false for the shipping fields that are re-writend by the postcode service. - * - * @param $fields - * @param $section - * @param bool $disableRequired - * @param bool $be - */ - private function setFieldToHide(&$fields, $section, $disableRequired = false) - { - $additionalClass = null; - if (isset($fields[$section]['config']['additionalClasses'])) { - $additionalClass = $fields[$section]['config']['additionalClasses']; - } - - if ($section == 'street' || $section == 'city') { - $additionalClass = $additionalClass . ' ' . 'tig_hidden'; - } - - if ($section !== 'city') { - $fields[$section]['visible'] = false; - } - - if ($disableRequired) { - $fields[$section]['validation']['required-entry'] = false; - } - - $fields[$section]['config']['additionalClasses'] = $additionalClass; - } - - /** - * @param $fields - */ - private function setFieldToAutocomplete(&$fields) - { - $additionalClass = null; - if (isset($fields['postcode']['config']['additionalClasses'])) { - $additionalClass = $fields['postcode']['config']['additionalClasses']; - } - $additionalClass .= ' tig_zipcodezone_autocomplete'; - $fields['postcode']['config']['additionalClasses'] = $additionalClass; - $fields['postcode']['config']['elementTmpl'] = 'TIG_Postcode/form/element/autocomplete'; - $fields['postcode']['sortOrder'] = $this->checkoutConfiguration->getPostcodeSortOrder(); - - $additionalClass = null; - if (isset($fields['street']['children'][0]['config']['additionalClasses'])) { - $additionalClass = $fields['street']['children'][0]['config']['additionalClasses']; - } - - $additionalClass .= ' tig_street_autocomplete'; - $fields['street']['children'][0]['config']['additionalClasses'] = $additionalClass; - $fields['street']['children'][0]['config']['elementTmpl'] = 'TIG_Postcode/form/element/autocomplete'; - - $fields['country_id']['sortOrder'] = $this->checkoutConfiguration->getCountrySortOrder(); - $fields['city']['sortOrder'] = $this->checkoutConfiguration->getCitySortOrder(); - } - - /** - * @return bool - */ - private function isDisplayBillingOnPaymentMethodAvailable() - { - return (bool) !$this->scopeConfig->getValue( - 'checkout/options/display_billing_address_on', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - } -} diff --git a/Plugin/Model/Checkout/LayoutProcessorPlugin.php b/Plugin/Model/Checkout/LayoutProcessorPlugin.php new file mode 100644 index 0000000..3331445 --- /dev/null +++ b/Plugin/Model/Checkout/LayoutProcessorPlugin.php @@ -0,0 +1,202 @@ +arrayManager = $arrayManager; + $this->notifier = $notifier; + } + + /** + * Adds tracked fields so we can dynamically add classes or visibility + * + * @param $jsLayout + * @param $fieldsetChildren + * + * @return array + */ + public function addTrackedFields($jsLayout, $fieldsetChildren): array + { + foreach ( + [ + 'street', + 'city', + 'postcode' + ] as $key + ) { + $jsLayout = $this->arrayManager->set($fieldsetChildren . '/' . $key . '/tracks/additionalClasses', $jsLayout, true); + } + + return $jsLayout; + } + + /** + * @param $dataScope + * @param $index + * @param $label + * @param array $options + * + * @return array + */ + private function createBaseFieldConfig($dataScope, $index, $label, $options = []) + { + return array_merge_recursive([ + 'component' => "Magento_Ui/js/form/element/abstract", + 'dataScope' => $dataScope . '.custom_attributes.' . $index, + 'config' => [ + 'customScope' => $dataScope . '.custom_attributes', + 'template' => 'ui/form/field', + 'elementTmpl' => 'ui/form/element/input', + ], + 'label' => __($label), + 'provider' => 'checkoutProvider', + 'visible' => false, + 'tracks' => [ + 'additionalClasses' => true + ] + ], $options); + } + + /** + * Create Field definitions + * + * @param $dataScope + * + * @return array[] + */ + public function createHousenumberFieldsDefinition($dataScope) + { + return [ + 'tig_housenumber' => $this->createBaseFieldConfig($dataScope, 'tig_housenumber', 'Housenumber', ["sortOrder" => 51]), + 'tig_housenumber_addition' => $this->createBaseFieldConfig($dataScope, 'tig_housenumber_addition', 'Housenumber addition', ["sortOrder" => 52]), + 'tig_street' => $this->createBaseFieldConfig($dataScope, 'tig_street', 'Street Address', ["sortOrder" => 53]), + ]; + } + + /** + * Split string and remove last n element(s) + * + * @param $path + * @param string $delimiter + * @param int $count + * + * @return string + */ + private function getParentPath($path, $delimiter = '/', $count = 1) + { + $splitPath = explode($delimiter, $path); + for ($i = 0; $i < $count; $i++) { + array_pop($splitPath); + } + + return implode($delimiter, $splitPath); + } + + /** + * Add message to admin panel + * + * Used when confronted with incompatible checkout + * + * @param $message + */ + public function addAdminErrorMessage($message) + { + $this->notifier->addMajor("TIG Postcode", "Postcodeservice detected one or more compability issues with your shop setup"); + } + + /** + * Modify checkout to add fields and change postcode field behaviour + * + * @param LayoutProcessor $subject + * @param array $jsLayout + * + * @return array + * + * @see LayoutProcessor::process() + */ + public function afterProcess( + $subject, + $jsLayout + ) { + $postalCodePaths = $this->arrayManager->findPaths('postcode', $jsLayout); + foreach ($postalCodePaths as $postalCodePath) { + $fieldsetChildren = $this->getParentPath($postalCodePath, '/'); + if ($this->arrayManager->get($postalCodePath . '/component', $jsLayout) !== self::MAGENTO_POSTCODE_COMPONENT_JS) { + $this->addAdminErrorMessage('Incompatible postcode field found @ ' . $postalCodePath . ': ' . $this->arrayManager->get($postalCodePath . '/component', $jsLayout)); + continue; + } + + // Update PostcodeField + $jsLayout = $this->arrayManager->set($postalCodePath . '/component', $jsLayout, self::TIG_POSTCODE_COMPONENT_JS); + $jsLayout = $this->arrayManager->set($postalCodePath . '/config/elementTmpl', $jsLayout, self::TIG_POSTCODE_COMPONENT_TEMPLATE); + + // Add housenumber fields + $postcodeParentDataScope = $this->getParentPath($this->arrayManager->get($postalCodePath . '/dataScope', $jsLayout), "."); + $jsLayout = $this->arrayManager->merge( + $fieldsetChildren, + $jsLayout, + $this->createHousenumberFieldsDefinition($postcodeParentDataScope) + ); + + // Modify fields + $jsLayout = $this->addTrackedFields($jsLayout, $fieldsetChildren); + } + + return $jsLayout; + } +} diff --git a/Plugin/Model/ResourceModel/Country/CollectionPlugin.php b/Plugin/Model/ResourceModel/Country/CollectionPlugin.php new file mode 100644 index 0000000..e75d3e8 --- /dev/null +++ b/Plugin/Model/ResourceModel/Country/CollectionPlugin.php @@ -0,0 +1,249 @@ + [ + self::SORT_ORDER_BASE => 10, + self::SORT_ORDER_INCREMENT => 0.1 + ] + ]; + + /** + * @var ModuleConfiguration + */ + private $moduleConfiguration; + + /** + * @var FullModuleList + */ + private $fullModuleList; + + public function __construct( + ModuleConfiguration $moduleConfiguration, + FullModuleList $fullModuleList + ){ + $this->moduleConfiguration = $moduleConfiguration; + $this->fullModuleList = $fullModuleList; + } + + /** + * @param $sortOrderBase + * @param $sortOrderIncrement + * + * @return array + */ + private function getPostcodeNLConfig($sortOrderBase, $sortOrderIncrement): array + { + return [ + 'enabled' => $this->moduleConfiguration->isNLCheckEnabled(), + 'postcode' => [ + 'sortOrder' => $sortOrderBase, + 'classes' => [ + 'tig_postcode_field' => true, + 'tig_postcode_nl' => true + ], + 'visible' => true, + ], + 'tig_housenumber' => [ + 'sortOrder' => $sortOrderBase + $sortOrderIncrement, + 'visible' => true, + 'classes' => [ + 'tig_housenumber_field' => true, + 'tig_postcode_nl' => true + + ] + ], + 'tig_housenumber_addition' => [ + 'sortOrder' => $sortOrderBase + 2 * $sortOrderIncrement, + 'visible' => true, + 'classes' => [ + 'tig_housenumber_addition_field' => true, + 'tig_postcode_nl' => true + ] + ], + 'tig_street' => [ + 'sortOrder' => $sortOrderBase + 3 * $sortOrderIncrement, + 'visible' => true, + 'classes' => [ + 'tig_street_field' => true, + 'tig_postcode_nl' => true + ] + ], + 'street' => [ + 'sortOrder' => $sortOrderBase + 4 * $sortOrderIncrement, + 'visible' => false, + 'classes' => [ + 'tig_street_fields' => true, + 'tig_postcode_nl' => true + ] + ], + 'city' => [ + 'sortOrder' => $sortOrderBase + 5 * $sortOrderIncrement, + 'visible' => false, + 'classes' => [ + 'tig_city_field' => true, + 'tig_postcode_nl' => true + ] + ] + ]; + } + + /** + * @param $sortOrderBase + * @param $sortOrderIncrement + * + * @return array + */ + private function getPostcodeBEConfig($sortOrderBase, $sortOrderIncrement) { + return [ + 'enabled' => $this->moduleConfiguration->isBECheckEnabled(), + 'postcode' => [ + 'sortOrder' => $sortOrderBase, + 'classes' => [ + 'tig_postcode_field' => true, + 'tig_postcode_be' => true + ], + 'visible' => true, + ], + 'tig_housenumber' => [ + 'sortOrder' => $sortOrderBase + $sortOrderIncrement, + 'visible' => true, + 'classes' => [ + 'tig_housenumber_field' => true, + 'tig_postcode_be' => true + ] + ], + 'tig_housenumber_addition' => [ + 'sortOrder' => $sortOrderBase + 2 * $sortOrderIncrement, + 'visible' => true, + 'classes' => [ + 'tig_housenumber_addition_field' => true, + 'tig_postcode_be' => true + ] + ], + 'tig_street' => [ + 'sortOrder' => $sortOrderBase + 3 * $sortOrderIncrement, + 'visible' => true, + 'classes' => [ + 'tig_street_field' => true, + 'tig_postcode_be' => true + ], + ], + 'street' => [ + 'sortOrder' => $sortOrderBase + 4 * $sortOrderIncrement, + 'visible' => false, + 'classes' => [ + 'tig_street_fields' => true, + 'tig_postcode_be' => true + ] + ], + 'city' => [ + 'sortOrder' => $sortOrderBase + 5 * $sortOrderIncrement, + 'visible' => true, + 'classes' => [ + 'tig_city_field' => true, + 'tig_postcode_be' => true + ] + ], + ]; + } + + /** + * @param $countryOption + * @param $country + * @param $sortOrderBase + * @param $sortOrderIncrement + */ + private function addPostcodeConfig(&$countryOption, $country, $sortOrderBase, $sortOrderIncrement) + { + if ($country === "NL") { + $countryOption['tig_postcode'] = $this->getPostcodeNLConfig($sortOrderBase, $sortOrderIncrement); + } + + if ($country === "BE") { + $countryOption['tig_postcode'] = $this->getPostcodeBEConfig($sortOrderBase, $sortOrderIncrement); + } + } + + /** + * @return int[] + */ + private function getSortOrderAndIncrement(){ + $sortOrderBase = 81; + $sortOrderIncrement = 1; + + foreach(self::SORT_ORDER_CONFIG as $module => $config){ + if(!$this->fullModuleList->has($module)) { + continue; + } + $sortOrderBase = $config[self::SORT_ORDER_BASE]; + $sortOrderIncrement = $config[self::SORT_ORDER_INCREMENT]; + } + + return [$sortOrderBase, $sortOrderIncrement]; + } + + /** + * @param \Magento\Directory\Model\ResourceModel\Country\Collection$subject + * @param $result + * + * @return mixed + * @see \Magento\Directory\Model\ResourceModel\Country\Collection::toOptionArray + */ + public function afterToOptionArray( + $subject, + $result + ) { + list($sortOrderBase, $sortOrderIncrement) = $this->getSortOrderAndIncrement(); + + foreach ($result as &$countryOption) { + $this->addPostcodeConfig( + $countryOption, + $countryOption['value'], + $sortOrderBase, + $sortOrderIncrement + ); + } + + return $result; + } +} diff --git a/etc/di.xml b/etc/di.xml index 9285ce3..a8dbc19 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -56,4 +56,12 @@ + + + + + + + + From 5e8fa471e8bcc4fc83469daded793c95d077cbf4 Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Fri, 18 Mar 2022 09:25:56 +0100 Subject: [PATCH 03/36] POSTCODENL-365 Added Knockout bindings for all fields --- .../web/js/form/element/helpers/cityHelper.js | 59 +++ .../js/form/element/helpers/countryHelper.js | 120 ++++++ .../element/helpers/magentoStreetFieldset.js | 61 +++ .../form/element/helpers/tigFieldsHelper.js | 72 ++++ .../js/form/element/helpers/tigStreetField.js | 61 +++ .../web/js/form/element/tig-postcode-field.js | 406 ++++++++++++++++++ view/base/web/js/helper/field-types.js | 40 ++ view/base/web/js/helper/reorder-fields.js | 138 ++++++ 8 files changed, 957 insertions(+) create mode 100644 view/base/web/js/form/element/helpers/cityHelper.js create mode 100644 view/base/web/js/form/element/helpers/countryHelper.js create mode 100644 view/base/web/js/form/element/helpers/magentoStreetFieldset.js create mode 100644 view/base/web/js/form/element/helpers/tigFieldsHelper.js create mode 100644 view/base/web/js/form/element/helpers/tigStreetField.js create mode 100644 view/base/web/js/form/element/tig-postcode-field.js create mode 100644 view/base/web/js/helper/field-types.js create mode 100644 view/base/web/js/helper/reorder-fields.js diff --git a/view/base/web/js/form/element/helpers/cityHelper.js b/view/base/web/js/form/element/helpers/cityHelper.js new file mode 100644 index 0000000..8b11895 --- /dev/null +++ b/view/base/web/js/form/element/helpers/cityHelper.js @@ -0,0 +1,59 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([ + 'underscore', + 'knockout', + '../../../helper/field-types', +], function (_,ko, FieldTypes) { + 'use strict'; + + return { + defaults: { + imports: { + updateCity: '${ $.parentName }.city:value', + }, + modules: { + city: '${ $.parentName }.city', + } + }, + + /** + * Called when City is updated + * + * @param value + */ + updateCity: function(value){ + if (this.currentPostcodeHandler && value) { + this.currentPostcodeHandler.handle(FieldTypes.city, value); + } + }, + } +}); diff --git a/view/base/web/js/form/element/helpers/countryHelper.js b/view/base/web/js/form/element/helpers/countryHelper.js new file mode 100644 index 0000000..0824beb --- /dev/null +++ b/view/base/web/js/form/element/helpers/countryHelper.js @@ -0,0 +1,120 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([ + 'underscore', + 'knockout', + '../../../helper/field-types', + + '../../../postcode-handler/postcode-nl', + '../../../postcode-handler/postcode-be' +], function (_,ko, FieldTypes, postcodeNL, postcodeBE) { + 'use strict'; + + const KnownHandlers = { + 'NL': postcodeNL, + 'BE': postcodeBE + }; + + return { + defaults: { + imports: { + updateCountry: '${ $.parentName }.country_id:value', + updateCountryOptions: '${ $.parentName }.country_id:indexedOptions', + }, + modules: { + city: '${ $.parentName }.city', + } + }, + + /** + * Called when Country is updated (ISO Value) + * + * @param value + */ + updateCountry: function(value){ + if (!value) { + return; + } + this.countryISO = value; + this.changeHandlerAfterUpdate(); + }, + + /** + * Called when Country Options are updated (contains Postcode Config) + * + * @param value + */ + updateCountryOptions: function(value) { + if (!value) { + return; + } + this.countryOptions = value; + this.changeHandlerAfterUpdate(); + }, + + /** + * Change PostCode Handler after update + */ + changeHandlerAfterUpdate: function() { + if (!this.countryOptions || !this.countryISO) { + return; + } + + if ( + this.currentPostcodeHandler && + this.currentPostcodeHandler.getISOCode() === this.countryISO + ) { + return; + } + + if (this.currentPostcodeHandler) { + this.currentPostcodeHandler.destroy(); + this.currentPostcodeHandler = null; + } + + if(!(this.countryISO in KnownHandlers)) { + return; + } + + var isoOptions = {}; + if (this.countryOptions && this.countryISO in this.countryOptions){ + isoOptions = this.countryOptions[this.countryISO]; + } + + this.currentPostcodeHandler = new KnownHandlers[this.countryISO](isoOptions, this); + + if(this.uiInitialized) { + this.currentPostcodeHandler.reset(); + this.currentPostcodeHandler.handle(); + } + }, + } +}); diff --git a/view/base/web/js/form/element/helpers/magentoStreetFieldset.js b/view/base/web/js/form/element/helpers/magentoStreetFieldset.js new file mode 100644 index 0000000..acf9362 --- /dev/null +++ b/view/base/web/js/form/element/helpers/magentoStreetFieldset.js @@ -0,0 +1,61 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([ + 'underscore', + 'knockout', + 'jquery', + '../../../helper/field-types', +], function ( _,ko,$, FieldTypes) { + 'use strict'; + + return { + defaults: { + imports: { + onMagentoStreetValueUpdate: '${ $.parentName }.street.0:value', + }, + + modules: { + magento_street: '${ $.parentName }.street', + } + }, + + /** + * Called when Street is updated + * + * @param value + */ + onMagentoStreetValueUpdate: function(value){ + if (this.currentPostcodeHandler && value) { + this.currentPostcodeHandler.handle(FieldTypes.magento_street, value); + } + } + } +}); diff --git a/view/base/web/js/form/element/helpers/tigFieldsHelper.js b/view/base/web/js/form/element/helpers/tigFieldsHelper.js new file mode 100644 index 0000000..de19581 --- /dev/null +++ b/view/base/web/js/form/element/helpers/tigFieldsHelper.js @@ -0,0 +1,72 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([ + 'underscore', + 'knockout', + '../../../helper/field-types', +], function (_,ko, FieldTypes) { + 'use strict'; + + return { + defaults: { + imports: { + updateHousenumber: '${ $.parentName }.tig_housenumber:value', + updateHouseNumberAddition: '${ $.parentName }.tig_housenumber_addition:value', + }, + modules: { + housenumber: '${ $.parentName }.tig_housenumber', + housenumber_addition: '${ $.parentName }.tig_housenumber_addition', + } + }, + + /** + * Called when Housenumber is updated + * + * @param value + */ + updateHousenumber: function(value){ + if (this.currentPostcodeHandler && value) { + this.currentPostcodeHandler.handle(FieldTypes.house_number, value); + } + }, + + /** + * Called when Housenumber addition is updated + * + * @param value + */ + updateHouseNumberAddition: function(value){ + if (this.currentPostcodeHandler && value) { + this.currentPostcodeHandler.handle(FieldTypes.house_number_addition, value); + } + }, + } +}); diff --git a/view/base/web/js/form/element/helpers/tigStreetField.js b/view/base/web/js/form/element/helpers/tigStreetField.js new file mode 100644 index 0000000..0ca9738 --- /dev/null +++ b/view/base/web/js/form/element/helpers/tigStreetField.js @@ -0,0 +1,61 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([ + 'underscore', + 'knockout', + 'jquery', + '../../../helper/field-types', +], function ( _,ko,$, FieldTypes) { + 'use strict'; + + return { + defaults: { + imports: { + onStreetValueUpdate: '${ $.parentName }.tig_street:value', + }, + modules: { + street: '${ $.parentName }.tig_street', + } + }, + + + /** + * Called when Street is updated + * + * @param value + */ + onStreetValueUpdate: function(value){ + if (this.currentPostcodeHandler && value) { + this.currentPostcodeHandler.handle(FieldTypes.street, value); + } + } + } +}); diff --git a/view/base/web/js/form/element/tig-postcode-field.js b/view/base/web/js/form/element/tig-postcode-field.js new file mode 100644 index 0000000..25103f5 --- /dev/null +++ b/view/base/web/js/form/element/tig-postcode-field.js @@ -0,0 +1,406 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([ + 'Magento_Ui/js/form/element/post-code', + 'jquery', + 'knockout', + 'mageUtils', + + './helpers/tigStreetField', + './helpers/cityHelper', + './helpers/countryHelper', + './helpers/tigFieldsHelper', + './helpers/magentoStreetFieldset', + + '../../helper/field-types', + '../../helper/reorder-fields' +], function (MagentoUiPostcode, $, ko, utils, + TigStreetHelper, + CityHelper, + CountryHelper, + TigFieldsHelper, + MagentoStreetHelper, + FieldTypes, reorderFields +) { + 'use strict'; + + return MagentoUiPostcode.extend(utils.extend({ + uiInitialized: false, + elemCount: 0, + + currentPostcodeHandler: null, + + defaults: { + template: 'TIG_Postcode/form/collection', + imports: { + updatePostcode: '${ $.name }:value' + }, + + modules: { + postcode: '${ $.parentName }.postcode', + fieldSet: '${ $.parentName }' + } + }, + + initialize: function(){ + this._super(); + }, + + /** + * After Render at this moment all elements are in the DOM so it is safe + * to restart the handler to initialize fields. + */ + afterRender: function(){ + if (!this.currentPostcodeHandler || this.uiInitialized) { + return + } + this.uiInitialized = true; + this.currentPostcodeHandler.reset(); + this.currentPostcodeHandler.handle(); + }, + + /** + * Called when Postcode is updated + * + * @param value + */ + updatePostcode: function(value){ + if (this.currentPostcodeHandler && value) { + this.currentPostcodeHandler.handle(FieldTypes.postcode, value); + } + }, + + /*********************************************************************** + * Accessors fields and configuration, called by postcodeHandler * + ***********************************************************************/ + /** + * Get Related field by FieldType + * + * @param fieldType + * @returns {null|*} + */ + getElement: function(fieldType){ + switch(fieldType){ + case FieldTypes.street: + return this.street(); + case FieldTypes.city: + return this.city(); + case FieldTypes.postcode: + return this.postcode(); + case FieldTypes.house_number: + return this.housenumber(); + case FieldTypes.house_number_addition: + return this.housenumber_addition(); + case FieldTypes.magento_street: + return this.magento_street(); + } + return null; + }, + + /** + * Reset field config to default + * + * Used to restore related fields back to default + */ + resetFieldsConfig: function() { + for(const key of Object.keys(FieldTypes)){ + const fieldType = FieldTypes[key]; + const elem = this.getElement(fieldType); + if (elem && 'tig_defaults' in elem) { + this.setFieldConfig(elem, elem.tig_defaults, true); + delete elem.tig_defaults; + } + } + reorderFields(this.fieldSet()); + }, + + /** + * Store default value so we can restore the fields back to its default + * + * @param field + * @param key + * @param value + */ + storeDefault: function(field, key, value) { + if (!('tig_defaults' in field)){ + field.tig_defaults = {}; + } + + if(key in field.tig_defaults) { + console.warn("Trying to overwrite default value ", field.index, key, value, field.tig_defaults[key]); + return; + } + + if(typeof value === 'function') { + value = value(); + } + if(typeof value === 'object') { + value = _.assign({}, value); + } + field.tig_defaults[key] = value; + }, + + /** + * Set Field Config + * + * We obtain a config array through the CountryOptions containing the + * initial settings for each related field. + * + * See PHP Class \TIG\Postcode\Model\ResourceModel\Country\CollectionPlugin + * @param field + * @param config + * @param isReset + */ + setFieldConfig: function (field, config, isReset = false){ + if ('sortOrder' in config) { + if(!isReset && 'sortOrder' in field) { + this.storeDefault( + field, + 'sortOrder', + field.sortOrder + ); + } + field.sortOrder = config.sortOrder; + } + + if ('visible' in config) { + if (!isReset && 'visible' in field) { + this.storeDefault( + field, + 'visible', + field.visible + ); + } + + this.showHideField(field, config.visible); + } + + if ('rows' in config) { + if (!isReset) { + this.storeDefault(field, 'rows', field.elems().length); + } + if ('elems' in field) { + for(var i = 0; i < field.elems().length; i++) { + this.showHideField(field.elems()[i], i < config.rows); + } + } + } + + if (!isReset && 'classes' in config){ + if('additionalClasses' in field) { + this.storeDefault( + field, + 'classes', + field.additionalClasses + ); + } + + this.addClassesToField( + field, + config.classes + ); + } + + if(isReset) { + this.disableTigClasses(field); + } + }, + + /*** + * Set config for all known fields + * + * @param config + */ + setFieldsConfig: function(config) { + for(const key in FieldTypes){ + var fieldType = FieldTypes[key]; + const elem = this.getElement(fieldType); + if(fieldType in config && elem){ + this.setFieldConfig(elem, config[fieldType]); + } + } + + if (this.containers && this.containers.length > 0) { + reorderFields(this.fieldSet()); + } + }, + + /*********************************************************************** + * Accessors for field changes (classes, visibility, rowCount) * + ***********************************************************************/ + + /** + * Add CSS Classes to field + * + * @param field fieldType or Field + * @param classes + */ + addClassesToField: function(field, classes){ + if (typeof field !== 'object') { + field = this.getElement(field); + } + if (typeof field.additionalClasses == 'function') { + field.additionalClasses( + _.extend( + field.additionalClasses(), + classes + ) + ); + return; + } + field.additionalClasses = _.extend(field.additionalClasses, classes); + }, + + /** + * Disable TIG Classes + * + * Sets all `tig_%` classes to disabled since + * removing classes from additionalClasses does not work + * + * @param field + */ + disableTigClasses: function(field) { + if (typeof field !== 'object') { + field = this.getElement(field); + } + + var classes = this.getClassesFromField(field); + for(var index in classes){ + if(index.startsWith('tig_')){ + classes[index] = false; + } + } + this.addClassesToField(field, classes); + }, + + /** + * Get CSS Classes from field + * + * @param field + * @returns {number|string|*} + */ + getClassesFromField: function(field){ + if (typeof field !== 'object') { + field = this.getElement(field); + } + + if(typeof field.additionalClasses == 'function') { + return field.additionalClasses(); + } + return field.additionalClasses; + }, + + /** + * Show or hide field + * + * @param field + * @param show + */ + showHideField: function(field, show) { + if (typeof field !== 'object') { + field = this.getElement(field); + } + + if('visible' in field) { + field.visible(show); + } + + this.addClassesToField(field, {'tig_hidden': !show}); + }, + + /** + * Set field value + * + * This function also supports street fieldsets + * + * @param field + * @param value + */ + setFieldValue: function(field, value) { + if (typeof field !== 'object') { + field = this.getElement(field); + } + + if (!field){ + return; + } + + if ('elems' in field && field.elems().length > 0){ + this.setFieldValue(field.elems()[0], value); + return; + } + + if ('value' in field && typeof field.value === 'function') { + field.value(value); + return; + } + + if ('value' in field) { + field.value = value; + } + }, + + /** + * Set field value + * + * This function also supports street fieldsets + * + * @param field + */ + getFieldValue: function(field) { + if (typeof field !== 'object') { + field = this.getElement(field); + } + + if (!field){ + return null; + } + + if ('elems' in field && field.elems().length > 0){ + return this.getFieldValue(field.elems()[0]); + } + + if ('value' in field && typeof field.value === 'function') { + return field.value(); + } + + if ('value' in field) { + return field.value; + } + return null; + }, + + /** + * We expand this object with functions from below helpers, these help + * too keep this file smaller and more readable. + */ + }, TigStreetHelper, CityHelper, CountryHelper, TigFieldsHelper, MagentoStreetHelper)); +}); diff --git a/view/base/web/js/helper/field-types.js b/view/base/web/js/helper/field-types.js new file mode 100644 index 0000000..3f98516 --- /dev/null +++ b/view/base/web/js/helper/field-types.js @@ -0,0 +1,40 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([], function(){ + return Object.seal({ + postcode: 'postcode', + house_number: 'tig_housenumber', + house_number_addition: 'tig_housenumber_addition', + street: 'tig_street', + magento_street: 'street', + city: 'city' + }); +}); diff --git a/view/base/web/js/helper/reorder-fields.js b/view/base/web/js/helper/reorder-fields.js new file mode 100644 index 0000000..04829b2 --- /dev/null +++ b/view/base/web/js/helper/reorder-fields.js @@ -0,0 +1,138 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([ + 'underscore', + 'knockout' +], function (_, ko) { + 'use strict'; + + /** + * Get sortOrder for field + * + * @param idx + * @param elems + * @returns {null|number} + */ + function getSortOrderFor(idx, elems){ + for(const elem of elems) { + if (elem.name === idx) { + const sortOrder = parseFloat(elem.sortOrder); + if(isNaN(sortOrder)) { + return null; + } + return sortOrder; + } + } + return null; + } + + /** + * Normalize Sort Orders + * + * To sort the fields dynamically we need to have an numeric sort order. + * Some fields have a 'before: element-x' or 'after: element-y' we solve this + * + * By adding .01 to the related field, some One Step Checkouts have low + * numeric values 1 - 10 so we add a very small number instead of integers. + * + * This loops max 5 times so we can resolve up to 5 dependency layers + * For Example: element x after element y, element y after element z ... + * + * @param elementArray + * @returns {boolean} + */ + function normalizeSortOrders(elementArray) { + var allResolved = true; + var maxLoops = 5; + do { + allResolved = true; + + for (const elem of elementArray) { + if (typeof elem.sortOrder === 'object') { + if ('after' in elem.sortOrder) { + const newSortOrder = getSortOrderFor( + elem.sortOrder.after, + elementArray + ); + if (newSortOrder === null) { + allResolved = false; + continue; + } + elem.sortOrder = newSortOrder + 0.01; + continue; + } + + if ('before' in elem.sortOrder) { + const newSortOrder = getSortOrderFor( + elem.sortOrder.before, + elementArray + ); + if (newSortOrder === null) { + allResolved = false; + continue; + } + elem.sortOrder = newSortOrder - 0.01; + continue; + } + } + + if (typeof elem.sortOrder === "string") { + elem.sortOrder = parseFloat(elem.sortOrder); + } + } + + } while(!allResolved && --maxLoops > 0); + + return allResolved; + } + + return function(fieldset){ + normalizeSortOrders(fieldset.elems()); + + fieldset.elems.sort(((a, b) => { + if(typeof a.sortOrder === 'undefined' || typeof b.sortOrder === 'undefined'){ + return 0; + } + + const sortOrderA = a.sortOrder; + const sortOrderB = b.sortOrder; + + if (sortOrderA < sortOrderB) { + return -1; + } + + if (sortOrderA > sortOrderB) { + return 1; + } + return 0; + })); + } +}); From 9bc54155bdedbfd3bb41404b6fbc094e2636c2fa Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Fri, 18 Mar 2022 09:31:22 +0100 Subject: [PATCH 04/36] POSTCODENL-366 Added Business logic --- view/base/web/js/helper/postcode-api.js | 69 +++++ view/base/web/js/helper/postcode-config.js | 57 +++++ .../web/js/postcode-handler/postcode-be.js | 240 ++++++++++++++++++ .../web/js/postcode-handler/postcode-de.js | 74 ++++++ .../js/postcode-handler/postcode-handler.js | 169 ++++++++++++ .../web/js/postcode-handler/postcode-nl.js | 155 +++++++++++ 6 files changed, 764 insertions(+) create mode 100644 view/base/web/js/helper/postcode-api.js create mode 100644 view/base/web/js/helper/postcode-config.js create mode 100644 view/base/web/js/postcode-handler/postcode-be.js create mode 100644 view/base/web/js/postcode-handler/postcode-de.js create mode 100644 view/base/web/js/postcode-handler/postcode-handler.js create mode 100644 view/base/web/js/postcode-handler/postcode-nl.js diff --git a/view/base/web/js/helper/postcode-api.js b/view/base/web/js/helper/postcode-api.js new file mode 100644 index 0000000..aff5518 --- /dev/null +++ b/view/base/web/js/helper/postcode-api.js @@ -0,0 +1,69 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define(['jquery', './postcode-config'], function($, postcodeConfig){ + + return { + getPostCodeNL: function (postcode, house_number) { + return $.ajax( + { + method: 'GET', + url: postcodeConfig.getWebserviceURL_NL(), + showLoader: true, + data: { + huisnummer: house_number, + postcode: postcode + } + }); + }, + + getPostCodeBE: function (postcode) { + return $.ajax({ + method : 'GET', + url : postcodeConfig.getWebserviceURL_BE_Postcode(), + data : { + zipcodezone : postcode + } + }); + }, + + getStreetBe: function (postcode, street, city) { + return $.ajax({ + method : 'GET', + url : postcodeConfig.getWebserviceURL_BE_Street(), + data : { + zipcode : postcode, + city : city, + street : street + }, + }); + } + } +}); diff --git a/view/base/web/js/helper/postcode-config.js b/view/base/web/js/helper/postcode-config.js new file mode 100644 index 0000000..0cebbcf --- /dev/null +++ b/view/base/web/js/helper/postcode-config.js @@ -0,0 +1,57 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define(['underscore'], function(_) { + var postcodeConfig = { + 'action_url': { + 'postcode_service': '/postcode/address/service', + 'postcode_be_getstreet': '/postcode/address/service/be/getstreet', + 'postcode_be_getpostcode': '/postcode/address/service/be/getpostcode' + } + }; + + if ('checkoutConfig' in window && 'postcode' in window.checkoutConfig) { + postcodeConfig = _.extend(postcodeConfig, window.checkoutConfig.postcode); + } + + return { + getWebserviceURL_NL : function() { + return postcodeConfig.action_url.postcode_service; + }, + + getWebserviceURL_BE_Street: function() { + return postcodeConfig.action_url.postcode_be_getstreet; + }, + + getWebserviceURL_BE_Postcode: function() { + return postcodeConfig.action_url.postcode_be_getpostcode; + } + } +}); diff --git a/view/base/web/js/postcode-handler/postcode-be.js b/view/base/web/js/postcode-handler/postcode-be.js new file mode 100644 index 0000000..1d45c7c --- /dev/null +++ b/view/base/web/js/postcode-handler/postcode-be.js @@ -0,0 +1,240 @@ +define( + [ + 'jquery', + 'knockout', + 'underscore', + './postcode-handler', + '../helper/field-types', + '../helper/postcode-api', + 'jquery-ui-modules/autocomplete' + ], + function ( + $, + ko, + _, + PostcodeHandler, + FieldTypes, + PostcodeApi + ) { + 'use strict'; + + const postcodeBeRegex = /^[1-9][0-9]{3}$/i; + + const states = Object.seal({ + INIT: PostcodeHandler.INIT, + IDLE: 'postcode_idle', + POSTCODE_CALL_MADE: 'postcode_call_made', + POSTCODE_CALL_FAILED: 'postcode_call_failed', + POSTCODE_SHOW_FIELDS_SUGGESTION: 'postcode_show_fields_suggestion', + POSTCODE_SHOW_FIELDS_EDIT: 'postcode_show_fields_edit' + }); + + function PostcodeHandlerBE( + config, + postcodeService + ) { + this.debounceBeforeCall = null; + this.data = { + + }; + PostcodeHandler.call( + this, + config, + postcodeService + ); + + return (this); + } + + PostcodeHandlerBE.prototype = Object.create(PostcodeHandler.prototype); + + PostcodeHandlerBE.prototype.getISOCode = function(){ return "BE";} + + PostcodeHandlerBE.prototype.destroy = function(){ + this.deleteAutoComplete(); + PostcodeHandler.prototype.destroy.call(this); + } + + PostcodeHandlerBE.prototype.getAutoCompleteResultCity = function() { + var currentPostcodeService = this.getPostcodeService(); + var postcodeField = currentPostcodeService.getElement(FieldTypes.postcode); + var domPostcodeField = $('#' + postcodeField.uid); + + if ($('.tig-autocomplete-result-city', domPostcodeField.parent()).length === 0) { + domPostcodeField.parent().append(''); + } + + return $('.tig-autocomplete-result-city', domPostcodeField.parent()); + } + + PostcodeHandlerBE.prototype.deleteAutoComplete = function() { + var currentPostcodeService = this.getPostcodeService(); + + var postcodeField = currentPostcodeService.getElement(FieldTypes.postcode); + var domPostcodeField = $('#' + postcodeField.uid); + if (domPostcodeField.length > 0 && domPostcodeField.data('uiAutocomplete')) { + domPostcodeField.autocomplete("destroy"); + } + + var streetField = currentPostcodeService.getElement(FieldTypes.street); + var domStreetField = $('#' + streetField.uid); + if (domStreetField.length > 0 && domStreetField.data('uiAutocomplete')) { + domStreetField.autocomplete("destroy"); + } + + $('.tig-autocomplete-result-city', domPostcodeField.parent()).remove(); + } + + PostcodeHandlerBE.prototype.addAutoCompleteToPostcode = function () { + var self = this; + + var currentPostcodeService = this.getPostcodeService(); + var postcodeField = currentPostcodeService.getElement(FieldTypes.postcode); + var domPostcodeField = $('#' + postcodeField.uid); + + if (domPostcodeField.length === 0) { + return; + } + + domPostcodeField.attr('autocomplete', 'off'); + + self.getAutoCompleteResultCity(); + domPostcodeField.autocomplete({ + delay: 500, + source: function (zipcodezone, response) { + this.menu.element.addClass(this.customScope + ".tigAutocomplete"); + this.menu.element.addClass('tigJqueryUiClass'); + + domPostcodeField.addClass('auto-complete-running'); + + self.getAutoCompleteResultCity().text(''); + + response([{ + label: $.mage.__('Busy with loading zipcodes...'), + data: false + }]); + + PostcodeApi.getPostCodeBE(zipcodezone.term).done(function(data){ + // If no results are found, a success = false is returned + if (data.success === false) { + response({label: $.mage.__('No results found.')}); + return; + } + + var selectBoxArr = []; + $.each(data, function (key) { + selectBoxArr.push({ + label: data[key].postcode + ' - ' + data[key].plaats, + value: data[key].postcode, + data: data[key] + }); + }); + + response(selectBoxArr); + }); + }, + select: function (event, ui) { + if (ui.item.value == $.mage.__('Busy with loading zipcodes...')) { + ui.item.value = ''; + return false; + } + + if (typeof ui.item.data === 'undefined') { + return false; + } + + var data = ui.item.data; + self.getPostcodeService().setFieldValue(FieldTypes.city, data.plaats); + self.getPostcodeService().setFieldValue(FieldTypes.postcode, data.postcode); + + self.getAutoCompleteResultCity().text(' - ' + data.plaats); + }, + close: function() { + domPostcodeField.removeClass('auto-complete-running'); + } + }); + } + + PostcodeHandlerBE.prototype.addAutoCompleteToStreet = function () { + var self = this; + + var currentPostcodeService = this.getPostcodeService(); + var streetFieldZero = currentPostcodeService.getElement(FieldTypes.street); + var streetField = $('#' + streetFieldZero.uid); + + if (streetField.length === 0) { + return; + } + + streetField.attr('autocomplete', 'yes'); + + streetField.autocomplete({ + delay: 500, + source : function (street, response) { + this.menu.element.addClass('tigJqueryUiClass'); + this.menu.element.appendTo(this.element.closest('.tig_street_autocomplete')); + + response([{ + label: $.mage.__('Busy with loading streets...'), + data: false + }]); + + var postcode = currentPostcodeService.getElement(FieldTypes.postcode).value(); + var city = currentPostcodeService.getElement(FieldTypes.city).value(); + + PostcodeApi.getStreetBe(postcode, street.term, city).done(function(data){ + // If no results are found, a success = false is returned + if (data.success == false) { + response([{ + label: $.mage.__('No results found.'), + data: false + }]); + return; + } + + var selectBoxArr = []; + $.each(data, function (key, value) { + selectBoxArr.push({ + label: data[key].straat, + value: data[key].straat + }); + }); + + response(selectBoxArr); + }); + }, + select : function (event, ui) { + if (ui.item.value == $.mage.__('Busy with loading streets...')) { + ui.item.value = ''; + return false; + } + + if (typeof ui.item.data === false) { + return false; + } + + var data = ui.item.value; + self.getPostcodeService().setFieldValue(FieldTypes.street, data); + } + }); + } + + PostcodeHandlerBE.prototype.handle = function (field_type, field_value) { + if (field_type === FieldTypes.postcode) { + this.data.postcode = field_value; + } + + switch(this.getCurrentState()) { + case states.INIT: + this.setCurrentState(states.IDLE); + this.getPostcodeService().addClassesToField(FieldTypes.street,{'tig_street_autocomplete': true}); + this.getPostcodeService().addClassesToField(FieldTypes.postcode,{'tig_zipcodezone_autocomplete': true}); + this.addAutoCompleteToPostcode(this.getPostcodeService().getElement(FieldTypes.postcode)); + this.addAutoCompleteToStreet(this.getPostcodeService().getElement(FieldTypes.street)); + break; + } + PostcodeHandler.prototype.handle.call(this, field_type, field_value); + } + return PostcodeHandlerBE; + } +); diff --git a/view/base/web/js/postcode-handler/postcode-de.js b/view/base/web/js/postcode-handler/postcode-de.js new file mode 100644 index 0000000..86e6da3 --- /dev/null +++ b/view/base/web/js/postcode-handler/postcode-de.js @@ -0,0 +1,74 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define( + [ + 'underscore', + './postcode-handler', + '../helper/field-types' + ], + function ( + underscore, + PostcodeHandler, + FieldTypes + ) { + 'use strict'; + + const postcodeDeRegex = /^[0-9]{4}\s?[A-Z]{2}$/i; + + function PostcodeHandlerDE(config,fields) { + this.states = Object.seal({ + INIT: 'init', + }); + + PostcodeHandler.call( + this, + config, + fields + ); + + return (this); + } + + PostcodeHandlerDE.prototype = Object.create(PostcodeHandler.prototype); + + PostcodeHandlerDE.prototype.getISOCode = function(){ return "DE";} + + PostcodeHandlerDE.prototype.handle = function (field_type, field_value) { + this.log('Handler @ ' + this.getCurrentState() + ': ' + field_type + ' => ' + field_value); + switch(this.getCurrentState()) { + case this.states.INIT: + + break; + } + } + return PostcodeHandlerDE; + } +); diff --git a/view/base/web/js/postcode-handler/postcode-handler.js b/view/base/web/js/postcode-handler/postcode-handler.js new file mode 100644 index 0000000..f347742 --- /dev/null +++ b/view/base/web/js/postcode-handler/postcode-handler.js @@ -0,0 +1,169 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([ + 'uiRegistry', + 'knockout', + '../helper/field-types', + '../helper/reorder-fields' +], function (registry, ko, FieldTypes, reorderFields) { + 'use strict'; + + const STATE_DISABLED = 'disabled'; + const STATE_INIT = 'init'; + + var postcodeInstanceId = 0; + + var postcodeInstances = []; + + /** + * Postcode Handler Constructor + * + * @param config + * @param postcodeFieldset + * @returns {PostcodeHandler} + * @constructor + */ + function PostcodeHandler (config, postcodeFieldset) + { + this.id = postcodeInstanceId++; + this.currentState = STATE_DISABLED; + + this.postcodeService = postcodeFieldset; + this.config = config; + + this.setIdByContainer(postcodeFieldset); + + this.log('Init'); + + postcodeInstances.push(this); + + return (this); + } + + /** + * Init State + * + * We need this for extending this abstract class + * @type {string} + */ + PostcodeHandler.INIT = STATE_INIT; + + /** + * Logger + * + * @param message + */ + PostcodeHandler.prototype.log = function(message){ + console.log('PostcodeService[' + this.id + '][' + this.getISOCode() + ']: ' + message); + } + + /** + * Concatenate field value + * + * This function also supports street fieldsets + * + * @param field + */ + PostcodeHandler.prototype.concatenateFieldsToStreet = function(field){ + if([FieldTypes.street, FieldTypes.house_number, FieldTypes.house_number_addition].includes((field))) { + var street = this.getPostcodeService().getFieldValue(FieldTypes.street); + var house_number = this.getPostcodeService().getFieldValue(FieldTypes.house_number); + var house_number_addition = this.getPostcodeService().getFieldValue(FieldTypes.house_number_addition); + this.log("Updating magento street" , [street, house_number, house_number_addition]) + this.getPostcodeService().setFieldValue(FieldTypes.magento_street, street + + (house_number ? ' ' + house_number : '') + + (house_number_addition ? ' ' + house_number_addition : '') + ); + } + } + /** + * Handle field changes + * + * @return boolean + * @param fieldType + * @param value + */ + PostcodeHandler.prototype.handle = function(fieldType, value) { + this.concatenateFieldsToStreet(fieldType); + } + + /** + * Destroy PostcodeHandler + * + * Cleans up instance and returns fields back to default state + * + */ + PostcodeHandler.prototype.destroy = function(){ + this.log('Destroy'); + postcodeInstances.filter(e => e !== this); + this.getPostcodeService().resetFieldsConfig(); + } + + /** + * Reset PostcodeHandler + * + * Called t + */ + PostcodeHandler.prototype.reset = function() { + if (!('tig_postcode' in this.config) || this.config.tig_postcode['enabled'] === false) { + this.currentState = STATE_DISABLED; + return; + } + + this.currentState = STATE_INIT; + this.postcodeService.setFieldsConfig(this.config.tig_postcode); + } + + PostcodeHandler.prototype.setIdByContainer = function(fieldSet){ + if (fieldSet && fieldSet.name) { + this.id = fieldSet.name; + } + } + + PostcodeHandler.prototype.getISOCode = function() { + return null; + } + + PostcodeHandler.prototype.getCurrentState = function() { + return this.currentState; + } + + PostcodeHandler.prototype.setCurrentState = function(state) { + this.log("State change to " + state); + this.currentState = state; + } + + PostcodeHandler.prototype.getPostcodeService = function() { + return this.postcodeService; + } + + return PostcodeHandler; +}); diff --git a/view/base/web/js/postcode-handler/postcode-nl.js b/view/base/web/js/postcode-handler/postcode-nl.js new file mode 100644 index 0000000..0f07865 --- /dev/null +++ b/view/base/web/js/postcode-handler/postcode-nl.js @@ -0,0 +1,155 @@ +/** + * + * ..::.. + * ..::::::::::::.. + * ::'''''':''::''''':: + * ::.. ..: : ....:: + * :::: ::: : : :: + * :::: ::: : ''' :: + * ::::..:::..::.....:: + * ''::::::::::::'' + * ''::'' + * + * + * NOTICE OF LICENSE + * + * This source file is subject to the Creative Commons License. + * It is available through the world-wide-web at this URL: + * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + * If you are unable to obtain it through the world-wide-web, please send an email + * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please contact servicedesk@totalinternetgroup.nl for more information. + * + * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US + */ +define([ + 'jquery', + 'underscore', + './postcode-handler', + '../helper/field-types', + '../helper/postcode-api' + ], function ( + $, + _, + PostcodeHandler, + FieldTypes, + PostcodeApi + ) { + 'use strict'; + + const postcodeNlRegex = /^[0-9]{4}\s?[A-Z]{2}$/i; + + const states = Object.seal({ + INIT: PostcodeHandler.INIT, + IDLE: 'postcode_idle', + POSTCODE_CALL_MADE: 'postcode_call_made', + POSTCODE_CALL_FAILED: 'postcode_call_failed', + POSTCODE_SHOW_FIELDS_SUGGESTION: 'postcode_show_fields_suggestion', + POSTCODE_SHOW_FIELDS_EDIT: 'postcode_show_fields_edit' + }); + + function PostcodeHandlerNL( + config, + postcodeService + ) { + this.debounceBeforeCall = null; + this.data = { + + }; + PostcodeHandler.call( + this, + config, + postcodeService + ); + + return (this); + } + + PostcodeHandlerNL.prototype = Object.create(PostcodeHandler.prototype); + + PostcodeHandlerNL.prototype.getISOCode = function(){ return "NL";} + + PostcodeHandlerNL.prototype.callApi = _.debounce(function(postcode, house_number){ + const self = this; + this.setCurrentState(states.POSTCODE_CALL_MADE); + + PostcodeApi.getPostCodeNL(postcode, house_number).done(function(data){ + self.getPostcodeService().getElement(FieldTypes.postcode).error(''); + + if (data.success !== true) { + self.setCurrentState(states.POSTCODE_CALL_FAILED); + self.getPostcodeService().getElement(FieldTypes.postcode).error('Sorry, wij konden geen adresgegevens vinden met de opgegeven postcode en huisnummer combinatie. Indien u er zeker van bent dat de opgegeven postcode en huisnummer correct zijn, vul dan adresinformatie handmatig aan.'); + return; + } + + self.getPostcodeService().setFieldValue(FieldTypes.street, data.straatnaam); + self.getPostcodeService().setFieldValue(FieldTypes.city, data.woonplaats); + self.concatenateFieldsToStreet(FieldTypes.street); + + self.setCurrentState(states.POSTCODE_SHOW_FIELDS_SUGGESTION); + }).fail(function(){ + self.setCurrentState(states.POSTCODE_CALL_FAILED); + }).always(function(){ + self.getPostcodeService().showHideField(FieldTypes.street, true); + self.getPostcodeService().showHideField(FieldTypes.city, true); + }); + },500); + + PostcodeHandlerNL.prototype.handle = function (field_type, field_value) { + if (this.getCurrentState() !== states.INIT) { + if (field_type === FieldTypes.postcode) { + this.data.postcode = field_value; + } + + if (field_type === FieldTypes.house_number) { + this.data.house_number = field_value; + } + + // Do validation and call, state change is handled in callApi due to debouncing + if ((field_type === FieldTypes.postcode || field_type === FieldTypes.house_number) && + typeof this.data.postcode !== 'undefined' && + typeof this.data.house_number !== 'undefined' && + this.data.postcode.match(postcodeNlRegex) && + this.data.house_number.match(/[0-9]+/)) { + this.callApi(this.data.postcode, this.data.house_number); + } + } + + switch(this.getCurrentState()) { + case states.INIT: + this.setCurrentState(states.IDLE); + var postcodeField = this.getPostcodeService().getElement(FieldTypes.postcode); + var housenumberField = this.getPostcodeService().getElement(FieldTypes.house_number); + + if (postcodeField) { + this.handle(FieldTypes.postcode, postcodeField.value()); + } + if (housenumberField) { + this.handle(FieldTypes.house_number, housenumberField.value()); + } + break; + case states.POSTCODE_SHOW_FIELDS_EDIT: + case states.POSTCODE_SHOW_FIELDS_SUGGESTION: + if ([FieldTypes.street, FieldTypes.city].includes(field_type)) { + this.setCurrentState(states.POSTCODE_SHOW_FIELDS_EDIT); + } + break; + } + + // Important, concatenates all values to Magento street value + PostcodeHandler.prototype.handle.call( + this, + field_type, + field_value + ); + } + + return PostcodeHandlerNL; + } +); From d32860fe4d2415baa4380c0454da38f4827ca253 Mon Sep 17 00:00:00 2001 From: Mickey Beijer Date: Tue, 5 Apr 2022 13:28:19 +0200 Subject: [PATCH 05/36] added plugin for guest payment information --- .../GuestPaymentInformationManagement.php | 72 +++++++++++++++++++ etc/di.xml | 4 ++ 2 files changed, 76 insertions(+) create mode 100644 Plugin/Checkout/Model/GuestPaymentInformationManagement.php diff --git a/Plugin/Checkout/Model/GuestPaymentInformationManagement.php b/Plugin/Checkout/Model/GuestPaymentInformationManagement.php new file mode 100644 index 0000000..43b2ede --- /dev/null +++ b/Plugin/Checkout/Model/GuestPaymentInformationManagement.php @@ -0,0 +1,72 @@ +fieldsHelper = $fieldsHelper; + } + + /** + * @param \Magento\Checkout\Model\GuestPaymentInformationManagement $subject + * @param $cartId + * @param $email + * @param PaymentInterface $paymentMethod + * @param AddressInterface $address + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function beforeSavePaymentInformation( + \Magento\Checkout\Model\GuestPaymentInformationManagement $subject, + $cartId, + $email, + PaymentInterface $paymentMethod, + AddressInterface $address + ) { + $extAttributes = $address->getExtensionAttributes(); + $this->fieldsHelper->copyFieldsFromExtensionAttributesToObject($extAttributes, $address); + } +} diff --git a/etc/di.xml b/etc/di.xml index ecd611a..14a7b23 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -61,6 +61,10 @@ + + + + From 2bc7ba5f4049fca3073d742d8595c5c03796d7ba Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Tue, 5 Apr 2022 14:20:31 +0200 Subject: [PATCH 06/36] Commited changes over from temp develop branch --- Block/Adminhtml/Config/Checkout/Mageplaza.php | 59 -- .../Config/Checkout/Onestepcheckout.php | 57 -- Block/Frontend/Checkout/DataProvider.php | 74 --- Block/Frontend/Customer/Address/Edit.php | 114 ---- .../GetCheckoutCompatibility.php | 58 -- .../IsPostcodeCheckActive.php | 58 -- Config/Source/Checkouts.php | 57 -- Plugin/Address/Management/CustomerForm.php | 86 --- Plugin/Mageplaza/AddressHelper.php | 100 ---- etc/adminhtml/system.xml | 1 - etc/adminhtml/system/checkout.xml | 56 -- etc/adminhtml/system/configuration.xml | 24 +- etc/adminhtml/system/countries.xml | 3 - etc/config.xml | 5 - etc/di.xml | 4 - etc/frontend/di.xml | 10 - .../templates/config/checkout/mageplaza.phtml | 51 -- .../config/checkout/onestepcheckout.phtml | 51 -- .../templates/config/parsing/streets.phtml | 2 + .../web/js/form/element/tig-postcode-field.js | 1 - view/frontend/layout/checkout_index_index.xml | 6 +- .../frontend/layout/customer_address_form.xml | 43 -- view/frontend/requirejs-config.js | 60 +- .../templates/checkout/DataProvider.phtml | 39 -- .../templates/customer/address/Postcode.phtml | 425 --------------- view/frontend/web/css/fields.css | 221 ++++++++ view/frontend/web/css/jquery-ui.css | 76 --- view/frontend/web/css/style.css | 239 -------- view/frontend/web/js/Address/State.js | 79 --- view/frontend/web/js/Helper/DataProvider.js | 42 -- view/frontend/web/js/Helper/Logger.js | 45 -- .../action/create-shipping-address-mixin.js | 20 + .../js/action/set-billing-address-mixin.js | 34 +- .../action/set-shipping-information-mixin.js | 43 +- view/frontend/web/js/lib/mage/mage-mixin.js | 53 -- .../web/js/view/billing-address-mixin.js | 65 --- .../js/view/form/be/autocompleteElement.js | 360 ------------ view/frontend/web/js/view/form/fields.js | 514 ------------------ .../web/js/view/hide-tig-attributes-mixin.js | 26 + .../view/myparcel/delivery-options-mixin.js | 58 -- .../web/template/billing-address/details.html | 30 - .../web/template/checkout/field-be-group.html | 6 - .../web/template/checkout/field-group.html | 7 - .../template/form/element/autocomplete.html | 12 - .../template/form/element/housenumber.html | 12 - .../{addition.html => postcode-field.html} | 3 +- .../address-renderer/default.html | 36 -- .../address-renderer/default.html | 26 - 48 files changed, 329 insertions(+), 3122 deletions(-) delete mode 100644 Block/Adminhtml/Config/Checkout/Mageplaza.php delete mode 100644 Block/Adminhtml/Config/Checkout/Onestepcheckout.php delete mode 100644 Block/Frontend/Checkout/DataProvider.php delete mode 100644 Block/Frontend/Customer/Address/Edit.php delete mode 100644 Config/CheckoutConfiguration/GetCheckoutCompatibility.php delete mode 100644 Config/CheckoutConfiguration/IsPostcodeCheckActive.php delete mode 100644 Config/Source/Checkouts.php delete mode 100644 Plugin/Address/Management/CustomerForm.php delete mode 100644 Plugin/Mageplaza/AddressHelper.php delete mode 100644 etc/adminhtml/system/checkout.xml delete mode 100644 view/adminhtml/templates/config/checkout/mageplaza.phtml delete mode 100644 view/adminhtml/templates/config/checkout/onestepcheckout.phtml delete mode 100644 view/frontend/layout/customer_address_form.xml delete mode 100644 view/frontend/templates/checkout/DataProvider.phtml delete mode 100644 view/frontend/templates/customer/address/Postcode.phtml create mode 100644 view/frontend/web/css/fields.css delete mode 100644 view/frontend/web/css/jquery-ui.css delete mode 100644 view/frontend/web/css/style.css delete mode 100644 view/frontend/web/js/Address/State.js delete mode 100644 view/frontend/web/js/Helper/DataProvider.js delete mode 100644 view/frontend/web/js/Helper/Logger.js create mode 100644 view/frontend/web/js/action/create-shipping-address-mixin.js delete mode 100644 view/frontend/web/js/lib/mage/mage-mixin.js delete mode 100644 view/frontend/web/js/view/billing-address-mixin.js delete mode 100644 view/frontend/web/js/view/form/be/autocompleteElement.js delete mode 100644 view/frontend/web/js/view/form/fields.js create mode 100644 view/frontend/web/js/view/hide-tig-attributes-mixin.js delete mode 100644 view/frontend/web/js/view/myparcel/delivery-options-mixin.js delete mode 100644 view/frontend/web/template/billing-address/details.html delete mode 100644 view/frontend/web/template/checkout/field-be-group.html delete mode 100644 view/frontend/web/template/checkout/field-group.html delete mode 100644 view/frontend/web/template/form/element/autocomplete.html delete mode 100644 view/frontend/web/template/form/element/housenumber.html rename view/frontend/web/template/form/element/{addition.html => postcode-field.html} (70%) delete mode 100644 view/frontend/web/template/shipping-address/address-renderer/default.html delete mode 100644 view/frontend/web/template/shipping-information/address-renderer/default.html diff --git a/Block/Adminhtml/Config/Checkout/Mageplaza.php b/Block/Adminhtml/Config/Checkout/Mageplaza.php deleted file mode 100644 index 3f64b71..0000000 --- a/Block/Adminhtml/Config/Checkout/Mageplaza.php +++ /dev/null @@ -1,59 +0,0 @@ -setElement($element); - - return $this->toHtml(); - } - // @codeCoverageIgnoreEnd -} diff --git a/Block/Adminhtml/Config/Checkout/Onestepcheckout.php b/Block/Adminhtml/Config/Checkout/Onestepcheckout.php deleted file mode 100644 index 35df630..0000000 --- a/Block/Adminhtml/Config/Checkout/Onestepcheckout.php +++ /dev/null @@ -1,57 +0,0 @@ -setElement($element); - - return $this->toHtml(); - } -} diff --git a/Block/Frontend/Checkout/DataProvider.php b/Block/Frontend/Checkout/DataProvider.php deleted file mode 100644 index 1866fba..0000000 --- a/Block/Frontend/Checkout/DataProvider.php +++ /dev/null @@ -1,74 +0,0 @@ -configuration = $configuration; - parent::__construct($context, $data); - } - - /** - * @return bool - */ - public function isPostcodeBeCheckOn() - { - return $this->configuration->isBECheckEnabled(); - } -} diff --git a/Block/Frontend/Customer/Address/Edit.php b/Block/Frontend/Customer/Address/Edit.php deleted file mode 100644 index 5770194..0000000 --- a/Block/Frontend/Customer/Address/Edit.php +++ /dev/null @@ -1,114 +0,0 @@ -urlBuilder = $urlBuilder; - $this->moduleConfiguration = $moduleConfiguration; - - parent::__construct($context, $data); - } - - /** - * @return string - */ - public function getPostcodeUrl() - { - return $this->urlBuilder->getUrl('postcode/address/service', ['_secure' => true]); - } - - /** - * @return string - */ - public function getBePostcodeUrl() - { - return $this->urlBuilder->getUrl('postcode/address/service/be/getpostcode', ['_secure' => true]); - } - - /** - * @return string - */ - public function getBeStreetUrl() - { - return $this->urlBuilder->getUrl('postcode/address/service/be/getstreet', ['_secure' => true]); - } - - /** - * @return string - */ - public function isPostcodeNlCheckOn() - { - return ($this->moduleConfiguration->isNLCheckEnabled() ? "true" : "false"); - } - - /** - * @return string - */ - public function isPostcodeBeCheckOn() - { - return ($this->moduleConfiguration->isBECheckEnabled() ? "true" : "false"); - } -} diff --git a/Config/CheckoutConfiguration/GetCheckoutCompatibility.php b/Config/CheckoutConfiguration/GetCheckoutCompatibility.php deleted file mode 100644 index 166f7df..0000000 --- a/Config/CheckoutConfiguration/GetCheckoutCompatibility.php +++ /dev/null @@ -1,58 +0,0 @@ -moduleConfiguration = $moduleConfiguration; - } - - /** - * @return mixed - */ - public function getValue() - { - return $this->moduleConfiguration->getCheckoutCompatibility(); - } -} diff --git a/Config/CheckoutConfiguration/IsPostcodeCheckActive.php b/Config/CheckoutConfiguration/IsPostcodeCheckActive.php deleted file mode 100644 index 609e117..0000000 --- a/Config/CheckoutConfiguration/IsPostcodeCheckActive.php +++ /dev/null @@ -1,58 +0,0 @@ -moduleConfiguration = $moduleConfiguration; - } - - /** - * @return bool - */ - public function getValue() - { - return !$this->moduleConfiguration->isModusOff(); - } -} diff --git a/Config/Source/Checkouts.php b/Config/Source/Checkouts.php deleted file mode 100644 index c922a9e..0000000 --- a/Config/Source/Checkouts.php +++ /dev/null @@ -1,57 +0,0 @@ - 'default', 'label' => __('Two Step Checkout Luma')], - ['value' => 'blank', 'label' => __('Two Step Checkout Blank')], - ['value' => 'onestepcheckout', 'label' => __('Iosc Onestepcheckout v1.2.036')], - ['value' => 'mageplaza', 'label' => __('Mageplaza One Step Checkout v2.5.0 - v2.6.1')], - ['value' => 'danslo', 'label' => __('Rubic Clean Checkout v1.1.0 - v2.0.0')], - ['value' => 'amasty', 'label' => __('Amasty One Step Checkout v1.6.0 - v1.8.17')] - ]; - // @codingStandardsIgnoreEnd - - return $options; - } -} diff --git a/Plugin/Address/Management/CustomerForm.php b/Plugin/Address/Management/CustomerForm.php deleted file mode 100644 index 5a8cb6b..0000000 --- a/Plugin/Address/Management/CustomerForm.php +++ /dev/null @@ -1,86 +0,0 @@ -attributeParser = $attributeParser; - $this->streetFields = $streetFields; - } - - /** - * @param Form $subject - * @param $result - * @param RequestInterface $request - * - * @return mixed - */ - // @codingStandardsIgnoreLine - public function afterExtractData(Form $subject, $result, RequestInterface $request) - { - $country = $request->getPostValue('country_id'); - - if (!array_key_exists('street', $result) || ($country !== 'NL' && $country !== 'BE')) { - return $result; - } - - $attributes = [ - 'tig_housenumber' => $request->getPostValue('tig-housenumber'), - 'tig_housenumber_addition', $request->getPostValue('tig-housenumber-addition') - ]; - - $this->attributeParser->set($attributes); - - $result['street'] = $this->streetFields->parse($result['street'], $this->attributeParser); - - return $result; - } -} diff --git a/Plugin/Mageplaza/AddressHelper.php b/Plugin/Mageplaza/AddressHelper.php deleted file mode 100644 index c55492b..0000000 --- a/Plugin/Mageplaza/AddressHelper.php +++ /dev/null @@ -1,100 +0,0 @@ -moduleConfig = $moduleConfiguration; - } - - /** - * Subject => \Mageplaza\Osc\Helper\Address - * Compatible plugin, Mageplaza skippes grouped fields, so we need to add this manualy. - * - * @param $subject - * @param $fieldPosition - * - * @return mixed - */ - // @codingStandardsIgnoreLine - public function afterGetAddressFieldPosition($subject, $fieldPosition) - { - if ($this->moduleConfig->isModusOff()) { - return $fieldPosition; - } - - return $this->addPostcodeFieldGroup($fieldPosition); - } - - /** - * @param $fieldPosition - * - * @return mixed - */ - private function addPostcodeFieldGroup($fieldPosition) - { - $fieldPosition = $this->orderFields($fieldPosition); - - $fieldPosition['postcode-field-group'] = [ - 'sortOrder' => 65, - 'colspan' => 12, - 'isNewRow' => true - ]; - - return $fieldPosition; - } - - /** - * @see \Mageplaza\Osc\Block\Checkout\LayoutProcessor::addAddressOption - * Because the postcode-field-group is not an Mageplaza OSC field it will be ignored. - * Affects since OSC version 2.5.0 - * - * @param $fieldPosition - * @return mixed - */ - private function orderFields(&$fieldPosition) - { - $sortOrder = 40; - foreach ($fieldPosition as $key => &$field) { - $field['sortOrder'] = $sortOrder += 10; - } - - return $fieldPosition; - } -} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 6b3f0a0..faff9a0 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -40,7 +40,6 @@ - diff --git a/etc/adminhtml/system/checkout.xml b/etc/adminhtml/system/checkout.xml deleted file mode 100644 index 8a44b85..0000000 --- a/etc/adminhtml/system/checkout.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - TIG\Postcode\Block\Adminhtml\Config\Form\Field\Fieldset - tig_postcode-section - - - - - tig_postcode/checkout/postcode_sort_order - - - - - tig_postcode/checkout/city_sort_order - - - - - tig_postcode/checkout/country_sort_order - - - diff --git a/etc/adminhtml/system/configuration.xml b/etc/adminhtml/system/configuration.xml index 5bf2098..99bf7cb 100644 --- a/etc/adminhtml/system/configuration.xml +++ b/etc/adminhtml/system/configuration.xml @@ -89,28 +89,6 @@ 1 - - - - - TIG\Postcode\Config\Source\Checkouts - tig_postcode/configuration/checkout_compatible - - - - TIG\Postcode\Block\Adminhtml\Config\Checkout\Mageplaza - tig_postcode-section - - mageplaza - - - - TIG\Postcode\Block\Adminhtml\Config\Checkout\Onestepcheckout - tig_postcode-section - - onestepcheckout - - @@ -132,12 +110,14 @@ + TIG\Postcode\Block\Adminhtml\Config\Form\Field\Disable TIG\Postcode\Config\Source\Parser tig_postcode/configuration/fieldparsing_housenumber + TIG\Postcode\Block\Adminhtml\Config\Form\Field\Disable TIG\Postcode\Config\Source\Parser tig_postcode/configuration/fieldparsing_addition diff --git a/etc/adminhtml/system/countries.xml b/etc/adminhtml/system/countries.xml index 5497b09..8ade118 100644 --- a/etc/adminhtml/system/countries.xml +++ b/etc/adminhtml/system/countries.xml @@ -47,9 +47,6 @@ Magento\Config\Model\Config\Source\Yesno tig_postcode/countries/enable_be_check - - mageplaza - diff --git a/etc/config.xml b/etc/config.xml index d2a25ee..c731dd5 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -56,11 +56,6 @@ 1 0 - - 65 - 72 - 64 - diff --git a/etc/di.xml b/etc/di.xml index 2ef866b..d69eb2b 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -52,10 +52,6 @@ - - - - diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 901d05d..e8da7bd 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -31,14 +31,6 @@ * --> - - - - - - - - @@ -51,9 +43,7 @@ TIG\Postcode\Config\CheckoutConfiguration\StreetParser - TIG\Postcode\Config\CheckoutConfiguration\IsPostcodeCheckActive TIG\Postcode\Config\CheckoutConfiguration\ActionUrl - TIG\Postcode\Config\CheckoutConfiguration\GetCheckoutCompatibility diff --git a/view/adminhtml/templates/config/checkout/mageplaza.phtml b/view/adminhtml/templates/config/checkout/mageplaza.phtml deleted file mode 100644 index 9b2f9b1..0000000 --- a/view/adminhtml/templates/config/checkout/mageplaza.phtml +++ /dev/null @@ -1,51 +0,0 @@ - -
-
-
-

- - escapeHtml(__('Using MagePlaza OneStepCheckout')); ?> - -

- escapeHtml(__('The codes to support the MagePlaza OneStepCheckout extension has been moved to a new extension.'));?> -
- escapeHtml(__('Please follow the instructions in the following link to make this extension compatible with the MagePlaza extension.'));?> -
- - escapeHtml(__('Checkout support extension installation manual'));?> - <?php echo $block->escapeHtml(__('Checkout support extension installation manual'));?> - -
-
-
diff --git a/view/adminhtml/templates/config/checkout/onestepcheckout.phtml b/view/adminhtml/templates/config/checkout/onestepcheckout.phtml deleted file mode 100644 index d1d0df0..0000000 --- a/view/adminhtml/templates/config/checkout/onestepcheckout.phtml +++ /dev/null @@ -1,51 +0,0 @@ - -
-
-
-

- - escapeHtml(__('Using iDev OneStepCheckout')); ?> - -

- escapeHtml(__('The codes to support the iDev OneStepCheckout extension requires the installation of our support extension.'));?> -
- escapeHtml(__('Please follow the instructions in the following link to make this extension compatible with the OneStepCheckout extension.'));?> -
- - escapeHtml(__('Checkout support extension installation manual'));?> - <?php echo $block->escapeHtml(__('Checkout support extension installation manual'));?> - -
-
-
diff --git a/view/adminhtml/templates/config/parsing/streets.phtml b/view/adminhtml/templates/config/parsing/streets.phtml index 10bc315..02ebfdd 100644 --- a/view/adminhtml/templates/config/parsing/streets.phtml +++ b/view/adminhtml/templates/config/parsing/streets.phtml @@ -41,6 +41,8 @@ escapeHtml(__('These settings have impact on how street address data is stored in the database.'));?>
escapeHtml(__('Tampering with the settings may affect the workflow of third party extensions. Use at your own risk.'));?> +
+ escapeHtml(__('Note: These settings are disabled in this new release. If you still need this functionality contact support'));?> diff --git a/view/base/web/js/form/element/tig-postcode-field.js b/view/base/web/js/form/element/tig-postcode-field.js index 25103f5..7df0892 100644 --- a/view/base/web/js/form/element/tig-postcode-field.js +++ b/view/base/web/js/form/element/tig-postcode-field.js @@ -59,7 +59,6 @@ define([ currentPostcodeHandler: null, defaults: { - template: 'TIG_Postcode/form/collection', imports: { updatePostcode: '${ $.name }:value' }, diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index f026c4d..001e0bd 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -32,10 +32,6 @@ --> - - + - - - diff --git a/view/frontend/layout/customer_address_form.xml b/view/frontend/layout/customer_address_form.xml deleted file mode 100644 index fedae77..0000000 --- a/view/frontend/layout/customer_address_form.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js index 4f0e7b3..76dc135 100644 --- a/view/frontend/requirejs-config.js +++ b/view/frontend/requirejs-config.js @@ -1,42 +1,11 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to support@postcodeservice.com so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact support@postcodeservice.com for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - */ - var config = { config: { mixins: { 'Magento_Checkout/js/action/set-shipping-information': { 'TIG_Postcode/js/action/set-shipping-information-mixin': true }, - 'Amasty_Checkout/js/action/set-shipping-information' : { - 'TIG_Postcode/js/action/set-shipping-information-mixin': true + 'Magento_Checkout/js/action/create-shipping-address': { + 'TIG_Postcode/js/action/create-shipping-address-mixin': true }, 'Magento_Checkout/js/action/set-billing-address' : { 'TIG_Postcode/js/action/set-billing-address-mixin': true @@ -50,26 +19,17 @@ var config = { 'Magento_Checkout/js/action/set-payment-information': { 'TIG_Postcode/js/action/set-billing-address-mixin': true }, - 'Magento_Ui/js/form/element/abstract': { - 'TIG_Postcode/js/view/form/be/autocompleteElement': true + + // Mixin for hiding TIG Attributes + 'Magento_Checkout/js/view/billing-address' : { + 'TIG_Postcode/js/view/hide-tig-attributes-mixin': true }, - 'mage/menu': { - 'TIG_Postcode/js/lib/mage/mage-mixin': true + 'Magento_Checkout/js/view/shipping-address/address-renderer/default' : { + 'TIG_Postcode/js/view/hide-tig-attributes-mixin': true }, - 'MyParcelNL_Magento/js/view/delivery-options': { - 'TIG_Postcode/js/view/myparcel/delivery-options-mixin': true + 'Magento_Checkout/js/view/shipping-information/address-renderer/default' : { + 'TIG_Postcode/js/view/hide-tig-attributes-mixin': true }, - 'Magento_Checkout/js/view/billing-address': { - 'TIG_Postcode/js/view/billing-address-mixin': true - } - } - }, - map : { - '*': { - 'Magento_Checkout/template/shipping-address/address-renderer/default.html' : 'TIG_Postcode/template/shipping-address/address-renderer/default.html', - 'Magento_Checkout/template/shipping-information/address-renderer/default.html' : 'TIG_Postcode/template/shipping-information/address-renderer/default.html', - 'Magento_Checkout/template/billing-address/details.html' : 'TIG_Postcode/template/billing-address/details.html', - 'Amasty_CustomerAttributes/js/action/set-shipping-information-mixin' : 'TIG_Postcode/js/action/set-shipping-information-mixin' } } }; diff --git a/view/frontend/templates/checkout/DataProvider.phtml b/view/frontend/templates/checkout/DataProvider.phtml deleted file mode 100644 index 0d99e53..0000000 --- a/view/frontend/templates/checkout/DataProvider.phtml +++ /dev/null @@ -1,39 +0,0 @@ - - \ No newline at end of file diff --git a/view/frontend/templates/customer/address/Postcode.phtml b/view/frontend/templates/customer/address/Postcode.phtml deleted file mode 100644 index af63939..0000000 --- a/view/frontend/templates/customer/address/Postcode.phtml +++ /dev/null @@ -1,425 +0,0 @@ - - diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css new file mode 100644 index 0000000..a4dadba --- /dev/null +++ b/view/frontend/web/css/fields.css @@ -0,0 +1,221 @@ +.tig_hidden { + display: none; +} + +/**** Validation ****/ +.tig_postcode_field._error .control, +.tig_postcode_field._warn .control { + margin-bottom: 70px; +} + +@media (max-width: 375px) { + .tig_postcode_field._error .control, + .tig_postcode_field._warn .control { + margin-bottom: 95px; + } +} + +.tig_postcode_field._error .field-error, +.tig_postcode_field._warn .message { + position: absolute; +} + +.tig_postcode_nl.tig_postcode_field._error .field-error { + border: 1px solid #e02b27; + background: #f9f9f9; + color: #e02b27; + padding: 5px; + font-size: 1.2rem; + box-sizing: border-box; + white-space: normal; + width: 100%; + height: 70px; +} + +.tig_postcode_nl.tig_postcode_field._error + .tig_housenumber_field input, +.tig_postcode_nl.tig_postcode_field._error + .tig_housenumber_field + .tig_housenumber_addition_field input { + border: 1px solid #e02b27; +} + +.fieldset.address { + position: relative; +} + +/*! jQuery UI - v1.12.1 - 2016-09-14 +* http://jqueryui.com +* Copyright jQuery Foundation and other contributors; Licensed MIT */ + +.ui-helper-hidden-accessible { + border: 0; + clip: rect(0 0 0 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; +} + +.tigJqueryUiClass { + position: absolute; + top: 0; + left: 0; + cursor: default; +} + +.ui-menu { + list-style: none; + padding: 0; + margin: 0; + display: block; + outline: 0; +} + +.tigJqueryUiClass .ui-menu-item { + cursor: pointer; + list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); +} + +.tigJqueryUiClass .ui-state-error a { + color: #5f3f3f; +} + +.tigJqueryUiClass { + font-family: Arial, Helvetica, sans-serif; + font-size: 1em; +} + +.tigJqueryUiClass .ui-widget { + font-size: 1em; +} + +.tigJqueryUiClass input, +.tigJqueryUiClass select, +.tigJqueryUiClass textarea, +.tigJqueryUiClass button { + font-family: Arial, Helvetica, sans-serif; + font-size: 1em; +} + +.tigJqueryUiClass.ui-widget-content { + border: 1px solid #c5c5c5; +} + +.tigJqueryUiClass { + border: 1px solid #dddddd; + background: #ffffff; + color: #333333; +} + +.tigJqueryUiClass a { + color: #333333; +} + +.tigJqueryUiClass a { + color: #333333; +} + +.tigJqueryUiClass .ui-state-focus { + border: 1px solid #003eff; + background: #007fff; + font-weight: normal; + color: #ffffff; + display: block; +} + +.tigJqueryUiClass.ui-corner-all a { + position: relative; + border: 1px solid white; + float: left; + width: 100%; + padding: 10px; + margin-top: 4px; + cursor: pointer; + list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7); + text-decoration: none; + box-sizing: border-box; +} + +.tig-autocomplete-result-city { + top: 6.5px; + left: 46px; + color: #ccc; + max-width: 100px; + white-space: nowrap; + pointer-events: none; + position: absolute; +} + +.auto-complete-running + .warning { + display: none; +} + +/**** NL ****/ +.field.tig_postcode_nl.tig_postcode_field, +.field.tig_postcode_nl.tig_housenumber_field, +.field.tig_postcode_nl.tig_housenumber_addition_field{ + display: inline-block; + margin: 0 10px 20px 0; + width: 100%; + max-width: calc(100% / 3 - 7px); +} + +@media (max-width: 400px) { + .tig_postcode_field.tig_postcode_nl { + max-width: 100%; + } + + .tig_housenumber_field.tig_postcode_nl, + .tig_housenumber_addition_field.tig_postcode_nl { + max-width: calc(100% / 2 - 7px); + } +} + +.tig_street_fields.tig_postcode_nl, .tig_city_field.tig_postcode_nl { + max-width: 100%; +} + +.field.tig_postcode_nl.tig_housenumber_addition_field { + margin: 0 0 20px 0; +} + +/**** BE ****/ +.field.tig_postcode_be { + display: inline-block; + margin: 0 10px 20px 0; + width: 100%; + max-width: calc(100% / 3 - 7px); +} + +.tig_postcode_field.tig_postcode_be { + max-width: calc(46% - 7px); +} + +.tig_street_fields.tig_postcode_be, .tig_city_field.tig_postcode_be { + max-width: 100%; +} + +.tig_housenumber_field.tig_postcode_be, +.tig_housenumber_addition_field.tig_postcode_be { + max-width: calc(54% / 2 - 7px); +} + +@media (max-width: 400px) { + .tig_postcode_field.tig_postcode_be { + max-width: 100%; + } + + .tig_housenumber_field.tig_postcode_be, + .tig_housenumber_addition_field.tig_postcode_be { + max-width: calc(100% / 2 - 7px); + } +} + +.tig_housenumber_addition_field.tig_postcode_be { + margin: 0 0 20px 0; +} + +/**** Mageplaza OSC ****/ +.one-step-checkout-container .field[name="shippingAddress.postcode"] { + max-width: calc(46% - 7px); +} diff --git a/view/frontend/web/css/jquery-ui.css b/view/frontend/web/css/jquery-ui.css deleted file mode 100644 index 26ed2cf..0000000 --- a/view/frontend/web/css/jquery-ui.css +++ /dev/null @@ -1,76 +0,0 @@ -/*! jQuery UI - v1.12.1 - 2016-09-14 -* http://jqueryui.com -* Copyright jQuery Foundation and other contributors; Licensed MIT */ - -.ui-helper-hidden-accessible { - border: 0; - clip: rect(0 0 0 0); - height: 1px; - margin: -1px; - overflow: hidden; - padding: 0; - position: absolute; - width: 1px; -} - -.tigJqueryUiClass { - position: absolute; - top: 0; - left: 0; - cursor: default; -} -.ui-menu { - list-style: none; - padding: 0; - margin: 0; - display: block; - outline: 0; -} - -.tigJqueryUiClass .ui-menu-item { - cursor: pointer; - list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); -} - -.tigJqueryUiClass .ui-state-error a { - color: #5f3f3f; -} - -.tigJqueryUiClass { - font-family: Arial,Helvetica,sans-serif; - font-size: 1em; -} -.tigJqueryUiClass .ui-widget { - font-size: 1em; -} -.tigJqueryUiClass input, -.tigJqueryUiClass select, -.tigJqueryUiClass textarea, -.tigJqueryUiClass button { - font-family: Arial,Helvetica,sans-serif; - font-size: 1em; -} -.tigJqueryUiClass.ui-widget-content { - border: 1px solid #c5c5c5; -} -.tigJqueryUiClass { - border: 1px solid #dddddd; - background: #ffffff; - color: #333333; -} - -.tigJqueryUiClass a { - color: #333333; -} - -.tigJqueryUiClass a { - color: #333333; -} - -.tigJqueryUiClass .ui-state-focus { - border: 1px solid #003eff; - background: #007fff; - font-weight: normal; - color: #ffffff; - display: block; -} \ No newline at end of file diff --git a/view/frontend/web/css/style.css b/view/frontend/web/css/style.css deleted file mode 100644 index b4195f8..0000000 --- a/view/frontend/web/css/style.css +++ /dev/null @@ -1,239 +0,0 @@ -/* Tools ============================================================================================================ */ - -.tig_street_autocomplete { - position: relative; -} - -.tigJqueryUiClass { - max-width: 100%; -} - -.tig_hidden { - display: none; -} - -.ui-autocomplete { - z-index: 950; -} - -.ui-autocomplete-loading { - background:url('../images/indicator.gif') no-repeat right center !important; -} - -.tigJqueryUiClass.ui-corner-all a { - position: relative; - border: 1px solid white; - float: left; - width: 100%; - padding: 10px; - margin-top: 4px; - cursor: pointer; - list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7); - text-decoration: none; - box-sizing: border-box; -} - -.ui-menu .ui-menu-item { - margin: 0; - display: block; -} - -input._disabled { - cursor: not-allowed; - opacity: 0.5; -} - -/* Default: Magento Luma checkout =================================================================================== */ - -.tig-postcode-field-group { - float: left; - width: 100%; -} - -.tig-postcode-field-group .field { - margin: 0 10px 20px 0; - width: 100%; - max-width: 30%; /* IE Fallback */ - max-width: calc(100%/3 - 10px); - float: left; -} - -.tig-postcode-field-group .field:last-child { - margin: 0 0 20px 0; - width: 100%; - max-width: calc(100%/3); -} - -.tig-postcode-field-group .tig-postcode-be { - max-width: calc(46% - 5px); -} - -.tig-postcode-field-group .tig-housenumber-be { - max-width: 28%; -} - -.address .tig-postcode-field-group .tig-housenumber-addition-be { - max-width: 22%; -} - -.tig-postcode-field-group .field span { - overflow: hidden; - max-width: 70%; - display: inline-block; - text-overflow: ellipsis; - vertical-align :bottom; -} - -.tig-postcode-field-group .field .control { - margin-top: 5px; -} - -.tig-billing-housenumber { - display: inline; -} - -/* Validation message */ - -.tig-postcode-validation-message { - float: left; - display: none; - width: 100%; - color: #e02b27; - font-size: 1.2rem; - margin-bottom: 10px; - margin-top: -12px; - border: 1px solid; - padding: 10px; - background: #f9f9f9; - box-sizing: border-box; - white-space: normal; -} - - -.tig-postcode-field-group .field.tig-postcode-full-width { - max-width: 100%; -} - -/* Account Address Edit Page ============================================================================================ */ -.tig-postcode-field-group-account .field span { - max-width: 100%; -} - -.tig-postcode-field-group-account .field:last-child, -.tig-postcode-field-group-account .field { - margin-bottom: 0; -} - -.tig-postcode-field-group-account .field.tig-housenumber-addition-be { - max-width: 22%; -} - -/* Required */ - -.tig-postcode-field-group .field._required>.label:after { - content: '*'; - color: #e02b27; - font-size: 1.2rem; - margin: 0 0 0 5px; -} - -.tig_zipcodezone_autocomplete .control { - position: relative; -} - -.tig-autocomplete-result-city { - position: absolute; - top: 6.5px; - left: 46px; - color: #ccc; - max-width: 100px; - white-space: nowrap; - pointer-events: none; -} - -/* Magento Blank checkout =========================================================================================== */ - -/* Disable float - which is used in Luma */ - -.blank.tig-postcode-field-group { - float: none; - width: auto; - display: block; -} - -.blank.tig-postcode-field-group .field { - width: auto; - float:none; - display: inline-block; - max-width: 30%; /* IE Fallback */ - max-width: calc(100%/3 - 10px); -} - -.blank.tig-postcode-field-group .tig-postcode-be { - max-width: calc(50% - 5px); -} - -.blank.tig-postcode-field-group .tig-housenumber-be { - max-width: 25%; -} - -.address .blank.tig-postcode-field-group .tig-housenumber-addition-be { - max-width: 22%; -} - -.blank.tig-postcode-validation-message { - float:none; -} - -/* Desktop exceptions */ - -@media screen and (min-width: 768px){ - .blank.tig-postcode-field-group { - margin-left: 25.8%; - margin-bottom: 10px; - } - - .blank.tig-postcode-validation-message { - margin-left: 25.8%; - width: 74.2%; - margin-bottom: 20px; - } -} - -/* Mage Plaza checkout ============================================================================================== */ -.tig-postcode-field-group.mp-12 .field:last-child { - width: 30%; -} - -/* Rubic Clean checkout ============================================================================================= */ -.danslo.tig-postcode-field-group { - margin: 4px 0; -} - -.danslo.tig-postcode-field-group .field { - max-width: 100%; - margin: 0 10px 4px 0; -} - -.danslo.tig-postcode-field-group .field:last-child { - max-width: calc(100%); -} - -/* Amasty Plaza checkout ============================================================================================ */ -.amasty.tig-postcode-field-group { - margin-left: 8px; -} - -.amasty.tig-postcode-field-group .field:last-child { - max-width: calc(91%/3); -} - -.amasty.tig-postcode-validation-message { - margin-left: 8px; - width: calc(97%); -} - -/** Onestepcheckout ================================================================================================= */ -.onestepcheckout.tig-postcode-field-group { - width: calc(100% - 8px); -} diff --git a/view/frontend/web/js/Address/State.js b/view/frontend/web/js/Address/State.js deleted file mode 100644 index 7b880c9..0000000 --- a/view/frontend/web/js/Address/State.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to support@postcodeservice.com so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact support@postcodeservice.com for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - */ -/*browser:true*/ -/*global define*/ -define([ - 'ko' -], function ( - ko -) { - 'use strict'; - - return { - address: ko.observable(null), - lastCall: ko.observable(null), - sameCall: ko.observable(null), - - setLastCall: function (data) { - this.lastCall(data); - }, - - setSameCall: function (bool) { - this.sameCall(bool); - }, - - isSameCall: function () { - return this.sameCall(); - }, - - getLastCall: function (dataOnly) { - if (dataOnly) { - return this.lastCall()[1]; - } - return this.lastCall(); - }, - - validateLastCall: function (keyToMatch) { - if (!this.lastCall) { - return false; - } - - if (this.lastCall[0] === keyToMatch) { - this.setSameCall(true); - return false; - } - - this.setSameCall(false); - - return true; - } - }; -}); diff --git a/view/frontend/web/js/Helper/DataProvider.js b/view/frontend/web/js/Helper/DataProvider.js deleted file mode 100644 index af289a2..0000000 --- a/view/frontend/web/js/Helper/DataProvider.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact servicedesk@totalinternetgroup.nl for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - */ -define(function () { - var isPostcodeBeOn = 0; - return { - isPostcodeBeOn: function () { - return isPostcodeBeOn; - }, - - setPostcodeBeOn: function (postcodeBeOn) { - isPostcodeBeOn = postcodeBeOn; - }, - }; -}); \ No newline at end of file diff --git a/view/frontend/web/js/Helper/Logger.js b/view/frontend/web/js/Helper/Logger.js deleted file mode 100644 index 137a984..0000000 --- a/view/frontend/web/js/Helper/Logger.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to support@postcodeservice.com so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact support@postcodeservice.com for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - */ -define([], function () { - return { - log: function () { - console.log.apply(console, arguments); - }, - - info: function () { - console.info.apply(console, arguments); - }, - - error: function () { - console.error.apply(console, arguments); - } - }; -}); diff --git a/view/frontend/web/js/action/create-shipping-address-mixin.js b/view/frontend/web/js/action/create-shipping-address-mixin.js new file mode 100644 index 0000000..53e0db7 --- /dev/null +++ b/view/frontend/web/js/action/create-shipping-address-mixin.js @@ -0,0 +1,20 @@ +define([ + 'jquery', + 'mage/utils/wrapper', + 'Magento_Checkout/js/model/quote' +], function ($, wrapper,quote) { + 'use strict'; + + return function (setShippingInformationAction) { + return wrapper.wrap(setShippingInformationAction, function (originalAction, messageContainer) { + + if (messageContainer.custom_attributes != undefined) { + $.each(messageContainer.custom_attributes , function( key, value ) { + messageContainer['custom_attributes'][key] = {'attribute_code':key,'value':value}; + }); + } + + return originalAction(messageContainer); + }); + }; +}); diff --git a/view/frontend/web/js/action/set-billing-address-mixin.js b/view/frontend/web/js/action/set-billing-address-mixin.js index 1eaf5f2..b783cef 100644 --- a/view/frontend/web/js/action/set-billing-address-mixin.js +++ b/view/frontend/web/js/action/set-billing-address-mixin.js @@ -28,7 +28,8 @@ * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US */ -/* jshint ignore:start */ +/*jshint browser:true jquery:true*/ +/*global alert*/ define([ 'jquery', 'mage/utils/wrapper', @@ -40,6 +41,14 @@ define([ ) { 'use strict'; + function findAttribute(attributeName, address) { + return address.customAttributes.find( + function (element) { + return element.attribute_code === attributeName; + } + ); + } + return function (setBillingAddressAction) { return wrapper.wrap(setBillingAddressAction, function (originalAction) { var billingAddress = quote.billingAddress(); @@ -56,24 +65,23 @@ define([ billingAddress['extension_attributes'] = {}; } - if (billingAddress['street'] !== undefined && billingAddress['street'].length > 1) { - billingAddress['street'].splice(1); + var housenumber = findAttribute('tig_housenumber', billingAddress); + var housenumberAddition = findAttribute('tig_housenumber_addition', billingAddress); + var street = findAttribute('tig_street', billingAddress); + + if (housenumber) { + billingAddress['extension_attributes']['tig_housenumber'] = housenumber.value; } - // < M2.3.0 - if (billingAddress.customAttributes !== undefined && billingAddress.customAttributes.tig_housenumber !== undefined) { - billingAddress['extension_attributes']['tig_housenumber'] = billingAddress.customAttributes.tig_housenumber; - billingAddress['extension_attributes']['tig_housenumber_addition'] = billingAddress.customAttributes.tig_housenumber_addition; - return originalAction(); + if (housenumberAddition) { + billingAddress['extension_attributes']['tig_housenumber_addition'] = housenumberAddition.value; } - // >= M2.3.0 - if (billingAddress.customAttributes[0] !== undefined && billingAddress.customAttributes[0].attribute_code === 'tig_housenumber') { - billingAddress['extension_attributes']['tig_housenumber'] = billingAddress.customAttributes[0].value; - billingAddress['extension_attributes']['tig_housenumber_addition'] = billingAddress.customAttributes[1].value; + + if (street) { + billingAddress['extension_attributes']['tig_street'] = street.value; } return originalAction(); }); }; }); -/* jshint ignore:end */ diff --git a/view/frontend/web/js/action/set-shipping-information-mixin.js b/view/frontend/web/js/action/set-shipping-information-mixin.js index 54d8ff9..78d1bf9 100644 --- a/view/frontend/web/js/action/set-shipping-information-mixin.js +++ b/view/frontend/web/js/action/set-shipping-information-mixin.js @@ -28,19 +28,25 @@ * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US */ -/* jshint ignore:start */ +/*jshint browser:true jquery:true*/ +/*global alert*/ define([ 'jquery', 'mage/utils/wrapper', - 'Magento_Checkout/js/model/quote' -], function ( - $, - wrapper, - quote -) { + 'Magento_Checkout/js/model/quote', + +], function ($, wrapper, quote) { 'use strict'; + function findAttribute(attributeName, address) { + return address.customAttributes.find( + function (element) { + return element.attribute_code === attributeName; + } + ); + } return function (setShippingInformationAction) { + return wrapper.wrap(setShippingInformationAction, function (originalAction) { var shippingAddress = quote.shippingAddress(); @@ -56,24 +62,23 @@ define([ shippingAddress['extension_attributes'] = {}; } - if (shippingAddress['street'] !== undefined && shippingAddress['street'].length > 1) { - shippingAddress['street'].splice(1); + var housenumber = findAttribute('tig_housenumber', shippingAddress); + var housenumberAddition = findAttribute('tig_housenumber_addition', shippingAddress); + var street = findAttribute('tig_street', shippingAddress); + + if (housenumber) { + shippingAddress['extension_attributes']['tig_housenumber'] = housenumber.value; } - // < M2.3.0 - if (shippingAddress.customAttributes !== undefined && shippingAddress.customAttributes.tig_housenumber !== undefined) { - shippingAddress['extension_attributes']['tig_housenumber'] = shippingAddress.customAttributes.tig_housenumber; - shippingAddress['extension_attributes']['tig_housenumber_addition'] = shippingAddress.customAttributes.tig_housenumber_addition; - return originalAction(); + if (housenumberAddition) { + shippingAddress['extension_attributes']['tig_housenumber_addition'] = housenumberAddition.value; } - // >= M2.3.0 - if (shippingAddress.customAttributes[0] !== undefined && shippingAddress.customAttributes[0].attribute_code === 'tig_housenumber') { - shippingAddress['extension_attributes']['tig_housenumber'] = shippingAddress.customAttributes[0].value; - shippingAddress['extension_attributes']['tig_housenumber_addition'] = shippingAddress.customAttributes[1].value; + + if (street) { + shippingAddress['extension_attributes']['tig_street'] = street.value; } return originalAction(); }); }; }); -/* jshint ignore:end */ diff --git a/view/frontend/web/js/lib/mage/mage-mixin.js b/view/frontend/web/js/lib/mage/mage-mixin.js deleted file mode 100644 index 768a140..0000000 --- a/view/frontend/web/js/lib/mage/mage-mixin.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact servicedesk@tig.nl for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * - * Credits to - * https://magento.stackexchange.com/questions/154393/magento-2-jquery-ui-autocomplete/154446#154446 - */ -define([ - 'jquery', - 'jquery/ui' -], function ($) { - 'use strict'; - - return function (data) { - - $.widget('mage.menu', data.menu, { - _create: function () { - $(this.element).data('ui-menu', this); - this._super(); - } - }); - - data.menu = $.mage.menu; - - return data; - }; -}); diff --git a/view/frontend/web/js/view/billing-address-mixin.js b/view/frontend/web/js/view/billing-address-mixin.js deleted file mode 100644 index 7b92a16..0000000 --- a/view/frontend/web/js/view/billing-address-mixin.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact servicedesk@totalinternetgroup.nl for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - */ -define([ - 'jquery', - 'Magento_Checkout/js/model/quote' -], function ( - $, - quote -) { - 'use strict'; - - return function (Component) { - return Component.extend({ - tigHouseNumber: function () { - var customAttributes = quote.billingAddress().customAttributes; - - if (customAttributes && customAttributes.length > 0) { - var houseNumber = ""; - var houseNumberAddition = ""; - - // check if custom attribute exists and is not empty - customAttributes.forEach(function (attribute) { - if (attribute.attribute_code === "tig_housenumber" && attribute.value !== "") { - houseNumber = attribute.value; - } - - if (attribute.attribute_code === "tig_housenumber_addition" && attribute.value !== "") { - houseNumberAddition = attribute.value; - } - }); - - return houseNumber + (houseNumberAddition ? " " + houseNumberAddition : ""); - } - } - }); - }; -}); diff --git a/view/frontend/web/js/view/form/be/autocompleteElement.js b/view/frontend/web/js/view/form/be/autocompleteElement.js deleted file mode 100644 index de6fa89..0000000 --- a/view/frontend/web/js/view/form/be/autocompleteElement.js +++ /dev/null @@ -1,360 +0,0 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to servicedesk@tig.nl so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact servicedesk@tig.nl for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - */ -define([ - 'jquery', - 'uiRegistry', - 'ko', - 'TIG_Postcode/js/Helper/DataProvider', - 'jquery-ui-modules/autocomplete' -], function ( - $, - Registry, - ko, - DataProvider -) { - 'use strict'; - - return function (originalElement) { - return originalElement.extend({ - defaults : { - message : ko.observable(null), - imports : { - observeCountry : '${ $.parentName }.country_id:value', - observePostcode : '${ $.parentName }.postcode-field-group.field-group.postcode:value', - observeStreet : '${ $.parentName }.street.0:value' - }, - isBePostcodeCheckOn : ko.observable(DataProvider.isPostcodeBeOn()) - }, - - observeCountry : function (value) { - if (!this.isBePostcodeCheckOn()) { - return; - } - - window.customSelf = this; - - if (value) { - window.customSelf.switchToBe(value === 'BE'); - } - }, - - /** - * When going through the autocompleteZipcodezone function, var self gets defined. When going back and forth - * through shipping/billing steps the 'this' scope will change, but stays the same within - * autocompleteZipcodezone. This observer makes the customScope/Parentname for the current scope available. - **/ - observePostcode : function (value) { - if (!this.isBePostcodeCheckOn()) { - return; - } - - window.customSelf = this; - - if (!value) { - /** Empty out the zipcode field when value is removed. **/ - var menuElement = $('.' + window.customSelf.customScope + '\\.tigAutocomplete'); - menuElement.hide(); - } - - if (value !== window.currentZipcode) { - var zipcodeElement = $('div[name="' + window.customSelf.customScope + '.postcode"]'); - zipcodeElement.find('.tig-autocomplete-result-city').text(''); - } - window.currentZipcode = value; - }, - - observeStreet : function () { - if (!this.isBePostcodeCheckOn()) { - return; - } - - window.customSelf = this; - }, - - /** - * if switchToBe is true, disable the street field when zipcode is empty - * otherwise switch back to defaults of Magento. - **/ - switchToBe : function (switchToBe) { - var self = this; - if (switchToBe) { - self.disableStreetField(); - - return; - } - self.enableStreetField(); - }, - - /** Disable the street field (but only if zipcode is empty). **/ - disableStreetField : function () { - var self = this; - - - var fields = [ - self.parentName + '.postcode-field-group.field-group.postcode', - self.parentName + '.street.0' - ]; - - var placeholder = $.mage.__('Please select a postcode before filling the street field.'); - Registry.get(fields, function (postcodeElement, streetElement) { - if (!postcodeElement.value()) { - // This is for setting the init placeholder - streetElement.placeholder = placeholder; - $('.tig_street_autocomplete .input-text').attr('placeholder', placeholder); - } - $('.tig_zipcodezone_autocomplete').addClass('tig-postcode-be'); - $("div[name*='tig_housenumber']").addClass('tig-housenumber-be'); - $("div[name*='tig_housenumber_addition']").addClass('tig-housenumber-addition-be'); - }); - }, - - /** Back to the Magento default. **/ - enableStreetField : function () { - var self = this; - Registry.get(self.parentName + '.street.0', function (streetElement) { - streetElement.placeholder = ''; - $('.tig_street_autocomplete .input-text').attr('placeholder', ''); - streetElement.enable(); - $('.tig_zipcodezone_autocomplete').removeClass('tig-postcode-be'); - $("div[name*='tig_housenumber']").removeClass('tig-housenumber-be'); - $("div[name*='tig_housenumber_addition']").removeClass('tig-housenumber-addition-be'); - }); - }, - - addAutocomplete : function () { - var self = this; - - var tigClass = "." + Object.keys(this.additionalClasses)[0]; - if (tigClass === '.tig_zipcodezone_autocomplete') { - self.autocompleteZipcodezone(); - } - - if (tigClass === '.tig_street_autocomplete') { - self.autocompleteStreet(); - } - - // Force auto complete off - $('.tig_zipcodezone_autocomplete .input-text').attr('autocomplete', 'no'); - $('.tig_street_autocomplete .input-text').attr('autocomplete', 'no'); - }, - - /** - * set the auto complete for the zipcode field. - */ - autocompleteZipcodezone : function () { - var self = this; - $(".tig_zipcodezone_autocomplete .input-text").each(function () { - $(this).parent().append(''); - $(this).autocomplete({ - source : function (zipcodezone, response) { - this.menu.element.addClass(self.customScope + ".tigAutocomplete"); - this.menu.element.addClass('tigJqueryUiClass'); - if (!self.isCountryBe()) { - /** - * Somehow the loader occasionally pops up on different countries. - * Here we force remove the loader. - */ - this.element.removeClass('ui-autocomplete-loading'); - response([]); - return; - } - response([$.mage.__('Busy with loading zipcodes...')]); - /** - * Prevent tabbing while zipcode is still loading. - */ - this.element.on('keydown', function (objEvent) { - if (objEvent.keyCode == 9) { - objEvent.preventDefault(); - } - }); - $.ajax({ - method : 'GET', - url : window.checkoutConfig.postcode.action_url.postcode_be_getpostcode, - data : { - zipcodezone : zipcodezone.term - }, - zipcodeElement : this - }).done(function (data) { - /** - * This part will refresh the data inside the array - */ - - // Force remove the loader & re-enable tabbing out of the field. - this.zipcodeElement.element.removeClass('ui-autocomplete-loading'); - - if (data.success == false) { - response([$.mage.__('No results found.')]); - return; - } - var selectBoxArr = []; - $.each(data, function (key, value) { - selectBoxArr.push(data[key].postcode + ' - ' + data[key].plaats); - }); - - response(selectBoxArr); - setTimeout(function (zipcodeElement) { - zipcodeElement.element.off('keydown'); - }, 250, this.zipcodeElement); - }).fail(function (data) { - console.log(data); - }); - }, - select : function (event, ui) { - /** Prevent weird values being inserted into the postcode / city fields **/ - if (ui.item.value == $.mage.__('Busy with loading zipcodes...') || - ui.item.value == $.mage.__('No results found.')) { - ui.item.value = ''; - return false; - } - var fields = [ - window.customSelf.parentName + '.city', - window.customSelf.parentName + '.street.0' - ]; - - Registry.get(fields, function ( - cityElement, - streetElement - ) { - cityElement.set('value', ui.item.value.substring(7, ui.item.value.length)); - $('.tig_street_autocomplete .input-text').attr('placeholder', ''); - streetElement.placeholder = ''; - streetElement.enable(); - }); - event.target.parentElement.getElementsByClassName('tig-autocomplete-result-city')[0] - .textContent = ui.item.value.substring(4, ui.item.value.length); - ui.item.value = ui.item.value.substring(0, 4); - window.currentZipcode = ui.item.value; - }, - close : function (event) { - var menuElement = $('.' + window.customSelf.customScope + '\\.tigAutocomplete'); - if (event.originalEvent !== undefined && - event.originalEvent.type !== 'menuselect' && - !menuElement.is(":visible") - ) { - menuElement.show(); - - return false; - } - $("input[name*='postcode']").trigger('change'); - $("input[name*='city']").trigger('change'); - }, - delay : 0 - }); - }); - }, - - /** - * set the auto complete for the street field after zipcodezone is filled. - */ - autocompleteStreet : function () { - var self = this; - - var postcode = null; - var city = null; - var street = null; - - $(".tig_street_autocomplete .input-text").each(function () { - $(this).autocomplete({ - source : function (request, response) { - this.menu.element.addClass('tigJqueryUiClass'); - this.menu.element.appendTo(this.element.closest('.tig_street_autocomplete')); - if (!self.isCountryBe()) { - /** - * Somehow the loader occasionally pops up on different countries. - * Here we force remove the loader. - */ - this.element.removeClass('ui-autocomplete-loading'); - response([]); - return; - } - response([$.mage.__('Busy with loading streets...')]); - Registry.get([ - window.customSelf.parentName + '.postcode-field-group.field-group.postcode', - window.customSelf.parentName + '.city', - window.customSelf.parentName + '.street.0' - ], function (postcodeElement, cityElement, streetElement) { - postcode = postcodeElement.value(); - city = cityElement.value(); - street = streetElement.value(); - }); - - $.ajax({ - method : 'GET', - url : window.checkoutConfig.postcode.action_url.postcode_be_getstreet, - data : { - zipcode : postcode, - city : city, - street : street - }, - streetElement : this - }).done(function (data) { - /** - * This part will refresh the data inside the array - */ - this.streetElement.element.removeClass('ui-autocomplete-loading'); - - if (data.success == false) { - response([$.mage.__('No results found. Please fill in manually.')]); - return; - } - var selectBoxArr = []; - $.each(data, function (key, value) { - selectBoxArr.push(value.straat); - }); - - response(selectBoxArr); - }).fail(function (data) { - console.log(data); - }); - }, - select : function (event, ui) { - /** Prevent weird values being inserted into the postcode / city fields **/ - if (ui.item.value == $.mage.__('Busy with loading streets...') || - ui.item.value == $.mage.__('No results found. Please fill in manually.')) { - ui.item.value = ''; - return false; - } - }, - close : function (event, ui) { - $("input[name*='street']").trigger('change'); - } - }); - }); - }, - - isCountryBe : function () { - var currentFormData = this.source.get(window.customSelf.customScope); - - return currentFormData && currentFormData.country_id === 'BE'; - }, - }); - }; -}); diff --git a/view/frontend/web/js/view/form/fields.js b/view/frontend/web/js/view/form/fields.js deleted file mode 100644 index 5d68bd4..0000000 --- a/view/frontend/web/js/view/form/fields.js +++ /dev/null @@ -1,514 +0,0 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to support@postcodeservice.com so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact support@postcodeservice.com for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - */ -define([ - 'jquery', - 'Magento_Checkout/js/model/quote', - 'Magento_Checkout/js/model/address-converter', - 'Magento_Ui/js/form/components/group', - 'ko', - 'TIG_Postcode/js/Helper/Logger', - 'TIG_Postcode/js/Address/State', - 'uiRegistry', - 'underscore' -], function ( - $, - quote, - AddressConverter, - uiComponent, - ko, - Logger, - State, - Registry, - _ -) { - 'use strict'; - - return uiComponent.extend({ - defaults : { - template : 'TIG_Postcode/checkout/field-group', - isLoading : false, - message : ko.observable(null), - imports : { - observePostcode : '${ $.parentName }.postcode-field-group.field-group.postcode:value', - observeHousenumber : '${ $.parentName }.postcode-field-group.field-group.housenumber:value', - observeAddition : '${ $.parentName }.postcode-field-group.field-group.housenumber_addition:value', - observeCountry : '${ $.parentName }.country_id:value' - }, - sameCall : false, - timer : undefined, - beAutocomplete : false - }, - - addToAddress: function (address, customAttributes) { - // Subtract one, as the index is 0 - var housenumberIndex = window.checkoutConfig.postcode.streetparser.housenumberParsing - 1; - var housenumberAdditionIndex = window.checkoutConfig.postcode.streetparser.housenumberAdditionParsing - 1; - - _.each(address[customAttributes], function (attr) { - if (_.isUndefined(attr.attribute_code || attr.value === '')) { - return; - } - - var value; - // Simply concating provides the housenumber "undefined 37", because street[1] can be undefined. - if (attr.attribute_code === 'tig_housenumber') { - value = [address.street[housenumberIndex], attr.value].join(' '); - address.street[housenumberIndex] = value.trim(); - } - - if (attr.attribute_code === 'tig_housenumber_addition') { - value = [address.street[housenumberAdditionIndex], attr.value].join(' '); - address.street[housenumberAdditionIndex] = value.trim(); - } - }.bind(this)); - - return address; - }, - - updateAddresses: function (options) { - if (typeof options.data === "string") { - var data = $.parseJSON(options.data); - - if (data != null) { - // Handle Magento inconsistencies - var customAttributes = 'custom_attributes'; - - if (!_.isUndefined(data.address) && !_.isUndefined(data.address[customAttributes])) { - data.address = this.addToAddress(data.address, customAttributes); - } - - customAttributes = 'customAttributes'; - - if (!_.isUndefined(data.addressInformation) && data.addressInformation && !_.isUndefined(data.addressInformation.shipping_address) && !_.isUndefined(data.addressInformation.shipping_address[customAttributes])) { - data.addressInformation.shipping_address = this.addToAddress(data.addressInformation.shipping_address, customAttributes); - } - - if (!_.isUndefined(data.addressInformation) && data.addressInformation && !_.isUndefined(data.addressInformation.billing_address) && !_.isUndefined(data.addressInformation.billing_address[customAttributes])) { - data.addressInformation.billing_address = this.addToAddress(data.addressInformation.billing_address, customAttributes); - } - - if (!_.isUndefined(data.billingAddress) && data.billingAddress && !_.isUndefined(data.billingAddress[customAttributes])) { - data.billingAddress = this.addToAddress(data.billingAddress, customAttributes); - } - - return JSON.stringify(data); - } - } - }, - - initialize : function () { - this._super() - ._setClasses(); - - // Only allow this prefilter once, to prevent updating addresses multiple times - if (window.checkoutConfig.postcode.is_initialized === undefined) { - // Credits to OneStepCheckout.com and @speedupmate (https://gist.github.com/speedupmate) for this logic and solution - $.ajaxPrefilter( - function ( options, originalOptions, jqXHR ) { - var allowedMethods = ["POST","DELETE","PUT"]; - var allowedUrls = _.filter(['checkout/onepage/update', 'rest/'], function (url) { - return options.url.indexOf(url) !== -1; - }); - - if ($.inArray(options.type.toUpperCase(), allowedMethods) === -1 || - allowedUrls.length < 1) { - return false; - } - - options.data = this.updateAddresses(options); - }.bind(this) - ); - window.checkoutConfig.postcode.is_initialized = true; - } - - // PSM2-116 - If customAttributes exist, the address already contains a tig_housenumber. - // Sometimes extension attributes get lost, fill them every time the address changes. - quote.shippingAddress.subscribe(function (address) { - if (address.extension_attributes === undefined) { - address.extension_attributes = {}; - } - - if (address.customAttributes !== undefined && address.customAttributes[0] !== undefined && address.customAttributes[0].attribute_code === 'tig_housenumber') { - address.extension_attributes.tig_housenumber = address.customAttributes[0].value; - address.extension_attributes.tig_housenumber_addition = address.customAttributes[1].value; - } - }); - - quote.billingAddress.subscribe(function (address) { - if (address.extension_attributes === undefined) { - address.extension_attributes = {}; - } - - if (address.customAttributes !== undefined && address.customAttributes[0] !== undefined && address.customAttributes[0].attribute_code === 'tig_housenumber') { - address.extension_attributes.tig_housenumber = address.customAttributes[0].value; - address.extension_attributes.tig_housenumber_addition = address.customAttributes[1].value; - } - }); - - var self = this; - Registry.async(this.provider)(function () { - self.initModules(); - self.updateFieldData(); - }); - - /** If zipcodezone is available, we can assume the be check is on **/ - Registry.get(self.parentName + '.zipcodezone', function () { - self.beAutocomplete = true; - }); - - return this; - }, - - initObservable : function () { - this._super().observe(['isLoading']); - - if (!window.checkoutConfig.postcode.postcode_active) { - return this; - } - - return this; - }, - - observeHousenumber : function (value) { - if (value) { - this.updateFieldData(); - } - }, - - observePostcode : function (value) { - if (value) { - this.updateFieldData(); - } - }, - - observeCountry : function (value) { - var message = $('.tig-postcode-validation-message'); - - this.toggleAddressFields(value); - - if (value !== 'NL') { - message.hide(); - return; - } - - if (value && value === 'NL') { - this.updateFieldData(); - } - }, - - /** - * Hide or show every address line that's not the first address line when NL or BE is - * selected. Restore the original checkout fields when NL or BE is NOT selected. - */ - toggleAddressFields : function (country) { - var fields = [ - this.parentName + '.street', - this.parentName + '.city', - this.parentName + '.postcode-field-group.field-group.postcode', - this.parentName + '.postcode-field-group.field-group.housenumber', - this.parentName + '.postcode-field-group.field-group.housenumber_addition' - ]; - - Registry.get(fields, function ( - streetElement, - cityElement, - postcodeElement, - housenumberElement, - housenumberAdditionalElement - ) { - streetElement.visible(!(country === 'BE' || country === 'NL')); - housenumberElement.visible(country === 'BE' || country === 'NL'); - housenumberAdditionalElement.visible(country === 'BE' || country === 'NL'); - - // In some countries housenumber is not required - housenumberElement.required(country === 'BE' || country === 'NL'); - housenumberElement.validation['required-entry'] = (country === 'BE' || country === 'NL'); - - // Next three lines are for initial load. Fields are available in uiRegistry, but not yet in jQuery. - postcodeElement.additionalClasses['tig-postcode-full-width'] = !(country === 'NL' || country === 'BE'); - streetElement.additionalClasses.tig_hidden = true; - cityElement.additionalClasses.tig_hidden = true; - - var postcodeField = $('.tig-postcode-field-group div[name$=postcode]'); - /* jshint ignore:start */ - country === 'NL' || country === 'BE' ? postcodeField.removeClass('tig-postcode-full-width') : postcodeField.addClass('tig-postcode-full-width'); - /* jshint ignore:end */ - - if (country === 'NL') { - $('.tig_hidden').hide(200); - - return; - } - - $('.tig_hidden').show(200); - }); - - // Handle street fields separately in a for loop. they could be disabled in the configs. - var streetFields = [ - this.parentName + '.street.1', - this.parentName + '.street.2', - this.parentName + '.street.3' - ]; - - /* jshint ignore:start */ - for (var i=0; i < streetFields.length; i++) { - Registry.get(streetFields[i], function (streetElement) { - streetElement.visible(!(country === 'BE' || country === 'NL')); - }); - } - /* jshint ignore:end */ - }, - - updateFieldData : function () { - var self = this; - - if (typeof this.timer !== 'undefined') { - clearTimeout(this.timer); - } - - this.timer = setTimeout(function () { - self.setFieldData(); - }, 1000); - }, - - setFieldData : function () { - if (!this.source) { - return; - } - - var address = this.controlRegistry(State.address()); - if (!address) { - return; - } - - if (!address.postcode || !address.housenumber) { - this.renderFieldsAndMessage(200, ''); - return; - } - - if (!State.validateLastCall(address.postcode+address.housenumber)) { - this.handelResponse(State.getLastCall(true)); - } - - if (JSON.stringify(State.address()) === JSON.stringify(address) && State.isSameCall()) { - this.renderFieldsAndMessage(200, ''); - return; - } - - Logger.info('Start postcode check'); - this.getAddressData(address.postcode, address.housenumber); - - }, - - getAddressData : function (postcode, housenumber) { - var self = this; - - if (self.request !== undefined) { - self.request.abort(); - } - - self.isLoading(true); - self.request = $.ajax({ - method:'GET', - url : window.checkoutConfig.postcode.action_url.postcode_service, - data : { - huisnummer : housenumber, - postcode : postcode - } - }).done(function (data) { - self.handelResponse(data, postcode+housenumber); - }).fail(function (data) { - Logger.error(data); - }).always(function (data) { - self.isLoading(false); - Logger.info(data); - }); - }, - - handelResponse : function (data, key) { - var self = this; - var type = 'failed'; - if (data === null || !data.success) { - Logger.error('Postcode check : No success'); - } - - if (data.straatnaam && data.woonplaats) { - State.setLastCall([key, data]); - Registry.get(self.parentName + '.street.0').set('value', data.straatnaam); - Registry.get(self.parentName + '.city').set('value', data.woonplaats); - - var streetNr = Registry.get(self.parentName + '.street.1'); - var streetAddition = Registry.get(self.parentName + '.street.2'); - - if (streetNr !== undefined) { - streetNr.set('value', ''); - } - - if (streetAddition !== undefined) { - streetAddition.set('value', ''); - } - - // Trigger change for subscripe methods. - $("input[name*='street[0]']").trigger('change'); - $("input[name*='city']").trigger('change'); - - type = 'success'; - } - - this.renderFieldsAndMessage(100, type); - }, - - renderFieldsAndMessage : function (motion, type) { - var message = $('.tig-postcode-validation-message'); - - $('.tig_hidden').show(motion); - if (type !== 'failed') { - this.renderAddressData(); - message.hide(motion); - return; - } - - message.html($.mage.__('Sorry, we could not find the address on the given zip code and house number combination. If you are sure that the zip code and house number are correct, please fill in the address details manually.')).show(); - }, - - // Magaplaza and other oneStepcheckouts render the billing fields on the same page. - renderAddressData : function () { - if (window.checkoutConfig.postcode.checkout === 'default' || - window.checkoutConfig.postcode.checkout === 'blank' - ) { - return; - } - - var shippingAddress = quote.shippingAddress(), - shippingData = AddressConverter.formAddressDataToQuoteAddress( - this.source.get('shippingAddress') - ); - - //Copy form data to quote shipping address object (Credit: Magaplaza) - for (var shippingField in shippingData) { - if (shippingData.hasOwnProperty(shippingField) && - shippingAddress.hasOwnProperty(shippingField) && - typeof shippingData[shippingField] != 'function' && //eslint-disable-line eqeqeq - _.isEqual(shippingAddress[shippingField], shippingData[shippingField]) - ) { - shippingAddress[shippingField] = shippingData[shippingField]; - } else if (typeof shippingData[shippingField] != 'function' && //eslint-disable-line eqeqeq - !_.isEqual(shippingAddress[shippingField], shippingData[shippingField]) - ) { - shippingAddress = shippingData; - break; - } - } - - quote.shippingAddress(shippingAddress); - - var billingAddress = quote.billingAddress(), - billingData = AddressConverter.formAddressDataToQuoteAddress( - this.source.get('billingAddress') - ); - - //Copy form data to quote shipping address object (Credit: Magaplaza) - for (var billingField in billingData) { - if (billingData.hasOwnProperty(billingField) && - billingAddress.hasOwnProperty(billingField) && - typeof billingData[billingField] != 'function' && //eslint-disable-line eqeqeq - _.isEqual(billingAddress[billingField], billingData[billingField]) - ) { - billingAddress[billingField] = billingData[billingField]; - } else if (typeof billingData[billingField] != 'function' && //eslint-disable-line eqeqeq - !_.isEqual(billingAddress[billingField], billingData[billingField]) - ) { - billingAddress = billingData; - break; - } - } - - quote.billingAddress(billingAddress); - }, - - controlRegistry : function (address) { - var self = this; - /** - * Country ID is not available yet and will default to NL, causing unexpected behaviour when a customer - * has a quote with another country in it. - */ - if ($("[name*='" + self.customScope + ".country_id']").length < 1) { - $('.tig_hidden').show(); - return; - } - var currentFormData = this.source.get(this.customScope); - - // Wait until the data is filled in. - if (!currentFormData) { - return null; - } - - // MagePlaza compatibility. - if (currentFormData.shippingAddress) { - var tempData = currentFormData.shippingAddress; - currentFormData.postcode = tempData.postcode; - currentFormData.custom_attributes = tempData.custom_attributes; - } - - $('.tig_hidden').hide(); - if (currentFormData.country_id !== "NL") { - $('.tig_hidden').show(); - return null; - } - - if (!currentFormData.postcode) { - currentFormData = this.source.shippingAddress; - } - - if (!currentFormData.postcode || !currentFormData.custom_attributes.tig_housenumber) { - return null; - } - - var addressData = { - postcode : currentFormData.postcode, - housenumber : currentFormData.custom_attributes.tig_housenumber, - addition : currentFormData.custom_attributes.tig_housenumber_addition - }; - - if (JSON.stringify(addressData) !== JSON.stringify(address)) { - address = addressData; - } - - State.address(address); - return address; - }, - - // Compatibility with Mageplaza - #POSTCODENL-235 - value: function () { - return null; - } - }); -}); diff --git a/view/frontend/web/js/view/hide-tig-attributes-mixin.js b/view/frontend/web/js/view/hide-tig-attributes-mixin.js new file mode 100644 index 0000000..ad67a06 --- /dev/null +++ b/view/frontend/web/js/view/hide-tig-attributes-mixin.js @@ -0,0 +1,26 @@ +'use strict'; +define([ + 'TIG_Postcode/js/helper/field-types' +],function (FieldTypes) { + 'use strict'; + + var mixin = { + + getCustomAttributeLabel: function(element) { + // Hide TIG Elements + if (element && 'attribute_code' in element && + [ + FieldTypes.house_number, + FieldTypes.house_number_addition, + FieldTypes.street + ].includes(element.attribute_code)) { + return; + } + return this._super(element); + } + }; + + return function (magentoBlock) { + return magentoBlock.extend(mixin); + }; +}); diff --git a/view/frontend/web/js/view/myparcel/delivery-options-mixin.js b/view/frontend/web/js/view/myparcel/delivery-options-mixin.js deleted file mode 100644 index a03bb1d..0000000 --- a/view/frontend/web/js/view/myparcel/delivery-options-mixin.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to support@postcodeservice.com so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact support@postcodeservice.com for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - */ -define([ - 'mage/utils/wrapper', - 'uiRegistry' -], function ( - wrapper, - Registry -) { - 'use strict'; - - return function (deliveryOptions) { - deliveryOptions.getHouseNumber = wrapper.wrapSuper(deliveryOptions.getHouseNumber, function (address) { - var housenumberElement = Registry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.postcode-field-group.field-group.housenumber'); - - if (housenumberElement === undefined) { - return this._super(address); - } - - var housenumber = housenumberElement.value(); - if (!housenumber) { - return this._super(address); - } - - return housenumber; - }); - - return deliveryOptions; - }; -}); diff --git a/view/frontend/web/template/billing-address/details.html b/view/frontend/web/template/billing-address/details.html deleted file mode 100644 index 9df1791..0000000 --- a/view/frontend/web/template/billing-address/details.html +++ /dev/null @@ -1,30 +0,0 @@ - -
- -
- -
- ,
-
-
- - -
- -
-
-
- - -
- diff --git a/view/frontend/web/template/checkout/field-be-group.html b/view/frontend/web/template/checkout/field-be-group.html deleted file mode 100644 index 166fbb5..0000000 --- a/view/frontend/web/template/checkout/field-be-group.html +++ /dev/null @@ -1,6 +0,0 @@ -
- - - -
- diff --git a/view/frontend/web/template/checkout/field-group.html b/view/frontend/web/template/checkout/field-group.html deleted file mode 100644 index b32abea..0000000 --- a/view/frontend/web/template/checkout/field-group.html +++ /dev/null @@ -1,7 +0,0 @@ -
- - - -
-
- diff --git a/view/frontend/web/template/form/element/autocomplete.html b/view/frontend/web/template/form/element/autocomplete.html deleted file mode 100644 index e99d903..0000000 --- a/view/frontend/web/template/form/element/autocomplete.html +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/view/frontend/web/template/form/element/housenumber.html b/view/frontend/web/template/form/element/housenumber.html deleted file mode 100644 index f51f2df..0000000 --- a/view/frontend/web/template/form/element/housenumber.html +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/view/frontend/web/template/form/element/addition.html b/view/frontend/web/template/form/element/postcode-field.html similarity index 70% rename from view/frontend/web/template/form/element/addition.html rename to view/frontend/web/template/form/element/postcode-field.html index 76554a3..2a7643e 100644 --- a/view/frontend/web/template/form/element/addition.html +++ b/view/frontend/web/template/form/element/postcode-field.html @@ -1,10 +1,11 @@ - - -
- - -
- -
-

- ,
-
-
- - -
- -
-
-
- - - - diff --git a/view/frontend/web/template/shipping-information/address-renderer/default.html b/view/frontend/web/template/shipping-information/address-renderer/default.html deleted file mode 100644 index 08b00e1..0000000 --- a/view/frontend/web/template/shipping-information/address-renderer/default.html +++ /dev/null @@ -1,26 +0,0 @@ - - - -
- - - - - -
- ,
-
-
- - -
- -
-
-
-
From 528e68348e123c8e71873b9209cd51641dd70051 Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Tue, 5 Apr 2022 14:24:58 +0200 Subject: [PATCH 07/36] Fix for when default country is not NL or BE --- view/base/web/js/form/element/tig-postcode-field.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/view/base/web/js/form/element/tig-postcode-field.js b/view/base/web/js/form/element/tig-postcode-field.js index 7df0892..a3b3c72 100644 --- a/view/base/web/js/form/element/tig-postcode-field.js +++ b/view/base/web/js/form/element/tig-postcode-field.js @@ -78,10 +78,10 @@ define([ * to restart the handler to initialize fields. */ afterRender: function(){ - if (!this.currentPostcodeHandler || this.uiInitialized) { + this.uiInitialized = true; + if (!this.currentPostcodeHandler) { return } - this.uiInitialized = true; this.currentPostcodeHandler.reset(); this.currentPostcodeHandler.handle(); }, From f4251615ae5ea46f0c96b34e4c3ec647cab1728e Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Tue, 5 Apr 2022 14:25:16 +0200 Subject: [PATCH 08/36] Removed DE for now --- .../web/js/postcode-handler/postcode-de.js | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 view/base/web/js/postcode-handler/postcode-de.js diff --git a/view/base/web/js/postcode-handler/postcode-de.js b/view/base/web/js/postcode-handler/postcode-de.js deleted file mode 100644 index 86e6da3..0000000 --- a/view/base/web/js/postcode-handler/postcode-de.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * - * ..::.. - * ..::::::::::::.. - * ::'''''':''::''''':: - * ::.. ..: : ....:: - * :::: ::: : : :: - * :::: ::: : ''' :: - * ::::..:::..::.....:: - * ''::::::::::::'' - * ''::'' - * - * - * NOTICE OF LICENSE - * - * This source file is subject to the Creative Commons License. - * It is available through the world-wide-web at this URL: - * http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - * If you are unable to obtain it through the world-wide-web, please send an email - * to servicedesk@totalinternetgroup.nl so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade this module to newer - * versions in the future. If you wish to customize this module for your - * needs please contact servicedesk@totalinternetgroup.nl for more information. - * - * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright - * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US - */ -define( - [ - 'underscore', - './postcode-handler', - '../helper/field-types' - ], - function ( - underscore, - PostcodeHandler, - FieldTypes - ) { - 'use strict'; - - const postcodeDeRegex = /^[0-9]{4}\s?[A-Z]{2}$/i; - - function PostcodeHandlerDE(config,fields) { - this.states = Object.seal({ - INIT: 'init', - }); - - PostcodeHandler.call( - this, - config, - fields - ); - - return (this); - } - - PostcodeHandlerDE.prototype = Object.create(PostcodeHandler.prototype); - - PostcodeHandlerDE.prototype.getISOCode = function(){ return "DE";} - - PostcodeHandlerDE.prototype.handle = function (field_type, field_value) { - this.log('Handler @ ' + this.getCurrentState() + ': ' + field_type + ' => ' + field_value); - switch(this.getCurrentState()) { - case this.states.INIT: - - break; - } - } - return PostcodeHandlerDE; - } -); From 6e5b88b98f29083494b51c04eef6c7c31e17548b Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Tue, 5 Apr 2022 15:11:51 +0200 Subject: [PATCH 09/36] Made Street field 100% width on Belgium --- view/frontend/web/css/fields.css | 1 - 1 file changed, 1 deletion(-) diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css index a4dadba..6456786 100644 --- a/view/frontend/web/css/fields.css +++ b/view/frontend/web/css/fields.css @@ -184,7 +184,6 @@ display: inline-block; margin: 0 10px 20px 0; width: 100%; - max-width: calc(100% / 3 - 7px); } .tig_postcode_field.tig_postcode_be { From 715a185db13f4f9d5a4f5009285e416fe1f4c1f8 Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Tue, 5 Apr 2022 15:46:39 +0200 Subject: [PATCH 10/36] Hide Magento Street in BE --- view/frontend/web/css/fields.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css index 6456786..951e267 100644 --- a/view/frontend/web/css/fields.css +++ b/view/frontend/web/css/fields.css @@ -181,12 +181,12 @@ /**** BE ****/ .field.tig_postcode_be { - display: inline-block; margin: 0 10px 20px 0; width: 100%; } .tig_postcode_field.tig_postcode_be { + display: inline-block; max-width: calc(46% - 7px); } @@ -196,6 +196,7 @@ .tig_housenumber_field.tig_postcode_be, .tig_housenumber_addition_field.tig_postcode_be { + display: inline-block; max-width: calc(54% / 2 - 7px); } From f6fb5e388736827e7a46f6825d2c686fef234325 Mon Sep 17 00:00:00 2001 From: Michiel Vonk Date: Tue, 5 Apr 2022 15:54:12 +0200 Subject: [PATCH 11/36] Fixed Postcode City label position --- view/base/web/js/postcode-handler/postcode-be.js | 2 +- view/frontend/web/css/fields.css | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/view/base/web/js/postcode-handler/postcode-be.js b/view/base/web/js/postcode-handler/postcode-be.js index 1d45c7c..01b1bd6 100644 --- a/view/base/web/js/postcode-handler/postcode-be.js +++ b/view/base/web/js/postcode-handler/postcode-be.js @@ -147,7 +147,7 @@ define( self.getPostcodeService().setFieldValue(FieldTypes.city, data.plaats); self.getPostcodeService().setFieldValue(FieldTypes.postcode, data.postcode); - self.getAutoCompleteResultCity().text(' - ' + data.plaats); + self.getAutoCompleteResultCity().text(data.plaats); }, close: function() { domPostcodeField.removeClass('auto-complete-running'); diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css index 951e267..0e89704 100644 --- a/view/frontend/web/css/fields.css +++ b/view/frontend/web/css/fields.css @@ -136,9 +136,13 @@ box-sizing: border-box; } +.tig_postcode_field.tig_postcode_be .control { + position: relative; +} + .tig-autocomplete-result-city { top: 6.5px; - left: 46px; + right: 6.5px; color: #ccc; max-width: 100px; white-space: nowrap; From f7ea7031ffe7e0117eb493b2525ddce39bfe1f3c Mon Sep 17 00:00:00 2001 From: Mickey Beijer Date: Mon, 25 Apr 2022 12:36:07 +0200 Subject: [PATCH 12/36] POSTCODENL-369 : bugixing from refactor --- .../form/element/helpers/tigFieldsHelper.js | 4 ++-- .../web/js/postcode-handler/postcode-nl.js | 2 +- .../js/action/set-billing-address-mixin.js | 22 +++++++++++++++--- .../action/set-shipping-information-mixin.js | 23 ++++++++++++++++--- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/view/base/web/js/form/element/helpers/tigFieldsHelper.js b/view/base/web/js/form/element/helpers/tigFieldsHelper.js index de19581..8f40d30 100644 --- a/view/base/web/js/form/element/helpers/tigFieldsHelper.js +++ b/view/base/web/js/form/element/helpers/tigFieldsHelper.js @@ -53,7 +53,7 @@ define([ * @param value */ updateHousenumber: function(value){ - if (this.currentPostcodeHandler && value) { + if (this.currentPostcodeHandler) { this.currentPostcodeHandler.handle(FieldTypes.house_number, value); } }, @@ -64,7 +64,7 @@ define([ * @param value */ updateHouseNumberAddition: function(value){ - if (this.currentPostcodeHandler && value) { + if (this.currentPostcodeHandler) { this.currentPostcodeHandler.handle(FieldTypes.house_number_addition, value); } }, diff --git a/view/base/web/js/postcode-handler/postcode-nl.js b/view/base/web/js/postcode-handler/postcode-nl.js index 0f07865..0284930 100644 --- a/view/base/web/js/postcode-handler/postcode-nl.js +++ b/view/base/web/js/postcode-handler/postcode-nl.js @@ -84,7 +84,7 @@ define([ if (data.success !== true) { self.setCurrentState(states.POSTCODE_CALL_FAILED); - self.getPostcodeService().getElement(FieldTypes.postcode).error('Sorry, wij konden geen adresgegevens vinden met de opgegeven postcode en huisnummer combinatie. Indien u er zeker van bent dat de opgegeven postcode en huisnummer correct zijn, vul dan adresinformatie handmatig aan.'); + self.getPostcodeService().getElement(FieldTypes.postcode).error('Sorry, we could not find the address on the given zip code and house number combination. If you are sure that the zip code and house number are correct, please fill in the address details manually.'); return; } diff --git a/view/frontend/web/js/action/set-billing-address-mixin.js b/view/frontend/web/js/action/set-billing-address-mixin.js index b783cef..76b66b0 100644 --- a/view/frontend/web/js/action/set-billing-address-mixin.js +++ b/view/frontend/web/js/action/set-billing-address-mixin.js @@ -49,6 +49,22 @@ define([ ); } + /** + * A custom/extension attribute object can have a different construction + * depending on where, how and when the address is being processed. + * Therefore make sure the attribute value is correctly retrieved. + * + * @param attribute + * @returns {*} + */ + function getValue(attribute) { + if (typeof attribute.value === 'object' && attribute.value.value !== 'undefined') { + return attribute.value.value; + } + + return attribute.value; + } + return function (setBillingAddressAction) { return wrapper.wrap(setBillingAddressAction, function (originalAction) { var billingAddress = quote.billingAddress(); @@ -70,15 +86,15 @@ define([ var street = findAttribute('tig_street', billingAddress); if (housenumber) { - billingAddress['extension_attributes']['tig_housenumber'] = housenumber.value; + billingAddress['extension_attributes']['tig_housenumber'] = getValue(housenumber); } if (housenumberAddition) { - billingAddress['extension_attributes']['tig_housenumber_addition'] = housenumberAddition.value; + billingAddress['extension_attributes']['tig_housenumber_addition'] = getValue(housenumberAddition); } if (street) { - billingAddress['extension_attributes']['tig_street'] = street.value; + billingAddress['extension_attributes']['tig_street'] = getValue(street); } return originalAction(); diff --git a/view/frontend/web/js/action/set-shipping-information-mixin.js b/view/frontend/web/js/action/set-shipping-information-mixin.js index 78d1bf9..9bfcdc3 100644 --- a/view/frontend/web/js/action/set-shipping-information-mixin.js +++ b/view/frontend/web/js/action/set-shipping-information-mixin.js @@ -45,6 +45,23 @@ define([ } ); } + + /** + * A custom/extension attribute object can have a different construction + * depending on where, how and when the address is being processed. + * Therefore make sure the attribute value is correctly retrieved. + * + * @param attribute + * @returns {*} + */ + function getValue(attribute) { + if (typeof attribute.value === 'object' && attribute.value.value !== 'undefined') { + return attribute.value.value; + } + + return attribute.value; + } + return function (setShippingInformationAction) { return wrapper.wrap(setShippingInformationAction, function (originalAction) { @@ -67,15 +84,15 @@ define([ var street = findAttribute('tig_street', shippingAddress); if (housenumber) { - shippingAddress['extension_attributes']['tig_housenumber'] = housenumber.value; + shippingAddress['extension_attributes']['tig_housenumber'] = getValue(housenumber); } if (housenumberAddition) { - shippingAddress['extension_attributes']['tig_housenumber_addition'] = housenumberAddition.value; + shippingAddress['extension_attributes']['tig_housenumber_addition'] = getValue(housenumberAddition); } if (street) { - shippingAddress['extension_attributes']['tig_street'] = street.value; + shippingAddress['extension_attributes']['tig_street'] = getValue(street); } return originalAction(); From a6b241a6fdfae9a1c8437eba9b462a7da8a7411a Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Tue, 10 May 2022 13:24:39 +0200 Subject: [PATCH 13/36] POSTCODENL-375 do not show select fields in advanced configuration tab --- etc/adminhtml/system/configuration.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/adminhtml/system/configuration.xml b/etc/adminhtml/system/configuration.xml index 99bf7cb..d85671f 100644 --- a/etc/adminhtml/system/configuration.xml +++ b/etc/adminhtml/system/configuration.xml @@ -101,21 +101,21 @@ tig_postcode-section - + TIG\Postcode\Block\Adminhtml\Config\Form\Field\Disable TIG\Postcode\Config\Source\Parser tig_postcode/configuration/fieldparsing_street - + TIG\Postcode\Block\Adminhtml\Config\Form\Field\Disable TIG\Postcode\Config\Source\Parser tig_postcode/configuration/fieldparsing_housenumber - + TIG\Postcode\Block\Adminhtml\Config\Form\Field\Disable TIG\Postcode\Config\Source\Parser From abf980a9db7d93f1a41386b6c1673dff9bd5cb1a Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Tue, 10 May 2022 17:46:15 +0200 Subject: [PATCH 14/36] POSTCODENL-376 added styling for amasty checkout --- view/frontend/web/css/fields.css | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css index 0e89704..5775e8b 100644 --- a/view/frontend/web/css/fields.css +++ b/view/frontend/web/css/fields.css @@ -1,4 +1,4 @@ -.tig_hidden { +.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden { display: none; } @@ -8,6 +8,11 @@ margin-bottom: 70px; } +.amcheckout-wrapper .tig_postcode_field._error .control, +.amcheckout-wrapper .tig_postcode_field._warn .control { + margin-bottom: 0px; +} + @media (max-width: 375px) { .tig_postcode_field._error .control, .tig_postcode_field._warn .control { @@ -20,6 +25,11 @@ position: absolute; } +.amcheckout-wrapper .tig_postcode_field._error .field-error, +.amcheckout-wrapper .tig_postcode_field._warn .message { + position: relative; +} + .tig_postcode_nl.tig_postcode_field._error .field-error { border: 1px solid #e02b27; background: #f9f9f9; @@ -164,6 +174,18 @@ max-width: calc(100% / 3 - 7px); } +.amcheckout-wrapper .field.tig_postcode_nl.tig_postcode_field{ + max-width: 100%; +} + +.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_field{ + max-width: calc(40% - 7px); +} + +.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field{ + max-width: calc(60% - 7px); +} + @media (max-width: 400px) { .tig_postcode_field.tig_postcode_nl { max-width: 100%; From 52bd311ff454c00356093b274725b1860a1515c2 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Wed, 11 May 2022 13:11:25 +0200 Subject: [PATCH 15/36] POSTCODENL-378 added styling for onestepcheckout iosc --- view/frontend/web/css/fields.css | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css index 5775e8b..251790f 100644 --- a/view/frontend/web/css/fields.css +++ b/view/frontend/web/css/fields.css @@ -1,4 +1,4 @@ -.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden { +.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden, .opc-wrapper .fieldset > .field.tig_hidden{ display: none; } @@ -178,6 +178,10 @@ max-width: 100%; } +.opc-wrapper .field.tig_postcode_nl.tig_postcode_field { + max-width: calc(100% - 8px); +} + .amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_field{ max-width: calc(40% - 7px); } @@ -186,6 +190,11 @@ max-width: calc(60% - 7px); } +.opc-wrapper .field.tig_postcode_nl.tig_housenumber_field, +.opc-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field { + max-width: calc(50% - 8px); +} + @media (max-width: 400px) { .tig_postcode_field.tig_postcode_nl { max-width: 100%; @@ -201,6 +210,15 @@ max-width: 100%; } +.opc-wrapper .field.tig_postcode_nl.tig_street_field { + max-width: calc(100% - 8px); + width: calc(50% - 8px); +} + +.opc-wrapper .tig_city_field.tig_postcode_nl { + max-width: calc(50% - 8px); +} + .field.tig_postcode_nl.tig_housenumber_addition_field { margin: 0 0 20px 0; } From 61377edeb3a340ea0f25b0c277052ca4b0d32a17 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Wed, 18 May 2022 13:17:10 +0200 Subject: [PATCH 16/36] POSTCODENL-378 reverted styling for onestepcheckout iosc --- view/frontend/web/css/fields.css | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css index 251790f..5775e8b 100644 --- a/view/frontend/web/css/fields.css +++ b/view/frontend/web/css/fields.css @@ -1,4 +1,4 @@ -.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden, .opc-wrapper .fieldset > .field.tig_hidden{ +.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden { display: none; } @@ -178,10 +178,6 @@ max-width: 100%; } -.opc-wrapper .field.tig_postcode_nl.tig_postcode_field { - max-width: calc(100% - 8px); -} - .amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_field{ max-width: calc(40% - 7px); } @@ -190,11 +186,6 @@ max-width: calc(60% - 7px); } -.opc-wrapper .field.tig_postcode_nl.tig_housenumber_field, -.opc-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field { - max-width: calc(50% - 8px); -} - @media (max-width: 400px) { .tig_postcode_field.tig_postcode_nl { max-width: 100%; @@ -210,15 +201,6 @@ max-width: 100%; } -.opc-wrapper .field.tig_postcode_nl.tig_street_field { - max-width: calc(100% - 8px); - width: calc(50% - 8px); -} - -.opc-wrapper .tig_city_field.tig_postcode_nl { - max-width: calc(50% - 8px); -} - .field.tig_postcode_nl.tig_housenumber_addition_field { margin: 0 0 20px 0; } From 62e55641b9e3ed85e63572bdc1f5d106d3b183f2 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Wed, 18 May 2022 13:28:05 +0200 Subject: [PATCH 17/36] POSTCODENL-377 - Added styling for Mageplaza OSC - Created LayoutProcessorPlugin for mageplaza to show the correct field --- Plugin/Model/Osc/LayoutProcessorPlugin.php | 204 +++++++++++++++++++++ etc/di.xml | 4 + view/frontend/web/css/fields.css | 31 +++- 3 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 Plugin/Model/Osc/LayoutProcessorPlugin.php diff --git a/Plugin/Model/Osc/LayoutProcessorPlugin.php b/Plugin/Model/Osc/LayoutProcessorPlugin.php new file mode 100644 index 0000000..052e89f --- /dev/null +++ b/Plugin/Model/Osc/LayoutProcessorPlugin.php @@ -0,0 +1,204 @@ +arrayManager = $arrayManager; + $this->notifier = $notifier; + } + + /** + * Adds tracked fields so we can dynamically add classes or visibility + * + * @param $jsLayout + * @param $fieldsetChildren + * + * @return array + */ + public function addTrackedFields($jsLayout, $fieldsetChildren): array + { + foreach ( + [ + 'street', + 'city', + 'postcode' + ] as $key + ) { + $jsLayout = $this->arrayManager->set($fieldsetChildren . '/' . $key . '/tracks/additionalClasses', $jsLayout, true); + } + + return $jsLayout; + } + + /** + * @param $dataScope + * @param $index + * @param $label + * @param array $options + * + * @return array + */ + private function createBaseFieldConfig($dataScope, $index, $label, $options = []) + { + return array_merge_recursive([ + 'component' => "Magento_Ui/js/form/element/abstract", + 'dataScope' => $dataScope . '.custom_attributes.' . $index, + 'config' => [ + 'customScope' => $dataScope . '.custom_attributes', + 'template' => 'ui/form/field', + 'elementTmpl' => 'ui/form/element/input', + ], + 'label' => __($label), + 'provider' => 'checkoutProvider', + 'visible' => false, + 'tracks' => [ + 'additionalClasses' => true + ] + ], $options); + } + + /** + * Create Field definitions + * + * @param $dataScope + * + * @return array[] + */ + public function createHousenumberFieldsDefinition($dataScope) + { + return [ + 'tig_housenumber' => $this->createBaseFieldConfig($dataScope, 'tig_housenumber', 'Housenumber', ["sortOrder" => 51]), + 'tig_housenumber_addition' => $this->createBaseFieldConfig($dataScope, 'tig_housenumber_addition', 'Housenumber addition', ["sortOrder" => 52]), + 'tig_street' => $this->createBaseFieldConfig($dataScope, 'tig_street', 'Street Address', ["sortOrder" => 53]), + ]; + } + + /** + * Split string and remove last n element(s) + * + * @param $path + * @param string $delimiter + * @param int $count + * + * @return string + */ + private function getParentPath($path, $delimiter = '/', $count = 1) + { + $splitPath = explode($delimiter, $path); + for ($i = 0; $i < $count; $i++) { + array_pop($splitPath); + } + + return implode($delimiter, $splitPath); + } + + /** + * Add message to admin panel + * + * Used when confronted with incompatible checkout + * + * @param $message + */ + public function addAdminErrorMessage($message) + { + $this->notifier->addMajor("TIG Postcode", "Postcodeservice detected one or more compability issues with your shop setup"); + } + + /** + * Modify checkout to add fields and change postcode field behaviour + * + * @param LayoutProcessor $subject + * @param array $jsLayout + * + * @return array + * + * @see LayoutProcessor::process() + */ + public function afterProcess( + $subject, + $jsLayout + ) { + $postalCodePaths = $this->arrayManager->findPaths('postcode', $jsLayout); + foreach ($postalCodePaths as $postalCodePath) { + $fieldsetChildren = $this->getParentPath($postalCodePath, '/'); + + if ($this->arrayManager->get($postalCodePath . '/component', $jsLayout) !== self::MAGENTO_POSTCODE_COMPONENT_JS + xor $this->arrayManager->get($postalCodePath . '/component',$jsLayout) === self::TIG_POSTCODE_COMPONENT_JS) { + $this->addAdminErrorMessage('Incompatible postcode field found @ ' . $postalCodePath . ': ' . $this->arrayManager->get($postalCodePath . '/component', $jsLayout)); + continue; + } + + // Update PostcodeField + $jsLayout = $this->arrayManager->set($postalCodePath . '/component', $jsLayout, self::TIG_POSTCODE_COMPONENT_JS); + $jsLayout = $this->arrayManager->set($postalCodePath . '/config/elementTmpl', $jsLayout, self::TIG_POSTCODE_COMPONENT_TEMPLATE); + + // Add housenumber fields + $postcodeParentDataScope = $this->getParentPath($this->arrayManager->get($postalCodePath . '/dataScope', $jsLayout), "."); + $jsLayout = $this->arrayManager->merge( + $fieldsetChildren, + $jsLayout, + $this->createHousenumberFieldsDefinition($postcodeParentDataScope) + ); + + // Modify fields + $jsLayout = $this->addTrackedFields($jsLayout, $fieldsetChildren); + } + + return $jsLayout; + } +} diff --git a/etc/di.xml b/etc/di.xml index 442e5bb..801a88e 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -56,6 +56,10 @@ + + + + diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css index 5775e8b..f9f196c 100644 --- a/view/frontend/web/css/fields.css +++ b/view/frontend/web/css/fields.css @@ -1,4 +1,5 @@ -.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden { +.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden, +.opc-wrapper.one-step-checkout-wrapper .fieldset > .field.tig_hidden { display: none; } @@ -178,6 +179,11 @@ max-width: 100%; } +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_postcode_field { + max-width: calc(100% - 8px); + padding: 0 10px; +} + .amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_field{ max-width: calc(40% - 7px); } @@ -186,6 +192,17 @@ max-width: calc(60% - 7px); } +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_field { + max-width: calc(45%); + margin: 0 0 20px 0; + padding: 0 10px; +} + +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field { + padding: 0 9px; + max-width: calc(45%); +} + @media (max-width: 400px) { .tig_postcode_field.tig_postcode_nl { max-width: 100%; @@ -201,6 +218,16 @@ max-width: 100%; } +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_street_field { + max-width: calc(45%); + padding: 0 10px; +} + +.opc-wrapper.one-step-checkout-wrapper .tig_city_field.tig_postcode_nl { + max-width: calc(45%); + padding: 0 10px; +} + .field.tig_postcode_nl.tig_housenumber_addition_field { margin: 0 0 20px 0; } @@ -243,5 +270,5 @@ /**** Mageplaza OSC ****/ .one-step-checkout-container .field[name="shippingAddress.postcode"] { - max-width: calc(46% - 7px); + /*max-width: calc(46% - 7px);*/ } From e9bced19220f0da13d522329b9179c24d6c97171 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Wed, 18 May 2022 13:44:39 +0200 Subject: [PATCH 18/36] POSTCODENL-377 - Added BE styling for Mageplaza OSC --- view/frontend/web/css/fields.css | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css index f9f196c..8c64c3a 100644 --- a/view/frontend/web/css/fields.css +++ b/view/frontend/web/css/fields.css @@ -179,7 +179,8 @@ max-width: 100%; } -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_postcode_field { +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_postcode_field, +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_postcode_field { max-width: calc(100% - 8px); padding: 0 10px; } @@ -192,13 +193,15 @@ max-width: calc(60% - 7px); } -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_field { +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_field, +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_housenumber_field { max-width: calc(45%); margin: 0 0 20px 0; padding: 0 10px; } -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field { +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field, +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_housenumber_addition_field { padding: 0 9px; max-width: calc(45%); } @@ -218,13 +221,15 @@ max-width: 100%; } -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_street_field { +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_street_field, +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_street_field { max-width: calc(45%); padding: 0 10px; } -.opc-wrapper.one-step-checkout-wrapper .tig_city_field.tig_postcode_nl { - max-width: calc(45%); +.opc-wrapper.one-step-checkout-wrapper .tig_city_field.tig_postcode_nl, +.opc-wrapper.one-step-checkout-wrapper .tig_city_field.tig_postcode_be { + max-width: calc(50%); padding: 0 10px; } @@ -267,8 +272,3 @@ .tig_housenumber_addition_field.tig_postcode_be { margin: 0 0 20px 0; } - -/**** Mageplaza OSC ****/ -.one-step-checkout-container .field[name="shippingAddress.postcode"] { - /*max-width: calc(46% - 7px);*/ -} From 30f5364da3458abad8002109aefd746f23871549 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Wed, 18 May 2022 14:30:49 +0200 Subject: [PATCH 19/36] POSTCODENL-376 Added BE styling for Amasty Checkout --- view/frontend/web/css/fields.css | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css index 8c64c3a..783e05e 100644 --- a/view/frontend/web/css/fields.css +++ b/view/frontend/web/css/fields.css @@ -168,14 +168,15 @@ /**** NL ****/ .field.tig_postcode_nl.tig_postcode_field, .field.tig_postcode_nl.tig_housenumber_field, -.field.tig_postcode_nl.tig_housenumber_addition_field{ +.field.tig_postcode_nl.tig_housenumber_addition_field { display: inline-block; margin: 0 10px 20px 0; width: 100%; max-width: calc(100% / 3 - 7px); } -.amcheckout-wrapper .field.tig_postcode_nl.tig_postcode_field{ +.amcheckout-wrapper .field.tig_postcode_nl.tig_postcode_field, +.amcheckout-wrapper .field.tig_postcode_be.tig_postcode_field { max-width: 100%; } @@ -185,11 +186,13 @@ padding: 0 10px; } -.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_field{ +.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_field, +.amcheckout-wrapper .field.tig_postcode_be.tig_housenumber_field { max-width: calc(40% - 7px); } -.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field{ +.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field, +.amcheckout-wrapper .field.tig_postcode_be.tig_housenumber_addition_field { max-width: calc(60% - 7px); } From d818e221bd68b25c7198e427664a6080950ff6b9 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Thu, 19 May 2022 11:34:17 +0200 Subject: [PATCH 20/36] POSTCODENL-373 improvement setup for tavis testing. --- Test/Script/Setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Script/Setup.sh b/Test/Script/Setup.sh index 7bbf927..f339844 100644 --- a/Test/Script/Setup.sh +++ b/Test/Script/Setup.sh @@ -54,7 +54,7 @@ mkdir -p ${BUILD_DIR} mkdir -p ${CACHE_DIR} if [ ! -f "$CACHE_FILE" ]; then - wget "http://magento.mirror.hypernode.com/releases/magento-${MAGENTO_VERSION}.tar.gz" -O $CACHE_FILE + wget "https://magento.mirror.hypernode.com/releases/magento-${MAGENTO_VERSION}.tar.gz" -O $CACHE_FILE fi tar xzf $CACHE_FILE -C /tmp/magento2 From d2b25db22148e3ec8e03d3fc94f3f20d1634f19b Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Thu, 19 May 2022 11:43:07 +0200 Subject: [PATCH 21/36] POSTCODENL-373 improvement setup for tavis testing. --- Test/Script/Setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Script/Setup.sh b/Test/Script/Setup.sh index f339844..750ab65 100644 --- a/Test/Script/Setup.sh +++ b/Test/Script/Setup.sh @@ -54,7 +54,7 @@ mkdir -p ${BUILD_DIR} mkdir -p ${CACHE_DIR} if [ ! -f "$CACHE_FILE" ]; then - wget "https://magento.mirror.hypernode.com/releases/magento-${MAGENTO_VERSION}.tar.gz" -O $CACHE_FILE + wget "https://magento.mirror.hypernode.com/releases/magento-${MAGENTO_VERSION}.tar.gz" -O $CACHE_FILE --no-check-certificate fi tar xzf $CACHE_FILE -C /tmp/magento2 From ec78884e430e60d0fd49c16ddb5a6438a45236ee Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Thu, 19 May 2022 12:31:09 +0200 Subject: [PATCH 22/36] POSTCODENL-298 Release Candidate 1.5.0-RC1 --- Block/Adminhtml/Config/Support/Tab.php | 2 +- Test/Unit/Block/Adminhtml/Config/Support/TabTest.php | 6 +++--- composer.json | 4 ++-- etc/config.xml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Block/Adminhtml/Config/Support/Tab.php b/Block/Adminhtml/Config/Support/Tab.php index 41f54ac..e614fd0 100644 --- a/Block/Adminhtml/Config/Support/Tab.php +++ b/Block/Adminhtml/Config/Support/Tab.php @@ -40,7 +40,7 @@ class Tab extends Template implements RendererInterface { const MODULE_NAME = 'TIG_Postcode'; - const EXTENSION_VERSION = '1.4.1'; + const EXTENSION_VERSION = '1.5.0-RC1'; // @codingStandardsIgnoreLine protected $_template = 'TIG_Postcode::config/support/tab.phtml'; diff --git a/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php b/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php index acb1b82..8f263a4 100644 --- a/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php +++ b/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php @@ -42,7 +42,7 @@ class TabTest extends TestCase public function testGetVersionNumber() { $instance = $this->getInstance(); - $this->assertSame('1.4.1', $instance->getVersionNumber()); + $this->assertSame('1.5.0-RC1', $instance->getVersionNumber()); } public function testGetSupportedMagentoVersions() @@ -51,7 +51,7 @@ public function testGetSupportedMagentoVersions() 'moduleConfiguration' => $this->getConfigurationMock() ]); - $this->assertSame('2.3.7, 2.4.3', $instance->getSupportedMagentoVersions()); + $this->assertSame('2.3.7, 2.4.4', $instance->getSupportedMagentoVersions()); } /**+ @@ -62,7 +62,7 @@ private function getConfigurationMock() $mock = $this->getFakeMock(ModuleConfiguration::class)->getMock(); $mockExpects = $mock->expects($this->once()); $mockExpects->method('getSupportedMagentoVersions'); - $mockExpects->willReturn('2.3.7, 2.4.3'); + $mockExpects->willReturn('2.3.7, 2.4.4'); return $mock; } diff --git a/composer.json b/composer.json index bc01203..e8b5120 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "magento/module-quote": ">=101.0.5,<=101.0.11|~101.1|~101.2" }, "type": "magento2-module", - "version": "1.4.1", + "version": "1.5.0-RC1", "license": "CC-BY-NC-ND-3.0", "authors": [ { @@ -21,7 +21,7 @@ "issues": "https://portal.tig.nl" }, "homepage": "https://postcodeservice.nl/", - "minimum-stability": "stable", + "minimum-stability": "RC", "autoload": { "files": [ "registration.php" diff --git a/etc/config.xml b/etc/config.xml index c731dd5..8a58f05 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -33,7 +33,7 @@ - 2.3.7, 2.4.3 + 2.3.7, 2.4.4 0 From a5aca379f26608dcf6a34ac5c5992014a11a9cf9 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Thu, 19 May 2022 13:45:19 +0200 Subject: [PATCH 23/36] POSTCODENL-298 Release Candidate 1.5.0-RC1 - Added PHP 8 support --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e8b5120..51fe595 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "tig/postcode-magento2", "description": "TIG Magento 2 Postcode extension", "require": { - "php": "~7.0|~7.1|~7.2|~7.3|~7.4", + "php": "~7.0|~7.1|~7.2|~7.3|~7.4|~8.0|~8.1", "magento/module-checkout": ">=100.2.6,<=100.2.11|~100.3|~100.4", "magento/module-quote": ">=101.0.5,<=101.0.11|~101.1|~101.2" }, From b5d9c9209fbf9eb3da1c6a1ce6086a0d95b929b0 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Tue, 31 May 2022 12:27:11 +0200 Subject: [PATCH 24/36] POSTCODENL-381 added check to set sortOrder if default country is NL or BE --- .../Model/Checkout/LayoutProcessorPlugin.php | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Plugin/Model/Checkout/LayoutProcessorPlugin.php b/Plugin/Model/Checkout/LayoutProcessorPlugin.php index 3331445..b4ac6f1 100644 --- a/Plugin/Model/Checkout/LayoutProcessorPlugin.php +++ b/Plugin/Model/Checkout/LayoutProcessorPlugin.php @@ -33,14 +33,20 @@ namespace TIG\Postcode\Plugin\Model\Checkout; use Magento\Checkout\Block\Checkout\LayoutProcessor; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Notification\NotifierInterface; use Magento\Framework\Stdlib\ArrayManager; +use Magento\Store\Model\ScopeInterface; class LayoutProcessorPlugin { const MAGENTO_POSTCODE_COMPONENT_JS = "Magento_Ui/js/form/element/post-code"; const TIG_POSTCODE_COMPONENT_JS = "TIG_Postcode/js/form/element/tig-postcode-field"; const TIG_POSTCODE_COMPONENT_TEMPLATE = 'TIG_Postcode/form/element/postcode-field'; + /** + * Get country path + */ + const COUNTRY_CODE_PATH = 'general/country/default'; /** * @var ArrayManager @@ -53,13 +59,20 @@ class LayoutProcessorPlugin private $notifier; /** - * @param ArrayManager $arrayManager - * @param NotifierInterface $notifier + * @var ScopeConfigInterface */ - public function __construct(ArrayManager $arrayManager, NotifierInterface $notifier) + private $scopeConfig; + + /** + * @param ArrayManager $arrayManager + * @param NotifierInterface $notifier + * @param ScopeConfigInterface $scopeConfig + */ + public function __construct(ArrayManager $arrayManager, NotifierInterface $notifier, ScopeConfigInterface $scopeConfig) { $this->arrayManager = $arrayManager; $this->notifier = $notifier; + $this->scopeConfig = $scopeConfig; } /** @@ -184,6 +197,15 @@ public function afterProcess( // Update PostcodeField $jsLayout = $this->arrayManager->set($postalCodePath . '/component', $jsLayout, self::TIG_POSTCODE_COMPONENT_JS); $jsLayout = $this->arrayManager->set($postalCodePath . '/config/elementTmpl', $jsLayout, self::TIG_POSTCODE_COMPONENT_TEMPLATE); + // Change default sortOrder of PostcodeField + $defaultCountry = $this->scopeConfig->getValue( + self::COUNTRY_CODE_PATH, + ScopeInterface::SCOPE_WEBSITE + ); + // Change default sortOrder of PostcodeField if country is set to NL or BE + if ($defaultCountry === "NL" || $defaultCountry === "BE" ) { + $jsLayout = $this->arrayManager->set($postalCodePath . '/config/sortOrder', $jsLayout, 50); + } // Add housenumber fields $postcodeParentDataScope = $this->getParentPath($this->arrayManager->get($postalCodePath . '/dataScope', $jsLayout), "."); From 098aa80362f265372dc5bf6dbc3a3d050d17702c Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Tue, 31 May 2022 13:23:34 +0200 Subject: [PATCH 25/36] POSTCODENL-381 added check to set sortOrder if default country NL or BE for Mageplaza --- .../Model/Checkout/LayoutProcessorPlugin.php | 5 +--- Plugin/Model/Osc/LayoutProcessorPlugin.php | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Plugin/Model/Checkout/LayoutProcessorPlugin.php b/Plugin/Model/Checkout/LayoutProcessorPlugin.php index b4ac6f1..a7e8fc3 100644 --- a/Plugin/Model/Checkout/LayoutProcessorPlugin.php +++ b/Plugin/Model/Checkout/LayoutProcessorPlugin.php @@ -43,10 +43,7 @@ class LayoutProcessorPlugin const MAGENTO_POSTCODE_COMPONENT_JS = "Magento_Ui/js/form/element/post-code"; const TIG_POSTCODE_COMPONENT_JS = "TIG_Postcode/js/form/element/tig-postcode-field"; const TIG_POSTCODE_COMPONENT_TEMPLATE = 'TIG_Postcode/form/element/postcode-field'; - /** - * Get country path - */ - const COUNTRY_CODE_PATH = 'general/country/default'; + const COUNTRY_CODE_PATH = 'general/country/default'; /** * @var ArrayManager diff --git a/Plugin/Model/Osc/LayoutProcessorPlugin.php b/Plugin/Model/Osc/LayoutProcessorPlugin.php index 052e89f..705fe08 100644 --- a/Plugin/Model/Osc/LayoutProcessorPlugin.php +++ b/Plugin/Model/Osc/LayoutProcessorPlugin.php @@ -30,17 +30,20 @@ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US */ -namespace TIG\Postcode\Plugin\Model\Osc; +namespace TIG\Postcode\Plugin\Model\Checkout; use Magento\Checkout\Block\Checkout\LayoutProcessor; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Notification\NotifierInterface; use Magento\Framework\Stdlib\ArrayManager; +use Magento\Store\Model\ScopeInterface; class LayoutProcessorPlugin { const MAGENTO_POSTCODE_COMPONENT_JS = "Magento_Ui/js/form/element/post-code"; const TIG_POSTCODE_COMPONENT_JS = "TIG_Postcode/js/form/element/tig-postcode-field"; const TIG_POSTCODE_COMPONENT_TEMPLATE = 'TIG_Postcode/form/element/postcode-field'; + const COUNTRY_CODE_PATH = 'general/country/default'; /** * @var ArrayManager @@ -53,13 +56,20 @@ class LayoutProcessorPlugin private $notifier; /** - * @param ArrayManager $arrayManager - * @param NotifierInterface $notifier + * @var ScopeConfigInterface */ - public function __construct(ArrayManager $arrayManager, NotifierInterface $notifier) + private $scopeConfig; + + /** + * @param ArrayManager $arrayManager + * @param NotifierInterface $notifier + * @param ScopeConfigInterface $scopeConfig + */ + public function __construct(ArrayManager $arrayManager, NotifierInterface $notifier, ScopeConfigInterface $scopeConfig) { $this->arrayManager = $arrayManager; $this->notifier = $notifier; + $this->scopeConfig = $scopeConfig; } /** @@ -186,6 +196,15 @@ public function afterProcess( // Update PostcodeField $jsLayout = $this->arrayManager->set($postalCodePath . '/component', $jsLayout, self::TIG_POSTCODE_COMPONENT_JS); $jsLayout = $this->arrayManager->set($postalCodePath . '/config/elementTmpl', $jsLayout, self::TIG_POSTCODE_COMPONENT_TEMPLATE); + // Change default sortOrder of PostcodeField + $defaultCountry = $this->scopeConfig->getValue( + self::COUNTRY_CODE_PATH, + ScopeInterface::SCOPE_WEBSITE + ); + // Change default sortOrder of PostcodeField if country is set to NL or BE + if ($defaultCountry === "NL" || $defaultCountry === "BE" ) { + $jsLayout = $this->arrayManager->set($postalCodePath . '/config/sortOrder', $jsLayout, 50); + } // Add housenumber fields $postcodeParentDataScope = $this->getParentPath($this->arrayManager->get($postalCodePath . '/dataScope', $jsLayout), "."); From 3be929b457f90e35e5aaffa365a463169f863a76 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Tue, 31 May 2022 13:32:36 +0200 Subject: [PATCH 26/36] POSTCODENL-381 fixed namespace --- Plugin/Model/Osc/LayoutProcessorPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin/Model/Osc/LayoutProcessorPlugin.php b/Plugin/Model/Osc/LayoutProcessorPlugin.php index 705fe08..6952168 100644 --- a/Plugin/Model/Osc/LayoutProcessorPlugin.php +++ b/Plugin/Model/Osc/LayoutProcessorPlugin.php @@ -30,7 +30,7 @@ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US */ -namespace TIG\Postcode\Plugin\Model\Checkout; +namespace TIG\Postcode\Plugin\Model\Osc; use Magento\Checkout\Block\Checkout\LayoutProcessor; use Magento\Framework\App\Config\ScopeConfigInterface; From 3757c578680b892f3efe034bf833cc163ab47ba7 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Thu, 16 Jun 2022 11:15:34 +0200 Subject: [PATCH 27/36] POSTCODENL-381 added TODO --- Plugin/Model/Checkout/LayoutProcessorPlugin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugin/Model/Checkout/LayoutProcessorPlugin.php b/Plugin/Model/Checkout/LayoutProcessorPlugin.php index b4ac6f1..9309e3c 100644 --- a/Plugin/Model/Checkout/LayoutProcessorPlugin.php +++ b/Plugin/Model/Checkout/LayoutProcessorPlugin.php @@ -203,6 +203,7 @@ public function afterProcess( ScopeInterface::SCOPE_WEBSITE ); // Change default sortOrder of PostcodeField if country is set to NL or BE + // @TODO use a better way to set sort order for postcode field, tried in branch "tryout_billing_address_sortorder_mixin" if ($defaultCountry === "NL" || $defaultCountry === "BE" ) { $jsLayout = $this->arrayManager->set($postalCodePath . '/config/sortOrder', $jsLayout, 50); } From 4682a2ea5238a7fac6c7f9d5d7b38b733c19cbaf Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Thu, 23 Jun 2022 14:37:51 +0200 Subject: [PATCH 28/36] POSTCODENL-379 devide css and use less files --- view/frontend/layout/checkout_index_index.xml | 2 +- .../web/css/aheadworks_onestepcheckout.less | 0 view/frontend/web/css/amasty_checkout.less | 29 ++ view/frontend/web/css/fields.css | 277 ------------------ .../web/css/mageplaza_onestepcheckout.less | 30 ++ .../web/css/onestepcheckout_iosc.less | 0 view/frontend/web/css/postcode_be.less | 41 +++ view/frontend/web/css/postcode_main.less | 143 +++++++++ view/frontend/web/css/postcode_nl.less | 46 +++ .../web/css/rubic_clean_checkout.less | 0 10 files changed, 290 insertions(+), 278 deletions(-) create mode 100644 view/frontend/web/css/aheadworks_onestepcheckout.less create mode 100644 view/frontend/web/css/amasty_checkout.less delete mode 100644 view/frontend/web/css/fields.css create mode 100644 view/frontend/web/css/mageplaza_onestepcheckout.less create mode 100644 view/frontend/web/css/onestepcheckout_iosc.less create mode 100644 view/frontend/web/css/postcode_be.less create mode 100644 view/frontend/web/css/postcode_main.less create mode 100644 view/frontend/web/css/postcode_nl.less create mode 100644 view/frontend/web/css/rubic_clean_checkout.less diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 001e0bd..050de17 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -32,6 +32,6 @@ --> - + diff --git a/view/frontend/web/css/aheadworks_onestepcheckout.less b/view/frontend/web/css/aheadworks_onestepcheckout.less new file mode 100644 index 0000000..e69de29 diff --git a/view/frontend/web/css/amasty_checkout.less b/view/frontend/web/css/amasty_checkout.less new file mode 100644 index 0000000..6b42b65 --- /dev/null +++ b/view/frontend/web/css/amasty_checkout.less @@ -0,0 +1,29 @@ +.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden { + display: none; +} + +.amcheckout-wrapper .tig_postcode_field._error .control, +.amcheckout-wrapper .tig_postcode_field._warn .control { + margin-bottom: 0px; +} +.amcheckout-wrapper .tig_postcode_field._error .field-error, +.amcheckout-wrapper .tig_postcode_field._warn .message { + position: relative; +} + + +.amcheckout-wrapper .field.tig_postcode_nl.tig_postcode_field, +.amcheckout-wrapper .field.tig_postcode_be.tig_postcode_field { + max-width: 100%; +} + + +.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_field, +.amcheckout-wrapper .field.tig_postcode_be.tig_housenumber_field { + max-width: calc(40% - 7px); +} + +.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field, +.amcheckout-wrapper .field.tig_postcode_be.tig_housenumber_addition_field { + max-width: calc(60% - 7px); +} diff --git a/view/frontend/web/css/fields.css b/view/frontend/web/css/fields.css deleted file mode 100644 index 783e05e..0000000 --- a/view/frontend/web/css/fields.css +++ /dev/null @@ -1,277 +0,0 @@ -.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden, -.opc-wrapper.one-step-checkout-wrapper .fieldset > .field.tig_hidden { - display: none; -} - -/**** Validation ****/ -.tig_postcode_field._error .control, -.tig_postcode_field._warn .control { - margin-bottom: 70px; -} - -.amcheckout-wrapper .tig_postcode_field._error .control, -.amcheckout-wrapper .tig_postcode_field._warn .control { - margin-bottom: 0px; -} - -@media (max-width: 375px) { - .tig_postcode_field._error .control, - .tig_postcode_field._warn .control { - margin-bottom: 95px; - } -} - -.tig_postcode_field._error .field-error, -.tig_postcode_field._warn .message { - position: absolute; -} - -.amcheckout-wrapper .tig_postcode_field._error .field-error, -.amcheckout-wrapper .tig_postcode_field._warn .message { - position: relative; -} - -.tig_postcode_nl.tig_postcode_field._error .field-error { - border: 1px solid #e02b27; - background: #f9f9f9; - color: #e02b27; - padding: 5px; - font-size: 1.2rem; - box-sizing: border-box; - white-space: normal; - width: 100%; - height: 70px; -} - -.tig_postcode_nl.tig_postcode_field._error + .tig_housenumber_field input, -.tig_postcode_nl.tig_postcode_field._error + .tig_housenumber_field + .tig_housenumber_addition_field input { - border: 1px solid #e02b27; -} - -.fieldset.address { - position: relative; -} - -/*! jQuery UI - v1.12.1 - 2016-09-14 -* http://jqueryui.com -* Copyright jQuery Foundation and other contributors; Licensed MIT */ - -.ui-helper-hidden-accessible { - border: 0; - clip: rect(0 0 0 0); - height: 1px; - margin: -1px; - overflow: hidden; - padding: 0; - position: absolute; - width: 1px; -} - -.tigJqueryUiClass { - position: absolute; - top: 0; - left: 0; - cursor: default; -} - -.ui-menu { - list-style: none; - padding: 0; - margin: 0; - display: block; - outline: 0; -} - -.tigJqueryUiClass .ui-menu-item { - cursor: pointer; - list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); -} - -.tigJqueryUiClass .ui-state-error a { - color: #5f3f3f; -} - -.tigJqueryUiClass { - font-family: Arial, Helvetica, sans-serif; - font-size: 1em; -} - -.tigJqueryUiClass .ui-widget { - font-size: 1em; -} - -.tigJqueryUiClass input, -.tigJqueryUiClass select, -.tigJqueryUiClass textarea, -.tigJqueryUiClass button { - font-family: Arial, Helvetica, sans-serif; - font-size: 1em; -} - -.tigJqueryUiClass.ui-widget-content { - border: 1px solid #c5c5c5; -} - -.tigJqueryUiClass { - border: 1px solid #dddddd; - background: #ffffff; - color: #333333; -} - -.tigJqueryUiClass a { - color: #333333; -} - -.tigJqueryUiClass a { - color: #333333; -} - -.tigJqueryUiClass .ui-state-focus { - border: 1px solid #003eff; - background: #007fff; - font-weight: normal; - color: #ffffff; - display: block; -} - -.tigJqueryUiClass.ui-corner-all a { - position: relative; - border: 1px solid white; - float: left; - width: 100%; - padding: 10px; - margin-top: 4px; - cursor: pointer; - list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7); - text-decoration: none; - box-sizing: border-box; -} - -.tig_postcode_field.tig_postcode_be .control { - position: relative; -} - -.tig-autocomplete-result-city { - top: 6.5px; - right: 6.5px; - color: #ccc; - max-width: 100px; - white-space: nowrap; - pointer-events: none; - position: absolute; -} - -.auto-complete-running + .warning { - display: none; -} - -/**** NL ****/ -.field.tig_postcode_nl.tig_postcode_field, -.field.tig_postcode_nl.tig_housenumber_field, -.field.tig_postcode_nl.tig_housenumber_addition_field { - display: inline-block; - margin: 0 10px 20px 0; - width: 100%; - max-width: calc(100% / 3 - 7px); -} - -.amcheckout-wrapper .field.tig_postcode_nl.tig_postcode_field, -.amcheckout-wrapper .field.tig_postcode_be.tig_postcode_field { - max-width: 100%; -} - -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_postcode_field, -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_postcode_field { - max-width: calc(100% - 8px); - padding: 0 10px; -} - -.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_field, -.amcheckout-wrapper .field.tig_postcode_be.tig_housenumber_field { - max-width: calc(40% - 7px); -} - -.amcheckout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field, -.amcheckout-wrapper .field.tig_postcode_be.tig_housenumber_addition_field { - max-width: calc(60% - 7px); -} - -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_field, -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_housenumber_field { - max-width: calc(45%); - margin: 0 0 20px 0; - padding: 0 10px; -} - -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field, -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_housenumber_addition_field { - padding: 0 9px; - max-width: calc(45%); -} - -@media (max-width: 400px) { - .tig_postcode_field.tig_postcode_nl { - max-width: 100%; - } - - .tig_housenumber_field.tig_postcode_nl, - .tig_housenumber_addition_field.tig_postcode_nl { - max-width: calc(100% / 2 - 7px); - } -} - -.tig_street_fields.tig_postcode_nl, .tig_city_field.tig_postcode_nl { - max-width: 100%; -} - -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_street_field, -.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_street_field { - max-width: calc(45%); - padding: 0 10px; -} - -.opc-wrapper.one-step-checkout-wrapper .tig_city_field.tig_postcode_nl, -.opc-wrapper.one-step-checkout-wrapper .tig_city_field.tig_postcode_be { - max-width: calc(50%); - padding: 0 10px; -} - -.field.tig_postcode_nl.tig_housenumber_addition_field { - margin: 0 0 20px 0; -} - -/**** BE ****/ -.field.tig_postcode_be { - margin: 0 10px 20px 0; - width: 100%; -} - -.tig_postcode_field.tig_postcode_be { - display: inline-block; - max-width: calc(46% - 7px); -} - -.tig_street_fields.tig_postcode_be, .tig_city_field.tig_postcode_be { - max-width: 100%; -} - -.tig_housenumber_field.tig_postcode_be, -.tig_housenumber_addition_field.tig_postcode_be { - display: inline-block; - max-width: calc(54% / 2 - 7px); -} - -@media (max-width: 400px) { - .tig_postcode_field.tig_postcode_be { - max-width: 100%; - } - - .tig_housenumber_field.tig_postcode_be, - .tig_housenumber_addition_field.tig_postcode_be { - max-width: calc(100% / 2 - 7px); - } -} - -.tig_housenumber_addition_field.tig_postcode_be { - margin: 0 0 20px 0; -} diff --git a/view/frontend/web/css/mageplaza_onestepcheckout.less b/view/frontend/web/css/mageplaza_onestepcheckout.less new file mode 100644 index 0000000..f5b324c --- /dev/null +++ b/view/frontend/web/css/mageplaza_onestepcheckout.less @@ -0,0 +1,30 @@ +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_street_field, +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_street_field { + max-width: calc(45%); + padding: 0 10px; +} + +.opc-wrapper.one-step-checkout-wrapper .tig_city_field.tig_postcode_nl, +.opc-wrapper.one-step-checkout-wrapper .tig_city_field.tig_postcode_be { + max-width: calc(50%); + padding: 0 10px; +} + +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_field, +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_housenumber_field { + max-width: calc(45%); + margin: 0 0 20px 0; + padding: 0 10px; +} + +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_housenumber_addition_field, +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_housenumber_addition_field { + padding: 0 9px; + max-width: calc(45%); +} + +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_nl.tig_postcode_field, +.opc-wrapper.one-step-checkout-wrapper .field.tig_postcode_be.tig_postcode_field { + max-width: calc(100% - 8px); + padding: 0 10px; +} diff --git a/view/frontend/web/css/onestepcheckout_iosc.less b/view/frontend/web/css/onestepcheckout_iosc.less new file mode 100644 index 0000000..e69de29 diff --git a/view/frontend/web/css/postcode_be.less b/view/frontend/web/css/postcode_be.less new file mode 100644 index 0000000..bb8b8e1 --- /dev/null +++ b/view/frontend/web/css/postcode_be.less @@ -0,0 +1,41 @@ + +/**** BE ****/ +.field.tig_postcode_be { + margin: 0 10px 20px 0; + width: 100%; +} + +.tig_postcode_field.tig_postcode_be { + display: inline-block; + max-width: calc(46% - 7px); +} + +.tig_street_fields.tig_postcode_be, .tig_city_field.tig_postcode_be { + max-width: 100%; +} + +.tig_housenumber_field.tig_postcode_be, +.tig_housenumber_addition_field.tig_postcode_be { + display: inline-block; + max-width: calc(54% / 2 - 7px); +} + +@media (max-width: 400px) { + .tig_postcode_field.tig_postcode_be { + max-width: 100%; + } + + .tig_housenumber_field.tig_postcode_be, + .tig_housenumber_addition_field.tig_postcode_be { + max-width: calc(100% / 2 - 7px); + } +} + +.tig_housenumber_addition_field.tig_postcode_be { + margin: 0 0 20px 0; +} + + +.tig_postcode_field.tig_postcode_be .control { + position: relative; +} diff --git a/view/frontend/web/css/postcode_main.less b/view/frontend/web/css/postcode_main.less new file mode 100644 index 0000000..2077905 --- /dev/null +++ b/view/frontend/web/css/postcode_main.less @@ -0,0 +1,143 @@ +// country specific styling +@import 'postcode_nl'; +@import 'postcode_be'; +// +@import 'amasty_checkout'; +@import 'mageplaza_onestepcheckout'; +@import 'onestepcheckout_iosc'; +@import 'aheadworks_onestepcheckout'; +@import 'rubic_clean_checkout'; + + +/**** Validation ****/ +.tig_postcode_field._error .control, +.tig_postcode_field._warn .control { + margin-bottom: 70px; +} +@media (max-width: 375px) { + .tig_postcode_field._error .control, + .tig_postcode_field._warn .control { + margin-bottom: 95px; + } +} +.tig_postcode_field._error .field-error, +.tig_postcode_field._warn .message { + position: absolute; +} + + + +.fieldset.address { + position: relative; +} + +.tig-autocomplete-result-city { + top: 6.5px; + right: 6.5px; + color: #ccc; + max-width: 100px; + white-space: nowrap; + pointer-events: none; + position: absolute; +} + +.auto-complete-running + .warning { + display: none; +} + + + +/*! jQuery UI - v1.12.1 - 2016-09-14 +* http://jqueryui.com +* Copyright jQuery Foundation and other contributors; Licensed MIT */ + +.ui-helper-hidden-accessible { + border: 0; + clip: rect(0 0 0 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; +} + +.tigJqueryUiClass { + position: absolute; + top: 0; + left: 0; + cursor: default; +} + +.ui-menu { + list-style: none; + padding: 0; + margin: 0; + display: block; + outline: 0; +} + +.tigJqueryUiClass .ui-menu-item { + cursor: pointer; + list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); +} + +.tigJqueryUiClass .ui-state-error a { + color: #5f3f3f; +} + +.tigJqueryUiClass { + font-family: Arial, Helvetica, sans-serif; + font-size: 1em; +} + +.tigJqueryUiClass .ui-widget { + font-size: 1em; +} + +.tigJqueryUiClass input, +.tigJqueryUiClass select, +.tigJqueryUiClass textarea, +.tigJqueryUiClass button { + font-family: Arial, Helvetica, sans-serif; + font-size: 1em; +} + +.tigJqueryUiClass.ui-widget-content { + border: 1px solid #c5c5c5; +} + +.tigJqueryUiClass { + border: 1px solid #dddddd; + background: #ffffff; + color: #333333; +} + +.tigJqueryUiClass a { + color: #333333; +} + +.tigJqueryUiClass a { + color: #333333; +} + +.tigJqueryUiClass .ui-state-focus { + border: 1px solid #003eff; + background: #007fff; + font-weight: normal; + color: #ffffff; + display: block; +} + +.tigJqueryUiClass.ui-corner-all a { + position: relative; + border: 1px solid white; + float: left; + width: 100%; + padding: 10px; + margin-top: 4px; + cursor: pointer; + list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7); + text-decoration: none; + box-sizing: border-box; +} diff --git a/view/frontend/web/css/postcode_nl.less b/view/frontend/web/css/postcode_nl.less new file mode 100644 index 0000000..7ad192e --- /dev/null +++ b/view/frontend/web/css/postcode_nl.less @@ -0,0 +1,46 @@ +/**** NL ****/ +.field.tig_postcode_nl.tig_postcode_field, +.field.tig_postcode_nl.tig_housenumber_field, +.field.tig_postcode_nl.tig_housenumber_addition_field { + display: inline-block; + margin: 0 10px 20px 0; + width: 100%; + max-width: calc(100% / 3 - 7px); +} + +@media (max-width: 400px) { + .tig_postcode_field.tig_postcode_nl { + max-width: 100%; + } + + .tig_housenumber_field.tig_postcode_nl, + .tig_housenumber_addition_field.tig_postcode_nl { + max-width: calc(100% / 2 - 7px); + } +} + +.tig_street_fields.tig_postcode_nl, .tig_city_field.tig_postcode_nl { + max-width: 100%; +} + + + +.field.tig_postcode_nl.tig_housenumber_addition_field { + margin: 0 0 20px 0; +} + +.tig_postcode_nl.tig_postcode_field._error + .tig_housenumber_field input, +.tig_postcode_nl.tig_postcode_field._error + .tig_housenumber_field + .tig_housenumber_addition_field input { + border: 1px solid #e02b27; +} +.tig_postcode_nl.tig_postcode_field._error .field-error { + border: 1px solid #e02b27; + background: #f9f9f9; + color: #e02b27; + padding: 5px; + font-size: 1.2rem; + box-sizing: border-box; + white-space: normal; + width: 100%; + height: 70px; +} diff --git a/view/frontend/web/css/rubic_clean_checkout.less b/view/frontend/web/css/rubic_clean_checkout.less new file mode 100644 index 0000000..e69de29 From 818be382ae0689befc738b208a3c0d5f6ac3c45b Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Fri, 24 Jun 2022 14:30:03 +0200 Subject: [PATCH 29/36] POSTCODENL-379 Create observer that load in the correct HTML for module specific CSS --- Observer/LessLoader.php | 58 +++++++++++++++++++++++++++++++++++++++++ etc/frontend/events.xml | 6 +++++ 2 files changed, 64 insertions(+) create mode 100644 Observer/LessLoader.php create mode 100644 etc/frontend/events.xml diff --git a/Observer/LessLoader.php b/Observer/LessLoader.php new file mode 100644 index 0000000..fe2b66e --- /dev/null +++ b/Observer/LessLoader.php @@ -0,0 +1,58 @@ +moduleList = $moduleList; + } + + /** + * @param Observer $observer + * + * @return Observer + */ + public function execute(Observer $observer) + { + $array = $this->getEnabledModuleList(); + + // TODO: implement a better way + if (in_array('Amasty_Checkout', $array)){ + $observer->getLayout()->getUpdate()->addUpdate($this->getXmlCode()); + } + + return $observer; + } + + /** + * Return the correct Less file in XML format + * + * @return string + */ + private function getXmlCode(){ + // TODO: implement better? + return ' + + '; + } + + /** + * Return an array of the enabled modules (bin/magento module:status) + * + * @return array + */ + private function getEnabledModuleList(){ + return $this->moduleList->getNames(); + } +} diff --git a/etc/frontend/events.xml b/etc/frontend/events.xml new file mode 100644 index 0000000..b9dac52 --- /dev/null +++ b/etc/frontend/events.xml @@ -0,0 +1,6 @@ + + + + + + From 93f91c02decabb7c2dc27d4fed4e1ef82dd47361 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Thu, 30 Jun 2022 15:37:47 +0200 Subject: [PATCH 30/36] POSTCODENL-379 added the css according to the module list --- Observer/LessLoader.php | 58 --------------- Plugin/View/Page/Config/Renderer.php | 70 +++++++++++++++++++ etc/frontend/di.xml | 5 ++ etc/frontend/events.xml | 6 -- view/frontend/layout/checkout_index_index.xml | 37 ---------- ...ut.less => aheadworks_onestepcheckout.css} | 0 ...asty_checkout.less => amasty_checkout.css} | 2 +- ...out.less => mageplaza_onestepcheckout.css} | 0 ...out_iosc.less => onestepcheckout_iosc.css} | 0 .../css/{postcode_be.less => postcode_be.css} | 0 .../{postcode_main.less => postcode_main.css} | 14 ++-- .../css/{postcode_nl.less => postcode_nl.css} | 0 ...checkout.less => rubic_clean_checkout.css} | 0 13 files changed, 80 insertions(+), 112 deletions(-) delete mode 100644 Observer/LessLoader.php create mode 100644 Plugin/View/Page/Config/Renderer.php delete mode 100644 etc/frontend/events.xml delete mode 100644 view/frontend/layout/checkout_index_index.xml rename view/frontend/web/css/{aheadworks_onestepcheckout.less => aheadworks_onestepcheckout.css} (100%) rename view/frontend/web/css/{amasty_checkout.less => amasty_checkout.css} (91%) rename view/frontend/web/css/{mageplaza_onestepcheckout.less => mageplaza_onestepcheckout.css} (100%) rename view/frontend/web/css/{onestepcheckout_iosc.less => onestepcheckout_iosc.css} (100%) rename view/frontend/web/css/{postcode_be.less => postcode_be.css} (100%) rename view/frontend/web/css/{postcode_main.less => postcode_main.css} (91%) rename view/frontend/web/css/{postcode_nl.less => postcode_nl.css} (100%) rename view/frontend/web/css/{rubic_clean_checkout.less => rubic_clean_checkout.css} (100%) diff --git a/Observer/LessLoader.php b/Observer/LessLoader.php deleted file mode 100644 index fe2b66e..0000000 --- a/Observer/LessLoader.php +++ /dev/null @@ -1,58 +0,0 @@ -moduleList = $moduleList; - } - - /** - * @param Observer $observer - * - * @return Observer - */ - public function execute(Observer $observer) - { - $array = $this->getEnabledModuleList(); - - // TODO: implement a better way - if (in_array('Amasty_Checkout', $array)){ - $observer->getLayout()->getUpdate()->addUpdate($this->getXmlCode()); - } - - return $observer; - } - - /** - * Return the correct Less file in XML format - * - * @return string - */ - private function getXmlCode(){ - // TODO: implement better? - return ' - - '; - } - - /** - * Return an array of the enabled modules (bin/magento module:status) - * - * @return array - */ - private function getEnabledModuleList(){ - return $this->moduleList->getNames(); - } -} diff --git a/Plugin/View/Page/Config/Renderer.php b/Plugin/View/Page/Config/Renderer.php new file mode 100644 index 0000000..09e9378 --- /dev/null +++ b/Plugin/View/Page/Config/Renderer.php @@ -0,0 +1,70 @@ +moduleList = $moduleList; + $this->config = $config; + + } + + /** + * @param \Magento\Framework\View\Page\Config\Renderer $subject + * @param $assetestlist + * + * @see Renderer::renderAssets() + * + * @return array|array[] + */ + public function beforeRenderAssets( + \Magento\Framework\View\Page\Config\Renderer $subject, + $assetestlist = []) + { + $modules = $this->getEnabledModuleList(); + + $checkoutModules = [ + 'Amasty_Checkout' => 'TIG_Postcode::css/amasty_checkout.css', + 'Mageplaza_Osc' => 'TIG_Postcode::css/mageplaza_onestepcheckout.css', + 'Aheadworks_OneStepCheckout' => 'TIG_Postcode::css/aheadworks_onestepcheckout.css', + 'OneStepCheckout_Iosc' => 'TIG_Postcode::css/onestepcheckout_iosc.css', + ]; + + foreach ($checkoutModules as $key => $value) { + if (in_array($key, $modules)){ + $this->config->addPageAsset($value); + } + if (in_array('TIG_Postcode',$modules)){ + $this->config->addPageAsset('TIG_Postcode::css/postcode_main.css'); + $this->config->addPageAsset('TIG_Postcode::css/postcode_nl.css'); + $this->config->addPageAsset('TIG_Postcode::css/postcode_be.css'); + } + } + + return [$assetestlist]; + } + + /** + * Return an array of the enabled modules (bin/magento module:status) + * + * @return array + */ + private function getEnabledModuleList(){ + return $this->moduleList->getNames(); + } +} diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index e8da7bd..f203640 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -47,4 +47,9 @@ + + + + +
diff --git a/etc/frontend/events.xml b/etc/frontend/events.xml deleted file mode 100644 index b9dac52..0000000 --- a/etc/frontend/events.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml deleted file mode 100644 index 050de17..0000000 --- a/view/frontend/layout/checkout_index_index.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - diff --git a/view/frontend/web/css/aheadworks_onestepcheckout.less b/view/frontend/web/css/aheadworks_onestepcheckout.css similarity index 100% rename from view/frontend/web/css/aheadworks_onestepcheckout.less rename to view/frontend/web/css/aheadworks_onestepcheckout.css diff --git a/view/frontend/web/css/amasty_checkout.less b/view/frontend/web/css/amasty_checkout.css similarity index 91% rename from view/frontend/web/css/amasty_checkout.less rename to view/frontend/web/css/amasty_checkout.css index 6b42b65..01387c8 100644 --- a/view/frontend/web/css/amasty_checkout.less +++ b/view/frontend/web/css/amasty_checkout.css @@ -1,4 +1,4 @@ -.tig_hidden, .amcheckout-wrapper .fieldset.address > .field.tig_hidden { +.amcheckout-wrapper .fieldset.address > .field.tig_hidden { display: none; } diff --git a/view/frontend/web/css/mageplaza_onestepcheckout.less b/view/frontend/web/css/mageplaza_onestepcheckout.css similarity index 100% rename from view/frontend/web/css/mageplaza_onestepcheckout.less rename to view/frontend/web/css/mageplaza_onestepcheckout.css diff --git a/view/frontend/web/css/onestepcheckout_iosc.less b/view/frontend/web/css/onestepcheckout_iosc.css similarity index 100% rename from view/frontend/web/css/onestepcheckout_iosc.less rename to view/frontend/web/css/onestepcheckout_iosc.css diff --git a/view/frontend/web/css/postcode_be.less b/view/frontend/web/css/postcode_be.css similarity index 100% rename from view/frontend/web/css/postcode_be.less rename to view/frontend/web/css/postcode_be.css diff --git a/view/frontend/web/css/postcode_main.less b/view/frontend/web/css/postcode_main.css similarity index 91% rename from view/frontend/web/css/postcode_main.less rename to view/frontend/web/css/postcode_main.css index 2077905..224d202 100644 --- a/view/frontend/web/css/postcode_main.less +++ b/view/frontend/web/css/postcode_main.css @@ -1,13 +1,7 @@ -// country specific styling -@import 'postcode_nl'; -@import 'postcode_be'; -// -@import 'amasty_checkout'; -@import 'mageplaza_onestepcheckout'; -@import 'onestepcheckout_iosc'; -@import 'aheadworks_onestepcheckout'; -@import 'rubic_clean_checkout'; - +/** hidden field **/ +.tig_hidden{ + display: none; +} /**** Validation ****/ .tig_postcode_field._error .control, diff --git a/view/frontend/web/css/postcode_nl.less b/view/frontend/web/css/postcode_nl.css similarity index 100% rename from view/frontend/web/css/postcode_nl.less rename to view/frontend/web/css/postcode_nl.css diff --git a/view/frontend/web/css/rubic_clean_checkout.less b/view/frontend/web/css/rubic_clean_checkout.css similarity index 100% rename from view/frontend/web/css/rubic_clean_checkout.less rename to view/frontend/web/css/rubic_clean_checkout.css From 399c31ad8126271a42dcfedef7c682ba51af1afc Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Thu, 30 Jun 2022 17:00:07 +0200 Subject: [PATCH 31/36] POSTCODENL-379 code cleanup --- Plugin/View/Page/Config/Renderer.php | 50 ++++++++++++++++------------ 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/Plugin/View/Page/Config/Renderer.php b/Plugin/View/Page/Config/Renderer.php index 09e9378..e18a73f 100644 --- a/Plugin/View/Page/Config/Renderer.php +++ b/Plugin/View/Page/Config/Renderer.php @@ -1,27 +1,34 @@ moduleList = $moduleList; - $this->config = $config; - + $this->config = $config; + $this->scopeConfig = $scopeConfig; + $this->moduleList = $moduleList; } /** @@ -36,7 +43,7 @@ public function beforeRenderAssets( \Magento\Framework\View\Page\Config\Renderer $subject, $assetestlist = []) { - $modules = $this->getEnabledModuleList(); + $modules = $this->moduleList->getNames(); $checkoutModules = [ 'Amasty_Checkout' => 'TIG_Postcode::css/amasty_checkout.css', @@ -51,20 +58,19 @@ public function beforeRenderAssets( } if (in_array('TIG_Postcode',$modules)){ $this->config->addPageAsset('TIG_Postcode::css/postcode_main.css'); - $this->config->addPageAsset('TIG_Postcode::css/postcode_nl.css'); - $this->config->addPageAsset('TIG_Postcode::css/postcode_be.css'); + // check if NL is enabled + if ($this->scopeConfig->getValue('tig_postcode/countries/enable_nl_check', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE)){ + $this->config->addPageAsset('TIG_Postcode::css/postcode_nl.css'); + } + // check if BE is enabled + if ($this->scopeConfig->getValue('tig_postcode/countries/enable_be_check', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE)){ + $this->config->addPageAsset('TIG_Postcode::css/postcode_be.css'); + } } } return [$assetestlist]; } - - /** - * Return an array of the enabled modules (bin/magento module:status) - * - * @return array - */ - private function getEnabledModuleList(){ - return $this->moduleList->getNames(); - } } From cb3b2a9eff4ae7fe19fa12cf43a81b2554504464 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Thu, 30 Jun 2022 17:00:51 +0200 Subject: [PATCH 32/36] POSTCODENL-379 file cleanup --- Plugin/View/Page/Config/Renderer.php | 2 -- view/frontend/web/css/aheadworks_onestepcheckout.css | 0 view/frontend/web/css/onestepcheckout_iosc.css | 0 view/frontend/web/css/rubic_clean_checkout.css | 0 4 files changed, 2 deletions(-) delete mode 100644 view/frontend/web/css/aheadworks_onestepcheckout.css delete mode 100644 view/frontend/web/css/onestepcheckout_iosc.css delete mode 100644 view/frontend/web/css/rubic_clean_checkout.css diff --git a/Plugin/View/Page/Config/Renderer.php b/Plugin/View/Page/Config/Renderer.php index e18a73f..f035dea 100644 --- a/Plugin/View/Page/Config/Renderer.php +++ b/Plugin/View/Page/Config/Renderer.php @@ -48,8 +48,6 @@ public function beforeRenderAssets( $checkoutModules = [ 'Amasty_Checkout' => 'TIG_Postcode::css/amasty_checkout.css', 'Mageplaza_Osc' => 'TIG_Postcode::css/mageplaza_onestepcheckout.css', - 'Aheadworks_OneStepCheckout' => 'TIG_Postcode::css/aheadworks_onestepcheckout.css', - 'OneStepCheckout_Iosc' => 'TIG_Postcode::css/onestepcheckout_iosc.css', ]; foreach ($checkoutModules as $key => $value) { diff --git a/view/frontend/web/css/aheadworks_onestepcheckout.css b/view/frontend/web/css/aheadworks_onestepcheckout.css deleted file mode 100644 index e69de29..0000000 diff --git a/view/frontend/web/css/onestepcheckout_iosc.css b/view/frontend/web/css/onestepcheckout_iosc.css deleted file mode 100644 index e69de29..0000000 diff --git a/view/frontend/web/css/rubic_clean_checkout.css b/view/frontend/web/css/rubic_clean_checkout.css deleted file mode 100644 index e69de29..0000000 From 43250aff291f7da6ac5d910cbda43ba47efbe5a7 Mon Sep 17 00:00:00 2001 From: Kevin van Dijk Date: Thu, 30 Jun 2022 22:27:38 +0200 Subject: [PATCH 33/36] POSTCODENL-387 postnl/postcode bug fixes --- view/frontend/web/js/action/create-shipping-address-mixin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/frontend/web/js/action/create-shipping-address-mixin.js b/view/frontend/web/js/action/create-shipping-address-mixin.js index 53e0db7..cd0c951 100644 --- a/view/frontend/web/js/action/create-shipping-address-mixin.js +++ b/view/frontend/web/js/action/create-shipping-address-mixin.js @@ -10,7 +10,7 @@ define([ if (messageContainer.custom_attributes != undefined) { $.each(messageContainer.custom_attributes , function( key, value ) { - messageContainer['custom_attributes'][key] = {'attribute_code':key,'value':value}; + messageContainer['custom_attributes'][key] = value; }); } From e8adcfb84cee8ecfcad55bbaeaa069517f2f50cc Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Mon, 4 Jul 2022 11:09:12 +0200 Subject: [PATCH 34/36] POSTCODENL-381 clean code --- Plugin/Model/Checkout/LayoutProcessorPlugin.php | 6 ++++-- Plugin/Model/Osc/LayoutProcessorPlugin.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Plugin/Model/Checkout/LayoutProcessorPlugin.php b/Plugin/Model/Checkout/LayoutProcessorPlugin.php index b5d78db..1d55ab5 100644 --- a/Plugin/Model/Checkout/LayoutProcessorPlugin.php +++ b/Plugin/Model/Checkout/LayoutProcessorPlugin.php @@ -65,8 +65,10 @@ class LayoutProcessorPlugin * @param NotifierInterface $notifier * @param ScopeConfigInterface $scopeConfig */ - public function __construct(ArrayManager $arrayManager, NotifierInterface $notifier, ScopeConfigInterface $scopeConfig) - { + public function __construct(ArrayManager $arrayManager, + NotifierInterface $notifier, + ScopeConfigInterface $scopeConfig + ) { $this->arrayManager = $arrayManager; $this->notifier = $notifier; $this->scopeConfig = $scopeConfig; diff --git a/Plugin/Model/Osc/LayoutProcessorPlugin.php b/Plugin/Model/Osc/LayoutProcessorPlugin.php index 6952168..1774497 100644 --- a/Plugin/Model/Osc/LayoutProcessorPlugin.php +++ b/Plugin/Model/Osc/LayoutProcessorPlugin.php @@ -65,8 +65,10 @@ class LayoutProcessorPlugin * @param NotifierInterface $notifier * @param ScopeConfigInterface $scopeConfig */ - public function __construct(ArrayManager $arrayManager, NotifierInterface $notifier, ScopeConfigInterface $scopeConfig) - { + public function __construct(ArrayManager $arrayManager, + NotifierInterface $notifier, + ScopeConfigInterface $scopeConfig + ) { $this->arrayManager = $arrayManager; $this->notifier = $notifier; $this->scopeConfig = $scopeConfig; From 7b430627140feab77832b7b1284a7278c115fdcf Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Mon, 4 Jul 2022 11:59:54 +0200 Subject: [PATCH 35/36] Change version number for release --- Block/Adminhtml/Config/Support/Tab.php | 2 +- Test/Unit/Block/Adminhtml/Config/Support/TabTest.php | 2 +- composer.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Block/Adminhtml/Config/Support/Tab.php b/Block/Adminhtml/Config/Support/Tab.php index e614fd0..7fc6ec4 100644 --- a/Block/Adminhtml/Config/Support/Tab.php +++ b/Block/Adminhtml/Config/Support/Tab.php @@ -40,7 +40,7 @@ class Tab extends Template implements RendererInterface { const MODULE_NAME = 'TIG_Postcode'; - const EXTENSION_VERSION = '1.5.0-RC1'; + const EXTENSION_VERSION = '1.5.0'; // @codingStandardsIgnoreLine protected $_template = 'TIG_Postcode::config/support/tab.phtml'; diff --git a/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php b/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php index 8f263a4..5850b9c 100644 --- a/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php +++ b/Test/Unit/Block/Adminhtml/Config/Support/TabTest.php @@ -42,7 +42,7 @@ class TabTest extends TestCase public function testGetVersionNumber() { $instance = $this->getInstance(); - $this->assertSame('1.5.0-RC1', $instance->getVersionNumber()); + $this->assertSame('1.5.0', $instance->getVersionNumber()); } public function testGetSupportedMagentoVersions() diff --git a/composer.json b/composer.json index 51fe595..72e64f6 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "magento/module-quote": ">=101.0.5,<=101.0.11|~101.1|~101.2" }, "type": "magento2-module", - "version": "1.5.0-RC1", + "version": "1.5.0", "license": "CC-BY-NC-ND-3.0", "authors": [ { From 5d2333eb1707283870549d8a4f4eb9f8b7010020 Mon Sep 17 00:00:00 2001 From: Luuk Smal Date: Tue, 5 Jul 2022 10:10:25 +0200 Subject: [PATCH 36/36] Code cleanup --- Helper/TigFieldsHelper.php | 4 +++- .../Model/Checkout/LayoutProcessorPlugin.php | 9 ++++---- Plugin/Model/Osc/LayoutProcessorPlugin.php | 9 ++++---- .../Country/CollectionPlugin.php | 11 +++++---- Plugin/View/Page/Config/Renderer.php | 23 ++++++++++++------- .../templates/config/parsing/streets.phtml | 2 +- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/Helper/TigFieldsHelper.php b/Helper/TigFieldsHelper.php index 3409124..6fb5d7c 100644 --- a/Helper/TigFieldsHelper.php +++ b/Helper/TigFieldsHelper.php @@ -52,7 +52,9 @@ class TigFieldsHelper /** * @param LoggerInterface $logger */ - public function __construct(LoggerInterface $logger){ + public function __construct( + LoggerInterface $logger + ){ $this->logger = $logger; } diff --git a/Plugin/Model/Checkout/LayoutProcessorPlugin.php b/Plugin/Model/Checkout/LayoutProcessorPlugin.php index 1d55ab5..526bc7d 100644 --- a/Plugin/Model/Checkout/LayoutProcessorPlugin.php +++ b/Plugin/Model/Checkout/LayoutProcessorPlugin.php @@ -65,9 +65,10 @@ class LayoutProcessorPlugin * @param NotifierInterface $notifier * @param ScopeConfigInterface $scopeConfig */ - public function __construct(ArrayManager $arrayManager, - NotifierInterface $notifier, - ScopeConfigInterface $scopeConfig + public function __construct( + ArrayManager $arrayManager, + NotifierInterface $notifier, + ScopeConfigInterface $scopeConfig ) { $this->arrayManager = $arrayManager; $this->notifier = $notifier; @@ -168,7 +169,7 @@ private function getParentPath($path, $delimiter = '/', $count = 1) */ public function addAdminErrorMessage($message) { - $this->notifier->addMajor("TIG Postcode", "Postcodeservice detected one or more compability issues with your shop setup"); + $this->notifier->addMajor("TIG Postcode", "Postcodeservice detected one or more compatibility issues with your shop setup"); } /** diff --git a/Plugin/Model/Osc/LayoutProcessorPlugin.php b/Plugin/Model/Osc/LayoutProcessorPlugin.php index 1774497..00ce5f1 100644 --- a/Plugin/Model/Osc/LayoutProcessorPlugin.php +++ b/Plugin/Model/Osc/LayoutProcessorPlugin.php @@ -65,9 +65,10 @@ class LayoutProcessorPlugin * @param NotifierInterface $notifier * @param ScopeConfigInterface $scopeConfig */ - public function __construct(ArrayManager $arrayManager, - NotifierInterface $notifier, - ScopeConfigInterface $scopeConfig + public function __construct( + ArrayManager $arrayManager, + NotifierInterface $notifier, + ScopeConfigInterface $scopeConfig ) { $this->arrayManager = $arrayManager; $this->notifier = $notifier; @@ -168,7 +169,7 @@ private function getParentPath($path, $delimiter = '/', $count = 1) */ public function addAdminErrorMessage($message) { - $this->notifier->addMajor("TIG Postcode", "Postcodeservice detected one or more compability issues with your shop setup"); + $this->notifier->addMajor("TIG Postcode", "Postcodeservice detected one or more compatibility issues with your shop setup"); } /** diff --git a/Plugin/Model/ResourceModel/Country/CollectionPlugin.php b/Plugin/Model/ResourceModel/Country/CollectionPlugin.php index e75d3e8..7b6074e 100644 --- a/Plugin/Model/ResourceModel/Country/CollectionPlugin.php +++ b/Plugin/Model/ResourceModel/Country/CollectionPlugin.php @@ -34,6 +34,7 @@ use Magento\Framework\Module\FullModuleList; use TIG\Postcode\Config\Provider\ModuleConfiguration; +use Magento\Directory\Model\ResourceModel\Country\Collection; class CollectionPlugin { @@ -208,14 +209,14 @@ private function addPostcodeConfig(&$countryOption, $country, $sortOrderBase, $s * @return int[] */ private function getSortOrderAndIncrement(){ - $sortOrderBase = 81; + $sortOrderBase = 81; $sortOrderIncrement = 1; foreach(self::SORT_ORDER_CONFIG as $module => $config){ if(!$this->fullModuleList->has($module)) { continue; } - $sortOrderBase = $config[self::SORT_ORDER_BASE]; + $sortOrderBase = $config[self::SORT_ORDER_BASE]; $sortOrderIncrement = $config[self::SORT_ORDER_INCREMENT]; } @@ -223,11 +224,11 @@ private function getSortOrderAndIncrement(){ } /** - * @param \Magento\Directory\Model\ResourceModel\Country\Collection$subject - * @param $result + * @param Collection $subject + * @param $result * * @return mixed - * @see \Magento\Directory\Model\ResourceModel\Country\Collection::toOptionArray + * @see Collection::toOptionArray */ public function afterToOptionArray( $subject, diff --git a/Plugin/View/Page/Config/Renderer.php b/Plugin/View/Page/Config/Renderer.php index f035dea..9c22ca4 100644 --- a/Plugin/View/Page/Config/Renderer.php +++ b/Plugin/View/Page/Config/Renderer.php @@ -3,6 +3,8 @@ use Magento\Framework\Module\ModuleList; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Store\Model\ScopeInterface; +use Magento\Framework\View\Page\Config\Renderer as pageRender; use Magento\Framework\View\Page\Config; class Renderer @@ -13,26 +15,31 @@ class Renderer /** @var ScopeConfigInterface */ private $scopeConfig; + /** @var ScopeInterface */ + private $scopeStore; + /** @var ModuleList */ public $moduleList; /** - * @param \Magento\Framework\View\Page\Config $config - * @param ScopeConfigInterface $scopeConfig - * @param ModuleList $moduleList + * @param Config $config + * @param ScopeConfigInterface $scopeConfig + * @param ModuleList $moduleList */ public function __construct( Config $config, ScopeConfigInterface $scopeConfig, + ScopeInterface $scopeStore, ModuleList $moduleList ){ $this->config = $config; $this->scopeConfig = $scopeConfig; + $this->scopeStore = $scopeStore; $this->moduleList = $moduleList; } /** - * @param \Magento\Framework\View\Page\Config\Renderer $subject + * @param pageRender $subject * @param $assetestlist * * @see Renderer::renderAssets() @@ -40,8 +47,8 @@ public function __construct( * @return array|array[] */ public function beforeRenderAssets( - \Magento\Framework\View\Page\Config\Renderer $subject, - $assetestlist = []) + pageRender $subject, + $assetestlist = []) { $modules = $this->moduleList->getNames(); @@ -58,12 +65,12 @@ public function beforeRenderAssets( $this->config->addPageAsset('TIG_Postcode::css/postcode_main.css'); // check if NL is enabled if ($this->scopeConfig->getValue('tig_postcode/countries/enable_nl_check', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE)){ + $this->scopeStore::SCOPE_STORE)){ $this->config->addPageAsset('TIG_Postcode::css/postcode_nl.css'); } // check if BE is enabled if ($this->scopeConfig->getValue('tig_postcode/countries/enable_be_check', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE)){ + $this->scopeStore::SCOPE_STORE)){ $this->config->addPageAsset('TIG_Postcode::css/postcode_be.css'); } } diff --git a/view/adminhtml/templates/config/parsing/streets.phtml b/view/adminhtml/templates/config/parsing/streets.phtml index 02ebfdd..a7659fc 100644 --- a/view/adminhtml/templates/config/parsing/streets.phtml +++ b/view/adminhtml/templates/config/parsing/streets.phtml @@ -42,7 +42,7 @@
escapeHtml(__('Tampering with the settings may affect the workflow of third party extensions. Use at your own risk.'));?>
- escapeHtml(__('Note: These settings are disabled in this new release. If you still need this functionality contact support'));?> + escapeHtml(__('Note: These settings are disabled in this new release. If you still need this functionality please contact support'));?>