<?php | |||||
namespace Lc\ShopBundle\Context ; | |||||
interface GlobalParamInterface | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Context; | |||||
interface PageInterface | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Context ; | |||||
interface PriceInterface | |||||
{ | |||||
/** | |||||
* Retourne le prix hérité | |||||
* | |||||
* @return float | |||||
*/ | |||||
public function getPriceInherited(); | |||||
/** | |||||
* Retourne le TaxRate hérité | |||||
* | |||||
* @return entity | |||||
*/ | |||||
public function getTaxRateInherited(); | |||||
/** | |||||
* Retourne le Unit hérité | |||||
* | |||||
* @return float | |||||
*/ | |||||
public function getUnitInherited(); | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Context ; | |||||
interface UnitInterface | |||||
{ | |||||
} |
$em->flush(); | $em->flush(); | ||||
} | } | ||||
} | } | ||||
return $this->redirect('admin/dashboard') ; | |||||
return $this->redirect('/admin/dashboard') ; | |||||
} | } | ||||
} | } |
use Lc\ShopBundle\Context\ProductFamilyInterface; | use Lc\ShopBundle\Context\ProductFamilyInterface; | ||||
use Lc\ShopBundle\Context\ProductInterface; | use Lc\ShopBundle\Context\ProductInterface; | ||||
use Lc\ShopBundle\Context\TaxRateInterface; | use Lc\ShopBundle\Context\TaxRateInterface; | ||||
use Lc\ShopBundle\Context\UnitInterface; | |||||
use Lc\ShopBundle\Form\ProductFamilyCategoriesType; | use Lc\ShopBundle\Form\ProductFamilyCategoriesType; | ||||
use Lc\ShopBundle\Form\ProductType; | use Lc\ShopBundle\Form\ProductType; | ||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
$this->choicesSupplierTaxRateParam[$tax->getId()] = $tax->getValue(); | $this->choicesSupplierTaxRateParam[$tax->getId()] = $tax->getValue(); | ||||
} | } | ||||
//là mon ami je kiffe symfo !!!!! | //là mon ami je kiffe symfo !!!!! | ||||
$this->choicesTaxRateParam[0] = $this->getUser()->getMerchant()->getTaxRate()->getValue(); | $this->choicesTaxRateParam[0] = $this->getUser()->getMerchant()->getTaxRate()->getValue(); | ||||
// choices unit | |||||
$choicesUnits = [] ; | |||||
$unitClass = $this->em->getClassMetadata(UnitInterface::class)->getName() ; | |||||
foreach ($this->em->getRepository($unitClass)->findAll() as $unit) { | |||||
$choicesUnits[$unit->getWording()] = $unit->getId() ; | |||||
} | |||||
$formBuilder->add('taxRate', ChoiceType::class, array( | $formBuilder->add('taxRate', ChoiceType::class, array( | ||||
'label' => 'TVA', | 'label' => 'TVA', | ||||
'choices' => $choicesTaxRate, | 'choices' => $choicesTaxRate, | ||||
}, | }, | ||||
)); | )); | ||||
$formBuilder->add('unit', ChoiceType::class, array( | |||||
'label' => 'Unité', | |||||
//'' | |||||
'choices' => $this->utils->getUnitsListFormatedForType() | |||||
$formBuilder->add('unit', EntityType::class, array( | |||||
'class' => $unitClass, | |||||
/*'label' => 'Unité', | |||||
'choices' => $choicesUnits, | |||||
'data'=> 0,*/ | |||||
)); | )); | ||||
$formBuilder->add('quantity', NumberType::class, array( | $formBuilder->add('quantity', NumberType::class, array( | ||||
'entity' => $entity | 'entity' => $entity | ||||
]); | ]); | ||||
$productCategoryRepository = $this->getDoctrine()->getRepository(ProductCategoryInterface::class); | $productCategoryRepository = $this->getDoctrine()->getRepository(ProductCategoryInterface::class); | ||||
$categories = $productCategoryRepository->findAllParents(); | $categories = $productCategoryRepository->findAllParents(); | ||||
Method('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); | |||||
$parameters = [ | |||||
'form' => $newForm->createView(), | |||||
'entity_fields' => $fields, | |||||
'entity' => $entity, | |||||
'categories' => $categories, | |||||
'sortableProductsField' => array() | |||||
]; | |||||
return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); | |||||
} | } | ||||
} | } |
*/ | */ | ||||
protected $image; | protected $image; | ||||
/** | |||||
* @ORM\Column(type="string", length=255, nullable=true) | |||||
*/ | |||||
protected $devAlias; | |||||
public function getTitle(): ?string | public function getTitle(): ?string | ||||
{ | { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getDevAlias(): ?string | |||||
{ | |||||
return $this->devAlias; | |||||
} | |||||
public function setDevAlias(?string $devAlias): self | |||||
{ | |||||
$this->devAlias = $devAlias; | |||||
return $this; | |||||
} | |||||
} | } |
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Gedmo\Mapping\Annotation as Gedmo; | use Gedmo\Mapping\Annotation as Gedmo; | ||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Context\UserInterface; | use Lc\ShopBundle\Context\UserInterface; | ||||
use Lc\ShopBundle\Services\Utils; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass | * @ORM\MappedSuperclass | ||||
*/ | */ | ||||
protected $updatedBy; | protected $updatedBy; | ||||
public function getCreatedAt(): ?\DateTimeInterface | public function getCreatedAt(): ?\DateTimeInterface | ||||
{ | { | ||||
return $this->createdAt; | return $this->createdAt; |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use Doctrine\Common\Collections\ArrayCollection; | |||||
use Doctrine\Common\Collections\Collection; | |||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
/** | /** |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use App\Entity\ProductCategory; | |||||
use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
*/ | */ | ||||
protected $address; | protected $address; | ||||
/** | |||||
* @ORM\OneToMany(targetEntity="App\Entity\ProductCategory", mappedBy="merchant", orphanRemoval=true) | |||||
*/ | |||||
private $productCategories; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->pointSales = new ArrayCollection(); | $this->pointSales = new ArrayCollection(); | ||||
$this->productFamilies = new ArrayCollection(); | $this->productFamilies = new ArrayCollection(); | ||||
$this->merchantConfigs = new ArrayCollection(); | $this->merchantConfigs = new ArrayCollection(); | ||||
$this->productCategories = new ArrayCollection(); | |||||
} | } | ||||
public function getCreditConfig(): ?CreditConfig | public function getCreditConfig(): ?CreditConfig | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|ProductCategory[] | |||||
*/ | |||||
public function getProductCategories(): Collection | |||||
{ | |||||
return $this->productCategories; | |||||
} | |||||
public function addProductCategory(ProductCategory $productCategory): self | |||||
{ | |||||
if (!$this->productCategories->contains($productCategory)) { | |||||
$this->productCategories[] = $productCategory; | |||||
$productCategory->setMerchant($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removeProductCategory(ProductCategory $productCategory): self | |||||
{ | |||||
if ($this->productCategories->contains($productCategory)) { | |||||
$this->productCategories->removeElement($productCategory); | |||||
// set the owning side to null (unless already changed) | |||||
if ($productCategory->getMerchant() === $this) { | |||||
$productCategory->setMerchant(null); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Lc\ShopBundle\Context\PriceInterface; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class OrderProduct extends AbstractEntity | |||||
abstract class OrderProduct extends AbstractEntity implements PriceInterface | |||||
{ | { | ||||
use PriceTrait ; | |||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", inversedBy="orderProducts", cascade={"persist"}) | * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", inversedBy="orderProducts", cascade={"persist"}) | ||||
* @ORM\JoinColumn(nullable=false) | * @ORM\JoinColumn(nullable=false) | ||||
*/ | */ | ||||
protected $product; | protected $product; | ||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $taxRate; | |||||
/** | |||||
* @ORM\Column(type="float") | |||||
*/ | |||||
protected $price; | |||||
/** | |||||
* @ORM\Column(type="string", length=31) | |||||
*/ | |||||
protected $unit; | |||||
/** | /** | ||||
* @ORM\Column(type="float") | * @ORM\Column(type="float") | ||||
*/ | */ | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getTaxRate(): ?TaxRate | |||||
{ | |||||
return $this->taxRate; | |||||
} | |||||
public function setTaxRate(?TaxRate $taxRate): self | |||||
{ | |||||
$this->taxRate = $taxRate; | |||||
return $this; | |||||
} | |||||
public function getPrice(): ?float | |||||
{ | |||||
return $this->price; | |||||
} | |||||
public function setPrice(float $price): self | |||||
{ | |||||
$this->price = $price; | |||||
return $this; | |||||
} | |||||
public function getUnit(): ?string | |||||
{ | |||||
return $this->unit; | |||||
} | |||||
public function setUnit(string $unit): self | |||||
{ | |||||
$this->unit = $unit; | |||||
return $this; | |||||
} | |||||
public function getQuantity(): ?float | public function getQuantity(): ?float | ||||
{ | { | ||||
return $this->quantity; | return $this->quantity; |
<?php | |||||
namespace Lc\ShopBundle\Model; | |||||
use Doctrine\ORM\Mapping as ORM; | |||||
/** | |||||
* @ORM\MappedSuperclass() | |||||
*/ | |||||
abstract class Page extends AbstractDocumentEntity | |||||
{ | |||||
/** | |||||
* @ORM\Column(type="text", nullable=true) | |||||
*/ | |||||
protected $content; | |||||
public function __toString() | |||||
{ | |||||
return $this->getTitle() ; | |||||
} | |||||
public function getContent(): ?string | |||||
{ | |||||
return $this->content; | |||||
} | |||||
public function setContent(?string $content): self | |||||
{ | |||||
$this->content = $content; | |||||
return $this; | |||||
} | |||||
} |
<?php | <?php | ||||
namespace Lc\ShopBundle\Model; | |||||
namespace Lc\ShopBundle\Model ; | |||||
use Doctrine\Common\Collections\ArrayCollection; | |||||
use Doctrine\ORM\Mapping as ORM; | |||||
use Lc\ShopBundle\Context\StatusInterface; | |||||
use Lc\ShopBundle\Context\UnitInterface; | |||||
class Price | |||||
trait PriceTrait | |||||
{ | { | ||||
/** | |||||
* @ORM\Column(type="float", nullable=true) | |||||
*/ | |||||
protected $price; | |||||
public function withTax() | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UnitInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $unit; | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $taxRate; | |||||
public function getPrice(): ?float | |||||
{ | |||||
return $this->price; | |||||
} | |||||
public function getPriceInherited() | |||||
{ | |||||
return $this->getPrice() ; | |||||
} | |||||
public function getUnitInherited() | |||||
{ | { | ||||
return self::getPriceWithTax( | |||||
$this->price, | |||||
$this->taxRate | |||||
) ; | |||||
return $this->getUnit() ; | |||||
} | } | ||||
public function withoutTax() | |||||
public function getTaxRateInherited(): ?TaxRate | |||||
{ | { | ||||
return $this->price ; | |||||
return $this->getTaxRate() ; | |||||
} | } | ||||
/* Static */ | |||||
public function getPriceWithTax() | |||||
{ | |||||
return $this->calculatePriceWithTax($this->getPriceInherited(), $this->getTaxRateInherited()->getValue()) ; | |||||
} | |||||
public static function priceTwoDecimals($number) | |||||
public function getPriceByUnitRef() | |||||
{ | { | ||||
return number_format(( ($number * 100)) / 100, 2) ; | |||||
return $this->getPriceInherited() * $this->getUnitInherited()->getCoefficient() ; | |||||
} | } | ||||
public static function getPriceWithoutTax($priceWithTax, $taxRate) | |||||
public function getPriceByUnitRefWithTax() | |||||
{ | { | ||||
return floatval($priceWithTax) / ($taxRate + 1); | |||||
return $this->calculatePriceWithTax($this->getPriceByUnitRef(), $this->getTaxRateInherited()->getValue()) ; | |||||
} | |||||
public function setPrice(float $price): self | |||||
{ | |||||
$this->price = $price; | |||||
return $this; | |||||
} | } | ||||
public static function getPriceWithTax($priceWithoutTax, $taxRate) | |||||
public function getUnit(): ?Unit | |||||
{ | { | ||||
return self::priceTwoDecimals(floatval($priceWithoutTax) * ($taxRate + 1)) ; | |||||
return $this->unit; | |||||
} | } | ||||
public function setUnit(Unit $unit): self | |||||
{ | |||||
$this->unit = $unit; | |||||
return $this; | |||||
} | |||||
public function getTaxRate(): ?TaxRate | |||||
{ | |||||
return $this->taxRate; | |||||
} | |||||
public function setTaxRate(?TaxRate $taxRate): self | |||||
{ | |||||
$this->taxRate = $taxRate; | |||||
return $this; | |||||
} | |||||
private function calculatePriceWithTax($priceWithoutTax, $taxRateValue) | |||||
{ | |||||
$price = floatval($priceWithoutTax) * ($taxRateValue + 1) ; | |||||
$price = number_format(( ($price * 100)) / 100, 2) ; | |||||
return $price ; | |||||
} | |||||
} | } |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Lc\ShopBundle\Context\PriceInterface; | |||||
use Lc\ShopBundle\Context\ProductPropertyInterface; | use Lc\ShopBundle\Context\ProductPropertyInterface; | ||||
use Lc\ShopBundle\Context\SortableInterface; | use Lc\ShopBundle\Context\SortableInterface; | ||||
use Lc\ShopBundle\Services\Price; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class Product extends AbstractEntity implements SortableInterface, ProductPropertyInterface | |||||
abstract class Product extends AbstractEntity implements SortableInterface, ProductPropertyInterface, PriceInterface | |||||
{ | { | ||||
use SortableTrait; | use SortableTrait; | ||||
use ProductPropertyTrait; | use ProductPropertyTrait; | ||||
/** | /** | ||||
*/ | */ | ||||
protected $title; | protected $title; | ||||
public function getPriceInherited(){ | |||||
if($this->price){ | |||||
public function getPriceInherited() | |||||
{ | |||||
if($this->price) { | |||||
return $this->price; | return $this->price; | ||||
}else{ | |||||
} | |||||
else { | |||||
return $this->productFamily->getPrice(); | return $this->productFamily->getPrice(); | ||||
} | } | ||||
} | } | ||||
public function getUnitInherited(){ | |||||
if($this->unit){ | |||||
public function getUnitInherited() | |||||
{ | |||||
if($this->unit) { | |||||
return $this->unit; | return $this->unit; | ||||
}else{ | |||||
} | |||||
else{ | |||||
return $this->productFamily->getUnit(); | return $this->productFamily->getUnit(); | ||||
} | } | ||||
} | } | ||||
public function getTitleInherited(){ | |||||
public function getTitleInherited() | |||||
{ | |||||
if($this->title){ | if($this->title){ | ||||
return $this->title; | return $this->title; | ||||
}else{ | |||||
} | |||||
else{ | |||||
return $this->productFamily->getTitle(); | return $this->productFamily->getTitle(); | ||||
} | } | ||||
} | } | ||||
public function getAvailableQuantityInherited(){ | |||||
if($this->productFamily->getBehaviorCountStock()){ | |||||
public function getQuantityInherited() | |||||
{ | |||||
if($this->quantity) { | |||||
return $this->quantity; | |||||
} | |||||
else{ | |||||
return $this->productFamily->getQuantity(); | |||||
} | |||||
} | |||||
public function getAvailableQuantityInherited() | |||||
{ | |||||
if($this->productFamily->getBehaviorCountStock()) { | |||||
return $this->availableQuantity; | return $this->availableQuantity; | ||||
}else{ | |||||
} | |||||
else{ | |||||
return $this->productFamily->getAvailableQuantity(); | return $this->productFamily->getAvailableQuantity(); | ||||
} | } | ||||
} | } | ||||
public function getTaxRateInherited(){ | |||||
if($this->productFamily->getTaxRate()){ | |||||
return $this->productFamily->getTaxRate()->getValue(); | |||||
}else{ | |||||
public function getTaxRateInherited() | |||||
{ | |||||
if($this->productFamily->getTaxRate()) { | |||||
return $this->productFamily->getTaxRate(); | |||||
} | |||||
else{ | |||||
return $this->productFamily->getMerchant()->getTaxRate()->getValue(); | return $this->productFamily->getMerchant()->getTaxRate()->getValue(); | ||||
} | } | ||||
} | } | ||||
public function getProductFamily(): ?ProductFamily | public function getProductFamily(): ?ProductFamily | ||||
{ | { | ||||
return $this->productFamily; | return $this->productFamily; |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use App\Entity\Hub; | |||||
use App\Entity\ProductFamily; | |||||
use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
abstract class ProductCategory extends AbstractDocumentEntity implements TreeInterface | abstract class ProductCategory extends AbstractDocumentEntity implements TreeInterface | ||||
{ | { | ||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productCategories") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $merchant; | |||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="childrens") | * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="childrens") | ||||
*/ | */ | ||||
*/ | */ | ||||
protected $childrens; | protected $childrens; | ||||
public function __toString() | |||||
{ | |||||
// TODO: Implement __toString() method. | |||||
return $this->getTitle(); | |||||
} | |||||
/** | |||||
* @ORM\ManyToMany(targetEntity="App\Entity\ProductFamily", mappedBy="productCategories") | |||||
*/ | |||||
protected $productFamilies; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->childrens = new ArrayCollection(); | $this->childrens = new ArrayCollection(); | ||||
$this->productFamilies = new ArrayCollection(); | |||||
} | } | ||||
public function __toString() | |||||
{ | |||||
// TODO: Implement __toString() method. | |||||
return $this->getTitle(); | |||||
} | |||||
public function getParent(): ?self | public function getParent(): ?self | ||||
{ | { | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|ProductFamily[] | |||||
*/ | |||||
public function getProductFamilies(): Collection | |||||
{ | |||||
return $this->productFamilies; | |||||
} | |||||
public function addProductFamily(ProductFamily $productFamily): self | |||||
{ | |||||
if (!$this->productFamilies->contains($productFamily)) { | |||||
$this->productFamilies[] = $productFamily; | |||||
$productFamily->addProductCategory($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removeProductFamily(ProductFamily $productFamily): self | |||||
{ | |||||
if ($this->productFamilies->contains($productFamily)) { | |||||
$this->productFamilies->removeElement($productFamily); | |||||
$productFamily->removeProductCategory($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function getMerchant(): ?Hub | |||||
{ | |||||
return $this->merchant; | |||||
} | |||||
public function setMerchant(?Hub $merchant): self | |||||
{ | |||||
$this->merchant = $merchant; | |||||
return $this; | |||||
} | |||||
} | } |
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Lc\ShopBundle\Context\FilterMerchantInterface; | use Lc\ShopBundle\Context\FilterMerchantInterface; | ||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Context\PriceInterface; | |||||
use Lc\ShopBundle\Context\ProductInterface; | use Lc\ShopBundle\Context\ProductInterface; | ||||
use Lc\ShopBundle\Context\ProductPropertyInterface; | use Lc\ShopBundle\Context\ProductPropertyInterface; | ||||
use Lc\ShopBundle\Services\Price; | |||||
use Lc\ShopBundle\Services\Utils; | |||||
use League\Flysystem\Util; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, FilterMerchantInterface | |||||
abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, PriceInterface, FilterMerchantInterface | |||||
{ | { | ||||
use ProductPropertyTrait; | use ProductPropertyTrait; | ||||
*/ | */ | ||||
protected $products; | protected $products; | ||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $taxRate; | |||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface") | * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface") | ||||
*/ | */ | ||||
protected $supplierTaxRate; | protected $supplierTaxRate; | ||||
/** | /** | ||||
* @ORM\Column(type="string", length=255, nullable=true) | * @ORM\Column(type="string", length=255, nullable=true) | ||||
*/ | */ | ||||
protected $subTitle; | protected $subTitle; | ||||
/** | /** | ||||
* @ORM\Column(type="text", nullable=true) | * @ORM\Column(type="text", nullable=true) | ||||
*/ | */ | ||||
protected $note; | protected $note; | ||||
/** | /** | ||||
* @ORM\Column(type="string", length=31, nullable=true) | * @ORM\Column(type="string", length=31, nullable=true) | ||||
*/ | */ | ||||
$this->products = new ArrayCollection(); | $this->products = new ArrayCollection(); | ||||
} | } | ||||
public function getTaxRateInherited() | |||||
{ | |||||
if($this->getTaxRate()) { | |||||
return $this->getTaxRate() ; | |||||
} | |||||
else { | |||||
return $this->getMerchant()->getTaxRate() ; | |||||
} | |||||
} | |||||
public function getMerchant(): ?Merchant | public function getMerchant(): ?Merchant | ||||
{ | { | ||||
return $this->merchant; | return $this->merchant; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getTaxRate(): ?TaxRate | |||||
{ | |||||
return $this->taxRate; | |||||
} | |||||
public function setTaxRate(?TaxRate $taxRate): self | |||||
{ | |||||
$this->taxRate = $taxRate; | |||||
return $this; | |||||
} | |||||
public function getSupplierTaxRate(): ?TaxRate | public function getSupplierTaxRate(): ?TaxRate | ||||
{ | { | ||||
return $this->supplierTaxRate; | return $this->supplierTaxRate; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getBehaviorOutOfStock(): ?string | public function getBehaviorOutOfStock(): ?string | ||||
{ | { | ||||
return $this->behaviorOutOfStock; | return $this->behaviorOutOfStock; | ||||
return $this; | return $this; | ||||
} | } | ||||
private function getCheapestOrMostExpensiveProduct($comparisonFunction, $returnSelfIfNotActiveProducts) | |||||
{ | |||||
$products = $this->getProducts()->getValues() ; | |||||
if(count($products) > 0) { | |||||
usort($products, $comparisonFunction) ; | |||||
return $products[0] ; | |||||
} | |||||
if($returnSelfIfNotActiveProducts) { | |||||
return $this ; | |||||
} | |||||
else { | |||||
return false ; | |||||
} | |||||
} | |||||
public function getCheapestProduct() | |||||
{ | |||||
return $this->getCheapestOrMostExpensiveProduct(function($a, $b) { | |||||
return $a->getPriceInherited() > $b->getPriceInherited() ; | |||||
},true) ; | |||||
} | |||||
public function getCheapestProductByUnitRef() | |||||
{ | |||||
return $this->getCheapestOrMostExpensiveProduct(function($a, $b) { | |||||
return $a->getPriceByUnitRef() > $b->getPriceByUnitRef() ; | |||||
},false) ; | |||||
} | |||||
public function getMostExpensiveProductByUnitRef() | |||||
{ | |||||
return $this->getCheapestOrMostExpensiveProduct(function($a, $b) { | |||||
return $a->getPriceByUnitRef() < $b->getPriceByUnitRef() ; | |||||
},false) ; | |||||
} | |||||
} | } |
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Gedmo\Mapping\Annotation as Gedmo; | use Gedmo\Mapping\Annotation as Gedmo; | ||||
use Lc\ShopBundle\Services\Price; | |||||
trait ProductPropertyTrait | trait ProductPropertyTrait | ||||
{ | { | ||||
/** | |||||
* @ORM\Column(type="float", nullable=true) | |||||
*/ | |||||
protected $price; | |||||
use PriceTrait ; | |||||
/** | /** | ||||
* @ORM\Column(type="float", nullable=true) | * @ORM\Column(type="float", nullable=true) | ||||
*/ | */ | ||||
protected $buyingPrice; | protected $buyingPrice; | ||||
/** | |||||
* @ORM\Column(type="string", length=31, nullable=true) | |||||
*/ | |||||
protected $unit; | |||||
/** | /** | ||||
* @ORM\Column(type="float", nullable=true) | * @ORM\Column(type="float", nullable=true) | ||||
*/ | */ | ||||
*/ | */ | ||||
protected $availableQuantity; | protected $availableQuantity; | ||||
/** | /** | ||||
* @ORM\Column(type="float", nullable=true) | * @ORM\Column(type="float", nullable=true) | ||||
*/ | */ | ||||
protected $availableQuantityDefault; | protected $availableQuantityDefault; | ||||
/** | /** | ||||
* @ORM\Column(type="date", nullable=true) | * @ORM\Column(type="date", nullable=true) | ||||
*/ | */ | ||||
protected $expirationDate; | protected $expirationDate; | ||||
public function getUnit(): ?string | |||||
{ | |||||
return $this->unit; | |||||
} | |||||
public function setUnit(?string $unit): self | |||||
{ | |||||
$this->unit = $unit; | |||||
return $this; | |||||
} | |||||
public function getPrice(): ?float | |||||
{ | |||||
return $this->price; | |||||
} | |||||
public function setPrice(?float $price): self | |||||
{ | |||||
$this->price = $price; | |||||
return $this; | |||||
} | |||||
public function getBuyingPrice(): ?float | public function getBuyingPrice(): ?float | ||||
{ | { | ||||
return $this->buyingPrice; | return $this->buyingPrice; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getAvailableQuantity(): ?float | public function getAvailableQuantity(): ?float | ||||
{ | { | ||||
return $this->availableQuantity; | return $this->availableQuantity; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getAvailableQuantityDefault(): ?float | public function getAvailableQuantityDefault(): ?float | ||||
{ | { | ||||
return $this->availableQuantityDefault; | return $this->availableQuantityDefault; | ||||
return $this; | return $this; | ||||
} | } | ||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Model; | |||||
use Doctrine\ORM\Mapping as ORM; | |||||
use Lc\ShopBundle\Model\AbstractEntity; | |||||
/** | |||||
* @ORM\MappedSuperclass | |||||
*/ | |||||
abstract class Unit extends AbstractEntity | |||||
{ | |||||
/** | |||||
* @ORM\Column(type="string", length=32) | |||||
*/ | |||||
protected $unit; | |||||
/** | |||||
* @ORM\Column(type="string", length=32) | |||||
*/ | |||||
protected $wording; | |||||
/** | |||||
* @ORM\Column(type="string", length=32) | |||||
*/ | |||||
protected $wordingUnit; | |||||
/** | |||||
* @ORM\Column(type="string", length=32) | |||||
*/ | |||||
protected $wordingShort; | |||||
/** | |||||
* @ORM\Column(type="integer") | |||||
*/ | |||||
protected $coefficient; | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="App\Entity\Unit") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $unitReference; | |||||
public function __toString() | |||||
{ | |||||
return $this->getWording() ; | |||||
} | |||||
public function getUnit(): ?string | |||||
{ | |||||
return $this->unit; | |||||
} | |||||
public function setUnit(string $unit): self | |||||
{ | |||||
$this->unit = $unit; | |||||
return $this; | |||||
} | |||||
public function getWording(): ?string | |||||
{ | |||||
return $this->wording; | |||||
} | |||||
public function setWording(string $wording): self | |||||
{ | |||||
$this->wording = $wording; | |||||
return $this; | |||||
} | |||||
public function getWordingUnit(): ?string | |||||
{ | |||||
return $this->wordingUnit; | |||||
} | |||||
public function setWordingUnit(string $wordingUnit): self | |||||
{ | |||||
$this->wordingUnit = $wordingUnit; | |||||
return $this; | |||||
} | |||||
public function getWordingShort(): ?string | |||||
{ | |||||
return $this->wordingShort; | |||||
} | |||||
public function setWordingShort(string $wordingShort): self | |||||
{ | |||||
$this->wordingShort = $wordingShort; | |||||
return $this; | |||||
} | |||||
public function getCoefficient(): ?int | |||||
{ | |||||
return $this->coefficient; | |||||
} | |||||
public function setCoefficient(int $coefficient): self | |||||
{ | |||||
$this->coefficient = $coefficient; | |||||
return $this; | |||||
} | |||||
public function getUnitReference(): ?self | |||||
{ | |||||
return $this->unitReference; | |||||
} | |||||
public function setUnitReference(?self $unitReference): self | |||||
{ | |||||
$this->unitReference = $unitReference; | |||||
return $this; | |||||
} | |||||
} |
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; | ||||
use Doctrine\ORM\EntityManager; | use Doctrine\ORM\EntityManager; | ||||
use Doctrine\ORM\EntityRepository; | use Doctrine\ORM\EntityRepository; | ||||
use Symfony\Component\Security\Core\Security; | |||||
class BaseRepository extends EntityRepository implements ServiceEntityRepositoryInterface | class BaseRepository extends EntityRepository implements ServiceEntityRepositoryInterface | ||||
{ | { | ||||
->setParameter('currentMerchant', $merchant->getId()) | ->setParameter('currentMerchant', $merchant->getId()) | ||||
->getQuery() | ->getQuery() | ||||
->getResult(); | ->getResult(); | ||||
} | |||||
public function findByMerchantQuery($merchant) | |||||
{ | |||||
return $this->createQueryBuilder('e') | |||||
->where('e.merchant = :currentMerchant') | |||||
->setParameter('currentMerchant', $merchant->getId()) ; | |||||
} | |||||
public function findOneByDevAlias($devAlias, $merchant) | |||||
{ | |||||
return $this->findByMerchantQuery($merchant) | |||||
->where('e.devAlias = :devAlias') | |||||
->andWhere('e.status = 1') | |||||
->setParameter('devAlias', $devAlias) | |||||
->getQuery() | |||||
->getResult(); | |||||
} | } | ||||
<?php | |||||
namespace Lc\ShopBundle\Repository; | |||||
use App\Entity\Page; | |||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | |||||
use Doctrine\Common\Persistence\ManagerRegistry; | |||||
use Lc\ShopBundle\Repository\BaseRepository; | |||||
/** | |||||
* @method Page|null find($id, $lockMode = null, $lockVersion = null) | |||||
* @method Page|null findOneBy(array $criteria, array $orderBy = null) | |||||
* @method Page[] findAll() | |||||
* @method Page[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | |||||
*/ | |||||
class PageRepository extends BaseRepository | |||||
{ | |||||
public function __construct(ManagerRegistry $registry) | |||||
{ | |||||
parent::__construct($registry, Page::class); | |||||
} | |||||
// /** | |||||
// * @return Page[] Returns an array of Page objects | |||||
// */ | |||||
/* | |||||
public function findByExampleField($value) | |||||
{ | |||||
return $this->createQueryBuilder('p') | |||||
->andWhere('p.exampleField = :val') | |||||
->setParameter('val', $value) | |||||
->orderBy('p.id', 'ASC') | |||||
->setMaxResults(10) | |||||
->getQuery() | |||||
->getResult() | |||||
; | |||||
} | |||||
*/ | |||||
/* | |||||
public function findOneBySomeField($value): ?Page | |||||
{ | |||||
return $this->createQueryBuilder('p') | |||||
->andWhere('p.exampleField = :val') | |||||
->setParameter('val', $value) | |||||
->getQuery() | |||||
->getOneOrNullResult() | |||||
; | |||||
} | |||||
*/ | |||||
} |
use Doctrine\Common\Persistence\ManagerRegistry; | use Doctrine\Common\Persistence\ManagerRegistry; | ||||
use Doctrine\ORM\EntityManager; | use Doctrine\ORM\EntityManager; | ||||
use Doctrine\ORM\QueryBuilder; | use Doctrine\ORM\QueryBuilder; | ||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Context\ProductCategoryInterface; | use Lc\ShopBundle\Context\ProductCategoryInterface; | ||||
/** | /** | ||||
*/ | */ | ||||
class ProductCategoryRepository extends BaseRepository | class ProductCategoryRepository extends BaseRepository | ||||
{ | { | ||||
public function __construct(EntityManager $entityManager) | |||||
{ | |||||
protected $globalParam ; | |||||
public function __construct(EntityManager $entityManager, GlobalParamInterface $globalParam) | |||||
{ | |||||
$this->globalParam = $globalParam ; | |||||
parent::__construct($entityManager, ProductCategoryInterface::class); | parent::__construct($entityManager, ProductCategoryInterface::class); | ||||
} | } | ||||
public static function adminQueryBuilderForTree(BaseRepository $e): QueryBuilder | public static function adminQueryBuilderForTree(BaseRepository $e): QueryBuilder | ||||
{ | { | ||||
return $e->createQueryBuilder('e') | return $e->createQueryBuilder('e') | ||||
->where('e.parent is NULL') | ->where('e.parent is NULL') | ||||
->andWhere('e.status >= 0') | ->andWhere('e.status >= 0') | ||||
public function findAllParents() | public function findAllParents() | ||||
{ | { | ||||
return $this->createQueryBuilder('e') | |||||
->where('e.parent is NULL') | |||||
return $this->findByMerchantQuery($this->globalParam->getCurrentMerchant()) | |||||
->andWhere('e.parent is NULL') | |||||
->andWhere('e.status >= 0') | ->andWhere('e.status >= 0') | ||||
->orderBy('e.position', 'ASC') | ->orderBy('e.position', 'ASC') | ||||
->getQuery() | ->getQuery() | ||||
->getResult(); | ->getResult(); | ||||
} | } | ||||
// /** | |||||
// * @return ProductCategory[] Returns an array of ProductCategory objects | |||||
// */ | |||||
/* | |||||
public function findByExampleField($value) | |||||
public function findAllByParent($parentCategory) | |||||
{ | { | ||||
return $this->createQueryBuilder('p') | |||||
->andWhere('p.exampleField = :val') | |||||
->setParameter('val', $value) | |||||
->orderBy('p.id', 'ASC') | |||||
->setMaxResults(10) | |||||
->getQuery() | |||||
->getResult() | |||||
; | |||||
} | |||||
*/ | |||||
//$query = $this->findByMerchantQuery($this->globalParam->getCurrentMerchant()) ; | |||||
$query = $this->createQueryBuilder('e') ; | |||||
$query->andWhere('e.parent = :idParentCategory') | |||||
->setParameter('idParentCategory', $parentCategory->getId()); | |||||
/* | |||||
public function findOneBySomeField($value): ?ProductCategory | |||||
{ | |||||
return $this->createQueryBuilder('p') | |||||
->andWhere('p.exampleField = :val') | |||||
->setParameter('val', $value) | |||||
->getQuery() | |||||
->getOneOrNullResult() | |||||
; | |||||
return $query->getQuery()->getResult() ; | |||||
} | } | ||||
*/ | |||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Repository; | |||||
use App\Entity\ProductFamily; | |||||
use Doctrine\ORM\EntityManager; | |||||
/** | |||||
* @method ProductFamily|null find($id, $lockMode = null, $lockVersion = null) | |||||
* @method ProductFamily|null findOneBy(array $criteria, array $orderBy = null) | |||||
* @method ProductFamily[] findAll() | |||||
* @method ProductFamily[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | |||||
*/ | |||||
class ProductFamilyRepository extends BaseRepository | |||||
{ | |||||
public function __construct(EntityManager $registry) | |||||
{ | |||||
parent::__construct($registry, ProductFamily::class); | |||||
} | |||||
// /** | |||||
// * @return ProductFamily[] Returns an array of ProductFamily objects | |||||
// */ | |||||
/* | |||||
public function findByExampleField($value) | |||||
{ | |||||
return $this->createQueryBuilder('p') | |||||
->andWhere('p.exampleField = :val') | |||||
->setParameter('val', $value) | |||||
->orderBy('p.id', 'ASC') | |||||
->setMaxResults(10) | |||||
->getQuery() | |||||
->getResult() | |||||
; | |||||
} | |||||
*/ | |||||
/* | |||||
public function findOneBySomeField($value): ?ProductFamily | |||||
{ | |||||
return $this->createQueryBuilder('p') | |||||
->andWhere('p.exampleField = :val') | |||||
->setParameter('val', $value) | |||||
->getQuery() | |||||
->getOneOrNullResult() | |||||
; | |||||
} | |||||
*/ | |||||
} |
services: | services: | ||||
# ... | # ... | ||||
Lc\ShopBundle\Routing\ExtraLoader: | Lc\ShopBundle\Routing\ExtraLoader: | ||||
tags: [routing.loader] | |||||
tags: [routing.loader] | |||||
Lc\ShopBundle\ProductFamily: | |||||
calls: | |||||
- [initServices] |
switch_merchant: | |||||
path: /switch-merchant | |||||
admin_switch_merchant: | |||||
path: /admin/switch-merchant | |||||
controller: Lc\ShopBundle\Controller\Admin\MerchantController::switchMerchantAction | controller: Lc\ShopBundle\Controller\Admin\MerchantController::switchMerchantAction | ||||
lc_api: | lc_api: |
var elements = $( '.lc-ckeditor' ); | var elements = $( '.lc-ckeditor' ); | ||||
for ( var i = 0; i < elements.length; ++i ) { | for ( var i = 0; i < elements.length; ++i ) { | ||||
CKEDITOR.replace( elements[ i ], {"toolbar":[{"name":"styles","items":["Bold","Italic","BulletedList","Link","imageUpload","ckfinder"]}],"language":"fr"} ); | |||||
var editor = CKEDITOR.replace( elements[ i ], {"toolbar":[ | |||||
{name:"styles",items:["Format",'Bold', 'Italic', 'Underline', 'Strike',"Link","BulletedList"]}, | |||||
{name: 'paragraph', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] }, | |||||
{name: 'insert', items: [ 'Image','SpecialChar'] }, | |||||
{name:"document",items:["Source"]}, | |||||
], | |||||
"language":"fr"} ); | |||||
CKFinder.setupCKEditor(editor); | |||||
} | } | ||||
} | } | ||||
{% block wrapper_wrapper %} | {% block wrapper_wrapper %} | ||||
<div class="wrapper"> | <div class="wrapper"> | ||||
{% block wrapper %} | {% block wrapper %} | ||||
<<<<<<< HEAD | |||||
<!-- Navbar --> | <!-- Navbar --> | ||||
<nav class="main-header navbar navbar-expand navbar-white navbar-light"> | <nav class="main-header navbar navbar-expand navbar-white navbar-light"> | ||||
{% block navbar %} | {% block navbar %} | ||||
</li> | </li> | ||||
<li> | <li> | ||||
{% if is_granted('ROLE_ADMIN') %} | {% if is_granted('ROLE_ADMIN') %} | ||||
<form action="{{ path('switch_merchant') }}" method="post"> | |||||
<form action="{{ path('admin_switch_merchant') }}" method="post"> | |||||
<label for="switch-merchant"><i | <label for="switch-merchant"><i | ||||
class="fa fa-store"></i> {{ 'action.switchMerchant'|trans() }} : | class="fa fa-store"></i> {{ 'action.switchMerchant'|trans() }} : | ||||
</label> | </label> |
<?php | |||||
namespace Lc\ShopBundle\Services; | |||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Symfony\Component\Security\Core\Security; | |||||
class GlobalParam | |||||
{ | |||||
private $security; | |||||
public function __construct(Security $security) | |||||
{ | |||||
$this->security = $security ; | |||||
} | |||||
public function getCurrentMerchant() | |||||
{ | |||||
$user = $this->security->getUser() ; | |||||
if($user && $user->getMerchant()) { | |||||
return $user->getMerchant() ; | |||||
} | |||||
else { | |||||
return false ; | |||||
} | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
class Price | |||||
{ | |||||
protected $price ; | |||||
protected $taxRate ; | |||||
public function __construct($price, $taxRate) | |||||
{ | |||||
$this->price = $price ; | |||||
$this->taxRate = $taxRate ; | |||||
} | |||||
public function withTax() | |||||
{ | |||||
return self::getPriceWithTax( | |||||
$this->price, | |||||
$this->taxRate | |||||
) ; | |||||
} | |||||
public function withoutTax() | |||||
{ | |||||
return $this->price ; | |||||
} | |||||
/* Static */ | |||||
public static function priceTwoDecimals($number) | |||||
{ | |||||
return number_format(( ($number * 100)) / 100, 2) ; | |||||
} | |||||
public static function getPriceWithoutTax($priceWithTax, $taxRate) | |||||
{ | |||||
return floatval($priceWithTax) / ($taxRate + 1); | |||||
} | |||||
public static function getPriceWithTax($priceWithoutTax, $taxRate) | |||||
{ | |||||
return self::priceTwoDecimals(floatval($priceWithoutTax) * ($taxRate + 1)) ; | |||||
} | |||||
} |
namespace Lc\ShopBundle\Services; | namespace Lc\ShopBundle\Services; | ||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\ShopBundle\Context\PageInterface; | |||||
class Utils | class Utils | ||||
{ | { | ||||
protected $em ; | |||||
protected $unitsArray = [ | protected $unitsArray = [ | ||||
'piece' => [ | 'piece' => [ | ||||
'unit' => 'piece', | 'unit' => 'piece', | ||||
], | ], | ||||
]; | ]; | ||||
public static function getDayByNumber($number) | |||||
public function __construct(EntityManagerInterface $em) | |||||
{ | { | ||||
$daysArray = [ | |||||
1 => 'Lundu', | |||||
2 => 'Mardi', | |||||
3 => 'Mercredi', | |||||
4 => 'Jeudi', | |||||
5 => 'Vendredi', | |||||
6 => 'Samedi', | |||||
7 => 'Dimanche' | |||||
] ; | |||||
$this->em = $em ; | |||||
} | |||||
public static function getDayByNumber($number, $lang = 'fr') | |||||
{ | |||||
if($lang == 'fr') { | |||||
$daysArray = [ | |||||
1 => 'Lundi', | |||||
2 => 'Mardi', | |||||
3 => 'Mercredi', | |||||
4 => 'Jeudi', | |||||
5 => 'Vendredi', | |||||
6 => 'Samedi', | |||||
7 => 'Dimanche' | |||||
] ; | |||||
} | |||||
else { | |||||
$daysArray = [ | |||||
1 => 'Monday', | |||||
2 => 'Tuesday', | |||||
3 => 'Wednesday', | |||||
4 => 'Thursday', | |||||
5 => 'Friday', | |||||
6 => 'Saturday', | |||||
7 => 'Sunday', | |||||
] ; | |||||
} | |||||
if(isset($daysArray[$number])) { | if(isset($daysArray[$number])) { | ||||
return $daysArray[$number] ; | return $daysArray[$number] ; | ||||
return '' ; | return '' ; | ||||
} | } | ||||
public function getUnitsListFormatedForType(){ | |||||
public function getUnitsListFormatedForType() | |||||
{ | |||||
$choices = [] ; | |||||
foreach ($this->unitsArray as $unit=>$unitInfo){ | foreach ($this->unitsArray as $unit=>$unitInfo){ | ||||
$choices[$unitInfo['wording_unit']] = $unit; | $choices[$unitInfo['wording_unit']] = $unit; | ||||
}; | }; | ||||
return $choices; | return $choices; | ||||
} | } | ||||
public function getUnitsList(){ | |||||
public function getUnitsList() | |||||
{ | |||||
return $this->unitsArray; | return $this->unitsArray; | ||||
} | } | ||||
public function getUnitProperty($unit, $property) | |||||
{ | |||||
$unitsArray = $this->getUnitsList() ; | |||||
if(isset($unitsArray[$unit][$property])) { | |||||
return $unitsArray[$unit][$property] ; | |||||
} | |||||
return false ; | |||||
} | |||||
public function getUnitWording($unit, $type = 'wording_short') | |||||
{ | |||||
return $this->getUnitProperty($unit, $type) ; | |||||
} | |||||
public function getUnitRef($unit) | |||||
{ | |||||
return $this->getUnitProperty($unit, 'ref') ; | |||||
} | |||||
public function getUnitCoefficient($unit) | |||||
{ | |||||
return $this->getUnitProperty($unit, 'coefficient') ; | |||||
} | |||||
public function getElementByDevAlias($devAlias, $class = PageInterface::class) | |||||
{ | |||||
$class = $this->em->getClassMetadata($class)->getName(); | |||||
return $this->em->getRepository($class)->findOneByDevAlias($devAlias) ; | |||||
} | |||||
} | } |
namespace Lc\ShopBundle\Twig; | namespace Lc\ShopBundle\Twig; | ||||
use Lc\ShopBundle\Context\PageInterface; | |||||
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 | ||||
return array( | return array( | ||||
new TwigFunction('getDayByNumber', [$this, 'getDayByNumber']), | new TwigFunction('getDayByNumber', [$this, 'getDayByNumber']), | ||||
new TwigFunction('getUnitsList', [$this, 'getUnitsList']), | new TwigFunction('getUnitsList', [$this, 'getUnitsList']), | ||||
new TwigFunction('getElementByDevAlias', [$this, 'getElementByDevAlias']), | |||||
); | ); | ||||
} | } | ||||
return $this->utils->getUnitsList() ; | return $this->utils->getUnitsList() ; | ||||
} | } | ||||
public function getElementByDevAlias($devAlias, $class = PageInterface::class) | |||||
{ | |||||
return $this->utils->getElementByDevAlias($devAlias, $class) ; | |||||
} | |||||
} | } |