Browse Source

Merge branch 'develop'

master
Guillaume 2 years ago
parent
commit
e6e26c4266
22 changed files with 323 additions and 192 deletions
  1. +3
    -3
      Builder/File/DocumentBuilder.php
  2. +10
    -1
      Builder/User/UserBuilder.php
  3. +10
    -1
      Container/File/DocumentContainer.php
  4. +1
    -1
      Controller/ControllerTrait.php
  5. +8
    -10
      Controller/Merchant/FavoriteMerchantAdminController.php
  6. +8
    -9
      Controller/Merchant/FavoriteMerchantController.php
  7. +18
    -6
      Controller/Merchant/SwitchMerchantController.php
  8. +1
    -1
      Controller/Section/SwitchSectionAdminController.php
  9. +2
    -0
      Definition/ActionDefinition.php
  10. +62
    -28
      Form/Section/SwitchSectionFormType.php
  11. +1
    -2
      Generator/DocumentReferenceGenerator.php
  12. +17
    -0
      Repository/File/DocumentRepositoryQuery.php
  13. +18
    -1
      Repository/File/DocumentStore.php
  14. +2
    -1
      Repository/Product/ProductFamilyRepositoryQuery.php
  15. +68
    -67
      Repository/Product/ProductFamilyStore.php
  16. +35
    -27
      Repository/Reduction/ReductionCatalogRepositoryQuery.php
  17. +16
    -1
      Resources/translations/admin.fr.yaml
  18. +5
    -3
      Resources/views/admin/order/field/order_payment.html.twig
  19. +15
    -17
      Resources/views/adminlte/layout.html.twig
  20. +13
    -0
      Solver/Price/ProductPriceSolver.php
  21. +6
    -5
      Transformer/Order/OrderShopTransformer.php
  22. +4
    -8
      Twig/FormTwigExtension.php

+ 3
- 3
Builder/File/DocumentBuilder.php View File

namespace Lc\CaracoleBundle\Builder\File; namespace Lc\CaracoleBundle\Builder\File;


use Lc\CaracoleBundle\Model\File\DocumentInterface; use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Model\File\DocumentModel;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator; use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator;
use Lc\CaracoleBundle\Solver\Address\AddressSolver; use Lc\CaracoleBundle\Solver\Address\AddressSolver;
{ {
$merchantAddress = $orderShop->getSection()->getMerchant()->getAddress(); $merchantAddress = $orderShop->getSection()->getMerchant()->getAddress();
$buyerAddress = $orderShop->getInvoiceAddress(); $buyerAddress = $orderShop->getInvoiceAddress();
//TODO a discuter, doit on garder le lien avec merchant pr la référence ou le mettre par section ? Est-ce que le nom de cette fonction est approprié. on fait une invoice et ça s'appele initFromOrderShop
$document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getSection()->getMerchant(), $document->getType())) ;

// @TODO a discuter, doit on garder le lien avec merchant pr la référence ou le mettre par section ? Est-ce que le nom de cette fonction est approprié. on fait une invoice et ça s'appele initFromOrderShop
$document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getSection()->getMerchant(), $document->getType(), $orderShop)) ;


$document->setMerchantAddress($merchantAddress); $document->setMerchantAddress($merchantAddress);
$document->setBuyerAddress($buyerAddress); $document->setBuyerAddress($buyerAddress);

+ 10
- 1
Builder/User/UserBuilder.php View File

namespace Lc\CaracoleBundle\Builder\User; namespace Lc\CaracoleBundle\Builder\User;


