Przeglądaj źródła

ControllerTrait + MailMailjetNotification + modifs liées à AbstractFieldDefinition

packProduct
Guillaume 3 lat temu
rodzic
commit
d4ce9258dc
11 zmienionych plików z 167 dodań i 70 usunięć
  1. +1
    -1
      Builder/Reduction/ReductionCreditBuilder.php
  2. +9
    -0
      Container/PointSale/PointSaleContainer.php
  3. +10
    -0
      Controller/AbstractAdminController.php
  4. +5
    -32
      Controller/AdminControllerTrait.php
  5. +1
    -2
      Controller/ControllerTrait.php
  6. +5
    -32
      Controller/PointSale/PointSaleAdminController.php
  7. +5
    -0
      Definition/Field/Order/OrderShopFieldDefinition.php
  8. +60
    -0
      Definition/Field/PointSale/PointSaleFieldDefinition.php
  9. +2
    -2
      Form/Setting/MerchantSettingsFormType.php
  10. +65
    -0
      Notification/MailMailjetNotification.php
  11. +4
    -1
      Resources/translations/admin.fr.yaml

+ 1
- 1
Builder/Reduction/ReductionCreditBuilder.php Wyświetl plik

@@ -11,7 +11,7 @@ use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\User\UserSolver;
use Lc\SovBundle\Notification\MailMailjetNotification;
use Lc\CaracoleBundle\Notification\MailMailjetNotification;

