<?php | |||||
namespace Lc\ShopBundle\Context ; | |||||
interface OrderProductReductionCatalogInterface | |||||
{ | |||||
} |
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; | |||||
} | |||||
} | } |
<?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; | |||||
} | |||||
} |
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) |
*/ | */ | ||||
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") |
<?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; | |||||
} | |||||
} |
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; | |||||
} | |||||
} | } |
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()); |
namespace Lc\ShopBundle\Services ; | namespace Lc\ShopBundle\Services ; | ||||
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface; | |||||
class ProductFamilyUtils implements ProductFamilyUtilsInterface | |||||
class ProductFamilyUtils | |||||
{ | { | ||||
protected $priceUtils ; | protected $priceUtils ; | ||||