From eca3396a13bc2049c30e98e0df2b53ffe6c69a01 Mon Sep 17 00:00:00 2001 From: Michael Dekker Date: Fri, 18 Jan 2019 14:31:54 +0100 Subject: [PATCH] Allow more carrier configurations --- mollie.php | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/mollie.php b/mollie.php index 1cd2531e3..b55cbf658 100644 --- a/mollie.php +++ b/mollie.php @@ -5599,7 +5599,8 @@ public function hookActionOrderStatusUpdate($params = array()) if (!(Configuration::get(static::MOLLIE_AUTO_SHIP_MAIN) && $orderStatus->shipped || in_array($orderStatusNumber, $checkStatuses) - ) || $shipmentInfo === null) { + ) || $shipmentInfo === null + ) { return; } @@ -5618,22 +5619,23 @@ public function hookActionOrderStatusUpdate($params = array()) } $length = Tools::strlen(\MollieModule\Mollie\Api\Endpoints\OrderEndpoint::RESOURCE_ID_PREFIX); - if (Tools::substr($dbPayment['transaction_id'], 0, $length) !== \MollieModule\Mollie\Api\Endpoints\OrderEndpoint::RESOURCE_ID_PREFIX) { + if (Tools::substr($dbPayment['transaction_id'], 0, $length) !== \MollieModule\Mollie\Api\Endpoints\OrderEndpoint::RESOURCE_ID_PREFIX + ) { // No need to check regular payments return; } try { - $apiPayment = $this->api->orders->get($dbPayment['transaction_id'], array('embed' => 'payments')); + $apiOrder = $this->api->orders->get($dbPayment['transaction_id']); $shippableItems = 0; - foreach ($apiPayment->lines as $line) { + foreach ($apiOrder->lines as $line) { $shippableItems += $line->shippableQuantity; } if ($shippableItems <= 0) { return; } - $apiPayment->shipAll(array('tracking' => $shipmentInfo)); + $apiOrder->shipAll($shipmentInfo); } catch (\MollieModule\Mollie\Api\Exceptions\ApiException $e) { Logger::addLog("Mollie module error: {$e->getMessage()}"); return; @@ -5667,7 +5669,7 @@ public static function getShipmentInformation($idOrder) || !Validate::isLoadedObject($deliveryAddress) || !$carrierConfig ) { - return null; + return array(); } if ($carrierConfig['source'] === static::MOLLIE_CARRIER_NO_TRACKING_INFO) { @@ -5693,9 +5695,11 @@ public static function getShipmentInformation($idOrder) $tracktrace = $info['tracktrace']; return array( - 'carrier' => 'PostNL', - 'code' => $info['tracktrace'], - 'url' => "http://postnl.nl/tracktrace/?L={$langIso}&B={$tracktrace}&P={$postcode}&D={$countryIso}&T=C", + 'tracking' => array( + 'carrier' => 'PostNL', + 'code' => $info['tracktrace'], + 'url' => "http://postnl.nl/tracktrace/?L={$langIso}&B={$tracktrace}&P={$postcode}&D={$countryIso}&T=C", + ), ); } } catch (PrestaShopDatabaseException $e) { @@ -5719,9 +5723,11 @@ public static function getShipmentInformation($idOrder) } return array( - 'carrier' => $carrier->name, - 'code' => $shippingNumber, - 'url' => str_replace('@', $shippingNumber, $carrier->url), + 'tracking' => array( + 'carrier' => $carrier->name, + 'code' => $shippingNumber, + 'url' => str_replace('@', $shippingNumber, $carrier->url), + ), ); } @@ -5755,17 +5761,19 @@ public static function getShipmentInformation($idOrder) ); return array( - 'carrier' => $carrier->name, - 'code' => $shippingNumber, - 'url' => str_ireplace( - array_keys($info), - array_values($info), - $carrierConfig['custom_url'] + 'tracking' => array( + 'carrier' => $carrier->name, + 'code' => $shippingNumber, + 'url' => str_ireplace( + array_keys($info), + array_values($info), + $carrierConfig['custom_url'] + ), ), ); } - return null; + return array(); } /**