Skip to content

Commit

Permalink
Modify AppliedPromotionInformationFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomanhez committed Sep 10, 2021
1 parent fc76adb commit e95b297
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
11 changes: 7 additions & 4 deletions Formatter/AppliedPromotionInformationFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ final class AppliedPromotionInformationFormatter implements AppliedPromotionInfo
{
public function format(CatalogPromotionInterface $catalogPromotion): array
{
$translationLabels = [];

/** @var CatalogPromotionTranslationInterface $translation */
$translation = $catalogPromotion->getTranslations()->first();
foreach ($catalogPromotion->getTranslations() as $translation) {
$translationLabels[$translation->getLocale()] = ['name' => $translation->getLabel()];
}

/** @var string $code */
$code = $catalogPromotion->getCode();
/** @var string $name */
$name = $translation->getLabel();

return [$code => ['name' => $name]];
return [$code => $translationLabels];
}
}
3 changes: 1 addition & 2 deletions Formatter/AppliedPromotionInformationFormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

use Sylius\Component\Core\Model\CatalogPromotionInterface;

interface
AppliedPromotionInformationFormatterInterface
interface AppliedPromotionInformationFormatterInterface
{
public function format(CatalogPromotionInterface $catalogPromotion): array;
}
1 change: 0 additions & 1 deletion Processor/CatalogPromotionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Sylius\Component\Core\Model\CatalogPromotionInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Provider\CatalogPromotionVariantsProviderInterface;
use Sylius\Component\Promotion\Model\CatalogPromotionActionInterface;

final class CatalogPromotionProcessor implements CatalogPromotionProcessorInterface
{
Expand Down
5 changes: 3 additions & 2 deletions spec/Formatter/AppliedPromotionInformationFormatterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ function it_formats_applied_promotion_information(
): void {
$catalogPromotion->getTranslations()->willReturn(new ArrayCollection([$translation->getWrappedObject()]));

$catalogPromotion->getCode()->willReturn('winter_sale');
$translation->getLabel()->willReturn('Winter sale');
$translation->getLocale()->willReturn('en_US');
$catalogPromotion->getCode()->willReturn('winter_sale');

$this->format($catalogPromotion)->shouldReturn(['winter_sale' => ['name' => 'Winter sale']]);
$this->format($catalogPromotion)->shouldReturn(['winter_sale' => ['en_US' => ['name' => 'Winter sale']]]);
}
}

0 comments on commit e95b297

Please sign in to comment.