Преглед на файлове

Adminlte template + Merged PriceTrait

reduction
Fab преди 4 години
родител
ревизия
d33536853b
променени са 30 файла, в които са добавени 808 реда и са изтрити 227 реда
  1. +8
    -0
      ShopBundle/Context/GlobalParamInterface.php
  2. +8
    -0
      ShopBundle/Context/PageInterface.php
  3. +27
    -0
      ShopBundle/Context/PriceInterface.php
  4. +8
    -0
      ShopBundle/Context/UnitInterface.php
  5. +1
    -1
      ShopBundle/Controller/Admin/MerchantController.php
  6. +22
    -8
      ShopBundle/Controller/Admin/ProductFamilyController.php
  7. +16
    -0
      ShopBundle/Model/AbstractDocumentEntity.php
  8. +2
    -1
      ShopBundle/Model/AbstractEntity.php
  9. +0
    -2
      ShopBundle/Model/Address.php
  10. +38
    -0
      ShopBundle/Model/Merchant.php
  11. +4
    -53
      ShopBundle/Model/OrderProduct.php
  12. +33
    -0
      ShopBundle/Model/Page.php
  13. +75
    -19
      ShopBundle/Model/PriceTrait.php
  14. +38
    -20
      ShopBundle/Model/Product.php
  15. +58
    -6
      ShopBundle/Model/ProductCategory.php
  16. +52
    -25
      ShopBundle/Model/ProductFamily.php
  17. +2
    -42
      ShopBundle/Model/ProductPropertyTrait.php
  18. +120
    -0
      ShopBundle/Model/Unit.php
  19. +17
    -0
      ShopBundle/Repository/BaseRepository.php
  20. +51
    -0
      ShopBundle/Repository/PageRepository.php
  21. +13
    -32
      ShopBundle/Repository/ProductCategoryRepository.php
  22. +50
    -0
      ShopBundle/Repository/ProductFamilyRepository.php
  23. +5
    -1
      ShopBundle/Resources/config/services.yaml
  24. +2
    -2
      ShopBundle/Resources/config/shop_routes.yaml
  25. +8
    -1
      ShopBundle/Resources/public/js/backend/script/utils.js
  26. +2
    -1
      ShopBundle/Resources/views/backend/default/layout.html.twig
  27. +29
    -0
      ShopBundle/Services/GlobalParam.php
  28. +45
    -0
      ShopBundle/Services/Price.php
  29. +68
    -12
      ShopBundle/Services/Utils.php
  30. +6
    -1
      ShopBundle/Twig/BridgeTwigExtension.php

+ 8
- 0
ShopBundle/Context/GlobalParamInterface.php Целия файл

@@ -0,0 +1,8 @@
<?php

namespace Lc\ShopBundle\Context ;

interface GlobalParamInterface
{

}

+ 8
- 0
ShopBundle/Context/PageInterface.php Целия файл

@@ -0,0 +1,8 @@
<?php

namespace Lc\ShopBundle\Context;

interface PageInterface
{

}

+ 27
- 0
ShopBundle/Context/PriceInterface.php Целия файл

@@ -0,0 +1,27 @@
<?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();
}

+ 8
- 0
ShopBundle/Context/UnitInterface.php Целия файл

@@ -0,0 +1,8 @@
<?php

namespace Lc\ShopBundle\Context ;

interface UnitInterface
{

}

+ 1
- 1
ShopBundle/Controller/Admin/MerchantController.php Целия файл

@@ -101,7 +101,7 @@ class MerchantController extends AdminController
$em->flush();
}
}
return $this->redirect('admin/dashboard') ;
return $this->redirect('/admin/dashboard') ;
}

}

+ 22
- 8
ShopBundle/Controller/Admin/ProductFamilyController.php Целия файл

@@ -10,6 +10,7 @@ use Lc\ShopBundle\Context\ProductCategoryInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Context\UnitInterface;
use Lc\ShopBundle\Form\ProductFamilyCategoriesType;
use Lc\ShopBundle\Form\ProductType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@@ -48,11 +49,16 @@ class ProductFamilyController extends AdminController
$this->choicesSupplierTaxRateParam[$tax->getId()] = $tax->getValue();
}



//là mon ami je kiffe symfo !!!!!
$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(
'label' => 'TVA',
'choices' => $choicesTaxRate,
@@ -80,10 +86,11 @@ class ProductFamilyController extends AdminController
},
));

$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(
@@ -335,11 +342,18 @@ class ProductFamilyController extends AdminController
'entity' => $entity
]);


