Skip to content

Commit

Permalink
Allow more carrier configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
firstred committed Jan 18, 2019
1 parent 01e29d7 commit eca3396
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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),
),
);
}

Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit eca3396

Please sign in to comment.