Преглед изворни кода

Mise en place OrderProductReductionCatalog

feature/export_comptable
Guillaume пре 4 година
родитељ
комит
8fe868d08b
9 измењених фајлова са 156 додато и 62 уклоњено
  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 Прегледај датотеку

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

namespace Lc\ShopBundle\Context ;

interface OrderProductReductionCatalogInterface
{

}

+ 19
- 0
ShopBundle/Model/OrderProduct.php Прегледај датотеку

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

namespace Lc\ShopBundle\Model;

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

@@ -38,6 +39,11 @@ abstract class OrderProduct implements PriceInterface
*/
protected $title;

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

public function __toString()
{
if($this->getTitle()) {
@@ -158,4 +164,17 @@ abstract class OrderProduct implements PriceInterface

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 Прегледај датотеку

@@ -0,0 +1,32 @@
<?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 Прегледај датотеку

@@ -7,6 +7,7 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\ReductionInterface;
use Lc\ShopBundle\Model\AbstractDocumentEntity;
use Lc\ShopBundle\Model\ReductionPropertyTrait;
use Lc\ShopBundle\Model\ReductionTrait;

/**
@@ -15,7 +16,7 @@ use Lc\ShopBundle\Model\ReductionTrait;
abstract class ReductionCart extends AbstractDocumentEntity
{
use ReductionTrait;
use ReductionPropertyTrait ;

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

+ 1
- 1
ShopBundle/Model/ReductionCatalog.php Прегледај датотеку

@@ -15,8 +15,8 @@ use phpDocumentor\Reflection\Types\Integer;
*/
abstract class ReductionCatalog extends AbstractDocumentEntity implements ReductionCatalogInterface, FilterMerchantInterface
{

use ReductionTrait;
use ReductionPropertyTrait ;

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

+ 61
- 0
ShopBundle/Model/ReductionPropertyTrait.php Прегледај датотеку

@@ -0,0 +1,61 @@
<?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 Прегледај датотеку

@@ -2,22 +2,10 @@

namespace Lc\ShopBundle\Model;

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

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

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

/**
* @ORM\Column(type="float", nullable=true)
*/
@@ -33,36 +21,6 @@ trait ReductionTrait
*/
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
{
@@ -99,17 +57,4 @@ trait ReductionTrait

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 Прегледај датотеку

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

namespace Lc\ShopBundle\Services ;

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

class OrderUtils
@@ -15,8 +17,10 @@ class OrderUtils
protected $merchantUtils;
private $orderShopRepo;
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->security = $security;
@@ -24,6 +28,7 @@ class OrderUtils
$this->merchantUtils = $merchantUtils;
$this->orderShopRepo = $this->em->getRepository(OrderShop::class);
$this->priceUtils = $priceUtils ;
$this->productFamilyUtils = $productFamilyUtils ;
}

public function getOrderShopCurrent()
@@ -95,8 +100,23 @@ class OrderUtils
$orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited());
$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) {
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;
$orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder());
$this->em->persist($orderProduct);
@@ -105,6 +125,8 @@ class OrderUtils

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

$this->em->persist($orderProductReductionCatalog);
$this->em->persist($orderProductAdd);
$this->em->persist($orderShop);
}
@@ -113,6 +135,14 @@ class OrderUtils
}
}

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

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

+ 1
- 3
ShopBundle/Services/ProductFamilyUtils.php Прегледај датотеку

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

namespace Lc\ShopBundle\Services ;

use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;

class ProductFamilyUtils implements ProductFamilyUtilsInterface
class ProductFamilyUtils
{
protected $priceUtils ;


Loading…
Откажи
Сачувај