Skip to content

Commit

Permalink
Add third-party support
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Jul 13, 2018
1 parent 28859f9 commit e863e3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions Plugin/Quote/Address/Total/ShippingPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,19 @@ public function aroundCollect(
foreach ($address->getAllShippingRates() as $rate) {
if ($rate->getCode() == $customOption['code']) {
$cost = $customOption['rate'];
$description = trim($customOption['description']);

$rate->setPrice($cost);
//$rate->setMethodTitle($customOption['type']);
//Empty by default. Use in third-party modules
if (empty($description) || strlen($description) < 2) {
$description = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();
}

$rate->setPrice($cost);
$rate->setMethodTitle($description);
$address->setShippingMethod($customOption['code']);
$address->setShippingAmount($cost);
$address->setBaseShippingAmount($cost);
$address->setShippingDescription($rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle());
$address->setShippingDescription($description);
$total->setShippingAmount($cost);
$total->setBaseShippingAmount($cost);

Expand All @@ -91,7 +96,8 @@ private function getCustomShippingJsonToArray($json)
$customOption = [
'code' => '',
'rate' => 0,
'type' => ''
'type' => '',
'description' => ''
];

$jsonToArray = (array)json_decode($json, true);
Expand All @@ -104,7 +110,7 @@ private function getCustomShippingJsonToArray($json)
}
}

if (is_array($jsonToArray) && count($jsonToArray) == 3) {
if (is_array($jsonToArray) && count($jsonToArray) == 4) {
foreach ($jsonToArray as $key => $value) {
$customOption[$key] = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"magento 2 free shipping extension"
],
"type": "magento2-module",
"version": "1.4.0",
"version": "1.4.1",
"license": [
"proprietary"
],
Expand Down

0 comments on commit e863e3e

Please sign in to comment.