$productCategoryRepository = $this->getDoctrine()->getRepository(ProductCategoryInterface::class);
$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]);
}

}

+ 16
- 0
ShopBundle/Model/AbstractDocumentEntity.php Целия файл

@@ -38,6 +38,11 @@ abstract class AbstractDocumentEntity extends AbstractEntity implements StatusIn
*/
protected $image;

/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $devAlias;


public function getTitle(): ?string
{
@@ -87,5 +92,16 @@ abstract class AbstractDocumentEntity extends AbstractEntity implements StatusIn
return $this;
}

public function getDevAlias(): ?string
{
return $this->devAlias;
}

public function setDevAlias(?string $devAlias): self
{
$this->devAlias = $devAlias;

return $this;
}

}

+ 2
- 1
ShopBundle/Model/AbstractEntity.php Целия файл

@@ -4,7 +4,9 @@ namespace Lc\ShopBundle\Model;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Lc\ShopBundle\Context\GlobalParamInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Services\Utils;

/**
* @ORM\MappedSuperclass
@@ -36,7 +38,6 @@ abstract class AbstractEntity
*/
protected $updatedBy;


public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;

+ 0
- 2
ShopBundle/Model/Address.php Целия файл

@@ -2,8 +2,6 @@

namespace Lc\ShopBundle\Model;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**

+ 38
- 0
ShopBundle/Model/Merchant.php Целия файл

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

namespace Lc\ShopBundle\Model;

use App\Entity\ProductCategory;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -44,11 +45,17 @@ abstract class Merchant extends AbstractDocumentEntity
*/
protected $address;

/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductCategory", mappedBy="merchant", orphanRemoval=true)
*/
private $productCategories;

public function __construct()
{
$this->pointSales = new ArrayCollection();
$this->productFamilies = new ArrayCollection();
$this->merchantConfigs = new ArrayCollection();
$this->productCategories = new ArrayCollection();
}

public function getCreditConfig(): ?CreditConfig
@@ -189,4 +196,35 @@ abstract class Merchant extends AbstractDocumentEntity

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;
}
}

+ 4
- 53
ShopBundle/Model/OrderProduct.php Целия файл

@@ -3,12 +3,15 @@
namespace Lc\ShopBundle\Model;

use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\PriceInterface;

/**
* @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\JoinColumn(nullable=false)
@@ -20,22 +23,6 @@ abstract class OrderProduct extends AbstractEntity
*/
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")
*/
@@ -80,42 +67,6 @@ abstract class OrderProduct extends AbstractEntity
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
{
return $this->quantity;

+ 33
- 0
ShopBundle/Model/Page.php Целия файл

@@ -0,0 +1,33 @@
<?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;
}
}

+ 75
- 19
ShopBundle/Model/PriceTrait.php Целия файл

@@ -1,42 +1,98 @@
<?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 ;
}
}

+ 38
- 20
ShopBundle/Model/Product.php Целия файл

@@ -3,16 +3,17 @@
namespace Lc\ShopBundle\Model;

use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\PriceInterface;
use Lc\ShopBundle\Context\ProductPropertyInterface;
use Lc\ShopBundle\Context\SortableInterface;
use Lc\ShopBundle\Services\Price;

