Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API][UI][Behat][Refactor] OriginalUnitPrice property on the OrderItem entity #13563

Merged
merged 3 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-1.11.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Add a new bundle to your list of used bundles in `config/bundles.php` if they ar
+ Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true],
```

### Order prices recalculator

Passing a `Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface` to `Sylius\Component\Core\OrderProcessing\OrderPricesRecalculator` constructor is deprecated since Sylius 1.11 and will be prohibited in 2.0.
Use `Sylius\Component\Core\Calculator\ProductVariantPricesCalculatorInterface` instead.

### Behat

- Service `sylius.behat.context.hook.calendar` has been removed, use in your suites `Sylius\Calendar\Tests\Behat\Context\Hook\CalendarContext` instead.
Expand Down
8 changes: 8 additions & 0 deletions UPGRADE-API-1.11.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,11 @@

1. The argument of `Sylius\Bundle\ApiBundle\Applicator\ArchivingShippingMethodApplicatorInterface` service has been changed
from `sylius.calendar` to `Sylius\Calendar\Provider\DateTimeProviderInterface`.

1. Renamed response body field `originalPrice` to `originalUnitPrice` of the following endpoints:
- `'POST', '/api/v2/shop/orders/{tokenValue}/items'`
- `'GET', '/api/v2/shop/orders/{tokenValue}/items'`
- `'GET', '/api/v2/shop/orders/{tokenValue}'`

1. Added response body field `originalUnitPrice` to the following endpoint:
- `'GET', '/api/v2/admin/orders/{tokenValue}'`
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Api/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ public function iShouldSeeWithOriginalPriceInMyCart(string $productName, int $or

foreach ($this->responseChecker->getValue($response, 'items') as $item) {
if ($item['productName'] === $productName) {
Assert::same($item['originalPrice'], $originalPrice);
Assert::same($item['originalUnitPrice'], $originalPrice);

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<group>shop:order_item:read</group>
<group>shop:cart:read</group>
</attribute>
<attribute name="originalUnitPrice">
<group>admin:order:read</group>
<group>admin:order_item:read</group>
<group>shop:order_item:read</group>
<group>shop:cart:read</group>
</attribute>
<attribute name="discountedUnitPrice">
<group>shop:order_item:read</group>
<group>shop:cart:read</group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@
<tag name="serializer.normalizer" priority="64" />
</service>

<service id="Sylius\Bundle\ApiBundle\Serializer\OrderItemNormalizer">
<argument type="service" id="sylius.context.channel" />
<argument type="service" id="sylius.section_resolver.uri_based_section_resolver" />
<tag name="serializer.normalizer" priority="64" />
</service>

<service id="Sylius\Bundle\ApiBundle\Serializer\ShippingMethodNormalizer">
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sylius.repository.shipment" />
Expand Down
76 changes: 0 additions & 76 deletions src/Sylius/Bundle/ApiBundle/Serializer/OrderItemNormalizer.php

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\Migrations;
Expand All @@ -19,7 +28,6 @@ public function getDescription(): string

public function up(Schema $schema): void
{
// 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('CREATE TABLE sylius_channel_pricing_catalog_promotions (channel_pricing_id INT NOT NULL, catalog_promotion_id INT NOT NULL, INDEX IDX_9F52FF513EADFFE5 (channel_pricing_id), INDEX IDX_9F52FF5122E2CB5A (catalog_promotion_id), PRIMARY KEY(channel_pricing_id, catalog_promotion_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
Expand All @@ -30,7 +38,6 @@ public function up(Schema $schema): void

public function down(Schema $schema): void
{
// 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('DROP TABLE sylius_channel_pricing_catalog_promotions');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220127150747 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add an original unit price field to OrderItem';
}

public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_order_item ADD original_unit_price INT DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_order_item DROP original_unit_price');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<field name="quantity" column="quantity" type="integer" />
<field name="unitPrice" column="unit_price" type="integer" />
<field name="originalUnitPrice" column="original_unit_price" type="integer" nullable="true"/>
<field name="unitsTotal" column="units_total" type="integer" />
<field name="adjustmentsTotal" column="adjustments_total" type="integer" />
<field name="total" column="total" type="integer" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}

{% set product_variant = item.variant %}
{% set original_price_to_display = sylius_order_item_original_price_to_display(item, cart.channel) %}
{% set original_price_to_display = sylius_order_item_original_price_to_display(item) %}

<tr {{ sylius_test_html_attribute('cart-product-row', item.productName) }}>
<td class="single line" {{ sylius_test_html_attribute('cart-item', loop_index|default(null) ) }}>
{% include '@SyliusShop/Product/_info.html.twig' with {'variant': product_variant} %}
</td>
<td class="right aligned">
{% if original_price_to_display != null %}
{% if original_price_to_display is not null %}
<span class="sylius-regular-unit-price" {{ sylius_test_html_attribute('cart-product-regular-unit-price') }}>
<span class="old-price">{{ money.convertAndFormat(original_price_to_display) }}</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Sylius\Bundle\ShopBundle\Twig;

use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\OrderItem;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
Expand All @@ -27,23 +26,17 @@ public function getFunctions(): array
];
}

public function getOriginalPriceToDisplay(OrderItem $item, ChannelInterface $channel): ?int
public function getOriginalPriceToDisplay(OrderItem $item): ?int
Rafikooo marked this conversation as resolved.
Show resolved Hide resolved
{
$variant = $item->getVariant();

$channelPricing = $variant->getChannelPricingForChannel($channel);
$originalPrice = $channelPricing->getOriginalPrice();
$price = $channelPricing->getPrice();

$regularPrice = $item->getUnitPrice();
$discountedPrice = $item->getDiscountedUnitPrice();

if ($originalPrice !== null && $originalPrice > $price) {
return $originalPrice;
if (
$item->getOriginalUnitPrice() !== null &&
($item->getOriginalUnitPrice() > $item->getUnitPrice() || $item->getOriginalUnitPrice() > $item->getDiscountedUnitPrice())
) {
return $item->getOriginalUnitPrice();
}

if ($originalPrice === null && $regularPrice > $discountedPrice) {
return $regularPrice;
if ($item->getOriginalUnitPrice() === null && $item->getUnitPrice() > $item->getDiscountedUnitPrice()) {
return $item->getUnitPrice();
}

return null;
Expand Down