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.2KB

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