Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validate for shippingRate and update composer.json #66

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Packetery/Checkout/Controller/Config/ShippingRatesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public function execute() {
$shippingRates = $postData['rates'];

foreach ($shippingRates as $shippingRate) {
if (!$this->validateShippingRate($shippingRate)) {
continue;
}
$ratesConfig[$shippingRate['rateCode']] = $this->getRateConfig($shippingRate['countryId'], $shippingRate['carrierCode'], $shippingRate['methodCode']);
}

Expand All @@ -158,4 +161,11 @@ public function execute() {

return $this->resultJsonFactory->create()->setData($response);
}

private function validateShippingRate(array $shippingRate): bool
{
return !empty($shippingRate['countryId']) &&
!empty($shippingRate['carrierCode']) &&
!empty($shippingRate['methodCode']);
}
}
4 changes: 4 additions & 0 deletions Packetery/Checkout/Model/Pricing/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ protected function resolvePrice(RateRequest $request, AbstractConfig $config, Pr
return 0;
}

if ($request->getFreeShipping()) {
return 0;
}

$weightRules = $this->getWeightRulesByPricingRule($pricingRule);
return $this->resolveWeightedPrice($weightRules, $weightTotal, $config->getMaxWeight());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class Modifier implements ModifierInterface
/** @var \Packetery\Checkout\Model\FeatureFlag\Manager */
private $featureFlagManager;

/** @var \Packetery\Checkout\Model\ResourceModel\Carrier\CollectionFactory */
private $carrierCollectionFactory;

/** @var Carrier\Imp\Packetery\Carrier */
private $packeteryCarrier;

/**
* Modifier constructor.
*
Expand Down
9 changes: 1 addition & 8 deletions Packetery/Checkout/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "module Packetery for Magento 2",
"type": "magento2-module",
"license": "AFL-3.0",
"version": "2.3.1",
"authors": [
{
"name": "Packeta Innovations",
Expand All @@ -18,13 +19,5 @@
"psr-4": {
"Packetery\\Checkout\\": ""
}
},
"extra": {
"map": [
[
"*",
"Packetery/Checkout"
]
]
}
}