Skip to content

Commit

Permalink
Merge pull request #2355 from dpfaffenbauer/forms-mapper
Browse files Browse the repository at this point in the history
[OrderBundle] don't modify CartItem twice
  • Loading branch information
dpfaffenbauer authored Aug 2, 2023
2 parents 1c41d07 + 08f6b2e commit 4baa2a3
Showing 1 changed file with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace CoreShop\Bundle\OrderBundle\Form\DataMapper;

use CoreShop\Component\StorageList\StorageListItemQuantityModifierInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Form\DataMapperInterface;

/**
Expand All @@ -40,13 +41,10 @@ public function mapDataToForms($viewData, $forms): void
public function mapFormsToData($forms, &$viewData): void
{
$formsOtherThanQuantity = [];
$quantityForm = null;

//First map all the other fields, then map quantity.
foreach ($forms as $form) {
if ('quantity' === $form->getName()) {
$quantityForm = $form;

$targetQuantity = $form->getData();
$this->cartItemQuantityModifier->modify($viewData, (float) $targetQuantity);

Expand All @@ -57,12 +55,7 @@ public function mapFormsToData($forms, &$viewData): void
}

if (!empty($formsOtherThanQuantity)) {
$this->propertyPathDataMapper->mapFormsToData($formsOtherThanQuantity, $viewData);
}

if (null !== $quantityForm) {
$targetQuantity = $quantityForm->getData();
$this->cartItemQuantityModifier->modify($viewData, (float) $targetQuantity);
$this->propertyPathDataMapper->mapFormsToData(new ArrayCollection($formsOtherThanQuantity), $viewData);
}
}
}

0 comments on commit 4baa2a3

Please sign in to comment.