Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

OrderUtilsReductionTrait.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 Symfony\Component\HttpFoundation\Session\SessionInterface;
  22. use Symfony\Component\Security\Core\Security;
  23. trait OrderUtilsReductionTrait
  24. {
  25. public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
  26. {
  27. return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
  28. || ($orderProductReductionCatalog1
  29. && $orderProductReductionCatalog2
  30. && $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
  31. && (string) $orderProductReductionCatalog1->getValue() == (string) $orderProductReductionCatalog2->getValue()
  32. && $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ;
  33. }
  34. public function getSummaryOrderProductReductionCatalog($orderProductReductionCatalog)
  35. {
  36. $text = '';
  37. if ($orderProductReductionCatalog) {
  38. if ($orderProductReductionCatalog->getUnit() == 'amount') {
  39. $text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;€';
  40. }
  41. if ($orderProductReductionCatalog->getUnit() == 'percent') {
  42. $text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;%';
  43. }
  44. }
  45. return $text;
  46. }
  47. public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart)
  48. {
  49. $orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class);
  50. $orderReductionCart = new $orderReductionCartClass->name;
  51. $orderReductionCart->setOrderShop($orderShop);
  52. $orderReductionCart->setReductionCart($reductionCart);
  53. $orderReductionCart->setTitle($reductionCart->getTitle());
  54. $orderReductionCart->setValue($reductionCart->getValue());
  55. $orderReductionCart->setUnit($reductionCart->getUnit());
  56. $orderReductionCart->setBehaviorTaxRate($reductionCart->getBehaviorTaxRate());
  57. $orderReductionCart->setFreeShipping($reductionCart->getFreeShipping());
  58. $orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
  59. $orderReductionCart->setType($reductionCart->getType());
  60. $this->em->persist($orderReductionCart) ;
  61. $this->em->flush() ;
  62. return $orderReductionCart;
  63. }
  64. public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit){
  65. if($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser())>0){
  66. return false;
  67. }else{
  68. return true;
  69. }
  70. }
  71. public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit)
  72. {
  73. $orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class);
  74. $orderReductionCredit = new $orderReductionCreditClass->name;
  75. $orderReductionCredit->setOrderShop($orderShop);
  76. $orderReductionCredit->setReductionCredit($reductionCredit);
  77. $orderReductionCredit->setTitle($reductionCredit->getTitle());
  78. $orderReductionCredit->setValue($reductionCredit->getValue());
  79. $orderReductionCredit->setUnit($reductionCredit->getUnit());
  80. $orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate());
  81. return $orderReductionCredit;
  82. }
  83. /*public function getReductionCreditsAvailable($order)
  84. {
  85. $reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class);
  86. $reductionCredits = $reductionCreditRepo->getReductionCreditByUser($order->getUser());
  87. foreach ($reductionCredits as $reductionCredit){
  88. }
  89. }*/
  90. }