Skip to content

Commit

Permalink
Merge pull request #4 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Jul 25, 2019
2 parents 99ed461 + 4e54ae1 commit 294f1e2
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 117 deletions.
83 changes: 40 additions & 43 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,64 @@ language: php
php:
- 7.0
- 7.1
- 7.2
sudo: required
dist: trusty
env:
global:
- COMPOSER_BIN_DIR=~/bin
- INTEGRATION_SETS=3
- NODE_JS_VERSION=6
- MAGENTO_HOST_NAME="magento2.travis"
- COMPOSER_MODULE=mageplaza/module-multi-flat-rates
- COMPOSER_BIN_DIR=~/bin
- INTEGRATION_SETS=3
- NODE_JS_VERSION=6
- MAGENTO_HOST_NAME="magento2.travis"
- COMPOSER_MODULE=mageplaza/module-multi-flat-rates
matrix:
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.2 TEST_SUITE=static
- MAGENTO_VERSION=2.2.2 TEST_SUITE=js GRUNT_COMMAND=static
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.5 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.5 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.5 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.6 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.6 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.6 TEST_SUITE=integration INTEGRATION_INDEX=3

- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.2 TEST_SUITE=static
- MAGENTO_VERSION=2.2.2 TEST_SUITE=js GRUNT_COMMAND=static
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=3

matrix:
exclude:
- php: 7.0
env: MAGENTO_VERSION=2.2.2 TEST_SUITE=js GRUNT_COMMAND=static
- php: 7.0
env: MAGENTO_VERSION=2.2.2 TEST_SUITE=static
- php: 7.0
env: MAGENTO_VERSION=2.2.2 TEST_SUITE=js GRUNT_COMMAND=static
- php: 7.0
env: MAGENTO_VERSION=2.2.2 TEST_SUITE=static
cache:
apt: true
directories:
- "$HOME/.composer/cache"
- "$HOME/.nvm"
- "$HOME/.composer/cache"
- "$HOME/.nvm"
addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6
- postfix
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6
- postfix
firefox: '46.0'
hosts:
- magento2.travis
before_install:
- git clone https://github.com/magento/magento2 --branch $MAGENTO_VERSION
- cd magento2
- bash ./dev/travis/before_install.sh
- git clone https://github.com/magento/magento2 --branch $MAGENTO_VERSION
- cd magento2
- bash ./dev/travis/before_install.sh
install:
- composer install --no-interaction --prefer-dist
- composer require $COMPOSER_MODULE
- composer install --no-interaction --prefer-dist
- composer require $COMPOSER_MODULE
before_script:
#- cp -f ${TRAVIS_BUILD_DIR}/dev/tests/integration/phpunit.xml.dist dev/tests/integration/
- echo "vendor/$COMPOSER_MODULE" > dev/tests/static/testsuite/Magento/Test/Less/_files/whitelist/common.txt
- echo "vendor/$COMPOSER_MODULE" > dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/common.txt
- echo "vendor/$COMPOSER_MODULE/**/*.js" > dev/tests/static/testsuite/Magento/Test/Js/_files/whitelist/magento.txt
- bash ./dev/travis/before_script.sh
#- cp -f ${TRAVIS_BUILD_DIR}/dev/tests/integration/phpunit.xml.dist dev/tests/integration/
- echo "vendor/$COMPOSER_MODULE" > dev/tests/static/testsuite/Magento/Test/Less/_files/whitelist/common.txt
- echo "vendor/$COMPOSER_MODULE" > dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/common.txt
- echo "vendor/$COMPOSER_MODULE/**/*.js" > dev/tests/static/testsuite/Magento/Test/Js/_files/whitelist/magento.txt
- bash ./dev/travis/before_script.sh
script:
- test $TEST_SUITE = "static" && TEST_FILTER='--filter "Magento\\Test\\Php\\LiveCodeTest"' || true
- test $TEST_SUITE = "functional" && TEST_FILTER='dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests.php' || true

- test $TEST_SUITE = "static" && TEST_FILTER='--filter "Magento\\Test\\Php\\LiveCodeTest"' || true
- test $TEST_SUITE = "functional" && TEST_FILTER='dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests.php' || true
- if [ $TEST_SUITE == "functional" ]; then dev/tests/functional/vendor/phpunit/phpunit/phpunit -c dev/tests/$TEST_SUITE $TEST_FILTER; fi
- if [ $TEST_SUITE != "functional" ] && [ $TEST_SUITE != "js" ]; then phpunit -c dev/tests/$TEST_SUITE $TEST_FILTER; fi
- if [ $TEST_SUITE == "js" ]; then grunt $GRUNT_COMMAND; fi

2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CHANGELOG: https://www.mageplaza.com/changelog/m2-multi-flat-rates.txt
CHANGELOG: https://www.mageplaza.com/releases/multi-flat-rates
74 changes: 70 additions & 4 deletions Model/Carrier/AbstractCarrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@

namespace Mageplaza\Multiflatrates\Model\Carrier;

use Magento\Backend\Model\Session\Quote;
use Magento\Framework\App\Area;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\State;
use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Model\Quote\Address\RateRequest;
use Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory;
use Magento\Quote\Model\Quote\Address\RateResult\MethodFactory;
use Magento\Shipping\Model\Carrier\CarrierInterface;
use Magento\Shipping\Model\Rate\ResultFactory;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -50,13 +57,38 @@ class AbstractCarrier extends \Magento\Shipping\Model\Carrier\AbstractCarrier im
*/
protected $_rateMethodFactory;

