Browse Source

Intégration app order

packProduct
Fabien Normand 3 years ago
parent
commit
ae3e930e62
24 changed files with 229 additions and 92 deletions
  1. +8
    -4
      Builder/File/DocumentBuilder.php
  2. +18
    -4
      Builder/Order/OrderShopBuilder.php
  3. +9
    -0
      Container/Order/OrderProductContainer.php
  4. +11
    -10
      Controller/Credit/CreditHistoryAdminController.php
  5. +1
    -1
      Form/Order/OrderProductsType.php
  6. +1
    -3
      Model/Order/OrderShopModel.php
  7. +5
    -0
      Repository/File/DocumentRepositoryQuery.php
  8. +19
    -3
      Repository/File/DocumentStore.php
  9. +47
    -0
      Repository/MerchantStoreTrait.php
  10. +0
    -19
      Repository/Order/OrderShopRepositoryQuery.php
  11. +5
    -9
      Repository/Order/OrderShopStore.php
  12. +1
    -0
      Repository/Product/ProductFamilyRepositoryQuery.php
  13. +10
    -1
      Repository/Product/ProductFamilyStore.php
  14. +7
    -0
      Repository/Reduction/ReductionCreditRepositoryQuery.php
  15. +10
    -2
      Repository/Reduction/ReductionCreditStore.php
  16. +21
    -0
      Repository/SectionRepositoryQueryTrait.php
  17. +27
    -0
      Repository/SectionStoreTrait.php
  18. +4
    -3
      Resolver/MerchantResolver.php
  19. +5
    -19
      Resolver/SectionResolver.php
  20. +1
    -2
      Solver/Order/OrderProductReductionCatalogSolver.php
  21. +1
    -1
      Solver/Order/OrderShopSolver.php
  22. +12
    -1
      Solver/Product/ProductFamilySolver.php
  23. +0
    -10
      Solver/Product/ProductSolver.php
  24. +6
    -0
      Twig/StoreTwigExtension.php

+ 8
- 4
Builder/File/DocumentBuilder.php View File

use Lc\CaracoleBundle\Model\File\DocumentModel; 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;


class DocumentBuilder class DocumentBuilder
{ {
protected DocumentReferenceGenerator $documentReferenceGenerator; protected DocumentReferenceGenerator $documentReferenceGenerator;
protected AddressSolver $addressSolver;


public function __construct(DocumentReferenceGenerator $documentReferenceGenerator)
public function __construct(DocumentReferenceGenerator $documentReferenceGenerator, AddressSolver $addressSolver)
{ {
$this->documentReferenceGenerator = $documentReferenceGenerator; $this->documentReferenceGenerator = $documentReferenceGenerator;
$this->addressSolver = $addressSolver;
} }


public function initFromOrderShop(DocumentInterface $document, OrderShopInterface $orderShop) :DocumentInterface public function initFromOrderShop(DocumentInterface $document, OrderShopInterface $orderShop) :DocumentInterface
$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 //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(), DocumentModel::TYPE_INVOICE)) ;
$document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getSection()->getMerchant(), $document->getType())) ;

$document->setMerchantAddress($merchantAddress); $document->setMerchantAddress($merchantAddress);
$document->setBuyerAddress($buyerAddress); $document->setBuyerAddress($buyerAddress);
$document->setMerchantAddressText($merchantAddress->getSummary());
$document->setBuyerAddressText($buyerAddress->getSummary());
$document->setMerchantAddressText($this->addressSolver->getSummary($merchantAddress));
$document->setBuyerAddressText($this->addressSolver->getSummary($buyerAddress));
$document->addOrderShop($orderShop); $document->addOrderShop($orderShop);
$document->setCreatedBy($orderShop->getUser()); $document->setCreatedBy($orderShop->getUser());



+ 18
- 4
Builder/Order/OrderShopBuilder.php View File

