2021-02-19 16:32:08 +01:00
|
|
|
<?php
|
|
|
|
|
|
2021-07-28 14:18:47 +02:00
|
|
|
namespace App\Http\Controllers\Api\V1;
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Resources\StatusResource;
|
|
|
|
|
use App\Mail\CourrierArcadiaError;
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use DOMDocument;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
2021-02-19 16:32:08 +01:00
|
|
|
class ArcadiaController extends Controller
|
|
|
|
|
{
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return StatusResource
|
|
|
|
|
*/
|
2021-02-19 16:32:08 +01:00
|
|
|
public function outgoingMail(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
|
|
'crm_id' => 'required',
|
|
|
|
|
'fields' => 'required|json',
|
|
|
|
|
'type' => 'required',
|
2021-05-17 17:39:56 +02:00
|
|
|
'shipping' => 'required_if:type,default|json'
|
2021-02-19 16:32:08 +01:00
|
|
|
]);
|
|
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($validator->fails()) {
|
|
|
|
|
return new StatusResource([
|
|
|
|
|
'status' => 'KO',
|
|
|
|
|
'code' => 201,
|
|
|
|
|
'message' => 'Error on required fields.',
|
|
|
|
|
'errors' => $validator->errors()
|
|
|
|
|
]);
|
|
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-07-22 15:14:07 +02:00
|
|
|
$brandId = $request->brand_id;
|
|
|
|
|
$crmId = $request->crm_id;
|
|
|
|
|
$fields = json_decode($request->fields);
|
|
|
|
|
$type = $request->type;
|
2021-05-17 17:39:56 +02:00
|
|
|
$shipping = $type === 'default' ? json_decode($request->shipping) : false;
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$customer = Customer::where('id', $crmId)->first();
|
2021-02-28 12:04:49 +01:00
|
|
|
if (!$customer) {
|
2021-02-19 16:32:08 +01:00
|
|
|
return new StatusResource(['status' => 'KO', 'code' => 202, 'message' => 'User not found.']);
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
$CustomerInfo = $customer->infos()->where('brand_id', $brandId)->first();
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
if (!$CustomerInfo) {
|
2021-02-19 16:32:08 +01:00
|
|
|
return new StatusResource(['status' => 'KO', 'code' => 202, 'message' => 'User not found.']);
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$check = $this->checkRequiredFields($fields, $type);
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($check['status'] !== 'OK') {
|
2021-02-19 16:32:08 +01:00
|
|
|
return new StatusResource($check);
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-05-17 17:39:56 +02:00
|
|
|
if ($type === 'default') {
|
|
|
|
|
$check = $this->checkShippingRequiredFields($shipping);
|
2021-07-22 15:14:07 +02:00
|
|
|
if ($check['status'] !== 'OK') {
|
2021-05-17 17:39:56 +02:00
|
|
|
return new StatusResource($check);
|
2021-07-22 15:14:07 +02:00
|
|
|
}
|
2021-05-17 17:39:56 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-22 15:14:07 +02:00
|
|
|
$xml = $this->makeXml($fields, $type, $customer, $CustomerInfo, $shipping);
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
try {
|
2021-07-22 15:14:07 +02:00
|
|
|
Storage::disk('arcadia')->put(date("Ymd_His") . microtime(true) . ".xml", $xml);
|
2021-02-19 16:32:08 +01:00
|
|
|
return new StatusResource(['status' => 'OK']);
|
2021-02-28 12:04:49 +01:00
|
|
|
} catch (\Exception $e) {
|
2021-02-19 16:32:08 +01:00
|
|
|
Log::critical("ARCADIA XML CREATION FAILED : " . $e->getMessage());
|
2021-03-14 10:45:42 +01:00
|
|
|
Mail::to(config('mail.MAIL_ADMIN'))->send(new CourrierArcadiaError(
|
2021-02-28 12:04:49 +01:00
|
|
|
"ARCADIA XML CREATION FAILED",
|
|
|
|
|
"Une erreur est survenue lors de la création du fichier XML : " . $e->getMessage(),
|
2021-12-19 15:57:24 +01:00
|
|
|
$xml ?: ''
|
2021-02-28 12:04:49 +01:00
|
|
|
));
|
2021-02-19 16:32:08 +01:00
|
|
|
return new StatusResource(['status' => 'KO', 'code' => 204, 'message' => 'Arcadia XML Creation failed.']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* @param mixed $fields
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2021-05-17 17:39:56 +02:00
|
|
|
private function checkShippingRequiredFields($fields)
|
|
|
|
|
{
|
|
|
|
|
$test = [
|
|
|
|
|
'firstname',
|
|
|
|
|
'lastname',
|
|
|
|
|
'address',
|
|
|
|
|
'city',
|
|
|
|
|
'postcode'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($test as $t) {
|
2021-07-22 15:14:07 +02:00
|
|
|
if (!array_key_exists($t, $fields)) {
|
2021-05-17 17:39:56 +02:00
|
|
|
$errors[] = ['field' => $t, 'error' => 'required'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 15:14:07 +02:00
|
|
|
if (!empty($errors)) {
|
2021-05-17 17:39:56 +02:00
|
|
|
return ['status' => 'KO', 'code' => 203, 'message' => $errors];
|
2021-07-22 15:14:07 +02:00
|
|
|
}
|
2021-02-28 12:04:49 +01:00
|
|
|
|
2021-05-17 17:39:56 +02:00
|
|
|
return ['status' => 'OK'];
|
|
|
|
|
}
|
2021-02-28 12:04:49 +01:00
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $fields
|
|
|
|
|
* @param mixed $type
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
// phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Squiz.Commenting.FunctionComment.Missing
|
|
|
|
|
private function checkRequiredFields($fields, $type): array
|
2021-02-19 16:32:08 +01:00
|
|
|
{
|
|
|
|
|
$errors = [];
|
|
|
|
|
|
|
|
|
|
$key = array_search('operation', array_column($fields->root, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'operation', 'error' => 'required'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-23 15:45:35 +01:00
|
|
|
$key = array_search('support_code', array_column($fields->orderLine, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'support_code', 'error' => 'required'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-23 15:45:35 +01:00
|
|
|
$key = array_search('label_type_support', array_column($fields->orderLine, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'label_type_support', 'error' => 'required'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$key = array_search('order_date', array_column($fields->root, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'order_date', 'error' => 'required'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
$regex = join('', [
|
|
|
|
|
'/^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|',
|
|
|
|
|
'((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))',
|
|
|
|
|
'|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]',
|
|
|
|
|
'|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/'
|
|
|
|
|
]);
|
|
|
|
|
if (!preg_match($regex, $fields->root[$key]->fieldValue)) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'order_date', 'error' => 'format must be DD/MM/YYYY'];
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($type === 'default') {
|
2021-02-19 16:32:08 +01:00
|
|
|
$key = array_search('order_num', array_column($fields->root, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'order_num', 'error' => 'required for default type'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
if (!is_numeric($fields->root[$key]->fieldValue) || strlen($fields->root[$key]->fieldValue) !== 9) {
|
2021-02-26 11:08:15 +01:00
|
|
|
$errors[] = ['field' => 'order_num', 'error' => 'format must be 9 numeric characters'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-26 11:08:15 +01:00
|
|
|
|
2021-02-19 16:32:08 +01:00
|
|
|
$key = array_search('state_order_cb', array_column($fields->root, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'state_order_cb', 'error' => 'required for default type'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($fields->root[$key]->fieldValue !== 1 && $fields->root[$key]->fieldValue !== 'Null') {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'state_order_cb', 'error' => 'value must be 1 or Null (Yes Null not NULL)'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$orderCB = $fields->root[$key]->fieldValue;
|
|
|
|
|
|
|
|
|
|
$key = array_search('state_order_check', array_column($fields->root, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'state_order_check', 'error' => 'required for default type'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($fields->root[$key]->fieldValue !== 1 && $fields->root[$key]->fieldValue !== 'Null') {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'state_order_check', 'error' => 'value must be 1 or Null (Yes Null not NULL)'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$orderCheck = $fields->root[$key]->fieldValue;
|
|
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($orderCB === $orderCheck) {
|
|
|
|
|
$errors[] = [
|
|
|
|
|
'field' => 'state_order',
|
|
|
|
|
'error' => 'state_order_cb and state_order_check values must be different'
|
|
|
|
|
];
|
|
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$key = array_search('package_unit_weight', array_column($fields->orderLine, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'package_unit_weight', 'error' => 'required for default type'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
|
|
|
|
} elseif ($type === 'game') {
|
2021-02-19 16:32:08 +01:00
|
|
|
$key = array_search('code_unique', array_column($fields->orderLine, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$errors[] = ['field' => 'code_unique', 'error' => 'required for game type'];
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-12-19 15:57:24 +01:00
|
|
|
}//end if
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-07-22 15:14:07 +02:00
|
|
|
if (!empty($errors)) {
|
2021-05-12 18:39:53 +02:00
|
|
|
return ['status' => 'KO', 'code' => 203, 'message' => $errors];
|
2021-07-22 15:14:07 +02:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
return ['status' => 'OK'];
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* @param mixed $fields
|
|
|
|
|
* @param mixed $type
|
|
|
|
|
* @param mixed $customer
|
|
|
|
|
* @param mixed $customerInfos
|
|
|
|
|
* @param mixed $shipping
|
|
|
|
|
* @return string|false
|
|
|
|
|
*/
|
|
|
|
|
// phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Squiz.Commenting.FunctionComment.Missing
|
2021-07-22 15:14:07 +02:00
|
|
|
private function makeXml($fields, $type, $customer, $customerInfos, $shipping)
|
2021-02-19 16:32:08 +01:00
|
|
|
{
|
|
|
|
|
$pivot = [
|
2021-12-19 15:57:24 +01:00
|
|
|
'order_num' => 'Num_Commande',
|
|
|
|
|
// Required if type = default - format 9 numeric characters.
|
|
|
|
|
'order_date' => 'Date_Commande',
|
|
|
|
|
// Required - format : DD/MM/YYYY .
|
|
|
|
|
'operation' => 'Operation',
|
|
|
|
|
// Required.
|
|
|
|
|
'support_code' => 'Code_Support',
|
|
|
|
|
// Required.
|
|
|
|
|
'label_type_support' => 'Libelle_Type_Support',
|
|
|
|
|
// Required.
|
|
|
|
|
'package_unit_weight' => 'Poids_Unitaire_Colis',
|
|
|
|
|
// Required if type = default.
|
2021-02-19 16:32:08 +01:00
|
|
|
'qty' => 'Quantite',
|
|
|
|
|
'code_on_pack' => 'Code_on_Pack',
|
2021-12-19 15:57:24 +01:00
|
|
|
'code_unique' => 'Code_Unique',
|
|
|
|
|
// Required if type = game.
|
|
|
|
|
// Required if type = default - format 1 ou Null (oui Null et pas NULL).
|
2021-02-28 12:04:49 +01:00
|
|
|
'state_order_cb' => 'Etat_Commande_CB',
|
2021-12-19 15:57:24 +01:00
|
|
|
// Required if type = default - format 1 ou Null (oui Null et pas NULL).
|
2021-02-28 12:04:49 +01:00
|
|
|
'state_order_check' => 'Etat_Commande_Cheque',
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
2021-03-14 10:45:42 +01:00
|
|
|
$dom = new DOMDocument('1.0', 'UTF-8');
|
2021-02-19 16:32:08 +01:00
|
|
|
$dom->formatOutput = true;
|
|
|
|
|
|
|
|
|
|
$root = $dom->createElement('export_arcadia');
|
|
|
|
|
$dom->appendChild($root);
|
|
|
|
|
$order = $root->appendChild($dom->createElement('Commande'));
|
|
|
|
|
|
|
|
|
|
$key = array_search('order_num', array_column($fields->root, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$order->appendChild($dom->createElement('Num_Commande'));
|
2021-02-28 12:04:49 +01:00
|
|
|
} else {
|
2021-02-23 15:45:35 +01:00
|
|
|
$order->appendChild($dom->createElement('Num_Commande', $fields->root[$key]->fieldValue));
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
foreach ($fields->root as $value) {
|
|
|
|
|
// phpcs:ignore PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace
|
|
|
|
|
if (
|
|
|
|
|
isset($pivot[$value->fieldName]) && $value->fieldName !== 'state_order_cb' &&
|
|
|
|
|
$value->fieldName !== 'state_order_check' && $value->fieldName !== 'order_num'
|
|
|
|
|
) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$order->appendChild($dom->createElement($pivot[$value->fieldName], $value->fieldValue));
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($type === 'default') {
|
|
|
|
|
$key = array_search('state_order_cb', array_column($fields->root, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$order->appendChild($dom->createElement('Etat_Commande_CB', $fields->root[$key]->fieldValue));
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$key = array_search('state_order_check', array_column($fields->root, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$order->appendChild($dom->createElement('Etat_Commande_Cheque', $fields->root[$key]->fieldValue));
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-22 15:14:07 +02:00
|
|
|
$order->appendChild($dom->createElement('Email_conso'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$customer->email"));
|
2021-02-19 16:32:08 +01:00
|
|
|
$order->appendChild($dom->createElement('Civilite'));
|
2021-05-17 17:39:56 +02:00
|
|
|
|
|
|
|
|
if ($type === 'default') {
|
2021-07-22 15:14:07 +02:00
|
|
|
$order->appendChild($dom->createElement('Nom'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$shipping->lastname"));
|
|
|
|
|
$order->appendChild($dom->createElement('Prenom'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$shipping->firstname"));
|
|
|
|
|
$order->appendChild($dom->createElement('Adresse'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$shipping->address"));
|
2021-05-17 17:39:56 +02:00
|
|
|
$order->appendChild($dom->createElement('Adresse_Complementaire'));
|
2021-07-22 15:14:07 +02:00
|
|
|
$order->appendChild($dom->createElement('CP'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$shipping->postcode"));
|
2021-05-17 17:39:56 +02:00
|
|
|
$order->appendChild($dom->createElement('Ville'))->appendChild($dom->createCDATASection("$shipping->city"));
|
|
|
|
|
if (isset($shipping->phone) && !empty($shipping->phone)) {
|
2021-07-22 15:14:07 +02:00
|
|
|
$order->appendChild($dom->createElement('Telephone'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$shipping->phone"));
|
|
|
|
|
} else {
|
2021-05-17 17:39:56 +02:00
|
|
|
$order->appendChild($dom->createElement('Telephone'));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2021-07-22 15:14:07 +02:00
|
|
|
$order->appendChild($dom->createElement('Nom'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$customerInfos->lastname"));
|
|
|
|
|
$order->appendChild($dom->createElement('Prenom'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$customerInfos->firstname"));
|
|
|
|
|
$order->appendChild($dom->createElement('Adresse'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$customerInfos->address"));
|
|
|
|
|
$order->appendChild($dom->createElement('Adresse_Complementaire'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$customerInfos->address2"));
|
|
|
|
|
$order->appendChild($dom->createElement('CP'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$customerInfos->postcode"));
|
|
|
|
|
$order->appendChild($dom->createElement('Ville'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$customerInfos->city"));
|
|
|
|
|
$order->appendChild($dom->createElement('Telephone'))
|
|
|
|
|
->appendChild($dom->createCDATASection("$customerInfos->phone"));
|
2021-12-19 15:57:24 +01:00
|
|
|
}//end if
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$orderLine = $order->appendChild($dom->createElement('Ligne_de_Commande'));
|
|
|
|
|
|
|
|
|
|
$key = array_search('qty', array_column($fields->orderLine, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$orderLine->appendChild($dom->createElement('Quantite', '1'));
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$key = array_search('package_unit_weight', array_column($fields->orderLine, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key === false) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$orderLine->appendChild($dom->createElement('Poids_Unitaire_Colis'));
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
foreach ($fields->orderLine as $value) {
|
|
|
|
|
// phpcs:ignore PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace
|
|
|
|
|
if (
|
|
|
|
|
isset($pivot[$value->fieldName]) &&
|
|
|
|
|
$value->fieldName !== 'code_on_pack' &&
|
|
|
|
|
$value->fieldName !== 'code_unique'
|
|
|
|
|
) {
|
2021-02-19 16:32:08 +01:00
|
|
|
$orderLine->appendChild($dom->createElement($pivot[$value->fieldName], $value->fieldValue));
|
2021-02-28 12:04:49 +01:00
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($type === 'game') {
|
|
|
|
|
$key = array_search('code_on_pack', array_column($fields->orderLine, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key) {
|
|
|
|
|
$orderLine->appendChild(
|
|
|
|
|
$dom->createElement('Code_on_Pack')
|
|
|
|
|
)->appendChild($dom->createCDATASection($fields->orderLine[$key]->fieldValue));
|
|
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
|
|
|
|
|
$key = array_search('code_unique', array_column($fields->orderLine, 'fieldName'));
|
2021-02-28 12:04:49 +01:00
|
|
|
if ($key) {
|
|
|
|
|
$orderLine->appendChild(
|
|
|
|
|
$dom->createElement('Code_Unique')
|
|
|
|
|
)->appendChild($dom->createCDATASection($fields->orderLine[$key]->fieldValue));
|
|
|
|
|
}
|
2021-02-19 16:32:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $dom->saveXML();
|
|
|
|
|
}
|
|
|
|
|
}
|