Skip to content

Commit

Permalink
[shopsys] removed transport type entity and replace it with enum clas…
Browse files Browse the repository at this point in the history
…s (#3431)
  • Loading branch information
grossmannmartin authored Sep 20, 2024
2 parents 8191df9 + c70fc83 commit 79cd98f
Show file tree
Hide file tree
Showing 30 changed files with 113 additions and 757 deletions.
8 changes: 2 additions & 6 deletions src/Component/Packetery/PacketeryCronModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
namespace Shopsys\FrameworkBundle\Component\Packetery;

use Shopsys\FrameworkBundle\Model\Order\OrderFacade;
use Shopsys\FrameworkBundle\Model\Transport\Type\TransportType;
use Shopsys\FrameworkBundle\Model\Transport\Type\TransportTypeFacade;
use Shopsys\FrameworkBundle\Model\Transport\TransportTypeEnum;
use Shopsys\Plugin\Cron\SimpleCronModuleInterface;
use Symfony\Bridge\Monolog\Logger;

Expand All @@ -15,12 +14,10 @@ class PacketeryCronModule implements SimpleCronModuleInterface
/**
* @param \Shopsys\FrameworkBundle\Component\Packetery\PacketeryClient $packeteryClient
* @param \Shopsys\FrameworkBundle\Model\Order\OrderFacade $orderFacade
* @param \Shopsys\FrameworkBundle\Model\Transport\Type\TransportTypeFacade $transportTypeFacade
*/
public function __construct(
protected readonly PacketeryClient $packeteryClient,
protected readonly OrderFacade $orderFacade,
protected readonly TransportTypeFacade $transportTypeFacade,
) {
}

Expand All @@ -36,8 +33,7 @@ public function setLogger(Logger $logger): void
*/
public function run(): void
{
$transportType = $this->transportTypeFacade->getByCode(TransportType::TYPE_PACKETERY);
$orders = $this->orderFacade->getAllWithoutTrackingNumberByTransportType($transportType);
$orders = $this->orderFacade->getAllWithoutTrackingNumberByTransportType(TransportTypeEnum::TYPE_PACKETERY);
$this->packeteryClient->sendPackets($orders);
}
}
101 changes: 0 additions & 101 deletions src/Controller/Admin/TransportTypeController.php

This file was deleted.

12 changes: 5 additions & 7 deletions src/Form/Admin/Transport/TransportFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Shopsys\FrameworkBundle\Model\Transport\Transport;
use Shopsys\FrameworkBundle\Model\Transport\TransportData;
use Shopsys\FrameworkBundle\Model\Transport\TransportFacade;
use Shopsys\FrameworkBundle\Model\Transport\Type\TransportTypeFacade;
use Shopsys\FrameworkBundle\Model\Transport\TransportTypeEnum;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
Expand All @@ -37,12 +37,12 @@ class TransportFormType extends AbstractType
/**
* @param \Shopsys\FrameworkBundle\Model\Payment\PaymentFacade $paymentFacade
* @param \Shopsys\FrameworkBundle\Model\Transport\TransportFacade $transportFacade
* @param \Shopsys\FrameworkBundle\Model\Transport\Type\TransportTypeFacade $transportTypeFacade
* @param \Shopsys\FrameworkBundle\Model\Transport\TransportTypeEnum $transportTypeEnum
*/
public function __construct(
private readonly PaymentFacade $paymentFacade,
private readonly TransportFacade $transportFacade,
private readonly TransportTypeFacade $transportTypeFacade,
protected readonly TransportTypeEnum $transportTypeEnum,
) {
}

