diff --git a/CHANGELOG.md b/CHANGELOG.md index de8c05c7..491bde42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). +## [3.3.5](https://github.com/packlink-dev/ecommerce_module_core/compare/v3.3.4...v3.3.5) - 2021-01-31 +### Added +- Added a new configuration flag that specifies whether a given integration supports drop-off carriers or not. The default will be `true` and only integrations that do not support drop-off carriers should set this flag to `false`. +### Changed +- Fixed a frontend issue when adding/editing a shipping service on the module configuration page. + ## [3.3.4](https://github.com/packlink-dev/ecommerce_module_core/compare/v3.3.3...v3.3.4) - 2021-11-30 ### Changed - Updated the mechanism for fetching controller URLs on the frontend views. diff --git a/src/BusinessLogic/Configuration.php b/src/BusinessLogic/Configuration.php index 600bb5b1..df223c04 100644 --- a/src/BusinessLogic/Configuration.php +++ b/src/BusinessLogic/Configuration.php @@ -53,6 +53,16 @@ public function setMaxTaskAge($maxAge) $this->saveConfigValue('maxTaskAge', $maxAge); } + /** + * Determines whether the drop-off shipping services are system supported. + * + * @return bool + */ + public function dropOffShippingServicesSupported() + { + return true; + } + /** * Returns web-hook callback URL for current system. * diff --git a/src/BusinessLogic/Http/Proxy.php b/src/BusinessLogic/Http/Proxy.php index 77188b6c..01ea99d0 100644 --- a/src/BusinessLogic/Http/Proxy.php +++ b/src/BusinessLogic/Http/Proxy.php @@ -301,6 +301,10 @@ public function getShippingServicesDeliveryDetails(ShippingServiceSearch $params $shippingDetails = ShippingServiceDetails::fromBatch($body); + if (!$this->configService->dropOffShippingServicesSupported()) { + return $this->getShippingServicesDeliveryDetailsWithoutDropOffServices($shippingDetails, $params); + } + foreach ($shippingDetails as $shippingDetail) { $shippingDetail->departureCountry = $params->fromCountry; $shippingDetail->destinationCountry = $params->toCountry; @@ -440,6 +444,29 @@ public function sendAnalytics($eventName) } } + /** + * @param $shippingDetails + * @param $params + * @return array + */ + protected function getShippingServicesDeliveryDetailsWithoutDropOffServices($shippingDetails, $params) + { + $newShippingDetails = array(); + + foreach ($shippingDetails as $shippingDetail) { + if ($shippingDetail->destinationDropOff) { + continue; + } else { + $shippingDetail->departureCountry = $params->fromCountry; + $shippingDetail->destinationCountry = $params->toCountry; + $shippingDetail->national = $params->toCountry === $params->fromCountry; + $newShippingDetails[] = $shippingDetail; + } + } + + return $newShippingDetails; + } + /** * Calls shipments endpoint and handles response. Any shipment endpoint can return 404 so this call handles that. * diff --git a/src/BusinessLogic/Resources/js/EditServiceController.js b/src/BusinessLogic/Resources/js/EditServiceController.js index cfc5f22b..b8ab0788 100644 --- a/src/BusinessLogic/Resources/js/EditServiceController.js +++ b/src/BusinessLogic/Resources/js/EditServiceController.js @@ -328,16 +328,20 @@ if (!window.Packlink) { } for (let systemId in pricePolicyControllers) { - let fieldName = pricePolicyControllers[systemId].getExcludedFieldForValidation(); - if (fieldName !== null) { - excludedElementNames.push(fieldName); + if (pricePolicyControllers.hasOwnProperty(systemId)) { + let fieldName = pricePolicyControllers[systemId].getExcludedFieldForValidation(); + if (fieldName !== null) { + excludedElementNames.push(fieldName); + } } } if (validationService.validateForm(form, excludedElementNames) && validateMiconfiguredPolicies()) { let pricingPolicies = []; for (let systemId in pricePolicyControllers) { - pricingPolicies = pricingPolicies.concat(pricePolicyControllers[systemId].getSystemPricingPolicies()); + if (pricePolicyControllers.hasOwnProperty(systemId)) { + pricingPolicies = pricingPolicies.concat(pricePolicyControllers[systemId].getSystemPricingPolicies()); + } } serviceModel.activated = true;