User Order step1
This commit is contained in:
parent
eb55b01b0d
commit
a5db985ae8
90 changed files with 6439 additions and 421 deletions
|
|
@ -229,6 +229,7 @@ class ShoppingUserController extends Controller
|
|||
'wp_order' => 'required',
|
||||
]);
|
||||
|
||||
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
return response()->json([
|
||||
|
|
@ -251,7 +252,10 @@ class ShoppingUserController extends Controller
|
|||
}else{
|
||||
$wp_order = $request->wp_order;
|
||||
}
|
||||
$wp_order = $this->prepareOrder($wp_order, $shopping_user);
|
||||
|
||||
$wp_invoice_path = isset($request->wp_invoice_path) ? $request->wp_invoice_path : null;
|
||||
$wp_order = $this->prepareOrder($wp_order, $shopping_user, $wp_invoice_path);
|
||||
|
||||
//TODO Status
|
||||
if ($wp_order){
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
|
|
@ -260,6 +264,7 @@ class ShoppingUserController extends Controller
|
|||
'success' => true,
|
||||
'data' => [
|
||||
'wp_order_number' => $shopping_user->wp_order_number,
|
||||
'wp_invoice_path' => $wp_invoice_path,
|
||||
'wp_order' => $wp_order,
|
||||
'user' => $user,
|
||||
'order' => $order,
|
||||
|
|
@ -351,6 +356,7 @@ class ShoppingUserController extends Controller
|
|||
}
|
||||
$ret = [
|
||||
'country' => isset($shopping_order->shipping_country->country->code) ? $shopping_order->shipping_country->country->code : '',
|
||||
'wp_invoice_path' => $shopping_order->wp_invoice_path,
|
||||
'total' => ($shopping_order->total*100),
|
||||
'shipping' => ($shopping_order->shipping*100),
|
||||
'total_net' => ($shopping_order->subtotal*100),
|
||||
|
|
@ -374,18 +380,21 @@ class ShoppingUserController extends Controller
|
|||
private function prepareForUpdate($data){
|
||||
|
||||
//$salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
|
||||
|
||||
if(isset($data['billing_salutation'])){
|
||||
$data['billing_salutation'] = (int) $data['billing_salutation'];
|
||||
$data['billing_salutation'] = $data['billing_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
if(isset($data['shipping_salutation'])){
|
||||
$data['shipping_salutation'] = (int) $data['shipping_salutation'];
|
||||
$data['shipping_salutation'] = $data['shipping_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
$needs = [ 'billing_salutation', 'billing_company', 'billing_firstname', 'billing_lastname', 'billing_address', 'billing_address_2', 'billing_zipcode', 'billing_city', 'billing_phone', 'billing_email', 'same_as_billing',
|
||||
'shipping_salutation', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_phone'];
|
||||
|
||||
foreach ($data as $key=>$value){
|
||||
|
||||
if($key === 'billing_salutation') {
|
||||
$ret['billing_salutation'] = $data['billing_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
if($key === 'shipping_salutation') {
|
||||
$ret['shipping_salutation'] = $data['shipping_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
if($key === 'billing_country_code' && isset($data['billing_country_code'])) {
|
||||
$ret['billing_country_id'] = Country::getCountryIdByCodeOrOne($data['billing_country_code']);
|
||||
}
|
||||
|
|
@ -408,6 +417,14 @@ class ShoppingUserController extends Controller
|
|||
private function prepareForStore($data){
|
||||
|
||||
//$salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
|
||||
if(isset($data['billing_salutation'])){
|
||||
$data['billing_salutation'] = (int) $data['billing_salutation'];
|
||||
$data['billing_salutation'] = $data['billing_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
if(isset($data['shipping_salutation'])){
|
||||
$data['shipping_salutation'] = (int) $data['shipping_salutation'];
|
||||
$data['shipping_salutation'] = $data['shipping_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
$ret = [];
|
||||
$needs = [ 'billing_salutation', 'billing_company', 'billing_firstname', 'billing_lastname', 'billing_address', 'billing_address_2', 'billing_zipcode', 'billing_city', 'billing_country_id', 'billing_phone', 'billing_email',
|
||||
'shipping_salutation', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_country_id', 'shipping_phone',
|
||||
|
|
@ -417,13 +434,6 @@ class ShoppingUserController extends Controller
|
|||
foreach ($needs as $need){
|
||||
|
||||
$ret[$need] = isset($data[$need]) ? $data[$need] : null;
|
||||
|
||||
if ($need === 'billing_salutation' && $ret[$need] !== null) {
|
||||
$ret['billing_salutation'] = $ret['billing_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
if ($need === 'shipping_salutation' && $ret[$need] !== null) {
|
||||
$ret['shipping_salutation'] = $ret['shipping_salutation'] == 2 ? 'ms' : 'mr';
|
||||
}
|
||||
if ($need === 'billing_country_id') {
|
||||
$ret['billing_country_id'] = isset($data['billing_country_code']) ? Country::getCountryIdByCodeOrOne($data['billing_country_code']) : 1;
|
||||
}
|
||||
|
|
@ -448,7 +458,7 @@ class ShoppingUserController extends Controller
|
|||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user){
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user, $wp_invoice_path){
|
||||
Yard::instance('shopping')->destroy();
|
||||
$ret = [];
|
||||
|
||||
|
|
@ -479,14 +489,14 @@ class ShoppingUserController extends Controller
|
|||
if($ShippingCountry){
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($ShippingCountry->id);
|
||||
}
|
||||
$shopping_order = $this->makeShoppingOrder($shopping_user);
|
||||
$shopping_order = $this->makeShoppingOrder($shopping_user, $wp_invoice_path);
|
||||
$shopping_user->shopping_order = $shopping_order;
|
||||
Yard::instance('shopping')->destroy();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function makeShoppingOrder($shopping_user){
|
||||
private function makeShoppingOrder($shopping_user, $wp_invoice_path){
|
||||
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
|
|
@ -503,6 +513,7 @@ class ShoppingUserController extends Controller
|
|||
'weight' => Yard::instance('shopping')->weight(),
|
||||
'paid' => true,
|
||||
'txaction' => 'extern',
|
||||
'wp_invoice_path' => $wp_invoice_path,
|
||||
'mode' => $shopping_user->mode,
|
||||
];
|
||||
$shopping_order = $shopping_user->shopping_order;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue