Skip to content

Commit a9cbbc1

Browse files
authored
whole application now correctly reflects input price type settings (#3836)
2 parents 8c0f015 + 56c686b commit a9cbbc1

File tree

49 files changed

+680
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+680
-203
lines changed

src/Controller/Admin/OrderController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Shopsys\FrameworkBundle\Model\Order\Item\OrderItemPriceCalculation;
2828
use Shopsys\FrameworkBundle\Model\Order\OrderDataFactory;
2929
use Shopsys\FrameworkBundle\Model\Order\OrderFacade;
30+
use Shopsys\FrameworkBundle\Model\Pricing\PricingSetting;
3031
use Symfony\Component\HttpFoundation\Request;
3132
use Symfony\Component\HttpFoundation\Response;
3233
use Symfony\Component\Routing\Annotation\Route;
@@ -49,6 +50,7 @@ class OrderController extends AdminBaseController
4950
* @param \Shopsys\FrameworkBundle\Component\EntityLog\Model\Grid\EntityLogGridFactory $entityLogGridFactory
5051
* @param \Shopsys\FrameworkBundle\Component\Cache\InMemoryCache $inMemoryCache
5152
* @param \Shopsys\FrameworkBundle\Component\EntityLog\Model\EntityLogFacade $entityLogFacade
53+
* @param \Shopsys\FrameworkBundle\Model\Pricing\PricingSetting $pricingSetting
5254
*/
5355
public function __construct(
5456
protected readonly OrderFacade $orderFacade,
@@ -64,6 +66,7 @@ public function __construct(
6466
protected readonly EntityLogGridFactory $entityLogGridFactory,
6567
protected readonly InMemoryCache $inMemoryCache,
6668
protected readonly EntityLogFacade $entityLogFacade,
69+
protected readonly PricingSetting $pricingSetting,
6770
) {
6871
}
6972

@@ -148,6 +151,7 @@ public function addProductAction(Request $request, int $orderId): Response
148151
'order' => $order,
149152
'orderItem' => $orderItem,
150153
'orderItemTotalPricesById' => $orderItemTotalPricesById,
154+
'inputPriceType' => $this->pricingSetting->getInputPriceType(),
151155
]);
152156
}
153157

src/Form/Admin/Pricing/Currency/CurrencyFormType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
9292
t('To whole numbers') => Currency::ROUNDING_TYPE_INTEGER,
9393
],
9494
'label' => t('Price including VAT rounding'),
95+
])
96+
->add('roundingPlacesPriceWithoutVat', NumberType::class, [
97+
'required' => true,
98+
'constraints' => [
99+
new Constraints\NotBlank(['message' => 'Please enter number of rounding places for price without VAT']),
100+
new Constraints\GreaterThanOrEqual(0),
101+
new Constraints\LessThanOrEqual(Currency::MAX_ROUNDING_PLACES_PRICE_WITHOUT_VAT),
102+
],
95103
]);
96104
}
97105

src/Form/Admin/PromoCode/PromoCodeFormType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private function buildLimitsFormGroup(FormBuilderInterface $builder): void
163163
'groups' => [self::VALIDATION_GROUP_TYPE_PERCENT, self::VALIDATION_GROUP_TYPE_NOMINAL],
164164
]),
165165
],
166-
'invalid_message' => 'Please enter whole number.',
166+
'invalid_message' => 'Please enter number.',
167167
'label' => t('Discount (%)'),
168168
];
169169

src/Form/Admin/PromoCode/PromoCodeLimitType.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Override;
88
use Shopsys\FrameworkBundle\Form\Admin\PromoCode\Transformer\PromoCodeLimitTransformer;
99
use Symfony\Component\Form\AbstractType;
10-
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
1110
use Symfony\Component\Form\Extension\Core\Type\NumberType;
1211
use Symfony\Component\Form\FormBuilderInterface;
1312
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -39,13 +38,14 @@ public function configureOptions(OptionsResolver $resolver): void
3938
#[Override]
4039
public function buildForm(FormBuilderInterface $builder, array $options): void
4140
{
42-
$builder->add('fromPriceWithVat', IntegerType::class, [
41+
$builder->add('fromPrice', NumberType::class, [
4342
'constraints' => [
4443
new Constraints\NotBlank([
4544
'message' => 'Please enter limit from',
4645
'groups' => [PromoCodeFormType::VALIDATION_GROUP_TYPE_PERCENT, PromoCodeFormType::VALIDATION_GROUP_TYPE_NOMINAL],
4746
]),
4847
],
48+
'scale' => 6,
4949
]);
5050

5151
$options = $options['discount'];
@@ -62,10 +62,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
6262
'value' => 1,
6363
]);
6464
$options['constraints'][] = new Constraints\Regex([
65-
'groups' => PromoCodeFormType::VALIDATION_GROUP_TYPE_NOMINAL,
65+
'groups' => PromoCodeFormType::VALIDATION_GROUP_TYPE_PERCENT,
6666
'pattern' => '/^\d+$/',
67+
'message' => 'Please enter a whole number.',
6768
]);
68-
$options['scale'] = 3;
69+
$options['scale'] = 6;
6970
$builder->add(
7071
'discount',
7172
NumberType::class,

src/Form/Admin/PromoCode/Transformer/PromoCodeLimitTransformer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function transform($promoCodeLimit): ?array
2525
{
2626
if ($promoCodeLimit instanceof PromoCodeLimit) {
2727
return [
28-
'fromPriceWithVat' => $promoCodeLimit->getFromPriceWithVat(),
28+
'fromPrice' => $promoCodeLimit->getFromPrice(),
2929
'discount' => $promoCodeLimit->getDiscount(),
3030
];
3131
}
@@ -39,10 +39,10 @@ public function transform($promoCodeLimit): ?array
3939
*/
4040
public function reverseTransform($value): PromoCodeLimit
4141
{
42-
if (is_array($value) === false || $value['fromPriceWithVat'] === null || $value['discount'] === null) {
42+
if (is_array($value) === false || $value['fromPrice'] === null || $value['discount'] === null) {
4343
$this->promoCodeLimitFactory->create('0', '0');
4444
}
4545

46-
return $this->promoCodeLimitFactory->create((string)$value['fromPriceWithVat'], (string)$value['discount']);
46+
return $this->promoCodeLimitFactory->create((string)$value['fromPrice'], (string)$value['discount']);
4747
}
4848
}

src/Form/Admin/TransportAndPayment/FreeTransportAndPaymentPriceLimitsFormType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ private function getPriceLimitsBuilder(FormBuilderInterface $builder): FormBuild
8282
'groups' => [static::VALIDATION_GROUP_PRICE_LIMIT_ENABLED],
8383
]),
8484
],
85+
'scale' => 6,
8586
]);
8687