use Lc\CaracoleBundle\Factory\User\UserPointSaleFactory; use Lc\CaracoleBundle\Factory\User\UserPointSaleFactory;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Builder\User\UserBuilder as SovUserBuilder; use Lc\SovBundle\Builder\User\UserBuilder as SovUserBuilder;
{ {


// linkUserToPointSale // linkUserToPointSale
public function linkToPointSale(UserInterface $user, PointSaleInterface $pointSale):bool
public function linkToPointSale(UserInterface $user, PointSaleInterface $pointSale): bool
{ {
if (!$this->userSolver->isLinkedToPointSale($user, $pointSale)) { if (!$this->userSolver->isLinkedToPointSale($user, $pointSale)) {
$userPointSaleFactory = new UserPointSaleFactory(); $userPointSaleFactory = new UserPointSaleFactory();


return false; return false;
} }

public function setFavoriteMerchant(UserInterface $user, MerchantInterface $merchant)
{
$user->setFavoriteMerchant($merchant);
$this->entityManager->update($user);
$this->entityManager->flush();
return true;
}
} }



+ 10
- 1
Container/File/DocumentContainer.php View File

namespace Lc\CaracoleBundle\Container\File; namespace Lc\CaracoleBundle\Container\File;


use Lc\CaracoleBundle\Factory\File\DocumentFactory; use Lc\CaracoleBundle\Factory\File\DocumentFactory;
use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator;
use Lc\CaracoleBundle\Repository\File\DocumentRepositoryQuery; use Lc\CaracoleBundle\Repository\File\DocumentRepositoryQuery;
use Lc\CaracoleBundle\Repository\File\DocumentStore; use Lc\CaracoleBundle\Repository\File\DocumentStore;


protected DocumentFactory $factory; protected DocumentFactory $factory;
protected DocumentRepositoryQuery $repositoryQuery; protected DocumentRepositoryQuery $repositoryQuery;
protected DocumentStore $store; protected DocumentStore $store;
protected DocumentReferenceGenerator $referenceGenerator;


public function __construct( public function __construct(
DocumentFactory $factory, DocumentFactory $factory,
DocumentRepositoryQuery $repositoryQuery, DocumentRepositoryQuery $repositoryQuery,
DocumentStore $store
DocumentStore $store,
DocumentReferenceGenerator $referenceGenerator
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->repositoryQuery = $repositoryQuery; $this->repositoryQuery = $repositoryQuery;
$this->store = $store; $this->store = $store;
$this->referenceGenerator = $referenceGenerator;
} }


public function getFactory(): DocumentFactory public function getFactory(): DocumentFactory


return $this->store; return $this->store;
} }

public function getReferenceGenerator(): DocumentReferenceGenerator
{
return $this->referenceGenerator;
}
} }

+ 1
- 1
Controller/ControllerTrait.php View File



trait ControllerTrait trait ControllerTrait
{ {
public static function getSubscribedServices()
public static function getSubscribedServices() :array
{ {
return array_merge( return array_merge(
parent::getSubscribedServices(), parent::getSubscribedServices(),

+ 8
- 10
Controller/Merchant/FavoriteMerchantAdminController.php View File

use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Container\Merchant\MerchantContainer; use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController; use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType; use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
if ($merchant) { if ($merchant) {


$user = $security->getUser(); $user = $security->getUser();
if($user) {
if ($user) {
$user->setFavoriteMerchant($merchant); $user->setFavoriteMerchant($merchant);
$entityManager->update($user); $entityManager->update($user);
$entityManager->flush(); $entityManager->flush();
} }


// @TODO : à fignoler, hein gamin ?
$url = $this->getSettingSolver()->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
) . 'admin';

if ($url) {
return $this->redirect($url);
}
$this->addFlashTranslator('success', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant', ['%merchant%' => $merchant->getTitle()]);
} }

} else {
$this->addFlashTranslator('error', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant');
} }

return $this->redirect($request->headers->get('referer'));
} }
} }

+ 8
- 9
Controller/Merchant/FavoriteMerchantController.php View File

use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Container\Merchant\MerchantContainer; use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController; use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType; use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
$entityManager->flush(); $entityManager->flush();
} }


// @TODO : à fignoler, hein gamin ?
$url = $this->getSettingSolver()->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
) . 'admin';

if ($url) {
return $this->redirect($url);
}
$this->addFlashTranslator('success', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant', ['%merchant%' => $merchant->getTitle()]);
} }

} else {
$this->addFlashTranslator('error', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant');
} }

return $this->redirect($request->headers->get('referer'));
} }

} }

+ 18
- 6
Controller/Merchant/SwitchMerchantController.php View File



use Lc\CaracoleBundle\Container\Merchant\MerchantContainer; use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController; use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType; use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
*/ */
public function switchMerchant(Request $request) public function switchMerchant(Request $request)
{ {
$form = $this->createForm(SwitchMerchantFormType::class);
$form = $this->createForm(
SwitchMerchantFormType::class,
null,
array('csrf_protection' => false)
);
$form->handleRequest($request); $form->handleRequest($request);


if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {


if ($merchant) { if ($merchant) {
$url = $this->getSettingValue( $url = $this->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
$merchant,
MerchantSettingDefinition::SETTING_URL
); );


if ($context == 'admin') { if ($context == 'admin') {
$url .= 'admin'; $url .= 'admin';
} }


if ($url) {
return $this->redirect($url);
}

} }
} }

if ($url) {
return $this->redirect($url);
} else {
$this->addFlashTranslator('error', ActionDefinition::SWITCH_MERCHANT, 'Merchant');
return $this->redirect($request->headers->get('referer'));
}


} }


} }

+ 1
- 1
Controller/Section/SwitchSectionAdminController.php View File



