Skip to content

Commit

Permalink
[Order] Remove immutable prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Oct 26, 2017
1 parent e303299 commit 539afbf
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions app/migrations/Version20170913125128.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ 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_order_item ADD immutable_product_name VARCHAR(255), ADD immutable_variant_name VARCHAR(255)');
$this->addSql('ALTER TABLE sylius_order_item ADD product_name VARCHAR(255), ADD variant_name VARCHAR(255)');

$this->addSql('UPDATE sylius_order_item
INNER JOIN sylius_order AS o ON sylius_order_item.order_id = o.id
INNER JOIN sylius_product_variant AS pv ON sylius_order_item.variant_id = pv.id
INNER JOIN sylius_product AS p ON pv.product_id = p.id
INNER JOIN sylius_product_translation AS pt ON pt.translatable_id = p.id
INNER JOIN sylius_order AS ol ON pt.locale = ol.locale_code
SET sylius_order_item.immutable_product_name = pt.name
SET sylius_order_item.product_name = pt.name
');
$this->addSql('UPDATE sylius_order_item
INNER JOIN sylius_order AS o ON sylius_order_item.order_id = o.id
INNER JOIN sylius_product_variant AS pv ON sylius_order_item.variant_id = pv.id
INNER JOIN sylius_product_variant_translation AS pvt ON pvt.translatable_id = pv.id
INNER JOIN sylius_order AS ol ON pvt.locale = ol.locale_code
SET sylius_order_item.immutable_variant_name = pvt.name
SET sylius_order_item.variant_name = pvt.name
');

$this->addSql('ALTER TABLE sylius_order_item CHANGE immutable_product_name immutable_product_name VARCHAR(255) DEFAULT NULL, CHANGE immutable_variant_name immutable_variant_name VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE sylius_order_item CHANGE product_name product_name VARCHAR(255) DEFAULT NULL, CHANGE variant_name variant_name VARCHAR(255) DEFAULT NULL');
}

/**
Expand All @@ -48,6 +48,6 @@ 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_order_item DROP immutable_product_name, DROP immutable_variant_name');
$this->addSql('ALTER TABLE sylius_order_item DROP product_name, DROP variant_name');
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="ui header">
{% include '@SyliusAdmin/Product/_mainImage.html.twig' with {'product': product, 'filter': 'sylius_admin_product_tiny_thumbnail'} %}
<div class="content">
<div class="sylius-product-name" title="{{ item.immutableProductName }}">{{ item.immutableProductName }}</div>
<div class="sylius-product-name" title="{{ item.productName }}">{{ item.productName }}</div>
<span class="sub header sylius-product-variant-code" title="{{ variant.code }}">
{{ variant.code }}
</span>
Expand All @@ -15,10 +15,10 @@
</div>
{% endfor %}
</div>
{% elseif item.immutableVariantName is not null %}
{% elseif item.variantName is not null %}
<div class="ui horizontal divided list">
<div class="item sylius-product-variant-name">
{{ item.immutableVariantName }}
{{ item.variantName }}
</div>
</div>
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<mapped-superclass name="Sylius\Component\Core\Model\OrderItem" table="sylius_order_item">
<field name="immutableProductName" column="immutable_product_name" type="string" nullable="true"/>
<field name="immutableVariantName" column="immutable_variant_name" type="string" nullable="true"/>
<field name="productName" column="product_name" type="string" nullable="true"/>
<field name="variantName" column="variant_name" type="string" nullable="true"/>

<many-to-one field="variant" target-entity="Sylius\Component\Product\Model\ProductVariantInterface">
<join-column name="variant_id" referenced-column-name="id" nullable="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="ui header">
{% include '@SyliusShop/Product/_mainImage.html.twig' with {'product': product, 'filter': 'sylius_shop_product_tiny_thumbnail'} %}
<div class="content">
<div class="sylius-product-name">{{ item.immutableProductName }}</div>
<div class="sylius-product-name">{{ item.productName }}</div>
<span class="sub header sylius-product-variant-code">
{{ variant.code }}
</span>
Expand All @@ -17,10 +17,10 @@
</div>
{% endfor %}
</div>
{% elseif item.immutableVariantName is not null %}
{% elseif item.variantName is not null %}
<div class="ui horizontal divided list">
<div class="item sylius-product-variant-name">
{{ item.immutableVariantName }}
{{ item.variantName }}
</div>
</div>
{% endif %}
24 changes: 12 additions & 12 deletions src/Sylius/Component/Core/Model/OrderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class OrderItem extends BaseOrderItem implements OrderItemInterface
/**
* @var string
*/
protected $immutableProductName;
protected $productName;

/**
* @var string
*/
protected $immutableVariantName;
protected $variantName;

/**
* {@inheritdoc}
Expand All @@ -51,11 +51,11 @@ public function setVariant(?ProductVariantInterface $variant): void
$localeCode = $order ? $order->getLocaleCode() : null;

if (null !== $variant) {
$this->setImmutableVariantName($variant->getTranslation($localeCode)->getName());
$this->setVariantName($variant->getTranslation($localeCode)->getName());
}

if (null !== $variant && null !== $variant->getProduct()) {
$this->setImmutableProductName($variant->getProduct()->getTranslation($localeCode)->getName());
$this->setProductName($variant->getProduct()->getTranslation($localeCode)->getName());
}

$this->variant = $variant;
Expand All @@ -72,33 +72,33 @@ public function getProduct(): ?ProductInterface
/**
* {@inheritdoc}
*/
public function getImmutableProductName(): ?string
public function getProductName(): ?string
{
return $this->immutableProductName ?: $this->variant->getProduct()->getName();
return $this->productName ?: $this->variant->getProduct()->getName();
}

/**
* {@inheritdoc}
*/
public function setImmutableProductName(?string $immutableProductName): void
public function setProductName(?string $productName): void
{
$this->immutableProductName = $immutableProductName;
$this->productName = $productName;
}

/**
* {@inheritdoc}
*/
public function getImmutableVariantName(): ?string
public function getVariantName(): ?string
{
return $this->immutableVariantName ?: $this->variant->getName();
return $this->variantName ?: $this->variant->getName();
}

/**
* {@inheritdoc}
*/
public function setImmutableVariantName(?string $immutableVariantName): void
public function setVariantName(?string $variantName): void
{
$this->immutableVariantName = $immutableVariantName;
$this->variantName = $variantName;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Sylius/Component/Core/Model/OrderItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ public function setVariant(?ProductVariantInterface $variant): void;
/**
* @return string|null
*/
public function getImmutableProductName(): ?string;
public function getProductName(): ?string;

/**
* @param string|null $immutableProductName
* @param string|null $productName
*/
public function setImmutableProductName(?string $immutableProductName): void;
public function setProductName(?string $productName): void;

/**
* @return string|null
*/
public function getImmutableVariantName(): ?string;
public function getVariantName(): ?string;

/**
* @param string|null $immutableVariantName
* @param string|null $variantName
*/
public function setImmutableVariantName(?string $immutableVariantName): void;
public function setVariantName(?string $variantName): void;

/**
* @return int
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Component/Core/spec/Model/OrderItemSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function it_sets_immutable_names_and_codes_during_setting_a_variant(
$this->setVariant($variant);

$this->getVariant()->shouldReturn($variant);
$this->getImmutableVariantName()->shouldReturn('Variant name');
$this->getImmutableProductName()->shouldReturn('Product name');
$this->getVariantName()->shouldReturn('Variant name');
$this->getProductName()->shouldReturn('Product name');
}
}

0 comments on commit 539afbf

Please sign in to comment.