Fix failing build + adjust fixtures and variant behat setup + UPGRADE improvements

This commit is contained in:
Mateusz Zalewski 2016-12-15 14:26:25 +01:00
parent f4bf99f7c2
commit 93a439bb61
No known key found for this signature in database
GPG key ID: CFC1E4176165876B
9 changed files with 66 additions and 10 deletions

View file

@ -46,7 +46,7 @@
### Product / ProductBundle
* `ProductVariant::$name` property (and corresponding getter and setter) was removed to make it translatable. Therefore, `ProductVariantTranslation` was introduced with one `$name` property. All product variants names are migrated to new concept with migration `Version2016121415313`.
* `ProductVariant::$name` property (and corresponding getter and setter) was removed to make it translatable. Therefore, `ProductVariantTranslation` was introduced with one `$name` property. All product variants names are migrated to new concept with migration `Version2016121415313`. Look at [this PR](https://github.com/Sylius/Sylius/pull/7091) if you have any problems with upgrade.
### Promotion / PromotionBundle

View file

@ -31,7 +31,7 @@ class Version20161214153137 extends AbstractMigration implements ContainerAwareI
$defaultLocale = $this->container->getParameter('locale');
$this->addSql('CREATE TABLE sylius_product_variant_translation (id INT AUTO_INCREMENT NOT NULL, translatable_id INT NOT NULL, name VARCHAR(255) NOT NULL, locale VARCHAR(255) NOT NULL, INDEX IDX_8DC18EDC2C2AC5D3 (translatable_id), UNIQUE INDEX sylius_product_variant_translation_uniq_trans (translatable_id, locale), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE sylius_product_variant_translation (id INT AUTO_INCREMENT NOT NULL, translatable_id INT NOT NULL, name VARCHAR(255) DEFAULT NULL, locale VARCHAR(255) NOT NULL, INDEX IDX_8DC18EDC2C2AC5D3 (translatable_id), UNIQUE INDEX sylius_product_variant_translation_uniq_trans (translatable_id, locale), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE sylius_product_variant_translation ADD CONSTRAINT FK_8DC18EDC2C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES sylius_product_variant (id) ON DELETE CASCADE');
$this->addSql('INSERT INTO sylius_product_variant_translation (translatable_id, name, locale) SELECT id, name, "'.$defaultLocale.'" from sylius_product_variant WHERE sylius_product_variant.name IS NOT null');
$this->addSql('ALTER TABLE sylius_product_variant DROP name');

View file

@ -810,6 +810,7 @@ final class ProductContext implements Context
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->defaultVariantResolver->getVariant($product);
$productVariant->setName($productName);
if (null === $channel && $this->sharedStorage->has('channel')) {
$channel = $this->sharedStorage->get('channel');

View file

@ -56,12 +56,13 @@ final class ProductVariantContext implements Context
sprintf('%d products has been found with name "%s".', count($products), $productName)
);
$productVariant = $this->productVariantRepository->findOneBy(['name' => $variantName, 'product' => $products[0]]);
if (null === $productVariant) {
throw new \InvalidArgumentException(sprintf('Product variant with name "%s" of product "%s" does not exist', $variantName, $productName));
}
$productVariants = $this->productVariantRepository->findByNameAndProduct($variantName, 'en_US', $products[0]);
Assert::notEmpty(
$productVariants,
sprintf('Product variant with name "%s" of product "%s" does not exist', $variantName, $productName)
);
return $productVariant;
return $productVariants[0];
}
/**
@ -71,7 +72,7 @@ final class ProductVariantContext implements Context
*/
public function getProductVariantByName($name)
{
$productVariants = $this->productVariantRepository->findBy(['name' => $name]);
$productVariants = $this->productVariantRepository->findByName($name, 'en_US');
Assert::eq(
1,

View file

@ -13,7 +13,6 @@
<h4 class="ui dividing header">{{ 'sylius.ui.availability'|trans }}</h4>
{{ form_row(form.channels) }}
</div>
{{ translationForm(form.translations) }}
<div class="ui styled fluid accordion">
{% for locale, translationForm in form.translations %}
<div class="title{% if 0 == loop.index0 %} active{% endif %}">

View file

@ -320,6 +320,7 @@ class ProductExampleFactory extends AbstractExampleFactory implements ExampleFac
$i = 0;
/** @var ProductVariantInterface $productVariant */
foreach ($product->getVariants() as $productVariant) {
$productVariant->setName($this->faker->word);
$productVariant->setAvailableOn($this->faker->dateTimeThisYear);
$productVariant->setCode(sprintf('%s-variant-%d', $options['code'], $i));
$productVariant->setOnHand($this->faker->randomNumber(1));

View file

@ -12,6 +12,8 @@
namespace Sylius\Bundle\ProductBundle\Doctrine\ORM;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\ProductVariantInterface;
use Sylius\Component\Product\Repository\ProductVariantRepositoryInterface;
/**
@ -30,4 +32,38 @@ class ProductVariantRepository extends EntityRepository implements ProductVarian
->setParameter('productId', $productId)
;
}
/**
* {@inheritdoc}
*/
public function findByName($name, $locale)
{
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation')
->andWhere('translation.name = :name')
->andWhere('translation.locale = :locale')
->setParameter('name', $name)
->setParameter('locale', $locale)
->getQuery()
->getResult()
;
}
/**
* {@inheritdoc}
*/
public function findByNameAndProduct($name, $locale, ProductInterface $product)
{
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation')
->andWhere('translation.name = :name')
->andWhere('translation.locale = :locale')
->andWhere('o.product = :product')
->setParameter('name', $name)
->setParameter('locale', $locale)
->setParameter('product', $product)
->getQuery()
->getResult()
;
}
}

View file

@ -18,7 +18,7 @@
<generator strategy="AUTO" />
</id>
<field name="name" column="name" type="string" />
<field name="name" column="name" type="string" nullable="true" />
</mapped-superclass>
</doctrine-mapping>

View file

@ -12,6 +12,7 @@
namespace Sylius\Component\Product\Repository;
use Doctrine\ORM\QueryBuilder;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\ProductVariantInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
@ -26,4 +27,21 @@ interface ProductVariantRepositoryInterface extends RepositoryInterface
* @return QueryBuilder
*/
public function createQueryBuilderByProductId($productId);
/**
* @param string $name
* @param string $locale
*
* @return ProductVariantInterface[]
*/
public function findByName($name, $locale);
/**
* @param string $name
* @param string $locale
* @param ProductInterface $product
*
* @return ProductVariantInterface[]
*/
public function findByNameAndProduct($name, $locale, ProductInterface $product);
}