// valeur par défaut de $section : Tout afficher // valeur par défaut de $section : Tout afficher
$section = null; $section = null;
$idSection = $form->get('id_section')->getData();
$idSection = $form->getClickedButton()->getConfig()->getOptions()['attr']['value'];
$userMerchant = $merchantResolver->getUserMerchant(); $userMerchant = $merchantResolver->getUserMerchant();


if($userMerchant) { if($userMerchant) {

+ 2
- 0
Definition/ActionDefinition.php View File

public const DUPLICATE_TO_OTHER_MERCHANT = 'duplicateToOtherMerchant'; public const DUPLICATE_TO_OTHER_MERCHANT = 'duplicateToOtherMerchant';
public const DUPLICATE_TO_OTHER_SECTION = 'duplicateToOtherSection'; public const DUPLICATE_TO_OTHER_SECTION = 'duplicateToOtherSection';
public const EDIT_ADDRESS_USER = 'editAddressUser'; public const EDIT_ADDRESS_USER = 'editAddressUser';
public const SWITCH_MERCHANT = 'switchMerchant';
public const SWITCH_FAVORITE_MERCHANT = 'switchFavoriteMerchant';




} }

+ 62
- 28
Form/Section/SwitchSectionFormType.php View File



namespace Lc\CaracoleBundle\Form\Section; namespace Lc\CaracoleBundle\Form\Section;


use App\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Repository\Section\SectionRepository; use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Resolver\MerchantResolver; use Lc\CaracoleBundle\Resolver\MerchantResolver;


class SwitchSectionFormType extends AbstractType class SwitchSectionFormType extends AbstractType
{ {
protected EntityManager $em;
protected TranslatorAdmin $translatorAdmin; protected TranslatorAdmin $translatorAdmin;
protected SectionStore $sectionStore;
protected SectionResolver $sectionResolver; protected SectionResolver $sectionResolver;
protected MerchantResolver $merchantResolver;
protected SectionSolver $sectionSolver; protected SectionSolver $sectionSolver;


public function __construct( public function __construct(
EntityManager $em,
TranslatorAdmin $translatorAdmin,
SectionResolver $sectionResolver,
SectionSolver $sectionSolver
) {
$this->em = $em;
TranslatorAdmin $translatorAdmin,
SectionStore $sectionStore,
SectionResolver $sectionResolver,
MerchantResolver $merchantResolver,
SectionSolver $sectionSolver
)
{
$this->translatorAdmin = $translatorAdmin; $this->translatorAdmin = $translatorAdmin;
$this->sectionResolver = $sectionResolver; $this->sectionResolver = $sectionResolver;
$this->sectionStore = $sectionStore;
$this->merchantResolver = $merchantResolver;
$this->sectionSolver = $sectionSolver; $this->sectionSolver = $sectionSolver;
} }


public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$section = $options['section'];



// $builder->add(
// 'id_section',
// HiddenType::class,
// [
// 'data' => $section ? $section->getId() : null
// ]
// );




$currentSection = $this->sectionResolver->getCurrent(); $currentSection = $this->sectionResolver->getCurrent();
$sections = $this->sectionStore->setMerchant($this->merchantResolver->getCurrent())->getOnline();


$styleButton = '';
$classButton = 'btn-section';
if (null == $currentSection) {
$classButton .= ' btn-section-current ' . $this->sectionSolver->getHtmlClass($currentSection);
}
//TOUT afficher
$builder->add( $builder->add(
'id_section',
HiddenType::class,
[
'data' => $section ? $section->getId() : null
'switch_all',
SubmitType::class,
[
'label' => 'Tout afficher',
'attr' => [
'class' => $classButton,
'style' => $styleButton,
'value' => null,
] ]
]
); );


$styleButton = '';
$classButton = 'btn-section';
if ($section == $currentSection) {
$classButton .= ' btn-section-current '.$this->sectionSolver->getHtmlClass($currentSection);
}


$builder->add(
'submit',
foreach ($sections as $section) {
$styleButton = '';
$classButton = 'btn-section';
if ($section == $currentSection) {
$classButton .= ' btn-section-current ' . $this->sectionSolver->getHtmlClass($currentSection);
}

$builder->add(
'switch_'.$section->getSlug(),
SubmitType::class, SubmitType::class,
[ [
'label' => $section ? $section->getTitle() : 'Tout afficher',
'attr' => [
'class' => $classButton,
'style' => $styleButton,
]
'label' => $section->getTitle(),
'attr' => [
'class' => $classButton,
'style' => $styleButton,
'value' => $section->getId(),
]
] ]
);
);
}
} }


