entityManager = $entityManager; $this->orderProductStore = $orderProductStore; $this->reductionCreditFactory = $reductionCreditFactory; $this->priceSolver = $priceSolver; $this->mailMailjetNotification = $mailMailjetNotification; $this->userSolver = $userSolver; $this->sectionStore = $sectionStore; } // generateReductionGiftFormOrderShop public function createReductionGiftFormOrderShop(OrderShopInterface $orderShop) { $user = $orderShop->getUser(); $orderProductsGiftVouchers = $this->orderProductStore->getGiftVouchersByOrder($orderShop); foreach ($orderProductsGiftVouchers as $orderProductsGiftVoucher) { $i = 1; // création de la reductionCredit while ($i <= $orderProductsGiftVoucher->getQuantityOrder()) { $reductionGift = $this->reductionCreditFactory->create($orderShop->getSection()->getMerchant(), ReductionCreditModel::TYPE_GIFT); $reductionGift->setTitle($orderProductsGiftVoucher->getTitle()); $reductionGift->setOwner($user); $reductionGift->setCreatedBy($user); $reductionGift->setUpdatedBy($user); $reductionGift->setValue($this->priceSolver->getPriceWithTax($orderProductsGiftVoucher->getProduct())); $reductionGift->setBehaviorTaxRate(TaxRateModel::BEHAVIOR_TAX_RATE_INCLUDED); $this->entityManager->create($reductionGift); $i++; } } $this->entityManager->flush(); if (count($orderProductsGiftVouchers) > 0) { $this->mailMailjetNotification->send([ MailMailjetNotification::SUBJECT => 'Comment offrir votre bon cadeau ?', MailMailjetNotification::TO_EMAIL => $user->getEmail(), MailMailjetNotification::TO_NAME => $this->userSolver->getName($user), MailMailjetNotification::CONTENT_TEMPLATE => 'mail/how-to-offer-gift-voucher' ]); } } }