use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore; use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Resolver\OpeningResolver; use Lc\CaracoleBundle\Resolver\OpeningResolver;
use Lc\CaracoleBundle\Resolver\OrderShopResolver; use Lc\CaracoleBundle\Resolver\OrderShopResolver;
use Lc\CaracoleBundle\Solver\Order\OrderProductReductionCatalogSolver;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver; use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver; use Lc\CaracoleBundle\Solver\Product\ProductSolver;
protected OpeningResolver $openingResolver; protected OpeningResolver $openingResolver;
protected ProductSolver $productSolver; protected ProductSolver $productSolver;
protected OrderShopResolver $orderShopResolver; protected OrderShopResolver $orderShopResolver;
protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver;


public function __construct( public function __construct(
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
FlashBagInterface $flashBag, FlashBagInterface $flashBag,
OpeningResolver $openingResolver, OpeningResolver $openingResolver,
ProductSolver $productSolver, ProductSolver $productSolver,
OrderShopResolver $orderShopResolver
OrderShopResolver $orderShopResolver,
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver
) { ) {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->orderShopStore = $orderShopStore; $this->orderShopStore = $orderShopStore;
$this->openingResolver = $openingResolver; $this->openingResolver = $openingResolver;
$this->productSolver = $productSolver; $this->productSolver = $productSolver;
$this->orderShopResolver = $orderShopResolver; $this->orderShopResolver = $orderShopResolver;
$this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver;
} }


