From f21c03417a57e0435f7d2608769511d3cab7db41 Mon Sep 17 00:00:00 2001 From: John Risby Date: Wed, 13 Sep 2017 16:54:12 +0200 Subject: [PATCH 1/9] #8628 Added immutable product/variant names and codes on OrderItem --- app/migrations/Version20170913125128.php | 40 ++++++++ .../config/doctrine/model/OrderItem.orm.xml | 4 + src/Sylius/Component/Core/Model/OrderItem.php | 97 ++++++++++++++++++- .../Component/Order/Model/OrderItem.php | 20 ++++ 4 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 app/migrations/Version20170913125128.php diff --git a/app/migrations/Version20170913125128.php b/app/migrations/Version20170913125128.php new file mode 100644 index 00000000000..1894bfd8aa1 --- /dev/null +++ b/app/migrations/Version20170913125128.php @@ -0,0 +1,40 @@ +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_product_code VARCHAR(255), ADD immutable_variant_name VARCHAR(255), ADD immutable_variant_code 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 pv1 ON sylius_order_item.variant_id = pv1.id INNER JOIN sylius_product as p1 ON pv1.product_id = p1.id INNER JOIN sylius_product_translation as pt1 ON pt1.translatable_id = p1.id INNER JOIN sylius_order as o2 on pt1.locale = o2.locale_code set sylius_order_item.immutable_product_name = pt1.name, sylius_order_item.immutable_product_code = p1.code'); + + $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 pv1 ON sylius_order_item.variant_id = pv1.id INNER JOIN sylius_product_variant_translation as pt1 ON pt1.translatable_id = pv1.id INNER JOIN sylius_order as o2 on pt1.locale = o2.locale_code set sylius_order_item.immutable_variant_name = pt1.name, sylius_order_item.immutable_variant_code = pv1.code'); + + $this->addSql('ALTER TABLE sylius_order_item CHANGE immutable_product_name immutable_product_name VARCHAR(255) DEFAULT NULL, CHANGE immutable_product_code immutable_product_code VARCHAR(255) DEFAULT NULL, CHANGE immutable_variant_name immutable_variant_name VARCHAR(255) DEFAULT NULL, CHANGE immutable_variant_code immutable_variant_code 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_order_item DROP immutable_product_name, DROP immutable_product_code, DROP immutable_variant_name, DROP immutable_variant_code'); + } +} diff --git a/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/OrderItem.orm.xml b/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/OrderItem.orm.xml index 34bf4c83d37..34a9bab9672 100644 --- a/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/OrderItem.orm.xml +++ b/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/OrderItem.orm.xml @@ -27,6 +27,10 @@ + + + + diff --git a/src/Sylius/Component/Core/Model/OrderItem.php b/src/Sylius/Component/Core/Model/OrderItem.php index 3e130e30317..9306426150d 100644 --- a/src/Sylius/Component/Core/Model/OrderItem.php +++ b/src/Sylius/Component/Core/Model/OrderItem.php @@ -23,12 +23,86 @@ class OrderItem extends BaseOrderItem implements OrderItemInterface */ protected $variant; + /** + * @return string + */ + public function getImmutableVariantName(): ?string + { + return $this->immutableVariantName ?: $this->variant->getName(); + } + + /** + * @param string $immutableVariantName + */ + public function setImmutableVariantName(?string $immutableVariantName) + { + $this->immutableVariantName = $immutableVariantName; + } + + /** + * @return string + */ + public function getImmutableVariantCode(): ?string + { + return $this->immutableVariantCode ?: $this->variant->getCode(); + } + + /** + * @param string $immutableVariantCode + */ + public function setImmutableVariantCode(?string $immutableVariantCode) + { + $this->immutableVariantCode = $immutableVariantCode; + } + + /** + * @return string + */ + public function getImmutableProductName(): ?string + { + return $this->immutableProductName ?: $this->variant->getProduct()->getName(); + } + + /** + * @param string $immutableProductName + */ + public function setImmutableProductName(?string $immutableProductName) + { + $this->immutableProductName = $immutableProductName; + } + + /** + * @return string + */ + public function getImmutableProductCode(): ?string + { + return $this->immutableProductCode ?: $this->variant->getProduct()->getCode(); + } + + /** + * @param string $immutableProductCode + */ + public function setImmutableProductCode(?string $immutableProductCode) + { + $this->immutableProductCode = $immutableProductCode; + } + /** * {@inheritdoc} */ - public function getProduct(): ?ProductInterface + public function setVariant(?ProductVariantInterface $variant): void { - return $this->variant->getProduct(); + if(isset($variant)) { + + $this->setImmutableProductName($variant->getProduct()->getName()); + $this->setImmutableVariantName($variant->getName()); + + $this->setImmutableProductCode($variant->getProduct()->getCode()); + $this->setImmutableVariantCode($variant->getCode()); + + } + + $this->variant = $variant; } /** @@ -36,17 +110,30 @@ public function getProduct(): ?ProductInterface */ public function getVariant(): ?ProductVariantInterface { - return $this->variant; + $variant = $this->variant; + + if(isset($variant)) { + + $variant->setName($this->getImmutableVariantName()); + $variant->setCode($this->getImmutableVariantCode()); + + $product = $variant->getProduct(); + $product->setName($this->getImmutableProductName()); + $product->setCode($this->getImmutableProductCode()); + } + + return $variant; } /** * {@inheritdoc} */ - public function setVariant(?ProductVariantInterface $variant): void + public function getProduct(): ?ProductInterface { - $this->variant = $variant; + return $this->variant->getProduct(); } + /** * {@inheritdoc} */ diff --git a/src/Sylius/Component/Order/Model/OrderItem.php b/src/Sylius/Component/Order/Model/OrderItem.php index f1dc29b7221..f3bfb3540f1 100644 --- a/src/Sylius/Component/Order/Model/OrderItem.php +++ b/src/Sylius/Component/Order/Model/OrderItem.php @@ -68,6 +68,26 @@ class OrderItem implements OrderItemInterface */ protected $adjustmentsTotal = 0; + /* + * @var string + */ + protected $immutableProductName; + + /* + * @var string + */ + protected $immutableProductCode; + + /* + * @var string + */ + protected $immutableVariantName; + + /* + * @var string + */ + protected $immutableVariantCode; + public function __construct() { $this->adjustments = new ArrayCollection(); From 7f35652d039845274f6af2a6b4a77142a65ad037 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 19 Oct 2017 12:38:22 +0200 Subject: [PATCH 2/9] [OrderItem] Refactor adding immutable product/variant names and codes --- app/migrations/Version20170913125128.php | 19 +++- .../config/doctrine/model/OrderItem.orm.xml | 5 + .../config/doctrine/model/OrderItem.orm.xml | 4 - src/Sylius/Component/Core/Model/OrderItem.php | 107 ++++++++++-------- .../Core/Model/OrderItemInterface.php | 40 +++++++ .../Core/spec/Model/OrderItemSpec.php | 39 +++++++ .../Component/Order/Model/OrderItem.php | 20 ---- 7 files changed, 159 insertions(+), 75 deletions(-) diff --git a/app/migrations/Version20170913125128.php b/app/migrations/Version20170913125128.php index 1894bfd8aa1..96d6a626568 100644 --- a/app/migrations/Version20170913125128.php +++ b/app/migrations/Version20170913125128.php @@ -20,9 +20,22 @@ public function up(Schema $schema) $this->addSql('ALTER TABLE sylius_order_item ADD immutable_product_name VARCHAR(255), ADD immutable_product_code VARCHAR(255), ADD immutable_variant_name VARCHAR(255), ADD immutable_variant_code 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 pv1 ON sylius_order_item.variant_id = pv1.id INNER JOIN sylius_product as p1 ON pv1.product_id = p1.id INNER JOIN sylius_product_translation as pt1 ON pt1.translatable_id = p1.id INNER JOIN sylius_order as o2 on pt1.locale = o2.locale_code set sylius_order_item.immutable_product_name = pt1.name, sylius_order_item.immutable_product_code = p1.code'); - - $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 pv1 ON sylius_order_item.variant_id = pv1.id INNER JOIN sylius_product_variant_translation as pt1 ON pt1.translatable_id = pv1.id INNER JOIN sylius_order as o2 on pt1.locale = o2.locale_code set sylius_order_item.immutable_variant_name = pt1.name, sylius_order_item.immutable_variant_code = pv1.code'); + $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, sylius_order_item.immutable_product_code = p.code + + '); + $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 pt ON pt.translatable_id = pv.id + INNER JOIN sylius_order AS ol ON pt.locale = ol.locale_code + SET sylius_order_item.immutable_variant_name = pt.name, sylius_order_item.immutable_variant_code = pv.code + '); $this->addSql('ALTER TABLE sylius_order_item CHANGE immutable_product_name immutable_product_name VARCHAR(255) DEFAULT NULL, CHANGE immutable_product_code immutable_product_code VARCHAR(255) DEFAULT NULL, CHANGE immutable_variant_name immutable_variant_name VARCHAR(255) DEFAULT NULL, CHANGE immutable_variant_code immutable_variant_code VARCHAR(255) DEFAULT NULL'); } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml index 8b60d7e6bb8..6feda45927f 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml @@ -17,6 +17,11 @@ http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + + + + + diff --git a/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/OrderItem.orm.xml b/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/OrderItem.orm.xml index 34a9bab9672..34bf4c83d37 100644 --- a/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/OrderItem.orm.xml +++ b/src/Sylius/Bundle/OrderBundle/Resources/config/doctrine/model/OrderItem.orm.xml @@ -27,10 +27,6 @@ - - - - diff --git a/src/Sylius/Component/Core/Model/OrderItem.php b/src/Sylius/Component/Core/Model/OrderItem.php index 9306426150d..88219138b9f 100644 --- a/src/Sylius/Component/Core/Model/OrderItem.php +++ b/src/Sylius/Component/Core/Model/OrderItem.php @@ -24,39 +24,65 @@ class OrderItem extends BaseOrderItem implements OrderItemInterface protected $variant; /** - * @return string + * @var string */ - public function getImmutableVariantName(): ?string - { - return $this->immutableVariantName ?: $this->variant->getName(); - } + protected $immutableProductName; + + /** + * @var string + */ + protected $immutableProductCode; + + /** + * @var string + */ + protected $immutableVariantName; + + /** + * @var string + */ + protected $immutableVariantCode; /** - * @param string $immutableVariantName + * {@inheritdoc} */ - public function setImmutableVariantName(?string $immutableVariantName) + public function getVariant(): ?ProductVariantInterface { - $this->immutableVariantName = $immutableVariantName; + return $this->variant; } /** - * @return string + * {@inheritdoc} */ - public function getImmutableVariantCode(): ?string + public function setVariant(?ProductVariantInterface $variant): void { - return $this->immutableVariantCode ?: $this->variant->getCode(); + /** @var OrderInterface $order */ + $order = $this->getOrder(); + $localeCode = $order ? $order->getLocaleCode() : null; + + if (null !== $variant) { + $this->setImmutableVariantName($variant->getTranslation($localeCode)->getName()); + $this->setImmutableVariantCode($variant->getCode()); + } + + if (null !== $variant && null !== $variant->getProduct()) { + $this->setImmutableProductName($variant->getProduct()->getTranslation($localeCode)->getName()); + $this->setImmutableProductCode($variant->getProduct()->getCode()); + } + + $this->variant = $variant; } /** - * @param string $immutableVariantCode + * @return ProductInterface|null */ - public function setImmutableVariantCode(?string $immutableVariantCode) + public function getProduct(): ?ProductInterface { - $this->immutableVariantCode = $immutableVariantCode; + return $this->variant->getProduct(); } /** - * @return string + * {@inheritdoc} */ public function getImmutableProductName(): ?string { @@ -64,15 +90,15 @@ public function getImmutableProductName(): ?string } /** - * @param string $immutableProductName + * {@inheritdoc} */ - public function setImmutableProductName(?string $immutableProductName) + public function setImmutableProductName(?string $immutableProductName): void { $this->immutableProductName = $immutableProductName; } /** - * @return string + * {@inheritdoc} */ public function getImmutableProductCode(): ?string { @@ -80,9 +106,9 @@ public function getImmutableProductCode(): ?string } /** - * @param string $immutableProductCode + * {@inheritdoc} */ - public function setImmutableProductCode(?string $immutableProductCode) + public function setImmutableProductCode(?string $immutableProductCode): void { $this->immutableProductCode = $immutableProductCode; } @@ -90,49 +116,34 @@ public function setImmutableProductCode(?string $immutableProductCode) /** * {@inheritdoc} */ - public function setVariant(?ProductVariantInterface $variant): void + public function getImmutableVariantName(): ?string { - if(isset($variant)) { - - $this->setImmutableProductName($variant->getProduct()->getName()); - $this->setImmutableVariantName($variant->getName()); - - $this->setImmutableProductCode($variant->getProduct()->getCode()); - $this->setImmutableVariantCode($variant->getCode()); - - } - - $this->variant = $variant; + return $this->immutableVariantName ?: $this->variant->getName(); } /** * {@inheritdoc} */ - public function getVariant(): ?ProductVariantInterface + public function setImmutableVariantName(?string $immutableVariantName): void { - $variant = $this->variant; - - if(isset($variant)) { - - $variant->setName($this->getImmutableVariantName()); - $variant->setCode($this->getImmutableVariantCode()); - - $product = $variant->getProduct(); - $product->setName($this->getImmutableProductName()); - $product->setCode($this->getImmutableProductCode()); - } - - return $variant; + $this->immutableVariantName = $immutableVariantName; } /** * {@inheritdoc} */ - public function getProduct(): ?ProductInterface + public function getImmutableVariantCode(): ?string { - return $this->variant->getProduct(); + return $this->immutableVariantCode ?: $this->variant->getCode(); } + /** + * {@inheritdoc} + */ + public function setImmutableVariantCode(?string $immutableVariantCode): void + { + $this->immutableVariantCode = $immutableVariantCode; + } /** * {@inheritdoc} diff --git a/src/Sylius/Component/Core/Model/OrderItemInterface.php b/src/Sylius/Component/Core/Model/OrderItemInterface.php index 24442f3a987..dd42e2dfbde 100644 --- a/src/Sylius/Component/Core/Model/OrderItemInterface.php +++ b/src/Sylius/Component/Core/Model/OrderItemInterface.php @@ -32,6 +32,46 @@ public function getVariant(): ?ProductVariantInterface; */ public function setVariant(?ProductVariantInterface $variant): void; + /** + * @return string|null + */ + public function getImmutableProductName(): ?string; + + /** + * @param string|null $immutableProductName + */ + public function setImmutableProductName(?string $immutableProductName): void; + + /** + * @return string|null + */ + public function getImmutableProductCode(): ?string; + + /** + * @param string|null $immutableProductCode + */ + public function setImmutableProductCode(?string $immutableProductCode): void; + + /** + * @return string|null + */ + public function getImmutableVariantName(): ?string; + + /** + * @param string|null $immutableVariantName + */ + public function setImmutableVariantName(?string $immutableVariantName): void; + + /** + * @return string|null + */ + public function getImmutableVariantCode(): ?string; + + /** + * @param string|null $immutableVariantCode + */ + public function setImmutableVariantCode(?string $immutableVariantCode): void; + /** * @return int */ diff --git a/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php b/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php index d48c71dccc2..0770f71473b 100644 --- a/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php +++ b/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php @@ -15,7 +15,12 @@ use PhpSpec\ObjectBehavior; use Sylius\Component\Core\Model\AdjustmentInterface; +use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\OrderItemUnitInterface; +use Sylius\Component\Core\Model\ProductInterface; +use Sylius\Component\Core\Model\ProductTranslationInterface; +use Sylius\Component\Core\Model\ProductVariantInterface; +use Sylius\Component\Product\Model\ProductVariantTranslationInterface; final class OrderItemSpec extends ObjectBehavior { @@ -110,4 +115,38 @@ function it_returns_subtotal_which_consist_of_discounted_unit_price_multiplied_b $this->getSubtotal()->shouldReturn(19000); } + + function it_has_no_variant_by_default(): void + { + $this->getVariant()->shouldReturn(null); + } + + function it_sets_immutable_names_and_codes_during_setting_a_variant( + OrderInterface $order, + ProductVariantInterface $variant, + ProductVariantTranslationInterface $variantTranslation, + ProductInterface $product, + ProductTranslationInterface $productTranslation + ): void { + $order->hasItem($this)->willReturn(true); + $order->getLocaleCode()->willReturn('en_US'); + + $variant->getCode()->willReturn('variant_code'); + $variant->getProduct()->willReturn($product); + $variant->getTranslation('en_US')->willReturn($variantTranslation); + $variantTranslation->getName()->willReturn('Variant name'); + + $product->getCode()->willReturn('product_code'); + $product->getTranslation('en_US')->willReturn($productTranslation); + $productTranslation->getName()->willReturn('Product name'); + + $this->setOrder($order); + $this->setVariant($variant); + + $this->getVariant()->shouldReturn($variant); + $this->getImmutableVariantName()->shouldReturn('Variant name'); + $this->getImmutableVariantCode()->shouldReturn('variant_code'); + $this->getImmutableProductName()->shouldReturn('Product name'); + $this->getImmutableProductCode()->shouldReturn('product_code'); + } } diff --git a/src/Sylius/Component/Order/Model/OrderItem.php b/src/Sylius/Component/Order/Model/OrderItem.php index f3bfb3540f1..f1dc29b7221 100644 --- a/src/Sylius/Component/Order/Model/OrderItem.php +++ b/src/Sylius/Component/Order/Model/OrderItem.php @@ -68,26 +68,6 @@ class OrderItem implements OrderItemInterface */ protected $adjustmentsTotal = 0; - /* - * @var string - */ - protected $immutableProductName; - - /* - * @var string - */ - protected $immutableProductCode; - - /* - * @var string - */ - protected $immutableVariantName; - - /* - * @var string - */ - protected $immutableVariantCode; - public function __construct() { $this->adjustments = new ArrayCollection(); From 3da58c35596ec183bd704b2250c07f7406fc5f1d Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 19 Oct 2017 14:55:31 +0200 Subject: [PATCH 3/9] [Behat][Order] Add scenarios for viewing items with proper names --- ...wing_order_items_with_proper_names.feature | 26 ++++++++++++++++++ ...eing_order_items_with_proper_names.feature | 27 +++++++++++++++++++ .../Behat/Context/Setup/ProductContext.php | 10 +++++++ .../Behat/Page/Admin/Order/ShowPage.php | 15 ++++++++--- .../Page/Admin/Order/ShowPageInterface.php | 2 +- .../Page/Shop/Account/Order/ShowPage.php | 17 +++++++++--- .../Shop/Account/Order/ShowPageInterface.php | 4 +-- 7 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature create mode 100644 features/order/managing_orders/seeing_order_items_with_proper_names.feature diff --git a/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature b/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature new file mode 100644 index 00000000000..26e3346aaa2 --- /dev/null +++ b/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature @@ -0,0 +1,26 @@ +@customer_account +Feature: Viewing order items with proper names + In order to check some details of my placed order + As an Customer + I want to be able to view items with proper names of my placed order + + Background: + Given the store operates on a single channel in "United States" + And the store has a product "Angel T-Shirt" priced at "$39.00" + And the store has a product "Angel Mug" priced at "$19.00" + And the store ships everywhere for free + And the store allows paying with "Cash on Delivery" + And I am a logged in customer + And I placed an order "#00000666" + And I bought an "Angel T-Shirt" and an "Angel Mug" + And I addressed it to "Lucifer Morningstar", "Seaside Fwy", "90802" "Los Angeles" in the "United States" with identical billing address + And I chose "Free" shipping method with "Cash on Delivery" payment + + @ui @todo + Scenario: Viewing basic information about an order + Given the product "Angel T-Shirt" was renamed to "Devil Cardigan" + And the product "Angel Mug" was renamed to "Devil Glass" + When I view the summary of the order "#00000666" + And I should see 2 items in the list + And the product named "Angel T-Shirt" should be in the items list + And the product named "Angel Mug" should be in the items list diff --git a/features/order/managing_orders/seeing_order_items_with_proper_names.feature b/features/order/managing_orders/seeing_order_items_with_proper_names.feature new file mode 100644 index 00000000000..3305a4b963f --- /dev/null +++ b/features/order/managing_orders/seeing_order_items_with_proper_names.feature @@ -0,0 +1,27 @@ +@managing_orders +Feature: Seeing order items with proper names + In order to see ordered products with proper names + As an Administrator + I want to be able to list items + + Background: + Given the store operates on a single channel in "United States" + And the store has a product "Angel T-Shirt" priced at "$39.00" + And the store has a product "Angel Mug" priced at "$19.00" + And the store ships everywhere for free + And the store allows paying with "Cash on Delivery" + And there is a customer "lucy@teamlucifer.com" that placed an order "#00000666" + And the customer bought an "Angel T-Shirt" and an "Angel Mug" + And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment + And I am logged in as an administrator + + @ui @todo + Scenario: Seeing order items with proper names + Given the product "Angel T-Shirt" was renamed to "Devil Cardigan" + And the product "Angel Mug" was renamed to "Devil Glass" + When I view the summary of the order "#00000666" + Then it should have 2 items + And the product named "Angel T-Shirt" should be in the items list + And the product named "Angel Mug" should be in the items list + And the order's items total should be "$58.00" + And the order's total should be "$58.00" diff --git a/src/Sylius/Behat/Context/Setup/ProductContext.php b/src/Sylius/Behat/Context/Setup/ProductContext.php index 971dce110bd..b7d9fb378c4 100644 --- a/src/Sylius/Behat/Context/Setup/ProductContext.php +++ b/src/Sylius/Behat/Context/Setup/ProductContext.php @@ -782,6 +782,16 @@ public function thisProductHasBeenDisabled(ProductInterface $product) $this->objectManager->flush(); } + /** + * @Given the product :product was renamed to :productName + */ + public function theProductWasRenamedTo(ProductInterface $product, string $productName): void + { + $product->setName($productName); + + $this->objectManager->flush(); + } + /** * @param string $price * diff --git a/src/Sylius/Behat/Page/Admin/Order/ShowPage.php b/src/Sylius/Behat/Page/Admin/Order/ShowPage.php index 32497cf166c..a01159ab2ab 100644 --- a/src/Sylius/Behat/Page/Admin/Order/ShowPage.php +++ b/src/Sylius/Behat/Page/Admin/Order/ShowPage.php @@ -145,15 +145,24 @@ public function countItems() /** * {@inheritdoc} */ - public function isProductInTheList($productName) + public function isProductInTheList(string $productName): bool { try { + $table = $this->getElement('table'); $rows = $this->tableAccessor->getRowsWithFields( - $this->getElement('table'), + $table, ['item' => $productName] ); - return 1 === count($rows); + foreach ($rows as $row) { + $field = $this->tableAccessor->getFieldFromRow($table, $row, 'item'); + $name = $field->find('css', '.sylius-product-name'); + if (null !== $name && $name->getText() === $productName) { + return true; + } + } + + return false; } catch (\InvalidArgumentException $exception) { return false; } diff --git a/src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php b/src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php index ff05f775508..cf567f735f8 100644 --- a/src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php @@ -103,7 +103,7 @@ public function countItems(); * * @return bool */ - public function isProductInTheList($productName); + public function isProductInTheList(string $productName): bool; /** * @return string diff --git a/src/Sylius/Behat/Page/Shop/Account/Order/ShowPage.php b/src/Sylius/Behat/Page/Shop/Account/Order/ShowPage.php index 3b0be8d0c94..a3e844460e2 100644 --- a/src/Sylius/Behat/Page/Shop/Account/Order/ShowPage.php +++ b/src/Sylius/Behat/Page/Shop/Account/Order/ShowPage.php @@ -122,15 +122,24 @@ public function getPaymentPrice() /** * {@inheritdoc} */ - public function isProductInTheList($name) + public function isProductInTheList(string $productName): bool { try { + $table = $this->getElement('order_items'); $rows = $this->tableAccessor->getRowsWithFields( - $this->getElement('order_items'), - ['item' => $name] + $table, + ['item' => $productName] ); - return 1 === count($rows); + foreach ($rows as $row) { + $field = $this->tableAccessor->getFieldFromRow($table, $row, 'item'); + $name = $field->find('css', '.sylius-product-name'); + if (null !== $name && $name->getText() === $productName) { + return true; + } + } + + return false; } catch (\InvalidArgumentException $exception) { return false; } diff --git a/src/Sylius/Behat/Page/Shop/Account/Order/ShowPageInterface.php b/src/Sylius/Behat/Page/Shop/Account/Order/ShowPageInterface.php index 9fea45da276..21caeec874e 100644 --- a/src/Sylius/Behat/Page/Shop/Account/Order/ShowPageInterface.php +++ b/src/Sylius/Behat/Page/Shop/Account/Order/ShowPageInterface.php @@ -65,11 +65,11 @@ public function countItems(); public function getPaymentPrice(); /** - * @param string $name + * @param string $productName * * @return bool */ - public function isProductInTheList($name); + public function isProductInTheList(string $productName): bool; /** * @return string From 3b0fb9542d759901d8422c12808b19b2040a5fa5 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 19 Oct 2017 15:44:43 +0200 Subject: [PATCH 4/9] [Order] Add displaying immutable product/variant names and codes in ui --- .../viewing_order_items_with_proper_names.feature | 2 +- .../seeing_order_items_with_proper_names.feature | 2 +- .../views/Order/Show/Summary/_item.html.twig | 2 +- .../Resources/views/Product/_info.html.twig | 12 +++++------- .../Resources/views/Product/_info.html.twig | 8 ++++---- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature b/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature index 26e3346aaa2..4674e441688 100644 --- a/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature +++ b/features/account/customer_account/viewing_orders_history/viewing_order_items_with_proper_names.feature @@ -16,7 +16,7 @@ Feature: Viewing order items with proper names And I addressed it to "Lucifer Morningstar", "Seaside Fwy", "90802" "Los Angeles" in the "United States" with identical billing address And I chose "Free" shipping method with "Cash on Delivery" payment - @ui @todo + @ui Scenario: Viewing basic information about an order Given the product "Angel T-Shirt" was renamed to "Devil Cardigan" And the product "Angel Mug" was renamed to "Devil Glass" diff --git a/features/order/managing_orders/seeing_order_items_with_proper_names.feature b/features/order/managing_orders/seeing_order_items_with_proper_names.feature index 3305a4b963f..87ca755e8fc 100644 --- a/features/order/managing_orders/seeing_order_items_with_proper_names.feature +++ b/features/order/managing_orders/seeing_order_items_with_proper_names.feature @@ -15,7 +15,7 @@ Feature: Seeing order items with proper names And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment And I am logged in as an administrator - @ui @todo + @ui Scenario: Seeing order items with proper names Given the product "Angel T-Shirt" was renamed to "Devil Cardigan" And the product "Angel Mug" was renamed to "Devil Glass" diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Order/Show/Summary/_item.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Order/Show/Summary/_item.html.twig index 91e5b99083c..0c3e4930bcb 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Order/Show/Summary/_item.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Order/Show/Summary/_item.html.twig @@ -6,7 +6,7 @@ {% set taxAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::TAX_ADJUSTMENT') %} {% set variant = item.variant %} -{% set product = variant.product %} +{% set product = item.variant.product %} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig index 8a710b2519a..99be434659e 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig @@ -1,11 +1,9 @@ -{% set product = variant.product %} -
{% include '@SyliusAdmin/Product/_mainImage.html.twig' with {'product': product, 'filter': 'sylius_admin_product_tiny_thumbnail'} %}
- {{ product.name }} - - {{ variant.code }} +
{{ item.immutableProductName }}
+ + {{ item.immutableVariantCode }}
@@ -17,10 +15,10 @@ {% endfor %} -{% elseif variant.name is not null %} +{% elseif item.immutableVariantName is not null %}
- {{ variant.name }} + {{ item.immutableVariantName }}
{% endif %} diff --git a/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig b/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig index 8cebac94a90..c4517cc6c0d 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig +++ b/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig @@ -3,9 +3,9 @@
{% include '@SyliusShop/Product/_mainImage.html.twig' with {'product': product, 'filter': 'sylius_shop_product_tiny_thumbnail'} %}
- {{ product.name }} +
{{ item.immutableProductName }}
- {{ variant.code }} + {{ item.immutableVariantCode }}
@@ -17,10 +17,10 @@ {% endfor %} -{% elseif variant.name is not null %} +{% elseif item.immutableVariantName is not null %}
- {{ variant.name }} + {{ item.immutableVariantName }}
{% endif %} From 1bafcbefb88ddf16ee9a66361707a05309ff41b2 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 20 Oct 2017 09:20:51 +0200 Subject: [PATCH 5/9] Fix unit tests by changing fixtures order --- .../ORM/resources/cart_with_items.yml | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/tests/DataFixtures/ORM/resources/cart_with_items.yml b/tests/DataFixtures/ORM/resources/cart_with_items.yml index 952558a530d..7713795c37f 100644 --- a/tests/DataFixtures/ORM/resources/cart_with_items.yml +++ b/tests/DataFixtures/ORM/resources/cart_with_items.yml @@ -1,60 +1,3 @@ -Sylius\Component\Core\Model\Order: - cart_with_items: - channel: "@channel_web" - addItem: ["@sw_mug_item", "@hard_available_mug_item"] - currencyCode: "USD" - localeCode: "en_US" - customer: "@customer_oliver" - state: "cart" - -Sylius\Component\Core\Model\OrderItem: - sw_mug_item: - quantity: 2 - addUnit: ["@sw_mug_item_unit1", "@sw_mug_item_unit2"] - variant: "@mug_sw" - order: "@cart_with_items" - hard_available_mug_item: - quantity: 1 - addUnit: ["@hard_available_mug_item_unit"] - variant: "@hard_available_mug" - order: "@cart_with_items" - -Sylius\Component\Core\Model\OrderItemUnit: - sw_mug_item_unit1: - __construct: ["@sw_mug_item"] - sw_mug_item_unit2: - __construct: ["@sw_mug_item"] - hard_available_mug_item_unit: - __construct: ["@hard_available_mug_item"] - -Sylius\Component\Core\Model\Channel: - channel_web: - code: "WEB" - name: "Web Channel" - hostname: "localhost" - description: "Lorem ipsum" - baseCurrency: "@currency" - defaultLocale: "@locale" - color: "black" - enabled: true - taxCalculationStrategy: "order_items_based" - -Sylius\Component\Currency\Model\Currency: - currency: - code: "USD" - -Sylius\Component\Locale\Model\Locale: - locale: - code: "en_US" - -Sylius\Component\Core\Model\Customer: - customer_oliver: - firstName: "Oliver" - lastName: "Queen" - email: "oliver.queen@star-city.com" - emailCanonical: "oliver.queen@star-city.com" - birthday: "<(new \\DateTime())>" - Sylius\Component\Core\Model\Product: mug: code: "MUG" @@ -125,6 +68,63 @@ Sylius\Component\Product\Model\ProductVariantTranslation: name: "Breaking bad mug" translatable: "@hard_available_mug" +Sylius\Component\Core\Model\Order: + cart_with_items: + channel: "@channel_web" + addItem: ["@sw_mug_item", "@hard_available_mug_item"] + currencyCode: "USD" + localeCode: "en_US" + customer: "@customer_oliver" + state: "cart" + +Sylius\Component\Core\Model\OrderItem: + sw_mug_item: + quantity: 2 + addUnit: ["@sw_mug_item_unit1", "@sw_mug_item_unit2"] + variant: "@mug_sw" + order: "@cart_with_items" + hard_available_mug_item: + quantity: 1 + addUnit: ["@hard_available_mug_item_unit"] + variant: "@hard_available_mug" + order: "@cart_with_items" + +Sylius\Component\Core\Model\OrderItemUnit: + sw_mug_item_unit1: + __construct: ["@sw_mug_item"] + sw_mug_item_unit2: + __construct: ["@sw_mug_item"] + hard_available_mug_item_unit: + __construct: ["@hard_available_mug_item"] + +Sylius\Component\Core\Model\Channel: + channel_web: + code: "WEB" + name: "Web Channel" + hostname: "localhost" + description: "Lorem ipsum" + baseCurrency: "@currency" + defaultLocale: "@locale" + color: "black" + enabled: true + taxCalculationStrategy: "order_items_based" + +Sylius\Component\Currency\Model\Currency: + currency: + code: "USD" + +Sylius\Component\Locale\Model\Locale: + locale: + code: "en_US" + +Sylius\Component\Core\Model\Customer: + customer_oliver: + firstName: "Oliver" + lastName: "Queen" + email: "oliver.queen@star-city.com" + emailCanonical: "oliver.queen@star-city.com" + birthday: "<(new \\DateTime())>" + Sylius\Component\Core\Model\ChannelPricing: sw_mug_web_channel_pricing: channelCode: "WEB" From 1f9f443e1763a6a53b0c03d028ad465fb55b9fb0 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 24 Oct 2017 12:27:14 +0200 Subject: [PATCH 6/9] [Order] Remove immutable product/variant code --- app/migrations/Version20170913125128.php | 14 +++--- .../Resources/views/Product/_info.html.twig | 4 +- .../config/doctrine/model/OrderItem.orm.xml | 2 - .../Resources/views/Product/_info.html.twig | 2 +- src/Sylius/Component/Core/Model/OrderItem.php | 44 ------------------- .../Core/Model/OrderItemInterface.php | 20 --------- .../Core/spec/Model/OrderItemSpec.php | 4 -- 7 files changed, 10 insertions(+), 80 deletions(-) diff --git a/app/migrations/Version20170913125128.php b/app/migrations/Version20170913125128.php index 96d6a626568..4df07de5d4b 100644 --- a/app/migrations/Version20170913125128.php +++ b/app/migrations/Version20170913125128.php @@ -18,7 +18,7 @@ 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_product_code VARCHAR(255), ADD immutable_variant_name VARCHAR(255), ADD immutable_variant_code VARCHAR(255)'); + $this->addSql('ALTER TABLE sylius_order_item ADD immutable_product_name VARCHAR(255), ADD immutable_variant_name VARCHAR(255)'); $this->addSql('UPDATE sylius_order_item INNER JOIN sylius_order AS o ON sylius_order_item.order_id = o.id @@ -26,18 +26,18 @@ public function up(Schema $schema) 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, sylius_order_item.immutable_product_code = p.code + SET sylius_order_item.immutable_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 pt ON pt.translatable_id = pv.id - INNER JOIN sylius_order AS ol ON pt.locale = ol.locale_code - SET sylius_order_item.immutable_variant_name = pt.name, sylius_order_item.immutable_variant_code = pv.code + 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 '); - $this->addSql('ALTER TABLE sylius_order_item CHANGE immutable_product_name immutable_product_name VARCHAR(255) DEFAULT NULL, CHANGE immutable_product_code immutable_product_code VARCHAR(255) DEFAULT NULL, CHANGE immutable_variant_name immutable_variant_name VARCHAR(255) DEFAULT NULL, CHANGE immutable_variant_code immutable_variant_code VARCHAR(255) DEFAULT NULL'); + $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'); } /** @@ -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_product_code, DROP immutable_variant_name, DROP immutable_variant_code'); + $this->addSql('ALTER TABLE sylius_order_item DROP immutable_product_name, DROP immutable_variant_name'); } } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig index 99be434659e..555505b79e7 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig @@ -2,8 +2,8 @@ {% include '@SyliusAdmin/Product/_mainImage.html.twig' with {'product': product, 'filter': 'sylius_admin_product_tiny_thumbnail'} %}
{{ item.immutableProductName }}
- - {{ item.immutableVariantCode }} + + {{ variant.code }}
diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml index 6feda45927f..7d897077727 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml @@ -18,9 +18,7 @@ - - diff --git a/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig b/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig index c4517cc6c0d..0a85f37de98 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig +++ b/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig @@ -5,7 +5,7 @@
{{ item.immutableProductName }}
- {{ item.immutableVariantCode }} + {{ variant.code }}
diff --git a/src/Sylius/Component/Core/Model/OrderItem.php b/src/Sylius/Component/Core/Model/OrderItem.php index 88219138b9f..7b46b9955c0 100644 --- a/src/Sylius/Component/Core/Model/OrderItem.php +++ b/src/Sylius/Component/Core/Model/OrderItem.php @@ -28,21 +28,11 @@ class OrderItem extends BaseOrderItem implements OrderItemInterface */ protected $immutableProductName; - /** - * @var string - */ - protected $immutableProductCode; - /** * @var string */ protected $immutableVariantName; - /** - * @var string - */ - protected $immutableVariantCode; - /** * {@inheritdoc} */ @@ -62,12 +52,10 @@ public function setVariant(?ProductVariantInterface $variant): void if (null !== $variant) { $this->setImmutableVariantName($variant->getTranslation($localeCode)->getName()); - $this->setImmutableVariantCode($variant->getCode()); } if (null !== $variant && null !== $variant->getProduct()) { $this->setImmutableProductName($variant->getProduct()->getTranslation($localeCode)->getName()); - $this->setImmutableProductCode($variant->getProduct()->getCode()); } $this->variant = $variant; @@ -97,22 +85,6 @@ public function setImmutableProductName(?string $immutableProductName): void $this->immutableProductName = $immutableProductName; } - /** - * {@inheritdoc} - */ - public function getImmutableProductCode(): ?string - { - return $this->immutableProductCode ?: $this->variant->getProduct()->getCode(); - } - - /** - * {@inheritdoc} - */ - public function setImmutableProductCode(?string $immutableProductCode): void - { - $this->immutableProductCode = $immutableProductCode; - } - /** * {@inheritdoc} */ @@ -129,22 +101,6 @@ public function setImmutableVariantName(?string $immutableVariantName): void $this->immutableVariantName = $immutableVariantName; } - /** - * {@inheritdoc} - */ - public function getImmutableVariantCode(): ?string - { - return $this->immutableVariantCode ?: $this->variant->getCode(); - } - - /** - * {@inheritdoc} - */ - public function setImmutableVariantCode(?string $immutableVariantCode): void - { - $this->immutableVariantCode = $immutableVariantCode; - } - /** * {@inheritdoc} */ diff --git a/src/Sylius/Component/Core/Model/OrderItemInterface.php b/src/Sylius/Component/Core/Model/OrderItemInterface.php index dd42e2dfbde..f7c079de8e8 100644 --- a/src/Sylius/Component/Core/Model/OrderItemInterface.php +++ b/src/Sylius/Component/Core/Model/OrderItemInterface.php @@ -42,16 +42,6 @@ public function getImmutableProductName(): ?string; */ public function setImmutableProductName(?string $immutableProductName): void; - /** - * @return string|null - */ - public function getImmutableProductCode(): ?string; - - /** - * @param string|null $immutableProductCode - */ - public function setImmutableProductCode(?string $immutableProductCode): void; - /** * @return string|null */ @@ -62,16 +52,6 @@ public function getImmutableVariantName(): ?string; */ public function setImmutableVariantName(?string $immutableVariantName): void; - /** - * @return string|null - */ - public function getImmutableVariantCode(): ?string; - - /** - * @param string|null $immutableVariantCode - */ - public function setImmutableVariantCode(?string $immutableVariantCode): void; - /** * @return int */ diff --git a/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php b/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php index 0770f71473b..f30510b2bff 100644 --- a/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php +++ b/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php @@ -131,12 +131,10 @@ function it_sets_immutable_names_and_codes_during_setting_a_variant( $order->hasItem($this)->willReturn(true); $order->getLocaleCode()->willReturn('en_US'); - $variant->getCode()->willReturn('variant_code'); $variant->getProduct()->willReturn($product); $variant->getTranslation('en_US')->willReturn($variantTranslation); $variantTranslation->getName()->willReturn('Variant name'); - $product->getCode()->willReturn('product_code'); $product->getTranslation('en_US')->willReturn($productTranslation); $productTranslation->getName()->willReturn('Product name'); @@ -145,8 +143,6 @@ function it_sets_immutable_names_and_codes_during_setting_a_variant( $this->getVariant()->shouldReturn($variant); $this->getImmutableVariantName()->shouldReturn('Variant name'); - $this->getImmutableVariantCode()->shouldReturn('variant_code'); $this->getImmutableProductName()->shouldReturn('Product name'); - $this->getImmutableProductCode()->shouldReturn('product_code'); } } From 003096cf6b74e4f415cb9715251f1b1fb17e3068 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 24 Oct 2017 12:31:27 +0200 Subject: [PATCH 7/9] [Order] Remove immutable prefix --- app/migrations/Version20170913125128.php | 10 ++++---- .../Resources/views/Product/_info.html.twig | 6 ++--- .../config/doctrine/model/OrderItem.orm.xml | 4 ++-- .../Resources/views/Product/_info.html.twig | 6 ++--- src/Sylius/Component/Core/Model/OrderItem.php | 24 +++++++++---------- .../Core/Model/OrderItemInterface.php | 12 +++++----- .../Core/spec/Model/OrderItemSpec.php | 4 ++-- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/app/migrations/Version20170913125128.php b/app/migrations/Version20170913125128.php index 4df07de5d4b..10bf022b08c 100644 --- a/app/migrations/Version20170913125128.php +++ b/app/migrations/Version20170913125128.php @@ -18,7 +18,7 @@ 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 @@ -26,7 +26,7 @@ public function up(Schema $schema) 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 @@ -34,10 +34,10 @@ public function up(Schema $schema) 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'); } /** @@ -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'); } } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig index 555505b79e7..41c8c0f5f82 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Product/_info.html.twig @@ -1,7 +1,7 @@
{% include '@SyliusAdmin/Product/_mainImage.html.twig' with {'product': product, 'filter': 'sylius_admin_product_tiny_thumbnail'} %}
-
{{ item.immutableProductName }}
+
{{ item.productName }}
{{ variant.code }} @@ -15,10 +15,10 @@
{% endfor %}
-{% elseif item.immutableVariantName is not null %} +{% elseif item.variantName is not null %}
- {{ item.immutableVariantName }} + {{ item.variantName }}
{% endif %} diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml index 7d897077727..72ab68cdfe8 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/OrderItem.orm.xml @@ -17,8 +17,8 @@ http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - - + + diff --git a/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig b/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig index 0a85f37de98..f7024eef4b6 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig +++ b/src/Sylius/Bundle/ShopBundle/Resources/views/Product/_info.html.twig @@ -3,7 +3,7 @@
{% include '@SyliusShop/Product/_mainImage.html.twig' with {'product': product, 'filter': 'sylius_shop_product_tiny_thumbnail'} %}
-
{{ item.immutableProductName }}
+
{{ item.productName }}
{{ variant.code }} @@ -17,10 +17,10 @@
{% endfor %}
-{% elseif item.immutableVariantName is not null %} +{% elseif item.variantName is not null %}
- {{ item.immutableVariantName }} + {{ item.variantName }}
{% endif %} diff --git a/src/Sylius/Component/Core/Model/OrderItem.php b/src/Sylius/Component/Core/Model/OrderItem.php index 7b46b9955c0..45c4c9b2e86 100644 --- a/src/Sylius/Component/Core/Model/OrderItem.php +++ b/src/Sylius/Component/Core/Model/OrderItem.php @@ -26,12 +26,12 @@ class OrderItem extends BaseOrderItem implements OrderItemInterface /** * @var string */ - protected $immutableProductName; + protected $productName; /** * @var string */ - protected $immutableVariantName; + protected $variantName; /** * {@inheritdoc} @@ -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; @@ -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; } /** diff --git a/src/Sylius/Component/Core/Model/OrderItemInterface.php b/src/Sylius/Component/Core/Model/OrderItemInterface.php index f7c079de8e8..66ee73dc1e1 100644 --- a/src/Sylius/Component/Core/Model/OrderItemInterface.php +++ b/src/Sylius/Component/Core/Model/OrderItemInterface.php @@ -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 diff --git a/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php b/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php index f30510b2bff..fd78cd2b416 100644 --- a/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php +++ b/src/Sylius/Component/Core/spec/Model/OrderItemSpec.php @@ -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'); } } From cdc922198aa936d5b1886435f686ad426acdb309 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 24 Oct 2017 12:36:55 +0200 Subject: [PATCH 8/9] Fixes after PR review --- app/migrations/Version20170913125128.php | 28 ++++++++++--------- .../views/Order/Show/Summary/_item.html.twig | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/migrations/Version20170913125128.php b/app/migrations/Version20170913125128.php index 10bf022b08c..8ddd520d375 100644 --- a/app/migrations/Version20170913125128.php +++ b/app/migrations/Version20170913125128.php @@ -20,21 +20,23 @@ public function up(Schema $schema) $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.product_name = pt.name + $this->addSql(' + UPDATE sylius_order_item + INNER JOIN sylius_order ON sylius_order_item.order_id = sylius_order.id + INNER JOIN sylius_product_variant ON sylius_order_item.variant_id = sylius_product_variant.id + INNER JOIN sylius_product ON sylius_product_variant.product_id = sylius_product.id + INNER JOIN sylius_product_translation ON sylius_product_translation.translatable_id = sylius_product.id + SET sylius_order_item.product_name = sylius_product_translation.name + WHERE sylius_product_translation.locale = sylius_order.locale_code '); - $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.variant_name = pvt.name + $this->addSql(' + UPDATE sylius_order_item + INNER JOIN sylius_order ON sylius_order_item.order_id = sylius_order.id + INNER JOIN sylius_product_variant ON sylius_order_item.variant_id = sylius_product_variant.id + INNER JOIN sylius_product_variant_translation ON sylius_product_variant_translation.translatable_id = sylius_product_variant.id + SET sylius_order_item.variant_name = sylius_product_variant_translation.name + WHERE sylius_product_variant_translation.locale = sylius_order.locale_code '); $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'); diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Order/Show/Summary/_item.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Order/Show/Summary/_item.html.twig index 0c3e4930bcb..91e5b99083c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Order/Show/Summary/_item.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Order/Show/Summary/_item.html.twig @@ -6,7 +6,7 @@ {% set taxAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::TAX_ADJUSTMENT') %} {% set variant = item.variant %} -{% set product = item.variant.product %} +{% set product = variant.product %} From bb52a56fd07801db08367f7b5dc6a65c45484070 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 26 Oct 2017 09:56:01 +0200 Subject: [PATCH 9/9] [Order] Add order product/variant names setter --- .../config/app/state_machine/sylius_order.yml | 4 ++ .../CoreBundle/Resources/config/services.xml | 2 + src/Sylius/Component/Core/Model/OrderItem.php | 12 ---- .../Core/Order/OrderItemNamesSetter.php | 41 ++++++++++++++ .../Order/OrderItemNamesSetterInterface.php | 24 ++++++++ .../Core/spec/Model/OrderItemSpec.php | 25 --------- .../spec/Order/OrderItemNamesSetterSpec.php | 56 +++++++++++++++++++ 7 files changed, 127 insertions(+), 37 deletions(-) create mode 100644 src/Sylius/Component/Core/Order/OrderItemNamesSetter.php create mode 100644 src/Sylius/Component/Core/Order/OrderItemNamesSetterInterface.php create mode 100644 src/Sylius/Component/Core/spec/Order/OrderItemNamesSetterSpec.php diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/state_machine/sylius_order.yml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/state_machine/sylius_order.yml index 1bff13d5d85..8b5e7ebddb3 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/app/state_machine/sylius_order.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/state_machine/sylius_order.yml @@ -58,6 +58,10 @@ winzou_state_machine: on: ["create"] do: ["@sylius.customer_order_addresses_saver", "saveAddresses"] args: ["object"] + sylius_set_order_immutable_names: + on: ["create"] + do: ["@sylius.order_item_names_setter", "__invoke"] + args: ["object"] sylius_cancel_payment: on: ["cancel"] do: ["@sm.callback.cascade_transition", "apply"] diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml index bfe59b31e2c..8546b173d38 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml @@ -164,5 +164,7 @@ + + diff --git a/src/Sylius/Component/Core/Model/OrderItem.php b/src/Sylius/Component/Core/Model/OrderItem.php index 45c4c9b2e86..15d1b66458b 100644 --- a/src/Sylius/Component/Core/Model/OrderItem.php +++ b/src/Sylius/Component/Core/Model/OrderItem.php @@ -46,18 +46,6 @@ public function getVariant(): ?ProductVariantInterface */ public function setVariant(?ProductVariantInterface $variant): void { - /** @var OrderInterface $order */ - $order = $this->getOrder(); - $localeCode = $order ? $order->getLocaleCode() : null; - - if (null !== $variant) { - $this->setVariantName($variant->getTranslation($localeCode)->getName()); - } - - if (null !== $variant && null !== $variant->getProduct()) { - $this->setProductName($variant->getProduct()->getTranslation($localeCode)->getName()); - } - $this->variant = $variant; } diff --git a/src/Sylius/Component/Core/Order/OrderItemNamesSetter.php b/src/Sylius/Component/Core/Order/OrderItemNamesSetter.php new file mode 100644 index 00000000000..7f314359918 --- /dev/null +++ b/src/Sylius/Component/Core/Order/OrderItemNamesSetter.php @@ -0,0 +1,41 @@ +getLocaleCode(); + + /** @var OrderItemInterface $item */ + foreach ($order->getItems() as $item) { + $variant = $item->getVariant(); + + if (null !== $variant) { + $item->setVariantName($variant->getTranslation($localeCode)->getName()); + } + + if (null !== $variant && null !== $variant->getProduct()) { + $item->setProductName($variant->getProduct()->getTranslation($localeCode)->getName()); + } + } + } +} diff --git a/src/Sylius/Component/Core/Order/OrderItemNamesSetterInterface.php b/src/Sylius/Component/Core/Order/OrderItemNamesSetterInterface.php new file mode 100644 index 00000000000..7973898fe3a --- /dev/null +++ b/src/Sylius/Component/Core/Order/OrderItemNamesSetterInterface.php @@ -0,0 +1,24 @@ +getVariant()->shouldReturn(null); } - - function it_sets_immutable_names_and_codes_during_setting_a_variant( - OrderInterface $order, - ProductVariantInterface $variant, - ProductVariantTranslationInterface $variantTranslation, - ProductInterface $product, - ProductTranslationInterface $productTranslation - ): void { - $order->hasItem($this)->willReturn(true); - $order->getLocaleCode()->willReturn('en_US'); - - $variant->getProduct()->willReturn($product); - $variant->getTranslation('en_US')->willReturn($variantTranslation); - $variantTranslation->getName()->willReturn('Variant name'); - - $product->getTranslation('en_US')->willReturn($productTranslation); - $productTranslation->getName()->willReturn('Product name'); - - $this->setOrder($order); - $this->setVariant($variant); - - $this->getVariant()->shouldReturn($variant); - $this->getVariantName()->shouldReturn('Variant name'); - $this->getProductName()->shouldReturn('Product name'); - } } diff --git a/src/Sylius/Component/Core/spec/Order/OrderItemNamesSetterSpec.php b/src/Sylius/Component/Core/spec/Order/OrderItemNamesSetterSpec.php new file mode 100644 index 00000000000..7d18efe76e6 --- /dev/null +++ b/src/Sylius/Component/Core/spec/Order/OrderItemNamesSetterSpec.php @@ -0,0 +1,56 @@ +shouldImplement(OrderItemNamesSetterInterface::class); + } + + function it_sets_product_and_product_variant_names_on_order_items( + OrderInterface $order, + OrderItemInterface $orderItem, + ProductVariantInterface $variant, + ProductVariantTranslationInterface $variantTranslation, + ProductInterface $product, + ProductTranslationInterface $productTranslation + ): void { + $order->getLocaleCode()->willReturn('en_US'); + $order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); + + $variant->getProduct()->willReturn($product); + $variant->getTranslation('en_US')->willReturn($variantTranslation); + $variantTranslation->getName()->willReturn('Variant name'); + + $product->getTranslation('en_US')->willReturn($productTranslation); + $productTranslation->getName()->willReturn('Product name'); + + $orderItem->setVariantName('Variant name'); + $orderItem->setProductName('Product name'); + + $this->__invoke($order); + } +}