Browse Source

Correctifs panier : formulaire ajout + getCartCurrent()

packProduct
Guillaume 3 years ago
parent
commit
9a30effd26
7 changed files with 47 additions and 11 deletions
  1. +18
    -6
      Builder/Order/OrderShopBuilder.php
  2. +1
    -0
      Controller/Order/CartController.php
  3. +6
    -2
      Form/Order/OrderProductsType.php
  4. +4
    -0
      Repository/Order/OrderShopStore.php
  5. +11
    -2
      Solver/Order/OrderProductReductionCatalogSolver.php
  6. +1
    -1
      Solver/Order/OrderShopSolver.php
  7. +6
    -0
      Twig/StoreTwigExtension.php

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

@@ -141,6 +141,8 @@ class OrderShopBuilder
bool $cache = false
): OrderShopInterface {

$cart = null;

// cache
$cacheIdCartCurrent = 'cart_current_'.$section->getId();
if($cache && isset($this->cacheCartCurrentBySection[$cacheIdCartCurrent])) {
@@ -155,20 +157,32 @@ class OrderShopBuilder
if ($cartUser && $cartVisitor && $cartUser->getId() != $cartVisitor->getId()) {
$cart = $this->merge($cartUser, $cartVisitor);
} else {
$cart = $cartUser ?: $cartVisitor;
if($cartUser) {
$cart = $cartUser;
}
elseif($cartVisitor) {

if($user && $cartVisitor && !$cartVisitor->getUser()) {
$cartVisitor->setUser($user);
$this->entityManager->update($cartVisitor);
$this->entityManager->flush();
}

$cart = $cartVisitor;
}
}

if (!$cart) {
$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);

// cache
$this->cacheCartCurrentBySection[$cacheIdCartCurrent] = $cart;

return $cart;

// @TODO : obligé de faire ça sinon le panier ne se met pas à jour quand on ajoute des produits. Pourquoi ?
//$this->entityManager->refresh($cart);
}

public function setOrderStatus(
@@ -249,8 +263,6 @@ class OrderShopBuilder
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery()
&& (string)$this->priceSolver->getPrice($orderProduct)
== (string)$this->priceSolver->getPrice($orderProductAdd)
&& $orderProduct->getOrderProductReductionCatalog()
&& $orderProductAdd->getOrderProductReductionCatalog()
&& $this->orderProductReductionCatalogSolver->compare(
$orderProduct->getOrderProductReductionCatalog(),
$orderProductAdd->getOrderProductReductionCatalog()

+ 1
- 0
Controller/Order/CartController.php View File

@@ -50,6 +50,7 @@ class CartController extends AbstractController
$form->handleRequest($request);

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

$orderShop = $this->getOrderShopContainer()->getBuilder()->createIfNotExist(
$this->getSectionCurrent(),
$this->getUserCurrent(),

+ 6
- 2
Form/Order/OrderProductsType.php View File

@@ -36,6 +36,9 @@ class OrderProductsType extends AbstractType
$idProductFamily = $options['data']['id_product_family'];
$productFamily = $this->productFamilyStore->getOneById($idProductFamily);

// @TODO : obligé sinon ne fonctionne pas. Problème avec le chargement des relations ?
$this->entityManager->refresh($productFamily);

$builder->add('id_product_family', HiddenType::class, [
'data' => $productFamily->getId()
]);
@@ -43,9 +46,9 @@ class OrderProductsType extends AbstractType
if ($productFamily) {
if ($productFamily->getActiveProducts()
&& $productFamily->getBehaviorAddToCart() == 'multiple') {
$cpt = 0;

foreach ($this->productFamilySolver->getProductsGroupByTitle($productFamily) as $key => $product) {
$cpt = 0;
foreach ($this->productFamilySolver->getProductsGroupByTitle($productFamily) as $product) {
$orderProduct = $this->orderProductFactory->create($product[0], 0);
$builder->add('order_product_' . $cpt, OrderProductType::class, [
'data' => $orderProduct
@@ -56,6 +59,7 @@ class OrderProductsType extends AbstractType
$product = null;
if ($productFamily->getActiveProducts()) {
$products = $this->productFamilySolver->getProductsOnline($productFamily);

if ($products && count($products) > 0) {
$product = $products[0];
}

+ 4
- 0
Repository/Order/OrderShopStore.php View File

@@ -286,6 +286,10 @@ class OrderShopStore extends AbstractStore
// findCartCurrent
public function getOneCartCurrent(UserInterface $user = null, VisitorInterface $visitor = null, $query = null): ?OrderShopInterface
{
if(is_null($user) && is_null($visitor)) {
return null;
}

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

if (!is_null($user)) {

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

@@ -24,9 +24,18 @@ class OrderProductReductionCatalogSolver

// compareOrderProductReductionCatalog
public function compare(
OrderProductReductionCatalogInterface $orderProductReductionCatalog,
OrderProductReductionCatalogInterface $orderProductReductionCatalogCompare
OrderProductReductionCatalogInterface $orderProductReductionCatalog = null,
OrderProductReductionCatalogInterface $orderProductReductionCatalogCompare = null
): bool {

if(is_null($orderProductReductionCatalog) && is_null($orderProductReductionCatalogCompare)) {
return true;
}

if(is_null($orderProductReductionCatalog) || is_null($orderProductReductionCatalogCompare)) {
return false;
}

return $orderProductReductionCatalog->getUnit() == $orderProductReductionCatalogCompare->getUnit()
&& (string)$orderProductReductionCatalog->getValue(
) == (string)$orderProductReductionCatalogCompare->getValue()

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

@@ -99,7 +99,7 @@ class OrderShopSolver
|| (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE)
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) {
if ($byWeight) {
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getProduct()->getUnitInherited()->getCoefficient());
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $this->productSolver->getUnitInherited($orderProduct->getProduct())->getCoefficient());
} else {
$quantity += $orderProduct->getQuantityOrder();
}

+ 6
- 0
Twig/StoreTwigExtension.php View File

@@ -90,6 +90,7 @@ class StoreTwigExtension extends AbstractExtension
new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']),
new TwigFunction('section_setting', [$this, 'getSectionSetting']),
new TwigFunction('section_setting_current', [$this, 'getSectionSettingCurrent']),
new TwigFunction('visitor_current', [$this, 'getVisitorCurrent']),
);
}

@@ -185,4 +186,9 @@ class StoreTwigExtension extends AbstractExtension
//TODO mettre à jour une fois les repo fait
return array();
}

public function getVisitorCurrent()
{
return $this->visitorResolver->getCurrent();
}
}

Loading…
Cancel
Save