public function create( public function create(
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery() && $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery()
&& (string)$this->priceSolver->getPrice($orderProduct) && (string)$this->priceSolver->getPrice($orderProduct)
== (string)$this->priceSolver->getPrice($orderProductAdd) == (string)$this->priceSolver->getPrice($orderProductAdd)
&& $orderProduct->getOrderProductReductionCatalog()->compare(
&& $orderProduct->getOrderProductReductionCatalog()
&& $orderProductAdd->getOrderProductReductionCatalog()
&& $this->orderProductReductionCatalogSolver->compare(
$orderProduct->getOrderProductReductionCatalog(),
$orderProductAdd->getOrderProductReductionCatalog() $orderProductAdd->getOrderProductReductionCatalog()
)) { )) {
$orderProduct->setQuantityOrder( $orderProduct->setQuantityOrder(
public function createDocumentInvoice(OrderShopInterface $orderShop): DocumentInterface public function createDocumentInvoice(OrderShopInterface $orderShop): DocumentInterface
{ {
$documentFactory = new DocumentFactory(); $documentFactory = new DocumentFactory();
$document = $documentFactory->create($orderShop->getSection(),DocumentModel::TYPE_INVOICE);

$document = $documentFactory->create($orderShop->getSection(), DocumentModel::TYPE_INVOICE);

$this->documentBuilder->initFromOrderShop($document, $orderShop); $this->documentBuilder->initFromOrderShop($document, $orderShop);
return $document; return $document;
} }


public function getProductsSalesStatistic(SectionInterface $section, $entity, $nbWeek = 2) public function getProductsSalesStatistic(SectionInterface $section, $entity, $nbWeek = 2)
{ {
$productsSalesStatistic = new ProductsSalesStatistic($this->entityManager, $entity, $nbWeek, $this->productSolver);
$productsSalesStatistic = new ProductsSalesStatistic(
$this->entityManager,
$entity,
$nbWeek,
$this->productSolver
);


$productsSalesStatistic->init($section, $this->orderShopSolver, $this->openingResolver); $productsSalesStatistic->init($section, $this->orderShopSolver, $this->openingResolver);
$productsSalesStatistic->populateProperties($this->orderShopStore); $productsSalesStatistic->populateProperties($this->orderShopStore);

+ 9
- 0
Container/Order/OrderProductContainer.php View File

use Lc\CaracoleBundle\Factory\Order\OrderProductFactory; use Lc\CaracoleBundle\Factory\Order\OrderProductFactory;
use Lc\CaracoleBundle\Repository\Order\OrderProductRepositoryQuery; use Lc\CaracoleBundle\Repository\Order\OrderProductRepositoryQuery;
use Lc\CaracoleBundle\Repository\Order\OrderProductStore; use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
use Lc\CaracoleBundle\Solver\Order\OrderProductSolver;


class OrderProductContainer class OrderProductContainer
{ {
protected OrderProductFactory $factory; protected OrderProductFactory $factory;
protected OrderProductSolver $solver;
protected OrderProductBuilder $builder; protected OrderProductBuilder $builder;
protected OrderProductRepositoryQuery $repositoryQuery; protected OrderProductRepositoryQuery $repositoryQuery;
protected OrderProductStore $store; protected OrderProductStore $store;


public function __construct( public function __construct(
OrderProductFactory $factory, OrderProductFactory $factory,
OrderProductSolver $solver,
OrderProductBuilder $builder, OrderProductBuilder $builder,
OrderProductRepositoryQuery $repositoryQuery, OrderProductRepositoryQuery $repositoryQuery,
OrderProductStore $store OrderProductStore $store
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->solver = $solver;
$this->builder = $builder; $this->builder = $builder;
$this->repositoryQuery = $repositoryQuery; $this->repositoryQuery = $repositoryQuery;
$this->store = $store; $this->store = $store;
return $this->factory; return $this->factory;
} }


public function getSolver(): OrderProductSolver
{
return $this->solver;
}

public function getBuilder(): OrderProductBuilder public function getBuilder(): OrderProductBuilder
{ {
return $this->builder; return $this->builder;

+ 11
- 10
Controller/Credit/CreditHistoryAdminController.php View File

use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory; use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel; use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
use Lc\CaracoleBundle\Model\Order\OrderPaymentModel;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\SovBundle\Controller\AbstractAdminController; use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Translation\TranslatorAdmin; use Lc\SovBundle\Translation\TranslatorAdmin;
ChoiceField::new('meanPayment')->setChoices( ChoiceField::new('meanPayment')->setChoices(
array( array(
$translatorAdmin->transField( $translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CASH,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CASH,
'CreditHistory' 'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CASH,
) => OrderPaymentModel::MEAN_PAYMENT_CASH,


$translatorAdmin->transField( $translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CHEQUE,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CHEQUE,
'CreditHistory' 'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CHEQUE,
) => OrderPaymentModel::MEAN_PAYMENT_CHEQUE,


$translatorAdmin->transField( $translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CREDIT,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CREDIT,
'CreditHistory' 'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CREDIT,
) => OrderPaymentModel::MEAN_PAYMENT_CREDIT,


$translatorAdmin->transField( $translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD,
'CreditHistory' 'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,
) => OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD,


$translatorAdmin->transField( $translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_TRANSFER,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_TRANSFER,
'CreditHistory' 'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_TRANSFER,
) => OrderPaymentModel::MEAN_PAYMENT_TRANSFER,
) )
), ),
TextField::new('reference'), TextField::new('reference'),

+ 1
- 1
Form/Order/OrderProductsType.php View File

} else { } else {
$product = null; $product = null;
if ($productFamily->getActiveProducts()) { if ($productFamily->getActiveProducts()) {
$products = $productFamily->getProductsOnline();
$products = $this->productFamilySolver->getProductsOnline($productFamily);
if ($products && count($products) > 0) { if ($products && count($products) > 0) {
$product = $products[0]; $product = $products[0];
} }

+ 1
- 3
Model/Order/OrderShopModel.php View File

const DELIVERY_TYPE_HOME = 'home'; const DELIVERY_TYPE_HOME = 'home';
const DELIVERY_TYPE_POINTSALE = 'point-sale'; const DELIVERY_TYPE_POINTSALE = 'point-sale';




/** /**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="orderShops", fetch="EAGER") * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="orderShops", fetch="EAGER")
*/ */
protected $orderReductionCredits; protected $orderReductionCredits;


/** /**
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\File\DocumentInterface", inversedBy="orderShops")
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\File\DocumentInterface", inversedBy="orderShops", cascade={"persist"})
*/ */
protected $documents; protected $documents;



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

parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }


public function filterByType($type)
{
return $this->andWhereEqual('type', $type);
}

public function filterByBuyerAddress(AddressInterface $buyerAddress) public function filterByBuyerAddress(AddressInterface $buyerAddress)
{ {
return $this return $this

+ 19
- 3
Repository/File/DocumentStore.php View File

namespace Lc\CaracoleBundle\Repository\File; namespace Lc\CaracoleBundle\Repository\File;


use App\Entity\Address\Address; use App\Entity\Address\Address;
use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait; use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;
class DocumentStore extends AbstractStore class DocumentStore extends AbstractStore
{ {
use SectionStoreTrait; use SectionStoreTrait;
use MerchantStoreTrait;


protected DocumentRepositoryQuery $query; protected DocumentRepositoryQuery $query;


public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
$query->filterIsOnlineAndOffline(); $query->filterIsOnlineAndOffline();
$query->filterBySection($this->section);

if(isset($this->section) && $this->section) {
$query->filterBySection($this->section);
}

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchantViaSection($this->merchant);
}

return $query; return $query;
} }


} }




public function getOneLatestByType(string $documentType, $query = null)
public function getOneLatestByType(string $documentType, $query = null): DocumentInterface
{ {
// @TODO : à écrire
$query = $this->createDefaultQuery($query);

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

return $query->findOne();
} }


// findLastInvoice // findLastInvoice

+ 47
- 0
Repository/MerchantStoreTrait.php View File

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


use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Lc\SovBundle\Repository\StoreInterface;


trait MerchantStoreTrait trait MerchantStoreTrait
{ {


return $this; return $this;
} }

public function isMerchantDefined(): bool
{
return isset($this->merchant) && $this->merchant;
}

public function addFilterByMerchantOptionnal(RepositoryQueryInterface $query): StoreInterface
{
if($this->isMerchantDefined()) {
$query->filterByMerchant($this->merchant);
}

return $this;
}

public function addFilterByMerchantRequired(RepositoryQueryInterface $query): StoreInterface
{
$this->addFilterByMerchantOptionnal($query);

if(!$this->isMerchantDefined()) {
throw new \ErrorException('Le Merchant doit être définie dans '.get_class($this));
}

return $this;
}

public function addFilterByMerchantViaSectionOptionnal(RepositoryQueryInterface $query): StoreInterface
{
if($this->isMerchantDefined()) {
$query->filterByMerchantViaSection($this->merchant);
}

return $this;
}

public function addFilterByMerchantViaSectionRequired(RepositoryQueryInterface $query): StoreInterface
{
$this->addFilterByMerchantOptionnal($query);

if(!$this->isMerchantDefined()) {
throw new \ErrorException('Le Merchant doit être définie dans '.get_class($this));
}

return $this;
}
} }

+ 0
- 19
Repository/Order/OrderShopRepositoryQuery.php View File

protected bool $isJoinOrderReductionCarts = false; protected bool $isJoinOrderReductionCarts = false;
protected bool $isJoinOrderStatus = false; protected bool $isJoinOrderStatus = false;
protected bool $isJoinMerchant = false; protected bool $isJoinMerchant = false;
protected bool $isJoinSection = false;
protected bool $isJoinComplementaryOrderShops = false; protected bool $isJoinComplementaryOrderShops = false;
protected bool $isJoinDeliveryPointSale = false; protected bool $isJoinDeliveryPointSale = false;


->select('count(r.id) as total'); ->select('count(r.id) as total');
} }


public function filterByMerchant(MerchantInterface $merchant)
{
$this->joinMerchant();
return $this->andWhere('s.merchant = :merchant')
->setParameter('merchant', $merchant);
}

public function filterByUser(UserInterface $user): self public function filterByUser(UserInterface $user): self
{ {
return $this return $this
return $this; return $this;
} }


public function joinSection(): self
{
if (!$this->isJoinSection) {
$this->isJoinSection = true;

return $this
->leftJoin('.section', 's');
}
return $this;
}

public function joinComplementaryOrderShops(): self public function joinComplementaryOrderShops(): self
{ {
if (!$this->isJoinComplementaryOrderShops) { if (!$this->isJoinComplementaryOrderShops) {

+ 5
- 9
Repository/Order/OrderShopStore.php View File



public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
if(isset($this->section) && $this->section) {
$query->filterBySection($this->section);
}

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchant($this->merchant);
}
$this
->addFilterBySectionOptionnal($query)
->addFilterByMerchantViaSectionOptionnal($query);


return $query; return $query;
} }
} }


if (isset($params['orderStatus'])) { if (isset($params['orderStatus'])) {
$query->filterByStatus($params['orderStatus']);
$query->filterByStatus([$params['orderStatus']]);
} }


if (isset($params['user'])) { if (isset($params['user'])) {
$reductionCreditsArray = []; $reductionCreditsArray = [];
foreach ($reductionCredits as $reductionCredit) { foreach ($reductionCredits as $reductionCredit) {
if (!$this->countValidWithReductionCredit($reductionCredit, $user) if (!$this->countValidWithReductionCredit($reductionCredit, $user)
&& (!$this->merchant || $reductionCredit->getSection()->getMerchant() == $this->merchant)) {
&& ($reductionCredit->getSection()->getMerchant() == $this->merchant)) {
$reductionCreditsArray[] = $reductionCredit; $reductionCreditsArray[] = $reductionCredit;
} }
} }

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

namespace Lc\CaracoleBundle\Repository\Product; namespace Lc\CaracoleBundle\Repository\Product;


use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait; use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery; use Lc\SovBundle\Repository\AbstractRepositoryQuery;

+ 10
- 1
Repository/Product/ProductFamilyStore.php View File

use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait; use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
class ProductFamilyStore extends AbstractStore class ProductFamilyStore extends AbstractStore
{ {
use SectionStoreTrait; use SectionStoreTrait;
use MerchantStoreTrait;


protected ProductFamilyRepositoryQuery $query; protected ProductFamilyRepositoryQuery $query;
protected PriceSolver $priceSolver; protected PriceSolver $priceSolver;


public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
$query->filterBySection($this->section);
if($this->section) {
$query->filterBySection($this->section);
}

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchantViaSection($this->merchant);
}

return $query; return $query;
} }



+ 7
- 0
Repository/Reduction/ReductionCreditRepositoryQuery.php View File

->setParameter('user', $user); ->setParameter('user', $user);
} }


public function filterByOwner(UserInterface $user)
{
return $this
->andWhere('.owner = :user')
->setParameter('user', $user);
}

public function filterByType(string $type = ReductionCreditModel::TYPE_CREDIT) public function filterByType(string $type = ReductionCreditModel::TYPE_CREDIT)
{ {
return $this return $this

+ 10
- 2
Repository/Reduction/ReductionCreditStore.php View File

use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel; use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Repository\SectionStoreTrait; use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
class ReductionCreditStore extends AbstractStore class ReductionCreditStore extends AbstractStore
{ {
use SectionStoreTrait; use SectionStoreTrait;
use MerchantStoreTrait;


protected ReductionCreditRepositoryQuery $query; protected ReductionCreditRepositoryQuery $query;


if($this->section) { if($this->section) {
$query->filterBySection($this->section); $query->filterBySection($this->section);
} }

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchantViaSection($this->merchant);
}

$query->filterIsOnlineAndOffline(); $query->filterIsOnlineAndOffline();

return $query; return $query;
} }


{ {
/// @TODO : à écrire /// @TODO : à écrire
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);
$query->filterByUser($user);
$query->filterByOwner($user);
return $query->find(); return $query->find();
} }


{ {
/// @TODO : à écrire /// @TODO : à écrire
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);
$query->filterByUser($user);
$query->filterByOwner($user);
return $query->find(); return $query->find();
} }



+ 21
- 0
Repository/SectionRepositoryQueryTrait.php View File



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


use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;


trait SectionRepositoryQueryTrait trait SectionRepositoryQueryTrait
{ {
protected bool $isJoinSection = false;

public function filterBySection(SectionInterface $section) public function filterBySection(SectionInterface $section)
{ {
return $this->andWhereSection($this->id, $section); return $this->andWhereSection($this->id, $section);
} }

public function filterByMerchantViaSection(MerchantInterface $merchant)
{
$this->joinSection();
return $this->andWhere('s.merchant = :merchant')
->setParameter('merchant', $merchant);
}

public function joinSection(): self
{
if (!$this->isJoinSection) {
$this->isJoinSection = true;

return $this
->leftJoin('.section', 's');
}
return $this;
}
} }

+ 27
- 0
Repository/SectionStoreTrait.php View File

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


use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Lc\SovBundle\Repository\StoreInterface;


trait SectionStoreTrait trait SectionStoreTrait
{ {
return $this; return $this;
} }


public function isSectionDefined(): bool
{
return isset($this->section) && $this->section;
}

public function addFilterBySectionOptionnal(RepositoryQueryInterface $query): StoreInterface
{
if($this->isSectionDefined()) {
$query->filterBySection($this->section);
}

return $this;
}

public function addFilterBySectionRequired(RepositoryQueryInterface $query): StoreInterface
{
$this->addFilterBySectionOptionnal($query);

if(!$this->isSectionDefined()) {
throw new \ErrorException('La Section doit être définie dans '.get_class($this));
}

return $this;
}

public function getParents() public function getParents()
{ {
$query = $this->query->create(); $query = $this->query->create();

+ 4
- 3
Resolver/MerchantResolver.php View File

use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface; use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository; use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore; use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
); );
} }


public function getUrl($merchant)
public function getUrl(SectionInterface $section)
{ {
if ($this->urlResolver->isServerLocalhost()) { if ($this->urlResolver->isServerLocalhost()) {
return $this->router->generate('frontend_home', [], UrlGeneratorInterface::ABSOLUTE_URL);
return $this->router->generate('frontend_home', ['section' => $section->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
} else { } else {
return $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL);
return $section->getMerchant()->getSettingValue(MerchantSettingDefinition::SETTING_URL);
} }
} }



+ 5
- 19
Resolver/SectionResolver.php View File

return $currentAdminSection; return $currentAdminSection;
} // front } // front
else { else {
$sectionStore = $this->sectionStore->setMerchant($this->merchantResolver->getCurrent());
$sectionCurrent = null; $sectionCurrent = null;
$isCli = php_sapi_name() === 'cli';
$sectionDefault = $sectionStore->getOneDefault();


// local
if ($isCli || $this->urlResolver->isServerLocalhost()) {
$sectionArray = $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOnline();

foreach ($sectionArray as $section) {
if ($section->getDevAlias() == $_ENV['CURRENT_SECTION_LOCAL']) {
$sectionCurrent = $section;
}
}
}
// distant
else {
$sectionCurrent = $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOneDefault();
if(isset($requestAttributesArray['section'])) {
$sectionCurrent = $sectionStore->getOneBySlug($requestAttributesArray['section']);
} }


return $sectionCurrent;
return $sectionCurrent ?: $sectionDefault;
} }
} }



