Browse Source

Merge branch 'develop' of https://gitea.laclic.fr/Laclic/LcShopBundle into develop

feature/export_comptable
Fab 4 years ago
parent
commit
052d5caec5
9 changed files with 156 additions and 62 deletions
  1. +8
    -0
      ShopBundle/Context/OrderProductReductionCatalogInterface.php
  2. +19
    -0
      ShopBundle/Model/OrderProduct.php
  3. +32
    -0
      ShopBundle/Model/OrderProductReductionCatalog.php
  4. +2
    -1
      ShopBundle/Model/ReductionCart.php
  5. +1
    -1
      ShopBundle/Model/ReductionCatalog.php
  6. +61
    -0
      ShopBundle/Model/ReductionPropertyTrait.php
  7. +0
    -55
      ShopBundle/Model/ReductionTrait.php
  8. +32
    -2
      ShopBundle/Services/OrderUtils.php
  9. +1
    -3
      ShopBundle/Services/ProductFamilyUtils.php

+ 8
- 0
ShopBundle/Context/OrderProductReductionCatalogInterface.php View File

<?php

namespace Lc\ShopBundle\Context ;

interface OrderProductReductionCatalogInterface
{

}

+ 19
- 0
ShopBundle/Model/OrderProduct.php View File



namespace Lc\ShopBundle\Model; namespace Lc\ShopBundle\Model;


use App\Entity\OrderProductReductionCatalog;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\PriceInterface; use Lc\ShopBundle\Context\PriceInterface;


*/ */
protected $title; protected $title;


/**
* @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\OrderProductReductionCatalogInterface", cascade={"persist", "remove"})
*/
protected $orderProductReductionCatalog;

public function __toString() public function __toString()
{ {
if($this->getTitle()) { if($this->getTitle()) {


return $this; return $this;
} }

public function getOrderProductReductionCatalog(): ?OrderProductReductionCatalog
{
return $this->orderProductReductionCatalog;
}

public function setOrderProductReductionCatalog(?OrderProductReductionCatalog $orderProductReductionCatalog): self
{
$this->orderProductReductionCatalog = $orderProductReductionCatalog;

return $this;
}

} }

+ 32
- 0
ShopBundle/Model/OrderProductReductionCatalog.php View File

<?php

namespace Lc\ShopBundle\Model;

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

/**
* @ORM\MappedSuperclass()
*/
abstract class OrderProductReductionCatalog implements OrderProductReductionCatalogInterface
{
use ReductionTrait ;

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


public function getTitle(): ?string
{
return $this->title;
}

public function setTitle(string $title): self
{
$this->title = $title;

return $this;
}
}

+ 2
- 1
ShopBundle/Model/ReductionCart.php View File

use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\ReductionInterface; use Lc\ShopBundle\Context\ReductionInterface;
use Lc\ShopBundle\Model\AbstractDocumentEntity; use Lc\ShopBundle\Model\AbstractDocumentEntity;
use Lc\ShopBundle\Model\ReductionPropertyTrait;
use Lc\ShopBundle\Model\ReductionTrait; use Lc\ShopBundle\Model\ReductionTrait;


