Skip to content

Commit

Permalink
bug Sylius#9919 Sylius#9858 Fix for promotion of 100 percent with cou…
Browse files Browse the repository at this point in the history
…pon (laurent35240)

This PR was merged into the 1.2 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.2
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | fixes Sylius#9858 
| License         | MIT



Commits
-------

c46e7b1 Sylius#9858 Fix for promotion of 100 percent with coupon
9280859 Sylius#9858 Another fix for promotion of 100 percent with coupon
4ef4380 PHPDoc added about transformation
c2af9ea Sylius#9858 Directly change view transformer to percent float when building the form for promotion
  • Loading branch information
Zales0123 authored Nov 30, 2018
2 parents 5113885 + 08b625c commit 27d8601
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Form/DataTransformer/PercentFloatToLocalizedStringTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\PromotionBundle\Form\DataTransformer;

use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer;

final class PercentFloatToLocalizedStringTransformer extends PercentToLocalizedStringTransformer
{
/**
* Transforms between a percentage value into a float
*
* @param string $value Percentage value
*
* @return float Normalized value
*
* @throws TransformationFailedException if the given value is not a string or
* if the value could not be transformed
*/
public function reverseTransform($value)
{
if ('' === $value) {
return;
}
return (float)parent::reverseTransform($value);
}
}
2 changes: 2 additions & 0 deletions Form/Type/Action/PercentageDiscountConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Bundle\PromotionBundle\Form\Type\Action;

use Sylius\Bundle\PromotionBundle\Form\DataTransformer\PercentFloatToLocalizedStringTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PercentType;
use Symfony\Component\Form\FormBuilderInterface;
Expand Down Expand Up @@ -43,6 +44,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
],
])
;
$builder->get('percentage')->resetViewTransformers()->addViewTransformer(new PercentFloatToLocalizedStringTransformer());
}

/**
Expand Down

0 comments on commit 27d8601

Please sign in to comment.