You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OrderUtilsReductionTrait.php 5.9KB

4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace Lc\ShopBundle\Services;
  3. use App\Entity\OrderProductReductionCatalog;
  4. use App\Entity\OrderShop;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Lc\ShopBundle\Context\DocumentInterface;
  7. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  8. use Lc\ShopBundle\Context\OrderPaymentInterface;
  9. use Lc\ShopBundle\Context\OrderReductionCartInterface;
  10. use Lc\ShopBundle\Context\OrderProductInterface;
  11. use Lc\ShopBundle\Context\OrderReductionCreditInterface;
  12. use Lc\ShopBundle\Context\OrderShopInterface;
  13. use Lc\ShopBundle\Context\OrderStatusHistoryInterface;
  14. use Lc\ShopBundle\Context\OrderStatusInterface;
  15. use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
  16. use Lc\ShopBundle\Context\ReductionCartInterface;
  17. use Lc\ShopBundle\Context\ReductionCreditInterface;
  18. use Lc\ShopBundle\Context\UserInterface;
  19. use Lc\ShopBundle\Model\Document;
  20. use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
  21. use Lc\ShopBundle\Model\ReductionCart;
  22. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  23. use Symfony\Component\Security\Core\Security;
  24. trait OrderUtilsReductionTrait
  25. {
  26. public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
  27. {
  28. return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
  29. || ($orderProductReductionCatalog1
  30. && $orderProductReductionCatalog2
  31. && $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
  32. && (string)$orderProductReductionCatalog1->getValue() == (string)$orderProductReductionCatalog2->getValue()
  33. && $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate());
  34. }
  35. public function getSummaryOrderProductReductionCatalog($orderProductReductionCatalog)
  36. {
  37. $text = '';
  38. if ($orderProductReductionCatalog) {
  39. if ($orderProductReductionCatalog->getUnit() == 'amount') {
  40. $text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;€';
  41. }
  42. if ($orderProductReductionCatalog->getUnit() == 'percent') {
  43. $text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;%';
  44. }
  45. }
  46. return $text;
  47. }
  48. public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart)
  49. {
  50. $orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class);
  51. $orderReductionCart = new $orderReductionCartClass->name;
  52. $orderReductionCart->setOrderShop($orderShop);
  53. $orderReductionCart->setReductionCart($reductionCart);
  54. $orderReductionCart->setTitle($reductionCart->getTitle());
  55. $orderReductionCart->setValue($reductionCart->getValue());
  56. $orderReductionCart->setUnit($reductionCart->getUnit());
  57. $orderReductionCart->setBehaviorTaxRate($reductionCart->getBehaviorTaxRate());
  58. $orderReductionCart->setFreeShipping($reductionCart->getFreeShipping());
  59. $orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
  60. $orderReductionCart->setType($reductionCart->getType());
  61. $this->em->persist($orderReductionCart);
  62. $this->em->flush();
  63. return $orderReductionCart;
  64. }
  65. public function isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)
  66. {
  67. $user = $orderShop->getUser() ;
  68. // appartient à l'utilisateur
  69. if(!$reductionCredit->getUsers()->contains($user)) {
  70. return false ;
  71. }
  72. // n'a pas été utilisé
  73. if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) {
  74. return false;
  75. }
  76. return true;
  77. }
  78. public function getReductionCartRemainingQuantity($reductionCart) :float
  79. {
  80. return $reductionCart->getAvailableQuantity() - $this->orderShopRepo->countValidOrderWithReductionCart();
  81. }
  82. public function getReductionCartRemainingQuantityPerUser($reductionCart) :float
  83. {
  84. return $reductionCart->getAvailableQuantityPerUser() - $this->orderShopRepo->countValidOrderWithReductionCartPerUser();
  85. }
  86. public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit)
  87. {
  88. $orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class);
  89. $orderReductionCredit = new $orderReductionCreditClass->name;
  90. $orderReductionCredit->setOrderShop($orderShop);
  91. $orderReductionCredit->setReductionCredit($reductionCredit);
  92. $orderReductionCredit->setTitle($reductionCredit->getTitle());
  93. $orderReductionCredit->setValue($reductionCredit->getValue());
  94. $orderReductionCredit->setUnit($reductionCredit->getUnit());
  95. $orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate());
  96. $this->em->persist($orderReductionCredit);
  97. $this->em->flush();
  98. return $orderReductionCredit;
  99. }
  100. /*public function getReductionCreditsAvailable($order)
  101. {
  102. $reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class);
  103. $reductionCredits = $reductionCreditRepo->getReductionCreditByUser($order->getUser());
  104. foreach ($reductionCredits as $reductionCredit){
  105. }
  106. }*/
  107. }