From 3051d04af7bc6f4a33b092fe242503ee324c3a90 Mon Sep 17 00:00:00 2001 From: Gabor Suranyi Date: Wed, 23 Sep 2015 14:17:54 +0100 Subject: [PATCH 01/11] Fixed issues from Code Audit Report 091415-1 - encrypting access tokens in db - escaping data coming from config - use of isSetFlag to check Yesno state - removed some dead code - corrected XSD paths - camelCaps for function names in the helpers. --- Helper/Data.php | 245 ++++++++++-------- Model/Source/Searchbg.php | 19 -- Model/Source/Searchicon.php | 16 -- composer.json | 2 +- composer.json~ | 24 ++ etc/adminhtml/system.xml | 4 +- etc/config.xml | 10 +- etc/module.xml | 2 +- view/adminhtml/layout/customer_index_edit.xml | 2 +- view/adminhtml/layout/sales_order_address.xml | 2 +- view/adminhtml/templates/config.phtml | 2 +- view/frontend/layout/checkout_index_index.xml | 2 +- .../frontend/layout/customer_address_form.xml | 2 +- view/frontend/templates/config.phtml | 2 +- 14 files changed, 180 insertions(+), 154 deletions(-) delete mode 100644 Model/Source/Searchbg.php delete mode 100644 Model/Source/Searchicon.php create mode 100644 composer.json~ diff --git a/Helper/Data.php b/Helper/Data.php index 219ac5f..4eac84e 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -3,141 +3,184 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper { - public function get_frontend_cfg(){ + /** + * @var \Magento\Framework\Escaper + */ + protected $_escaper; + /** + * @var \Magento\Framework\Encryption\EncryptorInterface + */ + protected $_encryptor; + /** + * @param \Magento\Framework\App\Helper\Context $context + * @param \Magento\Framework\Escaper $_escaper + * @param \Magento\Framework\Encryption\EncryptorInterface $_encryptor + */ + public function __construct( + \Magento\Framework\App\Helper\Context $context, + \Magento\Framework\Escaper $escaper, + \Magento\Framework\Encryption\EncryptorInterface $encryptor + ) { + $this->_escaper = $escaper; + $this->_encryptor = $encryptor; + parent::__construct($context); + } + public function getFrontendCfg(){ $cfg = []; - $cfg['key'] = $this->scopeConfig->getValue( - 'cc_uk/main_options/frontend_accesstoken', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['enabled'] = $this->scopeConfig->getValue( + $cfg['key'] = $this->_encryptor->decrypt( + $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/main_options/frontend_accesstoken', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ) + ); + $cfg['enabled'] = $this->scopeConfig->isSetFlag( 'cc_uk/main_options/frontend_enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) == 1; - $cfg['hide_fields'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/hide_fields', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) == 1; - $cfg['auto_search'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/searchbar_auto_search', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) == 1; - $cfg['clean_postsearch'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/searchbar_clean_postsearch', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) == 1; - // special search configs - - $cfg['searchbar_type'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/searchbar_type', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); - /* - $cfg['search_bg'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/search_bg', + $cfg['hide_fields'] = $this->scopeConfig->isSetFlag( + 'cc_uk/gfx_options/hide_fields', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); - $cfg['search_bg_color'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/search_bg_color', + $cfg['auto_search'] = $this->scopeConfig->isSetFlag( + 'cc_uk/gfx_options/searchbar_auto_search', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); - $cfg['search_icon'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/search_icon', + $cfg['clean_postsearch'] = $this->scopeConfig->isSetFlag( + 'cc_uk/gfx_options/searchbar_clean_postsearch', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); + // special search configs - $cfg['search_icon_color'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/search_icon_color', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + $cfg['searchbar_type'] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/gfx_options/searchbar_type', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) ); - */ // errors $cfg['error_msg'] = []; - $cfg['error_msg']["0001"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/error_msg_1', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['error_msg']["0002"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/error_msg_2', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['error_msg']["0003"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/error_msg_3', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['error_msg']["0004"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/error_msg_4', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + $cfg['error_msg']["0001"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/error_msg_1', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['error_msg']["0002"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/error_msg_2', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['error_msg']["0003"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/error_msg_3', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['error_msg']["0004"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/error_msg_4', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) ); $cfg['txt'] = []; - $cfg['txt']["search_label"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/search_label', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['txt']["search_placeholder"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/search_placeholder', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['txt']['button_text'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/button_text', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + $cfg['txt']["search_label"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/search_label', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['txt']["search_placeholder"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/search_placeholder', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['txt']['button_text'] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/gfx_options/button_text', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) ); return json_encode($cfg); } - public function get_backend_cfg(){ + public function getBackendCfg(){ $cfg = []; - $cfg['key'] = $this->scopeConfig->getValue( - 'cc_uk/main_options/backend_accesstoken', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['enabled'] = $this->scopeConfig->getValue( + $cfg['key'] = $this->_encryptor->decrypt( + $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/main_options/backend_accesstoken', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ) + ); + $cfg['enabled'] = $this->scopeConfig->isSetFlag( 'cc_uk/main_options/backend_enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) == 1; - $cfg['auto_search'] = $this->scopeConfig->getValue( + ); + $cfg['auto_search'] = $this->scopeConfig->isSetFlag( 'cc_uk/gfx_options/searchbar_auto_search', \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) == 1; - $cfg['clean_postsearch'] = $this->scopeConfig->getValue( + ); + $cfg['clean_postsearch'] = $this->scopeConfig->isSetFlag( 'cc_uk/gfx_options/searchbar_clean_postsearch', \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) == 1; + ); - $cfg['searchbar_type'] = $this->scopeConfig->getValue( - 'cc_uk/gfx_options/searchbar_type', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + $cfg['searchbar_type'] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/gfx_options/searchbar_type', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) ); $cfg['error_msg'] = []; - $cfg['error_msg']["0001"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/error_msg_1', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['error_msg']["0002"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/error_msg_2', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['error_msg']["0003"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/error_msg_3', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['error_msg']["0004"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/error_msg_4', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + $cfg['error_msg']["0001"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/error_msg_1', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['error_msg']["0002"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/error_msg_2', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['error_msg']["0003"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/error_msg_3', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['error_msg']["0004"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/error_msg_4', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) ); $cfg['txt'] = []; - $cfg['txt']["search_label"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/search_label', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['txt']["search_placeholder"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/search_placeholder', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $cfg['txt']["search_buttontext"] = $this->scopeConfig->getValue( - 'cc_uk/txt_options/search_buttontext', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + $cfg['txt']["search_label"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/search_label', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['txt']["search_placeholder"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/search_placeholder', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $cfg['txt']["search_buttontext"] = $this->_escaper->escapeHtml( + $this->scopeConfig->getValue( + 'cc_uk/txt_options/search_buttontext', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) ); return json_encode($cfg); diff --git a/Model/Source/Searchbg.php b/Model/Source/Searchbg.php deleted file mode 100644 index 233e34e..0000000 --- a/Model/Source/Searchbg.php +++ /dev/null @@ -1,19 +0,0 @@ - 'hex', 'label' => 'Hexagon'], - ['value' => 'flat', 'label' => 'Flat'], - ['value' => 'spike', 'label' => 'Spike'], - ['value' => 'convex', 'label' => 'Convex'] - ]; - } -} diff --git a/Model/Source/Searchicon.php b/Model/Source/Searchicon.php deleted file mode 100644 index 826fbbd..0000000 --- a/Model/Source/Searchicon.php +++ /dev/null @@ -1,16 +0,0 @@ - 'search', 'label' => 'Magnifier'] - ]; - } -} diff --git a/composer.json b/composer.json index 23f9f4d..bbc68df 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "magento/framework": "1.0.0-beta" }, "type": "magento2-module", - "version": "0.1.6", + "version": "0.1.6-alpha", "extra": { "map": [ [ diff --git a/composer.json~ b/composer.json~ new file mode 100644 index 0000000..bbc68df --- /dev/null +++ b/composer.json~ @@ -0,0 +1,24 @@ +{ + "name": "craftyclicks/module-clicktoaddress", + "description": "Apply postcode lookup to Magento 2.", + "require": { + "magento/framework": "1.0.0-beta" + }, + "type": "magento2-module", + "version": "0.1.6-alpha", + "extra": { + "map": [ + [ + "*", + "Craftyclicks/Clicktoaddress" + ] + ] + }, + "authors": [ + { + "name": "Gabor Peter Suranyi", + "homepage": "https://craftyclicks.co.uk/", + "role": "Developer" + } + ] +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 3aa19e2..5225c22 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,5 +1,5 @@ - + @@ -24,6 +24,7 @@ + Magento\Config\Model\Config\Backend\Encrypted @@ -31,6 +32,7 @@ + Magento\Config\Model\Config\Backend\Encrypted diff --git a/etc/config.xml b/etc/config.xml index 817cdd0..141b7c6 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -5,7 +5,7 @@ * See COPYING.txt for license details. */ --> - + @@ -19,14 +19,6 @@ 0 1 0 - - - Type your postcode here diff --git a/etc/module.xml b/etc/module.xml index 09f8ef7..6e519e3 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ + xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> diff --git a/view/adminhtml/layout/customer_index_edit.xml b/view/adminhtml/layout/customer_index_edit.xml index a0e5fec..2893d77 100644 --- a/view/adminhtml/layout/customer_index_edit.xml +++ b/view/adminhtml/layout/customer_index_edit.xml @@ -1,6 +1,6 @@ + xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 74d81e3..978bce6 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -1,6 +1,6 @@ + xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> From e4e37ff5f78cb3f91573ab557be70dcc0a31d6b6 Mon Sep 17 00:00:00 2001 From: Gabor Suranyi Date: Wed, 23 Sep 2015 14:23:14 +0100 Subject: [PATCH 02/11] Updated version number --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bbc68df..d60dbb9 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "magento/framework": "1.0.0-beta" }, "type": "magento2-module", - "version": "0.1.6-alpha", + "version": "0.1.7-alpha", "extra": { "map": [ [ From 5331a1e93a99b83d5e642633ea0d637f4257c73a Mon Sep 17 00:00:00 2001 From: Gabor Peter Suranyi Date: Wed, 23 Sep 2015 14:23:59 +0100 Subject: [PATCH 03/11] Delete composer.json~ --- composer.json~ | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 composer.json~ diff --git a/composer.json~ b/composer.json~ deleted file mode 100644 index bbc68df..0000000 --- a/composer.json~ +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "craftyclicks/module-clicktoaddress", - "description": "Apply postcode lookup to Magento 2.", - "require": { - "magento/framework": "1.0.0-beta" - }, - "type": "magento2-module", - "version": "0.1.6-alpha", - "extra": { - "map": [ - [ - "*", - "Craftyclicks/Clicktoaddress" - ] - ] - }, - "authors": [ - { - "name": "Gabor Peter Suranyi", - "homepage": "https://craftyclicks.co.uk/", - "role": "Developer" - } - ] -} From 33607b82600aeedaf747b75712c96bbb7822c122 Mon Sep 17 00:00:00 2001 From: Gabor Peter Suranyi Date: Wed, 23 Sep 2015 15:22:15 +0100 Subject: [PATCH 04/11] Update README.md Alpha stability required from now on. (instead of dev) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cded6a0..e92dbeb 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ First add the repository: } ], ``` -& make sure that your your minimum-stability is dev. +& make sure that your your minimum-stability is alpha. Then, add the module to the required list either via the composer.json, or execute ``` composer require craftyclicks/module-clicktoaddress From de4eb88e9b75e653463e8e0a2742e18ab602e7ff Mon Sep 17 00:00:00 2001 From: Gabor Peter Suranyi Date: Tue, 17 Nov 2015 13:23:38 +0000 Subject: [PATCH 05/11] Update composer.json Updating version requirements to m2ce --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d60dbb9..1bc7115 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "craftyclicks/module-clicktoaddress", "description": "Apply postcode lookup to Magento 2.", "require": { - "magento/framework": "1.0.0-beta" + "magento/magento2ce": "2.0.*" }, "type": "magento2-module", "version": "0.1.7-alpha", From 4dc79f53cd09b59abf7d0efe4039e7a6ad6559dd Mon Sep 17 00:00:00 2001 From: Gabor Peter Suranyi Date: Wed, 18 Nov 2015 12:34:28 +0000 Subject: [PATCH 06/11] Update README.md RC2 wrapup. register php file will be included. --- README.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e92dbeb..202c674 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,10 @@ First add the repository: ``` -"repositories": [ - { - "type": "vcs", - "url": "https://github.com/craftyclicks/magento2" - } - ], +composer config repositories.inchoostripe git https://github.com/craftyclicks/magento2.git ``` & make sure that your your minimum-stability is alpha. -Then, add the module to the required list either via the composer.json, or execute +Then, request composer to fetch the module: ``` composer require craftyclicks/module-clicktoaddress ``` @@ -21,7 +16,6 @@ composer require craftyclicks/module-clicktoaddress Then execute install script ``` -php -f bin/magento module:enable --clear-static-content Craftyclicks_Clicktoaddress php -f bin/magento setup:upgrade ``` @@ -31,7 +25,6 @@ php -f bin/magento setup:upgrade - Download & copy the git contents to the folder - Run install script ``` -php -f bin/magento module:enable --clear-static-content Craftyclicks_Clicktoaddress php -f bin/magento setup:upgrade ``` From 80ee932dcfef2c5014edf8d0703f650d6c259762 Mon Sep 17 00:00:00 2001 From: Gabor Peter Suranyi Date: Wed, 18 Nov 2015 12:34:49 +0000 Subject: [PATCH 07/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 202c674..5efc6f4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ First add the repository: ``` -composer config repositories.inchoostripe git https://github.com/craftyclicks/magento2.git +composer config repositories.craftyclicks git https://github.com/craftyclicks/magento2.git ``` & make sure that your your minimum-stability is alpha. Then, request composer to fetch the module: From 9fea81e8b4b95d44e84f76a21b1352c9a645bba2 Mon Sep 17 00:00:00 2001 From: Gabor Peter Suranyi Date: Thu, 19 Nov 2015 15:01:16 +0000 Subject: [PATCH 08/11] Updated for RC2 compatibility php classes are still not recognized. xsd paths updated & registration.php added. --- Model/Source/Searchtype.php | 5 ++--- composer.json | 5 +++-- etc/adminhtml/acl.xml | 2 +- etc/adminhtml/system.xml | 2 +- etc/config.xml | 4 +--- etc/module.xml | 6 ++---- registration.php | 10 ++++++++++ view/adminhtml/layout/customer_index_edit.xml | 2 +- view/adminhtml/layout/sales_order_address.xml | 2 +- view/frontend/layout/checkout_index_index.xml | 2 +- view/frontend/layout/customer_address_form.xml | 2 +- 11 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 registration.php diff --git a/Model/Source/Searchtype.php b/Model/Source/Searchtype.php index 2e23730..ff16722 100644 --- a/Model/Source/Searchtype.php +++ b/Model/Source/Searchtype.php @@ -10,9 +10,8 @@ class Searchtype implements \Magento\Framework\Option\ArrayInterface public function toOptionArray() { return [ - //['value' => 'searchbar_icon', 'label' => 'SearchBar + Icon'], - ['value' => 'searchbar_text', 'label' => 'SearchBar'], - ['value' => 'traditional', 'label' => 'Traditional'] + ['value' => 'searchbar_text', 'label' => __('SearchBar')], + ['value' => 'traditional', 'label' => __('Traditional')] ]; } } diff --git a/composer.json b/composer.json index 1bc7115..406d63c 100644 --- a/composer.json +++ b/composer.json @@ -2,10 +2,11 @@ "name": "craftyclicks/module-clicktoaddress", "description": "Apply postcode lookup to Magento 2.", "require": { - "magento/magento2ce": "2.0.*" + "php": "~5.5.0|~5.6.0", + "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.1.7-alpha", + "version": "0.1.7-beta", "extra": { "map": [ [ diff --git a/etc/adminhtml/acl.xml b/etc/adminhtml/acl.xml index cc7d9de..d91ee51 100644 --- a/etc/adminhtml/acl.xml +++ b/etc/adminhtml/acl.xml @@ -1,5 +1,5 @@ - + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 5225c22..e96b61b 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,5 +1,5 @@ - + diff --git a/etc/config.xml b/etc/config.xml index 141b7c6..7019458 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -5,14 +5,12 @@ * See COPYING.txt for license details. */ --> - + 0 0 - xxxxx-xxxxx-xxxxx-xxxxx - xxxxx-xxxxx-xxxxx-xxxxx traditional diff --git a/etc/module.xml b/etc/module.xml index 6e519e3..6f8e46f 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,5 @@ - - - + + diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..fe23c8a --- /dev/null +++ b/registration.php @@ -0,0 +1,10 @@ + + xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> diff --git a/view/adminhtml/web/cc_middleman.js b/view/adminhtml/web/cc_middleman.js deleted file mode 100644 index 241fe3c..0000000 --- a/view/adminhtml/web/cc_middleman.js +++ /dev/null @@ -1,253 +0,0 @@ -/** - * Lets define the CraftyClicks Constructor - * @cfg {object} containing base configurations. - */ - -function cc_ui_handler(cfg){ - console.log(cfg); - this.cfg = cfg; - - var lines = 0; - if(typeof cfg.dom.address_1 !== "undefined"){ - lines++; - } - if(typeof cfg.dom.address_2 !== "undefined"){ - lines++; - } - if(typeof cfg.dom.address_3 !== "undefined"){ - lines++; - } - this.cfg.core.lines = lines; - this.cc_core = new cc_rapid(this.cfg.core); -} -/** - * Fetches data from the api based on the configuration, and stores it. - * Skips the lookup if the data is already looked up. - * @return {object} the response data set. - */ - -cc_ui_handler.prototype.sort = function(is_uk){ - var elems = this.cfg.dom; - var country = elems['country'].parents(this.cfg.sort_fields.parent).last(); - // Sort disabled; position country on top - var company = elems['company'].parents(this.cfg.sort_fields.parent).last(); - var postcode = elems['postcode'].parents(this.cfg.sort_fields.parent).last(); - country.insertBefore(company); - if(this.cfg.search_type != 'traditional'){ - var searchContainer = this.search_object.parents(this.cfg.sort_fields.parent).last(); - country.after(searchContainer); - } else { - var searchContainer = this.search_object; - country.after(searchContainer); - } - - if(this.cfg.hide_fields){ - if(this.cfg.search_type != 'traditional'){ - var tagElement = ['postcode', 'company', 'address_1', 'town', 'county', 'county_list']; - } else { - var tagElement = ['company', 'address_1', 'town', 'county', 'county_list']; - } - for(var i=0; i < tagElement.length; i++){ - elems[tagElement[i]].parents(this.cfg.sort_fields.parent).last().addClass('crafty_address_field'); - } - } -} -/* -cc_ui_handler.prototype.sortTool = function(a,b){ - var a_holder = a.parents(this.cfg.sort_fields.parent).last(); - var b_holder = b.parents(this.cfg.sort_fields.parent).last(); - a_holder.after(b_holder); -}*/ -cc_ui_handler.prototype.country_change = function(country){ - - var active_countries = ['GB','IM','JE','GY']; - if(active_countries.indexOf(country) != -1){ - if(this.cfg.sort_fields.active){ - this.sort(true); - this.search_object.parents(this.cfg.sort_fields.parent).last().show(); - } - } else { - if(this.cfg.sort_fields.active){ - this.sort(false); - this.search_object.parents(this.cfg.sort_fields.parent).last().hide(); - } - } - if(this.cfg.hide_fields && (active_countries.indexOf(country) != -1) && (this.cfg.dom.postcode.val() == "")){ - jQuery('.crafty_address_field').hide(); - } else { - jQuery('.crafty_address_field').show(); - } -} - -cc_ui_handler.prototype.activate = function(){ - this.addui(); - if(this.cfg.only_uk){ - this.country_change(this.cfg.dom.country.val()); - // transfer object to event scope - var that = this; - this.cfg.dom.country.on('change',function(){ - // selected country - var sc = jQuery(this).val(); - that.country_change(sc); - }); - } -} - -cc_ui_handler.prototype.addui = function(){ - // transfer object to event scope - var that = this; - // apply dom elements - var html = ''; - switch(this.cfg.search_type){ - case "searchbar_text": - html = '
' - + '' - + '' - + '
' - + '
'; - break; - } - - if(this.cfg.search_type != 'traditional' && typeof this.cfg.search_wrapper !== 'undefined'){ - html = this.cfg.search_wrapper.before + html + this.cfg.search_wrapper.after; - } - if(this.cfg.search_type != 'traditional'){ - this.cfg.dom.country.parents(this.cfg.sort_fields.parent).last().after(html); - } else { - // input after postcode - var postcode_elem = this.cfg.dom.postcode; - postcode_elem.wrap(''); - postcode_elem.addClass('search-box'); - postcode_elem.after(''); - var new_container = postcode_elem.closest(this.cfg.sort_fields.parent); - new_container.addClass('search-container').attr('id',this.cfg.id).addClass('type_3'); - // add search list - postcode_elem.closest('.search-bar').after('' - + '
'); - } - - // apply postcode lookup (by button) - this.search_object = jQuery('.search-container[id="'+this.cfg.id+'"]'); - this.search_object.find('.action').on('click',function(){ - that.lookup(that.search_object.find('.search-box').val()); - }); - // apply hiding of list on input change && auto search - this.search_object.find('.search-box').on('keyup',function(){ - that.search_object.find('.search-list').hide(); - that.search_object.find('.extra-info').hide(); - - that.search_object.find('.mage-error').hide(); - - if(that.cfg.search_type != 'traditional'){ - // apply auto search - if(that.cfg.auto_search && (that.cc_core.clean_input(jQuery(this).val()) != null)){ - that.lookup(that.search_object.find('.search-box').val()); - } - } - }); - -} - -cc_ui_handler.prototype.lookup = function(postcode){ - var dataset = this.cc_core.search(postcode); - if(typeof dataset.error_code != "undefined"){ - this.prompt_error(dataset.error_code); - return; - } - var new_html = ""; - for(var i=0; i < dataset.delivery_point_count; i++){ - var elems = []; - var endpoint = dataset.delivery_points[i]; - if(endpoint.department_name != "") - elems.push(endpoint.department_name); - if(endpoint.organisation_name != "") - elems.push(endpoint.organisation_name); - if(endpoint.line_1 != "") - elems.push(endpoint.line_1); - if(endpoint.line_2 != "") - elems.push(endpoint.line_2); - if(this.cfg.search_type != 'traditional'){ - new_html += '
  • '+dataset.town+', ' + elems.join(', ') + '
  • '; - } else { - new_html += ''; - } - } - var search_list = this.search_object.find('.search-list'); - if(this.cfg.search_type != 'traditional'){ - search_list.find('ul').html(new_html); - } else { - search_list.find('select').html(new_html); - } - search_list.show(); - - this.search_object.find('.extra-info .search-subtext').html(dataset.town) - this.search_object.find('.extra-info').show(); - var that = this; - - if(this.cfg.search_type != 'traditional'){ - search_list.find('li').on('click',function(){ - that.select(postcode, jQuery(this).data('id')); - search_list.hide(); - }); - } else { - search_list.find('select').on('change',function(){ - that.select(postcode, jQuery(this).find('option:selected').data('id')); - search_list.hide(); - }); - } - - if(that.cfg.search_type != 'traditional'){ - this.search_object.on('focusout',function(){ - // give a tiny time for the on click event to trigger first - setTimeout(function(){ - search_list.hide(); - }, 250); - }); - } -} -cc_ui_handler.prototype.prompt_error = function(errorcode){ - this.search_object.find('.mage-error .search-subtext').html(this.cfg.error_msg[errorcode]); - this.search_object.find('.mage-error').show(); -} -cc_ui_handler.prototype.select = function(postcode, id){ - var dataset = this.cc_core.get_store(this.cc_core.clean_input(postcode)); - - this.cfg.dom.town.val(dataset.town); - this.cfg.dom.postcode.val(dataset.postcode); - - var company_details = []; - if(dataset.delivery_points[id].department_name != ""){ - company_details.push(dataset.delivery_points[id].department_name); - } - if(dataset.delivery_points[id].organisation_name != ""){ - company_details.push(dataset.delivery_points[id].organisation_name); - } - - this.cfg.dom.company.val(company_details.join(', ')); - - for(var i=1; i<=this.cfg.core.lines; i++){ - this.cfg.dom["address_"+i].val(dataset.delivery_points[id]["line_"+i]); - } - - if(this.cfg.hide_fields){ - jQuery('.crafty_address_field').show(); - } - if(this.cfg.search_type != 'traditional' && this.cfg.clean_postsearch){ - this.search_object.find('.search-box').val(''); - } - // trigger change for checkout validation - jQuery.each(this.cfg.dom, function(index, name){ - name.trigger('change'); - }); -} diff --git a/view/adminhtml/web/form_integrations/cc_admin_customer.js b/view/adminhtml/web/form_integrations/cc_admin_customer.js index bff88e1..40d833c 100644 --- a/view/adminhtml/web/form_integrations/cc_admin_customer.js +++ b/view/adminhtml/web/form_integrations/cc_admin_customer.js @@ -35,7 +35,7 @@ function activate_cc_m2(){ }, txt: crafty_cfg.txt, error_msg: crafty_cfg.error_msg - } + }; var address_dom = { company: jQuery("[name$='[company]']"), address_1: jQuery("[name$='[street][0]']"), @@ -46,7 +46,6 @@ function activate_cc_m2(){ county_list:jQuery("select[name$='[region_id]']"), country: jQuery("select[name$='[country_id]']") }; - address_dom; // special for admin panel: search each potential element address_dom.postcode.each(function(index){ // different tagging method; tag object as active @@ -60,7 +59,7 @@ function activate_cc_m2(){ county: jQuery(jQuery("[name$='[region]']")[index]), county_list:jQuery(jQuery("select[name$='[region_id]']")[index]), country: jQuery(jQuery("select[name$='[country_id]']")[index]) - } + }; jQuery(this).data('cc','active'); console.log(cfg.dom); diff --git a/view/adminhtml/web/form_integrations/cc_admin_order.js b/view/adminhtml/web/form_integrations/cc_admin_order.js index 19b6170..7af8ea2 100644 --- a/view/adminhtml/web/form_integrations/cc_admin_order.js +++ b/view/adminhtml/web/form_integrations/cc_admin_order.js @@ -30,7 +30,7 @@ function activate_cc_m2(){ }, txt: crafty_cfg.txt, error_msg: crafty_cfg.error_msg - } + }; var address_dom = { company: jQuery("[name='company']"), address_1: jQuery("[name='street[0]']"), diff --git a/view/frontend/web/cc_middleman.js b/view/base/web/cc_middleman.js similarity index 97% rename from view/frontend/web/cc_middleman.js rename to view/base/web/cc_middleman.js index c31bbc3..ddf3124 100644 --- a/view/frontend/web/cc_middleman.js +++ b/view/base/web/cc_middleman.js @@ -64,16 +64,18 @@ cc_ui_handler.prototype.country_change = function(country){ if(active_countries.indexOf(country) != -1){ if(this.cfg.sort_fields.active){ this.sort(true); - this.search_object.parents(this.cfg.sort_fields.parent).last().show(); } + this.search_object.parents(this.cfg.sort_fields.parent).last().show(); + } else { if(this.cfg.sort_fields.active){ this.sort(false); - this.search_object.parents(this.cfg.sort_fields.parent).last().hide(); } + this.search_object.parents(this.cfg.sort_fields.parent).last().hide(); } if(this.cfg.hide_fields && (active_countries.indexOf(country) != -1) && (this.cfg.dom.postcode.val() == "")){ jQuery('.crafty_address_field').hide(); + jQuery('.search-bar .action') } else { jQuery('.crafty_address_field').show(); } diff --git a/view/adminhtml/web/cc_rapid.css b/view/base/web/cc_rapid.css similarity index 100% rename from view/adminhtml/web/cc_rapid.css rename to view/base/web/cc_rapid.css diff --git a/view/adminhtml/web/cc_rapid2.css b/view/base/web/cc_rapid2.css similarity index 99% rename from view/adminhtml/web/cc_rapid2.css rename to view/base/web/cc_rapid2.css index 41838d2..6ea59b4 100644 --- a/view/adminhtml/web/cc_rapid2.css +++ b/view/base/web/cc_rapid2.css @@ -30,7 +30,6 @@ .search-container.type_3 .action{ position: absolute; right: 0px; - top: 0px; } .search-container.type_2 .action{ position: absolute; diff --git a/view/adminhtml/web/cc_rapid_core.js b/view/base/web/cc_rapid_core.js similarity index 100% rename from view/adminhtml/web/cc_rapid_core.js rename to view/base/web/cc_rapid_core.js diff --git a/view/frontend/web/cc_rapid.css b/view/frontend/web/cc_rapid.css deleted file mode 100644 index 8d0d176..0000000 --- a/view/frontend/web/cc_rapid.css +++ /dev/null @@ -1,56 +0,0 @@ -.search-container input{ - outline: none; - border: 0px; - background-color: #e4e8e9; - border-top-left-radius: 5px; - border-bottom-left-radius: 5px; - font-size: 14px; - padding: 8px 12px; - color: #85888d; - width: 200px; -} -.search-container .icon{ - background-image: url('https://dl.dropboxusercontent.com/u/8625455/hexagon1.png'); - position: absolute; - right: -25px; - top: -8px; - height: 30px; - width: 30px; - padding: 12px 10px; - color: white; -} -.search-container .icon .fa{ - color: white; - font-size: 1.5em; -} -.search-container{ - margin: 0px; - position: relative; - display: inline-block; -} -.search-container .search-list{ - background-color: #e4e8e9; - font-size: 14px; - padding: 0px; - color: #85888d; - list-style: none; - margin: 0px 0px 0px 10px; -} -.search-container .search-list li{ - border: 1px solid #85888d; - padding: 6px 10px; - cursor: pointer; - border-top: none; - margin-bottom: 0px; -} -.search-container .search-list li:hover{ - background-color: white; - -} -.search-container .search-list li:first-child{ - border-top: none; -} -.search-container .search-list li:last-child{ - border-bottom-left-radius: 5px; - border-bottom-right-radius: 5px; -} diff --git a/view/frontend/web/cc_rapid2.css b/view/frontend/web/cc_rapid2.css deleted file mode 100644 index 41838d2..0000000 --- a/view/frontend/web/cc_rapid2.css +++ /dev/null @@ -1,189 +0,0 @@ -.search-container input{ - outline: none; - border: 0px; - font-size: 14px; - padding: 8px 12px; - color: #85888d; - width: 100%; - min-width: 300px; - max-width: 75%; - background: #fff; - border: 1px solid #c2c2c2; - border-top-left-radius: 1px; - border-bottom-left-radius: 1px; -} -.search-container input:focus{ - outline: none; -} -.search-container .search-bar{ - min-width: 300px; - max-width: 66%; -} -.search-container.type_1 .action{ - position: absolute; - right: 10px; - top: -4px; - height: 40px; - width: 33%; - color: white; -} -.search-container.type_3 .action{ - position: absolute; - right: 0px; - top: 0px; -} -.search-container.type_2 .action{ - position: absolute; - right: 0px; - top: 0px; -} -.search-container.type_1 .action .icon, .search-container.type_1 .action .icon_bg{ - position: absolute; - top: 0px; -} -.search-container.type_1 .action .icon svg{ - width: 20px; - height: auto; - padding: 10px; -} -.search-container.type_1 .action .icon_bg svg{ - width: 40px; - height: auto; -} -.search-container.type_1 .action .icon_bg svg.bg_flat{ - width: auto; - height: 32px; - margin-top: 4px; -} -.search-container.type_1 .action .icon_bg svg.bg_spike{ - width: auto; - height: 32px; - margin-top: 4px; - padding-left: 12px; -} -.search-container.type_1 .action .icon_bg svg.bg_convex{ - width: auto; - height: 32px; - margin-top: 4px; - padding-left: 9px; -} - -.search-container.type_1 .action .spin.icon svg{ - -webkit-animation-name: spin; - -webkit-animation-duration: 1000ms; - -webkit-animation-iteration-count: infinite; - -webkit-animation-timing-function: linear; - -moz-animation-name: spin; - -moz-animation-duration: 1000ms; - -moz-animation-iteration-count: infinite; - -moz-animation-timing-function: linear; - -ms-animation-name: spin; - -ms-animation-duration: 1000ms; - -ms-animation-iteration-count: infinite; - -ms-animation-timing-function: linear; - - animation-name: spin; - animation-duration: 1000ms; - animation-iteration-count: infinite; - animation-timing-function: linear; -} -.search-container .extra-info{ - display: block; - color: white; - background-color: #1979c3; - border-bottom-left-radius: 5px; - border-bottom-right-radius: 5px; - border: 1px solid #1979c3; - - min-width: inherit; - max-width: inherit; -} -.search-container{ - margin: 0px; - position: relative; - width: 100%; - display: inline-block; -} -.search-container .search-list{ - min-width: 300px; - max-width: 66%; -} -.search-container .search-list{ - min-width: 300px; - max-width: 66%; -} -.search-container .search-list ul{ - max-height: 200px; - overflow-y: scroll; - font-size: 14px; - padding: 0px; - color: #85888d; - list-style: none; - margin: 0px; - border-left: 1px solid #c2c2c2; - border-right: 1px solid #c2c2c2; - - min-width: inherit; - max-width: inherit; -} -.search-container .search-list li{ - //background-color: #e4e8e9; - //border-bottom: 1px solid #85888d; - padding: 0.25em 0.5em; - cursor: pointer; - margin-bottom: 0px; - text-align: left; - font-size: 12px; - -} -.search-container .search-list li:nth-child(odd){ - //background-color: #f1f3f4; -} -.search-container .search-list li:hover{ - //background-color: white; - background-color: #f1f1f1; -} -.search-container .search-list li:first-child{ - border-top: none; -} -.search-container .search-list li:last-child{ - border-bottom: none; -} -.search-container .error{ - font-size: 0.8em; - display: none; - color: white; - border-bottom-left-radius: 10px; - border-bottom-right-radius: 10px; - font-weight: bold; - text-align: center; - - min-width: 300px; - max-width: 66%; - /* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ff5501+0,e33827+100 */ - background: #e33827; /* Old browsers */ - background: -moz-linear-gradient(top, #ff5501 0%, #e33827 100%); /* FF3.6+ */ - background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ff5501), color-stop(100%,#e33827)); /* Chrome,Safari4+ */ - background: -webkit-linear-gradient(top, #ff5501 0%,#e33827 100%); /* Chrome10+,Safari5.1+ */ - background: -o-linear-gradient(top, #ff5501 0%,#e33827 100%); /* Opera 11.10+ */ - background: -ms-linear-gradient(top, #ff5501 0%,#e33827 100%); /* IE10+ */ - background: linear-gradient(to bottom, #ff5501 0%,#e33827 100%); /* W3C */ - filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff5501', endColorstr='#e33827',GradientType=0 ); /* IE6-9 */ - -} -.search-subtext{ - padding: 0.25em 0.5em; -} - -@-moz-keyframes spin { - from { -moz-transform: rotate(0deg); } - to { -moz-transform: rotate(360deg); } -} -@-webkit-keyframes spin { - from { -webkit-transform: rotate(0deg); } - to { -webkit-transform: rotate(360deg); } -} -@keyframes spin { - from {transform:rotate(0deg);} - to {transform:rotate(360deg);} -} diff --git a/view/frontend/web/cc_rapid_core.js b/view/frontend/web/cc_rapid_core.js deleted file mode 100644 index fd7fc99..0000000 --- a/view/frontend/web/cc_rapid_core.js +++ /dev/null @@ -1,254 +0,0 @@ -/** - * Lets define the CraftyClicks Constructor - * @cfg {object} containing base configurations. - */ - -function cc_rapid(cfg){ - this.baseURL = 'https://pcls1.craftyclicks.co.uk/json/rapidaddress'; - this.key = cfg.key; - this.geocode = cfg.geocode; - if(typeof this.geocode == "undefined") - this.geocode = false; - this.alias = cfg.alias; - if(typeof this.alias == "undefined") - this.alias = false; - this.preformat = cfg.preformat; - if(typeof this.preformat == "undefined") - this.preformat = false; - this.capsformat = cfg.capsformat; - if(typeof this.capsformat == "undefined") - this.capsformat = { - address : false, - organization : false, - county : false, - town: false - }; - // store previously retrieved datasets - this.lines = cfg.lines; - this.dataStore = new Array(); - -} -/** - * Fetches data from the api based on the configuration, and stores it. - * Skips the lookup if the data is already looked up. - * @return {object} the response data set. - */ - - -cc_rapid.prototype.search = function(input){ - // clean postcode - var postcode = this.clean_input(input); - if(postcode == null){ - return { error_code: "0002" }; - } - var data = {}; - if(this.is_stored(postcode)){ - data = this.get_store(postcode); - } else { - data = this.fetch_data(postcode); - if(typeof data.error_code == "undefined"){ - data = this.format_data(data); - } - this.store(postcode, data); - } - return data; -} -// gets data from storage -cc_rapid.prototype.get_store = function(postcode){ - console.warn('retrieving data from store'); - return this.dataStore[postcode]; -} -// adds data to storage -cc_rapid.prototype.store = function(postcode, object){ - this.dataStore[postcode] = object; - console.warn('data saved'); - return true; -} -// checks if postcode related data is already stored -cc_rapid.prototype.is_stored = function(postcode){ - return this.dataStore.hasOwnProperty(postcode); -} -// gets data from craftyclicks API -cc_rapid.prototype.fetch_data = function(postcode){ - // Set up the URL - var url = this.baseURL + '?key=' + this.key + '&postcode=' + postcode; - url += '&sort=asc'; - if(this.preformat){ - url += '&response=data_formatted'; - url += '&lines='+this.lines; - } - - // Create new XMLHttpRequest, has to be synchronous so we can handle response - request = new XMLHttpRequest(); - request.open('GET', url, false); - - // Wait for change and then either JSON parse response text or throw exception for HTTP error - request.onreadystatechange = function() { - if (this.readyState === 4){ - if (this.status >= 200 && this.status < 400){ - // Success! - data = JSON.parse(this.responseText); - console.log(data); - } else { - data = { error_code: "0004" }; - } - } - }; - // Send request - try{ - request.send(); - } - catch(err){ - data = { error_code: "0003" }; - } - // Nullify request object - request = null; - return data; -} -// formatting text from capital to leading caps based on cfg -cc_rapid.prototype.format_data = function(data){ - if(this.capsformat.county){ - data.postal_county = this.leading_caps(data.postal_county); - data.traditional_county = this.leading_caps(data.traditional_county); - } - if(this.capsformat.town){ - data.town = this.leading_caps(data.town); - } - if(this.preformat){ - for(var i=0; i txt.length) { return (txt) } - var out_text = ''; - var words = txt.split(" "); - for (var i=0; i l && s[r] == ' ') { r-=1; } - return s.substring(l, r+1); -} - -cc_rapid.prototype.cp_uc = function(text) { - if ("PC" == text || "UK" == text || "EU" == text) {return (text);} - var alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - var out_text = ''; - var do_uc = 1; - var all_uc = 0; - for (var i=0; i= text.length && "'" == text.charAt(i)) { // only one more char left, don't capitalise - do_uc = 0; - } else if ("(" == text.charAt(i)) { - close_idx = text.indexOf(")",i+1); - if (i+3 < close_idx) { // more than 2 chars - all_uc = 0; do_uc = 1; - } else { // no closing bracket or 2 or les chars in brackets, leave uppercase - all_uc = 1; - } - } else if (")" == text.charAt(i)) { - all_uc = 0; do_uc = 1; - } else if ("-" == text.charAt(i)) { - close_idx = text.indexOf("-",i+1); - if ((-1 != close_idx && i+3 >= close_idx) || i+3 >= text.length) { // less than 2 chars - all_uc = 0; do_uc = 0; - } else { // 2 or more chars - all_uc = 0; do_uc = 1; - } - } else if (i+2 < text.length && "0" <= text.charAt(i) && "9" >= text.charAt(i)) { - do_uc = 0; - } else { - do_uc = 1; - } - } - } - return (out_text); -} -// cleaning the postcode input for all caps no space version -cc_rapid.prototype.clean_input = function(dirty_pc){ - // first strip out anything not alphanumenric - var pc = ''; - do { - pc = dirty_pc; - dirty_pc = dirty_pc.replace(/[^A-Za-z0-9]/, ""); - } while (pc != dirty_pc); - pc = dirty_pc.toUpperCase(); - // check if we have the right length with what is left - if (7 >= pc.length && 5 <= pc.length) { - // get the in code - var inc = pc.substring(pc.length-3,pc.length); - // get the out code - var outc = pc.substring(0, pc.length-3); - // now validate both in and out codes - if (true == /[CIKMOV]/.test(inc)) { - return null; - } - // inCode must be NAA - if ( '0' <= inc.charAt(0) && '9' >= inc.charAt(0) && - 'A' <= inc.charAt(1) && 'Z' >= inc.charAt(1) && - 'A' <= inc.charAt(2) && 'Z' >= inc.charAt(2) ) { - // outcode must be one of AN, ANN, AAN, ANA, AANN, AANA - switch (outc.length) { - case 2: // AN - if ('A' <= outc.charAt(0) && 'Z' >= outc.charAt(0) && - '0' <= outc.charAt(1) && '9' >= outc.charAt(1) ) { return (pc); } - break; - case 3: // ANN, AAN, ANA - if ('A' <= outc.charAt(0) && 'Z' >= outc.charAt(0)) { - if ('0' <= outc.charAt(1) && '9' >= outc.charAt(1) && - '0' <= outc.charAt(2) && '9' >= outc.charAt(2) ) { return (pc); } - else if ('A' <= outc.charAt(1) && 'Z' >= outc.charAt(1) && - '0' <= outc.charAt(2) && '9' >= outc.charAt(2) ) { return (pc); } - else if ('0' <= outc.charAt(1) && '9' >= outc.charAt(1) && - 'A' <= outc.charAt(2) && 'Z' >= outc.charAt(2) ) { return (pc); } - } - break; - case 4: // AANN, AANA - if ('A' <= outc.charAt(0) && 'Z' >= outc.charAt(0) && - 'A' <= outc.charAt(1) && 'Z' >= outc.charAt(1) && - '0' <= outc.charAt(2) && '9' >= outc.charAt(2)) { - if ('0' <= outc.charAt(3) && '9' >= outc.charAt(3) ) { return (pc); } - else if ('A' <= outc.charAt(3) && 'Z' >= outc.charAt(3) ) { return (pc); } - } - break; - default: - break; - } - } - } - return null; -} diff --git a/view/frontend/web/form_integrations/cc_customer_address.js b/view/frontend/web/form_integrations/cc_customer_address.js index e74ae86..e43cd3f 100644 --- a/view/frontend/web/form_integrations/cc_customer_address.js +++ b/view/frontend/web/form_integrations/cc_customer_address.js @@ -30,7 +30,7 @@ function activate_cc_m2(){ }, txt: crafty_cfg.txt, error_msg: crafty_cfg.error_msg - } + }; var address_dom = { company: jQuery("[name='company']"), address_1: jQuery("#street_1"), diff --git a/view/frontend/web/form_integrations/cc_default_checkout.js b/view/frontend/web/form_integrations/cc_default_checkout.js index 3824734..8c9047f 100644 --- a/view/frontend/web/form_integrations/cc_default_checkout.js +++ b/view/frontend/web/form_integrations/cc_default_checkout.js @@ -40,7 +40,8 @@ function activate_cc_m2(){ }, txt: crafty_cfg.txt, error_msg: crafty_cfg.error_msg - } + }; + /* var billing_dom = { company: jQuery("[name='billingAddresscheckmo[company]']"), address_1: jQuery("[name='billingAddresscheckmo[street][0]']"), @@ -50,35 +51,39 @@ function activate_cc_m2(){ county: jQuery("[name='billingAddresscheckmo[region]']"), county_list:jQuery("[name='billingAddresscheckmo[region_id]']"), country: jQuery("[name='billingAddresscheckmo[country_id]']") + };*/ + dom = { + company: jQuery("[name='company']"), + address_1: jQuery("[name='street[0]']"), + address_2: jQuery("[name='street[1]']"), + postcode: jQuery("[name='postcode']"), + town: jQuery("[name='city']"), + county: jQuery("[name='region']"), + county_list:jQuery("[name='region_id']"), + country: jQuery("[name='country_id']") }; - var shipping_dom = { - company: jQuery("[name='shippingAddress[company]']"), - address_1: jQuery("[name='shippingAddress[street][0]']"), - address_2: jQuery("[name='shippingAddress[street][1]']"), - postcode: jQuery("[name='shippingAddress[postcode]']"), - town: jQuery("[name='shippingAddress[city]']"), - county: jQuery("[name='shippingAddress[region]']"), - county_list:jQuery("[name='shippingAddress[region_id]']"), - country: jQuery("[name='shippingAddress[country_id]']") - }; - cfg.dom = billing_dom; - cfg.id = "m2_billing"; - if(cfg.dom.postcode.length == 1 && cfg.dom.postcode.data('cc') != '1'){ - cfg.dom.postcode.data('cc','1'); - var cc_billing = new cc_ui_handler(cfg); - cc_billing.activate(); - } - cfg.dom = shipping_dom; - cfg.id = "m2_shipping"; - if(cfg.dom.postcode.length == 1 && cfg.dom.postcode.data('cc') != '1'){ - console.log('apply shipping'); - cfg.dom.postcode.data('cc','1'); - var cc_shipping = new cc_ui_handler(cfg); - cc_shipping.activate(); - } + dom.postcode.each(function(index){ + if(dom.postcode.eq(index).data('cc') != '1'){ + cfg.id = "m2_"+cc_index; + cc_index++; + cfg.dom = { + company: dom.company.eq(index), + address_1: dom.address_1.eq(index), + address_2: dom.address_2.eq(index), + postcode: dom.postcode.eq(index), + town: dom.town.eq(index), + county: dom.county.eq(index), + county_list: dom.county_list.eq(index), + country: dom.country.eq(index) + }; + cfg.dom.postcode.data('cc','1'); + var cc_generic = new cc_ui_handler(cfg); + cc_generic.activate(); + } + }); } } - +var cc_index = 0; requirejs(['jquery'], function( $ ) { jQuery( document ).ready(function() { if(crafty_cfg.enabled){ From a1c84389761d6c1433104538ad074abcc2612e5a Mon Sep 17 00:00:00 2001 From: Gabor Peter Suranyi Date: Wed, 25 Nov 2015 15:38:10 +0000 Subject: [PATCH 10/11] Order/Create/Customer support - added support to Order -> Create Customer step - changed dropdown type from arrayInterface to OptionSourceInterface - unused code & css removed --- Model/Source/Searchtype.php | 2 +- composer.json | 2 +- etc/adminhtml/system.xml | 45 +---------- etc/module.xml | 2 +- .../sales_order_create_customer_block.xml | 18 +++++ .../cc_admin_order_create_customer.js | 60 ++++++++++++++ view/base/web/cc_middleman.js | 56 +++++++------ view/base/web/cc_rapid.css | 56 ------------- view/base/web/cc_rapid2.css | 81 +------------------ 9 files changed, 118 insertions(+), 204 deletions(-) create mode 100644 view/adminhtml/layout/sales_order_create_customer_block.xml create mode 100644 view/adminhtml/web/form_integrations/cc_admin_order_create_customer.js delete mode 100644 view/base/web/cc_rapid.css diff --git a/Model/Source/Searchtype.php b/Model/Source/Searchtype.php index ff16722..320ccd5 100644 --- a/Model/Source/Searchtype.php +++ b/Model/Source/Searchtype.php @@ -2,7 +2,7 @@ namespace Craftyclicks\Clicktoaddress\Model\Source; -class Searchtype implements \Magento\Framework\Option\ArrayInterface +class Searchtype implements \Magento\Framework\Data\OptionSourceInterface { /** * @return array diff --git a/composer.json b/composer.json index 197982b..2594c72 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.1.8-beta", + "version": "0.1.9-beta", "extra": { "map": [ [ diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index e96b61b..96893d6 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -10,14 +10,6 @@ Craftyclicks_Clicktoaddress::main_config - Magento\Config\Model\Config\Source\Yesno @@ -54,15 +46,10 @@ ]]> Craftyclicks\Clicktoaddress\Model\Source\Searchtype - Magento\Config\Model\Config\Source\Yesno - Initiates search as soon as the input is a valid UK postcode. (only graphical mode) + Initiates search as soon as the input is a valid UK postcode. (only SearchBar mode) @@ -71,36 +58,8 @@ Magento\Config\Model\Config\Source\Yesno - Cleans the search input after selecting an address from the dropdown. (only graphical mode) - - - diff --git a/etc/module.xml b/etc/module.xml index 6f8e46f..830e212 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,5 +1,5 @@ - + diff --git a/view/adminhtml/layout/sales_order_create_customer_block.xml b/view/adminhtml/layout/sales_order_create_customer_block.xml new file mode 100644 index 0000000..0270253 --- /dev/null +++ b/view/adminhtml/layout/sales_order_create_customer_block.xml @@ -0,0 +1,18 @@ + + + +