8788
$formBuilderForDomains->add($formBuilderForDomain);

src/Form/OrderItemsType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Shopsys\FrameworkBundle\Form\Admin\Order\OrderTransportFormType;
1111
use Shopsys\FrameworkBundle\Model\Order\Order;
1212
use Shopsys\FrameworkBundle\Model\Payment\PaymentFacade;
13+
use Shopsys\FrameworkBundle\Model\Pricing\PricingSetting;
1314
use Shopsys\FrameworkBundle\Model\Transport\TransportFacade;
1415
use Symfony\Component\Form\AbstractType;
1516
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
@@ -23,10 +24,12 @@ class OrderItemsType extends AbstractType
2324
/**
2425
* @param \Shopsys\FrameworkBundle\Model\Transport\TransportFacade $transportFacade
2526
* @param \Shopsys\FrameworkBundle\Model\Payment\PaymentFacade $paymentFacade
27+
* @param \Shopsys\FrameworkBundle\Model\Pricing\PricingSetting $pricingSetting
2628
*/
2729
public function __construct(
2830
private readonly TransportFacade $transportFacade,
2931
private readonly PaymentFacade $paymentFacade,
32+
private readonly PricingSetting $pricingSetting,
3033
) {
3134
}
3235

@@ -78,6 +81,7 @@ public function buildView(FormView $view, FormInterface $form, array $options):
7881
$order = $options['order'];
7982

8083
$view->vars['order'] = $order;
84+
$view->vars['inputPriceType'] = $this->pricingSetting->getInputPriceType();
8185
$view->vars['transportPricesWithVatByTransportId'] = $this->transportFacade->getTransportPricesWithVatByCurrencyAndDomainIdIndexedByTransportId(
8286
$order->getDomainId(),
8387
);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Override;
9+
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;
10+
11+
class Version20250226102020 extends AbstractMigration
12+
{
13+
/**
14+
* @param \Doctrine\DBAL\Schema\Schema $schema
15+
*/
16+
#[Override]
17+
public function up(Schema $schema): void
18+
{
19+
$this->sql('ALTER TABLE currencies ADD rounding_places_price_without_vat INT NOT NULL DEFAULT 2');
20+
$this->sql('ALTER TABLE currencies ALTER rounding_places_price_without_vat DROP DEFAULT');
21+
}
22+
23+
/**
24+
* @param \Doctrine\DBAL\Schema\Schema $schema
25+
*/
26+
#[Override]
27+
public function down(Schema $schema): void
28+
{
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Override;
9+
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;
10+
11+
class Version20250303130234 extends AbstractMigration
12+
{
13+
/**
14+
* @param \Doctrine\DBAL\Schema\Schema $schema
15+
*/
16+
#[Override]
17+
public function up(Schema $schema): void
18+
{
19+
$this->sql('ALTER TABLE promo_code_limit DROP CONSTRAINT promo_code_limit_pkey');
20+
$this->sql('ALTER TABLE promo_code_limit RENAME COLUMN from_price_with_vat TO from_price');
21+
$this->sql('ALTER TABLE promo_code_limit ADD PRIMARY KEY (promo_code_id, from_price)');
22+
}
23+
24+
/**
25+
* @param \Doctrine\DBAL\Schema\Schema $schema
26+
*/
27+
#[Override]
28+
public function down(Schema $schema): void
29+
{
30+
}
31+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Override;
9+
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;
10+
11+
class Version20250312132504 extends AbstractMigration
12+
{
13+
/**
14+
* @param \Doctrine\DBAL\Schema\Schema $schema
15+
*/
16+
#[Override]
17+
public function up(Schema $schema): void
18+
{
19+
$this->sql('ALTER TABLE promo_code_limit ALTER from_price TYPE NUMERIC(20, 6)');
20+
$this->sql('ALTER TABLE promo_code_limit ALTER discount TYPE NUMERIC(20, 6)');
21+
}
22+
23+
/**
24+
* @param \Doctrine\DBAL\Schema\Schema $schema
25+
*/
26+
#[Override]
27+
public function down(Schema $schema): void
28+
{
29+
}
30+
}

0 commit comments

Comments
 (0)