Deploy Ladill Woo Manager / deploy (push) Successful in 51s
Free: 1 store and 20 products. Pro/Business mirrors Invoice pricing (GHS 49/149) with wallet renewals, Paystack prepay, session-based store switcher, and scoped UI. Co-authored-by: Cursor <cursoragent@cursor.com>
75 lines
2.4 KiB
PHP
75 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Woo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Woo\Concerns\ResolvesWooContext;
|
|
use App\Models\WooOrder;
|
|
use App\Services\Woo\FulfillmentSyncService;
|
|
use App\Services\Woo\OrderSyncService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\View\View;
|
|
|
|
class OrderController extends Controller
|
|
{
|
|
use ResolvesWooContext;
|
|
|
|
public function __construct(
|
|
private FulfillmentSyncService $sync,
|
|
private OrderSyncService $orderSync,
|
|
) {}
|
|
|
|
public function index(Request $request): View
|
|
{
|
|
$store = $this->currentStore($request);
|
|
$search = trim((string) $request->query('q', ''));
|
|
|
|
$orders = WooOrder::query()
|
|
->when($store, fn ($q) => $q->where('woo_store_id', $store->id))
|
|
->when(! $store, fn ($q) => $q->whereRaw('1 = 0'))
|
|
->when($search !== '', function ($query) use ($search) {
|
|
$like = '%'.$search.'%';
|
|
$query->where(function ($inner) use ($like) {
|
|
$inner->where('customer_name', 'like', $like)
|
|
->orWhere('customer_email', 'like', $like)
|
|
->orWhere('order_number', 'like', $like);
|
|
});
|
|
})
|
|
->with('store')
|
|
->latest('created_at')
|
|
->paginate(20)
|
|
->withQueryString();
|
|
|
|
return view('woo.orders.index', compact('orders', 'search', 'store'));
|
|
}
|
|
|
|
public function updateStatus(Request $request, WooOrder $order): RedirectResponse
|
|
{
|
|
$store = $this->currentStoreOrFail($request);
|
|
abort_if($order->woo_store_id !== $store->id, 404);
|
|
|
|
$validated = $request->validate([
|
|
'fulfillment_status' => ['required', Rule::in(array_keys(WooOrder::FULFILLMENT_STATUSES))],
|
|
]);
|
|
|
|
$order->update(['fulfillment_status' => $validated['fulfillment_status']]);
|
|
$this->sync->push($order->fresh());
|
|
|
|
return back()->with('success', 'Fulfillment status updated.');
|
|
}
|
|
|
|
public function sync(Request $request): RedirectResponse
|
|
{
|
|
$store = $this->currentStoreOrFail($request);
|
|
$count = $this->orderSync->syncOrders($store);
|
|
|
|
return back()->with('success', sprintf(
|
|
'Synced %d orders from %s.',
|
|
$count,
|
|
$store->site_name ?? $store->site_url,
|
|
));
|
|
}
|
|
}
|