From acaae4e3ab1685fdd03cac27744e14f9343b8352 Mon Sep 17 00:00:00 2001 From: Thomas Belliard Date: Thu, 23 Nov 2017 15:56:40 +0200 Subject: [PATCH] Added missing tests on presence of lce_service publish version 1.0.9 --- controllers/admin/adminshipment.php | 3 +++ lowcostexpress.php | 28 +++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/controllers/admin/adminshipment.php b/controllers/admin/adminshipment.php index 65fd9dd..346d5cb 100644 --- a/controllers/admin/adminshipment.php +++ b/controllers/admin/adminshipment.php @@ -537,6 +537,9 @@ public function displayAjaxGetOffers() $offers = array(); foreach ($quote->offers as $offer) { $lce_service = LceService::findByCode($offer->product->code); + // We cannot proceed with offers that have no corresponding service initialized + // locally. + if (!$lce_service) continue; $data = new stdClass(); $data->id = $offer->id; diff --git a/lowcostexpress.php b/lowcostexpress.php index b26f58d..80d0f0c 100755 --- a/lowcostexpress.php +++ b/lowcostexpress.php @@ -90,7 +90,7 @@ public function __construct() { $this->name = 'lowcostexpress'; $this->tab = 'shipping_logistics'; - $this->version = '1.0.8'; + $this->version = '1.0.9'; $this->author = 'MY FLYING BOX SAS'; parent::__construct(); @@ -707,7 +707,7 @@ public function getOrderShippingCost($cart, $shipping_cost) } // Exceptions must never be raised directly without being caught. - // We are in the frontend when executed the current code. + // We are in the frontend when executing the current code. try { $api_quote = Lce\Resource\Quote::request($params); @@ -718,18 +718,20 @@ public function getOrderShippingCost($cart, $shipping_cost) // Now we create the offers foreach ($api_quote->offers as $api_offer) { $lce_service = LceService::findByCode($api_offer->product->code); - $offer = new LceOffer(); - $offer->id_quote = $quote->id; - $offer->lce_service_id = $lce_service->id_service; - $offer->api_offer_uuid = $api_offer->id; - $offer->lce_product_code = $api_offer->product->code; - $offer->base_price_in_cents = $api_offer->price->amount_in_cents; - $offer->total_price_in_cents = $api_offer->total_price->amount_in_cents; - if ($api_offer->insurance_price) { - $offer->insurance_price_in_cents = $api_offer->insurance_price->amount_in_cents; + if ($lce_service) { + $offer = new LceOffer(); + $offer->id_quote = $quote->id; + $offer->lce_service_id = $lce_service->id_service; + $offer->api_offer_uuid = $api_offer->id; + $offer->lce_product_code = $api_offer->product->code; + $offer->base_price_in_cents = $api_offer->price->amount_in_cents; + $offer->total_price_in_cents = $api_offer->total_price->amount_in_cents; + if ($api_offer->insurance_price) { + $offer->insurance_price_in_cents = $api_offer->insurance_price->amount_in_cents; + } + $offer->currency = $api_offer->total_price->currency; + $offer->add(); } - $offer->currency = $api_offer->total_price->currency; - $offer->add(); } } } catch (Exception $e) {