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/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" diff --git a/bin/setup.sh b/bin/setup.sh index d0324e0..5215e9e 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -1,32 +1,22 @@ -#!/bin/bash +#!/usr/bin/env bash -MAGENTO_ROOT="/magento" -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 \ No newline at end of file +# 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 diff --git a/docker-compose.yml b/docker-compose.yml index bfc91eb..a6a7b9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,13 +10,14 @@ web: env_file: - current.env environment: - - VIRTUAL_HOST=mage2.docker + - VIRTUAL_HOST=magento2-royalmail.docker + - VIRTUAL_PORT=80 - MAGENTO_RUN_MODE=developer appdata: image: tianon/true volumes: - - ./magento:/magento + - ./magento:/var/www/magento - ./:/src - ~/.composer/cache:/root/.composer/cache @@ -68,12 +69,12 @@ 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 - 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 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 f0cc4a2..f962078 100644 --- a/src/Test/Unit/Model/CarrierTest.php +++ b/src/Test/Unit/Model/CarrierTest.php @@ -1,8 +1,4 @@ scopeConfig @@ -125,7 +121,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 +139,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 +155,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 +170,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 +214,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); @@ -272,7 +268,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 +289,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); } 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); + } + } +} diff --git a/src/Test/Unit/Model/RounderTest.php b/src/Test/Unit/Model/RounderTest.php index ad5fdcb..198c6a8 100644 --- a/src/Test/Unit/Model/RounderTest.php +++ b/src/Test/Unit/Model/RounderTest.php @@ -1,8 +1,4 @@ 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. 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 @@ - +