src/Repository/CartRepository.php line 409

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Repository;
  3. use EADPlataforma\Entity\Eadmin\Plan;
  4. use EADPlataforma\Entity\Cart;
  5. use EADPlataforma\Entity\Course;
  6. use EADPlataforma\Entity\Product;
  7. use EADPlataforma\Entity\ProductOffer;
  8. use EADPlataforma\Entity\ProductTeam;
  9. use EADPlataforma\Entity\ProductCoupon;
  10. use EADPlataforma\Entity\Receiver;
  11. use EADPlataforma\Entity\TransactionItem;
  12. use EADPlataforma\Entity\Transaction;
  13. use EADPlataforma\Entity\User;
  14. use EADPlataforma\Entity\UserCard;
  15. use EADPlataforma\Entity\ProductSuggestion;
  16. use EADPlataforma\Entity\Whishlist;
  17. use EADPlataforma\Enum\CartEnum;
  18. use EADPlataforma\Enum\ProductEnum;
  19. use EADPlataforma\Enum\ProductTeamEnum;
  20. use EADPlataforma\Enum\ProductOfferEnum;
  21. use EADPlataforma\Enum\ProductCouponEnum;
  22. use EADPlataforma\Enum\ReceiverEnum;
  23. use EADPlataforma\Enum\TagsMarketingEnum;
  24. use EADPlataforma\Enum\TransactionEnum;
  25. use EADPlataforma\Enum\TransactionItemEnum;
  26. use EADPlataforma\Enum\ProductSuggestionEnum;
  27. use EADPlataforma\Enum\UserEnum;
  28. use EADPlataforma\Enum\ProductOpportunityEnum;
  29. use EADPlataforma\Enum\EnrollmentEnum;
  30. use EADPlataforma\Enum\WebhookEnum;
  31. use EADPlataforma\Enum\CourseEnum;
  32. /**
  33.  * @method Cart|null find($id, $lockMode = null, $lockVersion = null)
  34.  * @method Cart|null findOneBy(array $criteria, array $orderBy = null)
  35.  * @method Cart[]    findAll()
  36.  * @method Cart[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  37.  */
  38. class CartRepository extends AbstractRepository
  39. {
  40.     public function getEntityClass(){
  41.         return Cart::class;
  42.     }
  43.     public function getConnectionName(){
  44.         return "school";
  45.     }
  46.     public function sendConclusionConversion(string $hashReference){
  47.         $transactionRepository $this->em->getRepository(Transaction::class);
  48.         $transactions $transactionRepository->findBy([
  49.             "deleted" => TransactionEnum::ITEM_NO_DELETED,
  50.             "hashReference" => $hashReference
  51.         ]);
  52.         foreach ($transactions as $key => $transaction) {
  53.             $this->sendConversionTransaction($transaction);
  54.         }
  55.     }
  56.     public function sendConversionTransaction(Transaction $transaction)
  57.     {
  58.         $pixelService $this->generalService->getService('Marketing\\PixelService');
  59.         $contents = [];
  60.         $transactionItemRepository $this->em->getRepository(TransactionItem::class);
  61.         $items $transactionItemRepository->findBy([
  62.             "deleted" => TransactionItemEnum::ITEM_NO_DELETED,
  63.             "transaction" => $transaction->getId(),
  64.         ]);
  65.         $tStatus $transaction->getStatus();
  66.         $tPayment $transaction->getPaymentMethod();
  67.         $statusValid = [
  68.             TransactionEnum::WAITING,
  69.             TransactionEnum::APPROVED,
  70.             TransactionEnum::CANCELED,
  71.         ];
  72.         if(!in_array($tStatus$statusValid)){
  73.             return;
  74.         }
  75.         $checkFunction = function ($value){
  76.             return (TransactionEnum::YES == $value);
  77.         };
  78.         $paymentMethodCheck = [
  79.             TransactionEnum::PAYMENT_CARD => $checkFunction,
  80.             TransactionEnum::PAYMENT_BILL => $checkFunction,
  81.             TransactionEnum::PAYMENT_PIX => $checkFunction
  82.         ];
  83.         $statusCheck = [
  84.             TransactionEnum::WAITING => $checkFunction,
  85.             TransactionEnum::APPROVED => $checkFunction,
  86.             TransactionEnum::CANCELED => $checkFunction
  87.         ];
  88.         foreach ($items as $key => $item) {
  89.             $product $item->getProduct();
  90.             if($checkFunction($product->getExecuteScriptTypeNative())){
  91.                 $valueCheckPaymentMethod = [
  92.                     TransactionEnum::PAYMENT_CARD => $product->getExecuteScriptCard(),
  93.                     TransactionEnum::PAYMENT_BILL => $product->getExecuteScriptBill(),
  94.                     TransactionEnum::PAYMENT_PIX => $product->getExecuteScriptPix()
  95.                 ];
  96.                 $valueCheckStatus = [
  97.                     TransactionEnum::WAITING => $product->getExecuteScriptStatusApproved(),
  98.                     TransactionEnum::APPROVED => $product->getExecuteScriptStatusWaiting(),
  99.                     TransactionEnum::CANCELED => $product->getExecuteScriptStatusCanceled(),
  100.                 ];
  101.                 if($paymentMethodCheck[$tPayment]($valueCheckPaymentMethod[$tPayment])){
  102.                     if($statusCheck[$tStatus]($valueCheckStatus[$tStatus])){
  103.                         $contents[] = (object)[
  104.                             "id" => $product->getId(),
  105.                             "quantity" => 1,
  106.                             "item_price" => $item->getAmount(),
  107.                             //"item_name" => $product->getTitle(),
  108.                             //"type" => $product->getType()
  109.                         ];
  110.                     }
  111.                 }
  112.             }
  113.             if($product->getType() == ProductEnum::SUBSCRIPTION){
  114.                 $pixelService->sendConversion('Subscribe', (object)[
  115.                     "value" => (float)$item->getAmount(),
  116.                     "currency" => $transaction->getCurrencyCode(),
  117.                     "contents" => [
  118.                         (object)[
  119.                             "id" => $product->getId(),
  120.                             "quantity" => 1,
  121.                             "item_price" => $item->getAmount(),
  122.                             //"name" => $product->getTitle(),
  123.                             //"type" => $product->getType()
  124.                         ]
  125.                     ],
  126.                     "num_items" => 1,
  127.                     "content_type" => "product",
  128.                     "transaction_id" => $transaction->getId(),
  129.                 ]);
  130.             }
  131.         }
  132.         if(empty($contents)){
  133.             return;
  134.         }
  135.         $data = (object)[
  136.             "value" => (float)$transaction->getAmount(),
  137.             "currency" => $transaction->getCurrencyCode(),
  138.             "contents" => $contents,
  139.             "num_items" => count($contents),
  140.             "content_type" => "product",
  141.             "transaction_id" => $transaction->getId(),
  142.         ];
  143.         $pixelService->sendConversion('Purchase'$data);
  144.     }
  145.     public function addCartByProductOffer(
  146.         ProductOffer $productOffer
  147.         ?User $user null
  148.         ?ProductSuggestion $productSuggestion null
  149.         ?ProductCoupon $productCoupon null,
  150.         ?string $utmsUrl null,
  151.         ?array $courses null
  152.     )
  153.     {
  154.         $product $productOffer->getProduct();
  155.         if($product->isDisable()){
  156.             return false;
  157.         }
  158.         if($productOffer->getNotForSale() == ProductOfferEnum::YES){
  159.             return false;
  160.         }
  161.         $transactionItemRepository $this->em->getRepository(TransactionItem::class);
  162.         $saleNumber $transactionItemRepository->countSalesApprovedByProductOffer(
  163.             $productOffer
  164.         );
  165.         $poRepository $this->em->getRepository(ProductOffer::class);
  166.         if(!$poRepository->checkProductOfferIsOnSale($productOffer)){
  167.             return false;
  168.         }
  169.         if($user){
  170.             $productRepository $this->em->getRepository(Product::class);
  171.             if($productRepository->userHasProduct($user$product)){
  172.                 return false;
  173.             }
  174.         }
  175.         if(empty($courses) && $product->isTypeResource()){
  176.             return false;
  177.         }
  178.         $hashIdentify $this->generalService->getCookieHashIdentify();
  179.         $filter = [
  180.             "product" => $product->getId()
  181.         ];
  182.         if($user){
  183.             $filter["user"] = $user->getId();
  184.         } else if(!empty($hashIdentify)){
  185.             $filter["hashIdentify"] = $hashIdentify;
  186.         }
  187.         
  188.         $new false;
  189.         $cart $this->findOneBy($filter);
  190.         if (!$cart) {
  191.             $new true;
  192.             $cart = new Cart();
  193.         }
  194.         if(!$new){
  195.             if($cart->getProductOffer()->getId() != $productOffer->getId()){
  196.                 if($utmsUrl){
  197.                     $cart->setUtmsUrl($utmsUrl);
  198.                 }
  199.                 $this->updateCartProductSuggestion($cart);
  200.             }
  201.         }
  202.         if($utmsUrl){
  203.             $cart->setUtmsUrl($utmsUrl);
  204.         }
  205.         if($courses){
  206.             foreach ($courses as $key => $course) {
  207.                 $cart->addCourse($course);
  208.             }
  209.         }
  210.         $cart->setProductOffer($productOffer);
  211.         $cart->setProduct($product);
  212.         if($productSuggestion){
  213.             $cart->setProductSuggestion($productSuggestion);
  214.         }
  215.         if($user){
  216.             $cart->setUser($user);
  217.             $cart->setHashIdentify($user->getHashIdentify());
  218.         }else if(!empty($hashIdentify)){
  219.             $cart->setHashIdentify($hashIdentify);
  220.         }
  221.         $price $productOffer->getPriceReal();
  222.         $membershipFee $productOffer->getMembershipFee();
  223.         if($productCoupon){
  224.             $productCouponRepository $this->em->getRepository(ProductCoupon::class);
  225.             if($productCoupon->getApplyMembershipFee() == ProductCouponEnum::YES){
  226.                 $membershipFee $productCouponRepository->applyDiscount(
  227.                     $productCoupon
  228.                     $membershipFee
  229.                 );
  230.             }else{
  231.                 $price $productCouponRepository->applyDiscount(
  232.                     $productCoupon
  233.                     $price
  234.                 );
  235.                 if(
  236.                     !$productCouponRepository->checkApplyCoupon(
  237.                         $productCoupon
  238.                         $productOffer
  239.                     )
  240.                 ){
  241.                     return;
  242.                 }
  243.             }
  244.             $cart->setProductCoupon($productCoupon);
  245.         }
  246.         $cart->setPrice($productOffer->getPriceReal());
  247.         if(
  248.             $product->getType() == ProductEnum::SUBSCRIPTION || 
  249.             $productOffer->getAllowRecurrency() == ProductEnum::YES
  250.         ){
  251.             $cart->setMembershipFee($membershipFee);
  252.         }
  253.         
  254.         if($cart->getProduct()){
  255.             $cart->setProductType($cart->getProduct()->getType());
  256.         }
  257.         $entityUtil $this->generalService->getUtil('EntityUtil');
  258.         $errors $entityUtil->setEntity($cart)->validateEntity();
  259.         if($errors){
  260.             return false;
  261.         }
  262.         if(!empty($price) || $productCoupon){
  263.             $cart->setPrice($price);
  264.         }
  265.         $cart->restore();
  266.         
  267.         if($new){
  268.             $this->em->persist($cart);
  269.         }
  270.         $this->em->flush();
  271.         $this->processAddCart($cart$new);
  272.         return $cart;
  273.     }
  274.     public function processAddCart(Cart $cart, ?bool $new false)
  275.     {
  276.         $crmService $this->generalService->getService('CRM\\CrmService');
  277.         $product $cart->getProduct();
  278.         $productOffer $cart->getProductOffer();
  279.         $user $cart->getUser();
  280.         if(!$product->getPipedriveProduct()){
  281.             $crmService->saveProduct($product);
  282.         }
  283.         if($user){
  284.             $pipedriveDealId null;
  285.             if(!$user->getPipedrivePerson()){
  286.                 $crmService->savePerson($user);
  287.             }
  288.             $whishlist $this->em->getRepository(Whishlist::class)->findOneBy([
  289.                 "product" => $product->getId(), 
  290.                 "user" => $user->getId()
  291.             ]);
  292.             if(!$whishlist){
  293.                 $pipedriveDealId $crmService->saveDeal(
  294.                     $cart->getPipedriveDeal(),
  295.                     $user,
  296.                     $product,
  297.                     'open',
  298.                     $this->configuration->get("pipedrive_cart"),
  299.                     $cart->getPrice(),
  300.                     $productOffer->getCurrencyCode()
  301.                 );
  302.                 $cart->setPipedriveDeal($pipedriveDealId);
  303.             }else{
  304.                 $pipedriveDeal $cart->getPipedriveDeal();
  305.                 $price $cart->getPrice();
  306.                 if(empty($pipedriveDeal)){
  307.                     $pipedriveDeal $whishlist->getPipedriveDeal();
  308.                     $price $productOffer->getPriceReal();
  309.                 }
  310.                 $pipedriveDealId $crmService->saveDeal(
  311.                     $pipedriveDeal,
  312.                     $user,
  313.                     $product,
  314.                     'open',
  315.                     $this->configuration->get("pipedrive_cart"),
  316.                     $price,
  317.                     $productOffer->getCurrencyCode()
  318.                 );
  319.                 $whishlist->setPipedriveDeal($pipedriveDealId);
  320.                 $cart->setPipedriveDeal($pipedriveDealId);
  321.             }
  322.             $this->em->flush();
  323.             
  324.             //tags
  325.             $mkgService $this->generalService->getService('Marketing\\MarketingService');
  326.             $mkgService->setTag(TagsMarketingEnum::TAG_ADD_CART);
  327.             $mkgService->setTextComplement($product->getTitle());
  328.             $mkgService->setUser($user);
  329.             $mkgService->setProductOffer($productOffer);
  330.             $mkgService->setOpportunity(ProductOpportunityEnum::TAG_ADD_CART);
  331.             $mkgService->send();
  332.         }
  333.         
  334.         //pixel
  335.         $pixelService $this->generalService->getService('Marketing\\PixelService');
  336.         $pixelService->sendConversion('AddToCart', (object)[
  337.             "content_ids" => [ $productOffer->getId() ],
  338.             "content_name" => $productOffer->getTitle(),
  339.             "currency" => $productOffer->getCurrencyCode(),
  340.             "value" => $productOffer->getPriceReal(),
  341.         ]);
  342.         return;
  343.     }
  344.     public function updateCartHashToUser(User $user)
  345.     {
  346.         $crmService $this->generalService->getService('CRM\\CrmService');
  347.         $productRepository $this->em->getRepository(Product::class);
  348.         $cookieName 'hashcartoff';
  349.         $hashIdentify $this->generalService->getCookie($cookieName);
  350.         if(empty($hashIdentify)){
  351.             return;
  352.         }
  353.         //if($hashIdentify != $user->getHashIdentify()){
  354.             //return;
  355.         //}
  356.         $enrollmentService $this->generalService->getService('EnrollmentService');
  357.         $carts $this->getHashValidCarts($hashIdentify);
  358.         $cartsNumber count($carts);
  359.         $free 0;
  360.         foreach ($carts as $key => $cart) {
  361.             $product $cart->getProduct();
  362.             $userCart $cart->getUser();
  363.             $cartSave $this->findOneBy([
  364.                 "user" => $user->getId(),
  365.                 "product" => $product->getId(),
  366.             ]);
  367.             $productCoupon $cart->getProductCoupon();
  368.             $price = (float)$cart->getPrice();
  369.             if(empty($price) && $productCoupon){
  370.                 $free $free 1;
  371.                 $productCoupon->setUsageNumber($productCoupon->getUsageNumber() + 1);
  372.                 $enrollmentService->setOrigin(EnrollmentEnum::ORIGIN_COUPOM);
  373.                 $enrollmentService->setCouponKey($productCoupon->getKey());
  374.                 $enrollmentService->enrollUserByProduct(
  375.                     $user,
  376.                     $cart->getProduct(),
  377.                     ($cart->getProduct()->isTypeResource() ? $cart->getCourse() : null)
  378.                 );
  379.                 $this->em->remove($cart);
  380.             }else{
  381.                 if($userCart){
  382.                     if($userCart->getId() == $user->getId()){
  383.                         if($productRepository->userHasProduct($user$product)){
  384.                             $this->em->remove($cart);
  385.                             $free $free 1;
  386.                         }else if($cartSave && $cartSave->getId() != $cart->getId()){
  387.                             $this->em->remove($cartSave);
  388.                         }
  389.                     }else{
  390.                         if($cartSave){
  391.                             $pipedriveDealId $cartSave->getPipedriveDeal();
  392.                             $this->em->remove($cartSave);
  393.                         }
  394.                         $newCart = clone $cart;
  395.                         $newCart->setUser($user);
  396.                         $newCart->setHashIdentify($user->getHashIdentify());
  397.                         $pipedriveDealId $crmService->saveDeal(
  398.                             (!empty($pipedriveDealId) ? $pipedriveDealId null),
  399.                             $user,
  400.                             $product,
  401.                             'open',
  402.                             $this->configuration->get("pipedrive_cart"),
  403.                             $newCart->getPrice(),
  404.                             $newCart->getProductOffer()->getCurrencyCode()
  405.                         );
  406.                         $newCart->setPipedriveDeal($pipedriveDealId);
  407.                         $this->em->persist($newCart);
  408.                     }
  409.                 }else{
  410.                     $pipedriveDealId null;
  411.                     if($cartSave){
  412.                         $pipedriveDealId $cartSave->getPipedriveDeal();
  413.                         $this->em->remove($cartSave);
  414.                     }
  415.                     $cart->setUser($user);
  416.                     $cart->setHashIdentify($user->getHashIdentify());
  417.                     
  418.                     $pipedriveDealId $crmService->saveDeal(
  419.                         (!empty($pipedriveDealId) ? $pipedriveDealId $cart->getPipedriveDeal()),
  420.                         $user,
  421.                         $product,
  422.                         'open',
  423.                         $this->configuration->get("pipedrive_cart"),
  424.                         $cart->getPrice(),
  425.                         $cart->getProductOffer()->getCurrencyCode()
  426.                     );
  427.                     $cart->setPipedriveDeal($pipedriveDealId);
  428.                 }
  429.             }
  430.         }
  431.         $this->em->flush();
  432.         $this->generalService->setCookie($cookieName$user->getHashIdentify());
  433.         return ($cartsNumber == $free);
  434.     }
  435.     public function updateCartProductSuggestion(Cart $cart)
  436.     {
  437.         $poRepository $this->em->getRepository(ProductOffer::class);
  438.         $user $cart->getUser();
  439.         $query $this->createQueryBuilder('c');
  440.         $query->innerJoin(
  441.             'EADPlataforma:ProductSuggestion'
  442.             'ps'
  443.             'WITH',
  444.             'ps.id = c.productSuggestion'
  445.         );
  446.         $query->andWhere('c.id != :cartDeleted');
  447.         $query->andWhere('ps.productOrigin = :productOrigin');
  448.         $query->andWhere(':productOfferOrigin MEMBER OF ps.productOfferOrigin');
  449.         $query->andWhere('c.deleted = :deleted');
  450.         if($user){
  451.             $query->andWhere('c.user = :userId');
  452.             $query->setParameter('userId'$cart->getUser()->getId());
  453.         }else{
  454.             $query->andWhere('c.hashIdentify = :hashIdentify');
  455.             $query->setParameter('hashIdentify'$cart->getHashIdentify());
  456.         }
  457.         $query->setParameter('cartDeleted'$cart->getId());
  458.         $query->setParameter('productOrigin'$cart->getProduct()->getId());
  459.         $query->setParameter('productOfferOrigin'$cart->getProductOffer()->getId());
  460.         $query->setParameter('deleted'CartEnum::ITEM_NO_DELETED);
  461.         $cartsWithSuggestion $query->getQuery()->execute();
  462.         foreach ($cartsWithSuggestion as $key => $cartWithSuggestion) {
  463.             $cartWithSuggestion->setProductSuggestion(null);
  464.             $product $cartWithSuggestion->getProduct();
  465.             $productOfferDefault $poRepository->getProductOfferDefaultByProduct($product);
  466.             if($productOfferDefault){
  467.                 $cartWithSuggestion->setProductOffer($productOfferDefault);
  468.                 $cartWithSuggestion->setPrice($productOfferDefault->getPriceReal());
  469.                 if(
  470.                     $product->getType() == ProductEnum::SUBSCRIPTION || 
  471.                     $productOfferDefault->getAllowRecurrency() == ProductEnum::YES
  472.                 ){
  473.                     $cartWithSuggestion->setMembershipFee(
  474.                         $productOfferDefault->getMembershipFee()
  475.                     );
  476.                 }
  477.             }else{
  478.                 $cartsWithSuggestion->delete();
  479.             }
  480.         }
  481.         $this->em->flush();
  482.         return;
  483.     }
  484.     
  485.     public function countUserOnCart()
  486.     {
  487.         if($this->getUser()){
  488.             return $this->countUserValidCarts($this->getUser()->getId());
  489.         }else{
  490.             $hashIdentify $this->generalService->getCookie('hashcartoff');
  491.             if(!empty($hashIdentify)){
  492.                 return $this->countHashValidCarts($hashIdentify);
  493.             }
  494.         }
  495.         return 0;
  496.     }
  497.     public function countCustomCheckout(int $userId)
  498.     {
  499.         $query $this->createQueryBuilder('c');
  500.         $query->select('COUNT(c.id) AS total');
  501.         $query->innerJoin('EADPlataforma:Product''p''WITH''p.id = c.product');
  502.         
  503.         $query->innerJoin(
  504.             'EADPlataforma:ProductOffer'
  505.             'po'
  506.             'WITH'
  507.             'po.id = c.productOffer AND po.product = p.id'
  508.         );
  509.         $query->andWhere('( 
  510.             po.saleDateType = 0 
  511.             OR (:today BETWEEN po.saleDateStart AND po.saleDateClose) 
  512.         )');
  513.         $query->andWhere('po.notForSale = :no');
  514.         $query->setParameter('no'ProductOfferEnum::NO);
  515.         $query->andWhere('c.user = :userId');
  516.         $query->andWhere('c.deleted = :deleted');
  517.         $query->andWhere('p.status != :statusDraftProduct');
  518.         $query->andWhere('po.status = :statusPublicProductOffer');
  519.         $query->andWhere('p.deleted = :deletedProduct');
  520.         $query->andWhere('po.deleted = :deletedProductOffer');
  521.         $query->andWhere('po.typeCheckout = :customCheckout');
  522.         $query->setParameter('userId'$userId);
  523.         $query->setParameter('today'date('Y-m-d H:i:s'));
  524.         $query->setParameter('statusDraftProduct'ProductEnum::DRAFT);
  525.         $query->setParameter('statusPublicProductOffer'ProductOfferEnum::PUBLISHED);
  526.         $query->setParameter('deleted'CartEnum::ITEM_NO_DELETED);
  527.         $query->setParameter('deletedProduct'ProductEnum::ITEM_NO_DELETED);
  528.         $query->setParameter('deletedProductOffer'ProductEnum::ITEM_NO_DELETED);
  529.         $query->setParameter('customCheckout'ProductOfferEnum::CHECKOUT_CUSTOM);
  530.         $result = (object)$query->getQuery()->getOneOrNullResult();
  531.         return $result->total;
  532.     }
  533.     public function hasOnlyCourseInCart(int $userId)
  534.     {
  535.         $query $this->createQueryBuilder('c');
  536.         $query->select('COUNT(c.id) AS total');
  537.         $query->innerJoin('EADPlataforma:Product''p''WITH''p.id = c.product');
  538.         $query->innerJoin(
  539.             'EADPlataforma:ProductOffer'
  540.             'po'
  541.             'WITH'
  542.             'po.id = c.productOffer AND po.product = p.id'
  543.         );
  544.         $query->andWhere('( 
  545.             po.saleDateType = :saleDateType
  546.             OR (:today BETWEEN po.saleDateStart AND po.saleDateClose) 
  547.         )');
  548.         $query->andWhere('po.notForSale = :no');
  549.         $query->setParameter('no'ProductOfferEnum::NO);
  550.         $query->andWhere('c.user = :userId');
  551.         $query->andWhere('c.deleted = :deleted');
  552.         $query->andWhere('p.status != :statusDraftProduct');
  553.         $query->andWhere('po.status = :statusPublicProductOffer');
  554.         $query->andWhere('p.deleted = :deletedProduct');
  555.         $query->andWhere('po.deleted = :deletedProductOffer');
  556.         $query->andWhere('(
  557.             (p.type != :typeCourse AND p.type != :typeCombo)
  558.             OR
  559.             po.allowRecurrency = :allowRecurrency
  560.         )');
  561.         $query->setParameter('allowRecurrency'ProductOfferEnum::YES);
  562.         $query->setParameter('saleDateType'ProductOfferEnum::SALE_OPEN);
  563.         $query->setParameter('userId'$userId);
  564.         $query->setParameter('today'date('Y-m-d H:i:s'));
  565.         $query->setParameter('statusDraftProduct'ProductEnum::DRAFT);
  566.         $query->setParameter('statusPublicProductOffer'ProductOfferEnum::PUBLISHED);
  567.         $query->setParameter('deleted'CartEnum::ITEM_NO_DELETED);
  568.         $query->setParameter('deletedProduct'ProductEnum::ITEM_NO_DELETED);
  569.         $query->setParameter('deletedProductOffer'ProductEnum::ITEM_NO_DELETED);
  570.         $query->setParameter('typeCourse'ProductEnum::COURSE);
  571.         $query->setParameter('typeCombo'ProductEnum::COMBO);
  572.         $result = (object)$query->getQuery()->getOneOrNullResult();
  573.         return ($result->total false true);
  574.     }
  575.     public function getUserValidCarts(int $userId, ?int $productId null
  576.                                       ?int $limit null)
  577.     {
  578.         $query $this->createQueryBuilder('c');
  579.         $query->innerJoin('EADPlataforma:Product''p''WITH''p.id = c.product');
  580.         $query->innerJoin(
  581.             'EADPlataforma:ProductOffer'
  582.             'po'
  583.             'WITH'
  584.             'po.id = c.productOffer AND po.product = p.id'
  585.         );
  586.         $query->andWhere('( 
  587.             po.saleDateType = :saleDateType 
  588.             OR (:today BETWEEN po.saleDateStart AND po.saleDateClose) 
  589.         )');
  590.         $query->andWhere('po.notForSale = :no');
  591.         $query->setParameter('no'ProductOfferEnum::NO);
  592.         $query->andWhere('c.user = :userId');
  593.         $query->andWhere('c.deleted = :deleted');
  594.         $query->andWhere('p.status != :statusDraftProduct');
  595.         $query->andWhere('po.status = :statusPublicProductOffer');
  596.         $query->andWhere('p.deleted = :deletedProduct');
  597.         $query->andWhere('po.deleted = :deletedProductOffer');
  598.         $query->setParameter('userId'$userId);
  599.         $query->setParameter('today'date('Y-m-d H:i:s'));
  600.         $query->setParameter('saleDateType'ProductOfferEnum::SALE_OPEN);
  601.         $query->setParameter('statusDraftProduct'ProductEnum::DRAFT);
  602.         $query->setParameter('statusPublicProductOffer'ProductOfferEnum::PUBLISHED);
  603.         $query->setParameter('deleted'CartEnum::ITEM_NO_DELETED);
  604.         $query->setParameter('deletedProduct'ProductEnum::ITEM_NO_DELETED);
  605.         $query->setParameter('deletedProductOffer'ProductEnum::ITEM_NO_DELETED);
  606.         
  607.         
  608.         if($productId 0){
  609.             $query->andWhere('c.product = :productId');
  610.             $query->setParameter('productId'$productId);
  611.         }
  612.         if(!empty($limit)){
  613.             $query->setMaxResults($limit);
  614.         }
  615.         return $query->getQuery()->execute();
  616.     }
  617.     public function countUserValidCarts(int $userId)
  618.     {
  619.         $query $this->createQueryBuilder('c');
  620.         $query->select('COUNT(c.id) AS total');
  621.         $query->innerJoin('EADPlataforma:Product''p''WITH''p.id = c.product');
  622.         
  623.         $query->innerJoin(
  624.             'EADPlataforma:ProductOffer'
  625.             'po'
  626.             'WITH'
  627.             'po.id = c.productOffer AND po.product = p.id'
  628.         );
  629.         
  630.         $query->andWhere('( 
  631.             po.saleDateType = 0 
  632.             OR (:today BETWEEN po.saleDateStart AND po.saleDateClose) 
  633.         )');
  634.         $query->andWhere('po.notForSale = :no');
  635.         $query->setParameter('no'ProductOfferEnum::NO);
  636.         $query->andWhere('c.user = :userId');
  637.         $query->andWhere('c.deleted = :deleted');
  638.         $query->andWhere('p.status != :statusDraftProduct');
  639.         $query->andWhere('po.status = :statusPublicProductOffer');
  640.         $query->andWhere('p.deleted = :deletedProduct');
  641.         $query->andWhere('po.deleted = :deletedProductOffer');
  642.         $query->setParameter('userId'$userId);
  643.         $query->setParameter('today'date('Y-m-d H:i:s'));
  644.         $query->setParameter('statusDraftProduct'ProductEnum::DRAFT);
  645.         $query->setParameter('statusPublicProductOffer'ProductOfferEnum::PUBLISHED);
  646.         $query->setParameter('deleted'CartEnum::ITEM_NO_DELETED);
  647.         $query->setParameter('deletedProduct'ProductEnum::ITEM_NO_DELETED);
  648.         $query->setParameter('deletedProductOffer'ProductEnum::ITEM_NO_DELETED);
  649.         $result = (object)$query->getQuery()->getOneOrNullResult();
  650.         return $result->total;
  651.     }
  652.     public function countHashValidCarts(string $hash)
  653.     {
  654.         $query $this->createQueryBuilder('c');
  655.         $query->select('COUNT(c.id) AS total');
  656.         $query->innerJoin('EADPlataforma:Product''p''WITH''p.id = c.product');
  657.         $query->innerJoin(
  658.             'EADPlataforma:ProductOffer'
  659.             'po'
  660.             'WITH'
  661.             'po.id = c.productOffer AND po.product = p.id'
  662.         );
  663.         $query->andWhere('( 
  664.             po.saleDateType = 0 
  665.             OR (:today BETWEEN po.saleDateStart AND po.saleDateClose) 
  666.         )');
  667.         $query->andWhere('po.notForSale = :no');
  668.         $query->setParameter('no'ProductOfferEnum::NO);
  669.         $query->andWhere('c.hashIdentify = :hash');
  670.         $query->andWhere('c.deleted = :deleted');
  671.         $query->andWhere('p.status != :statusDraftProduct');
  672.         $query->andWhere('po.status = :statusPublicProductOffer');
  673.         $query->andWhere('p.deleted = :deletedProduct');
  674.         $query->andWhere('po.deleted = :deletedProductOffer');
  675.         $query->setParameter('hash'$hash);
  676.         $query->setParameter('today'date('Y-m-d H:i:s'));
  677.         $query->setParameter('statusDraftProduct'ProductEnum::DRAFT);
  678.         $query->setParameter('statusPublicProductOffer'ProductOfferEnum::PUBLISHED);
  679.         $query->setParameter('deleted'CartEnum::ITEM_NO_DELETED);
  680.         $query->setParameter('deletedProduct'ProductEnum::ITEM_NO_DELETED);
  681.         $query->setParameter('deletedProductOffer'ProductEnum::ITEM_NO_DELETED);
  682.         $result = (object)$query->getQuery()->getOneOrNullResult();
  683.         return $result->total;
  684.     }
  685.     public function getUserDisplaySubTotal(int $userId)
  686.     {
  687.         $query $this->createQueryBuilder('c');
  688.         
  689.         $query->select('
  690.             SUM(
  691.                 CASE
  692.                 WHEN po.priceDisplay > po.priceReal
  693.                 THEN po.priceDisplay + po.membershipFee
  694.                 ELSE po.priceReal + po.membershipFee
  695.                 END
  696.             ) AS subtotal
  697.         ');
  698.         $query->innerJoin('EADPlataforma:Product''p''WITH''p.id = c.product');
  699.         $query->innerJoin(
  700.             'EADPlataforma:ProductOffer'
  701.             'po'
  702.             'WITH'
  703.             'po.id = c.productOffer AND po.product = p.id'
  704.         );
  705.         $query->andWhere('( 
  706.             po.saleDateType = :no
  707.             OR (:today BETWEEN po.saleDateStart AND po.saleDateClose) 
  708.         )');
  709.         $query->andWhere('po.notForSale = :no');
  710.         $query->setParameter('no'ProductOfferEnum::NO);
  711.         $query->andWhere('c.user = :userId');
  712.         $query->andWhere('c.deleted = :deleted');
  713.         $query->andWhere('p.status != :statusDraftProduct');
  714.         $query->andWhere('po.status = :statusPublicProductOffer');
  715.         $query->andWhere('p.deleted = :deletedProduct');
  716.         $query->andWhere('po.deleted = :deletedProductOffer');
  717.         $query->setParameter('userId'$userId);
  718.         $query->setParameter('today'date('Y-m-d H:i:s'));
  719.         $query->setParameter('no'ProductOfferEnum::NO);
  720.         $query->setParameter('statusDraftProduct'ProductEnum::DRAFT);
  721.         $query->setParameter('statusPublicProductOffer'ProductOfferEnum::PUBLISHED);
  722.         $query->setParameter('deleted'CartEnum::ITEM_NO_DELETED);
  723.         $query->setParameter('deletedProduct'ProductEnum::ITEM_NO_DELETED);
  724.         $query->setParameter('deletedProductOffer'ProductEnum::ITEM_NO_DELETED);
  725.         
  726.         $result = (object)$query->getQuery()->getOneOrNullResult();
  727.         return $result->subtotal;
  728.     }
  729.     public function getUserSubTotal(int $userId)
  730.     {
  731.         $query $this->createQueryBuilder('c');
  732.         $query->select('SUM(c.price + c.membershipFee) AS subtotal');
  733.         $query->innerJoin('EADPlataforma:Product''p''WITH''p.id = c.product');
  734.         
  735.         $query->innerJoin(
  736.             'EADPlataforma:ProductOffer'
  737.             'po'
  738.             'WITH'
  739.             'po.id = c.productOffer AND po.product = p.id'
  740.         );
  741.         $query->andWhere('( 
  742.             po.saleDateType = 0 
  743.             OR (:today BETWEEN po.saleDateStart AND po.saleDateClose) 
  744.         )');
  745.         $query->andWhere('po.notForSale = :no');
  746.         $query->setParameter('no'ProductOfferEnum::NO);
  747.         $query->andWhere('c.user = :userId');
  748.         $query->andWhere('c.deleted = :deleted');
  749.         $query->andWhere('p.status != :statusDraftProduct');
  750.         $query->andWhere('po.status = :statusPublicProductOffer');
  751.         $query->andWhere('p.deleted = :deletedProduct');
  752.         $query->andWhere('po.deleted = :deletedProductOffer');
  753.         $query->andWhere('c.user = :userId');
  754.         $query->andWhere('c.deleted = :deleted');
  755.         $query->andWhere('p.status != :statusDraftProduct');
  756.         $query->andWhere('po.status = :statusPublicProductOffer');
  757.         $query->andWhere('p.deleted = :deletedProduct');
  758.         $query->andWhere('po.deleted = :deletedProductOffer');
  759.         $query->setParameter('userId'$userId);
  760.         $query->setParameter('today'date('Y-m-d H:i:s'));
  761.         $query->setParameter('statusDraftProduct'ProductEnum::DRAFT);
  762.         $query->setParameter('statusPublicProductOffer'ProductOfferEnum::PUBLISHED);
  763.         $query->setParameter('deleted'CartEnum::ITEM_NO_DELETED);
  764.         $query->setParameter('deletedProduct'ProductEnum::ITEM_NO_DELETED);
  765.         $query->setParameter('deletedProductOffer'ProductEnum::ITEM_NO_DELETED);
  766.         
  767.         $result = (object)$query->getQuery()->getOneOrNullResult();
  768.         return (!empty($result->subtotal) ? $result->subtotal );
  769.     }
  770.     public function isValidCart(Cart $cart)
  771.     {
  772.         $product $cart->getProduct();
  773.         $productOffer $cart->getProductOffer();
  774.         if($product->isDisable()){
  775.             return false;
  776.         }
  777.         if($productOffer->getStatus() != ProductOfferEnum::PUBLISHED){
  778.             return false;
  779.         }
  780.         if($productOffer->getNotForSale() == ProductOfferEnum::YES){
  781.             return false;
  782.         }
  783.         if(!$productOffer->getSaleIsOpen()){
  784.             return false;
  785.         }
  786.         return true;
  787.     }
  788.     public function getHashValidCartsInfo(string $hash)
  789.     {
  790.         $filter = [
  791.             "hashIdentify" => $hash,
  792.             "deleted" => CartEnum::ITEM_NO_DELETED,
  793.         ];
  794.         $carts $this->findBy($filter);
  795.         $total 0;
  796.         $totalCustom 0;
  797.         $totalPrice 0;
  798.         $totalDisplay 0;
  799.         $data = [];
  800.         foreach ($carts as $key => $cart) {
  801.             if(!$this->isValidCart($cart)){
  802.                 continue;
  803.             }
  804.             $productOffer $cart->getProductOffer();
  805.             $price = (
  806.                 $productOffer->getPriceDisplay() > $productOffer->getPriceReal() ? 
  807.                 $productOffer->getPriceDisplay() : 
  808.                 $productOffer->getPriceReal()
  809.             );
  810.             $total $total 1;
  811.             if($productOffer->getTypeCheckout() == ProductOfferEnum::CHECKOUT_CUSTOM){
  812.                 $totalCustom $totalCustom 1;
  813.             }
  814.             $totalPrice $totalPrice $cart->getPrice() + $cart->getMembershipFee();
  815.             $totalDisplay $totalDisplay $price $productOffer->getMembershipFee();
  816.             $data[] = $cart;
  817.         }
  818.         return (object)[
  819.             "total" => $total,
  820.             "totalCustom" => $totalCustom,
  821.             "totalPrice" => $totalPrice,
  822.             "totalDisplay" => $totalDisplay,
  823.             "data" => $data,
  824.         ];
  825.     }
  826.     public function countCustomCheckoutHash(string $hash)
  827.     {
  828.         $carts $this->findBy([
  829.             "hashIdentify" => $hash,
  830.             "deleted" => CartEnum::ITEM_NO_DELETED,
  831.         ]);
  832.         $total 0;
  833.         foreach ($carts as $key => $cart) {
  834.             if(!$this->isValidCart($cart)){
  835.                 continue;
  836.             }
  837.             $total $total 1;
  838.         }
  839.         return $total;
  840.     }
  841.     public function getHashValidCarts(string $hash, ?int $productId null
  842.                                       ?int $limit null)
  843.     {
  844.         $filter = [
  845.             "hashIdentify" => $hash,
  846.             "deleted" => CartEnum::ITEM_NO_DELETED,
  847.         ];
  848.         if($productId 0){
  849.             $filter["product"] = $productId;
  850.         }
  851.         $carts $this->findBy($filternull$limit);
  852.         $data = [];
  853.         foreach ($carts as $key => $cart) {
  854.             if(!$this->isValidCart($cart)){
  855.                 continue;
  856.             }
  857.             $data[] = $cart;
  858.         }
  859.         return $data;
  860.     }
  861.     public function getHashDisplaySubTotal(string $hash)
  862.     {
  863.         $filter = [
  864.             "hashIdentify" => $hash,
  865.             "deleted" => CartEnum::ITEM_NO_DELETED,
  866.         ];
  867.         $carts $this->findBy($filter);
  868.         $total 0;
  869.         foreach ($carts as $key => $cart) {
  870.             if(!$this->isValidCart($cart)){
  871.                 continue;
  872.             }
  873.             $productOffer $cart->getProductOffer();
  874.             $price = (
  875.                 $productOffer->getPriceDisplay() > $productOffer->getPriceReal() ? 
  876.                 $productOffer->getPriceDisplay() : 
  877.                 $productOffer->getPriceReal()
  878.             );
  879.             $total $total $price $productOffer->getMembershipFee();
  880.         }
  881.         return $total;
  882.     }
  883.     public function getHashSubTotal(string $hash)
  884.     {
  885.         $filter = [
  886.             "hashIdentify" => $hash,
  887.             "deleted" => CartEnum::ITEM_NO_DELETED,
  888.         ];
  889.         $carts $this->findBy($filter);
  890.         $total 0;
  891.         foreach ($carts as $key => $cart) {
  892.             if(!$this->isValidCart($cart)){
  893.                 continue;
  894.             }
  895.             $total $total $cart->getPrice() + $cart->getMembershipFee();
  896.         }
  897.         return $total;
  898.     }
  899.     public function getAbandonedCarts(int $type)
  900.     {
  901.         $query $this->createQueryBuilder('c');
  902.         $query->innerJoin('EADPlataforma:Product''p''WITH''p.id = c.product');
  903.         $query->innerJoin('EADPlataforma:User''u''WITH''u.id = c.user');
  904.         
  905.         $query->innerJoin(
  906.             'EADPlataforma:ProductOffer'
  907.             'po'
  908.             'WITH'
  909.             'po.id = c.productOffer AND po.product = p.id'
  910.         );
  911.         $query->andWhere('( 
  912.             po.saleDateType = 0 
  913.             OR (:today BETWEEN po.saleDateStart AND po.saleDateClose) 
  914.         )');
  915.         $query->andWhere('po.notForSale = :no');
  916.         $query->setParameter('no'ProductOfferEnum::NO);
  917.         $query->andWhere('u.status != 2');
  918.         $query->andWhere('c.type = :type');
  919.         $query->andWhere('c.deleted = :deleted');
  920.         $query->andWhere('p.status != :statusDraftProduct');
  921.         $query->andWhere('po.status = :statusPublicProductOffer');
  922.         $query->andWhere('p.deleted = :deletedProduct');
  923.         $query->andWhere('po.deleted = :deletedProductOffer');
  924.         $query->setParameter('type'$type);
  925.         $query->setParameter('today'date('Y-m-d H:i:s'));
  926.         $query->setParameter('statusDraftProduct'ProductEnum::DRAFT);
  927.         $query->setParameter('statusPublicProductOffer'ProductOfferEnum::PUBLISHED);
  928.         $query->setParameter('deleted'CartEnum::ITEM_NO_DELETED);
  929.         $query->setParameter('deletedProduct'ProductEnum::ITEM_NO_DELETED);
  930.         $query->setParameter('deletedProductOffer'ProductEnum::ITEM_NO_DELETED);
  931.         return $query->getQuery()->execute();
  932.     }
  933.     public function getSplitRules(
  934.         array $productsUser 
  935.         $user
  936.         $amount
  937.         int $installments
  938.         int $paymentMethod
  939.         ?UserCard $userCard null
  940.         ?int $freeInstallments null,
  941.         ?bool $debug false
  942.     )
  943.     {
  944.         $paymentConfig $this->configuration->getPaymentConfig();
  945.         $installmentNumberInterest $paymentConfig->installmentNumberInterest;
  946.         $productOfferRepository $this->em->getRepository(ProductOffer::class);
  947.         $productTeamRepository $this->em->getRepository(ProductTeam::class);
  948.         $receiverRepository $this->em->getRepository(Receiver::class);
  949.         $pagarMeTransaction $this->generalService->getService(
  950.             'PagarMe\\PagarMeTransaction'
  951.         );
  952.         
  953.         $receiverIdEAD $pagarMeTransaction->getReceiverIdEAD();
  954.         $numberItems count($products);
  955.         $splits = [];
  956.         $splitsUser = [];
  957.         $amountTotal $amount 100;
  958.         $amountOrigin $amount 100;
  959.         $transactionService $this->generalService->getService(
  960.             'Transaction\\TransactionService'
  961.         );
  962.         $checkoutAmountsEAD $transactionService->getEADCheckoutAmount(
  963.             $amountTotal
  964.             $paymentMethod
  965.             $installments,
  966.             false,
  967.             $userCard
  968.         );
  969.         $rate $checkoutAmountsEAD->rate;
  970.         $fee $checkoutAmountsEAD->fee;
  971.         $amountTotal $checkoutAmountsEAD->amountTotalCents;
  972.         $amountEAD $checkoutAmountsEAD->amountEADCents;
  973.         if($rate && $numberItems 0){
  974.             $rate round$rate $numberItems2);
  975.         }
  976.         $splitEAD = (object)[
  977.             "recipient_id" => $receiverIdEAD,
  978.             "charge_processing_fee" => false,
  979.             "liable" => true,
  980.             "percentage" => null,
  981.             "amount" => (int)round($amountEAD),
  982.             "date_created" => date('Y-m-d H:i:s'),
  983.             "date_updated" => date('Y-m-d H:i:s')
  984.         ];
  985.         $discordService $this->generalService->getService('DiscordService');
  986.         $discordService->setChannel('debug');
  987.         
  988.         foreach ($products as $key => $item) {
  989.             if(!empty($item->cartId)){
  990.                 $cart $this->find($item->cartId);
  991.             }
  992.             $productTeams $productTeamRepository->findBy([
  993.                 "product" => $item->productId,
  994.                 "commission" => ProductTeamEnum::YES,
  995.                 "deleted" => ProductTeamEnum::ITEM_NO_DELETED
  996.             ]);
  997.             $productOffer $productOfferRepository->find($item->productOfferId);
  998.             $productAmount $item->amount;
  999.             
  1000.             if(empty($productAmount)){
  1001.                 $productOffer->getPriceReal();
  1002.             }
  1003.             if(empty($freeInstallments)){
  1004.                 $freeInstallments $productOfferRepository->getFreeInstallment(
  1005.                     $productOffer
  1006.                 );
  1007.             }
  1008.             if($paymentMethod != CartEnum::PAYMENT_CARD){
  1009.                 $freeInstallments 12;
  1010.                 $installments 1;
  1011.             }
  1012.             $pagarMeTransaction $this->generalService->getService(
  1013.                 'PagarMe\\PagarMeTransaction'
  1014.             );
  1015.             $productAmount $pagarMeTransaction->calculateInterest(
  1016.                 $productAmount,
  1017.                 (int)$installments
  1018.                 (int)$freeInstallments
  1019.             );
  1020.             $feeAmount $productAmount * ($fee 100) + $rate;
  1021.             $productAmount = ($productAmount $feeAmount);
  1022.             $productAmount round($productAmount2);
  1023.             foreach ($productTeams as $teamKey => $productTeam) {
  1024.                 if($productTeam->getCommission() == ProductTeamEnum::YES){
  1025.                     $receiver $receiverRepository->findOneBy([
  1026.                         "user" => $productTeam->getUser()->getId(),
  1027.                         "accountType" => ReceiverEnum::EAD_CHECKOUT,
  1028.                         "status" => ReceiverEnum::ACTIVE,
  1029.                         "type" => ReceiverEnum::EMPLOYEE,
  1030.                         "deleted" => ReceiverEnum::ITEM_NO_DELETED
  1031.                     ]);
  1032.                     if($receiver){
  1033.                         $teamAmount $productAmount * ( $productTeam->getPercent() / 100 );
  1034.                         
  1035.                         $teamAmount round($teamAmount2);
  1036.                         $teamAmountCents ceil($teamAmount 100);
  1037.                         $splitTeam = (object)[
  1038.                             "recipient_id" => $receiver->getReceiverHash(),
  1039.                             "charge_processing_fee" => false,
  1040.                             "liable" => true,
  1041.                             "percentage" => null,
  1042.                             "amount" => (int)$teamAmountCents,
  1043.                             "date_created" => date('Y-m-d H:i:s'),
  1044.                             "date_updated" => date('Y-m-d H:i:s')
  1045.                         ];
  1046.                         $amountTotal $amountTotal $teamAmountCents;
  1047.                         $splitsUser[] = $splitTeam;
  1048.                     }
  1049.                 }
  1050.             }
  1051.         }
  1052.         //remover iguais
  1053.         $ignore = [];
  1054.         foreach ($splitsUser as $splitsKey => $split) {
  1055.             foreach ($splitsUser as $splitsKey2 => $split2) {
  1056.                 if(
  1057.                     $split->recipient_id == $split2->recipient_id && 
  1058.                     $splitsKey != $splitsKey2
  1059.                 ){
  1060.                     $split->amount $split->amount $split2->amount;
  1061.                 }
  1062.             }
  1063.             if(!in_array($split->recipient_id$ignore)){
  1064.                 $splits[] = $split;
  1065.                 $ignore[] = $split->recipient_id;
  1066.             }
  1067.         }
  1068.         $receiverSchool $this->configuration->getReceiverSchool(
  1069.             ReceiverEnum::EAD_CHECKOUT,
  1070.             $debug
  1071.         );
  1072.         if(!$receiverSchool){
  1073.             if($debug){
  1074.                 $discordService->setMessage("Not found receiver");
  1075.                 $discordService->sendDiscord();
  1076.             }
  1077.             return [];
  1078.         }
  1079.         $splitAdmin = (object)[
  1080.             "recipient_id" => $receiverSchool->getReceiverHash(),
  1081.             "charge_processing_fee" => true,
  1082.             "liable" => true,
  1083.             "percentage" => null,
  1084.             "amount" => (int)round($amountTotal),
  1085.             "date_created" => date('Y-m-d H:i:s'),
  1086.             "date_updated" => date('Y-m-d H:i:s')
  1087.         ];
  1088.         $splits[] = $splitEAD;
  1089.         $splits[] = $splitAdmin;
  1090.         if($debug){
  1091.             $discordService->setMessage(json_encode($splits));
  1092.             $discordService->sendDiscord();
  1093.         }
  1094.         return $splits;
  1095.     }
  1096.     public function applyCouponUserCart($couponKey, ?User $user null
  1097.                                         ?string $hashIdentify null)
  1098.     {
  1099.         if(empty($user) && empty($hashIdentify)){
  1100.             return false;
  1101.         }
  1102.         $productRepository $this->em->getRepository(Product::class);
  1103.         $productCouponRepository $this->em->getRepository(ProductCoupon::class);
  1104.         $productCoupons $productCouponRepository->findValidProductCoupon($couponKey);
  1105.         if(empty($productCoupons)){
  1106.             return false;
  1107.         }
  1108.         $enrollmentService $this->generalService->getService('EnrollmentService');
  1109.         $filter = [ 
  1110.             "deleted" => ProductCouponEnum::ITEM_NO_DELETED
  1111.         ];
  1112.         if($user){
  1113.             $filter["user"] = $user;
  1114.         }else if(!empty($hashIdentify)){
  1115.             $filter["hashIdentify"] = $hashIdentify;
  1116.         }
  1117.         $carts $this->findBy($filter);
  1118.         $apply false;
  1119.         foreach ($productCoupons as $key => $productCoupon) {
  1120.             $couponType $productCoupon->getType();
  1121.             $all $productCoupon->getAll();
  1122.             $discountType $productCoupon->getDiscountType();
  1123.             $discount $productCoupon->getDiscount();
  1124.             $applyOfferType $productCoupon->getApplyOfferType();
  1125.             $public $productCoupon->getPublic();
  1126.             if($public == ProductCouponEnum::YES){
  1127.                 $applyOfferType ProductCouponEnum::OFFER_DEFAULT;
  1128.             }
  1129.             $is100 = ($discountType == ProductCouponEnum::PERCENTAGE && $discount >= 100);
  1130.             $usageNumber $productCoupon->getUsageNumber();
  1131.             if($productCoupon->getApplyMembershipFee() == ProductCouponEnum::YES){
  1132.                 if(!empty($carts)){
  1133.                     foreach ($carts as $keyCart => $cart) {
  1134.                         $product $cart->getProduct();
  1135.                         $productOffer $cart->getProductOffer();
  1136.                         $default $productOffer->getDefault();
  1137.                         $amount $productOffer->getMembershipFee();
  1138.                         $amount $productCouponRepository->applyDiscount(
  1139.                             $productCoupon
  1140.                             $amount
  1141.                         );
  1142.                         if($couponType == ProductCouponEnum::CATEGORY){
  1143.                             if($default == ProductCouponEnum::YES){
  1144.                                 $hasCategory $product->getCategory()->contains(
  1145.                                     $productCoupon->getCategory()
  1146.                                 );
  1147.                                 if($hasCategory){
  1148.                                     $apply true;
  1149.                                     $cart->setMembershipFee($amount);
  1150.                                     $cart->setPrice($productOffer->getPriceReal());
  1151.                                     $cart->setProductCoupon($productCoupon);
  1152.                                 }
  1153.                             }
  1154.                         }else if(
  1155.                             $couponType == $product->getType() &&
  1156.                             (
  1157.                                 $all == ProductCouponEnum::YES ||
  1158.                                 (
  1159.                                     $productCoupon->getProduct() && 
  1160.                                     $product->getId() == $productCoupon->getProduct()->getId()
  1161.                                 )
  1162.                             )
  1163.                         ){
  1164.                             if(
  1165.                                 $applyOfferType == ProductCouponEnum::OFFER_ALL ||
  1166.                                 (
  1167.                                     $applyOfferType == ProductCouponEnum::OFFER_DEFAULT && 
  1168.                                     $default == ProductCouponEnum::YES
  1169.                                 ) ||
  1170.                                 (
  1171.                                     $applyOfferType == ProductCouponEnum::OFFER_CUSTOM && 
  1172.                                     $productCoupon->getProductOffer()->contains($productOffer)
  1173.                                 )
  1174.                             ){
  1175.                                 $apply true;
  1176.                                 $cart->setMembershipFee($amount);
  1177.                                 $cart->setPrice($productOffer->getPriceReal());
  1178.                                 $cart->setProductCoupon($productCoupon);
  1179.                             }
  1180.                         }
  1181.                     }
  1182.                 }
  1183.             }else{
  1184.                 if($all == ProductCouponEnum::YES && $is100 && $user){
  1185.                     if($couponType != ProductCouponEnum::SUBSCRIPTION){
  1186.                         $apply true;
  1187.                         $usageNumber $usageNumber 1;
  1188.                         $products $productRepository->getAllPublicByType($couponType);
  1189.                         foreach ($products as $keyProduct => $product){
  1190.                             $enrollmentService->setOrigin(EnrollmentEnum::ORIGIN_COUPOM);
  1191.                             $enrollmentService->setCouponKey($couponKey);
  1192.                             $enrollmentService->enrollUserByProduct(
  1193.                                 $user,
  1194.                                 $product
  1195.                             );
  1196.                         }
  1197.                     }
  1198.                 }else if(!empty($carts)){
  1199.                     foreach ($carts as $keyCart => $cart) {
  1200.                         $product $cart->getProduct();
  1201.                         $productOffer $cart->getProductOffer();
  1202.                         $default $productOffer->getDefault();
  1203.                         if($couponType == ProductCouponEnum::CATEGORY){
  1204.                             if($default == ProductCouponEnum::YES){
  1205.                                 $hasCategory $product->getCategory()->contains(
  1206.                                     $productCoupon->getCategory()
  1207.                                 );
  1208.                                 if ($hasCategory){
  1209.                                     $amount $productOffer->getPriceReal();
  1210.                                     $amount $productCouponRepository->applyDiscount(
  1211.                                         $productCoupon
  1212.                                         $amount
  1213.                                     );
  1214.                                     if($amount 0){
  1215.                                         $apply true;
  1216.                                         $cart->setPrice($amount);
  1217.                                         $cart->setProductCoupon($productCoupon);
  1218.                                     }else if(
  1219.                                         $product->getType() != ProductCouponEnum::SUBSCRIPTION &&
  1220.                                         $productOffer->getAllowRecurrency() == ProductEnum::NO
  1221.                                     ){
  1222.                                         if($user){
  1223.                                             $apply true;
  1224.                                             $usageNumber $usageNumber 1;
  1225.                                             $enrollmentService->setOrigin(
  1226.                                                 EnrollmentEnum::ORIGIN_COUPOM
  1227.                                             );
  1228.                                             $enrollmentService->setCouponKey($couponKey);
  1229.                                             $enrollmentService->enrollUserByProduct(
  1230.                                                 $user,
  1231.                                                 $product,
  1232.                                                 (
  1233.                                                     $product->isTypeResource() ? 
  1234.                                                     $cart->getCourse() : 
  1235.                                                     null
  1236.                                                 )
  1237.                                             );
  1238.                                         }else{
  1239.                                             $apply true;
  1240.                                             $cart->setPrice($amount);
  1241.                                             $cart->setProductCoupon($productCoupon);
  1242.                                         }
  1243.                                     }
  1244.                                 }
  1245.                             }
  1246.                         }else if(
  1247.                             $couponType == $product->getType() &&
  1248.                             (
  1249.                                 $all == ProductCouponEnum::YES ||
  1250.                                 (
  1251.                                     $productCoupon->getProduct() && 
  1252.                                     $product->getId() == $productCoupon->getProduct()->getId()
  1253.                                 )
  1254.                             )
  1255.                         ){
  1256.                             if(
  1257.                                 $applyOfferType == ProductCouponEnum::OFFER_ALL ||
  1258.                                 (
  1259.                                     $applyOfferType == ProductCouponEnum::OFFER_DEFAULT && 
  1260.                                     $default == ProductCouponEnum::YES
  1261.                                 ) ||
  1262.                                 (
  1263.                                     $applyOfferType == ProductCouponEnum::OFFER_CUSTOM && 
  1264.                                     $productCoupon->getProductOffer()->contains($productOffer)
  1265.                                 )
  1266.                             ){
  1267.                                 $amount $productOffer->getPriceReal();
  1268.                                 $amount $productCouponRepository->applyDiscount(
  1269.                                     $productCoupon
  1270.                                     $amount
  1271.                                 );
  1272.                                 if($amount 0){
  1273.                                     $apply true;
  1274.                                     $cart->setPrice($amount);
  1275.                                     $cart->setProductCoupon($productCoupon);
  1276.                                 }else if(
  1277.                                     $couponType != ProductCouponEnum::SUBSCRIPTION && 
  1278.                                     $productOffer->getAllowRecurrency() == ProductEnum::NO
  1279.                                 ){
  1280.                                     if($user){
  1281.                                         $apply true;
  1282.                                         $usageNumber $usageNumber 1;
  1283.                                         $enrollmentService->setOrigin(
  1284.                                             EnrollmentEnum::ORIGIN_COUPOM
  1285.                                         );
  1286.                                         $enrollmentService->setCouponKey($couponKey);
  1287.                                         $enrollmentService->enrollUserByProduct(
  1288.                                             $user
  1289.                                             $product,
  1290.                                             (
  1291.                                                 $product->isTypeResource() ? 
  1292.                                                 $cart->getCourse() : 
  1293.                                                 null
  1294.                                             )
  1295.                                         );
  1296.                                     }else{
  1297.                                         $apply true;
  1298.                                         $cart->setPrice($amount);
  1299.                                         $cart->setProductCoupon($productCoupon);
  1300.                                     }
  1301.                                 }
  1302.                             }
  1303.                         }
  1304.                     }
  1305.                 }
  1306.             }
  1307.             $productCoupon->setUsageNumber($usageNumber);
  1308.         }
  1309.         $this->em->flush();
  1310.         return $apply;
  1311.     }
  1312.     public function resetCartsByProductOffer(ProductOffer $productOffer)
  1313.     {
  1314.         $carts $this->findBy([ "productOffer" => $productOffer->getId() ]);
  1315.         foreach ($carts as $key => $cart) {
  1316.             $cart->setProductCoupon(null);
  1317.             $cart->setProductSuggestion(null);
  1318.             $cart->setPrice($productOffer->getPriceReal());
  1319.         }
  1320.         $this->em->flush();
  1321.     }
  1322.     public function getCartsWithProductCoupon(?int $userId null
  1323.                                               ?string $hashIdentify null)
  1324.     {
  1325.         $query $this->createQueryBuilder('c');
  1326.         $query->innerJoin(
  1327.             'EADPlataforma:ProductCoupon'
  1328.             'pc'
  1329.             'WITH'
  1330.             'pc.id = c.productCoupon'
  1331.         );
  1332.         if(!empty($userId)){
  1333.             $query->andWhere('c.user = :userId');
  1334.             $query->setParameter('userId'$userId);
  1335.         }else if(!empty($hashIdentify)){
  1336.             $query->andWhere('c.hashIdentify = :hashIdentify');
  1337.             $query->setParameter('hashIdentify'$hashIdentify);
  1338.         }
  1339.         return $query->getQuery()->execute();
  1340.     }
  1341.     public function updateCartsWithProductCouponExpired(?int $userId null,
  1342.                                                         ?string $hashIdentify null)
  1343.     {
  1344.         $carts $this->getCartsWithProductCoupon($userId$hashIdentify);
  1345.         $today strtotime("now");
  1346.         foreach ($carts as $key => $cart) {
  1347.             $product $cart->getProduct();
  1348.             $productOffer $cart->getProductOffer();
  1349.             $productCoupon $cart->getProductCoupon();
  1350.             $update false;
  1351.             if($productCoupon){
  1352.                 $dateStart strtotime($productCoupon->getDateStart());
  1353.                 $dateEnd strtotime($productCoupon->getDateEnd());
  1354.                 if($productCoupon->getUsageNumber() >= $productCoupon->getQuantity()){
  1355.                     $update true;
  1356.                 }else if($today $dateEnd || $today $dateStart){
  1357.                     $update true;
  1358.                 }
  1359.             }
  1360.             if($update){
  1361.                 $cart->setProductCoupon(null);
  1362.                 $cart->setProductSuggestion(null);
  1363.                 $cart->setPrice($productOffer->getPriceReal());
  1364.                 if(
  1365.                     $product->getType() == ProductEnum::SUBSCRIPTION || 
  1366.                     $productOffer->getAllowRecurrency() == ProductEnum::YES
  1367.                 ){
  1368.                     $cart->setMembershipFee($productOffer->getMembershipFee());
  1369.                 }
  1370.             }
  1371.         }
  1372.         $this->em->flush();
  1373.     }
  1374.     public function getCartsWait($type)
  1375.     {
  1376.         $query $this->createQueryBuilder('c');
  1377.         $query->innerJoin('EADPlataforma:Product''p''WITH''p.id = c.product');
  1378.         
  1379.         $query->innerJoin(
  1380.             'EADPlataforma:ProductOffer'
  1381.             'po'
  1382.             'WITH'
  1383.             'po.id = c.productOffer'
  1384.         );
  1385.         $query->innerJoin('EADPlataforma:User''u''WITH''u.id = c.user');
  1386.         $query->andWhere('po.notForSale = :no');
  1387.         $query->setParameter('no'ProductOfferEnum::NO);
  1388.         $query->andWhere('po.status = :statusPublicProductOffer');
  1389.         $query->andWhere('po.deleted = :deletedProductOffer');
  1390.         $query->setParameter('deletedProductOffer'ProductEnum::ITEM_NO_DELETED);
  1391.         $query->setParameter('statusPublicProductOffer'ProductOfferEnum::PUBLISHED);
  1392.         $query->andWhere('u.deleted = :deleted');
  1393.         $query->andWhere('u.status != :status');
  1394.         $query->andWhere('u.allowNotifyCart = :notify');
  1395.         $query->andWhere('c.type = :type');
  1396.         $query->setParameter('deleted'UserEnum::ITEM_NO_DELETED);
  1397.         $query->setParameter('status'UserEnum::BLOCK);
  1398.         $query->setParameter('notify'UserEnum::YES);
  1399.         $query->setParameter('type',  $type);
  1400.         $query->addOrderBy('c.user''ASC');
  1401.         return $query->getQuery()->execute();
  1402.     }
  1403.     public function alertCheckoutWait(){
  1404.         $emailService $this->generalService->getService('EmailService');
  1405.         $numberUtil $this->generalService->getUtil('NumberUtil');
  1406.         $webhookService $this->generalService->getService('WebhookService');
  1407.         $client $this->configuration->getClient();
  1408.         $carts $this->getCartsWait(CartEnum::CHECKOUT);
  1409.         $today date('Y-m-d');
  1410.         $auxId null;
  1411.         $auxValue null;
  1412.         $auxEmail null;
  1413.         $auxName null;
  1414.         $itemsHtml '';
  1415.         $auxLinkCheckout '';
  1416.         foreach ($carts as $key => $cart) {
  1417.             $product $cart->getProduct();
  1418.             $productOffer $cart->getProductOffer();
  1419.             $user $cart->getUser();
  1420.             if(!$emailService->checkUserToSend($user)){
  1421.                 continue;
  1422.             }
  1423.             if(!$productOffer){
  1424.                 continue;
  1425.             }
  1426.             if(!$product){
  1427.                 continue;
  1428.             }
  1429.             if($product->getStatus() == ProductEnum::DRAFT){
  1430.                 continue;
  1431.             }
  1432.             $oneDay date('Y-m-d'strtotime($cart->getDate() . ' + 1 day '));
  1433.             $threeDay date('Y-m-d'strtotime($cart->getDate() . ' + 3 day '));
  1434.             $sevenDay date('Y-m-d'strtotime($cart->getDate() . ' + 7 day '));
  1435.             if($oneDay != $today && $threeDay != $today && $sevenDay != $today){
  1436.                 continue;
  1437.             }
  1438.                 
  1439.             $auxId $user->getId();
  1440.             $auxValue $auxValue $cart->getPrice();
  1441.             $auxEmail $user->getEmail();
  1442.             $auxName $user->getName();
  1443.             $domainClient $client->getDomainPrimary();
  1444.             $domainClient "https://{$domainClient}";
  1445.             $linkCheckout "{$domainClient}/cart/add/{$productOffer->getId()}";
  1446.             $linkStop "{$domainClient}/stopNotification/{$user->getHashIdentify()}";
  1447.             if($user->getId() != $auxId && $auxId 0){
  1448.                 //$auxValue = number_format($auxValue, 2, ',', '.');
  1449.                 $auxValue $numberUtil->currencyFormat($auxValue);
  1450.                 $emailService->setToEmail($auxEmail);
  1451.                 $emailService->setToName($auxName);
  1452.                 $subText $this->configuration->getLanguage(
  1453.                     'remember_cart.subject''email'
  1454.                 );
  1455.                 $subject "{$subText}{$client->getBrand()}?";
  1456.                 $emailService->setSubject($subject);
  1457.                 $emailService->setData([
  1458.                     "userName" => $auxName,
  1459.                     "text2" => "{$subText}?",
  1460.                     "status" => '',
  1461.                     "code" => '',
  1462.                     "moeda" => "R$",
  1463.                     "itens" => $itemsHtml,
  1464.                     "value" => $auxValue,
  1465.                     "btnLink" => $linkCheckout,
  1466.                     "urlDisableNot" => $linkStop,
  1467.                     "year" => date('Y')
  1468.                 ]);
  1469.                 $emailService->setTemplateBody("remember_cart");
  1470.                 $emailService->send();
  1471.                 $itemsHtml '';
  1472.                 $auxValue null;
  1473.             }
  1474.             
  1475.             $todayTime strtotime(date('Y-m-d H:i:s'));
  1476.             $dateStart strtotime($productOffer->getSaleDateStart());
  1477.             $dateClose strtotime($productOffer->getSaleDateClose());
  1478.             if($todayTime $dateClose || $todayTime $dateStart){
  1479.                 continue;
  1480.             }
  1481.             
  1482.             $itemName $product->getTitle();
  1483.             if(!empty($itemName)){
  1484.                 $itemName htmlentities($itemName);
  1485.                 $itemsHtml .= "
  1486.                     <tr style='margin:0px;border:1px solid rgb(238,238,238)'>
  1487.                         <td style='padding:5px 0px 5px 15px;border:1px solid rgb(238,238,238)'>
  1488.                             <p style='margin:0px;font-size:0.9em;color:rgb(102,102,102);line-height:1.2em'>{$itemName}</p>
  1489.                         </td>
  1490.                     </tr>";
  1491.             }
  1492.             #last
  1493.             if(($key 1) == count($carts)){
  1494.                 $auxValue $numberUtil->currencyFormat($auxValue);
  1495.                 $emailService->setToEmail($auxEmail);
  1496.                 $emailService->setToName($auxName);
  1497.                 
  1498.                 $subText $this->configuration->getLanguage(
  1499.                     'remember_cart.subject''email'
  1500.                 );
  1501.                 
  1502.                 $subject "{$subText}{$client->getBrand()}?";
  1503.                 $emailService->setSubject($subject);
  1504.                 $emailService->setData([
  1505.                     "userName" => $auxName,
  1506.                     "text2" => "{$subText}?",
  1507.                     "status" => '',
  1508.                     "code" => '',
  1509.                     "moeda" => "R$",
  1510.                     "itens" => $itemsHtml,
  1511.                     "value" => $auxValue,
  1512.                     "btnLink" => $linkCheckout,
  1513.                     "urlDisableNot" => $linkStop,
  1514.                     "year" => date('Y')
  1515.                 ]);
  1516.                 $emailService->setTemplateBody("remember_cart");
  1517.                 $emailService->send();
  1518.                 $itemsHtml '';
  1519.             }
  1520.             $userWebhook $this->em->getRepository(User::class)->getToWebhook($user);
  1521.             //webhook
  1522.             $dataObj = (object)[
  1523.                 "customer" => $userWebhook,
  1524.                 "products" => [
  1525.                     [
  1526.                         "id" => $product->getId(),
  1527.                         "offer_id" => $productOffer->getId(),
  1528.                         "name" => $product->getTitle(),
  1529.                         "original_price" => $productOffer->getPriceReal(),
  1530.                         "price" => $productOffer->getPriceDisplay(),
  1531.                         "coupon" => null,
  1532.                         "type" => $product->getType(),
  1533.                         "nfe" => "0"
  1534.                     ]
  1535.                 ],
  1536.             ];
  1537.             $webhookService->addItemList(WebhookEnum::CART$dataObj);
  1538.         }
  1539.         return;
  1540.     }
  1541.     public function alertCartWait(){
  1542.         $emailService $this->generalService->getService('EmailService');
  1543.         $numberUtil $this->generalService->getUtil('NumberUtil');
  1544.         $webhookService $this->generalService->getService('WebhookService');
  1545.         $client $this->configuration->getClient();
  1546.         $carts $this->getCartsWait(CartEnum::CART);
  1547.         $today date('Y-m-d');
  1548.         $auxId null;
  1549.         $auxValue null;
  1550.         $auxEmail null;
  1551.         $auxName null;
  1552.         $itemsHtml '';
  1553.         $auxLinkCheckout '';
  1554.         foreach ($carts as $key => $cart) {
  1555.             $product $cart->getProduct();
  1556.             $productOffer $cart->getProductOffer();
  1557.             $user $cart->getUser();
  1558.             if(!$emailService->checkUserToSend($user)){
  1559.                 continue;
  1560.             }
  1561.             if(!$productOffer){
  1562.                 continue;
  1563.             }
  1564.             if(!$product){
  1565.                 continue;
  1566.             }
  1567.             if($product->getStatus() == ProductEnum::DRAFT){
  1568.                 continue;
  1569.             }
  1570.             $oneDay date('Y-m-d'strtotime($cart->getDate() . ' + 1 day '));
  1571.             $threeDay date('Y-m-d'strtotime($cart->getDate() . ' + 3 day '));
  1572.             $sevenDay date('Y-m-d'strtotime($cart->getDate() . ' + 7 day '));
  1573.             if($oneDay != $today && $threeDay != $today && $sevenDay != $today){
  1574.                 continue;
  1575.             }
  1576.                 
  1577.             $auxId $user->getId();
  1578.             $auxValue $auxValue $cart->getPrice();
  1579.             $auxEmail $user->getEmail();
  1580.             $auxName $user->getName();
  1581.             $domainClient $client->getDomainPrimary();
  1582.             $domainClient "https://{$domainClient}";
  1583.             $linkCheckout "{$domainClient}/cart/add/{$productOffer->getId()}";
  1584.             $linkStop "{$domainClient}/stopNotification/{$user->getHashIdentify()}";
  1585.             if($user->getId() != $auxId && $auxId 0){
  1586.                 //$auxValue = number_format($auxValue, 2, ',', '.');
  1587.                 $auxValue $numberUtil->currencyFormat($auxValue);
  1588.                 $emailService->setToEmail($auxEmail);
  1589.                 $emailService->setToName($auxName);
  1590.                 $subText $this->configuration->getLanguage(
  1591.                     'remember_cart.subject''email'
  1592.                 );
  1593.                 $subject "{$subText}{$client->getBrand()}?";
  1594.                 $emailService->setSubject($subject);
  1595.                 $emailService->setData([
  1596.                     "userName" => $auxName,
  1597.                     "text2" => "{$subText}?",
  1598.                     "status" => '',
  1599.                     "code" => '',
  1600.                     "moeda" => "R$",
  1601.                     "itens" => $itemsHtml,
  1602.                     "value" => $auxValue,
  1603.                     "btnLink" => $linkCheckout,
  1604.                     "urlDisableNot" => $linkStop,
  1605.                     "year" => date('Y')
  1606.                 ]);
  1607.                 $emailService->setTemplateBody("remember_cart");
  1608.                 $emailService->send();
  1609.                 $itemsHtml '';
  1610.                 $auxValue null;
  1611.             }
  1612.             
  1613.             $todayTime strtotime(date('Y-m-d H:i:s'));
  1614.             $dateStart strtotime($productOffer->getSaleDateStart());
  1615.             $dateClose strtotime($productOffer->getSaleDateClose());
  1616.             if($todayTime $dateClose || $todayTime $dateStart){
  1617.                 continue;
  1618.             }
  1619.             $itemName $product->getTitle();
  1620.             if(!empty($itemName)){
  1621.                 $itemName htmlentities($itemName);
  1622.                 $itemsHtml .= "
  1623.                     <tr style='margin:0px;border:1px solid rgb(238,238,238)'>
  1624.                         <td style='padding:5px 0px 5px 15px;border:1px solid rgb(238,238,238)'>
  1625.                             <p style='margin:0px;font-size:0.9em;color:rgb(102,102,102);line-height:1.2em'>{$itemName}</p>
  1626.                         </td>
  1627.                     </tr>";
  1628.             }
  1629.             #last
  1630.             if(($key 1) == count($carts)){
  1631.                 $auxValue $numberUtil->currencyFormat($auxValue);
  1632.                 $emailService->setToEmail($auxEmail);
  1633.                 $emailService->setToName($auxName);
  1634.                 
  1635.                 $subText $this->configuration->getLanguage(
  1636.                     'remember_cart.subject''email'
  1637.                 );
  1638.                 
  1639.                 $subject "{$subText}{$client->getBrand()}?";
  1640.                 $emailService->setSubject($subject);
  1641.                 $emailService->setData([
  1642.                     "userName" => $auxName,
  1643.                     "text2" => "{$subText}?",
  1644.                     "status" => '',
  1645.                     "code" => '',
  1646.                     "moeda" => "R$",
  1647.                     "itens" => $itemsHtml,
  1648.                     "value" => $auxValue,
  1649.                     "btnLink" => $linkCheckout,
  1650.                     "urlDisableNot" => $linkStop,
  1651.                     "year" => date('Y')
  1652.                 ]);
  1653.                 $emailService->setTemplateBody("remember_cart");
  1654.                 $emailService->send();
  1655.                 $itemsHtml '';
  1656.             }
  1657.             $userWebhook $this->em->getRepository(User::class)->getToWebhook($user);
  1658.             
  1659.             //webhook
  1660.             $dataObj = (object)[
  1661.                 "customer" => $userWebhook,
  1662.                 "products" => [
  1663.                     [
  1664.                         "id" => $product->getId(),
  1665.                         "offer_id" => $productOffer->getId(),
  1666.                         "name" => $product->getTitle(),
  1667.                         "original_price" => $productOffer->getPriceReal(),
  1668.                         "price" => $productOffer->getPriceDisplay(),
  1669.                         "coupon" => null,
  1670.                         "type" => $product->getType(),
  1671.                         "nfe" => "0"
  1672.                     ]
  1673.                 ],
  1674.             ];
  1675.             $webhookService->addItemList(WebhookEnum::CART$dataObj);
  1676.         }
  1677.         return;
  1678.     }
  1679.     public function deleteByUser(int $userId$deleted)
  1680.     {
  1681.         $sql "UPDATE EADPlataforma:Cart AS c 
  1682.                 SET c.deleted = :deleted WHERE c.user = :userId";
  1683.         $query $this->em->createQuery($sql);
  1684.         $query->setParameter('userId'$userId);
  1685.         $query->setParameter('deleted'$deleted);
  1686.         $query->execute();
  1687.         
  1688.         return true;
  1689.     }
  1690. }