Link retail POS products to the CRM products API (restaurant stays local)
Deploy Ladill POS / deploy (push) Successful in 28s

Products are now mode-aware:
- Retail: the catalog lives in Ladill CRM. The Products page proxies CRUD to the
  CRM products API (CrmClient gains product/create/update/delete), and the
  register reads CRM products live; a sold line is stored as a name/price
  snapshot (product_id null, since CRM products aren't local rows). Resilient —
  the register shows an empty catalog if CRM is unreachable. CRM import is hidden
  in Settings (not needed when reading live).
- Restaurant: unchanged — the local pos_products catalog keeps its POS-only depth
  (category, kitchen station, course, modifier groups).

ProductController routes take a raw {product} id (CRM id in retail, local id in
restaurant). Suite green (17), covering both modes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
isaacclad
2026-06-25 12:27:19 +00:00
co-authored by Claude Opus 4.8
parent 0d816daed3
commit 5d8e185223
10 changed files with 377 additions and 61 deletions
@@ -26,18 +26,44 @@ class RegisterController extends Controller
$owner = $this->ownerRef($request);
$location = $this->locations->ensureDefault($owner);
$products = PosProduct::owned($owner)
->active()
->orderBy('name')
->get();
return view('pos.register', [
'products' => $products,
'products' => $this->registerProducts($owner, $location),
'location' => $location,
'crmCustomers' => $this->crmCustomers($owner),
]);
}
/**
* Register catalog: local pos_products in restaurant mode, live CRM products
* in retail mode (resilient empty if CRM is unreachable).
*
* @return list<array{id: int|string|null, name: string, price_minor: int}>
*/
private function registerProducts(string $owner, PosLocation $location): array
{
if ($location->isRestaurant()) {
return PosProduct::owned($owner)->active()->orderBy('name')->get()
->map(fn (PosProduct $p) => ['id' => $p->id, 'name' => $p->name, 'price_minor' => $p->price_minor])
->all();
}
try {
$rows = (array) (CrmClient::for($owner)->products(['type' => 'product', 'active' => 1, 'per_page' => 500])['data'] ?? []);
} catch (\Throwable) {
$rows = [];
}
return collect($rows)
->map(fn ($r) => [
'id' => $r['id'] ?? null,
'name' => (string) ($r['name'] ?? ''),
'price_minor' => (int) ($r['unit_price_minor'] ?? 0),
])
->filter(fn ($r) => $r['name'] !== '' && $r['price_minor'] > 0)
->values()
->all();
}
/** Quick switch between retail and restaurant service from the register. */
public function setMode(Request $request): RedirectResponse
{
@@ -81,8 +107,14 @@ class RegisterController extends Controller
$merchant = ladill_account() ?? $request->user();
$location = $this->locations->ensureDefault($this->ownerRef($request));
$lines = $data['lines'];
if (! $location->isRestaurant()) {
// Retail lines reference CRM products, not local pos_products — keep a name/price snapshot only.
$lines = array_map(fn ($l) => [...$l, 'product_id' => null], $lines);
}
try {
$sale = $this->sales->createSale($merchant, $data['lines'], [
$sale = $this->sales->createSale($merchant, $lines, [
'location_id' => $location->id,
'currency' => $location->currency,
'customer_name' => $data['customer_name'] ?? null,