class ReductionCreditBuilder
{

+ 9
- 0
Container/PointSale/PointSaleContainer.php Wyświetl plik

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Container\PointSale;

use Lc\CaracoleBundle\Definition\Field\PointSale\PointSaleFieldDefinition;
use Lc\CaracoleBundle\Factory\PointSale\PointSaleFactory;
use Lc\CaracoleBundle\Repository\PointSale\PointSaleRepositoryQuery;
use Lc\CaracoleBundle\Repository\PointSale\PointSaleStore;
@@ -11,17 +12,20 @@ class PointSaleContainer
{
protected PointSaleFactory $factory;
protected PointSaleSolver $solver;
protected PointSaleFieldDefinition $fieldDefinition;
protected PointSaleRepositoryQuery $repositoryQuery;
protected PointSaleStore $store;

public function __construct(
PointSaleFactory $factory,
PointSaleSolver $solver,
PointSaleFieldDefinition $fieldDefinition,
PointSaleRepositoryQuery $repositoryQuery,
PointSaleStore $store
) {
$this->factory = $factory;
$this->solver = $solver;
$this->fieldDefinition = $fieldDefinition;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
}
@@ -36,6 +40,11 @@ class PointSaleContainer
return $this->solver;
}

public function getFieldDefinition(): PointSaleFieldDefinition
{
return $this->fieldDefinition;
}

public function getRepositoryQuery(): PointSaleRepositoryQuery
{
return $this->repositoryQuery;

+ 10
- 0
Controller/AbstractAdminController.php Wyświetl plik

@@ -0,0 +1,10 @@
<?php

namespace Lc\CaracoleBundle\Controller;

use Lc\SovBundle\Controller\AbstractAdminController as SovAbstractAdminController;

abstract class AbstractAdminController extends SovAbstractAdminController
{
use AdminControllerTrait;
}

+ 5
- 32
Controller/AdminControllerTrait.php Wyświetl plik

@@ -62,8 +62,11 @@ use Symfony\Component\HttpFoundation\Response;

trait AdminControllerTrait
{

use ControllerTrait;

//TODO doit implementer ControllerTrait
public static function getSubscribedServices()
/*public static function getSubscribedServices()
{
return array_merge(
parent::getSubscribedServices(),
@@ -107,7 +110,7 @@ trait AdminControllerTrait
UserPointSaleContainer::class => UserPointSaleContainer::class,
VisitorContainer::class => VisitorContainer::class
];
}
}*/

public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
{
@@ -334,36 +337,6 @@ trait AdminControllerTrait
return $duplicateAction;
}

public function getCurrentSection()
{
return $this->get(SectionResolver::class)->getCurrent();
}

public function getCurrentMerchant()
{
return $this->get(MerchantResolver::class)->getCurrent();
}

public function getMerchantSettingCurrent(string $settingName)
{
return $this->getSettingValue($this->getCurrentMerchant(), $settingName);
}

public function getSectionSettingCurrent(string $settingName)
{
return $this->getSettingValue($this->getCurrentSection(), $settingName);
}

public function getSettingSolver(): SettingSolver
{
return $this->get(SettingSolver::class);
}

public function getSettingValue($entity, $settingName)
{
return $this->getSettingSolver()->getSettingValue($entity, $settingName);
}


}


+ 1
- 2
Controller/ControllerTrait.php Wyświetl plik

@@ -96,7 +96,7 @@ trait ControllerTrait

public function getSectionSettingCurrent(string $settingName)
{
return $this->getSettingValue($this->getCurrentSection(), $settingName);
return $this->getSettingValue($this->getSectionCurrent(), $settingName);
}

public function getSettingSolver(): SettingSolver
@@ -109,7 +109,6 @@ trait ControllerTrait
return $this->getSettingSolver()->getSettingValue($entity, $settingName);
}


public function getUserCurrent(): ?UserInterface
{
return $this->get(Security::class)->getUser();

+ 5
- 32
Controller/PointSale/PointSaleAdminController.php Wyświetl plik

@@ -2,20 +2,9 @@

namespace Lc\CaracoleBundle\Controller\PointSale;

use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Container\PointSale\PointSaleContainer;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\PointSale\PointSaleFactory;
use Lc\CaracoleBundle\Field\Address\AddressField;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Field\ToggleField;

abstract class PointSaleAdminController extends AbstractAdminController
{
@@ -23,31 +12,15 @@ abstract class PointSaleAdminController extends AbstractAdminController

public function configureFields(string $pageName): iterable
{
return array_merge(
[
FormField::addPanel('general'),
IntegerField::new('id')->onlyOnIndex()->setSortable(true),
TextField::new('title')->setSortable(true),
MoneyField::new('orderAmountMin')->setCurrency('EUR')->setSortable(true),
NumberField::new('deliveryPrice')
->setCustomOption('appendHtml', '€')
->hideOnIndex(),
StatusField::new('status')->setSortable(true),
ToggleField::new('isPublic')->setSortable(true),
ToggleField::new('isDepository')->setSortable(true),
FormField::addPanel('address'),
AddressField::new('address')
->setRequired(true)
],
$this->getSeoPanel(),
$this->getConfPanel(),
);
return $this->getPointSaleContainer()
->getFieldDefinition()
->getFieldList($pageName);
}

public function createEntity(string $entityFqcn)
{
return $this->get(PointSaleContainer::class)
->getFactory()
->create($this->get(MerchantResolver::class)->getCurrent());
->getFactory()
->create($this->getMerchantCurrent());
}
}

+ 5
- 0
Definition/Field/Order/OrderShopFieldDefinition.php Wyświetl plik

@@ -16,6 +16,11 @@ class OrderShopFieldDefinition extends AbstractFieldDefinition
{
use MerchantContextTrait;

public function configureFieldsIndex(): array
{
return ['id'];
}

public function configurePanels(): array
{
return [];

+ 60
- 0
Definition/Field/PointSale/PointSaleFieldDefinition.php Wyświetl plik

@@ -0,0 +1,60 @@
<?php

namespace Lc\CaracoleBundle\Definition\Field\PointSale;

use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Field\Address\AddressField;
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;
use Lc\SovBundle\Field\StatusField;

class PointSaleFieldDefinition extends AbstractFieldDefinition
{

public function configureFieldsIndex(): array
{
return [
'id',
'title',
'status'
];
}

public function configurePanels(): array
{
return [
'main',
'address',
'seo',
'conf'
];
}

public function configureFieldsPanelMain(): array
{
return [
'title',
'description',
'status'
];
}

public function configureFieldsPanelAddress(): array
{
return ['address'];
}

public function configureFields(): array
{
return [
'id' => IntegerField::new('id')->setSortable(true)->onlyOnIndex(),
'title' => TextField::new('title')->setSortable(true),
'description' => TextEditorField::new('description'),
'status' => StatusField::new('status')->setSortable(true),
'address' => AddressField::new('address')
->setRequired(true),
];
}

}

+ 2
- 2
Form/Setting/MerchantSettingsFormType.php Wyświetl plik

@@ -15,8 +15,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver;

class MerchantSettingsFormType extends AbstractType
{
protected $em;
protected $translatorAdmin;
protected EntityManagerInterface $em;
protected TranslatorAdmin $translatorAdmin;

public function __construct(EntityManagerInterface $em, TranslatorAdmin $translatorAdmin)
{

+ 65
- 0
Notification/MailMailjetNotification.php Wyświetl plik

@@ -0,0 +1,65 @@
<?php

namespace Lc\CaracoleBundle\Notification;

use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Notification\MailMailjetNotification as SovMailMailjetNotification;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\SovBundle\Repository\Site\SiteStore;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Twig\Environment;

class MailMailjetNotification extends SovMailMailjetNotification
{
protected MerchantResolver $merchantResolver;

public function __construct(
MailjetTransport $mailjetTransport,
Environment $templating,
ParameterBagInterface $parameterBag,
SettingSolver $settingSolver,
MerchantResolver $merchantResolver,
SiteStore $siteStore
) {
parent::__construct($mailjetTransport, $templating, $parameterBag, $settingSolver, $siteStore);
$this->merchantResolver = $merchantResolver;
}

public function send($params = [])
{
$merchantCurrent = $this->merchantResolver->getCurrent();

$merchantConfigEmailFrom = $this->settingSolver->getSettingValue(
$merchantCurrent,
MerchantSettingDefinition::SETTING_EMAIL_FROM
);
$emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen(
$params[self::FROM_EMAIL]
)) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom;

$merchantConfigEmailFromName = $this->settingSolver->getSettingValue(
$merchantCurrent,
MerchantSettingDefinition::SETTING_EMAIL_FROM_NAME
);
$emailFromName = isset($params[self::FROM_NAME]) ?? $merchantConfigEmailFromName;

$merchantConfigEmailSubjectPrefix = $this->settingSolver->getSettingValue(
$merchantCurrent,
MerchantSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX
);
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ?? $merchantConfigEmailSubjectPrefix;
if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) {
$emailSubjectPrefix .= ' ';
}

return parent::send(
array_merge($params, [
self::FROM_EMAIL => $emailFrom,
self::FROM_NAME => $emailFromName,
self::SUBJECT_PREFIX => $emailSubjectPrefix
])
);
}
}

+ 4
- 1
Resources/translations/admin.fr.yaml Wyświetl plik

@@ -47,7 +47,9 @@ setting_definition:
entity:
default:
panels:
main: Général
address: Adresse
conf: Configuration
fields:
property: Caractéristiques
propertyValue : Valeurs
@@ -73,8 +75,9 @@ entity:
label_plurial: Points de vente
fields:
orderAmountMin: Montant minimum de commande
isPublic: Public
isPublic: Publique
isDepository: Dépôt
deliveryPrice: Montant de la livraison

Address:
fields:

Ładowanie…
Anuluj
Zapisz