Skip to content

Commit

Permalink
[CatalogPromotion] Fix editing catalog promotion by changing its action
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Nov 24, 2021
1 parent 19df9ba commit 3478fe3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,14 @@ public function iEditCatalogPromotionToHaveFixedDiscountInTheChannel(
ChannelInterface $channel
): void {
$this->client->buildUpdateRequest($catalogPromotion->getCode());
$scopes = [[
$content = $this->client->getContent();

$content['actions'] = [[
'type' => CatalogPromotionActionInterface::TYPE_FIXED_DISCOUNT,
'configuration' => [
'amount' => $amount,
],
'configuration' => [$channel->getCode() => ['amount' => $amount]],
]];

$this->client->updateRequestData(['actions' => $scopes]);
$this->client->setRequestData($content);
$this->client->update();
}

Expand Down Expand Up @@ -801,7 +801,7 @@ public function thisCatalogPromotionShouldHaveFixedDiscountInTheChannel(int $amo
$catalogPromotionActions = $this->responseChecker->getValue($this->client->getLastResponse(), 'actions');

Assert::same($catalogPromotionActions[0]['type'], CatalogPromotionActionInterface::TYPE_FIXED_DISCOUNT);
Assert::same($catalogPromotionActions[0]['configuration']['amount'], $amount);
Assert::same($catalogPromotionActions[0]['configuration'][$channel->getCode()]['amount'], $amount);
}

/**
Expand Down Expand Up @@ -1036,6 +1036,7 @@ public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void
*/
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void
{
$res = $this->client->getLastResponse();
Assert::true(
$this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()),
'Catalog promotion could not be edited'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;
use http\Exception\InvalidArgumentException;
use Sylius\Behat\Element\Admin\CatalogPromotion\FormElementInterface;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\Admin\CatalogPromotion\CreatePageInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event): void {
/** @var CatalogPromotionActionInterface|null $data */
$data = $event->getData();
$form = $event->getForm();

if ($data === null) {
return;
}

$form = $event->getForm();

$actionConfigurationType = $this->actionConfigurationTypes[$data->getType()];
$form->add('configuration', $actionConfigurationType, [
'label' => false,
Expand All @@ -64,12 +64,18 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event): void {
/** @var array|null $data */
$data = $event->getData();
$form = $event->getForm();

if ($data === null) {
return;
}

$form = $event->getForm();
$formData = $form->getData();
if ($formData !== null) {
$formData->setType($data['type']);
$formData->setConfiguration($data['configuration']);
$form->setData($formData);
}

$actionConfigurationType = $this->actionConfigurationTypes[$data['type']];
$form->add('configuration', $actionConfigurationType, [
'label' => false,
Expand Down

0 comments on commit 3478fe3

Please sign in to comment.