Skip to content

Commit

Permalink
Merge pull request #60 from fabianaromagnoli/attribute-translations
Browse files Browse the repository at this point in the history
Make brand, size and color attributes translatable
  • Loading branch information
loevgaard authored Jun 13, 2022
2 parents 08c84fa + b2fdd45 commit 24ff26c
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/FeedContext/Google/Shopping/ProductItemContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Setono\SyliusFeedPlugin\Model\ColorAwareInterface;
use Setono\SyliusFeedPlugin\Model\ConditionAwareInterface;
use Setono\SyliusFeedPlugin\Model\GtinAwareInterface;
use Setono\SyliusFeedPlugin\Model\LocalizedBrandAwareInterface;
use Setono\SyliusFeedPlugin\Model\LocalizedColorAwareInterface;
use Setono\SyliusFeedPlugin\Model\LocalizedSizeAwareInterface;
use Setono\SyliusFeedPlugin\Model\MpnAwareInterface;
use Setono\SyliusFeedPlugin\Model\SizeAwareInterface;
use Setono\SyliusFeedPlugin\Model\TaxonPathAwareInterface;
Expand Down Expand Up @@ -101,8 +104,12 @@ public function getContextList(object $product, ChannelInterface $channel, Local
$data->setProductType($productType);
}

if ($variant instanceof BrandAwareInterface && $variant->getBrand() !== null) {
if ($variant instanceof LocalizedBrandAwareInterface && $variant->getBrand($locale) !== null) {
$data->setBrand((string) $variant->getBrand($locale));
} elseif ($variant instanceof BrandAwareInterface && $variant->getBrand() !== null) {
$data->setBrand((string) $variant->getBrand());
} elseif ($product instanceof LocalizedBrandAwareInterface && $product->getBrand($locale) !== null) {
$data->setBrand((string) $product->getBrand($locale));
} elseif ($product instanceof BrandAwareInterface && $product->getBrand() !== null) {
$data->setBrand((string) $product->getBrand());
}
Expand All @@ -119,14 +126,22 @@ public function getContextList(object $product, ChannelInterface $channel, Local
$data->setMpn((string) $product->getMpn());
}

if ($variant instanceof SizeAwareInterface && $variant->getSize() !== null) {
if ($variant instanceof LocalizedSizeAwareInterface && $variant->getSize($locale) !== null) {
$data->setSize((string) $variant->getSize($locale));
} elseif ($variant instanceof SizeAwareInterface && $variant->getSize() !== null) {
$data->setSize((string) $variant->getSize());
} elseif ($product instanceof LocalizedSizeAwareInterface && $product->getSize($locale) !== null) {
$data->setSize((string) $product->getSize($locale));
} elseif ($product instanceof SizeAwareInterface && $product->getSize() !== null) {
$data->setSize((string) $product->getSize());
}

if ($variant instanceof ColorAwareInterface && $variant->getColor() !== null) {
if ($variant instanceof LocalizedColorAwareInterface && $variant->getColor($locale) !== null) {
$data->setColor((string) $variant->getColor($locale));
} elseif ($variant instanceof ColorAwareInterface && $variant->getColor() !== null) {
$data->setColor((string) $variant->getColor());
} elseif ($product instanceof LocalizedColorAwareInterface && $product->getColor($locale) !== null) {
$data->setColor((string) $product->getColor($locale));
} elseif ($product instanceof ColorAwareInterface && $product->getColor() !== null) {
$data->setColor((string) $product->getColor());
}
Expand Down
4 changes: 4 additions & 0 deletions src/Model/BrandAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace Setono\SyliusFeedPlugin\Model;

/**
* @deprecated since 0.6.6 This interface is deprecated and will be removed in 0.7.0
* Use \Setono\SyliusFeedPlugin\Model\LocalizedBrandAwareInterface instead.
*/
interface BrandAwareInterface
{
/**
Expand Down
4 changes: 4 additions & 0 deletions src/Model/ColorAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace Setono\SyliusFeedPlugin\Model;

/**
* @deprecated since 0.6.6 This interface is deprecated and will be removed in 0.7.0
* Use \Setono\SyliusFeedPlugin\Model\LocalizedColorAwareInterface instead.
*/
interface ColorAwareInterface
{
/**
Expand Down
17 changes: 17 additions & 0 deletions src/Model/LocalizedBrandAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusFeedPlugin\Model;

use Sylius\Component\Locale\Model\LocaleInterface;

interface LocalizedBrandAwareInterface
{
/**
* Must return a string or an object with __toString implemented
*
* @return string|object|null
*/
public function getBrand(LocaleInterface $locale);
}
17 changes: 17 additions & 0 deletions src/Model/LocalizedColorAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusFeedPlugin\Model;

use Sylius\Component\Locale\Model\LocaleInterface;

interface LocalizedColorAwareInterface
{
/**
* Must return a string or an object with __toString implemented
*
* @return string|object|null
*/
public function getColor(LocaleInterface $locale);
}
17 changes: 17 additions & 0 deletions src/Model/LocalizedSizeAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusFeedPlugin\Model;

use Sylius\Component\Locale\Model\LocaleInterface;

interface LocalizedSizeAwareInterface
{
/**
* Must return a string or an object with __toString implemented
*
* @return string|object|null
*/
public function getSize(LocaleInterface $locale);
}
4 changes: 4 additions & 0 deletions src/Model/SizeAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace Setono\SyliusFeedPlugin\Model;

/**
* @deprecated since 0.6.6 This interface is deprecated and will be removed in 0.7.0
* Use \Setono\SyliusFeedPlugin\Model\LocalizedSizeAwareInterface instead.
*/
interface SizeAwareInterface
{
/**
Expand Down

0 comments on commit 24ff26c

Please sign in to comment.