選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

129 行
5.6KB

  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. if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser()) > 0) {
  68. return false;
  69. } else {
  70. return true;
  71. }
  72. }
  73. public function getReductionCartRemainingQuantity($reductionCart) :float
  74. {
  75. return $reductionCart->getAvailableQuantity() - $this->orderShopRepo->countValidOrderWithReductionCart();
  76. }
  77. public function getReductionCartRemainingQuantityPerUser($reductionCart) :float
  78. {
  79. return $reductionCart->getAvailableQuantityPerUser() - $this->orderShopRepo->countValidOrderWithReductionCartPerUser();
  80. }
  81. public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit)
  82. {
  83. $orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class);
  84. $orderReductionCredit = new $orderReductionCreditClass->name;
  85. $orderReductionCredit->setOrderShop($orderShop);
  86. $orderReductionCredit->setReductionCredit($reductionCredit);
  87. $orderReductionCredit->setTitle($reductionCredit->getTitle());
  88. $orderReductionCredit->setValue($reductionCredit->getValue());
  89. $orderReductionCredit->setUnit($reductionCredit->getUnit());
  90. $orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate());
  91. return $orderReductionCredit;
  92. }
  93. /*public function getReductionCreditsAvailable($order)
  94. {
  95. $reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class);
  96. $reductionCredits = $reductionCreditRepo->getReductionCreditByUser($order->getUser());
  97. foreach ($reductionCredits as $reductionCredit){
  98. }
  99. }*/
  100. }