Browse Source

Frontend : intégration page produit

reduction
Guillaume 4 years ago
parent
commit
45392b1370
5 changed files with 74 additions and 7 deletions
  1. +7
    -0
      ShopBundle/Model/Product.php
  2. +40
    -0
      ShopBundle/Model/ProductFamily.php
  3. +7
    -0
      ShopBundle/Services/Utils.php
  4. +7
    -0
      ShopBundle/Twig/BridgeTwigExtension.php
  5. +13
    -7
      ShopBundle/Twig/FrontendTwigExtension.php

+ 7
- 0
ShopBundle/Model/Product.php View File

} }
} }


public function getQuantityLabelInherited()
{
$quantity = $this->getQuantityInherited() ;
$unit = $this->getUnitInherited() ;
return $quantity.$unit->getWordingShort() ;
}

public function getAvailableQuantityInherited() public function getAvailableQuantityInherited()
{ {
if($this->productFamily->getBehaviorCountStock()) { if($this->productFamily->getBehaviorCountStock()) {

+ 40
- 0
ShopBundle/Model/ProductFamily.php View File

return $this; return $this;
} }


public function hasProductsWithVariousWeight()
{
if($this->getActiveProducts()) {
$arrayCountProducts = [] ;
$products = $this->getProducts() ;

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

if(!in_array($product->getQuantityLabelInherited(), $arrayCountProducts[$titleProduct])) {
$arrayCountProducts[$titleProduct][] = $product->getQuantityLabelInherited() ;
}

if(count($arrayCountProducts[$titleProduct]) > 1) {
return true ;
}
}
}

return false ;
}

public function getProductsGroupByTitle()
{
$arrayProductsGroupByTitle = [] ;
$products = $this->getProducts() ;

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

return $arrayProductsGroupByTitle ;
}
} }

+ 7
- 0
ShopBundle/Services/Utils.php View File



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


use Cocur\Slugify\Slugify;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\PageInterface; use Lc\ShopBundle\Context\PageInterface;
use Lc\ShopBundle\Context\TaxRateInterface; use Lc\ShopBundle\Context\TaxRateInterface;
return $text; return $text;
} }


public function slugify($string)
{
$slugify = new Slugify();
return $slugify->slugify($string) ;
}

} }

+ 7
- 0
ShopBundle/Twig/BridgeTwigExtension.php View File

use Lc\ShopBundle\Form\Frontend\NewsletterType; use Lc\ShopBundle\Form\Frontend\NewsletterType;
use Lc\ShopBundle\Services\Utils; use Lc\ShopBundle\Services\Utils;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction; use Twig\TwigFunction;


class BridgeTwigExtension extends AbstractExtension class BridgeTwigExtension extends AbstractExtension
public function getFilters() public function getFilters()
{ {
return [ return [
new TwigFilter('slugify', [$this, 'slugify']),
]; ];
} }


{ {
return $this->utils->getElementByDevAlias($devAlias, $class) ; return $this->utils->getElementByDevAlias($devAlias, $class) ;
} }

public function slugify($string)
{
return $this->utils->slugify($string) ;
}
} }

+ 13
- 7
ShopBundle/Twig/FrontendTwigExtension.php View File

use App\Repository\HubRepository; use App\Repository\HubRepository;
use App\Services\GlobalParam; use App\Services\GlobalParam;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\GlobalParamInterface;
use Lc\ShopBundle\Context\MerchantInterface;
use Lc\ShopBundle\Context\ProductCategoryInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Form\Frontend\NewsletterType; use Lc\ShopBundle\Form\Frontend\NewsletterType;
use Lc\ShopBundle\Repository\ProductCategoryRepository; use Lc\ShopBundle\Repository\ProductCategoryRepository;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;
protected $security ; protected $security ;
protected $globalParam ; protected $globalParam ;
protected $formFactory ; protected $formFactory ;
protected $productCategoryRepository ;
protected $hubRepository ;
protected $requestStack ; protected $requestStack ;
protected $productCategoryRepository ;
protected $merchantRepository ;
protected $productFamilyRepository ;


public function __construct(EntityManagerInterface $em, Security $security, ProductCategoryRepository $productCategoryRepository,
GlobalParam $globalParam, FormFactoryInterface $formFactory, HubRepository $hubRepository, RequestStack $requestStack)
public function __construct(EntityManagerInterface $em, Security $security, GlobalParamInterface $globalParam,
FormFactoryInterface $formFactory, RequestStack $requestStack)
{ {
$this->em = $em ; $this->em = $em ;
$this->security = $security ; $this->security = $security ;
$this->productCategoryRepository = $productCategoryRepository ;
$this->hubRepository = $hubRepository ;
$this->globalParam = $globalParam ; $this->globalParam = $globalParam ;
$this->formFactory = $formFactory ; $this->formFactory = $formFactory ;
$this->requestStack = $requestStack ; $this->requestStack = $requestStack ;
$this->productCategoryRepository = $this->em->getRepository($this->em->getClassMetadata(ProductCategoryInterface::class)->getName()) ;
$this->merchantRepository = $this->em->getRepository($this->em->getClassMetadata(MerchantInterface::class)->getName()) ;
$this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetadata(ProductFamilyInterface::class)->getName()) ;
} }


public function getFunctions() public function getFunctions()


public function getMerchants() public function getMerchants()
{ {
return $this->hubRepository->findAll() ;
return $this->merchantRepository->findAll() ;
} }


} }

Loading…
Cancel
Save