From 9ed3a8c9523c01b002bd6bc1fd9e15b2cc2a65f4 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Thu, 11 May 2017 10:52:35 +0100 Subject: [PATCH 01/14] Magento root is already defined. --- bin/setup.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/setup.sh b/bin/setup.sh index d0324e0..4746063 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -1,6 +1,5 @@ #!/bin/bash -MAGENTO_ROOT="/magento" PHP="/usr/local/bin/php" COMPOSER="$PHP /usr/local/bin/composer" @@ -29,4 +28,4 @@ $MAGENTO_TOOL setup:static-content:deploy $MAGENTO_TOOL cache:flush -$MAGENTO_TOOL deploy:mode:set developer \ No newline at end of file +$MAGENTO_TOOL deploy:mode:set developer From ddab3fad5aeb6aa99a250ff2b50afdb4b4990659 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Thu, 11 May 2017 10:53:00 +0100 Subject: [PATCH 02/14] Magento root is already defined in container. --- bin/run_unit_tests.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/run_unit_tests.sh b/bin/run_unit_tests.sh index a1243a5..13611cb 100755 --- a/bin/run_unit_tests.sh +++ b/bin/run_unit_tests.sh @@ -1,7 +1,5 @@ #!/bin/bash -x -MAGENTO_ROOT="/magento" - PHP="/usr/local/bin/php -d memory_limit=2G" PHPUNIT_CONFIGURATION="$MAGENTO_ROOT/dev/tests/unit/phpunit.xml.dist" PHPUNIT="$PHP $MAGENTO_ROOT/vendor/bin/phpunit -c $PHPUNIT_CONFIGURATION" From eb3b67373d452581f1150dde1446d6958d2567f8 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Thu, 11 May 2017 10:53:12 +0100 Subject: [PATCH 03/14] Change magento install location and upgrade to CE 2.1.5 --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bfc91eb..d0da727 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ web: appdata: image: tianon/true volumes: - - ./magento:/magento + - ./magento:/var/www/magento - ./:/src - ~/.composer/cache:/root/.composer/cache @@ -75,5 +75,5 @@ cli: - M2SETUP_ADMIN_USER=admin - M2SETUP_ADMIN_PASSWORD=password1 - M2SETUP_BACKEND_FRONTNAME=admin - - M2SETUP_VERSION=2.0.4 + - M2SETUP_VERSION=2.1.5 - M2SETUP_USE_SAMPLE_DATA=true From 0854137a199f8df0b2607a4bfd1c9afd835aa6d6 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Thu, 11 May 2017 10:53:40 +0100 Subject: [PATCH 04/14] Remove magento 2 base requirement which breaks marketplace tech validation process. --- src/composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/composer.json b/src/composer.json index 2a3d77c..036cb74 100644 --- a/src/composer.json +++ b/src/composer.json @@ -2,7 +2,7 @@ "name": "meanbee/module-royalmail", "description": "A Royal Mail shipping integration for Magento 2.", "type": "magento2-module", - "version": "0.1.1", + "version": "0.1.2", "license": [ "OSL-3.0" ], @@ -10,7 +10,6 @@ "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "zendframework/zend-json": "^2.4.0", - "magento/magento2-base": "^2.0.0", "magento/module-config": "^100.0.0", "magento/module-store": "^100.0.0", "magento/module-shipping": "^100.0.0", From fc84ca1c1ab1001105fa35a1450bd8c13b0bb0d5 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Mon, 22 May 2017 12:51:57 +0100 Subject: [PATCH 05/14] Update install process with latest approach. --- bin/setup.sh | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/bin/setup.sh b/bin/setup.sh index 4746063..5215e9e 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -1,31 +1,22 @@ -#!/bin/bash +#!/usr/bin/env bash -PHP="/usr/local/bin/php" -COMPOSER="$PHP /usr/local/bin/composer" +set -e # Exit on error -MODULE_NAME="Meanbee_RoyalMail" -COMPOSER_NAME="meanbee/module-royalmail" - -MAGENTO_TOOL="magento-command" +# Install Magento 2 if necessary +magento-installer cd $MAGENTO_ROOT -# This is required because Magento doesn't support the path type in composer -# this is a hack. - -$COMPOSER config repositories.meanbee_royalmail path /src/src - -$COMPOSER require "$COMPOSER_NAME" "*@dev" - -# Required due to us using the "path" type for the repository -$COMPOSER require "composer/composer" "1.0.0-alpha11 as 1.0.0-alpha10" - -$MAGENTO_TOOL module:enable $MODULE_NAME - -$MAGENTO_TOOL setup:upgrade +# Add the extension via Composer +composer config repositories.meanbee_royalmail '{"type": "path", "url": "/src/src", "options": {"symlink": true}}' -$MAGENTO_TOOL setup:static-content:deploy +composer require "meanbee/module-royalmail" "@dev" -$MAGENTO_TOOL cache:flush +# Workaround for Magento only allowing template paths within the install root +ln -s /src $MAGENTO_ROOT/src/src -$MAGENTO_TOOL deploy:mode:set developer +# Enable the extension and run migrations +magento-command module:enable Meanbee_Royalmail +magento-command setup:upgrade +magento-command setup:static-content:deploy +magento-command cache:flush From 0f010a082784c25b196ce68899f9121baa8b74b5 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Mon, 22 May 2017 12:52:22 +0100 Subject: [PATCH 06/14] Declare project URL in readme for clarity. --- README.md | 2 ++ docker-compose.yml | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cb2f54..4696607 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ docker-compose run cli /tools/setup.sh docker-compose up -d ``` +The site should now be available from http://magento2-royalmail.docker + We are experimenting with grump in this repository to sniff commits for code format violations. You can run these manually by: diff --git a/docker-compose.yml b/docker-compose.yml index d0da727..a6a7b9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,8 @@ web: env_file: - current.env environment: - - VIRTUAL_HOST=mage2.docker + - VIRTUAL_HOST=magento2-royalmail.docker + - VIRTUAL_PORT=80 - MAGENTO_RUN_MODE=developer appdata: @@ -68,7 +69,7 @@ cli: - M2SETUP_DB_NAME=magento2 - M2SETUP_DB_USER=magento2 - M2SETUP_DB_PASSWORD=magento2 - - M2SETUP_BASE_URL=http://mage2.docker/ + - M2SETUP_BASE_URL=http://magento2-royalmail.docker/ - M2SETUP_ADMIN_FIRSTNAME=Admin - M2SETUP_ADMIN_LASTNAME=User - M2SETUP_ADMIN_EMAIL=dummy@gmail.com From c071217f434e8ec914b91647f5f31f39fe27bc2a Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Mon, 22 May 2017 12:52:53 +0100 Subject: [PATCH 07/14] Pass all method data through all our own method class to control code format. With this control, we use a dictionary to shorten method codes. Magento fails with longer method codes, presumably because of length of database fields. Fixes #1 --- src/Model/Carrier.php | 34 +++- src/Model/Method.php | 230 ++++++++++++++++++++++++++++ src/Test/Unit/Model/CarrierTest.php | 20 +-- src/etc/config.xml | 2 +- 4 files changed, 269 insertions(+), 17 deletions(-) create mode 100644 src/Model/Method.php diff --git a/src/Model/Carrier.php b/src/Model/Carrier.php index 6096979..6312111 100644 --- a/src/Model/Carrier.php +++ b/src/Model/Carrier.php @@ -1,8 +1,5 @@ getId(), + $libMethod->getCode(), + $libMethod->getName(), + $libMethod->getCountryCode(), + $libMethod->getPrice(), + $libMethod->getInsuranceValue(), + $libMethod->getMinimumWeight(), + $libMethod->getMaximumWeight(), + $libMethod->getSize() + ); + if (!array_key_exists($method->getCode(), $allowedMethods)) { continue; } @@ -169,7 +178,20 @@ public function getAllowedMethods() */ public function getMethods() { - return $this->getCarrier()->getAllMethods(); + $libraryMethods = $this->getCarrier()->getAllMethods(); + + $methods = array(); + foreach ($libraryMethods as $libMethodCode => $libMethodLabel) { + $method = new \Meanbee\MagentoRoyalmail\Model\Method( + $libMethodCode, + $libMethodCode, + $libMethodLabel + ); + + $methods[$method->getCode()] = $method->getName(); + } + + return $methods; } /** diff --git a/src/Model/Method.php b/src/Model/Method.php new file mode 100644 index 0000000..aa564d5 --- /dev/null +++ b/src/Model/Method.php @@ -0,0 +1,230 @@ + 'eco', + 'express' => 'xp', + 'firstclass' => '1st', + 'international' => 'i11l', + 'large' => 'lg', + 'letter' => 'ltr', + 'medium' => 'med', + 'parcelforce' => 'pf', + 'parcel' => 'prcl', + 'saturday' => 'sat', + 'standard' => 'std', + 'secondclass' => '2nd', + 'signedfor' => 'signed', + 'small' => 'sm', + 'specialdelivery' => 'special', + 'trackedandsigned' => 'tracksign', + 'trackedsigned' => 'tracksign', + 'worldwide' => 'ww', + ); + + /** + * Method constructor. + * + * @param string $id - Method unique identifier + * @param string $code - Method code + * @param string $name - Method label + * @param string $countryCode - Country code of method + * @param string $price - Price of method + * @param string $insuranceValue - Insurance value of method + * @param string $minimumWeight - Minimum weight the method can have + * @param string $maximumWeight - Maximum weight the method can have + * @param null $size - Parcel size, only applies to sm and md parcels + */ + public function __construct( + $id, + $code, + $name, + $countryCode = null, + $price = null, + $insuranceValue = null, + $minimumWeight = null, + $maximumWeight = null, + $size = null + ) { + $this->id = $id; + $this->code = str_replace( + array_keys(self::$methodDictionary), + array_values(self::$methodDictionary), + $code + ); + $this->name = $name; + $this->countryCode = $countryCode; + $this->price = $price; + $this->insuranceValue = $insuranceValue; + $this->minimumWeight = $minimumWeight; + $this->maximumWeight = $maximumWeight; + $this->size = $size; + } + + /** + * The unique ID of a method + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * The method code + * + * @return string + */ + public function getCode() + { + return $this->code; + } + + /** + * The clean shipping method name of the shipping method + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The country code of the method + * + * @return string + */ + public function getCountryCode() + { + return $this->countryCode; + } + + /** + * Price of method + * + * @return string + */ + public function getPrice() + { + return $this->price; + } + + /** + * Maximum value of package that is insured + * + * @return string + */ + public function getInsuranceValue() + { + return $this->insuranceValue; + } + + /** + * The minimum weight the shipping method can accommodate + * + * @return string + */ + public function getMinimumWeight() + { + return $this->minimumWeight; + } + + /** + * The maximum weight the shipping method can accommodate + * + * @return string + */ + public function getMaximumWeight() + { + return $this->maximumWeight; + } + + /** + * The parcel size, only applies to small and medium parcels + * + * @return string + */ + public function getSize() + { + return $this->size; + } + +} diff --git a/src/Test/Unit/Model/CarrierTest.php b/src/Test/Unit/Model/CarrierTest.php index f0cc4a2..62cf353 100644 --- a/src/Test/Unit/Model/CarrierTest.php +++ b/src/Test/Unit/Model/CarrierTest.php @@ -106,8 +106,8 @@ protected function setUp() public function testGetAllowedMethods() { - $methods = "internationalstandardletter,internationalstandardlargeletter"; - $code = 'internationalstandardletter'; + $methods = "i11lstdltr,i11lstdlrgltr"; + $code = 'i11lstdltr'; $name = "International Standard Letter"; $this->scopeConfig @@ -125,7 +125,7 @@ public function testGetAllowedMethods() public function testGetMethods() { - $methods = ['internationalstandardletter' => "International Standard Letter"]; + $methods = ['i11lstdltr' => "International Standard Letter"]; $this->mockAllMethods($methods); $this->assertEquals($methods, $this->model->getMethods()); } @@ -143,7 +143,7 @@ public function testCollectRatesNoAllowedMethods() $this->mockMethodsConfigured(false); $this->mockLibraryRates([$rate]); - $this->mockAllMethods(['internationalstandardsmallparcel' + $this->mockAllMethods(['i11lstdsmprcl' => "International Standard Small Parcel" ]); $this->mockHasResults(false); @@ -159,9 +159,9 @@ public function testCollectRatesDisabledMethods() $rate = $this->getMethod('International Standard Medium Parcel'); - $this->mockMethodsConfigured('internationalstandardsmallparcel'); + $this->mockMethodsConfigured('i11lstdsmprcl'); $this->mockLibraryRates([$rate]); - $this->mockAllMethods(['internationalstandardsmallparcel' + $this->mockAllMethods(['i11lstdsmprcl' => "International Standard Small Parcel" ]); $this->mockHasResults(false); @@ -174,10 +174,10 @@ public function testCollectRatesMediumParcels() { $this->mockIsActive(true); $rate = $this->getMethod('International Standard Small Parcel'); - $this->mockMethodsConfigured('internationalstandardsmallparcel'); + $this->mockMethodsConfigured('i11lstdsmprcl'); $this->mockLibraryRates([$rate]); $this->mockParcelSize(ParcelSize::MEDIUM); - $this->mockAllMethods(['internationalstandardsmallparcel' + $this->mockAllMethods(['i11lstdsmprcl' => "International Standard Small Parcel" ]); $this->mockHasResults(false); @@ -218,9 +218,9 @@ public function testCollectRates() { $this->mockIsActive(true); $rate = $this->getMethod('International Standard Small Parcel'); - $this->mockMethodsConfigured('internationalstandardsmallparcel'); + $this->mockMethodsConfigured('i11lstdsmprcl'); $this->mockLibraryRates([$rate]); - $this->mockAllMethods(['internationalstandardsmallparcel' + $this->mockAllMethods(['i11lstdsmprcl' => "International Standard Small Parcel" ]); $this->mockHasResults(true); diff --git a/src/etc/config.xml b/src/etc/config.xml index a4ca3d0..11a909a 100644 --- a/src/etc/config.xml +++ b/src/etc/config.xml @@ -4,7 +4,7 @@ 0 - specialdelivery9am,specialdelivery1pm,specialdelivery1pmsaturday,specialdelivery9amsaturday,firstclasslettersignedfor,firstclasslargelettersignedfor,firstclasssignedforsmall,firstclasssignedformedium,secondclasslettersignedfor,secondclasslargelettersignedfor,secondclasssmallparcelsignedfor,secondclassmediumparcelsignedfor,letter,largeletter,firstclasssmall,firstclassmedium,secondclassletter,secondclasslargeletter,secondclasssmallparcel,secondclassmediumparcel,internationalstandardletter,internationalstandardlargeletter,internationalstandardsmallparcel,internationallettertrackedsigned,internationallargelettertrackedandsigned,internationalsmallparceltrackedsigned,internationaltrackedletter,internationaltrackedlargeletter,internationaltrackedsmallparcel,internationallettersigned,internationalsignedlargeletter,internationalsignedsmallparcel,internationaleconomyletter,internationaleconomyletter,internationaleconomylargeletter,internationaleconomylargeletter,internationaleconomysmallparcel,parcelforceworldwideexpress9,parcelforceworldwideexpress10,parcelforceworldwideexpressAM,parcelforceworldwideexpress24,parcelforceworldwideexpress48,parcelforceworldwideexpress9saturday,parcelforceworldwideexpress10saturday,parcelforceworldwideexpressAMsaturday,parcelforceworldwideexpress24saturday,parcelforceworldwideexpress48saturday + i11lstdltr,i11lstdlgltr,i11lstdsmprcl,i11lltrtracksign,i11llgltrtracksign,i11lsmprcltracksign,i11ltrackedltr,i11ltrackedlgltr,i11ltrackedsmprcl,i11lltrsigned,i11lsignedlgltr,i11lsignedsmprcl,i11lecoltr,i11lecolgltr,i11lecosmprcl,special1pm,special9am,special1pmsat,special9amsat,1stltrsigned,1stlgltrsigned,1stsignedsm,1stsignedmed,2ndltrsigned,2ndlgltrsigned,2ndsmprclsigned,2ndmedprclsigned,ltr,lgltr,1stsm,1stmed,2ndltr,2ndlgltr,2ndsmprcl,2ndmedprcl,pfwwxp9,pfwwxp10,pfwwxpAM,pfwwxp24,pfwwxp48,pfwwxp9sat,pfwwxp10sat,pfwwxpAMsat,pfwwxp24sat,pfwwxp48sat Royal Mail Meanbee\MagentoRoyalmail\Model\Carrier This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us. From eba3c49f8128c2ac73d63fe541262d70371c97c8 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 22 May 2017 15:38:54 +0100 Subject: [PATCH 08/14] Update test to use correct config path (#7) --- src/Test/Unit/Model/CarrierTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Test/Unit/Model/CarrierTest.php b/src/Test/Unit/Model/CarrierTest.php index f0cc4a2..84540ff 100644 --- a/src/Test/Unit/Model/CarrierTest.php +++ b/src/Test/Unit/Model/CarrierTest.php @@ -272,7 +272,7 @@ protected function mockIsActive($result) $this->scopeConfig ->expects($this->at(0)) ->method('getValue') - ->with('carriers/meanbee_royalmail/active') + ->with('carriers/rm/active') ->willReturn($result); } @@ -293,7 +293,7 @@ protected function mockParcelSize($parcelSize) $this->scopeConfig ->expects($this->at(2)) ->method('getValue') - ->with('carriers/meanbee_royalmail/parcel_size') + ->with('carriers/rm/parcel_size') ->willReturn($parcelSize); } From e789dd711b2815e521e1eb1f0ec0c4b1c273db00 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Mon, 22 May 2017 12:51:57 +0100 Subject: [PATCH 09/14] Update install process with latest approach. --- bin/setup.sh | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/bin/setup.sh b/bin/setup.sh index 4746063..5215e9e 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -1,31 +1,22 @@ -#!/bin/bash +#!/usr/bin/env bash -PHP="/usr/local/bin/php" -COMPOSER="$PHP /usr/local/bin/composer" +set -e # Exit on error -MODULE_NAME="Meanbee_RoyalMail" -COMPOSER_NAME="meanbee/module-royalmail" - -MAGENTO_TOOL="magento-command" +# Install Magento 2 if necessary +magento-installer cd $MAGENTO_ROOT -# This is required because Magento doesn't support the path type in composer -# this is a hack. - -$COMPOSER config repositories.meanbee_royalmail path /src/src - -$COMPOSER require "$COMPOSER_NAME" "*@dev" - -# Required due to us using the "path" type for the repository -$COMPOSER require "composer/composer" "1.0.0-alpha11 as 1.0.0-alpha10" - -$MAGENTO_TOOL module:enable $MODULE_NAME - -$MAGENTO_TOOL setup:upgrade +# Add the extension via Composer +composer config repositories.meanbee_royalmail '{"type": "path", "url": "/src/src", "options": {"symlink": true}}' -$MAGENTO_TOOL setup:static-content:deploy +composer require "meanbee/module-royalmail" "@dev" -$MAGENTO_TOOL cache:flush +# Workaround for Magento only allowing template paths within the install root +ln -s /src $MAGENTO_ROOT/src/src -$MAGENTO_TOOL deploy:mode:set developer +# Enable the extension and run migrations +magento-command module:enable Meanbee_Royalmail +magento-command setup:upgrade +magento-command setup:static-content:deploy +magento-command cache:flush From 7e51e647dd9101fcb6c6766f10ee50119ba023d6 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Mon, 22 May 2017 12:52:22 +0100 Subject: [PATCH 10/14] Declare project URL in readme for clarity. --- README.md | 2 ++ docker-compose.yml | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cb2f54..4696607 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ docker-compose run cli /tools/setup.sh docker-compose up -d ``` +The site should now be available from http://magento2-royalmail.docker + We are experimenting with grump in this repository to sniff commits for code format violations. You can run these manually by: diff --git a/docker-compose.yml b/docker-compose.yml index d0da727..a6a7b9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,8 @@ web: env_file: - current.env environment: - - VIRTUAL_HOST=mage2.docker + - VIRTUAL_HOST=magento2-royalmail.docker + - VIRTUAL_PORT=80 - MAGENTO_RUN_MODE=developer appdata: @@ -68,7 +69,7 @@ cli: - M2SETUP_DB_NAME=magento2 - M2SETUP_DB_USER=magento2 - M2SETUP_DB_PASSWORD=magento2 - - M2SETUP_BASE_URL=http://mage2.docker/ + - M2SETUP_BASE_URL=http://magento2-royalmail.docker/ - M2SETUP_ADMIN_FIRSTNAME=Admin - M2SETUP_ADMIN_LASTNAME=User - M2SETUP_ADMIN_EMAIL=dummy@gmail.com From a490600196949e769f53bd3d7e693663de32efda Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Mon, 22 May 2017 12:52:53 +0100 Subject: [PATCH 11/14] Pass all method data through all our own method class to control code format. With this control, we use a dictionary to shorten method codes. Magento fails with longer method codes, presumably because of length of database fields. Fixes #1 --- src/Model/Carrier.php | 34 +++- src/Model/Method.php | 230 ++++++++++++++++++++++++++++ src/Test/Unit/Model/CarrierTest.php | 20 +-- src/etc/config.xml | 2 +- 4 files changed, 269 insertions(+), 17 deletions(-) create mode 100644 src/Model/Method.php diff --git a/src/Model/Carrier.php b/src/Model/Carrier.php index 04d4c3f..352acde 100644 --- a/src/Model/Carrier.php +++ b/src/Model/Carrier.php @@ -1,8 +1,5 @@ getId(), + $libMethod->getCode(), + $libMethod->getName(), + $libMethod->getCountryCode(), + $libMethod->getPrice(), + $libMethod->getInsuranceValue(), + $libMethod->getMinimumWeight(), + $libMethod->getMaximumWeight(), + $libMethod->getSize() + ); + if (!array_key_exists($method->getCode(), $allowedMethods)) { continue; } @@ -169,7 +178,20 @@ public function getAllowedMethods() */ public function getMethods() { - return $this->getCarrier()->getAllMethods(); + $libraryMethods = $this->getCarrier()->getAllMethods(); + + $methods = array(); + foreach ($libraryMethods as $libMethodCode => $libMethodLabel) { + $method = new \Meanbee\MagentoRoyalmail\Model\Method( + $libMethodCode, + $libMethodCode, + $libMethodLabel + ); + + $methods[$method->getCode()] = $method->getName(); + } + + return $methods; } /** diff --git a/src/Model/Method.php b/src/Model/Method.php new file mode 100644 index 0000000..aa564d5 --- /dev/null +++ b/src/Model/Method.php @@ -0,0 +1,230 @@ + 'eco', + 'express' => 'xp', + 'firstclass' => '1st', + 'international' => 'i11l', + 'large' => 'lg', + 'letter' => 'ltr', + 'medium' => 'med', + 'parcelforce' => 'pf', + 'parcel' => 'prcl', + 'saturday' => 'sat', + 'standard' => 'std', + 'secondclass' => '2nd', + 'signedfor' => 'signed', + 'small' => 'sm', + 'specialdelivery' => 'special', + 'trackedandsigned' => 'tracksign', + 'trackedsigned' => 'tracksign', + 'worldwide' => 'ww', + ); + + /** + * Method constructor. + * + * @param string $id - Method unique identifier + * @param string $code - Method code + * @param string $name - Method label + * @param string $countryCode - Country code of method + * @param string $price - Price of method + * @param string $insuranceValue - Insurance value of method + * @param string $minimumWeight - Minimum weight the method can have + * @param string $maximumWeight - Maximum weight the method can have + * @param null $size - Parcel size, only applies to sm and md parcels + */ + public function __construct( + $id, + $code, + $name, + $countryCode = null, + $price = null, + $insuranceValue = null, + $minimumWeight = null, + $maximumWeight = null, + $size = null + ) { + $this->id = $id; + $this->code = str_replace( + array_keys(self::$methodDictionary), + array_values(self::$methodDictionary), + $code + ); + $this->name = $name; + $this->countryCode = $countryCode; + $this->price = $price; + $this->insuranceValue = $insuranceValue; + $this->minimumWeight = $minimumWeight; + $this->maximumWeight = $maximumWeight; + $this->size = $size; + } + + /** + * The unique ID of a method + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * The method code + * + * @return string + */ + public function getCode() + { + return $this->code; + } + + /** + * The clean shipping method name of the shipping method + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The country code of the method + * + * @return string + */ + public function getCountryCode() + { + return $this->countryCode; + } + + /** + * Price of method + * + * @return string + */ + public function getPrice() + { + return $this->price; + } + + /** + * Maximum value of package that is insured + * + * @return string + */ + public function getInsuranceValue() + { + return $this->insuranceValue; + } + + /** + * The minimum weight the shipping method can accommodate + * + * @return string + */ + public function getMinimumWeight() + { + return $this->minimumWeight; + } + + /** + * The maximum weight the shipping method can accommodate + * + * @return string + */ + public function getMaximumWeight() + { + return $this->maximumWeight; + } + + /** + * The parcel size, only applies to small and medium parcels + * + * @return string + */ + public function getSize() + { + return $this->size; + } + +} diff --git a/src/Test/Unit/Model/CarrierTest.php b/src/Test/Unit/Model/CarrierTest.php index 84540ff..cf94ff0 100644 --- a/src/Test/Unit/Model/CarrierTest.php +++ b/src/Test/Unit/Model/CarrierTest.php @@ -106,8 +106,8 @@ protected function setUp() public function testGetAllowedMethods() { - $methods = "internationalstandardletter,internationalstandardlargeletter"; - $code = 'internationalstandardletter'; + $methods = "i11lstdltr,i11lstdlrgltr"; + $code = 'i11lstdltr'; $name = "International Standard Letter"; $this->scopeConfig @@ -125,7 +125,7 @@ public function testGetAllowedMethods() public function testGetMethods() { - $methods = ['internationalstandardletter' => "International Standard Letter"]; + $methods = ['i11lstdltr' => "International Standard Letter"]; $this->mockAllMethods($methods); $this->assertEquals($methods, $this->model->getMethods()); } @@ -143,7 +143,7 @@ public function testCollectRatesNoAllowedMethods() $this->mockMethodsConfigured(false); $this->mockLibraryRates([$rate]); - $this->mockAllMethods(['internationalstandardsmallparcel' + $this->mockAllMethods(['i11lstdsmprcl' => "International Standard Small Parcel" ]); $this->mockHasResults(false); @@ -159,9 +159,9 @@ public function testCollectRatesDisabledMethods() $rate = $this->getMethod('International Standard Medium Parcel'); - $this->mockMethodsConfigured('internationalstandardsmallparcel'); + $this->mockMethodsConfigured('i11lstdsmprcl'); $this->mockLibraryRates([$rate]); - $this->mockAllMethods(['internationalstandardsmallparcel' + $this->mockAllMethods(['i11lstdsmprcl' => "International Standard Small Parcel" ]); $this->mockHasResults(false); @@ -174,10 +174,10 @@ public function testCollectRatesMediumParcels() { $this->mockIsActive(true); $rate = $this->getMethod('International Standard Small Parcel'); - $this->mockMethodsConfigured('internationalstandardsmallparcel'); + $this->mockMethodsConfigured('i11lstdsmprcl'); $this->mockLibraryRates([$rate]); $this->mockParcelSize(ParcelSize::MEDIUM); - $this->mockAllMethods(['internationalstandardsmallparcel' + $this->mockAllMethods(['i11lstdsmprcl' => "International Standard Small Parcel" ]); $this->mockHasResults(false); @@ -218,9 +218,9 @@ public function testCollectRates() { $this->mockIsActive(true); $rate = $this->getMethod('International Standard Small Parcel'); - $this->mockMethodsConfigured('internationalstandardsmallparcel'); + $this->mockMethodsConfigured('i11lstdsmprcl'); $this->mockLibraryRates([$rate]); - $this->mockAllMethods(['internationalstandardsmallparcel' + $this->mockAllMethods(['i11lstdsmprcl' => "International Standard Small Parcel" ]); $this->mockHasResults(true); diff --git a/src/etc/config.xml b/src/etc/config.xml index d2c10e9..6a03950 100644 --- a/src/etc/config.xml +++ b/src/etc/config.xml @@ -4,7 +4,7 @@ 0 - specialdelivery9am,specialdelivery1pm,specialdelivery1pmsaturday,specialdelivery9amsaturday,firstclasslettersignedfor,firstclasslargelettersignedfor,firstclasssignedforsmall,firstclasssignedformedium,secondclasslettersignedfor,secondclasslargelettersignedfor,secondclasssmallparcelsignedfor,secondclassmediumparcelsignedfor,letter,largeletter,firstclasssmall,firstclassmedium,secondclassletter,secondclasslargeletter,secondclasssmallparcel,secondclassmediumparcel,internationalstandardletter,internationalstandardlargeletter,internationalstandardsmallparcel,internationallettertrackedsigned,internationallargelettertrackedandsigned,internationalsmallparceltrackedsigned,internationaltrackedletter,internationaltrackedlargeletter,internationaltrackedsmallparcel,internationallettersigned,internationalsignedlargeletter,internationalsignedsmallparcel,internationaleconomyletter,internationaleconomyletter,internationaleconomylargeletter,internationaleconomylargeletter,internationaleconomysmallparcel,parcelforceworldwideexpress9,parcelforceworldwideexpress10,parcelforceworldwideexpressAM,parcelforceworldwideexpress24,parcelforceworldwideexpress48,parcelforceworldwideexpress9saturday,parcelforceworldwideexpress10saturday,parcelforceworldwideexpressAMsaturday,parcelforceworldwideexpress24saturday,parcelforceworldwideexpress48saturday + i11lstdltr,i11lstdlgltr,i11lstdsmprcl,i11lltrtracksign,i11llgltrtracksign,i11lsmprcltracksign,i11ltrackedltr,i11ltrackedlgltr,i11ltrackedsmprcl,i11lltrsigned,i11lsignedlgltr,i11lsignedsmprcl,i11lecoltr,i11lecolgltr,i11lecosmprcl,special1pm,special9am,special1pmsat,special9amsat,1stltrsigned,1stlgltrsigned,1stsignedsm,1stsignedmed,2ndltrsigned,2ndlgltrsigned,2ndsmprclsigned,2ndmedprclsigned,ltr,lgltr,1stsm,1stmed,2ndltr,2ndlgltr,2ndsmprcl,2ndmedprcl,pfwwxp9,pfwwxp10,pfwwxpAM,pfwwxp24,pfwwxp48,pfwwxp9sat,pfwwxp10sat,pfwwxpAMsat,pfwwxp24sat,pfwwxp48sat Royal Mail Meanbee\MagentoRoyalmail\Model\Carrier This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us. From 67b072825f39e75cda93a67c5c95646731116fa9 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Tue, 23 May 2017 10:48:12 +0100 Subject: [PATCH 12/14] Add test that method class returns codes shorter than 37 characters in all instances. --- src/Test/Unit/Model/MethodTest.php | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/Test/Unit/Model/MethodTest.php diff --git a/src/Test/Unit/Model/MethodTest.php b/src/Test/Unit/Model/MethodTest.php new file mode 100644 index 0000000..e6a521a --- /dev/null +++ b/src/Test/Unit/Model/MethodTest.php @@ -0,0 +1,44 @@ +carrier = new Carrier(); + } + + /** + * Test that all codes returned are 37 characters or shorter + * We're trying to keep carrer_method under 40 + */ + public function testGetCode() + { + $carrierMethods= $this->carrier->getAllMethods(); + + foreach ($carrierMethods as $carrierMethodCode => $carrierMethodName) { + $method = new Method( + $carrierMethodCode, + $carrierMethodCode, + $carrierMethodName + ); + + $this->assertTrue(strlen($method->getCode()) < 38); + } + } +} From c0e002490960520e8a576c0409c95b89d124f6b4 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Tue, 23 May 2017 10:48:41 +0100 Subject: [PATCH 13/14] Remove Magento copyright notice from our code. --- src/Test/Unit/Model/CarrierTest.php | 4 ---- src/Test/Unit/Model/RounderTest.php | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/Test/Unit/Model/CarrierTest.php b/src/Test/Unit/Model/CarrierTest.php index cf94ff0..f962078 100644 --- a/src/Test/Unit/Model/CarrierTest.php +++ b/src/Test/Unit/Model/CarrierTest.php @@ -1,8 +1,4 @@ Date: Tue, 23 May 2017 11:53:39 +0100 Subject: [PATCH 14/14] Bumber version number to 0.1.3 --- src/composer.json | 2 +- src/etc/module.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/composer.json b/src/composer.json index 036cb74..38a9047 100644 --- a/src/composer.json +++ b/src/composer.json @@ -2,7 +2,7 @@ "name": "meanbee/module-royalmail", "description": "A Royal Mail shipping integration for Magento 2.", "type": "magento2-module", - "version": "0.1.2", + "version": "0.1.3", "license": [ "OSL-3.0" ], diff --git a/src/etc/module.xml b/src/etc/module.xml index e89d1d5..e76c4d0 100644 --- a/src/etc/module.xml +++ b/src/etc/module.xml @@ -1,5 +1,5 @@ - +