Procházet zdrojové kódy

Frontend : intégration page produit

reduction
Guillaume před 4 roky
rodič
revize
45392b1370
5 změnil soubory, kde provedl 74 přidání a 7 odebrání
  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 Zobrazit soubor

@@ -67,6 +67,13 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod
}
}

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

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

+ 40
- 0
ShopBundle/Model/ProductFamily.php Zobrazit soubor

@@ -507,4 +507,44 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
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 Zobrazit soubor

@@ -2,6 +2,7 @@

namespace Lc\ShopBundle\Services;

use Cocur\Slugify\Slugify;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\PageInterface;
use Lc\ShopBundle\Context\TaxRateInterface;
@@ -145,4 +146,10 @@ class Utils
return $text;
}

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

}

+ 7
- 0
ShopBundle/Twig/BridgeTwigExtension.php Zobrazit soubor

@@ -6,6 +6,7 @@ use Lc\ShopBundle\Context\PageInterface;
use Lc\ShopBundle\Form\Frontend\NewsletterType;
use Lc\ShopBundle\Services\Utils;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;

class BridgeTwigExtension extends AbstractExtension
@@ -31,6 +32,7 @@ class BridgeTwigExtension extends AbstractExtension
public function getFilters()
{
return [
new TwigFilter('slugify', [$this, 'slugify']),
];
}

@@ -53,4 +55,9 @@ class BridgeTwigExtension extends AbstractExtension
{
return $this->utils->getElementByDevAlias($devAlias, $class) ;
}

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

+ 13
- 7
ShopBundle/Twig/FrontendTwigExtension.php Zobrazit soubor

@@ -5,6 +5,10 @@ namespace Lc\ShopBundle\Twig;
use App\Repository\HubRepository;
use App\Services\GlobalParam;
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\Repository\ProductCategoryRepository;
use Symfony\Component\Form\FormFactoryInterface;
@@ -20,20 +24,22 @@ class FrontendTwigExtension extends AbstractExtension
protected $security ;
protected $globalParam ;
protected $formFactory ;
protected $productCategoryRepository ;
protected $hubRepository ;
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->security = $security ;
$this->productCategoryRepository = $productCategoryRepository ;
$this->hubRepository = $hubRepository ;
$this->globalParam = $globalParam ;
$this->formFactory = $formFactory ;
$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()
@@ -73,7 +79,7 @@ class FrontendTwigExtension extends AbstractExtension

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

}

Načítá se…
Zrušit
Uložit