您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ReductionCreditBuilder.php 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Lc\CaracoleBundle\Builder\Reduction;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Factory\Reduction\ReductionCreditFactory;
  5. use Lc\CaracoleBundle\Model\Config\TaxRateModel;
  6. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  7. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
  8. use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
  9. use Lc\CaracoleBundle\Repository\Section\SectionStore;
  10. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  11. use Lc\CaracoleBundle\Solver\User\UserSolver;
  12. use Lc\CaracoleBundle\Notification\MailMailjetNotification;
  13. class ReductionCreditBuilder
  14. {
  15. protected EntityManagerInterface $entityManager;
  16. protected OrderProductStore $orderProductStore;
  17. protected ReductionCreditFactory $reductionCreditFactory;
  18. protected PriceSolver $priceSolver;
  19. protected MailMailjetNotification $mailMailjetNotification;
  20. protected UserSolver $userSolver;
  21. protected SectionStore $sectionStore;
  22. public function __construct(
  23. EntityManagerInterface $entityManager,
  24. OrderProductStore $orderProductStore,
  25. ReductionCreditFactory $reductionCreditFactory,
  26. PriceSolver $priceSolver,
  27. MailMailjetNotification $mailMailjetNotification,
  28. UserSolver $userSolver,
  29. SectionStore $sectionStore
  30. ) {
  31. $this->entityManager = $entityManager;
  32. $this->orderProductStore = $orderProductStore;
  33. $this->reductionCreditFactory = $reductionCreditFactory;
  34. $this->priceSolver = $priceSolver;
  35. $this->mailMailjetNotification = $mailMailjetNotification;
  36. $this->userSolver = $userSolver;
  37. $this->sectionStore = $sectionStore;
  38. }
  39. // generateReductionGiftFormOrderShop
  40. public function createReductionGiftFormOrderShop(OrderShopInterface $orderShop)
  41. {
  42. $user = $orderShop->getUser();
  43. $orderProductsGiftVouchers = $this->orderProductStore->getGiftVouchersByOrder($orderShop);
  44. $sectionMarket = $this->sectionStore
  45. ->setMerchant($orderShop->getSection()->getMerchant())
  46. ->getOneMarket();
  47. foreach ($orderProductsGiftVouchers as $orderProductsGiftVoucher) {
  48. $i = 1;
  49. // création de la reductionCredit
  50. while ($i <= $orderProductsGiftVoucher->getQuantityOrder()) {
  51. $reductionGift = $this->reductionCreditFactory->create($sectionMarket, ReductionCreditModel::TYPE_GIFT);
  52. $reductionGift->setTitle($orderProductsGiftVoucher->getTitle());
  53. $reductionGift->setOwner($user);
  54. $reductionGift->setCreatedBy($user);
  55. $reductionGift->setUpdatedBy($user);
  56. $reductionGift->setValue($this->priceSolver->getPriceWithTax($orderProductsGiftVoucher->getProduct()));
  57. $reductionGift->setBehaviorTaxRate(TaxRateModel::BEHAVIOR_TAX_RATE_INCLUDED);
  58. $this->entityManager->persist($reductionGift);
  59. $i++;
  60. }
  61. }
  62. $this->entityManager->flush();
  63. if (count($orderProductsGiftVouchers) > 0) {
  64. $this->mailMailjetNotification->send([
  65. MailMailjetNotification::SUBJECT => 'Comment offrir votre bon cadeau ?',
  66. MailMailjetNotification::TO_EMAIL => $user->getEmail(),
  67. MailMailjetNotification::TO_NAME => $this->userSolver->getName($user),
  68. MailMailjetNotification::CONTENT_TEMPLATE => 'mail/how-to-offer-gift-voucher'
  69. ]);
  70. }
  71. }
  72. }