3.2 KiB
3.2 KiB
task, cycles, context, private, started, finished
| task | cycles | context | private | started | finished |
|---|---|---|---|---|---|
| Fix POS Main not showing products assigned to store; update dictionary | 5 | true | false | 2026-05-16T00:00:00Z | 2026-05-16T00:01:00Z |
files
- app/Http/Controllers/Market/ProductController.php [lines 561-633] — listProductsData: contains the if/elseif/elseif bug
- resources/js/stores/pos.js [lines 40-85] — fetchProducts: sends access_key + store_hash + session_hash
- resources/js/composables/Market/usePosSession.js [lines 25-78] — initialize: orchestrates session/product load order
- ai-docs/dictionary.md — project dictionary to be updated with root cause pattern
steps
- In
app/Http/Controllers/Market/ProductController.phpatlistProductsData(line 580-592), replace theif/elseif/elseifchain with sequentialif (!$targetStore && ...)checks so that all three lookup paths (access_key → session_hash → store_hash) are tried in order regardless of which params are present. - Update
ai-docs/dictionary.mdunder the "POS (Point of Sale)" section to document this pattern:listProductsDataMUST use sequentialif (!$targetStore)guards, NOTif/elseif, so a stale/invalid access_key does not silently block the store_hash and session_hash fallbacks.
context
Root cause
listProductsData (ProductController.php line 580-592):
if ($accessKey) {
$keyObj = PosAccessKey::where('access_key', $accessKey)->first();
if ($keyObj) { $targetStore = $keyObj->store; }
} elseif ($sessionHash) { // ← NEVER REACHED when access_key is present
...
} elseif ($storeHash) { // ← NEVER REACHED when access_key is present
...
}
If access_key is in the request (from localStorage) but doesn't match any pos_access_keys row (stale, revoked, or a session-specific token), $targetStore stays null and the store_hash/session_hash fallbacks are silently skipped. The result is all global active products are shown instead of the store's assigned products.
Fix (ProductController.php lines 580-592)
Replace with:
if ($accessKey) {
$keyObj = PosAccessKey::where('access_key', $accessKey)->first();
if ($keyObj) {
$targetStore = $keyObj->store;
}
}
if (!$targetStore && $sessionHash) {
$sessionObj = PosSession::where('hashkey', $sessionHash)->first();
if ($sessionObj) {
$targetStore = $sessionObj->store;
}
}
if (!$targetStore && $storeHash) {
$targetStore = Store::where('hashkey', $storeHash)->first();
}
Frontend sends all three params (pos.js lines 53-56)
if (accessKey) params.access_key = accessKey
if (storeHash) params.store_hash = storeHash
if (this.activeSession) params.session_hash = this.activeSession.hashkey
So the fix only needs to be backend-side.
Dictionary addition
Add under "POS (Point of Sale)" in dictionary.md:
- listProductsData store resolution: Must use sequential
if (!$targetStore)guards, NOTif/elseif. A staleaccess_keyin localStorage should not blockstore_hash/session_hashfallbacks. Priority order: access_key → session_hash → store_hash.
notes
- dictionary: ai-docs/dictionary.md
- linters: phpcs, eslint, tsc
- constraints: Hypervel/Hyperf project — use Hypervel imports, not Illuminate