Expand Down Expand Up @@ -97,11 +97,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'empty_message' => t('You have to create some payment first.'),
'label' => t('Available payment methods'),
])
->add('transportType', ChoiceType::class, [
->add('type', ChoiceType::class, [
'required' => true,
'choices' => $this->transportTypeFacade->getAll(),
'choice_label' => 'name',
'choice_value' => 'id',
'choices' => $this->transportTypeEnum->getAllIndexedByTranslations(),
'constraints' => [
new NotBlank(),
],
Expand Down
57 changes: 0 additions & 57 deletions src/Form/Admin/Transport/TransportTypeFormType.php

This file was deleted.

11 changes: 7 additions & 4 deletions src/Migrations/Version20240403091822.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

use Doctrine\DBAL\Schema\Schema;
use Shopsys\FrameworkBundle\Component\Translation\Translator;
use Shopsys\FrameworkBundle\Model\Transport\Type\TransportType;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

class Version20240403091822 extends AbstractMigration implements ContainerAwareInterface
{
use MultidomainMigrationTrait;

private const string TRANSPORT_TYPE_COMMON = 'common';
private const string TRANSPORT_TYPE_PACKETERY = 'packetery';
private const string TRANSPORT_TYPE_PERSONAL_PICKUP = 'personal_pickup';

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
Expand Down Expand Up @@ -297,7 +300,7 @@ public function up(Schema $schema): void
CONSTRAINT FK_11E2A9472C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES transport_types (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->sql('CREATE UNIQUE INDEX UNIQ_C43F2EC877153098 ON transport_types (code)');

$this->sql('INSERT INTO transport_types (code) VALUES (\'' . TransportType::TYPE_COMMON . '\')');
$this->sql('INSERT INTO transport_types (code) VALUES (\'' . self::TRANSPORT_TYPE_COMMON . '\')');

foreach ($this->getAllLocales() as $locale) {
$this->sql('INSERT INTO transport_type_translations (translatable_id, name, locale) VALUES (1, \'' . t('Standard', [], Translator::DEFAULT_TRANSLATION_DOMAIN, $locale) . '\', \'' . $locale . '\')');
Expand Down Expand Up @@ -329,7 +332,7 @@ public function up(Schema $schema): void
}

if ($this->isAppMigrationNotInstalledRemoveIfExists('Version20231004072533')) {
$this->sql('INSERT INTO transport_types (code) VALUES (\'' . TransportType::TYPE_PERSONAL_PICKUP . '\')');
$this->sql('INSERT INTO transport_types (code) VALUES (\'' . self::TRANSPORT_TYPE_PERSONAL_PICKUP . '\')');
$lastTransportTypeId = $this->connection->lastInsertId('transport_types_id_seq');

foreach ($this->getAllLocales() as $locale) {
Expand Down Expand Up @@ -378,7 +381,7 @@ public function up(Schema $schema): void
}

if ($this->isAppMigrationNotInstalledRemoveIfExists('Version20210813063216')) {
$this->sql('INSERT INTO transport_types (code) VALUES (\'' . TransportType::TYPE_PACKETERY . '\')');
$this->sql('INSERT INTO transport_types (code) VALUES (\'' . self::TRANSPORT_TYPE_PACKETERY . '\')');
$lastTransportTypeId = $this->connection->lastInsertId('transport_types_id_seq');
$this->sql('INSERT INTO transport_type_translations (translatable_id, name, locale) VALUES (' . $lastTransportTypeId . ', \'Zásilkovna\', \'cs\')');
$this->sql('INSERT INTO transport_type_translations (translatable_id, name, locale) VALUES (' . $lastTransportTypeId . ', \'Packetery\', \'en\')');
Expand Down
35 changes: 35 additions & 0 deletions src/Migrations/Version20240911133739.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrameworkBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;

class Version20240911133739 extends AbstractMigration
{
/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function up(Schema $schema): void
{
$this->sql('ALTER TABLE transports ADD type VARCHAR(25) NOT NULL DEFAULT \'\'');
$this->sql('ALTER TABLE transports ALTER type DROP DEFAULT');

$this->sql(
'UPDATE transports SET type = (SELECT code FROM transport_types WHERE transports.transport_type_id = transport_types.id)',
);
$this->sql('ALTER TABLE transports DROP COLUMN transport_type_id');

$this->sql('DROP TABLE transport_type_translations');
$this->sql('DROP TABLE transport_types');
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function down(Schema $schema): void
{
}
}
5 changes: 2 additions & 3 deletions src/Model/Order/OrderFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use Shopsys\FrameworkBundle\Model\Payment\Transaction\PaymentTransactionFacade;
use Shopsys\FrameworkBundle\Model\Pricing\Price;
use Shopsys\FrameworkBundle\Model\Transport\TransportPriceCalculation;
use Shopsys\FrameworkBundle\Model\Transport\Type\TransportType;
use Shopsys\FrameworkBundle\Twig\NumberFormatterExtension;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -389,10 +388,10 @@ public function updateTrackingNumber(Order $order, string $trackingNumber): void
}

/**
* @param \Shopsys\FrameworkBundle\Model\Transport\Type\TransportType $transportType
* @param string $transportType
* @return \Shopsys\FrameworkBundle\Model\Order\Order[]
*/
public function getAllWithoutTrackingNumberByTransportType(TransportType $transportType): array
public function getAllWithoutTrackingNumberByTransportType(string $transportType): array
{
return $this->orderRepository->getAllWithoutTrackingNumberByTransportType($transportType);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Model/Order/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Shopsys\FrameworkBundle\Model\Order\Listing\OrderListAdminRepository;
use Shopsys\FrameworkBundle\Model\Order\Status\OrderStatus;
use Shopsys\FrameworkBundle\Model\Pricing\Currency\Currency;
use Shopsys\FrameworkBundle\Model\Transport\Type\TransportType;

class OrderRepository
{
Expand Down Expand Up @@ -303,15 +302,15 @@ protected function getOrderListQueryBuilder()
}

/**
* @param \Shopsys\FrameworkBundle\Model\Transport\Type\TransportType $transportType
* @param string $transportType
* @return \Shopsys\FrameworkBundle\Model\Order\Order[]
*/
public function getAllWithoutTrackingNumberByTransportType(TransportType $transportType): array
public function getAllWithoutTrackingNumberByTransportType(string $transportType): array
{
$queryBuilder = $this->createOrderQueryBuilder()
->join('o.transport', 't')
->andWhere('o.trackingNumber IS NULL')
->andWhere('t.transportType = :transportType')
->andWhere('t.type = :transportType')
->setParameter('transportType', $transportType);

return $queryBuilder->getQuery()->execute();
Expand Down
3 changes: 0 additions & 3 deletions src/Model/Security/MenuItemsGrantedRolesSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ protected function getPagesGrantedRoles(): array
'settings' . static::MENU_ITEM_PATH_SEPARATOR . 'lists' . static::MENU_ITEM_PATH_SEPARATOR . 'parameter_values' => [
Roles::ROLE_PARAMETER_VALUE_VIEW,
],
'settings' . static::MENU_ITEM_PATH_SEPARATOR . 'lists' . static::MENU_ITEM_PATH_SEPARATOR . 'transport_type' => [
Roles::ROLE_TRANSPORT_TYPE_VIEW,
],
'settings' . static::MENU_ITEM_PATH_SEPARATOR . 'seo' . static::MENU_ITEM_PATH_SEPARATOR . 'seo' => [
Roles::ROLE_SEO_VIEW,
],
Expand Down
7 changes: 0 additions & 7 deletions src/Model/Security/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ class Roles
public const string ROLE_PARAMETER_VALUE_FULL = 'ROLE_PARAMETER_VALUE_FULL';
public const string ROLE_PARAMETER_VALUE_VIEW = 'ROLE_PARAMETER_VALUE_VIEW';

public const string ROLE_TRANSPORT_TYPE_FULL = 'ROLE_TRANSPORT_TYPE_FULL';
public const string ROLE_TRANSPORT_TYPE_VIEW = 'ROLE_TRANSPORT_TYPE_VIEW';

public const string ROLE_SEO_FULL = 'ROLE_SEO_FULL';
public const string ROLE_SEO_VIEW = 'ROLE_SEO_VIEW';

Expand Down Expand Up @@ -340,10 +337,6 @@ public function getAvailableAdministratorRolesGrid(): array
static::ROLE_PARAMETER_VALUE_FULL => t('Color parameter values - full'),
static::ROLE_PARAMETER_VALUE_VIEW => t('Color parameter values - view'),
],
[
static::ROLE_TRANSPORT_TYPE_FULL => t('Transport types - full'),
static::ROLE_TRANSPORT_TYPE_VIEW => t('Transport types - view'),
],
[
static::ROLE_SEO_FULL => t('SEO - full'),
static::ROLE_SEO_VIEW => t('SEO - view'),
Expand Down
Loading

0 comments on commit 79cd98f

Please sign in to comment.