|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Builder\Distribution\DistributionBuilder; |
|
|
use App\Builder\Distribution\DistributionBuilder; |
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder; |
|
|
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; |
|
|
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; |
|
|
use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent; |
|
|
use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent; |
|
|
|
|
|
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory; |
|
|
use Lc\CaracoleBundle\Factory\File\DocumentFactory; |
|
|
use Lc\CaracoleBundle\Factory\File\DocumentFactory; |
|
|
use Lc\CaracoleBundle\Factory\Order\OrderPaymentFactory; |
|
|
use Lc\CaracoleBundle\Factory\Order\OrderPaymentFactory; |
|
|
use Lc\CaracoleBundle\Factory\Order\OrderProductFactory; |
|
|
use Lc\CaracoleBundle\Factory\Order\OrderProductFactory; |
|
|
|
|
|
|
|
|
use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; |
|
|
use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; |
|
|
use Lc\CaracoleBundle\Factory\Order\OrderStatusHistoryFactory; |
|
|
use Lc\CaracoleBundle\Factory\Order\OrderStatusHistoryFactory; |
|
|
use Lc\CaracoleBundle\Model\Address\AddressInterface; |
|
|
use Lc\CaracoleBundle\Model\Address\AddressInterface; |
|
|
|
|
|
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel; |
|
|
use Lc\CaracoleBundle\Model\File\DocumentInterface; |
|
|
use Lc\CaracoleBundle\Model\File\DocumentInterface; |
|
|
use Lc\CaracoleBundle\Model\File\DocumentModel; |
|
|
use Lc\CaracoleBundle\Model\File\DocumentModel; |
|
|
|
|
|
use Lc\CaracoleBundle\Model\Order\OrderPaymentModel; |
|
|
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; |
|
|
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; |
|
|
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface; |
|
|
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface; |
|
|
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; |
|
|
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; |
|
|
|
|
|
|
|
|
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; |
|
|
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; |
|
|
use Lc\CaracoleBundle\Repository\Order\OrderStatusStore; |
|
|
use Lc\CaracoleBundle\Repository\Order\OrderStatusStore; |
|
|
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore; |
|
|
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore; |
|
|
|
|
|
use Lc\CaracoleBundle\Resolver\MerchantResolver; |
|
|
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\OrderProductReductionCatalogSolver; |
|
|
|
|
|
|
|
|
use Lc\CaracoleBundle\Solver\Product\ProductSolver; |
|
|
use Lc\CaracoleBundle\Solver\Product\ProductSolver; |
|
|
use Lc\CaracoleBundle\Statistic\Product\ProductsSalesStatistic; |
|
|
use Lc\CaracoleBundle\Statistic\Product\ProductsSalesStatistic; |
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
|
|
|
use Lc\SovBundle\Translation\FlashBagTranslator; |
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; |
|
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected OrderShopResolver $orderShopResolver; |
|
|
protected OrderShopResolver $orderShopResolver; |
|
|
protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver; |
|
|
protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver; |
|
|
protected DistributionBuilder $distributionBuilder; |
|
|
protected DistributionBuilder $distributionBuilder; |
|
|
|
|
|
protected MerchantResolver $merchantResolver; |
|
|
|
|
|
protected CreditHistoryBuilder $creditHistoryBuilder; |
|
|
|
|
|
|
|
|
public function __construct( |
|
|
public function __construct( |
|
|
EntityManagerInterface $entityManager, |
|
|
EntityManagerInterface $entityManager, |
|
|
|
|
|
|
|
|
ProductSolver $productSolver, |
|
|
ProductSolver $productSolver, |
|
|
OrderShopResolver $orderShopResolver, |
|
|
OrderShopResolver $orderShopResolver, |
|
|
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver, |
|
|
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver, |
|
|
DistributionBuilder $distributionBuilder |
|
|
|
|
|
|
|
|
DistributionBuilder $distributionBuilder, |
|
|
|
|
|
MerchantResolver $merchantResolver, |
|
|
|
|
|
CreditHistoryBuilder $creditHistoryBuilder |
|
|
) { |
|
|
) { |
|
|
$this->entityManager = $entityManager; |
|
|
$this->entityManager = $entityManager; |
|
|
$this->orderShopStore = $orderShopStore; |
|
|
$this->orderShopStore = $orderShopStore; |
|
|
|
|
|
|
|
|
$this->orderShopResolver = $orderShopResolver; |
|
|
$this->orderShopResolver = $orderShopResolver; |
|
|
$this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver; |
|
|
$this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver; |
|
|
$this->distributionBuilder = $distributionBuilder; |
|
|
$this->distributionBuilder = $distributionBuilder; |
|
|
|
|
|
$this->merchantResolver = $merchantResolver; |
|
|
|
|
|
$this->creditHistoryBuilder = $creditHistoryBuilder; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function create( |
|
|
public function create( |
|
|
|
|
|
|
|
|
UserInterface $user = null, |
|
|
UserInterface $user = null, |
|
|
VisitorInterface $visitor = null |
|
|
VisitorInterface $visitor = null |
|
|
): OrderShopInterface { |
|
|
): OrderShopInterface { |
|
|
$cart = $this->orderShopStore |
|
|
|
|
|
->setSection($section) |
|
|
|
|
|
->getOneCartCurrent($user, $visitor); |
|
|
|
|
|
|
|
|
$this->orderShopStore->setSection($section); |
|
|
|
|
|
|
|
|
|
|
|
$cartUser = $this->orderShopStore->getOneCartCurrent($user); |
|
|
|
|
|
$cartVisitor = $this->orderShopStore->getOneCartCurrent(null, $visitor); |
|
|
|
|
|
|
|
|
|
|
|
if ($cartUser && $cartVisitor && $cartUser->getId() != $cartVisitor->getId()) { |
|
|
|
|
|
$cart = $this->merge($cartUser, $cartVisitor); |
|
|
|
|
|
} else { |
|
|
|
|
|
$cart = $cartUser ?: $cartVisitor; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (!$cart) { |
|
|
if (!$cart) { |
|
|
$cart = $this->create($section, $user, $visitor); |
|
|
$cart = $this->create($section, $user, $visitor); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @TODO : obligé de faire ça sinon le panier ne se met pas à jour quand on ajoute des produits. Pourquoi ? |
|
|
|
|
|
$this->entityManager->refresh($cart); |
|
|
|
|
|
|
|
|
return $cart; |
|
|
return $cart; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if ($persist) { |
|
|
if ($persist) { |
|
|
$this->entityManager->persist($orderProduct); |
|
|
|
|
|
|
|
|
$this->entityManager->update($orderProduct); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$updated = true; |
|
|
$updated = true; |
|
|
|
|
|
|
|
|
): OrderShopInterface { |
|
|
): OrderShopInterface { |
|
|
if ($orderShop1 && $orderShop2) { |
|
|
if ($orderShop1 && $orderShop2) { |
|
|
foreach ($orderShop2->getOrderProducts() as $orderProduct) { |
|
|
foreach ($orderShop2->getOrderProducts() as $orderProduct) { |
|
|
$orderProductAlreadyInCart = $orderShop1->hasOrderProductAlreadyInCart($orderProduct); |
|
|
|
|
|
|
|
|
$orderProductAlreadyInCart = $this->orderShopSolver->hasOrderProductAlreadyInCart($orderShop1, $orderProduct); |
|
|
|
|
|
|
|
|
if ($orderProductAlreadyInCart) { |
|
|
if ($orderProductAlreadyInCart) { |
|
|
if ($orderProduct->getQuantityOrder() > $orderProductAlreadyInCart->getQuantityOrder()) { |
|
|
if ($orderProduct->getQuantityOrder() > $orderProductAlreadyInCart->getQuantityOrder()) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$orderShop->addOrderPayment($orderPayment); |
|
|
$orderShop->addOrderPayment($orderPayment); |
|
|
|
|
|
|
|
|
|
|
|
if($meanPayment == OrderPaymentModel::MEAN_PAYMENT_CREDIT) { |
|
|
|
|
|
$this->creditHistoryBuilder->create(CreditHistoryModel::TYPE_DEBIT, $this->merchantResolver->getUserMerchant(), [ |
|
|
|
|
|
'orderPayment' => $orderPayment |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if ($this->orderShopResolver->isPaid($orderShop)) { |
|
|
if ($this->orderShopResolver->isPaid($orderShop)) { |
|
|
$nextStatus = OrderStatusModel::ALIAS_PAID; |
|
|
$nextStatus = OrderStatusModel::ALIAS_PAID; |
|
|
} else { |
|
|
} else { |