/** /**
abstract class ReductionCart extends AbstractDocumentEntity abstract class ReductionCart extends AbstractDocumentEntity
{ {
use ReductionTrait; use ReductionTrait;
use ReductionPropertyTrait ;


/** /**
* @ORM\Column(type="boolean", nullable=true) * @ORM\Column(type="boolean", nullable=true)

+ 1
- 1
ShopBundle/Model/ReductionCatalog.php View File

*/ */
abstract class ReductionCatalog extends AbstractDocumentEntity implements ReductionCatalogInterface, FilterMerchantInterface abstract class ReductionCatalog extends AbstractDocumentEntity implements ReductionCatalogInterface, FilterMerchantInterface
{ {

use ReductionTrait; use ReductionTrait;
use ReductionPropertyTrait ;


/** /**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies") * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies")

+ 61
- 0
ShopBundle/Model/ReductionPropertyTrait.php View File

<?php

namespace Lc\ShopBundle\Model;

use Doctrine\ORM\Mapping as ORM;

trait ReductionPropertyTrait
{
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $dateStart;

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

/**
* @ORM\Column(type="boolean")
*/
protected $permanent;


public function getDateStart(): ?\DateTimeInterface
{
return $this->dateStart;
}

public function setDateStart(?\DateTimeInterface $dateStart): self
{
$this->dateStart = $dateStart;

return $this;
}

public function getDateEnd(): ?\DateTimeInterface
{
return $this->dateEnd;
}

public function setDateEnd(?\DateTimeInterface $dateEnd): self
{
$this->dateEnd = $dateEnd;

return $this;
}

public function getPermanent(): ?bool
{
return $this->permanent;
}

public function setPermanent(bool $permanent): self
{
$this->permanent = $permanent;

return $this;
}

}

+ 0
- 55
ShopBundle/Model/ReductionTrait.php View File



namespace Lc\ShopBundle\Model; namespace Lc\ShopBundle\Model;


use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\StatusInterface;


trait ReductionTrait trait ReductionTrait
{ {
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $dateStart;

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

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


/**
* @ORM\Column(type="boolean")
*/
protected $permanent;



public function getDateStart(): ?\DateTimeInterface
{
return $this->dateStart;
}

public function setDateStart(?\DateTimeInterface $dateStart): self
{
$this->dateStart = $dateStart;

return $this;
}

public function getDateEnd(): ?\DateTimeInterface
{
return $this->dateEnd;
}

public function setDateEnd(?\DateTimeInterface $dateEnd): self
{
$this->dateEnd = $dateEnd;

return $this;
}


public function getValue(): ?float public function getValue(): ?float
{ {


return $this; return $this;
} }

public function getPermanent(): ?bool
{
return $this->permanent;
}

public function setPermanent(bool $permanent): self
{
$this->permanent = $permanent;

return $this;
}

} }

+ 32
- 2
ShopBundle/Services/OrderUtils.php View File



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


use App\Entity\OrderProductReductionCatalog;
use App\Entity\OrderShop; use App\Entity\OrderShop;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface; use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;


class OrderUtils class OrderUtils
protected $merchantUtils; protected $merchantUtils;
private $orderShopRepo; private $orderShopRepo;
protected $priceUtils ; protected $priceUtils ;
protected $productFamilyUtils ;


public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils, MerchantUtilsInterface $merchantUtils, PriceUtils $priceUtils)
public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils,
MerchantUtilsInterface $merchantUtils, PriceUtils $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils)
{ {
$this->em = $em; $this->em = $em;
$this->security = $security; $this->security = $security;
$this->merchantUtils = $merchantUtils; $this->merchantUtils = $merchantUtils;
$this->orderShopRepo = $this->em->getRepository(OrderShop::class); $this->orderShopRepo = $this->em->getRepository(OrderShop::class);
$this->priceUtils = $priceUtils ; $this->priceUtils = $priceUtils ;
$this->productFamilyUtils = $productFamilyUtils ;
} }


public function getOrderShopCurrent() public function getOrderShopCurrent()
$orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited()); $orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited());
$orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited()); $orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited());


$productFamily = $this->productFamilyUtils->getProductFamilyBySlug($orderProductAdd->getProduct()->getProductFamily()->getSlug()) ;
$reductionCatalog = $productFamily->getReductionCatalog() ;
if($reductionCatalog) {
$orderProductReductionCatalog = new OrderProductReductionCatalog() ;
$orderProductReductionCatalog->setTitle($reductionCatalog->getTitle()) ;
$orderProductReductionCatalog->setValue($reductionCatalog->getValue()) ;
$orderProductReductionCatalog->setUnit($reductionCatalog->getUnit()) ;
$orderProductReductionCatalog->setBehaviorTaxRate($reductionCatalog->getBehaviorTaxRate()) ;

$orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog);
}

foreach($orderShop->getOrderProducts() as $orderProduct) { foreach($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId()) {
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId()
&& $this->priceUtils->getPrice($orderProduct) == $this->priceUtils->getPrice($orderProductAdd)
&& $this->compareOrderProductReductionCatalog($orderProduct->getOrderProductReductionCatalog(), $orderProductAdd->getOrderProductReductionCatalog())) {

$updated = true; $updated = true;
$orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()); $orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder());
$this->em->persist($orderProduct); $this->em->persist($orderProduct);


if (!$updated) { if (!$updated) {
$orderShop->addOrderProduct($orderProductAdd); $orderShop->addOrderProduct($orderProductAdd);

$this->em->persist($orderProductReductionCatalog);
$this->em->persist($orderProductAdd); $this->em->persist($orderProductAdd);
$this->em->persist($orderShop); $this->em->persist($orderShop);
} }
} }
} }


public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
{
return $orderProductReductionCatalog1 && $orderProductReductionCatalog2
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
&& $orderProductReductionCatalog1->getValue() == $orderProductReductionCatalog2->getValue()
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate() ;
}

public function countQuantities($orderShop) public function countQuantities($orderShop)
{ {
return $this->countQuantitiesByOrderProducts($orderShop->getOrderProducts()); return $this->countQuantitiesByOrderProducts($orderShop->getOrderProducts());

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



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


use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;

class ProductFamilyUtils implements ProductFamilyUtilsInterface
class ProductFamilyUtils
{ {
protected $priceUtils ; protected $priceUtils ;



Loading…
Cancel
Save