No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

ReductionCreditBuilder.php 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. foreach ($orderProductsGiftVouchers as $orderProductsGiftVoucher) {
  45. $i = 1;
  46. // création de la reductionCredit
  47. while ($i <= $orderProductsGiftVoucher->getQuantityOrder()) {
  48. $reductionGift = $this->reductionCreditFactory->create($orderShop->getSection()->getMerchant(), ReductionCreditModel::TYPE_GIFT);
  49. $reductionGift->setTitle($orderProductsGiftVoucher->getTitle());
  50. $reductionGift->setOwner($user);
  51. $reductionGift->setCreatedBy($user);
  52. $reductionGift->setUpdatedBy($user);
  53. $reductionGift->setValue($this->priceSolver->getPriceWithTax($orderProductsGiftVoucher->getProduct()));
  54. $reductionGift->setBehaviorTaxRate(TaxRateModel::BEHAVIOR_TAX_RATE_INCLUDED);
  55. $this->entityManager->create($reductionGift);
  56. $i++;
  57. }
  58. }
  59. $this->entityManager->flush();
  60. if (count($orderProductsGiftVouchers) > 0) {
  61. $this->mailMailjetNotification->send([
  62. MailMailjetNotification::SUBJECT => 'Comment offrir votre bon cadeau ?',
  63. MailMailjetNotification::TO_EMAIL => $user->getEmail(),
  64. MailMailjetNotification::TO_NAME => $this->userSolver->getName($user),
  65. MailMailjetNotification::CONTENT_TEMPLATE => 'mail/how-to-offer-gift-voucher'
  66. ]);
  67. }
  68. }
  69. }