https://github.com/bdcrops/module-banglacourier
This module is used as Offline Shipping methods of Magento 2 extensions.
https://github.com/bdcrops/module-banglacourier
Last synced: 3 days ago
JSON representation
This module is used as Offline Shipping methods of Magento 2 extensions.
- Host: GitHub
- URL: https://github.com/bdcrops/module-banglacourier
- Owner: bdcrops
- Created: 2019-09-20T12:24:33.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-16T07:45:27.000Z (over 5 years ago)
- Last Synced: 2024-12-26T12:09:49.868Z (5 months ago)
- Language: PHP
- Homepage: https://www.bdcrops.com
- Size: 121 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BDC_BanglaCourier
This module is used as Offline Shipping methods of Magento 2 extensions.
Customize Checkout Add custom shipping carrier.## 1. How to install & upgrade BDC_BanglaCourier
#### 1.1 Copy and paste
If you don't want to install via composer, you can use this way.
- Download [the latest version here](https://github.com/bdcrops/module-banglacourier/archive/master.zip)
- Extract `master.zip` file to `app/code/BDC/BanglaCourier` ; You should create a folder path `app/code/BDC/BanglaCourier` if not exist.
- Go to Magento root folder and run upgrade command line to install `BDC_BanglaCourier`:#### 1.2. Install via composer
We recommend you to install BDC_BanglaCourier module via composer. It is easy to install, update and maintaince.Run the following command in Magento 2 root folder.
```
composer config repositories.module-banglacourier git
https://github.com/bdcrops/module-banglacourier.gitcomposer require bdcrops/module-banglacourier:~1.0.0
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
```
#### 1.3 Upgrade```
composer update bdcrops/module-banglacourier
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
```
Run compile if your store in Product mode:
```
php bin/magento setup:di:compile
```## 2 Manual Tutorial
- Create app/code/BDC/BanglaCourier/registration.php
```
```
- create app/code/BDC/BanglaCourier/etc/config.xml
```
1
Bangla Courier Shipping
0
0
10
BDC\BanglaCourier\Model\Carrier\BanglaCourier
4.99
9.99
```
- create app/code/BDC/BanglaCourier/etc/adminhtml/system.xml
```
Bangla Courier Shipping
Enabled
Magento\Config\Model\Config\Source\Yesno
Title
Ship to Applicable Countries
shipping-applicable-country
Magento\Shipping\Model\Config\Source\Allspecificcountries
Ship to Specific Countries
1
Magento\Directory\Model\Config\Source\Country
Show Method if Not Applicable
Magento\Config\Model\Config\Source\Yesno
shipping-skip-hide
Displayed Error Message
Sort Order
validate-number validate-zero-or-greater
complex
validate-number validate-zero-or-greater
complex
validate-number validate-zero-or-greater
```
- create app/code/BDC/BanglaCourier/Model/Carrier/BanglaCourier.php
```
_rateResultFactory = $rateResultFactory;
$this->_rateMethodFactory = $rateMethodFactory;
parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);
}/**
* {@inheritdoc}
*/
public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request){
if (!$this->getConfigFlag('active')) {
return false;
}
// $request->getPackageWeight();
// $request->getPackageValue()// Init result object
$result = $this->_rateResultFactory->create();
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
// todo: Any calculation/logic based on order items?
}
}$method = $this->_rateMethodFactory->create();
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod(self::BANGLA_COURIER_STANDARD);
$method->setMethodTitle($this->getMethodTitle($method->getMethod()));
$method->setPrice($this->getMethodPrice($method->getMethod()));
$method->setCost($this->getMethodCost($method->getMethod()));
$method->setErrorMessage(__('The %1 method error message here.'));
$result->append($method);$method = $this->_rateMethodFactory->create();
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod(self::BANGLA_COURIER_48HR);
$method->setMethodTitle($this->getMethodTitle($method->getMethod()));
$method->setPrice($this->getMethodPrice($method->getMethod()));
$method->setCost($this->getMethodCost($method->getMethod()));
$method->setErrorMessage(__('The %1 method error message here.'));
$result->append($method);return $result;
}/**
* This method is used in \Magento\Shipping\Model\Config\Source\Allmethods::toOptionArray()
*
* Which in turn is used with:
* (1) Sales/cart rule condition, see https://goo.gl/goUKzU.
* (2) Stores > Configuration > Sales > Clean Checkout > General > Default Shipping Method, see https://goo.gl/66aopF
*
* @return array
*/
public function getAllowedMethods(){
return [
self::BANGLA_COURIER_STANDARD => $this->getConfigData(self::BANGLA_COURIER_STANDARD . '/title'),
self::BANGLA_COURIER_48HR => $this->getConfigData(self::BANGLA_COURIER_48HR . '/title'),
];
}/**
* @param $method
* @return false|string
*/
private function getMethodTitle($method){
return $this->getConfigData($method . '/title');
}/**
* @param $method
* @return false|string
*/
private function getMethodPrice($method){
return $this->getMethodCost($method);
}/**
* @param $method
* @return false|string
*/
private function getMethodCost($method){
return $this->getConfigData($method . '/shippingcost');
}
}```
- Admin Panel Sales & Shipping section Show as below:

- The Order Summary section of the Review & Payments step should also reflect on the method
selected in the Shipping step, as follows:
## Ref
- [Devdocs](https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout-add-custom-carrier.html)