|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
-
- namespace Lc\CaracoleBundle\Builder\Reduction;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Factory\Reduction\ReductionCreditFactory;
- use Lc\CaracoleBundle\Model\Config\TaxRateModel;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
- use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
- use Lc\CaracoleBundle\Repository\Section\SectionStore;
- use Lc\CaracoleBundle\Solver\Price\PriceSolver;
- use Lc\CaracoleBundle\Solver\User\UserSolver;
- use Lc\CaracoleBundle\Notification\MailMailjetNotification;
-
- class ReductionCreditBuilder
- {
- protected EntityManagerInterface $entityManager;
- protected OrderProductStore $orderProductStore;
- protected ReductionCreditFactory $reductionCreditFactory;
- protected PriceSolver $priceSolver;
- protected MailMailjetNotification $mailMailjetNotification;
- protected UserSolver $userSolver;
- protected SectionStore $sectionStore;
-
- public function __construct(
- EntityManagerInterface $entityManager,
- OrderProductStore $orderProductStore,
- ReductionCreditFactory $reductionCreditFactory,
- PriceSolver $priceSolver,
- MailMailjetNotification $mailMailjetNotification,
- UserSolver $userSolver,
- SectionStore $sectionStore
- ) {
- $this->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);
-
- $sectionMarket = $this->sectionStore
- ->setMerchant($orderShop->getSection()->getMerchant())
- ->getOneMarket();
-
- foreach ($orderProductsGiftVouchers as $orderProductsGiftVoucher) {
- $i = 1;
-
- // création de la reductionCredit
- while ($i <= $orderProductsGiftVoucher->getQuantityOrder()) {
- $reductionGift = $this->reductionCreditFactory->create($sectionMarket, 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->persist($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'
- ]);
- }
- }
- }
|