Skip to content

Commit

Permalink
Added missing tests on presence of lce_service
Browse files Browse the repository at this point in the history
publish version 1.0.9
  • Loading branch information
tbelliard committed Nov 23, 2017
1 parent 702b94f commit acaae4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
3 changes: 3 additions & 0 deletions controllers/admin/adminshipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 15 additions & 13 deletions lowcostexpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit acaae4e

Please sign in to comment.