Skip to content

fix(api): configurable POST creates the variants it receives - #410

Merged
navneetkumar-pim-webkul merged 3 commits into
unopim:masterfrom
dripar-webkul:fix/841-configurable-post-variants
May 26, 2026
Merged

navneetkumar-pim-webkul merged 3 commits into
unopim:masterfrom
dripar-webkul:fix/841-configurable-post-variants

Conversation

@dripar-webkul

Copy link
Copy Markdown
Collaborator

Summary

Fixes #841. POST /api/v1/rest/configrable-products with variants: [{sku, attributes:{}}] silently dropped the variants — parent created, variants: [].

Cause: request()->only(...) whitelist missed 'variants', and the API-facing shape differed from the internal variant_<idx> shape createVariant expects.

Fix

  • Add 'variants' to request()->only(...) in ConfigurableProductController::store.
  • New normalizeVariantsPayload() converts [{sku, attributes:{}}] → ['variant_0' => {sku, values:{common:{...}}}].

Test plan

  • Pest fail-first reproduction (ApiVariantDetachmentTest) — passes after fix
  • Full AdminApi suite — 296 passed / 1677 assertions
  • Pint clean
  • Manual: replay the original Postman call → variant appears in parent's variants on GET

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Admin API configurable product creation so POST /api/v1/rest/(configurable|configrable)-products no longer drops variants from the request payload, aligning the API-facing variant shape with the internal variant_<idx> format used by variant creation.

Changes:

  • Whitelist variants in ConfigurableProductController::store() and normalize [{sku, attributes:{...}}] into the internal variants[variant_<idx>][values][common] structure.
  • Add a Pest regression test to ensure variants provided in the POST payload are created and linked to the configurable parent.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/Webkul/AdminApi/src/Http/Controllers/API/Catalog/ConfigurableProductController.php Accepts variants on configurable product creation and normalizes API payload into internal variant structure.
packages/Webkul/AdminApi/tests/Feature/Catalog/ApiVariantDetachmentTest.php Adds regression coverage to ensure posted variants are created and attached to the parent product.

@navneetkumar-pim-webkul
navneetkumar-pim-webkul merged commit 2b2a649 into unopim:master May 26, 2026
14 checks passed
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.

3 participants