/**
* @var StoreManagerInterface
*/
protected $storeManager;

/**
* @var RequestInterface
*/
private $request;

/**
* @var Quote
*/
protected $quote;

/**
* Magento\Framework\App\State
*/
protected $state;

/**
* AbstractCarrier constructor.
*
* @param ScopeConfigInterface $scopeConfig
* @param ErrorFactory $rateErrorFactory
* @param LoggerInterface $logger
* @param ResultFactory $rateResultFactory
* @param MethodFactory $rateMethodFactory
* @param StoreManagerInterface $storeManager
* @param RequestInterface $request
* @param Quote $quote
* @param State $state
* @param array $data
*/
public function __construct(
Expand All @@ -65,11 +97,18 @@ public function __construct(
LoggerInterface $logger,
ResultFactory $rateResultFactory,
MethodFactory $rateMethodFactory,
StoreManagerInterface $storeManager,
RequestInterface $request,
Quote $quote,
State $state,
array $data = []
)
{
) {
$this->_rateResultFactory = $rateResultFactory;
$this->_rateMethodFactory = $rateMethodFactory;
$this->storeManager = $storeManager;
$this->request = $request;
$this->quote = $quote;
$this->state = $state;

parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);
}
Expand All @@ -79,21 +118,28 @@ public function __construct(
*/
public function collectRates(RateRequest $request)
{
$this->setStore($this->getScopeId());
if (!$this->getConfigFlag('active')) {
return false;
}

$shippingPrice = $this->getConfigData('price');
if ($postCode = $this->getConfigFlag('postcode')) {
$zipcodes = explode(';', $postCode);
if (!in_array($request->getDestPostcode(), $zipcodes)) {
return false;
}
}

$result = $this->_rateResultFactory->create();

$shippingPrice = $this->getConfigData('price');
if ($shippingPrice !== false) {
$method = $this->_rateMethodFactory->create();

$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));

$method->setMethod($this->_code);
$method->setMethod('flatrate');
$method->setMethodTitle($this->getConfigData('name'));

if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
Expand All @@ -118,4 +164,24 @@ public function getAllowedMethods()
{
return ['flatrate' => $this->getConfigData('name')];
}

/**
* @return int
* @throws LocalizedException
*/
protected function getScopeId()
{
if ($this->state->getAreaCode() === Area::AREA_ADMINHTML) {
$storeId = $this->quote->getStoreId();
} else {
$storeId = $this->storeManager->getStore()->getId();
}

$scope = $this->request->getParam(ScopeInterface::SCOPE_STORE) ?: $storeId;
if ($website = $this->request->getParam(ScopeInterface::SCOPE_WEBSITE)) {
$scope = $this->storeManager->getWebsite($website)->getDefaultStore()->getId();
}

return $scope;
}
}
2 changes: 1 addition & 1 deletion USER-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- Product Page: https://www.mageplaza.com/magento-2-multi-flat-rates/
- Get Support: https://github.com/mageplaza/magento-2-multi-flat-rates/issues
- Contribute on Github: https://github.com/mageplaza/magento-2-multi-flat-rates
- Changelog: https://www.mageplaza.com/changelog/m2-multi-flat-rates.txt
- Changelog: https://www.mageplaza.com/releases/multi-flat-rates

## 2. How to install

Expand Down
Binary file modified UserGuide.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mageplaza/module-multi-flat-rates",
"description": "Magento 2 Multi Flat Rates extension",
"type": "magento2-module",
"version": "1.0.0",
"version": "1.1.0",
"license": "proprietary",
"authors": [
{
Expand Down
15 changes: 15 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<can_be_empty>1</can_be_empty>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="postcode" translate="label comment" type="text" sortOrder="75" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Ship to Specific Zipcodes</label>
</field>
<field id="showmethod" translate="label" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Show Method if Not Applicable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down Expand Up @@ -90,6 +93,9 @@
<can_be_empty>1</can_be_empty>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="postcode" translate="label comment" type="text" sortOrder="75" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Ship to Specific Zipcodes</label>
</field>
<field id="showmethod" translate="label" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Show Method if Not Applicable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down Expand Up @@ -128,6 +134,9 @@
<can_be_empty>1</can_be_empty>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="postcode" translate="label comment" type="text" sortOrder="75" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Ship to Specific Zipcodes</label>
</field>
<field id="showmethod" translate="label" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Show Method if Not Applicable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down Expand Up @@ -166,6 +175,9 @@
<can_be_empty>1</can_be_empty>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="postcode" translate="label comment" type="text" sortOrder="75" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Ship to Specific Zipcodes</label>
</field>
<field id="showmethod" translate="label" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Show Method if Not Applicable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down Expand Up @@ -204,6 +216,9 @@
<can_be_empty>1</can_be_empty>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="postcode" translate="label comment" type="text" sortOrder="75" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Ship to Specific Zipcodes</label>
</field>
<field id="showmethod" translate="label" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Show Method if Not Applicable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
6 changes: 4 additions & 2 deletions registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
* @license https://www.mageplaza.com/LICENSE.txt
*/

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Mageplaza_Multiflatrates',
__DIR__
);
65 changes: 0 additions & 65 deletions travis.yml

This file was deleted.

0 comments on commit 294f1e2

Please sign in to comment.