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\Order\OrderProductSolver; | |||||
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 CreditHistoryBuilder $creditHistoryBuilder; | protected CreditHistoryBuilder $creditHistoryBuilder; | ||||
protected FlashBagTranslator $flashBagTranslator; | protected FlashBagTranslator $flashBagTranslator; | ||||
protected OrderShopFactory $orderShopFactory; | protected OrderShopFactory $orderShopFactory; | ||||
protected OrderProductSolver $orderProductSolver; | |||||
public function __construct( | public function __construct( | ||||
EntityManagerInterface $entityManager, | EntityManagerInterface $entityManager, | ||||
MerchantResolver $merchantResolver, | MerchantResolver $merchantResolver, | ||||
CreditHistoryBuilder $creditHistoryBuilder, | CreditHistoryBuilder $creditHistoryBuilder, | ||||
FlashBagTranslator $flashBagTranslator, | FlashBagTranslator $flashBagTranslator, | ||||
OrderShopFactory $orderShopFactory | |||||
OrderShopFactory $orderShopFactory, | |||||
OrderProductSolver $orderProductSolver | |||||
) { | ) { | ||||
$this->entityManager = $entityManager; | $this->entityManager = $entityManager; | ||||
$this->orderShopStore = $orderShopStore; | $this->orderShopStore = $orderShopStore; | ||||
$this->creditHistoryBuilder = $creditHistoryBuilder; | $this->creditHistoryBuilder = $creditHistoryBuilder; | ||||
$this->flashBagTranslator = $flashBagTranslator; | $this->flashBagTranslator = $flashBagTranslator; | ||||
$this->orderShopFactory = $orderShopFactory; | $this->orderShopFactory = $orderShopFactory; | ||||
$this->orderProductSolver = $orderProductSolver; | |||||
} | } | ||||
public function create( | public function create( | ||||
} | } | ||||
foreach ($orderShop->getOrderProducts() as $orderProduct) { | foreach ($orderShop->getOrderProducts() as $orderProduct) { | ||||
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId() | |||||
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery() | |||||
&& (string)$this->priceSolver->getPrice($orderProduct) | |||||
== (string)$this->priceSolver->getPrice($orderProductAdd) | |||||
&& $this->orderProductReductionCatalogSolver->compare( | |||||
$orderProduct->getOrderProductReductionCatalog(), | |||||
$orderProductAdd->getOrderProductReductionCatalog() | |||||
)) { | |||||
if ($this->orderProductSolver->compare($orderProduct, $orderProductAdd)) { | |||||
$orderProduct->setQuantityOrder( | $orderProduct->setQuantityOrder( | ||||
$orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder() | $orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder() | ||||
); | ); |
use Lc\CaracoleBundle\Controller\AbstractController; | use Lc\CaracoleBundle\Controller\AbstractController; | ||||
use Lc\CaracoleBundle\Form\Order\OrderProductsType; | use Lc\CaracoleBundle\Form\Order\OrderProductsType; | ||||
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | ||||
use Symfony\Component\HttpFoundation\JsonResponse; | use Symfony\Component\HttpFoundation\JsonResponse; | ||||
use Symfony\Component\HttpFoundation\RedirectResponse; | use Symfony\Component\HttpFoundation\RedirectResponse; | ||||
$data = $form->getData(); | $data = $form->getData(); | ||||
foreach ($data as $orderProduct) { | foreach ($data as $orderProduct) { | ||||
if ($orderProduct instanceof OrderProductInterface) { | if ($orderProduct instanceof OrderProductInterface) { | ||||
if ($orderProduct->getQuantityOrder() > 0) { | |||||
$addOrderProduct = $this->getOrderShopContainer()->getBuilder()->addOrderProduct( | |||||
$orderShop, | |||||
$orderProduct | |||||
); | |||||
} | |||||
if (isset($addOrderProduct) && $addOrderProduct && $orderProduct->getQuantityOrder() > 0) { | |||||
$this->orderProducts[] = $orderProduct; | |||||
} | |||||
$this->addOrderProduct($orderShop, $orderProduct); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
return new JsonResponse($return); | return new JsonResponse($return); | ||||
} | } | ||||
public function addOrderProduct(OrderShopInterface $orderShop, OrderProductInterface $orderProduct): void | |||||
{ | |||||
$this->addOrderProductApply($orderShop, $orderProduct); | |||||
} | |||||
public function addOrderProductApply(OrderShopInterface $orderShop, OrderProductInterface $orderProduct): void | |||||
{ | |||||
if ($orderProduct->getQuantityOrder() > 0) { | |||||
$addOrderProduct = $this->getOrderShopContainer()->getBuilder()->addOrderProduct( | |||||
$orderShop, | |||||
$orderProduct | |||||
); | |||||
} | |||||
if (isset($addOrderProduct) && $addOrderProduct && $orderProduct->getQuantityOrder() > 0) { | |||||
$this->orderProducts[] = $orderProduct; | |||||
} | |||||
} | |||||
/** | /** | ||||
* @Route("/order-reduction-cart/delete/{id}", name="delete_reduction_cart") | * @Route("/order-reduction-cart/delete/{id}", name="delete_reduction_cart") | ||||
*/ | */ |
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Solver\Price\PriceSolver; | |||||
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver; | use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver; | ||||
use Lc\CaracoleBundle\Solver\Product\ProductSolver; | use Lc\CaracoleBundle\Solver\Product\ProductSolver; | ||||
{ | { | ||||
protected ProductSolver $productSolver; | protected ProductSolver $productSolver; | ||||
protected ProductFamilySolver $productFamilySolver; | protected ProductFamilySolver $productFamilySolver; | ||||
public function __construct(ProductSolver $productSolver, ProductFamilySolver $productFamilySolver) | |||||
{ | |||||
protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver; | |||||
protected PriceSolver $priceSolver; | |||||
public function __construct( | |||||
ProductSolver $productSolver, | |||||
ProductFamilySolver $productFamilySolver, | |||||
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver, | |||||
PriceSolver $priceSolver | |||||
) { | |||||
$this->productSolver = $productSolver; | $this->productSolver = $productSolver; | ||||
$this->productFamilySolver = $productFamilySolver; | $this->productFamilySolver = $productFamilySolver; | ||||
$this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver; | |||||
$this->priceSolver = $priceSolver; | |||||
} | |||||
public function compare(OrderProductInterface $orderProduct1, OrderProductInterface $orderProduct2) | |||||
{ | |||||
return $orderProduct1->getProduct()->getId() == $orderProduct2->getProduct()->getId() | |||||
&& $orderProduct1->getRedelivery() == $orderProduct2->getRedelivery() | |||||
&& (string)$this->priceSolver->getPrice($orderProduct1) | |||||
== (string)$this->priceSolver->getPrice($orderProduct2) | |||||
&& $this->orderProductReductionCatalogSolver->compare( | |||||
$orderProduct1->getOrderProductReductionCatalog(), | |||||
$orderProduct2->getOrderProductReductionCatalog() | |||||
); | |||||
} | } | ||||
// groupOrderProductsByProductFamily | // groupOrderProductsByProductFamily | ||||
// simple | // simple | ||||
if ($productFamily->getBehaviorAddToCart() == 'simple') { | if ($productFamily->getBehaviorAddToCart() == 'simple') { | ||||
if ($productFamily->getActiveProducts()) { | |||||
$title .= $titleProduct; | |||||
if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) { | |||||
$title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product); | |||||
if($orderProduct->getOrderPackProduct()) { | |||||
$title .= $this->productFamilySolver->getTitleProduct($product); | |||||
} | |||||
else { | |||||
if ($productFamily->getActiveProducts()) { | |||||
$title .= $titleProduct; | |||||
if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) { | |||||
$title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
} | } | ||||
return $isCategoriesOnlineInSection; | return $isCategoriesOnlineInSection; | ||||
} | } | ||||
public function getTitleProduct(ProductInterface $product) | |||||
{ | |||||
$productFamily = $product->getProductFamily(); | |||||
$title = $product->getProductFamily()->getTitle(); | |||||
if ($product->getTitle() && strlen($product->getTitle())) { | |||||
$title .= ' - ' . $product->getTitle(); | |||||
} | |||||
if ($this->hasProductsWithVariousWeight($productFamily)) { | |||||
$title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product); | |||||
} | |||||
return $title; | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public function getTitle(ProductInterface $product) | |||||
{ | |||||
$title = $product->getProductFamily()->getTitle(); | |||||
if ($product->getTitle() && strlen($product->getTitle())) { | |||||
$title .= ' - ' . $product->getTitle(); | |||||
} | |||||
return $title; | |||||
} | |||||
public function getTitleInherited(ProductInterface $product) | public function getTitleInherited(ProductInterface $product) | ||||
{ | { | ||||
if ($product->getTitle()) { | if ($product->getTitle()) { |