/**
* @ORM\MappedSuperclass()
*/
abstract class Product extends AbstractEntity implements SortableInterface, ProductPropertyInterface
abstract class Product extends AbstractEntity implements SortableInterface, ProductPropertyInterface, PriceInterface
{
use SortableTrait;

use ProductPropertyTrait;

/**
@@ -26,49 +27,66 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod
*/
protected $title;

public function getPriceInherited(){
if($this->price){
public function getPriceInherited()
{
if($this->price) {
return $this->price;
}else{
}
else {
return $this->productFamily->getPrice();
}
}

public function getUnitInherited(){
if($this->unit){
public function getUnitInherited()
{
if($this->unit) {
return $this->unit;
}else{
}
else{
return $this->productFamily->getUnit();
}
}

public function getTitleInherited(){
public function getTitleInherited()
{
if($this->title){
return $this->title;
}else{
}
else{
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;
}else{
}
else{
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();
}
}



public function getProductFamily(): ?ProductFamily
{
return $this->productFamily;

+ 58
- 6
ShopBundle/Model/ProductCategory.php Целия файл

@@ -2,6 +2,8 @@

namespace Lc\ShopBundle\Model;

use App\Entity\Hub;
use App\Entity\ProductFamily;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -13,6 +15,12 @@ use Lc\ShopBundle\Context\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")
*/
@@ -23,18 +31,22 @@ abstract class ProductCategory extends AbstractDocumentEntity implements TreeInt
*/
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()
{
$this->childrens = new ArrayCollection();
$this->productFamilies = new ArrayCollection();
}


public function __toString()
{
// TODO: Implement __toString() method.
return $this->getTitle();
}

public function getParent(): ?self
{
@@ -78,4 +90,44 @@ abstract class ProductCategory extends AbstractDocumentEntity implements TreeInt

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;
}
}

+ 52
- 25
ShopBundle/Model/ProductFamily.php Целия файл

@@ -6,13 +6,19 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\FilterMerchantInterface;
use Lc\ShopBundle\Context\GlobalParamInterface;
use Lc\ShopBundle\Context\PriceInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ProductPropertyInterface;
use Lc\ShopBundle\Services\Price;
use Lc\ShopBundle\Services\Utils;
use League\Flysystem\Util;

/**
* @ORM\MappedSuperclass()
*/
abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, FilterMerchantInterface

abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, PriceInterface, FilterMerchantInterface
{
use ProductPropertyTrait;

@@ -42,30 +48,21 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
*/
protected $products;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface")
* @ORM\JoinColumn(nullable=true)
*/
protected $taxRate;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface")
*/
protected $supplierTaxRate;


/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $subTitle;


/**
* @ORM\Column(type="text", nullable=true)
*/
protected $note;


/**
* @ORM\Column(type="string", length=31, nullable=true)
*/
@@ -103,6 +100,16 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
$this->products = new ArrayCollection();
}

public function getTaxRateInherited()
{
if($this->getTaxRate()) {
return $this->getTaxRate() ;
}
else {
return $this->getMerchant()->getTaxRate() ;
}
}

public function getMerchant(): ?Merchant
{
return $this->merchant;
@@ -201,19 +208,6 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
return $this;
}

public function getTaxRate(): ?TaxRate
{
return $this->taxRate;
}

public function setTaxRate(?TaxRate $taxRate): self
{
$this->taxRate = $taxRate;

return $this;
}


public function getSupplierTaxRate(): ?TaxRate
{
return $this->supplierTaxRate;
@@ -251,8 +245,6 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
return $this;
}



public function getBehaviorOutOfStock(): ?string
{
return $this->behaviorOutOfStock;
@@ -328,5 +320,40 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
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) ;
}

}

+ 2
- 42
ShopBundle/Model/ProductPropertyTrait.php Целия файл

@@ -4,27 +4,17 @@ namespace Lc\ShopBundle\Model;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Lc\ShopBundle\Services\Price;

trait ProductPropertyTrait
{



/**
* @ORM\Column(type="float", nullable=true)
*/
protected $price;
use PriceTrait ;

/**
* @ORM\Column(type="float", nullable=true)
*/
protected $buyingPrice;

/**
* @ORM\Column(type="string", length=31, nullable=true)
*/
protected $unit;

/**
* @ORM\Column(type="float", nullable=true)
*/
@@ -35,42 +25,16 @@ trait ProductPropertyTrait
*/
protected $availableQuantity;


/**
* @ORM\Column(type="float", nullable=true)
*/
protected $availableQuantityDefault;


/**
* @ORM\Column(type="date", nullable=true)
*/
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
{
return $this->buyingPrice;
@@ -95,7 +59,6 @@ trait ProductPropertyTrait
return $this;
}


public function getAvailableQuantity(): ?float
{
return $this->availableQuantity;
@@ -108,7 +71,6 @@ trait ProductPropertyTrait
return $this;
}


public function getAvailableQuantityDefault(): ?float
{
return $this->availableQuantityDefault;
@@ -132,6 +94,4 @@ trait ProductPropertyTrait

return $this;
}


}

+ 120
- 0
ShopBundle/Model/Unit.php Целия файл

@@ -0,0 +1,120 @@
<?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;
}
}

+ 17
- 0
ShopBundle/Repository/BaseRepository.php Целия файл

@@ -5,6 +5,7 @@ namespace Lc\ShopBundle\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Security\Core\Security;

class BaseRepository extends EntityRepository implements ServiceEntityRepositoryInterface
{
@@ -33,7 +34,23 @@ class BaseRepository extends EntityRepository implements ServiceEntityRepository
->setParameter('currentMerchant', $merchant->getId())
->getQuery()
->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();
}



+ 51
- 0
ShopBundle/Repository/PageRepository.php Целия файл

@@ -0,0 +1,51 @@
<?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()
;
}
*/
}