+ 1
- 2
Solver/Order/OrderProductReductionCatalogSolver.php View File

OrderProductReductionCatalogInterface $orderProductReductionCatalog, OrderProductReductionCatalogInterface $orderProductReductionCatalog,
OrderProductReductionCatalogInterface $orderProductReductionCatalogCompare OrderProductReductionCatalogInterface $orderProductReductionCatalogCompare
): bool { ): bool {
return $orderProductReductionCatalogCompare
&& $orderProductReductionCatalog->getUnit() == $orderProductReductionCatalogCompare->getUnit()
return $orderProductReductionCatalog->getUnit() == $orderProductReductionCatalogCompare->getUnit()
&& (string)$orderProductReductionCatalog->getValue( && (string)$orderProductReductionCatalog->getValue(
) == (string)$orderProductReductionCatalogCompare->getValue() ) == (string)$orderProductReductionCatalogCompare->getValue()
&& $orderProductReductionCatalog->getBehaviorTaxRate( && $orderProductReductionCatalog->getBehaviorTaxRate(

+ 1
- 1
Solver/Order/OrderShopSolver.php View File

} }


// getProductQuantityMaxAddCart // getProductQuantityMaxAddCart
public function getProductQuantityMaxAddCart(ProductInterface $product, OrderShopInterface $orderShop)
public function getProductQuantityMaxAddCart(OrderShopInterface $orderShop, ProductInterface $product)
{ {
$productFamily = $product->getProductFamily(); $productFamily = $product->getProductFamily();



+ 12
- 1
Solver/Product/ProductFamilySolver.php View File



foreach ($products as $product) { foreach ($products as $product) {
if ($product->getStatus() == 1) { if ($product->getStatus() == 1) {
$titleProduct = $product->getTitleInherited();
$titleProduct = $this->productSolver->getTitleInherited($product);
if (!isset($arrayProductsGroupByTitle[$titleProduct])) { if (!isset($arrayProductsGroupByTitle[$titleProduct])) {
$arrayProductsGroupByTitle[$titleProduct] = []; $arrayProductsGroupByTitle[$titleProduct] = [];
} }
return $arrayProductsGroupByTitle; return $arrayProductsGroupByTitle;
} }


public function getQuantityTitle(ProductFamilyInterface $productFamily, ProductInterface $product)
{
$title = $this->productSolver->getQuantityLabelInherited($product);

if ($this->hasProductsWithVariousWeight($productFamily)) {
$title .= ', ' . $this->productSolver->getTitleInherited($product);
}

return $title;
}

public function getOriginProduct(ProductFamilyInterface $productFamily): ?ProductInterface public function getOriginProduct(ProductFamilyInterface $productFamily): ?ProductInterface
{ {
$products = $productFamily->getProducts(); $products = $productFamily->getProducts();

+ 0
- 10
Solver/Product/ProductSolver.php View File

return $quantity . $unit->getWordingShort(); return $quantity . $unit->getWordingShort();
} }


// @TODO : si besoin, à remettre en place
/*public function getQuantityTitle(ProductInterface $product, ProductFamilyInterface $productFamily)
{
$title = $product->getQuantityLabelInherited();
if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
$title .= ', ' . $product->getTitleInherited();
}
return $title;
}*/

public function getAvailableQuantityInherited(ProductInterface $product) public function getAvailableQuantityInherited(ProductInterface $product)
{ {
switch ($product->getProductFamily()->getBehaviorCountStock()) { switch ($product->getProductFamily()->getBehaviorCountStock()) {

+ 6
- 0
Twig/StoreTwigExtension.php View File

new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']), new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']),
new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']), new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']),
new TwigFunction('section_current', [$this, 'getSectionCurrent']), new TwigFunction('section_current', [$this, 'getSectionCurrent']),
new TwigFunction('section_slug_current', [$this, 'getSectionSlugCurrent']),
new TwigFunction('merchant_setting', [$this, 'getMerchantSetting']), new TwigFunction('merchant_setting', [$this, 'getMerchantSetting']),
new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']), new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']),
new TwigFunction('section_setting', [$this, 'getSectionSetting']), new TwigFunction('section_setting', [$this, 'getSectionSetting']),
return $this->sectionResolver->getCurrent(); return $this->sectionResolver->getCurrent();
} }


public function getSectionSlugCurrent(): string
{
return $this->sectionResolver->getCurrent()->getSlug();
}

public function getCartCurrent(): OrderShopInterface public function getCartCurrent(): OrderShopInterface
{ {
return $this->orderShopBuilder->createIfNotExist( return $this->orderShopBuilder->createIfNotExist(

Loading…
Cancel
Save