- Update shipping for order
This commit is contained in:
parent
cb9bba67b5
commit
69256faaeb
1 changed files with 55 additions and 9 deletions
|
|
@ -21,6 +21,7 @@ class ArcadiaController extends Controller
|
|||
'crm_id' => 'required',
|
||||
'fields' => 'required|json',
|
||||
'type' => 'required',
|
||||
'shipping' => 'required_if:type,default|json'
|
||||
]);
|
||||
|
||||
if ($validator->fails())
|
||||
|
|
@ -30,6 +31,7 @@ class ArcadiaController extends Controller
|
|||
$crmId = $request->crm_id;
|
||||
$fields = json_decode($request->fields);
|
||||
$type = $request->type;
|
||||
$shipping = $type === 'default' ? json_decode($request->shipping) : false;
|
||||
|
||||
$customer = Customer::where('id', $crmId)->first();
|
||||
if (!$customer)
|
||||
|
|
@ -44,7 +46,13 @@ class ArcadiaController extends Controller
|
|||
if ($check['status'] !== 'OK')
|
||||
return new StatusResource($check);
|
||||
|
||||
$xml = $this->makeXML($fields, $type, $customer, $customerInfos);
|
||||
if ($type === 'default') {
|
||||
$check = $this->checkShippingRequiredFields($shipping);
|
||||
if ($check['status'] !== 'OK')
|
||||
return new StatusResource($check);
|
||||
}
|
||||
|
||||
$xml = $this->makeXML($fields, $type, $customer, $customerInfos, $shipping);
|
||||
|
||||
try {
|
||||
Storage::disk('arcadia')->put(date ("Ymd_His") . microtime(true) . ".xml", $xml);
|
||||
|
|
@ -57,6 +65,29 @@ class ArcadiaController extends Controller
|
|||
|
||||
}
|
||||
|
||||
private function checkShippingRequiredFields($fields)
|
||||
{
|
||||
$test = [
|
||||
'firstname',
|
||||
'lastname',
|
||||
'address',
|
||||
'city',
|
||||
'postcode'
|
||||
];
|
||||
|
||||
foreach ($test as $t) {
|
||||
if (!array_key_exists($t, $fields)){
|
||||
$errors[] = ['field' => $t, 'error' => 'required'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($errors))
|
||||
return ['status' => 'KO', 'code' => 203, 'message' => $errors];
|
||||
|
||||
return ['status' => 'OK'];
|
||||
|
||||
}
|
||||
|
||||
private function checkRequiredFields($fields, $type)
|
||||
{
|
||||
$errors = [];
|
||||
|
|
@ -129,7 +160,7 @@ class ArcadiaController extends Controller
|
|||
return ['status' => 'OK'];
|
||||
}
|
||||
|
||||
private function makeXML($fields, $type, $customer, $customerInfos)
|
||||
private function makeXML($fields, $type, $customer, $customerInfos, $shipping)
|
||||
{
|
||||
$pivot = [
|
||||
'order_num' => 'Num_Commande', // required if type = default - format 9 numeric characters
|
||||
|
|
@ -176,13 +207,28 @@ class ArcadiaController extends Controller
|
|||
|
||||
$order->appendChild($dom->createElement('Email_conso'))->appendChild($dom->createCDATASection( "$customer->email"));
|
||||
$order->appendChild($dom->createElement('Civilite'));
|
||||
$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"));
|
||||
|
||||
if ($type === 'default') {
|
||||
$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"));
|
||||
$order->appendChild($dom->createElement('Adresse_Complementaire'));
|
||||
$order->appendChild($dom->createElement('CP'))->appendChild($dom->createCDATASection("$shipping->postcode"));
|
||||
$order->appendChild($dom->createElement('Ville'))->appendChild($dom->createCDATASection("$shipping->city"));
|
||||
if (isset($shipping->phone) && !empty($shipping->phone)) {
|
||||
$order->appendChild($dom->createElement('Telephone'))->appendChild($dom->createCDATASection("$shipping->phone"));
|
||||
}else{
|
||||
$order->appendChild($dom->createElement('Telephone'));
|
||||
}
|
||||
} else {
|
||||
$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"));
|
||||
}
|
||||
|
||||
$orderLine = $order->appendChild($dom->createElement('Ligne_de_Commande'));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue