Browse Source

ProductFamily / Product : gestion status

feature/export_comptable
Guillaume 4 years ago
parent
commit
963ae79059
4 changed files with 26 additions and 5 deletions
  1. +20
    -4
      ShopBundle/Model/ProductFamily.php
  2. +1
    -0
      ShopBundle/Repository/ProductFamilyRepository.php
  3. +4
    -0
      ShopBundle/Services/Order/OrderUtilsStockTrait.php
  4. +1
    -1
      ShopBundle/Services/ProductFamilyUtils.php

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

@@ -321,6 +321,20 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
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
{
if (!$this->products->contains($product)) {
@@ -759,11 +773,13 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
$products = $this->getProducts();

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;

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

@@ -40,6 +40,7 @@ class ProductFamilyRepository extends BaseRepository implements DefaultRepositor
{
$query = $this->findByMerchantQuery() ;
$query->andWhere('e.slug = :slug')->setParameter('slug',$slug) ;
$query->andWhere('e.status = 1');
return $query->getQuery()->getOneOrNullResult() ;
}


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

@@ -59,6 +59,10 @@ trait OrderUtilsStockTrait

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

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

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

@@ -40,7 +40,7 @@ class ProductFamilyUtils

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

Loading…
Cancel
Save