+ 13
- 32
ShopBundle/Repository/ProductCategoryRepository.php Целия файл

@@ -5,6 +5,7 @@ namespace Lc\ShopBundle\Repository;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Lc\ShopBundle\Context\GlobalParamInterface;
use Lc\ShopBundle\Context\ProductCategoryInterface;

/**
@@ -15,16 +16,16 @@ use Lc\ShopBundle\Context\ProductCategoryInterface;
*/
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);
}


public static function adminQueryBuilderForTree(BaseRepository $e): QueryBuilder
{

return $e->createQueryBuilder('e')
->where('e.parent is NULL')
->andWhere('e.status >= 0')
@@ -33,41 +34,21 @@ class ProductCategoryRepository extends BaseRepository

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')
->orderBy('e.position', 'ASC')
->getQuery()
->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() ;
}
*/
}

+ 50
- 0
ShopBundle/Repository/ProductFamilyRepository.php Целия файл

@@ -0,0 +1,50 @@
<?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()
;
}
*/
}

+ 5
- 1
ShopBundle/Resources/config/services.yaml Целия файл

@@ -1,4 +1,8 @@
services:
# ...
Lc\ShopBundle\Routing\ExtraLoader:
tags: [routing.loader]
tags: [routing.loader]

Lc\ShopBundle\ProductFamily:
calls:
- [initServices]

+ 2
- 2
ShopBundle/Resources/config/shop_routes.yaml Целия файл

@@ -1,6 +1,6 @@

switch_merchant:
path: /switch-merchant
admin_switch_merchant:
path: /admin/switch-merchant
controller: Lc\ShopBundle\Controller\Admin\MerchantController::switchMerchantAction

lc_api:

+ 8
- 1
ShopBundle/Resources/public/js/backend/script/utils.js Целия файл

@@ -45,7 +45,14 @@ function initLcCkEditor(){
var elements = $( '.lc-ckeditor' );

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);
}
}


+ 2
- 1
ShopBundle/Resources/views/backend/default/layout.html.twig Целия файл

@@ -63,6 +63,7 @@
{% block wrapper_wrapper %}
<div class="wrapper">
{% block wrapper %}
<<<<<<< HEAD
<!-- Navbar -->
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
{% block navbar %}
@@ -97,7 +98,7 @@
</li>
<li>
{% 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
class="fa fa-store"></i> {{ 'action.switchMerchant'|trans() }} :
</label>

+ 29
- 0
ShopBundle/Services/GlobalParam.php Целия файл

@@ -0,0 +1,29 @@
<?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 ;
}
}

}

+ 45
- 0
ShopBundle/Services/Price.php Целия файл

@@ -0,0 +1,45 @@
<?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)) ;
}
}

+ 68
- 12
ShopBundle/Services/Utils.php Целия файл

@@ -2,8 +2,13 @@

namespace Lc\ShopBundle\Services;

use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\PageInterface;

class Utils
{
protected $em ;

protected $unitsArray = [
'piece' => [
'unit' => 'piece',
@@ -55,17 +60,35 @@ class Utils
],
];

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])) {
return $daysArray[$number] ;
@@ -74,17 +97,50 @@ class Utils
return '' ;
}

public function getUnitsListFormatedForType(){
public function getUnitsListFormatedForType()
{
$choices = [] ;
foreach ($this->unitsArray as $unit=>$unitInfo){
$choices[$unitInfo['wording_unit']] = $unit;
};
return $choices;
}
public function getUnitsList(){

public function getUnitsList()
{
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) ;
}

}

+ 6
- 1
ShopBundle/Twig/BridgeTwigExtension.php Целия файл

@@ -2,9 +2,9 @@

namespace Lc\ShopBundle\Twig;

use Lc\ShopBundle\Context\PageInterface;
use Lc\ShopBundle\Services\Utils;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;

class BridgeTwigExtension extends AbstractExtension
@@ -21,6 +21,7 @@ class BridgeTwigExtension extends AbstractExtension
return array(
new TwigFunction('getDayByNumber', [$this, 'getDayByNumber']),
new TwigFunction('getUnitsList', [$this, 'getUnitsList']),
new TwigFunction('getElementByDevAlias', [$this, 'getElementByDevAlias']),
);
}

@@ -40,4 +41,8 @@ class BridgeTwigExtension extends AbstractExtension
return $this->utils->getUnitsList() ;
}

public function getElementByDevAlias($devAlias, $class = PageInterface::class)
{
return $this->utils->getElementByDevAlias($devAlias, $class) ;
}
}

Loading…
Отказ
Запис