浏览代码

Refactoring ajout panier + adaptations title product

packProduct
Guillaume 2 年前
父节点
当前提交
4f25ba82a7
共有 5 个文件被更改,包括 77 次插入36 次删除
  1. +7
    -9
      Builder/Order/OrderShopBuilder.php
  2. +20
    -9
      Controller/Order/CartController.php
  3. +34
    -7
      Solver/Order/OrderProductSolver.php
  4. +16
    -0
      Solver/Product/ProductFamilySolver.php
  5. +0
    -11
      Solver/Product/ProductSolver.php

+ 7
- 9
Builder/Order/OrderShopBuilder.php 查看文件

@@ -41,6 +41,7 @@ use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\OpeningResolver;
use Lc\CaracoleBundle\Resolver\OrderShopResolver;
use Lc\CaracoleBundle\Solver\Order\OrderProductReductionCatalogSolver;
use Lc\CaracoleBundle\Solver\Order\OrderProductSolver;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;
@@ -72,6 +73,7 @@ class OrderShopBuilder
protected CreditHistoryBuilder $creditHistoryBuilder;
protected FlashBagTranslator $flashBagTranslator;
protected OrderShopFactory $orderShopFactory;
protected OrderProductSolver $orderProductSolver;

public function __construct(
EntityManagerInterface $entityManager,
@@ -93,7 +95,8 @@ class OrderShopBuilder
MerchantResolver $merchantResolver,
CreditHistoryBuilder $creditHistoryBuilder,
FlashBagTranslator $flashBagTranslator,
OrderShopFactory $orderShopFactory
OrderShopFactory $orderShopFactory,
OrderProductSolver $orderProductSolver
) {
$this->entityManager = $entityManager;
$this->orderShopStore = $orderShopStore;
@@ -115,6 +118,7 @@ class OrderShopBuilder
$this->creditHistoryBuilder = $creditHistoryBuilder;
$this->flashBagTranslator = $flashBagTranslator;
$this->orderShopFactory = $orderShopFactory;
$this->orderProductSolver = $orderProductSolver;
}

public function create(
@@ -259,14 +263,8 @@ class OrderShopBuilder
}

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->getQuantityOrder() + $orderProductAdd->getQuantityOrder()
);

+ 20
- 9
Controller/Order/CartController.php 查看文件

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Controller\Order;
use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Form\Order\OrderProductsType;
use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -63,15 +64,7 @@ class CartController extends AbstractController
$data = $form->getData();
foreach ($data as $orderProduct) {
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);
}
}
}
@@ -81,6 +74,24 @@ class CartController extends AbstractController
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")
*/

+ 34
- 7
Solver/Order/OrderProductSolver.php 查看文件

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Solver\Order;

use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;

@@ -11,11 +12,31 @@ class OrderProductSolver
{
protected ProductSolver $productSolver;
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->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
@@ -113,10 +134,16 @@ class OrderProductSolver

// 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);
}
}
}
}

+ 16
- 0
Solver/Product/ProductFamilySolver.php 查看文件

@@ -491,5 +491,21 @@ class ProductFamilySolver
}
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;
}
}


+ 0
- 11
Solver/Product/ProductSolver.php 查看文件

@@ -117,17 +117,6 @@ class ProductSolver
}
}

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)
{
if ($product->getTitle()) {

正在加载...
取消
保存