Skip to content

Fix parent product price cleared when variant price is changed#2974

Draft
Copilot wants to merge 2 commits into5.0from
copilot/fix-parent-product-price-issue
Draft

Fix parent product price cleared when variant price is changed#2974
Copilot wants to merge 2 commits into5.0from
copilot/fix-parent-product-price-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 16, 2026

Changing a variant's price overwrites the parent product's price/VAT to 0. Root cause: clone on a Doctrine-managed ProductStoreValues entity preserves the id, so persisting the "new" variant entity actually updates the parent's DB record.

Replace clone with factory-created instances in both code paths:

  • preSetData (admin form path): New blank entity via getFactory()->createNew(). The Symfony form submission immediately populates all fields (store, price, taxRule, unitDefinitionPrices), so no property copying needed.
  • save (programmatic path): New entity via factory with explicit copy of store, price, and taxRule from the inherited entity before persist.
// Before: clone retains the parent's Doctrine identity
$productStoreValue = clone $productStoreValue;

// After: fresh entity gets its own INSERT instead of UPDATE on parent
$newStoreValue = $this->getFactory()->createNew();
$newStoreValue->setStore($productStoreValue->getStore());
$newStoreValue->setPrice($productStoreValue->getPrice());
$newStoreValue->setTaxRule($productStoreValue->getTaxRule());

Regression of #1486, previously patched in #1491 for CoreShop 2.2.

Original prompt

This section details on the original issue you should resolve

<issue_title>Price and VAT are cleared on parent product when price of new created variant is changed</issue_title>
<issue_description>Steps to reproduce:

  • Add a product and set its price
  • On CoreShopProduct set "allowInherit" and "allowVariants" to true
  • Add a product variant and change its price
  • The price of parent product will be set to 0

This appears to be a regression of #1486
This patch fixed the issue previously in CoreShop 2.2: https://github.com/coreshop/CoreShop/pull/1491/files

In the current version I've replaced the $storeValuesEntity = clone $storeValuesEntity; with $storeValuesEntity = new ProductStoreValues() and it seems to work correctly in my local environment. However, I don’t fully understand why "clone" doesn't work as expected.
I’m also not sure what the consequences might be if a completely new ProductStoreValues instance is created.

I can create a PR if my changes make sense.</issue_description>

Comments on the Issue (you are @copilot in this section)

@dpfaffenbauer @80Quattro please create a PR and lets see if the tests still run

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Replace clone of ProductStoreValues with new instance creation via factory
to prevent shared Doctrine identity (ID) from causing the parent's database
record to be updated when persisting the variant's store values.

Fixes the regression where changing a variant's price would reset the
parent product's price and VAT to 0.

Co-authored-by: dpfaffenbauer <5981845+dpfaffenbauer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix clearing price and VAT on parent product when variant price changes Fix parent product price cleared when variant price is changed Feb 16, 2026
Copilot AI requested a review from dpfaffenbauer February 16, 2026 15:43
@sonarqubecloud
Copy link

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.

Price and VAT are cleared on parent product when price of new created variant is changed

2 participants