Skip to content

Commit

Permalink
Use product model instead of cart product
Browse files Browse the repository at this point in the history
  • Loading branch information
radua committed Sep 27, 2022
1 parent 5dac843 commit ad6e9eb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
Binary file modified flagship.ocmod.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modification>
<code>flagship</code>
<name>FlagShip Modification</name>
<version>1.0.11</version>
<version>1.0.12</version>
<author>FlagShip Courier Solutions</author>
<link>https://www.flagshipcompany.com</link>
<file path="admin/controller/sale/order.php">
Expand Down
8 changes: 4 additions & 4 deletions upload/admin/model/extension/shipping/flagship.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function updateShipment(int $flagship_shipment_id,array $payload,int $ord
$url = $this->config->get('smartship_api_url').'/ship/shipments/'.$flagship_shipment_id;
$token = $this->config->get('shipping_flagship_token');

$shipment = $this->apiRequest($url,$payload,$token,'PUT',30,'1.0.11',$orderId,$orderLink);
$shipment = $this->apiRequest($url,$payload,$token,'PUT',30,'1.0.12',$orderId,$orderLink);
return $shipment["response"]->content;
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public function getSelectedCouriers() : \stdClass {
public function prepareShipment(array $payload, int $orderId, string $orderLink) : \stdClass {
$url = $this->config->get('smartship_api_url').'/ship/prepare';
$token = $this->config->get('shipping_flagship_token');
$shipment = $this->apiRequest($url,$payload,$token,'POST',30,'1.0.11',$orderId,$orderLink);
$shipment = $this->apiRequest($url,$payload,$token,'POST',30,'1.0.12',$orderId,$orderLink);
return $shipment["response"]->content;
}

Expand Down Expand Up @@ -200,12 +200,12 @@ protected function getFlagshipShipmentStatus(int $shipment_id, int $orderId) : ?
$url = $this->config->get('smartship_api_url').'/ship/shipments/'.$shipment_id;
$token = $this->config->get('shipping_flagship_token');

$shipment = $this->apiRequest($url,[],$token,'GET',10,'1.0.11',$orderId);
$shipment = $this->apiRequest($url,[],$token,'GET',10,'1.0.12',$orderId);
$status = $shipment["response"]->content->status;
return $status;
}

protected function apiRequest(string $url,array $json, string $apiToken,string $method, int $timeout, string $version='1.0.11', int $orderId=0, string $orderLink='') : array {
protected function apiRequest(string $url,array $json, string $apiToken,string $method, int $timeout, string $version='1.0.12', int $orderId=0, string $orderLink='') : array {

$curl = curl_init();
$storeName = $this->config->get('config_name');
Expand Down
57 changes: 32 additions & 25 deletions upload/catalog/model/extension/shipping/flagship.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function getRates(array $payload)
}


protected function apiRequest(string $url,array $json, string $apiToken,string $method, int $timeout, string $flagshipFor='OpenCart',string $version='1.0.11') : array {
protected function apiRequest(string $url,array $json, string $apiToken,string $method, int $timeout, string $flagshipFor='OpenCart',string $version='1.0.12') : array {

$curl = curl_init();
$options = [
Expand Down Expand Up @@ -225,34 +225,13 @@ protected function packingRequest(array $payload): ?array

protected function getItems(): array
{
$this->load->model('catalog/product');
$items = [];
$products = $this->cart->getProducts();
$imperialLengthClass = $this->getImperialLengthClass();
$imperialWeightClass = $this->getImperialWeightClass();


foreach ($products as $orderProduct) {
for ($i = 0; $i < $orderProduct['quantity']; $i++) {
$length = $orderProduct["length_class_id"] != $imperialLengthClass ?
max($this->length->convert($orderProduct["length"],$orderProduct["length_class_id"],$imperialLengthClass),1) : max($orderProduct["length"],1);
$width = $orderProduct["length_class_id"] != $imperialLengthClass ?
max($this->length->convert($orderProduct["width"],$orderProduct["length_class_id"],$imperialLengthClass),1) : max($orderProduct["width"],1);
$height = $orderProduct["length_class_id"] != $imperialLengthClass ?
max($this->length->convert($orderProduct["height"],$orderProduct["length_class_id"],$imperialLengthClass),1) : max($orderProduct["height"],1);
$weight = $orderProduct["weight_class_id"] != $imperialWeightClass ?
max($this->weight->convert($orderProduct["weight"],$orderProduct["weight_class_id"],$imperialWeightClass),1) :
max($orderProduct["weight"],1);

$items[] = [
"length" => ceil($length),
"width" => ceil($width),
"height" => ceil($height),
"weight" => $weight,
"description" => $orderProduct["name"]
];
}
$items = $this->getProductsByQuantity($items, $orderProduct);
}


return $items;
}
protected function getCountryCode(int $country_id): string
Expand Down Expand Up @@ -288,4 +267,32 @@ protected function getSelectedCouriers(): array
$query = $this->db->query("SELECT value FROM `" . DB_PREFIX . "flagship_couriers` ");
return $query->rows;
}

protected function getProductsByQuantity($items, $orderProduct) {
$imperialLengthClass = $this->getImperialLengthClass();
$imperialWeightClass = $this->getImperialWeightClass();

$product_id = ($orderProduct["product_id"]);
for ($i = 0; $i < $orderProduct['quantity']; $i++) {
$product = $this->model_catalog_product->getProduct($product_id);
$length = $product["length_class_id"] != $imperialLengthClass ?
max($this->length->convert($product["length"],$product["length_class_id"],$imperialLengthClass),1) : max($product["length"],1);
$width = $product["length_class_id"] != $imperialLengthClass ?
max($this->length->convert($product["width"],$product["length_class_id"],$imperialLengthClass),1) : max($product["width"],1);
$height = $product["length_class_id"] != $imperialLengthClass ?
max($this->length->convert($product["height"],$product["length_class_id"],$imperialLengthClass),1) : max($product["height"],1);
$weight = $product["weight_class_id"] != $imperialWeightClass ?
max($this->weight->convert($product["weight"],$product["weight_class_id"],$imperialWeightClass),1) :
max($product["weight"],1);

$items[] = [
"length" => ceil($length),
"width" => ceil($width),
"height" => ceil($height),
"weight" => $weight,
"description" => $orderProduct["name"]
];
}
return $items;
}
}

0 comments on commit ad6e9eb

Please sign in to comment.