Warenwirtschaft: AP-13 API-Bestellungen — Protokoll mit SKU-Fehlermarkierung
Neuer Navigationspunkt „API-Bestellungen": jede wp/order-Übertragung wird protokolliert (api_order_logs) — auch abgelehnte (Kunde unbekannt, Bestellung existiert bereits, Speicherfehler). Positionen ohne Produktzuordnung (unbekannte WP-Nummer) markieren den Eintrag rot; das Modal zeigt den Inhalt der Übertragung je Position (SKU, Produkt, Menge, Preis, Meldung übersetzt). Dazu SKU-Konsistenzprüfung auf der Seite: doppelte WP-Nummern aktiver Produkte (Warnung) und aktive Produkte ohne WP-Nummer (aufklappbar). Behebt die stille Lücke, dass „article not found" nur in der API-Antwort unterging und die Position kommentarlos in Bestellung und Bestandsabzug fehlte (Plan §4). ShoppingUserController per Pint formatiert. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
211aeed384
commit
71d5591e7b
8 changed files with 859 additions and 170 deletions
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Inventory;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ApiOrderLog;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* AP-13: Übersicht der über die Partnercenter-API eingegangenen Bestell-Übertragungen.
|
||||
* Einträge mit fehlgeschlagener Produktzuordnung (unbekannte SKU) sind markiert;
|
||||
* das Modal zeigt den Inhalt der Übertragung je Position.
|
||||
*/
|
||||
class ApiOrderLogController extends Controller
|
||||
{
|
||||
private const INDEX_LIMIT = 500;
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->query('all') ? null : self::INDEX_LIMIT;
|
||||
|
||||
$logs = ApiOrderLog::query()
|
||||
->with(['shoppingOrder', 'shoppingUser'])
|
||||
->orderByDesc('id')
|
||||
->when($limit !== null, fn ($query) => $query->limit($limit))
|
||||
->get();
|
||||
|
||||
$errorCount = ApiOrderLog::query()->where('has_errors', true)->count();
|
||||
|
||||
// SKU-Konsistenz (Plan §4): doppelte WP-Nummern brechen die Zuordnung,
|
||||
// aktive Produkte ohne WP-Nummer können nie per API zugeordnet werden.
|
||||
$duplicateNumbers = Product::query()
|
||||
->where('active', true)
|
||||
->whereNotNull('wp_number')
|
||||
->where('wp_number', '!=', 0)
|
||||
->selectRaw('wp_number, COUNT(*) as sku_count')
|
||||
->groupBy('wp_number')
|
||||
->havingRaw('COUNT(*) > 1')
|
||||
->pluck('wp_number');
|
||||
|
||||
$duplicateSkuProducts = $duplicateNumbers->isEmpty()
|
||||
? collect()
|
||||
: Product::query()
|
||||
->where('active', true)
|
||||
->whereIn('wp_number', $duplicateNumbers)
|
||||
->orderBy('wp_number')
|
||||
->orderBy('name')
|
||||
->get(['id', 'name', 'wp_number']);
|
||||
|
||||
$missingSkuProducts = Product::query()
|
||||
->where('active', true)
|
||||
->where(fn ($query) => $query->whereNull('wp_number')->orWhere('wp_number', 0))
|
||||
->orderBy('name')
|
||||
->get(['id', 'name']);
|
||||
|
||||
return view('admin.inventory.api-orders.index', [
|
||||
'logs' => $logs,
|
||||
'listLimit' => $limit,
|
||||
'errorCount' => $errorCount,
|
||||
'duplicateSkuProducts' => $duplicateSkuProducts,
|
||||
'missingSkuProducts' => $missingSkuProducts,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\MailCheckout;
|
||||
use App\Models\ApiOrderLog;
|
||||
use App\Models\Country;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
|
|
@ -10,30 +12,27 @@ use App\Models\ShoppingOrder;
|
|||
use App\Models\ShoppingOrderItem;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\CustomerPriority;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Shop;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PHPUnit\Framework\Constraint\Count;
|
||||
use Yard;
|
||||
|
||||
|
||||
class ShoppingUserController extends Controller
|
||||
{
|
||||
|
||||
//protected static API_MAIL = 'api.thomas.krummel@gmail.com';
|
||||
//protected static API_PASS = 'UF(Q<9knap!ev3vH?5~!b8DP';
|
||||
//URL api.gruene-seele.bio
|
||||
|
||||
// protected static API_MAIL = 'api.thomas.krummel@gmail.com';
|
||||
// protected static API_PASS = 'UF(Q<9knap!ev3vH?5~!b8DP';
|
||||
// URL api.gruene-seele.bio
|
||||
|
||||
protected $successStatus = 200;
|
||||
protected $member_id = 2; //thomas.krummel@gmail.com
|
||||
|
||||
protected $member_id = 2; // thomas.krummel@gmail.com
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_numbers[1234, 1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @param Request $request
|
||||
* wp_order_numbers[1234, 1234]
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function status(Request $request)
|
||||
{
|
||||
|
|
@ -42,24 +41,23 @@ class ShoppingUserController extends Controller
|
|||
'wp_order_numbers' => 'required',
|
||||
]);
|
||||
|
||||
if(!is_array($request->wp_order_numbers)){
|
||||
if (! is_array($request->wp_order_numbers)) {
|
||||
$wp_order_numbers = json_decode($request->wp_order_numbers);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
$wp_order_numbers = $request->wp_order_numbers;
|
||||
}
|
||||
|
||||
|
||||
if(!$wp_order_numbers || !is_array($wp_order_numbers)){
|
||||
if (! $wp_order_numbers || ! is_array($wp_order_numbers)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'wp_order_numbers need as json [1234, 1234] ',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
$status = [];
|
||||
foreach ($wp_order_numbers as $wp_order_number){
|
||||
foreach ($wp_order_numbers as $wp_order_number) {
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $wp_order_number)->first();
|
||||
$status[] = [
|
||||
'wp_order_number' => $wp_order_number,
|
||||
|
|
@ -72,15 +70,15 @@ class ShoppingUserController extends Controller
|
|||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $status,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
|
|
@ -88,31 +86,31 @@ class ShoppingUserController extends Controller
|
|||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found',
|
||||
'order' => false,
|
||||
'status' => false,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if(!$shopping_user->shopping_order){
|
||||
if (! $shopping_user->shopping_order) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' has no order',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' has no order',
|
||||
'order' => false,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if($shopping_user->shopping_order->shipped > 0){
|
||||
if ($shopping_user->shopping_order->shipped > 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' can not cancel',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' can not cancel',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
|
|
@ -121,19 +119,18 @@ class ShoppingUserController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' is cancel',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' is cancel',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function open(Request $request)
|
||||
{
|
||||
|
|
@ -141,31 +138,31 @@ class ShoppingUserController extends Controller
|
|||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found',
|
||||
'order' => false,
|
||||
'status' => false,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if(!$shopping_user->shopping_order){
|
||||
if (! $shopping_user->shopping_order) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' has no order',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' has no order',
|
||||
'order' => false,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if($shopping_user->shopping_order->shipped !== 10){
|
||||
if ($shopping_user->shopping_order->shipped !== 10) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' can not open',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' can not open',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
|
|
@ -174,44 +171,43 @@ class ShoppingUserController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' is open',
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' is open',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_numbers [1234, 1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @param Request $request
|
||||
* wp_order_numbers [1234, 1234]
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(Request $request)
|
||||
{
|
||||
//$this->member_id = auth()->user()->m_sponsor;
|
||||
// $this->member_id = auth()->user()->m_sponsor;
|
||||
$request->validate([
|
||||
'wp_order_numbers' => 'required',
|
||||
]);
|
||||
|
||||
if(!is_array($request->wp_order_numbers)){
|
||||
if (! is_array($request->wp_order_numbers)) {
|
||||
$wp_order_numbers = json_decode($request->wp_order_numbers);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
$wp_order_numbers = $request->wp_order_numbers;
|
||||
}
|
||||
|
||||
if(!$wp_order_numbers || !is_array($wp_order_numbers)){
|
||||
if (! $wp_order_numbers || ! is_array($wp_order_numbers)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'wp_order_numbers need as json [1234, 1234] ',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
$data = [];
|
||||
|
||||
foreach ($wp_order_numbers as $wp_order_number){
|
||||
foreach ($wp_order_numbers as $wp_order_number) {
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $wp_order_number)->first();
|
||||
$user = false;
|
||||
$order = false;
|
||||
|
|
@ -222,22 +218,22 @@ class ShoppingUserController extends Controller
|
|||
$data[] = [
|
||||
'wp_order_number' => $wp_order_number,
|
||||
'user' => $user,
|
||||
'order' => $order,
|
||||
'order' => $order,
|
||||
'customer_number' => $shopping_user ? $shopping_user->number : false,
|
||||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
'status' => $shopping_user ? $shopping_user->getAPIShippedType() : false, ];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $data,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
|
@ -264,11 +260,12 @@ class ShoppingUserController extends Controller
|
|||
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
|
||||
//Kundenhoheit prüfen
|
||||
// Kundenhoheit prüfen
|
||||
$priority = CustomerPriority::checkOne($shopping_user, true, false, true);
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
//exists //like //update
|
||||
Shop::newUserOrder($shopping_user->number);
|
||||
// exists //like //update
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
|
|
@ -278,14 +275,13 @@ class ShoppingUserController extends Controller
|
|||
'customer_number' => $shopping_user->number,
|
||||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
],
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
|
|
@ -293,40 +289,42 @@ class ShoppingUserController extends Controller
|
|||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found',
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
$data = $this->prepareForUpdate($request->all());
|
||||
//Kundenhoheit prüfen
|
||||
// Kundenhoheit prüfen
|
||||
$priority = CustomerPriority::checkChangeOne($shopping_user, $data, true);
|
||||
$updated = $shopping_user->fill($data)->save();
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
Shop::newUserOrder($shopping_user->number);
|
||||
|
||||
if ($updated){
|
||||
if ($updated) {
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
$order = $this->prepareForShowOrder($shopping_user->shopping_order);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'wp_order_number' => $shopping_user->wp_order_number,
|
||||
'user' => $user,
|
||||
'order' => $order,
|
||||
'order' => $order,
|
||||
'customer_priority' => $priority,
|
||||
'customer_number' => $shopping_user ? $shopping_user->number : false,
|
||||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
'status' => $shopping_user ? $shopping_user->getAPIShippedType() : false,
|
||||
],
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry could not be updated'
|
||||
'message' => 'Entry could not be updated',
|
||||
], 500);
|
||||
}
|
||||
|
||||
|
|
@ -337,27 +335,31 @@ class ShoppingUserController extends Controller
|
|||
'wp_order' => 'required',
|
||||
]);
|
||||
|
||||
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
// AP-13: jede eingehende Bestell-Übertragung protokollieren — auch abgelehnte
|
||||
ApiOrderLog::recordFailure($request->wp_order_number, null, $request->wp_order, __('WP-Bestellnummer unbekannt — keine Kundendaten übertragen'));
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found',
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
if($shopping_user->shopping_order){
|
||||
if ($shopping_user->shopping_order) {
|
||||
ApiOrderLog::recordFailure($request->wp_order_number, $shopping_user, $request->wp_order, __('Bestellung existiert bereits — Übertragung abgelehnt'));
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Order with wp_order_number ' . $request->wp_order_number . ' exists',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'message' => 'Order with wp_order_number '.$request->wp_order_number.' exists',
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
if(!is_array($request->wp_order)){
|
||||
if (! is_array($request->wp_order)) {
|
||||
$wp_order = json_decode($request->wp_order);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
$wp_order = $request->wp_order;
|
||||
}
|
||||
|
||||
|
|
@ -372,9 +374,12 @@ class ShoppingUserController extends Controller
|
|||
|
||||
$wp_order = $this->prepareOrder($wp_order, $shopping_user, $wp_invoice_path, $wp_notice);
|
||||
|
||||
if ($wp_order){
|
||||
if ($wp_order) {
|
||||
// AP-13: Übertragung inkl. SKU-Zuordnungsergebnis je Position protokollieren
|
||||
ApiOrderLog::recordTransfer($request->wp_order_number, $shopping_user, $shopping_user->shopping_order, $wp_order);
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
$order = $this->prepareForShowOrder($shopping_user->shopping_order);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
|
|
@ -389,12 +394,14 @@ class ShoppingUserController extends Controller
|
|||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
],
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 200);
|
||||
}
|
||||
ApiOrderLog::recordFailure($request->wp_order_number, $shopping_user, $request->wp_order, __('Bestellung konnte nicht gespeichert werden'));
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Order could not be stored'
|
||||
'message' => 'Order could not be stored',
|
||||
], 500);
|
||||
}
|
||||
|
||||
|
|
@ -404,16 +411,16 @@ class ShoppingUserController extends Controller
|
|||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->where('mode', '=', 'dev')->first();
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found or mode != dev',
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
'message' => 'Entry with wp_order_number '.$request->wp_order_number.' not found or mode != dev',
|
||||
'time' => Carbon::now()->toDateTimeString(),
|
||||
], 400);
|
||||
}
|
||||
$shopping_order = $shopping_user->shopping_order;
|
||||
if($shopping_order){
|
||||
foreach ($shopping_order->shopping_order_items as $shopping_order_item){
|
||||
if ($shopping_order) {
|
||||
foreach ($shopping_order->shopping_order_items as $shopping_order_item) {
|
||||
$shopping_order_item->delete();
|
||||
}
|
||||
$shopping_order->delete();
|
||||
|
|
@ -422,68 +429,72 @@ class ShoppingUserController extends Controller
|
|||
$shopping_user->save();
|
||||
if ($shopping_user->delete()) {
|
||||
return response()->json([
|
||||
'success' => true
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry could not be deleted'
|
||||
'message' => 'Entry could not be deleted',
|
||||
], 500);
|
||||
}
|
||||
|
||||
private function prepareForShow($shopping_user){
|
||||
private function prepareForShow($shopping_user)
|
||||
{
|
||||
|
||||
if(!$shopping_user){
|
||||
if (! $shopping_user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$shopping_user_data = $shopping_user->toArray();
|
||||
$needs = ['wp_order_number', 'wp_order_date', 'billing_company', 'billing_firstname', 'billing_lastname', 'billing_address', 'billing_address_2', 'billing_zipcode', 'billing_city', 'billing_phone', 'billing_email',
|
||||
'same_as_billing', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_phone',
|
||||
'created_at', 'updated_at', 'user_deleted_at']; //'has_buyed', 'subscribed',
|
||||
'created_at', 'updated_at', 'user_deleted_at']; // 'has_buyed', 'subscribed',
|
||||
|
||||
//$salutation = array('mr' => 1, 'ms' => 2);
|
||||
// $salutation = array('mr' => 1, 'ms' => 2);
|
||||
$ret = [];
|
||||
foreach ($shopping_user_data as $key=>$value){
|
||||
foreach ($shopping_user_data as $key => $value) {
|
||||
|
||||
if($key === 'billing_country_id'){
|
||||
if ($key === 'billing_country_id') {
|
||||
$ret['billing_country_code'] = $shopping_user->billing_country_id ? $shopping_user->billing_country->code : null;
|
||||
}
|
||||
if($key === 'shipping_country_id'){
|
||||
if ($key === 'shipping_country_id') {
|
||||
$ret['shipping_country_code'] = $shopping_user->shipping_country_id ? $shopping_user->shipping_country->code : null;
|
||||
}
|
||||
if($key === 'billing_salutation'){
|
||||
if ($key === 'billing_salutation') {
|
||||
$ret['billing_salutation'] = $shopping_user->billing_salutation === 'ms' ? 2 : 1;
|
||||
}
|
||||
if($key === 'shipping_salutation'){
|
||||
if ($key === 'shipping_salutation') {
|
||||
$ret['shipping_salutation'] = $shopping_user->shipping_salutation === 'ms' ? 2 : 1;
|
||||
}
|
||||
|
||||
if(in_array($key, $needs)){
|
||||
if (in_array($key, $needs)) {
|
||||
$ret[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareForShowOrder($shopping_order){
|
||||
private function prepareForShowOrder($shopping_order)
|
||||
{
|
||||
|
||||
if(!$shopping_order){
|
||||
if (! $shopping_order) {
|
||||
return false;
|
||||
}
|
||||
$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),
|
||||
'tax_rate' => ($shopping_order->tax_rate*100),
|
||||
'tax' => ($shopping_order->tax*100),
|
||||
'total_with_shipping' => ($shopping_order->total_shipping*100),
|
||||
'total' => ($shopping_order->total * 100),
|
||||
'shipping' => ($shopping_order->shipping * 100),
|
||||
'total_net' => ($shopping_order->subtotal * 100),
|
||||
'tax_rate' => ($shopping_order->tax_rate * 100),
|
||||
'tax' => ($shopping_order->tax * 100),
|
||||
'total_with_shipping' => ($shopping_order->total_shipping * 100),
|
||||
'weight' => $shopping_order->weight,
|
||||
];
|
||||
$ret['items'] = [];
|
||||
foreach ($shopping_order->shopping_order_items as $item){
|
||||
foreach ($shopping_order->shopping_order_items as $item) {
|
||||
$ret['items'][] = [
|
||||
'article' => $item->product->wp_number,
|
||||
'name' => $item->product->name,
|
||||
|
|
@ -491,64 +502,68 @@ class ShoppingUserController extends Controller
|
|||
'price' => ($item->price * 100),
|
||||
];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareForUpdate($data){
|
||||
private function prepareForUpdate($data)
|
||||
{
|
||||
|
||||
//$salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
|
||||
// $salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
|
||||
|
||||
if(isset($data['billing_salutation'])){
|
||||
$data['billing_salutation'] = (int) $data['billing_salutation'];
|
||||
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';
|
||||
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',
|
||||
$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_country_code' && isset($data['billing_country_code'])) {
|
||||
$ret['billing_country_id'] = Country::getCountryIdByCodeOrOne($data['billing_country_code']);
|
||||
foreach ($data as $key => $value) {
|
||||
if ($key === 'billing_country_code' && isset($data['billing_country_code'])) {
|
||||
$ret['billing_country_id'] = Country::getCountryIdByCodeOrOne($data['billing_country_code']);
|
||||
}
|
||||
if($key === 'shipping_country_code' && isset($data['shipping_country_code']) ) {
|
||||
if ($key === 'shipping_country_code' && isset($data['shipping_country_code'])) {
|
||||
$ret['shipping_country_id'] = Country::getCountryIdByCodeOrOne($data['shipping_country_code']);
|
||||
}
|
||||
if($key === 'billing_phone') {
|
||||
if ($key === 'billing_phone') {
|
||||
$ret['billing_phone'] = strlen($data['billing_phone']) <= 3 ? '' : $data['billing_phone'];
|
||||
}
|
||||
if($key === 'shipping_phone') {
|
||||
if ($key === 'shipping_phone') {
|
||||
$ret['shipping_phone'] = strlen($data['shipping_phone']) <= 3 ? '' : $data['shipping_phone'];
|
||||
}
|
||||
if(in_array($key, $needs)){
|
||||
if (in_array($key, $needs)) {
|
||||
$ret[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareForStore($data){
|
||||
private function prepareForStore($data)
|
||||
{
|
||||
|
||||
//$salutation = array(1 => 'mr', 2 => 'ms', 3=>null);
|
||||
if(isset($data['billing_salutation'])){
|
||||
$data['billing_salutation'] = (int) $data['billing_salutation'];
|
||||
// $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';
|
||||
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',
|
||||
$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',
|
||||
'same_as_billing', //'has_buyed', 'subscribed',
|
||||
'same_as_billing', // 'has_buyed', 'subscribed',
|
||||
'wp_order_number', 'wp_order_date'];
|
||||
|
||||
foreach ($needs as $need){
|
||||
foreach ($needs as $need) {
|
||||
|
||||
$ret[$need] = isset($data[$need]) ? $data[$need] : null;
|
||||
if ($need === 'billing_country_id') {
|
||||
|
|
@ -567,37 +582,38 @@ class ShoppingUserController extends Controller
|
|||
$ret['wp_order_date'] = Carbon::parse($ret['wp_order_date'])->toDateTimeString();
|
||||
}
|
||||
if ($need === 'same_as_billing') {
|
||||
$ret['same_as_billing'] = isset($data['same_as_billing']) ? (int) $data['same_as_billing'] : 1;
|
||||
$ret['same_as_billing'] = isset($data['same_as_billing']) ? (int) $data['same_as_billing'] : 1;
|
||||
}
|
||||
}
|
||||
$ret['has_buyed'] = true;
|
||||
$ret['subscribed'] = false;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user, $wp_invoice_path, $wp_notice){
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user, $wp_invoice_path, $wp_notice)
|
||||
{
|
||||
Yard::instance('shopping')->destroy();
|
||||
$ret = [];
|
||||
|
||||
if(is_array($wp_shopping_order)){
|
||||
if (is_array($wp_shopping_order)) {
|
||||
foreach ($wp_shopping_order as $order) {
|
||||
//$object = json_decode(json_encode($order), FALSE);
|
||||
// $object = json_decode(json_encode($order), FALSE);
|
||||
$order = (object) $order;
|
||||
$error = [];
|
||||
if (!isset($order->article) || !isset($order->qty) || !isset($order->price)) {
|
||||
$error[] = "article parameter is missing";
|
||||
if (! isset($order->article) || ! isset($order->qty) || ! isset($order->price)) {
|
||||
$error[] = 'article parameter is missing';
|
||||
} else {
|
||||
|
||||
$product = Product::whereWpNumber($order->article)->first();
|
||||
if (!$product) {
|
||||
$error[] = "article not found";
|
||||
if (! $product) {
|
||||
$error[] = 'article not found';
|
||||
} else {
|
||||
if ($order->price != ($product->price * 100)) {
|
||||
$error[] = "different price: " . ($product->price * 100);
|
||||
$error[] = 'different price: '.($product->price * 100);
|
||||
}
|
||||
|
||||
|
||||
Yard::instance('shopping')->add($product->id, $product->name, (int) $order->qty, $product->price, $product->tax, ['image' => [], 'slug' => $product->slug, 'weight' => $product->weight]);
|
||||
Yard::instance('shopping')->add($product->id, $product->name, (int) $order->qty, $product->price, $product->tax, ['image' => [], 'slug' => $product->slug, 'weight' => $product->weight]);
|
||||
}
|
||||
}
|
||||
$order->message = $error;
|
||||
|
|
@ -605,7 +621,7 @@ class ShoppingUserController extends Controller
|
|||
}
|
||||
|
||||
$ShippingCountry = ShippingCountry::whereCountryId($shopping_user->shipping_country_id)->first();
|
||||
if($ShippingCountry){
|
||||
if ($ShippingCountry) {
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($ShippingCountry->id, 'ot');
|
||||
}
|
||||
$shopping_order = $this->makeShoppingOrder($shopping_user, $wp_invoice_path, $wp_notice);
|
||||
|
|
@ -614,16 +630,18 @@ class ShoppingUserController extends Controller
|
|||
$shopping_user->shopping_order = $shopping_order;
|
||||
Yard::instance('shopping')->destroy();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function makeShoppingOrder($shopping_user, $wp_invoice_path, $wp_notice){
|
||||
private function makeShoppingOrder($shopping_user, $wp_invoice_path, $wp_notice)
|
||||
{
|
||||
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'auth_user_id' => $shopping_user->auth_user_id,
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
// 'user_shop_id' => auth()->user()->user_sponsor->shop->id,
|
||||
// 'user_shop_id' => auth()->user()->user_sponsor->shop->id,
|
||||
'member_id' => $shopping_user->member_id,
|
||||
'total' => Yard::instance('shopping')->total(2, '.', ''),
|
||||
'subtotal' => Yard::instance('shopping')->subtotal(2, '.', ''),
|
||||
|
|
@ -641,20 +659,20 @@ class ShoppingUserController extends Controller
|
|||
'mode' => $shopping_user->mode,
|
||||
];
|
||||
$shopping_order = $shopping_user->shopping_order;
|
||||
if($shopping_order){
|
||||
if ($shopping_order) {
|
||||
$shopping_order->fill($data);
|
||||
$shopping_order->save();
|
||||
}else{
|
||||
$shopping_order= ShoppingOrder::create($data);
|
||||
} else {
|
||||
$shopping_order = ShoppingOrder::create($data);
|
||||
}
|
||||
$items = Yard::instance('shopping')->content();
|
||||
|
||||
$shopping_order->shopping_order_items()->each(function($model) use ($items, $shopping_order) {
|
||||
$shopping_order->shopping_order_items()->each(function ($model) use ($items, $shopping_order) {
|
||||
foreach ($items as $item) {
|
||||
if ($model->row_id === $item->rowId) {
|
||||
$model->fill([
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
|
|
@ -662,42 +680,43 @@ class ShoppingUserController extends Controller
|
|||
'tax_rate' => $item->taxRate,
|
||||
'slug' => $item->options->slug,
|
||||
])->save();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $model->delete();
|
||||
});
|
||||
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (!ShoppingOrderItem::where('shopping_order_id', $shopping_order->id)->where('row_id', $item->rowId)->count())
|
||||
if (! ShoppingOrderItem::where('shopping_order_id', $shopping_order->id)->where('row_id', $item->rowId)->count()) {
|
||||
ShoppingOrderItem::create([
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
'price_net' => Yard::instance('shopping')->rowPriceNet($item, 3, '.', ''),
|
||||
'tax_rate' => $item->taxRate,
|
||||
'slug' => $item->options->slug
|
||||
'slug' => $item->options->slug,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $shopping_order;
|
||||
}
|
||||
|
||||
|
||||
public function orderStatusSendMail(ShoppingOrder $shopping_order){
|
||||
public function orderStatusSendMail(ShoppingOrder $shopping_order)
|
||||
{
|
||||
|
||||
$bcc = [];
|
||||
$user_mail = ($shopping_order->shopping_user && $shopping_order->shopping_user->member) ? $shopping_order->shopping_user->member->email : false;
|
||||
if($shopping_order->mode === 'dev'){
|
||||
if ($shopping_order->mode === 'dev') {
|
||||
$bcc[] = config('app.checkout_test_mail');
|
||||
}else{
|
||||
} else {
|
||||
$bcc[] = config('app.checkout_mail');
|
||||
}
|
||||
|
||||
Mail::to($user_mail)->bcc($bcc)->send(new MailCheckout($shopping_order->txaction, $shopping_order, null, false, $shopping_order->mode));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue