| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of FulfillmentClient |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace AliNext_Lite;; |
| 10 |
|
| 11 |
class FulfillmentClient extends AbstractClient implements FulfillmentClientInterface |
| 12 |
{ |
| 13 |
/** |
| 14 |
* @param OrderPreviewDataDto $OrderPreviewData |
| 15 |
* @return array |
| 16 |
* @throws ApiException |
| 17 |
*/ |
| 18 |
public function getOrderPreview(OrderPreviewDataDto $OrderPreviewData): array |
| 19 |
{ |
| 20 |
$params = [ |
| 21 |
'country_code' => $OrderPreviewData->getCountryCode(), |
| 22 |
'country' => $OrderPreviewData->getCountry(), |
| 23 |
'province' => $OrderPreviewData->getProvince(), |
| 24 |
'city' => $OrderPreviewData->getCity(), |
| 25 |
'items' => [], |
| 26 |
]; |
| 27 |
|
| 28 |
foreach ($OrderPreviewData->getItems() as $item) { |
| 29 |
$params['items'][] = [ |
| 30 |
'quantity' => $item->getQuantity(), |
| 31 |
'product_id' => $item->getProductId(), |
| 32 |
'sku_id' => $item->getSkuId(), |
| 33 |
'image_url' => $item->getImageUrl(), |
| 34 |
'attributes' => $item->getAttributes(), |
| 35 |
]; |
| 36 |
} |
| 37 |
|
| 38 |
$json = wp_json_encode($params); |
| 39 |
|
| 40 |
$args = [ |
| 41 |
'headers' => ['Content-Type' => 'application/json'], |
| 42 |
]; |
| 43 |
|
| 44 |
$request_url = RequestHelper::build_request('get_order_preview'); |
| 45 |
$request = a2wl_remote_post($request_url, $json, $args); |
| 46 |
$result = $this->handleRequestResult($request); |
| 47 |
|
| 48 |
if ($result['state'] == 'error') { |
| 49 |
throw new ApiException('Fulfillment Client Error', $result['error_code'] ?? 0); |
| 50 |
} |
| 51 |
|
| 52 |
return $result; |
| 53 |
} |
| 54 |
} |
| 55 |
|