Browse Source

ControllerTrait + MailMailjetNotification + modifs liées à AbstractFieldDefinition

packProduct
Guillaume 3 years ago
parent
commit
d4ce9258dc
11 changed files with 167 additions and 70 deletions
  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 View File

use Lc\CaracoleBundle\Repository\Section\SectionStore; use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\User\UserSolver; use Lc\CaracoleBundle\Solver\User\UserSolver;
use Lc\SovBundle\Notification\MailMailjetNotification;
use Lc\CaracoleBundle\Notification\MailMailjetNotification;


class ReductionCreditBuilder class ReductionCreditBuilder
{ {

+ 9
- 0
Container/PointSale/PointSaleContainer.php View File



namespace Lc\CaracoleBundle\Container\PointSale; namespace Lc\CaracoleBundle\Container\PointSale;


use Lc\CaracoleBundle\Definition\Field\PointSale\PointSaleFieldDefinition;
use Lc\CaracoleBundle\Factory\PointSale\PointSaleFactory; use Lc\CaracoleBundle\Factory\PointSale\PointSaleFactory;
use Lc\CaracoleBundle\Repository\PointSale\PointSaleRepositoryQuery; use Lc\CaracoleBundle\Repository\PointSale\PointSaleRepositoryQuery;
use Lc\CaracoleBundle\Repository\PointSale\PointSaleStore; use Lc\CaracoleBundle\Repository\PointSale\PointSaleStore;
{ {
protected PointSaleFactory $factory; protected PointSaleFactory $factory;
protected PointSaleSolver $solver; protected PointSaleSolver $solver;
protected PointSaleFieldDefinition $fieldDefinition;
protected PointSaleRepositoryQuery $repositoryQuery; protected PointSaleRepositoryQuery $repositoryQuery;
protected PointSaleStore $store; protected PointSaleStore $store;


public function __construct( public function __construct(
PointSaleFactory $factory, PointSaleFactory $factory,
PointSaleSolver $solver, PointSaleSolver $solver,
PointSaleFieldDefinition $fieldDefinition,
PointSaleRepositoryQuery $repositoryQuery, PointSaleRepositoryQuery $repositoryQuery,
PointSaleStore $store PointSaleStore $store
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->solver = $solver; $this->solver = $solver;
$this->fieldDefinition = $fieldDefinition;
$this->repositoryQuery = $repositoryQuery; $this->repositoryQuery = $repositoryQuery;
$this->store = $store; $this->store = $store;
} }
return $this->solver; return $this->solver;
} }


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

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

+ 10
- 0
Controller/AbstractAdminController.php View File

<?php

namespace Lc\CaracoleBundle\Controller;

use Lc\SovBundle\Controller\AbstractAdminController as SovAbstractAdminController;

abstract class AbstractAdminController extends SovAbstractAdminController
{
use AdminControllerTrait;
}

+ 5
- 32
Controller/AdminControllerTrait.php View File



trait AdminControllerTrait trait AdminControllerTrait
{ {

use ControllerTrait;

//TODO doit implementer ControllerTrait //TODO doit implementer ControllerTrait
public static function getSubscribedServices()
/*public static function getSubscribedServices()
{ {
return array_merge( return array_merge(
parent::getSubscribedServices(), parent::getSubscribedServices(),
UserPointSaleContainer::class => UserPointSaleContainer::class, UserPointSaleContainer::class => UserPointSaleContainer::class,
VisitorContainer::class => VisitorContainer::class VisitorContainer::class => VisitorContainer::class
]; ];
}
}*/


public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
{ {
return $duplicateAction; 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 View File



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


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



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

+ 5
- 32
Controller/PointSale/PointSaleAdminController.php View File



namespace Lc\CaracoleBundle\Controller\PointSale; 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\Container\PointSale\PointSaleContainer;
use Lc\CaracoleBundle\Controller\AdminControllerTrait; 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\Controller\AbstractAdminController;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Field\ToggleField;


abstract class PointSaleAdminController extends AbstractAdminController abstract class PointSaleAdminController extends AbstractAdminController
{ {


public function configureFields(string $pageName): iterable 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) public function createEntity(string $entityFqcn)
{ {
return $this->get(PointSaleContainer::class) return $this->get(PointSaleContainer::class)
->getFactory()
->create($this->get(MerchantResolver::class)->getCurrent());
->getFactory()
->create($this->getMerchantCurrent());
} }
} }

+ 5
- 0
Definition/Field/Order/OrderShopFieldDefinition.php View File

{ {
use MerchantContextTrait; use MerchantContextTrait;


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

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

+ 60
- 0
Definition/Field/PointSale/PointSaleFieldDefinition.php View File

<?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 View File



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


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

+ 65
- 0
Notification/MailMailjetNotification.php View File

<?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 View File

entity: entity:
default: default:
panels: panels:
main: Général
address: Adresse address: Adresse
conf: Configuration
fields: fields:
property: Caractéristiques property: Caractéristiques
propertyValue : Valeurs propertyValue : Valeurs
label_plurial: Points de vente label_plurial: Points de vente
fields: fields:
orderAmountMin: Montant minimum de commande orderAmountMin: Montant minimum de commande
isPublic: Public
isPublic: Publique
isDepository: Dépôt isDepository: Dépôt
deliveryPrice: Montant de la livraison


Address: Address:
fields: fields:

Loading…
Cancel
Save