Feat: Moving File Handling To Core

This commit is contained in:
2026-09-25 13:47:58 +03:00
parent 540da1af24
commit a51e9456d6
11 changed files with 134 additions and 218 deletions
@@ -2,13 +2,13 @@ import { Controller } from '@hotwired/stimulus'
// One product custom field of type `file` (see x-product-custom-fields).
// Uploads the photo to the storefront's own endpoint (CustomFieldUploadController)
// as soon as it's picked, then writes the returned opaque reference into the
// hidden input the add-to-cart form actually submits — the checkout module
// never receives the file itself.
// as soon as it's picked, then writes the returned File row's id (boboko-core's
// Modules\Core\File\Models\File) into the hidden input the add-to-cart form
// actually submits — the checkout module never receives the file itself.
//
// While uploading, the file input is marked invalid via setCustomValidity(),
// so the browser's own form validation blocks add-to-cart until the reference
// is in place. A failed upload clears the input, so `required` blocks it too.
// so the browser's own form validation blocks add-to-cart until the id is in
// place. A failed upload clears the input, so `required` blocks it too.
export default class extends Controller {
static targets = ['file', 'reference', 'preview', 'error']
static values = {
@@ -52,12 +52,12 @@ export default class extends Controller {
})
const data = await response.json().catch(() => null)
if (!response.ok || !data?.reference) {
if (!response.ok || !data?.file_id) {
this.fail(data?.error)
return
}
this.referenceTarget.value = data.reference
this.referenceTarget.value = data.file_id
this.showPreview(file)
} catch (error) {
// A newer pick superseded this upload — reset() already handled it.