Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyshaw committed May 23, 2017
2 parents 66ab7d8 + 36b456d commit b75b9aa
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 60 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions bin/run_unit_tests.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
38 changes: 14 additions & 24 deletions bin/setup.sh
Original file line number Diff line number Diff line change
@@ -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
# 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
9 changes: 5 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
34 changes: 28 additions & 6 deletions src/Model/Carrier.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Meanbee\MagentoRoyalmail\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
Expand Down Expand Up @@ -121,7 +118,19 @@ public function collectRates(RateRequest $request)
}

/** @var \Meanbee\RoyalMail\Method $method */
foreach ($methods as $method) {
foreach ($methods as $libMethod) {
$method = new \Meanbee\MagentoRoyalmail\Model\Method(
$libMethod->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;
}
Expand Down Expand Up @@ -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;
}

/**
Expand Down
230 changes: 230 additions & 0 deletions src/Model/Method.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<?php

namespace Meanbee\MagentoRoyalmail\Model;

/**
* Class Method
*/
class Method
{
/**
* The ID of the method rule.
*
* @var string
*/
protected $id;


/**
* The shipping code name of the method
*
* @var string
*/
protected $code;

/**
* The clean shipping method name of the shipping method
*
* @var string
*/
protected $name;

/**
* The country code of the method
*
* @var string
*/
protected $countryCode;

/**
* Price of method
*
* @var string
*/
protected $price;

/**
* Maximum value of package that is insured
*
* @var string
*/
protected $insuranceValue;

/**
* The minimum weight the shipping method can accommodate
*
* @var string
*/
protected $minimumWeight;

/**
* The maximum weight the shipping method can accommodate
*
* @var string
*/
protected $maximumWeight;

/**
* The parcel size, only applies to small and medium parcels
*
* @var string
*/
protected $size;

/**
* Dictionary to replace strings within method codes.
* Without shortening, method codes are too long and Magento rejects order.
*
* @var $methodDitionary
*/
protected static $methodDictionary = array(
'economy' => '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;
}

}
Loading

0 comments on commit b75b9aa

Please sign in to comment.