Skip to content

feat(vendor-settings): flat-array Store settings backend (schema, mapper, writer, REST)#3310

Open
MdAsifHossainNadim wants to merge 2 commits into
refactor/simplify-settings-to-flat-arrayfrom
feat/vendor-store-settings-backend
Open

feat(vendor-settings): flat-array Store settings backend (schema, mapper, writer, REST)#3310
MdAsifHossainNadim wants to merge 2 commits into
refactor/simplify-settings-to-flat-arrayfrom
feat/vendor-store-settings-backend

Conversation

@MdAsifHossainNadim

Copy link
Copy Markdown
Contributor

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)

Changes proposed in this Pull Request:

PR 1 of 3 for the vendor Store Settings → React migration (spec: getdokan/plugin-internal-tasks#2115, parent: getdokan/plugin-internal-tasks#1981). This is the pure PHP backend — no UI change, no behavior change for the legacy page.

Serves the plugin-ui flat-array schema with values from dokan_profile_settings and persists through the exact legacy save pipeline, so storage keys and value shapes stay byte-identical and every Pro consumer on the two seams keeps working.

  • Vendor/Settings/Schema/StoreSettingsSchema.php — flat SettingsElement[] (page → subpage → collapsible section cards → fields) with values populated inline. Conditional blocks use the same server-side gates as templates/settings/store-form.php: map only with dokan_has_map_api_key(), ToC only when seller_enable_terms_and_conditions is on, schedule only when appearance store_open_close is on, email visibility hidden per dokan_is_vendor_info_hidden('email'), address handed over when Pro delivery-time is active, catalog-mode per its admin gates. Pro appends via the new dokan_get_vendor_settings_schema filter (mirrors dokan_get_admin_settings_schema).
  • Vendor/Settings/ValueMapper.php — flat field ids → legacy keys. Composites handled bespoke: store_maplocation + find_address; address merges over previous subkeys (preserves store-pickup's location_name); catalog-mode ids → nested catalog_mode array preserving RFQ's request_a_quote_enabled + the legacy forced-off rule. Any Pro-injected field persists via its string legacy_key (defaults to the field id).
  • Vendor/Settings/StoreSettingsWriter.php — the one write path: shallow array_merge, dokan_store_name mirror meta, dokan_store_profile_settings_args filter, canonical meta write, dokan_store_profile_saved( $id, $merged, $prev ). Deliberately never re-applies the legacy dokan_store_time POST-parsing filter (Pro's parser returns null without the legacy nonce and would wipe the schedule on REST saves).
  • REST/VendorStoreSettingsController.phpGET/PUT /dokan/v1/vendor-settings/store on DokanBaseVendorController (vendor-staff aware via get_vendor_id_for_user()), permission dokandar + dokan_view_store_settings_menu. Validation failures return 400 { errors: { field_id: [messages] } } (plugin-ui merges these into per-field errors). Validations use the plugin-ui client contract ([{ rules: 'not_empty', message }]) so one declaration drives both sides; the schedule validator enforces matching g:i a pairs with opening < closing (single Lite slot and Pro multi-slot both accepted). Pro extension filters: dokan_rest_vendor_settings_sanitize_field / dokan_rest_vendor_settings_validate_field.

Related Pull Request(s)

  • PR 2 (React wiring + components) and PR 3 (full page) stack on this branch.

Closes

  • Part of getdokan/plugin-internal-tasks#2115 (section 1–3: data contract, file layout, flat array)

How to test the changes in this Pull Request:

  1. As a logged-in vendor, GET /wp-json/dokan/v1/vendor-settings/store — returns the flat schema with current values; sections respect the admin gates (disable the map API key → store_map_section disappears, etc.).
  2. PUT /wp-json/dokan/v1/vendor-settings/store with { "values": { "store_name": "" } }400 with errors.store_name.
  3. PUT a valid payload → dokan_profile_settings keys/shapes are byte-identical to a legacy form save ('yes'/'no', 'on'/'off', attachment-ID ints, per-day {status, opening_time[], closing_time[]} with g:i a strings); untouched keys (payment, vendor_biography, …) survive; dokan_store_name mirror meta syncs; both legacy seams fire (verify a Seam-B consumer like store-support still persists).
  4. Smoke-tested on this branch: schema builds for a real seller (20 elements, delivery-time active correctly omits the address section) and the route registers.

Changelog entry

Vendor Store Settings flat-array backend

Adds the schema/REST backend for the React vendor Store Settings page. No user-facing change yet: the legacy page keeps rendering and saving as before; storage stays in dokan_profile_settings with unchanged keys and value shapes.

🤖 Generated with Claude Code

…per, writer, REST)

Backend for the vendor Store Settings React migration (PR 1 of 3, spec:
getdokan/plugin-internal-tasks#2115). Serves the plugin-ui flat-array schema
with values from dokan_profile_settings and persists through the exact legacy
pipeline - storage keys and value shapes stay byte-identical.

- StoreSettingsSchema: sections/fields with legacy server-side gating; Pro
  extends via the new dokan_get_vendor_settings_schema filter.
- ValueMapper: flat ids -> legacy keys (composite store_map/address, nested
  catalog_mode preserving RFQ's key + the legacy forced-off rule).
- StoreSettingsWriter: shallow merge, dokan_store_name mirror, both legacy
  seams; never re-applies the legacy dokan_store_time POST filter.
- VendorStoreSettingsController: GET/PUT /dokan/v1/vendor-settings/store,
  400 {errors:{field_id}} contract, g:i a schedule validation, Pro
  sanitize/validate extension filters.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 963ee21d-653c-4414-b0e0-dbebc4513a7c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vendor-store-settings-backend

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…ST saves

Verifier finding (plan-aligner #7): RFQ's Seam-A handler is nonce-guarded
and silent on REST saves, so a React save turning the cart button back on
left request_a_quote_enabled='on' where the identical legacy save writes
'off'. The mapper now applies the same forced-off rule when the key exists,
keeping REST and AJAX saves byte-identical.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant