Created
April 10, 2017 07:19
-
-
Save stefandoorn/b1df6f1ab4a86cc60b5d428eab0fedd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/migrations/Version20170406115337.php b/app/migrations/Version20170406115337.php | |
new file mode 100644 | |
index 0000000..37d72a7 | |
--- /dev/null | |
+++ b/app/migrations/Version20170406115337.php | |
@@ -0,0 +1,34 @@ | |
+<?php | |
+ | |
+namespace Sylius\Migrations; | |
+ | |
+use Doctrine\DBAL\Migrations\AbstractMigration; | |
+use Doctrine\DBAL\Schema\Schema; | |
+ | |
+/** | |
+ * Auto-generated Migration: Please modify to your needs! | |
+ */ | |
+class Version20170406115337 extends AbstractMigration | |
+{ | |
+ /** | |
+ * @param Schema $schema | |
+ */ | |
+ public function up(Schema $schema) | |
+ { | |
+ // this up() migration is auto-generated, please modify it to your needs | |
+ $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | |
+ | |
+ $this->addSql('ALTER TABLE sylius_product_translation ADD slogan VARCHAR(255) DEFAULT NULL'); | |
+ } | |
+ | |
+ /** | |
+ * @param Schema $schema | |
+ */ | |
+ public function down(Schema $schema) | |
+ { | |
+ // this down() migration is auto-generated, please modify it to your needs | |
+ $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | |
+ | |
+ $this->addSql('ALTER TABLE sylius_product_translation DROP slogan'); | |
+ } | |
+} | |
diff --git a/spec/AppBundle/Entity/ProductSpec.php b/spec/AppBundle/Entity/ProductSpec.php | |
index e7b35dc..fcd13d9 100644 | |
--- a/spec/AppBundle/Entity/ProductSpec.php | |
+++ b/spec/AppBundle/Entity/ProductSpec.php | |
@@ -4,6 +4,7 @@ namespace spec\AppBundle\Entity; | |
use AppBundle\DBAL\Types\LadderType; | |
use AppBundle\Entity\Interfaces\ProductInterface; | |
+use AppBundle\Entity\Interfaces\ProductTranslationInterface; | |
use AppBundle\Entity\Product; | |
use PhpSpec\ObjectBehavior; | |
@@ -13,6 +14,7 @@ class ProductSpec extends ObjectBehavior | |
{ | |
$this->shouldHaveType(Product::class); | |
$this->shouldHaveType(ProductInterface::class); | |
+ $this->shouldHaveType(ProductTranslationInterface::class); | |
} | |
function it_should_have_a_default_value() | |
diff --git a/spec/AppBundle/Entity/ProductTranslationSpec.php b/spec/AppBundle/Entity/ProductTranslationSpec.php | |
new file mode 100644 | |
index 0000000..a6a5e7c | |
--- /dev/null | |
+++ b/spec/AppBundle/Entity/ProductTranslationSpec.php | |
@@ -0,0 +1,30 @@ | |
+<?php | |
+ | |
+namespace spec\AppBundle\Entity; | |
+ | |
+use AppBundle\DBAL\Types\LadderType; | |
+use AppBundle\Entity\Interfaces\ProductInterface; | |
+use AppBundle\Entity\Interfaces\ProductTranslationInterface; | |
+use AppBundle\Entity\Product; | |
+use AppBundle\Entity\ProductTranslation; | |
+use PhpSpec\ObjectBehavior; | |
+ | |
+class ProductTranslationSpec extends ObjectBehavior | |
+{ | |
+ function it_is_initializable() | |
+ { | |
+ $this->shouldHaveType(ProductTranslation::class); | |
+ $this->shouldHaveType(ProductTranslationInterface::class); | |
+ } | |
+ | |
+ function it_should_have_no_value_for_slogan_default() | |
+ { | |
+ $this->getSlogan()->shouldReturn(null); | |
+ } | |
+ | |
+ function it_should_accept_a_slogan() | |
+ { | |
+ $this->setSlogan('Super test slogan')->shouldReturn(null); | |
+ $this->getSlogan()->shouldReturn('Super test slogan'); | |
+ } | |
+} | |
diff --git a/src/AppBundle/Entity/Interfaces/ProductInterface.php b/src/AppBundle/Entity/Interfaces/ProductInterface.php | |
index 3cfb39a..3e5cc47 100644 | |
--- a/src/AppBundle/Entity/Interfaces/ProductInterface.php | |
+++ b/src/AppBundle/Entity/Interfaces/ProductInterface.php | |
@@ -9,7 +9,7 @@ use Sylius\Component\Core\Model\ProductVariantInterface; | |
* Interface ProductInterface | |
* @package AppBundle\Entity | |
*/ | |
-interface ProductInterface extends ProductPriceGroupsAwareInterface, LadderAwareInterface, \Sylius\Component\Product\Model\ProductInterface, \Sylius\Component\Core\Model\ProductInterface | |
+interface ProductInterface extends ProductTranslationInterface, ProductPriceGroupsAwareInterface, LadderAwareInterface, \Sylius\Component\Product\Model\ProductInterface, \Sylius\Component\Core\Model\ProductInterface | |
{ | |
/** | |
* | |
diff --git a/src/AppBundle/Entity/Interfaces/ProductTranslationInterface.php b/src/AppBundle/Entity/Interfaces/ProductTranslationInterface.php | |
new file mode 100644 | |
index 0000000..9b3c91e | |
--- /dev/null | |
+++ b/src/AppBundle/Entity/Interfaces/ProductTranslationInterface.php | |
@@ -0,0 +1,20 @@ | |
+<?php | |
+ | |
+namespace AppBundle\Entity\Interfaces; | |
+ | |
+/** | |
+ * Interface ProductTranslationInterface | |
+ * @package AppBundle\Entity\Interfaces | |
+ */ | |
+interface ProductTranslationInterface | |
+{ | |
+ /** | |
+ * @return string | |
+ */ | |
+ public function getSlogan(): ?string; | |
+ | |
+ /** | |
+ * @param string $slogan | |
+ */ | |
+ public function setSlogan(?string $slogan); | |
+} | |
diff --git a/src/AppBundle/Entity/Product.php b/src/AppBundle/Entity/Product.php | |
index 1e89ed2..13eff73 100644 | |
--- a/src/AppBundle/Entity/Product.php | |
+++ b/src/AppBundle/Entity/Product.php | |
@@ -9,12 +9,15 @@ use AppBundle\Entity\Interfaces\ProductInterface; | |
use AppBundle\Entity\Interfaces\ProductOptionInterface; | |
use AppBundle\Entity\Interfaces\ProductOptionValueInterface; | |
use AppBundle\Entity\Interfaces\ProductPriceGroupInterface; | |
+use AppBundle\Entity\Interfaces\ProductTranslationInterface; | |
use AppBundle\Entity\Traits\Ladder; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Doctrine\Common\Collections\Collection; | |
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert; | |
use Sylius\Component\Core\Model\Product as CoreProduct; | |
use Sylius\Component\Core\Model\ProductVariantInterface; | |
+use Sylius\Component\Product\Model\ProductTranslation; | |
+use Sylius\Component\Resource\Model\TranslatableTrait; | |
/** | |
* Class Product | |
@@ -24,6 +27,10 @@ class Product extends CoreProduct implements ProductInterface | |
{ | |
+ use TranslatableTrait { | |
+ __construct as private initializeTranslationsCollection; | |
+ } | |
+ | |
/** | |
* @var string | |
*/ | |
@@ -106,6 +113,26 @@ class Product extends CoreProduct implements ProductInterface | |
/** | |
+ * Product constructor. | |
+ */ | |
+ public function __construct() | |
+ { | |
+ parent::__construct(); | |
+ $this->initializeTranslationsCollection(); | |
+ | |
+ $this->productPriceGroups = new ArrayCollection(); | |
+ $this->calculationStrategy = self::CALCULATION_STRATEGY_DEFAULT; | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public static function getTranslationClass() | |
+ { | |
+ return ProductTranslation::class; | |
+ } | |
+ | |
+ /** | |
* @return int|null | |
*/ | |
public function getBasePrice(): ?int | |
@@ -186,17 +213,6 @@ class Product extends CoreProduct implements ProductInterface | |
} | |
/** | |
- * Product constructor. | |
- */ | |
- public function __construct() | |
- { | |
- parent::__construct(); | |
- | |
- $this->productPriceGroups = new ArrayCollection(); | |
- $this->calculationStrategy = self::CALCULATION_STRATEGY_DEFAULT; | |
- } | |
- | |
- /** | |
* @return string | |
*/ | |
public function getCalculationStrategy(): string | |
@@ -525,4 +541,24 @@ class Product extends CoreProduct implements ProductInterface | |
return $results; | |
} | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function getSlogan(): ?string | |
+ { | |
+ /** @var ProductTranslationInterface $translation */ | |
+ $translation = $this->getTranslation(); | |
+ return $translation->getSlogan(); | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function setSlogan(?string $slogan) | |
+ { | |
+ /** @var ProductTranslationInterface $translation */ | |
+ $translation = $this->getTranslation(); | |
+ $translation->setSlogan($slogan); | |
+ } | |
} | |
diff --git a/src/AppBundle/Entity/ProductTranslation.php b/src/AppBundle/Entity/ProductTranslation.php | |
new file mode 100644 | |
index 0000000..d835593 | |
--- /dev/null | |
+++ b/src/AppBundle/Entity/ProductTranslation.php | |
@@ -0,0 +1,34 @@ | |
+<?php | |
+ | |
+namespace AppBundle\Entity; | |
+ | |
+use AppBundle\Entity\Interfaces\ProductTranslationInterface; | |
+use \Sylius\Component\Core\Model\ProductTranslation as BaseProductTranslation; | |
+ | |
+/** | |
+ * Class ProductTranslation | |
+ * @package AppBundle\Entity | |
+ */ | |
+class ProductTranslation extends BaseProductTranslation implements ProductTranslationInterface | |
+{ | |
+ /** | |
+ * @var string | |
+ */ | |
+ protected $slogan; | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function getSlogan(): ?string | |
+ { | |
+ return $this->slogan; | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function setSlogan(?string $slogan) | |
+ { | |
+ $this->slogan = $slogan; | |
+ } | |
+} | |
diff --git a/src/AppBundle/Form/Extension/ProductTranslationTypeExtension.php b/src/AppBundle/Form/Extension/ProductTranslationTypeExtension.php | |
new file mode 100644 | |
index 0000000..61184e2 | |
--- /dev/null | |
+++ b/src/AppBundle/Form/Extension/ProductTranslationTypeExtension.php | |
@@ -0,0 +1,36 @@ | |
+<?php | |
+ | |
+namespace AppBundle\Form\Extension; | |
+ | |
+use Sylius\Bundle\ProductBundle\Form\Type\ProductTranslationType; | |
+use Symfony\Component\Form\AbstractTypeExtension; | |
+use Symfony\Component\Form\Extension\Core\Type\TextType; | |
+use Symfony\Component\Form\FormBuilderInterface; | |
+ | |
+/** | |
+ * Class ProductTranslationTypeExtension | |
+ * @package AppBundle\Form\Extension | |
+ */ | |
+final class ProductTranslationTypeExtension extends AbstractTypeExtension | |
+{ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function buildForm(FormBuilderInterface $builder, array $options) | |
+ { | |
+ $builder | |
+ ->add('slogan', TextType::class, [ | |
+ 'required' => false, | |
+ 'label' => 'sylius.form.product.slogan', | |
+ ]) | |
+ ; | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function getExtendedType() | |
+ { | |
+ return ProductTranslationType::class; | |
+ } | |
+} | |
diff --git a/src/AppBundle/Resources/config/app/config.yml b/src/AppBundle/Resources/config/app/config.yml | |
index b70c0af..ea323fc 100644 | |
--- a/src/AppBundle/Resources/config/app/config.yml | |
+++ b/src/AppBundle/Resources/config/app/config.yml | |
@@ -4,6 +4,9 @@ sylius_product: | |
classes: | |
model: AppBundle\Entity\Product | |
repository: AppBundle\Repository\ProductRepository | |
+ translation: | |
+ classes: | |
+ model: AppBundle\Entity\ProductTranslation | |
product_option: | |
classes: | |
model: AppBundle\Entity\ProductOption | |
diff --git a/src/AppBundle/Resources/config/doctrine/ProductTranslation.orm.yml b/src/AppBundle/Resources/config/doctrine/ProductTranslation.orm.yml | |
new file mode 100644 | |
index 0000000..7afee10 | |
--- /dev/null | |
+++ b/src/AppBundle/Resources/config/doctrine/ProductTranslation.orm.yml | |
@@ -0,0 +1,7 @@ | |
+AppBundle\Entity\ProductTranslation: | |
+ type: entity | |
+ table: sylius_product_translation | |
+ fields: | |
+ slogan: | |
+ type: string | |
+ nullable: true | |
diff --git a/src/AppBundle/Resources/config/services/app/form/extension/type.yml b/src/AppBundle/Resources/config/services/app/form/extension/type.yml | |
index a9c0dfb..8d77802 100644 | |
--- a/src/AppBundle/Resources/config/services/app/form/extension/type.yml | |
+++ b/src/AppBundle/Resources/config/services/app/form/extension/type.yml | |
@@ -25,3 +25,8 @@ services: | |
+ | |
+ app.form.extension.type.product_translation: | |
+ class: AppBundle\Form\Extension\ProductTranslationTypeExtension | |
+ tags: | |
+ - { name: form.type_extension, extended_type: Sylius\Bundle\ProductBundle\Form\Type\ProductTranslationType } | |
diff --git a/src/AppBundle/Resources/translations/messages.en.yml b/src/AppBundle/Resources/translations/messages.en.yml | |
index 7602d84..b1ac088 100644 | |
--- a/src/AppBundle/Resources/translations/messages.en.yml | |
+++ b/src/AppBundle/Resources/translations/messages.en.yml | |
@@ -1,6 +1,7 @@ | |
sylius: | |
form: | |
product: | |
+ slogan: Slogan | |
diff --git a/src/AppBundle/Resources/translations/messages.nl.yml b/src/AppBundle/Resources/translations/messages.nl.yml | |
index 1c07b98..4c138cb 100644 | |
--- a/src/AppBundle/Resources/translations/messages.nl.yml | |
+++ b/src/AppBundle/Resources/translations/messages.nl.yml | |
@@ -1,6 +1,7 @@ | |
sylius: | |
form: | |
product: | |
+ slogan: Slogan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment