diff --git a/.travis.yml b/.travis.yml index 4b62d4c..aff7089 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGELOG b/CHANGELOG index 24eb6bb..b8773a0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1 +1 @@ -CHANGELOG: https://www.mageplaza.com/changelog/m2-multi-flat-rates.txt \ No newline at end of file +CHANGELOG: https://www.mageplaza.com/releases/multi-flat-rates diff --git a/Model/Carrier/AbstractCarrier.php b/Model/Carrier/AbstractCarrier.php index 86ef284..af95406 100644 --- a/Model/Carrier/AbstractCarrier.php +++ b/Model/Carrier/AbstractCarrier.php @@ -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; /** @@ -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( @@ -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); } @@ -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()) { @@ -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; + } } diff --git a/USER-GUIDE.md b/USER-GUIDE.md index b37dd31..ad0ffc5 100644 --- a/USER-GUIDE.md +++ b/USER-GUIDE.md @@ -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 diff --git a/UserGuide.pdf b/UserGuide.pdf index 0493e78..2778c53 100644 Binary files a/UserGuide.pdf and b/UserGuide.pdf differ diff --git a/composer.json b/composer.json index a17a91a..df1d5da 100644 --- a/composer.json +++ b/composer.json @@ -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": [ { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 97c5a9e..c6bddd2 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -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> @@ -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> @@ -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> @@ -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> @@ -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> diff --git a/registration.php b/registration.php index e7575a5..6853918 100644 --- a/registration.php +++ b/registration.php @@ -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__ ); diff --git a/travis.yml b/travis.yml deleted file mode 100644 index 5485066..0000000 --- a/travis.yml +++ /dev/null @@ -1,65 +0,0 @@ -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 - 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 - -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 -cache: - apt: true - directories: - - "$HOME/.composer/cache" - - "$HOME/.nvm" -addons: - apt: - packages: - - 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 -install: -- 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 -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 -- 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 -