Skip to content
Draft
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,7 @@
- Added timeframes to shipment request
- Fixed phone area code, city and street select width rendering as 0px when switching carriers in checkout
- Fixed DPDBaltics menu item disappearing from sidebar when navigating to module pages

## [3.3.2]
- Fixed checkout pickup point selection returning a 500 error when the selected city and street do not match an imported pickup point
- Fixed pickup point error messages not being displayed in checkout when a request fails
21 changes: 13 additions & 8 deletions controllers/front/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,20 @@ private function saveParcelShop($countryCode, $city, $street)

$pudoId = $pudoService->getPudoIdByCityAndAddress($city, $street);
$parcelShops = $pudoService->getClosestParcelShops($pudoId);
$coordinates = [];
$selectedPudo = null;
if (isset($parcelShops[0])) {
$coordinates = [
'lat' => $parcelShops[0]->getLatitude(),
'lng' => $parcelShops[0]->getLongitude(),
];
$selectedPudo = $parcelShops[0];

if (!isset($parcelShops[0])) {
$this->messages[] = $this->module->l('No pickup points found for the selected address.', self::FILENAME);
$this->ajaxDie(json_encode([
'template' => $this->getMessageTemplate('danger'),
'status' => false
]));
}

$selectedPudo = $parcelShops[0];
$coordinates = [
'lat' => $selectedPudo->getLatitude(),
'lng' => $selectedPudo->getLongitude(),
];
$pudoServices = $pudoService->setPudoServiceTypes($parcelShops);
$pudoServices = $pudoService->formatPudoServicesWorkHours($pudoServices);

Expand Down
9 changes: 2 additions & 7 deletions src/Service/GoogleApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class GoogleApiService
public function __construct(Language $language, Shop $shop)
{
$apiKey = Configuration::get(Config::GOOGLE_API_KEY);
$this->geolocationApi = $this->getGeolocationUrl($apiKey);
$this->isSslEnabled =
(Configuration::get('PS_SSL_ENABLED')) && Configuration::get('PS_SSL_ENABLED_EVERYWHERE');
$this->geolocationApi = $this->getGeolocationUrl($apiKey);
$this->language = $language;
$this->shop = $shop;
}
Expand Down Expand Up @@ -191,13 +191,8 @@ public function getResultFromGoogleApiService($requestStringified)

private function getGeolocationUrl($apiKey)
{
$url = 'https';
if ($this->isSslEnabled) {
$url .='s';
}
$url .= '://maps.googleapis.com/maps/api/geocode/json?key='.
return 'https://maps.googleapis.com/maps/api/geocode/json?key='.
$apiKey.'&sensor=false&address=';
return $url;
}


Expand Down
9 changes: 9 additions & 0 deletions src/Service/PudoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use Language;
use Smarty;
use Tools;
use Validate;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -325,13 +326,21 @@ public function getClosestParcelShops($pudoId)
/** @var DPDShop $pudo */
$pudo = DPDShop::getShopByPudoId($pudoId);

if (!Validate::isLoadedObject($pudo)) {
return [];
}

$parcelShops = $this->parcelShopRepository->getClosestPudoShops(
$pudo->longitude,
$pudo->latitude,
Config::PARCEL_SHOP_MAP_DISTANCE,
Config::PARCEL_SHOP_MAP_POINTS_LIMIT
);

if (!is_array($parcelShops)) {
return [];
}

return $this->shopFactory->createShop($parcelShops);
}

Expand Down
41 changes: 30 additions & 11 deletions views/js/front/pudo-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ $( document ).ajaxComplete(function( event, request, settings ) {
});

function updateStreetSelect(city) {
var $container = $(this).closest('.dpd-pudo-container');

$.ajax(dpdHookAjaxUrl, {
type: 'POST',
data: {
Expand All @@ -109,10 +107,17 @@ function updateStreetSelect(city) {
}
},
error: function (response) {
var responseText = JSON.parse(response.responseText);
var $parent = $('.dpd-pudo-container');
var responseText = null;

if (responseText) {
DPDdisplayMessage($container, responseText.template);
try {
responseText = JSON.parse(response.responseText);
} catch (e) {
responseText = null;
}

if (responseText && responseText.template) {
DPDdisplayMessage($parent, responseText.template);
}
}
});
Expand Down Expand Up @@ -146,10 +151,17 @@ function saveSelectedStreet(city, street) {
}
},
error: function (response) {
var responseText = JSON.parse(response.responseText);
var $parent = $('.dpd-pudo-container');
var responseText = null;

if (responseText) {
DPDdisplayMessage($container, responseText.template);
try {
responseText = JSON.parse(response.responseText);
} catch (e) {
responseText = null;
}

if (responseText && responseText.template) {
DPDdisplayMessage($parent, responseText.template);
}
}
});
Expand Down Expand Up @@ -178,10 +190,17 @@ function updateParcelBlock(city, street, idCarrier) {
}
},
error: function (response) {
var responseText = JSON.parse(response.responseText);
var $parent = $('.dpd-pudo-container');
var responseText = null;

try {
responseText = JSON.parse(response.responseText);
} catch (e) {
responseText = null;
}

if (responseText) {
DPDdisplayMessage($container, responseText.template);
if (responseText && responseText.template) {
DPDdisplayMessage($parent, responseText.template);
}
}
});
Expand Down
Loading