/** /**
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)
{ {
$resolver->setDefaults( $resolver->setDefaults(
[
'section' => null,
]
[
'section' => null,
]
); );
} }



+ 1
- 2
Generator/DocumentReferenceGenerator.php View File



class DocumentReferenceGenerator class DocumentReferenceGenerator
{ {

protected DocumentStore $documentStore; protected DocumentStore $documentStore;


public function __construct(DocumentStore $documentStore) public function __construct(DocumentStore $documentStore)
$this->documentStore = $documentStore; $this->documentStore = $documentStore;
} }


public function buildReference(MerchantInterface $merchant, string $documentType)
public function buildReference(MerchantInterface $merchant, string $documentType, OrderShopInterface $orderShop = null)
{ {
$prefix = ''; $prefix = '';
if ($documentType == DocumentModel::TYPE_DELIVERY_NOTE) { if ($documentType == DocumentModel::TYPE_DELIVERY_NOTE) {

+ 17
- 0
Repository/File/DocumentRepositoryQuery.php View File

->andWhere('.buyerAddress = :buyerAddress') ->andWhere('.buyerAddress = :buyerAddress')
->setParameter('buyerAddress', $buyerAddress); ->setParameter('buyerAddress', $buyerAddress);
} }

public function filterByReference(string $reference = null)
{
if(is_null($reference)) {
return $this->andWhere('.reference IS NULL');
}
else {
return $this
->andWhere('.reference LIKE :reference')
->setParameter('reference', $reference);
}
}

public function filterIsReferenceNotNull()
{
return $this->andWhere('.reference IS NOT NULL');
}
} }

+ 18
- 1
Repository/File/DocumentStore.php View File



use App\Entity\Address\Address; use App\Entity\Address\Address;
use Lc\CaracoleBundle\Model\File\DocumentInterface; use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Model\File\DocumentModel;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait; use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Repository\AbstractStore; use Lc\CaracoleBundle\Repository\AbstractStore;


public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
$query->orderBy('id');
return $query; return $query;
} }


return $query; return $query;
} }


public function getOneByReference(string $reference = null, string $type = null, $query = null)
{
$query = $this->createDefaultQuery($query);

$query
->filterByReference($reference)
->orderBy('createdAt', 'ASC')
->innerJoin('.orderShops', 'orderShops')
;

if(!is_null($type)) {
$query->filterByType($type);
}

return $query->findOne();
}


public function getOneLatestByType(string $documentType, $query = null): DocumentInterface public function getOneLatestByType(string $documentType, $query = null): DocumentInterface
{ {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterIsReferenceNotNull()
->filterByType($documentType) ->filterByType($documentType)
->orderBy('createdAt', 'DESC'); ->orderBy('createdAt', 'DESC');



+ 2
- 1
Repository/Product/ProductFamilyRepositoryQuery.php View File



$this->leftJoin('.productCategories', 'productCategories'); $this->leftJoin('.productCategories', 'productCategories');
if ($addSelect) { if ($addSelect) {
$this->addSelect('productCategories');
//Commenté sinon doctrine n'hydrate pas correctement les catégories liés au ProductFamily (exemple : un seul sur trois)
//$this->addSelect('productCategories');
} }
return $this; return $this;
} }

+ 68
- 67
Repository/Product/ProductFamilyStore.php View File

} }


public function getByParentCategory( public function getByParentCategory(
ProductCategoryInterface $parentCategory,
$user = null,
$query = null
) {
ProductCategoryInterface $parentCategory,
$user = null,
$query = null
)
{
$productFamiliesArray = []; $productFamiliesArray = [];


foreach ($parentCategory->getChildrens() as $i => $category) { foreach ($parentCategory->getChildrens() as $i => $category) {


// getProductFamiliesByCategory // getProductFamiliesByCategory
public function getByCategory( public function getByCategory(
ProductCategoryInterface $productCategory,
$query = null
) {
ProductCategoryInterface $productCategory,
$query = null
)
{
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterIsOnline()
->filterByProductCategory($productCategory);
->filterIsOnline()
->filterByProductCategory($productCategory);


return $query->find(); return $query->find();
} }
public function getByCategoryOnlineAndOffline( public function getByCategoryOnlineAndOffline(
ProductCategoryInterface $productCategory, ProductCategoryInterface $productCategory,
$query = null $query = null
) {
)
{
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterByPropertyNoveltyExpirationDate()
->filterIsOnline();
->filterByPropertyNoveltyExpirationDate()
->filterIsOnline();


$results = $query->find(); $results = $query->find();


$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterIsOrganicLabel()
->filterIsOnline();
->filterIsOrganicLabel()
->filterIsOnline();


$results = $query->find(); $results = $query->find();


{ {
if ($user) { if ($user) {
return $this->getWithReductions( return $this->getWithReductions(
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
); );
} }




// findByTerms // findByTerms
public function getByTerms( public function getByTerms(
$terms,
$maxResults = false,
$organizeByParentCategory = false,
$user = null,
$query = null
) {
$terms,
$maxResults = false,
$organizeByParentCategory = false,
$user = null,
$query = null
)
{
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query->filterIsOnline(); $query->filterIsOnline();
} }


public function getBestReductionCatalog( public function getBestReductionCatalog(
ProductFamilyInterface $productFamily,
ReductionCatalogInterface $reductionCatalog1,
ReductionCatalogInterface $reductionCatalog2
) {
$price1 = $this->priceSolver->applyReductionCatalog(
$productFamily,
$this->priceSolver->getPrice($productFamily),
$this->priceSolver->getPriceWithTax($productFamily),
1,
$reductionCatalog1
ProductFamilyInterface $productFamily,
ReductionCatalogInterface $reductionCatalog1,
ReductionCatalogInterface $reductionCatalog2
)
{
$price1 = $this->priceSolver->getPriceWithTaxByReduction(
$productFamily,
$reductionCatalog1
); );

$price2 = $this->priceSolver->applyReductionCatalog(
$productFamily,
$this->priceSolver->getPrice($productFamily),
$this->priceSolver->getPriceWithTax($productFamily),
1,
$reductionCatalog2
$price2 = $this->priceSolver->getPriceWithTaxByReduction(
$productFamily,
$reductionCatalog2
); );



if ($price1 > $price2) { if ($price1 > $price2) {
return $reductionCatalog2; return $reductionCatalog2;
} else { } else {


// setReductionForProductFamilies // setReductionForProductFamilies
public function getWithReductions( public function getWithReductions(
$productFamilies,
UserInterface $user = null,
$organizeByCategory = false,
$organizeByParentCategory = false,
$onlyOnDiscount = false
) {
$productFamilies,
UserInterface $user = null,
$organizeByCategory = false,
$organizeByParentCategory = false,
$onlyOnDiscount = false
)
{
$conditions = [ $conditions = [
'ids' => [],
'categories' => [],
'productFamiliesIds' => [],
'categories' => [],
'productFamilies' => [],
]; ];


foreach ($productFamilies as $productFamily) { foreach ($productFamilies as $productFamily) {
$conditions['ids'][] = $productFamily->getId();
$conditions['productFamiliesIds'][] = $productFamily->getId();
$conditions['productFamilies'][] = $productFamily;
$conditions['categories'] = array_merge( $conditions['categories'] = array_merge(
$conditions['categories'],
$productFamily->getProductCategories()->toArray()
$conditions['categories'],
$productFamily->getProductCategories()->toArray()
); );
} }


if ($productFamilies) { if ($productFamilies) {
$reductionCatalogs = $this->reductionCatalogStore->getByProductFamiliesConditions( $reductionCatalogs = $this->reductionCatalogStore->getByProductFamiliesConditions(
$conditions,
$user
$conditions,
$user
); );
} }


$conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false; $conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false;


if ($reductionCatalog->getProductFamilies()->contains( if ($reductionCatalog->getProductFamilies()->contains(
$productFamily
) || $reductionCatalog->getProductFamilies()->isEmpty()) {
$productFamily
) || $reductionCatalog->getProductFamilies()->isEmpty()) {
$conditionProductFamilies = true; $conditionProductFamilies = true;
} }


if ($reductionCatalog->getProductFamily() == $productFamily || $reductionCatalog->getProductFamily(
) === null) {
if ($reductionCatalog->getProductFamily() == $productFamily || $reductionCatalog->getProductFamily() === null) {
$conditionProductFamily = true; $conditionProductFamily = true;
} }


foreach ($productFamily->getProductCategories() as $productCategory) { foreach ($productFamily->getProductCategories() as $productCategory) {
if ($reductionCatalog->getProductCategories()->contains( if ($reductionCatalog->getProductCategories()->contains(
$productCategory
) || $reductionCatalog->getProductCategories()->isEmpty()) {
$productCategory
) || $reductionCatalog->getProductCategories()->isEmpty()) {
$conditionProductCategory = true; $conditionProductCategory = true;
} }
} }
if ($conditionProductFamilies && $conditionProductFamily && $conditionProductCategory) { if ($conditionProductFamilies && $conditionProductFamily && $conditionProductCategory) {
if ($productFamily->getReductionCatalog()) { if ($productFamily->getReductionCatalog()) {
$productFamily->setReductionCatalog( $productFamily->setReductionCatalog(
$this->getBestReductionCatalog(
$productFamily,
$reductionCatalog,
$productFamily->getReductionCatalog()
)
$this->getBestReductionCatalog(
$productFamily,
$reductionCatalog,
$productFamily->getReductionCatalog()
)
); );
} else { } else {
$productFamily->setReductionCatalog($reductionCatalog); $productFamily->setReductionCatalog($reductionCatalog);
if ($this->productCategorySolver->isDisplay($parentCategory, $user)) { if ($this->productCategorySolver->isDisplay($parentCategory, $user)) {
if (!isset($productFamiliesToReturn[$parentCategory->getId()])) { if (!isset($productFamiliesToReturn[$parentCategory->getId()])) {
$productFamiliesToReturn[$parentCategory->getId()] = [ $productFamiliesToReturn[$parentCategory->getId()] = [
'category' => $parentCategory,
'products' => []
'category' => $parentCategory,
'products' => []
]; ];
} }
$productFamiliesToReturn[$parentCategory->getId()]['products'][] = $productFamily; $productFamiliesToReturn[$parentCategory->getId()]['products'][] = $productFamily;

+ 35
- 27
Repository/Reduction/ReductionCatalogRepositoryQuery.php View File



namespace Lc\CaracoleBundle\Repository\Reduction; namespace Lc\CaracoleBundle\Repository\Reduction;


use Doctrine\Common\Collections\ArrayCollection;
use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
$this->isJoinUsers = true; $this->isJoinUsers = true;


return $this return $this
->leftJoin('.users', 'pf_users')
->addSelect('pf_users') ;
->leftJoin('.users', 'pf_users')
->addSelect('pf_users');
} }
return $this; return $this;
} }
$this->isJoinGroupUsers = true; $this->isJoinGroupUsers = true;


return $this return $this
->leftJoin('.groupUsers', 'groupUsers')
->addSelect('groupUsers') ;
->leftJoin('.groupUsers', 'groupUsers')
->addSelect('groupUsers');
} }
return $this; return $this;
} }
$this->isJoinProductFamilies = true; $this->isJoinProductFamilies = true;


return $this return $this
->leftJoin('.productFamilies', 'productFamilies')
->addSelect('productFamilies') ;
->leftJoin('.productFamilies', 'productFamilies')
->addSelect('productFamilies');
} }
return $this; return $this;
} }
$this->isJoinProductFamily = true; $this->isJoinProductFamily = true;


return $this return $this
->leftJoin('.productFamily', 'productFamily')
->addSelect('productFamily') ;
->leftJoin('.productFamily', 'productFamily')
->addSelect('productFamily');
} }


return $this; return $this;
$this->isJoinProductCategories = true; $this->isJoinProductCategories = true;


return $this return $this
->leftJoin('.productCategories', 'productCategories')
->addSelect('productCategories') ;
->leftJoin('.productCategories', 'productCategories')
->addSelect('productCategories');
} }


return $this; return $this;
public function filterProductFamily(ProductFamilyInterface $productFamily) public function filterProductFamily(ProductFamilyInterface $productFamily)
{ {
return $this return $this
->andWhere('.productFamily = :productFamily')
->setParameter(':productFamily', $productFamily);
->andWhere('.productFamily = :productFamily')
->setParameter(':productFamily', $productFamily);
} }


public function filterConditionDate() public function filterConditionDate()
{ {
return $this return $this
->andWhere('.permanent = 1 OR ( .dateStart <= :now AND .dateEnd >= :now)')
->setParameter(':now', new \DateTime());
->andWhere('.permanent = 1 OR ( .dateStart <= :now AND .dateEnd >= :now)')
->setParameter(':now', new \DateTime());
} }


public function filterConditionUser(UserInterface $user = null) public function filterConditionUser(UserInterface $user = null)


if ($user) { if ($user) {
return $this return $this
->andWhere(':user MEMBER OF .users OR .users is empty')
->setParameter('user', $user);
->andWhere(':user MEMBER OF .users OR .users is empty')
->setParameter('user', $user);
} else { } else {
return $this return $this
->andWhere('.users is empty');
->andWhere('.users is empty');
} }
} }




if ($user) { if ($user) {
return $this return $this
->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
->setParameter('groupUser', $user->getGroupUsers());
->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
->setParameter('groupUser', $user->getGroupUsers());
} else { } else {
return $this return $this
->andWhere('.groupUsers is empty');
->andWhere('.groupUsers is empty');
} }
} }


public function filterConditionProductFamilies(array $productFamilies)
public function filterConditionProductFamilies(array $productFamiliesIds, array $productFamilies)
{ {
$this->joinProductFamilies(); $this->joinProductFamilies();
$this->joinProductFamily();


return $this return $this
->andWhere(':productFamilies MEMBER OF .productFamilies OR .productFamilies is empty')
->setParameter('productFamilies', $productFamilies);
->andWhere(':productFamiliesIds MEMBER OF .productFamilies OR .productFamilies is empty')
->andWhere('.productFamily IN (:productFamilies) OR .productFamily is null')
->setParameter('productFamiliesIds', $productFamiliesIds)
->setParameter('productFamilies', $productFamilies);
} }


public function filterConditionProductFamily(ProductFamilyInterface $productFamily) public function filterConditionProductFamily(ProductFamilyInterface $productFamily)
$this->joinProductFamily(); $this->joinProductFamily();


return $this return $this
->andWhere(':productFamily MEMBER OF .productFamily OR .productFamily is empty')
->setParameter('productFamily', $productFamily);
->andWhere(':productFamily MEMBER OF .productFamily OR .productFamily is empty')
->setParameter('productFamily', $productFamily);
} }


public function filterConditionProductCategories(array $productCategories) public function filterConditionProductCategories(array $productCategories)
$this->joinProductCategories(); $this->joinProductCategories();


return $this return $this
->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
->setParameter('productCategory', $productCategories);
->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
->setParameter('productCategory', $productCategories);
} }


public function filterIsNotLinkToProductFamily()
{
return $this->andWhere('.productFamily is null');
}


} }

+ 16
- 1
Resources/translations/admin.fr.yaml View File

Merchant: Merchant:
label: Marchand label: Marchand
label_plurial: Marchands label_plurial: Marchands

flashes:
error:
switchMerchant: Une erreur est survenue lors du changement de marchand, veuillez réessayer.
switchFavoriteMerchant: Une erreur est survenue lors de la sauvegarde de votre marchand favoris.
success:
switchFavoriteMerchant: "%merchant% est maintenant votre marchand favoris."
Section: Section:
label: Section label: Section
label_plurial: Sections label_plurial: Sections
error: error:
saveCreditHistory: Une erreur est survenue à l'ajout de crédit/débit saveCreditHistory: Une erreur est survenue à l'ajout de crédit/débit
OrderShop: OrderShop:
modals:
sendPaymentLink: Envoyer le lien de paiement
changeOrderStatus: Modifier le statut de commande
invoiceAddress: Modifier l'adresse de facturation
deliveryAddress: Modifier l'adresse de livraison
addOrderProduct: Ajouter un produit
addReductionCart: Ajouter une réduction panier
addReductionCredit: Ajouter un avoir
orderPayment: Ajouter un paiement
orderStatusHistories: Historique des changements de statuts
fields: fields:
deliveryInfos: | deliveryInfos: |
Merci de nous laisser le maximum d'informations pour faciliter notre arrivée : digicode, Merci de nous laisser le maximum d'informations pour faciliter notre arrivée : digicode,

+ 5
- 3
Resources/views/admin/order/field/order_payment.html.twig View File

{% set value = field.value %} {% set value = field.value %}
{% set item = entity.instance %} {% set item = entity.instance %}
{% for val in value %} {% for val in value %}
<span class="badge badge-success">
{{ val.meanPayment|sov_trans_admin_choice('meanPayment', 'OrderPayment') }}
</span>
{% if val.meanPayment %}
<span class="badge badge-success">
{{ val.meanPayment|sov_trans_admin_choice('meanPayment', 'OrderPayment') }}
</span>
{% endif %}
{% endfor %} {% endfor %}


{% set is_paid = order_shop_container.resolver.isPaid(item) %} {% set is_paid = order_shop_container.resolver.isPaid(item) %}

+ 15
- 17
Resources/views/adminlte/layout.html.twig View File



<nav class="carac navbar navbar-expand navbar-light main-header{% if is_display_switch_section %} display-section-switch {{ section_container.solver.getHtmlClass(section_current()) }}{% endif %}"> <nav class="carac navbar navbar-expand navbar-light main-header{% if is_display_switch_section %} display-section-switch {{ section_container.solver.getHtmlClass(section_current()) }}{% endif %}">


{% if is_display_switch_section %}
<ul class="navbar-nav left">
<li class="nav-item d-none d-sm-inline-block">
{{ _self.form_switch_section(null) }}
</li>
{% for section in carac_sections() %}
<li class="nav-item d-none d-sm-inline-block">
{{ _self.form_switch_section(section) }}
</li>
{% endfor %}
</ul>
{% endif %}
{% if is_display_switch_section %}
{{ _self.form_switch_section() }}
{% endif %}

<ul class="navbar-nav ml-auto right"> <ul class="navbar-nav ml-auto right">
<li class="nav-item nav-switch-merchant"> <li class="nav-item nav-switch-merchant">
<i class="fa fa-store"></i> <i class="fa fa-store"></i>
{% set form_switch_merchant = carac_form_switch_merchant('admin') %}
{% set form_switch_merchant = carac_form_switch_merchant('admin', 'carac_merchant_switch', false) %}
{% form_theme form_switch_merchant '@LcSov/adminlte/crud/form_theme.html.twig' %} {% form_theme form_switch_merchant '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_merchant) }} {{ form_start(form_switch_merchant) }}
{{ form(form_switch_merchant) }} {{ form(form_switch_merchant) }}


{% if(user.favoriteMerchant != merchant_current) %} {% if(user.favoriteMerchant != merchant_current) %}
{# modal affichée uniquement si la sessionStorage.visit_merchant n'est pas défini (js) #} {# modal affichée uniquement si la sessionStorage.visit_merchant n'est pas défini (js) #}
{% include '@LcCaracole/admin/merchant/modal/switch_merchant.html.twig' %}
{% include '@LcCaracole/admin/merchant/modal/switch_merchant.html.twig' %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}


{% macro form_switch_section(section) %}
{% set form_switch_section = carac_form_switch_section(section) %}
{% macro form_switch_section() %}
{% set form_switch_section = carac_form_switch_section() %}
{% form_theme form_switch_section '@LcSov/adminlte/crud/form_theme.html.twig' %} {% form_theme form_switch_section '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_section) }} {{ form_start(form_switch_section) }}
{{ form(form_switch_section) }}
<ul class="navbar-nav left">
{% for field in form_switch_section %}
<li class="nav-item d-none d-sm-inline-block">
{{ form_row(field) }}
</li>
{% endfor %}
</ul>
{{ form_end(form_switch_section) }} {{ form_end(form_switch_section) }}
{% endmacro %} {% endmacro %}

+ 13
- 0
Solver/Price/ProductPriceSolver.php View File

use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface; use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface; use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver; use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver; use Lc\CaracoleBundle\Solver\Product\ProductSolver;


); );
} }


//Bridge pour applyReductionCatalog qui ne peut pas être appeler à cause du call
public function getPriceWithTaxByReduction(ProductPropertyInterface $product, ReductionCatalogInterface $reductionCatalog)
{
return $this->applyReductionCatalog(
$product,
$this->getPrice($product),
$this->getPriceWithTax($product),
1,
$reductionCatalog
);
}

public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product) public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product)
{ {
return ($this->getPriceByRefUnitWithTax($product) * $this->getPriceWithTaxAndReduction($product)) return ($this->getPriceByRefUnitWithTax($product) * $this->getPriceWithTaxAndReduction($product))

+ 6
- 5
Transformer/Order/OrderShopTransformer.php View File

'orderReference' => $order->getReference(), 'orderReference' => $order->getReference(),
'comment' => $orderPayment->getComment(), 'comment' => $orderPayment->getComment(),
'meanPayment' => $orderPayment->getMeanPayment(), 'meanPayment' => $orderPayment->getMeanPayment(),
'meanPaymentText' => $this->translatorAdmin->transChoice(
'OrderPayment',
'meanPayment',
$orderPayment->getMeanPayment()
),
'meanPaymentText' => $orderPayment->getMeanPayment() ?
$this->translatorAdmin->transChoice(
'OrderPayment',
'meanPayment',
$orderPayment->getMeanPayment()
) : '',
'paidAtText' => $orderPayment->getPaidAt()->format('d/m/Y'), 'paidAtText' => $orderPayment->getPaidAt()->format('d/m/Y'),
'paidAt' => $orderPayment->getPaidAt()->format('Y-m-d'), 'paidAt' => $orderPayment->getPaidAt()->format('Y-m-d'),
'amount' => $orderPayment->getAmount(), 'amount' => $orderPayment->getAmount(),

+ 4
- 8
Twig/FormTwigExtension.php View File



namespace Lc\CaracoleBundle\Twig; namespace Lc\CaracoleBundle\Twig;


use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantButtonAdminFormType;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType; use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType; use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
); );
} }


public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_merchant_switch')
public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_merchant_switch', $csrfProtection = true)
{ {
$form = $this->formFactory->create( $form = $this->formFactory->create(
SwitchMerchantFormType::class, SwitchMerchantFormType::class,
[ [
'action' => $this->urlGenerator->generate($actionRoute), 'action' => $this->urlGenerator->generate($actionRoute),
'attr' => ['class' => 'switch-merchant'], 'attr' => ['class' => 'switch-merchant'],
'csrf_protection' => $csrfProtection,
'context' => $context 'context' => $context
] ]
); );
return $form->createView(); return $form->createView();
} }


public function getFormSwitchSection($section)
public function getFormSwitchSection()
{ {
$form = $this->formFactory->create( $form = $this->formFactory->create(
SwitchSectionFormType::class, SwitchSectionFormType::class,
null, null,
[ [
'action' => $this->urlGenerator->generate('admin_section_switch'), 'action' => $this->urlGenerator->generate('admin_section_switch'),
'attr' => ['class' => 'switch-section'],
'section' => $section,
'attr' => ['class' => 'switch-section']
] ]
); );
return $form->createView(); return $form->createView();

Loading…
Cancel
Save