diff --git a/.travis.yml b/.travis.yml index aff7089..50ff74e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,65 +1,65 @@ -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 - +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 + diff --git a/LICENSE b/LICENSE index fa08b4a..704c055 100644 --- a/LICENSE +++ b/LICENSE @@ -1,33 +1,33 @@ -Copyright (c) 2016-present Mageplaza Co. Ltd. - -This License is entered by Mageplaza to govern the usage or redistribution of Mageplaza software. This is a legal agreement between you (either an individual or a single entity) and Mageplaza for Mageplaza software product(s) which may include extensions, templates and services. - -By purchasing, installing, or otherwise using Mageplaza products, you acknowledge that you have read this License and agree to be bound by the terms of this Agreement. If you do not agree to the terms of this License, do not install or use Mageplaza products. - -The Agreement becomes effective at the moment when you acquire software from our site or receive it through email or on data medium or by any other means. Mageplaza reserves the right to make reasonable changes to the terms of this license agreement and impose its clauses at any given time. - - 1. GRANT OF LICENSE: By purchasing a product of Mageplaza: - - 1. Customer will receive source code open 100%. - - 2. Customer will obtain a License Certificate which will remain valid until the Customer stops using the Product or until Mageplaza terminates this License because of Customer’s failure to comply with any of its Terms and Conditions. Each License Certificate includes a license serial which is valid for one live Magento installation only and unlimited test Magento installations. - - 3. You are allowed to customize our products to fit with your using purpose. - - 4. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS - - 5. Installation and Use - - 6. For each new Software installation, you are obliged to purchase a separate License. You are not permitted to use any part of the code in whole or part in any other software or product or website. You are legally bound to preserve the copyright information intact including the text/link at bottom. - - 2. Distribution: You are not allowed to distribute Mageplaza software to third parties. Any distribution without our permission, including non commercial distribution is considered as violation of this Agreement and entails liability, according to the current law. You may not place the Software onto a server that allows access to the Software via a public network or the Internet for distribution purposes. - - 3. Rental: You may not give, sell, sub-license, rent, lease or lend any portion of the Software to anyone. - - 4. Compliance with Applicable Laws: You must comply with all applicable laws regarding use of software products. Mageplaza software and a portion of it are protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. Accordingly, customer is required to treat the software like any other copyrighted material. Any activity violating copyright law will be prosecuted according to the current law. We retain the right to revoke the license of any user holding an invalid license. - - 5. TERMINATION: Without prejudice to any other rights, Mageplaza may terminate this License at any time if you fail to comply with the terms and conditions of this License. In such event, it constitutes a breach of the agreement, and your license to use the program is revoked and you must destroy all copies of Mageplaza products in your possession. After being notified of termination of your license, if you continue to use Mageplaza software, you hereby agree to accept an injunction to prevent you from its further use and to pay all costs (including but not limited to reasonable attorney fees) to enforce our revocation of your license and any damages suffered by us because of your misuse of the Software. We are not bound to return you the amount spent for purchase of the Software for the termination of this License. - - 6. LIMITATION OF LIABILITY: In no event shall Mageplaza be liable for any damages (including, without limitation, lost profits, business interruption, or lost information) rising out of ‘Authorized Users’ use of or inability to use the Mageplaza products, even if Mageplaza has been advised of the possibility of such damages. In no event will Mageplaza be liable for prosecution arising from use of the Software against law or for any illegal use. - +Copyright (c) 2016-present Mageplaza Co. Ltd. + +This License is entered by Mageplaza to govern the usage or redistribution of Mageplaza software. This is a legal agreement between you (either an individual or a single entity) and Mageplaza for Mageplaza software product(s) which may include extensions, templates and services. + +By purchasing, installing, or otherwise using Mageplaza products, you acknowledge that you have read this License and agree to be bound by the terms of this Agreement. If you do not agree to the terms of this License, do not install or use Mageplaza products. + +The Agreement becomes effective at the moment when you acquire software from our site or receive it through email or on data medium or by any other means. Mageplaza reserves the right to make reasonable changes to the terms of this license agreement and impose its clauses at any given time. + + 1. GRANT OF LICENSE: By purchasing a product of Mageplaza: + + 1. Customer will receive source code open 100%. + + 2. Customer will obtain a License Certificate which will remain valid until the Customer stops using the Product or until Mageplaza terminates this License because of Customer’s failure to comply with any of its Terms and Conditions. Each License Certificate includes a license serial which is valid for one live Magento installation only and unlimited test Magento installations. + + 3. You are allowed to customize our products to fit with your using purpose. + + 4. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS + + 5. Installation and Use + + 6. For each new Software installation, you are obliged to purchase a separate License. You are not permitted to use any part of the code in whole or part in any other software or product or website. You are legally bound to preserve the copyright information intact including the text/link at bottom. + + 2. Distribution: You are not allowed to distribute Mageplaza software to third parties. Any distribution without our permission, including non commercial distribution is considered as violation of this Agreement and entails liability, according to the current law. You may not place the Software onto a server that allows access to the Software via a public network or the Internet for distribution purposes. + + 3. Rental: You may not give, sell, sub-license, rent, lease or lend any portion of the Software to anyone. + + 4. Compliance with Applicable Laws: You must comply with all applicable laws regarding use of software products. Mageplaza software and a portion of it are protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. Accordingly, customer is required to treat the software like any other copyrighted material. Any activity violating copyright law will be prosecuted according to the current law. We retain the right to revoke the license of any user holding an invalid license. + + 5. TERMINATION: Without prejudice to any other rights, Mageplaza may terminate this License at any time if you fail to comply with the terms and conditions of this License. In such event, it constitutes a breach of the agreement, and your license to use the program is revoked and you must destroy all copies of Mageplaza products in your possession. After being notified of termination of your license, if you continue to use Mageplaza software, you hereby agree to accept an injunction to prevent you from its further use and to pay all costs (including but not limited to reasonable attorney fees) to enforce our revocation of your license and any damages suffered by us because of your misuse of the Software. We are not bound to return you the amount spent for purchase of the Software for the termination of this License. + + 6. LIMITATION OF LIABILITY: In no event shall Mageplaza be liable for any damages (including, without limitation, lost profits, business interruption, or lost information) rising out of ‘Authorized Users’ use of or inability to use the Mageplaza products, even if Mageplaza has been advised of the possibility of such damages. In no event will Mageplaza be liable for prosecution arising from use of the Software against law or for any illegal use. + The latest License: https://www.mageplaza.com/LICENSE.txt \ No newline at end of file diff --git a/Model/Carrier/AbstractCarrier.php b/Model/Carrier/AbstractCarrier.php index af95406..8425c98 100644 --- a/Model/Carrier/AbstractCarrier.php +++ b/Model/Carrier/AbstractCarrier.php @@ -28,11 +28,13 @@ use Magento\Framework\App\State; use Magento\Framework\Exception\LocalizedException; use Magento\Quote\Model\Quote\Address\RateRequest; +use Magento\Quote\Model\Quote\Address\RateResult\Error; 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\Store; use Magento\Store\Model\StoreManagerInterface; use Psr\Log\LoggerInterface; @@ -105,10 +107,10 @@ public function __construct( ) { $this->_rateResultFactory = $rateResultFactory; $this->_rateMethodFactory = $rateMethodFactory; - $this->storeManager = $storeManager; - $this->request = $request; - $this->quote = $quote; - $this->state = $state; + $this->storeManager = $storeManager; + $this->request = $request; + $this->quote = $quote; + $this->state = $state; parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data); } @@ -118,41 +120,35 @@ public function __construct( */ public function collectRates(RateRequest $request) { - $this->setStore($this->getScopeId()); + try { + $this->setData('store', $this->getScopeId()); + } catch (LocalizedException $e) { + return $this->showErrorResult($e->getMessage()); + } + if (!$this->getConfigFlag('active')) { return false; } - if ($postCode = $this->getConfigFlag('postcode')) { - $zipcodes = explode(';', $postCode); - if (!in_array($request->getDestPostcode(), $zipcodes)) { - return false; + if ($postCode = $this->getConfigData('postcode')) { + $zipCodes = array_map('trim', explode(';', $postCode)); + if (!in_array($request->getDestPostcode(), $zipCodes, true)) { + return $this->showErrorResult(); } } $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('flatrate'); - $method->setMethodTitle($this->getConfigData('name')); - - if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) { - $shippingPrice = '0.00'; - } - - $method->setPrice($shippingPrice); - $method->setCost($shippingPrice); - - $result->append($method); - } - - return $result; + $price = $request->getFreeShipping() ? 0 : (float) $this->getConfigData('price'); + $method = $this->_rateMethodFactory->create()->setData([ + 'carrier' => $this->_code, + 'carrier_title' => $this->getConfigData('title'), + 'method' => 'flatrate', + 'method_title' => $this->getConfigData('name'), + 'price' => $price, + 'cost' => $price, + ]); + + return $result->append($method); } /** @@ -165,6 +161,24 @@ public function getAllowedMethods() return ['flatrate' => $this->getConfigData('name')]; } + /** + * @param string|null $errorMsg + * + * @return bool|Error + */ + private function showErrorResult($errorMsg = null) + { + if (!$this->getConfigData('showmethod')) { + return false; + } + + return $this->_rateErrorFactory->create()->setData([ + 'carrier' => $this->_code, + 'carrier_title' => $this->getConfigData('title'), + 'error_message' => $errorMsg ?: $this->getConfigData('specificerrmsg'), + ]); + } + /** * @return int * @throws LocalizedException @@ -179,7 +193,11 @@ protected function getScopeId() $scope = $this->request->getParam(ScopeInterface::SCOPE_STORE) ?: $storeId; if ($website = $this->request->getParam(ScopeInterface::SCOPE_WEBSITE)) { - $scope = $this->storeManager->getWebsite($website)->getDefaultStore()->getId(); + /** @var Store $store */ + $store = $this->storeManager->getWebsite($website)->getDefaultStore(); + if ($store) { + return $store->getId(); + } } return $scope; diff --git a/README.md b/README.md index f2938ff..8e9390c 100644 --- a/README.md +++ b/README.md @@ -1,124 +1,124 @@ -# Magento 2 Multiple Flat Rates Shipping extension - -Native Magento 2 only supports **one flat rate shipping** which can lead to difficulty for stores in defining the best price for delivering products to customers in different countries. - -[Magento 2 Multiple flat rate shipping](https://www.mageplaza.com/magento-2-multi-flat-rates/) is a must have for many online stores, especially international brands which deliver their products worldwide. Offering buyers different flat rates to select makes shopping easier and convenient for customers. Besides, this also helps stores manage shipping methods better. - -[![Latest Stable Version](https://poser.pugx.org/mageplaza/module-multi-flat-rates/v/stable)](https://packagist.org/packages/mageplaza/module-multi-flat-rates) -[![Total Downloads](https://poser.pugx.org/mageplaza/module-multi-flat-rates/downloads)](https://packagist.org/packages/mageplaza/module-multi-flat-rates) - - -## 1. Flat Rates Shipping Documentation - -- [Installation guide](https://www.mageplaza.com/install-magento-2-extension/) -- [User guide](https://docs.mageplaza.com/multi-flat-rates/index.html) -- [Contribute on Github](https://github.com/mageplaza/magento-2-multi-flat-rates/) -- [Get Support](https://github.com/mageplaza/magento-2-multi-flat-rates/issues) - -## 2. FAQs - -- **Q: I got an error: Mageplaza_Core has been already defined** - -- A: Read solution: https://github.com/mageplaza/module-core/issues/3 - -## 3. How to install Magento 2 Multi Flat Rates Shipping extension - -### Install via composer (recommend) - -Run the following command in Magento 2 root folder: - -``` -composer require mageplaza/module-multi-flat-rates -php bin/magento setup:upgrade -php bin/magento setup:static-content:deploy -``` -## 4. Multiple Flat Rates Shipping features - -### 5 multiple flat rate shipping - -**Magento 2 Multi flat rate shipping extension** allows store admins to add up to 5 other shipping rates. Admins are free to give a shipping flat rate a name and/or a title to help buyers distinguish it with others on Cart page and Checkout page. - -Each flat rate can be turned on/off easily on the backend. A set of configuration options for price, sort order, applicable countries, and error message are also ready to be selected. - -### Sort multi flat rates neatly - -As a store may want to have more than only one flat rate shipping, **Multiple Flat Rates Shipping** should be in a certain order. Admins can choose this order by sorting every shipping rate on the backend. - -### Multi flat rate visibility - -**Each flat rate shipping** can be applied on a restricted number of countries or all allowed countries depending on the settings on backend. - -Admins can multiple select countries to allow buyers in those countries to choose a specific shipping flat rate. - -### Error message - -Buyers who are not in applicable countries will not be allowed to select that shipping flat rate. In this case, admins can set an error message to inform buyers. This message can be enabled/disabled and changed easily on the backend. - -### Compatible with One Step Checkout - -**Magento 2 Multi Flat Rates Shipping extension** is amazingly compatible with [Mageplaza One Step Checkout](https://www.mageplaza.com/magento-2-one-step-checkout-extension/) which delivers the best shopping experience for your customers. - - -## 5. How to configure multiple flat rate shipping on Magento 2 - -From your Magento admin panel, follow this route: `Stores > Settings > Configuration > Sales > Shipping methods`. Then, click on `Flat rate #1 - Flat rate #5` to configure these 5 shipping rates. - -![Magento 2 Multiple Flat Rates Shipping](https://i.imgur.com/yiEzfE6.png) - -### Configure flat rate shipping #1 - -![Magento 2 Multiple Flat Rates Shipping module](https://i.imgur.com/s3kpRye.png) - -- **Enable**: Select Yes to run Flat Rate #1 -- **Method Name**: This is the name the flat rate #1 that is displayed on the View cart page and the Checkout page. If you leave this field blank, the rate will have no name on these two pages. -- **Price**: This is the shipping fee of Flat Rate #1 which is displayed on the frontend. If you leave this field blank, the price will be automatically set $0.00 as default. -- **Sort Order**: This is the order of Flat Rate #1 on the flat rates list displayed on the frontend. For example: If Sort Order = 1 is set for Flat Rate #1 while Sort Order = 2 is set for Flat Rate #2, Flat Rate #1 will stand above Flat Rate #2 on the frontend. - -![Magento 2 Multiple Flat Rates Shipping extension](https://i.imgur.com/sgrBrOz.png) - - -- **Title**: This is the title of the flat rate which is displayed on the Cart page and Checkout page. If you leave this field blank, no title is displayed. - -![Configure Multiple Flat Rates Shipping for Magento 2](https://i.imgur.com/bIfptAy.png) - - -- `Ship to Applicable Countries`: - - Select All Allowed Countries to apply the rate on all available countries. - - Select Specific Countries to apply the rate on the countries which are selected on the field Ship to Specific Countries. - -![Configure Magento 2 Multiple Flat Rates Shipping](https://i.imgur.com/GWOQSeW.png) - -- `Ship to Specific Countries`: Select one or several countries which the rate is applied for. -- `Display Error Message`: Enter an error message which is displayed to buyers when the rate is not available. If you leave this box blank, the default message will be displayed: `Sorry, but we can’t deliver to the destination country with this shipping module`. This error message is displayed only when `Show Method if Not Applicable` = Yes -- `Show Method if Not Applicable`: Select Yes to display all shipping methods even when they do not belong to any applicable countries. - -Similarly, admins can add up to 5 shipping methods and configure them for their online store. - -![Mageplaza Multiple Flat Rates Shipping](https://i.imgur.com/JvvkKHF.png) - -![Magento 2 Multi Flat Rates Shipping](https://i.imgur.com/bniI7zg.png) - - -**People alse search:** -- magento 2 multiple flat rate shipping -- magento 2 flat rate shipping -- flat rate magento 2 -- magento 2 multiple shipping methods -- magento 2 multiple flat rate shipping free -- magento 2 shipping rates per product extension -- magento 2 shipping per product per country extension -- magento 2 product shipping rates per country extension - - -**Other free extension on Github** -- [Magento 2 Same Order Number](https://github.com/mageplaza/magento-2-same-order-number) -- [Magento 2 Google Maps](https://github.com/mageplaza/magento-2-google-maps) -- [Magento 2 popup extension](https://github.com/mageplaza/magento-2-better-popup) -- [Magento 2 Reports extension](https://github.com/mageplaza/magento-2-reports) -- [Magento 2 seo extension](https://github.com/mageplaza/magento-2-seo) -- [Magento 2 blog](https://github.com/mageplaza/magento-2-blog) -- [Magento 2 Layered Navigation](https://github.com/mageplaza/magento-2-ajax-layered-navigation) -- [Magento 2 security extension](https://github.com/mageplaza/magento-2-security) - - - +# Magento 2 Multiple Flat Rates Shipping extension + +Native Magento 2 only supports **one flat rate shipping** which can lead to difficulty for stores in defining the best price for delivering products to customers in different countries. + +[Magento 2 Multiple flat rate shipping](https://www.mageplaza.com/magento-2-multi-flat-rates/) is a must have for many online stores, especially international brands which deliver their products worldwide. Offering buyers different flat rates to select makes shopping easier and convenient for customers. Besides, this also helps stores manage shipping methods better. + +[![Latest Stable Version](https://poser.pugx.org/mageplaza/module-multi-flat-rates/v/stable)](https://packagist.org/packages/mageplaza/module-multi-flat-rates) +[![Total Downloads](https://poser.pugx.org/mageplaza/module-multi-flat-rates/downloads)](https://packagist.org/packages/mageplaza/module-multi-flat-rates) + + +## 1. Flat Rates Shipping Documentation + +- [Installation guide](https://www.mageplaza.com/install-magento-2-extension/) +- [User guide](https://docs.mageplaza.com/multi-flat-rates/index.html) +- [Contribute on Github](https://github.com/mageplaza/magento-2-multi-flat-rates/) +- [Get Support](https://github.com/mageplaza/magento-2-multi-flat-rates/issues) + +## 2. FAQs + +- **Q: I got an error: Mageplaza_Core has been already defined** + +- A: Read solution: https://github.com/mageplaza/module-core/issues/3 + +## 3. How to install Magento 2 Multi Flat Rates Shipping extension + +### Install via composer (recommend) + +Run the following command in Magento 2 root folder: + +``` +composer require mageplaza/module-multi-flat-rates +php bin/magento setup:upgrade +php bin/magento setup:static-content:deploy +``` +## 4. Multiple Flat Rates Shipping features + +### 5 multiple flat rate shipping + +**Magento 2 Multi flat rate shipping extension** allows store admins to add up to 5 other shipping rates. Admins are free to give a shipping flat rate a name and/or a title to help buyers distinguish it with others on Cart page and Checkout page. + +Each flat rate can be turned on/off easily on the backend. A set of configuration options for price, sort order, applicable countries, and error message are also ready to be selected. + +### Sort multi flat rates neatly + +As a store may want to have more than only one flat rate shipping, **Multiple Flat Rates Shipping** should be in a certain order. Admins can choose this order by sorting every shipping rate on the backend. + +### Multi flat rate visibility + +**Each flat rate shipping** can be applied on a restricted number of countries or all allowed countries depending on the settings on backend. + +Admins can multiple select countries to allow buyers in those countries to choose a specific shipping flat rate. + +### Error message + +Buyers who are not in applicable countries will not be allowed to select that shipping flat rate. In this case, admins can set an error message to inform buyers. This message can be enabled/disabled and changed easily on the backend. + +### Compatible with One Step Checkout + +**Magento 2 Multi Flat Rates Shipping extension** is amazingly compatible with [Mageplaza One Step Checkout](https://www.mageplaza.com/magento-2-one-step-checkout-extension/) which delivers the best shopping experience for your customers. + + +## 5. How to configure multiple flat rate shipping on Magento 2 + +From your Magento admin panel, follow this route: `Stores > Settings > Configuration > Sales > Shipping methods`. Then, click on `Flat rate #1 - Flat rate #5` to configure these 5 shipping rates. + +![Magento 2 Multiple Flat Rates Shipping](https://i.imgur.com/yiEzfE6.png) + +### Configure flat rate shipping #1 + +![Magento 2 Multiple Flat Rates Shipping module](https://i.imgur.com/s3kpRye.png) + +- **Enable**: Select Yes to run Flat Rate #1 +- **Method Name**: This is the name the flat rate #1 that is displayed on the View cart page and the Checkout page. If you leave this field blank, the rate will have no name on these two pages. +- **Price**: This is the shipping fee of Flat Rate #1 which is displayed on the frontend. If you leave this field blank, the price will be automatically set $0.00 as default. +- **Sort Order**: This is the order of Flat Rate #1 on the flat rates list displayed on the frontend. For example: If Sort Order = 1 is set for Flat Rate #1 while Sort Order = 2 is set for Flat Rate #2, Flat Rate #1 will stand above Flat Rate #2 on the frontend. + +![Magento 2 Multiple Flat Rates Shipping extension](https://i.imgur.com/sgrBrOz.png) + + +- **Title**: This is the title of the flat rate which is displayed on the Cart page and Checkout page. If you leave this field blank, no title is displayed. + +![Configure Multiple Flat Rates Shipping for Magento 2](https://i.imgur.com/bIfptAy.png) + + +- `Ship to Applicable Countries`: + - Select All Allowed Countries to apply the rate on all available countries. + - Select Specific Countries to apply the rate on the countries which are selected on the field Ship to Specific Countries. + +![Configure Magento 2 Multiple Flat Rates Shipping](https://i.imgur.com/GWOQSeW.png) + +- `Ship to Specific Countries`: Select one or several countries which the rate is applied for. +- `Display Error Message`: Enter an error message which is displayed to buyers when the rate is not available. If you leave this box blank, the default message will be displayed: `Sorry, but we can’t deliver to the destination country with this shipping module`. This error message is displayed only when `Show Method if Not Applicable` = Yes +- `Show Method if Not Applicable`: Select Yes to display all shipping methods even when they do not belong to any applicable countries. + +Similarly, admins can add up to 5 shipping methods and configure them for their online store. + +![Mageplaza Multiple Flat Rates Shipping](https://i.imgur.com/JvvkKHF.png) + +![Magento 2 Multi Flat Rates Shipping](https://i.imgur.com/bniI7zg.png) + + +**People alse search:** +- magento 2 multiple flat rate shipping +- magento 2 flat rate shipping +- flat rate magento 2 +- magento 2 multiple shipping methods +- magento 2 multiple flat rate shipping free +- magento 2 shipping rates per product extension +- magento 2 shipping per product per country extension +- magento 2 product shipping rates per country extension + + +**Other free extension on Github** +- [Magento 2 Same Order Number](https://github.com/mageplaza/magento-2-same-order-number) +- [Magento 2 Google Maps](https://github.com/mageplaza/magento-2-google-maps) +- [Magento 2 popup extension](https://github.com/mageplaza/magento-2-better-popup) +- [Magento 2 Reports extension](https://github.com/mageplaza/magento-2-reports) +- [Magento 2 seo extension](https://github.com/mageplaza/magento-2-seo) +- [Magento 2 blog](https://github.com/mageplaza/magento-2-blog) +- [Magento 2 Layered Navigation](https://github.com/mageplaza/magento-2-ajax-layered-navigation) +- [Magento 2 security extension](https://github.com/mageplaza/magento-2-security) + + + diff --git a/USER-GUIDE.md b/USER-GUIDE.md index ad0ffc5..3e8bbf5 100644 --- a/USER-GUIDE.md +++ b/USER-GUIDE.md @@ -1,39 +1,39 @@ -## 1. Documentation -- User Guide: https://docs.mageplaza.com/multi-flat-rates/index.html -- 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/releases/multi-flat-rates - -## 2. How to install - -### ✓ Install via composer (recommend) - -Run the following command in Magento 2 root folder: - -``` -composer require mageplaza/module-multi-flat-rates -php bin/magento setup:upgrade -php bin/magento setup:static-content:deploy -``` - - -## 3. FAQs - -#### Q: When I click on Login link, the popup does't work -A: You can read https://github.com/mageplaza/magento-2-social-login/issues/39 - -#### Q: I am using custom theme, it is compatible with our design? -A: We have developed Social Login based on Magento coding standard and best practice test on Magento Community and Magento Enterpise site. So it is compatible with themes and custom designs. Ask Magento community on http://magento.stackexchange.com/ or https://github.com/mageplaza/magento-2-social-login/issues/ - -#### Q: Can I install it by myself? -A: Yes, you absolutely can! You can install it like installing any extensions to website, follow our Installation Guide http://docs.mageplaza.com/kb/installation.html. User guide: https://docs.mageplaza.com/social-login-m2/index.html - -#### Q: I got this message `Erro: invalid_scope` -A: Read this https://github.com/mageplaza/magento-2-social-login/issues/42 - -#### Q: I got error: `Mageplaza_Core has been already defined` -A: Read solution: https://github.com/mageplaza/module-core/issues/3 - -#### Q: My site is down -A: Please follow this guide: https://www.mageplaza.com/blog/magento-site-down.html +## 1. Documentation +- User Guide: https://docs.mageplaza.com/multi-flat-rates/index.html +- 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/releases/multi-flat-rates + +## 2. How to install + +### ✓ Install via composer (recommend) + +Run the following command in Magento 2 root folder: + +``` +composer require mageplaza/module-multi-flat-rates +php bin/magento setup:upgrade +php bin/magento setup:static-content:deploy +``` + + +## 3. FAQs + +#### Q: When I click on Login link, the popup does't work +A: You can read https://github.com/mageplaza/magento-2-social-login/issues/39 + +#### Q: I am using custom theme, it is compatible with our design? +A: We have developed Social Login based on Magento coding standard and best practice test on Magento Community and Magento Enterpise site. So it is compatible with themes and custom designs. Ask Magento community on http://magento.stackexchange.com/ or https://github.com/mageplaza/magento-2-social-login/issues/ + +#### Q: Can I install it by myself? +A: Yes, you absolutely can! You can install it like installing any extensions to website, follow our Installation Guide http://docs.mageplaza.com/kb/installation.html. User guide: https://docs.mageplaza.com/social-login-m2/index.html + +#### Q: I got this message `Erro: invalid_scope` +A: Read this https://github.com/mageplaza/magento-2-social-login/issues/42 + +#### Q: I got error: `Mageplaza_Core has been already defined` +A: Read solution: https://github.com/mageplaza/module-core/issues/3 + +#### Q: My site is down +A: Please follow this guide: https://www.mageplaza.com/blog/magento-site-down.html diff --git a/UserGuide.pdf b/UserGuide.pdf index 2778c53..e20c24f 100644 Binary files a/UserGuide.pdf and b/UserGuide.pdf differ diff --git a/composer.json b/composer.json index df1d5da..aef5314 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,23 @@ -{ - "name": "mageplaza/module-multi-flat-rates", - "description": "Magento 2 Multi Flat Rates extension", - "type": "magento2-module", - "version": "1.1.0", - "license": "proprietary", - "authors": [ - { - "name": "Mageplaza", - "email": "support@mageplaza.com", - "homepage": "https://www.mageplaza.com", - "role": "Technical Support" - } - ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Mageplaza\\Multiflatrates\\": "" - } - } +{ + "name": "mageplaza/module-multi-flat-rates", + "description": "Magento 2 Multi Flat Rates extension", + "type": "magento2-module", + "version": "1.1.1", + "license": "proprietary", + "authors": [ + { + "name": "Mageplaza", + "email": "support@mageplaza.com", + "homepage": "https://www.mageplaza.com", + "role": "Technical Support" + } + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Mageplaza\\Multiflatrates\\": "" + } + } } \ No newline at end of file diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c6bddd2..ff88ff7 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,233 +1,238 @@ - - - - -
- - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - - validate-number validate-zero-or-greater - - - - - - - - - - shipping-applicable-country - Magento\Shipping\Model\Config\Source\Allspecificcountries - - - - 1 - Magento\Directory\Model\Config\Source\Country - - - - - - - Magento\Config\Model\Config\Source\Yesno - shipping-skip-hide - - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - - validate-number validate-zero-or-greater - - - - - - - - - - shipping-applicable-country - Magento\Shipping\Model\Config\Source\Allspecificcountries - - - - 1 - Magento\Directory\Model\Config\Source\Country - - - - - - - Magento\Config\Model\Config\Source\Yesno - shipping-skip-hide - - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - - validate-number validate-zero-or-greater - - - - - - - - - - shipping-applicable-country - Magento\Shipping\Model\Config\Source\Allspecificcountries - - - - 1 - Magento\Directory\Model\Config\Source\Country - - - - - - - Magento\Config\Model\Config\Source\Yesno - shipping-skip-hide - - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - - validate-number validate-zero-or-greater - - - - - - - - - - shipping-applicable-country - Magento\Shipping\Model\Config\Source\Allspecificcountries - - - - 1 - Magento\Directory\Model\Config\Source\Country - - - - - - - Magento\Config\Model\Config\Source\Yesno - shipping-skip-hide - - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - - validate-number validate-zero-or-greater - - - - - - - - - - shipping-applicable-country - Magento\Shipping\Model\Config\Source\Allspecificcountries - - - - 1 - Magento\Directory\Model\Config\Source\Country - - - - - - - Magento\Config\Model\Config\Source\Yesno - shipping-skip-hide - - - - - -
-
-
+ + + + +
+ + + + + Magento\Config\Model\Config\Source\Yesno + + + + + + + validate-number validate-zero-or-greater + + + + + + + + + + shipping-applicable-country + Magento\Shipping\Model\Config\Source\Allspecificcountries + + + + 1 + Magento\Directory\Model\Config\Source\Country + + + + Separated by semicolons (;) + + + + Magento\Config\Model\Config\Source\Yesno + shipping-skip-hide + + + + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + + + + validate-number validate-zero-or-greater + + + + + + + + + + shipping-applicable-country + Magento\Shipping\Model\Config\Source\Allspecificcountries + + + + 1 + Magento\Directory\Model\Config\Source\Country + + + + Separated by semicolons (;) + + + + Magento\Config\Model\Config\Source\Yesno + shipping-skip-hide + + + + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + + + + validate-number validate-zero-or-greater + + + + + + + + + + shipping-applicable-country + Magento\Shipping\Model\Config\Source\Allspecificcountries + + + + 1 + Magento\Directory\Model\Config\Source\Country + + + + Separated by semicolons (;) + + + + Magento\Config\Model\Config\Source\Yesno + shipping-skip-hide + + + + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + + + + validate-number validate-zero-or-greater + + + + + + + + + + shipping-applicable-country + Magento\Shipping\Model\Config\Source\Allspecificcountries + + + + 1 + Magento\Directory\Model\Config\Source\Country + + + + Separated by semicolons (;) + + + + Magento\Config\Model\Config\Source\Yesno + shipping-skip-hide + + + + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + + + + validate-number validate-zero-or-greater + + + + + + + + + + shipping-applicable-country + Magento\Shipping\Model\Config\Source\Allspecificcountries + + + + 1 + Magento\Directory\Model\Config\Source\Country + + + + Separated by semicolons (;) + + + + Magento\Config\Model\Config\Source\Yesno + shipping-skip-hide + + + + + +
+
+
diff --git a/etc/config.xml b/etc/config.xml index 063fe4d..e8347af 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -1,73 +1,78 @@ - - - - - - - Mageplaza\Multiflatrates\Model\Carrier\Flatrateone - 0 - Flatrateone - Flatrateone - 0.00 - This shipping method is not available. To use this shipping method, please contact us. - 0 - - - Mageplaza\Multiflatrates\Model\Carrier\Flatratetwo - 0 - Flatratetwo - Flatratetwo - 0.00 - This shipping method is not available. To use this shipping method, please contact us. - 0 - - - Mageplaza\Multiflatrates\Model\Carrier\Flatratethree - 0 - Flatratethree - Flatratethree - 0.00 - This shipping method is not available. To use this shipping method, please contact us. - 0 - - - Mageplaza\Multiflatrates\Model\Carrier\Flatratefour - 0 - Flatratefour - Flatratefour - 0.00 - This shipping method is not available. To use this shipping method, please contact us. - 0 - - - Mageplaza\Multiflatrates\Model\Carrier\Flatratefive - 0 - Flatratefive - Flatratefive - 0.00 - This shipping method is not available. To use this shipping method, please contact us. - 0 - - - - + + + + + + + Mageplaza\Multiflatrates\Model\Carrier\Flatrateone + 0 + Flat Rate #1 + Flat Rate #1 + 0.00 + 0 + This shipping method is not available. To use this shipping method, please contact us. + 0 + + + Mageplaza\Multiflatrates\Model\Carrier\Flatratetwo + 0 + Flat Rate #2 + Flat Rate #2 + 0.00 + 0 + This shipping method is not available. To use this shipping method, please contact us. + 0 + + + Mageplaza\Multiflatrates\Model\Carrier\Flatratethree + 0 + Flat Rate #3 + Flat Rate #3 + 0.00 + 0 + This shipping method is not available. To use this shipping method, please contact us. + 0 + + + Mageplaza\Multiflatrates\Model\Carrier\Flatratefour + 0 + Flat Rate #4 + Flat Rate #4 + 0.00 + 0 + This shipping method is not available. To use this shipping method, please contact us. + 0 + + + Mageplaza\Multiflatrates\Model\Carrier\Flatratefive + 0 + Flat Rate #5 + Flat Rate #5 + 0.00 + 0 + This shipping method is not available. To use this shipping method, please contact us. + 0 + + + + diff --git a/etc/module.xml b/etc/module.xml index 056878c..3c22100 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,25 +1,25 @@ - - - - - + + + + + diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 70d6c04..828be7f 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -1,3 +1,5 @@ +"Field ","Field " +" is required."," is required." "Flat Rate #1","Flat Rate #1" Enabled,Enabled "Method Name","Method Name" @@ -6,6 +8,8 @@ Price,Price Title,Title "Ship to Applicable Countries","Ship to Applicable Countries" "Ship to Specific Countries","Ship to Specific Countries" +"Ship to Specific Zip/Postal Codes","Ship to Specific Zip/Postal Codes" +"Separated by semicolons (;)","Separated by semicolons (;)" "Show Method if Not Applicable","Show Method if Not Applicable" "Displayed Error Message","Displayed Error Message" "Flat Rate #2","Flat Rate #2" diff --git a/view/frontend/layout/checkout_cart_index.xml b/view/frontend/layout/checkout_cart_index.xml new file mode 100644 index 0000000..f67a163 --- /dev/null +++ b/view/frontend/layout/checkout_cart_index.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + Mageplaza_Multiflatrates/js/view/shipping-rates-validation + + + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml new file mode 100644 index 0000000..b11359c --- /dev/null +++ b/view/frontend/layout/checkout_index_index.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + Mageplaza_Multiflatrates/js/view/shipping-rates-validation + + + + + + + + + + + + + + + + + diff --git a/view/frontend/web/js/model/shipping-rates-validation-rules.js b/view/frontend/web/js/model/shipping-rates-validation-rules.js new file mode 100644 index 0000000..6fe6542 --- /dev/null +++ b/view/frontend/web/js/model/shipping-rates-validation-rules.js @@ -0,0 +1,39 @@ +/** + * Mageplaza + * + * NOTICE OF LICENSE + * + * This source file is subject to the Mageplaza.com license that is + * available through the world-wide-web at this URL: + * https://www.mageplaza.com/LICENSE.txt + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this extension to newer + * version in the future. + * + * @category Mageplaza + * @package Mageplaza_Multiflatrates + * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) + * @license https://www.mageplaza.com/LICENSE.txt + */ + +define([], function () { + 'use strict'; + + return { + /** + * @return {Object} + */ + getRules: function () { + return { + 'country_id': { + 'required': true + }, + 'postcode': { + 'required': false + } + }; + } + }; +}); diff --git a/view/frontend/web/js/model/shipping-rates-validator.js b/view/frontend/web/js/model/shipping-rates-validator.js new file mode 100644 index 0000000..8eaafce --- /dev/null +++ b/view/frontend/web/js/model/shipping-rates-validator.js @@ -0,0 +1,50 @@ +/** + * Mageplaza + * + * NOTICE OF LICENSE + * + * This source file is subject to the Mageplaza.com license that is + * available through the world-wide-web at this URL: + * https://www.mageplaza.com/LICENSE.txt + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this extension to newer + * version in the future. + * + * @category Mageplaza + * @package Mageplaza_Multiflatrates + * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) + * @license https://www.mageplaza.com/LICENSE.txt + */ + +define([ + 'jquery', + 'mageUtils', + '../model/shipping-rates-validation-rules', + 'mage/translate' +], function ($, utils, validationRules, $t) { + 'use strict'; + + return { + validationErrors: [], + + /** + * @param {Object} address + * @return {Boolean} + */ + validate: function (address) { + var self = this; + + this.validationErrors = []; + + $.each(validationRules.getRules(), function (field, rule) { + if (rule.required && utils.isEmpty(address[field])) { + self.validationErrors.push($t('Field ') + field + $t(' is required.')); + } + }); + + return !this.validationErrors.length; + } + }; +}); diff --git a/view/frontend/web/js/view/shipping-rates-validation.js b/view/frontend/web/js/view/shipping-rates-validation.js new file mode 100644 index 0000000..93b1a22 --- /dev/null +++ b/view/frontend/web/js/view/shipping-rates-validation.js @@ -0,0 +1,40 @@ +/** + * Mageplaza + * + * NOTICE OF LICENSE + * + * This source file is subject to the Mageplaza.com license that is + * available through the world-wide-web at this URL: + * https://www.mageplaza.com/LICENSE.txt + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this extension to newer + * version in the future. + * + * @category Mageplaza + * @package Mageplaza_Multiflatrates + * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) + * @license https://www.mageplaza.com/LICENSE.txt + */ + +define([ + 'uiComponent', + 'Magento_Checkout/js/model/shipping-rates-validator', + 'Magento_Checkout/js/model/shipping-rates-validation-rules', + '../model/shipping-rates-validator', + '../model/shipping-rates-validation-rules' +], function ( + Component, + defaultShippingRatesValidator, + defaultShippingRatesValidationRules, + mpShippingRatesValidator, + mpShippingRatesValidationRules +) { + 'use strict'; + + defaultShippingRatesValidator.registerValidator('mpflatrate', mpShippingRatesValidator); + defaultShippingRatesValidationRules.registerRules('mpflatrate', mpShippingRatesValidationRules); + + return Component; +});