Browse Source

Merge branch 'develop' of https://gitea.laclic.fr/Laclic/LcShopBundle into develop

feature/export_comptable
Fab 4 years ago
parent
commit
2586f36687
6 changed files with 54 additions and 9 deletions
  1. +20
    -4
      ShopBundle/Model/ProductFamily.php
  2. +1
    -0
      ShopBundle/Repository/ProductFamilyRepository.php
  3. +23
    -3
      ShopBundle/Services/Order/OrderUtils.php
  4. +5
    -1
      ShopBundle/Services/Order/OrderUtilsCartTrait.php
  5. +4
    -0
      ShopBundle/Services/Order/OrderUtilsStockTrait.php
  6. +1
    -1
      ShopBundle/Services/ProductFamilyUtils.php

+ 20
- 4
ShopBundle/Model/ProductFamily.php View File

return $this->products; return $this->products;
} }


public function getProductsOnline(): Collection
{
$products = $this->getProducts() ;
$productsOnlineArray = new ArrayCollection() ;

foreach($products as $product) {
if($product->getStatus() == 1) {
$productsOnlineArray[] = $product ;
}
}

return $productsOnlineArray ;
}

public function addProduct(ProductInterface $product): self public function addProduct(ProductInterface $product): self
{ {
if (!$this->products->contains($product)) { if (!$this->products->contains($product)) {
$products = $this->getProducts(); $products = $this->getProducts();


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


return $arrayProductsGroupByTitle; return $arrayProductsGroupByTitle;

+ 1
- 0
ShopBundle/Repository/ProductFamilyRepository.php View File

{ {
$query = $this->findByMerchantQuery() ; $query = $this->findByMerchantQuery() ;
$query->andWhere('e.slug = :slug')->setParameter('slug',$slug) ; $query->andWhere('e.slug = :slug')->setParameter('slug',$slug) ;
$query->andWhere('e.status = 1');
return $query->getQuery()->getOneOrNullResult() ; return $query->getQuery()->getOneOrNullResult() ;
} }



+ 23
- 3
ShopBundle/Services/Order/OrderUtils.php View File



public function createOrderShop($params) public function createOrderShop($params)
{ {

//TODO vérifier que l'utilisateur n'a pas déjà une commande en cours //TODO vérifier que l'utilisateur n'a pas déjà une commande en cours
$orderShop = new OrderShop(); $orderShop = new OrderShop();


$orderShopBelongTo = true; $orderShopBelongTo = true;
$orderShop->setUser($params['user']); $orderShop->setUser($params['user']);
} }
if (isset($params['visitor']) && $params['visitor']) {
if (isset($params['visitor']) && $params['visitor'] && !$orderShop->getUser()) {
$orderShopBelongTo = true; $orderShopBelongTo = true;
$orderShop->setVisitor($params['visitor']); $orderShop->setVisitor($params['visitor']);
} }
if ($orderShop1 && $orderShop2) { if ($orderShop1 && $orderShop2) {


foreach ($orderShop2->getOrderProducts() as $orderProduct) { foreach ($orderShop2->getOrderProducts() as $orderProduct) {
$this->addOrderProduct($orderShop1, $orderProduct);

$orderProductAlreadyInCart = $this->hasOrderProductAlreadyInCart($orderShop1, $orderProduct) ;
if($orderProductAlreadyInCart) {
if($orderProduct->getQuantityOrder() > $orderProductAlreadyInCart->getQuantityOrder()) {
$orderShop1->removeOrderProduct($orderProductAlreadyInCart) ;
$this->addOrderProduct($orderShop1, $orderProduct);
}
}
else {
$this->addOrderProduct($orderShop1, $orderProduct);
}


if($persist) { if($persist) {
$this->em->remove($orderProduct); $this->em->remove($orderProduct);
} }




public function hasOrderProductAlreadyInCart($orderShop, $orderProductTest)
{
foreach($orderShop->getOrderProducts() as $orderProduct) {
if($orderProduct->getProduct() == $orderProductTest->getProduct()) {
return $orderProduct ;
}
}

return false ;
}

public function groupOrderProductsByProductFamily($orderProducts) public function groupOrderProductsByProductFamily($orderProducts)
{ {
$orderProductsByProductFamily = []; $orderProductsByProductFamily = [];

+ 5
- 1
ShopBundle/Services/Order/OrderUtilsCartTrait.php View File

namespace Lc\ShopBundle\Services\Order; namespace Lc\ShopBundle\Services\Order;




use Lc\ShopBundle\Model\OrderStatus;

trait OrderUtilsCartTrait trait OrderUtilsCartTrait
{ {
public function getCartCurrent() public function getCartCurrent()
if ($orderShopUser || $orderShopVisitor) { if ($orderShopUser || $orderShopVisitor) {
// merge // merge
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) {
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())
&& $orderShopUser->getOrderStatus()->getAlias() == OrderStatus::ALIAS_CART) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor); $orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->utils->addFlash('success', "Votre panier visiteur vient d'être fusionné avec votre panier client."); $this->utils->addFlash('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
} else { } else {
// set user // set user
if ($orderShop && $user && !$orderShop->getUser()) { if ($orderShop && $user && !$orderShop->getUser()) {
$orderShop->setUser($user); $orderShop->setUser($user);
$orderShop->setVisitor(null) ;
$this->em->persist($orderShop); $this->em->persist($orderShop);
$this->em->flush(); $this->em->flush();
} }

+ 4
- 0
ShopBundle/Services/Order/OrderUtilsStockTrait.php View File



public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null) public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null)
{ {
if($product->getStatus() != 1) {
return false ;
}

if(!$orderShop) { if(!$orderShop) {
$orderShop = $this->getCartCurrent() ; $orderShop = $this->getCartCurrent() ;
} }

+ 1
- 1
ShopBundle/Services/ProductFamilyUtils.php View File



private function getCheapestOrMostExpensiveProduct($productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts) private function getCheapestOrMostExpensiveProduct($productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts)
{ {
$products = $productFamily->getProducts()->getValues() ;
$products = $productFamily->getProductsOnline()->getValues() ;
if (count($products) > 0) { if (count($products) > 0) {
usort($products, $comparisonFunction); usort($products, $comparisonFunction);
return $products[0]; return $products[0];

Loading…
Cancel
Save