src/Service/Cart/Cart.php line 506

Open in your IDE?
  1. <?php
  2. namespace App\Service\Cart;
  3. use App\Env;
  4. use App\DTO\AppDTO;
  5. use App\DTO\CartDTO;
  6. use App\Entity\Prod;
  7. use App\Model\ProdColor;
  8. use App\Service\Auth\Auth;
  9. use App\ValueObject\Money;
  10. use App\Entity\CartUnsaved;
  11. use App\Entity\Cart as EntityCart;
  12. use App\Repository\CartRepository;
  13. use App\Repository\ProdRepository;
  14. use App\Service\Discount\NumDiscount;
  15. use App\Service\Discount\SumDiscount;
  16. use App\Service\Discount\UserDiscount;
  17. use Doctrine\ORM\EntityManagerInterface;
  18. use App\Repository\CartUnsavedRepository;
  19. use Symfony\Component\Security\Core\Security;
  20. use Symfony\Component\HttpFoundation\RequestStack;
  21. use Symfony\Component\HttpFoundation\Session\Session;
  22. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  23. class Cart
  24. {
  25.     protected EntityManagerInterface $em;
  26.     protected AppDTO $app;
  27.     protected Auth $Auth;
  28.     protected SessionInterface $Session;
  29.     protected ProdColor $prodColor;
  30.     protected RequestStack $rs;
  31.     protected $cart;
  32.     protected $prods_limited = [];
  33.     protected $order_id;
  34.     protected NumDiscount $NumDiscount;
  35.     protected SumDiscount $SumDiscount;
  36.     protected UserDiscount $UserDiscount;
  37.     //Repository
  38.     protected ProdRepository $Prods;
  39.     protected CartUnsavedRepository $CartUnsaved;
  40.     protected CartRepository $Carts;
  41.     public function __construct(EntityManagerInterface $emAppDTO $appAuth $AuthNumDiscount $NumDiscountSumDiscount $SumDiscountUserDiscount $UserDiscountProdColor $prodColorRequestStack $rsSecurity $security)
  42.     {
  43.         $this->em $em;
  44.         $this->app $app;
  45.         $this->Auth $Auth;
  46.         $this->Auth->setUser($security->getUser());
  47.         $this->prodColor $prodColor;
  48.         $this->rs $rs;
  49.         $this->Session $rs->getSession();
  50.         $this->Prods $this->em->getRepository(Prod::class);
  51.         $this->CartUnsaved $this->em->getRepository(CartUnsaved::class);
  52.         $this->Carts $this->em->getRepository(EntityCart::class);
  53.         $this->NumDiscount $NumDiscount;
  54.         $this->SumDiscount $SumDiscount;
  55.         $this->UserDiscount $UserDiscount;
  56.         $this->cart $this->Session->get('cart');
  57.         
  58.         if (empty($this->cart)) {
  59.             $this->cart = [];
  60.         }
  61.         if (empty($this->cart)) {
  62.             $this->load_session();
  63.         }
  64.         $this->recount();
  65.         $this->flush();
  66.     }
  67.     public function getCart(): array
  68.     {
  69.         $deleted 0;
  70.         foreach ($this->cart as $k => $v) {
  71.             $prod $this->Prods->find($v['id']);
  72.             if ($prod == null) {
  73.                 $deleted 1;
  74.                 unset ($this->cart[$k]);
  75.             }
  76.         }
  77.         if ($deleted) {
  78.             $this->save_session();
  79.             $this->flush();
  80.         }
  81.         return $this->cart;
  82.     }
  83.     public function isFreeDelivery(float $free_delivery_min): bool
  84.     {
  85.         $freedelivery false;
  86.         if ($this->getAmount() >= $free_delivery_min && !$this->Auth->isOpt()) {
  87.             $freedelivery true;
  88.         }
  89.         return $freedelivery;
  90.     }
  91.     public function getDeliveryIndicatorData(float $free_delivery_min): array
  92.     {
  93.         $percent round($this->getAmount()/$free_delivery_min*100);
  94.         $percent 100 $percent 100 null;
  95.         $remainder $free_delivery_min $this->getAmount();
  96.         $remainder $remainder null;
  97.         $data = [
  98.             'freedelivery' => $this->isFreeDelivery($free_delivery_min),
  99.             'freedelivery_min' => $free_delivery_min,
  100.             'amount' => $this->getAmount(),
  101.             'remainder' => round($remainderEnv::price_precission()),
  102.             'percent' => $percent,
  103.         ];
  104.         return $data;
  105.     }
  106.     public function getFromOrder(int $order_id): array
  107.     {
  108.         $Prods $this->em->getRepository(Prod::class);
  109.         $cart $this->loadFromOrder2($order_id);
  110.         // $cart = $this->getCart();
  111.         if (empty($cart)) {
  112.             return [];
  113.         }
  114.         
  115.         foreach ($cart as $k => $v) {
  116.             $cart[$k]['prod'] = $Prods->find($v['id']);
  117.         }
  118.         
  119.         return $cart;
  120.     }
  121.     public function loadFromOrder(int $order_id)
  122.     {
  123.         $this->order_id $order_id;
  124.         /** @var \App\Entity\Cart[] $prods */
  125.         $prods $this->em->createQuery("SELECT c FROM App\Entity\Cart c WHERE c.order_id = ".$order_id)->getResult();
  126.                 
  127.         foreach($prods as $prod) {
  128.             $this->cart[$this->getCartId($prod->getProd()->getId(), 0)] = [
  129.                 'cid' => $prod->getId(),
  130.                 'id' => $prod->getProd()->getId(),
  131.                 'var' => $prod->getVar(),
  132.                 'num' => $prod->getNum(),
  133.                 'baseprice' => (new Money($prod->getPrice()))->getAmount(),
  134.                 'price' => 0,
  135.                 'skidka' => $prod->getSkidka(),
  136.                 'numdiscount' => $prod->getNumdiscount(),
  137.                 'userdiscount' => $prod->getUserdiscount(),
  138.             ];
  139.         }
  140.         $this->cart $this->recount($this->cart);
  141.         $this->flush();
  142.     }
  143.     public function loadFromOrder2(int $order_id)
  144.     {
  145.         $cart = [];
  146.         $this->order_id $order_id;
  147.         /** @var \App\Entity\Cart[] $prods */
  148.         $prods $this->em->createQuery("SELECT c FROM App\Entity\Cart c WHERE c.order_id = ".$order_id)->getResult();
  149.                 
  150.         foreach($prods as $prod) {
  151.             if ($prod->getProd() == null) {
  152.                 continue;
  153.             }
  154.             $cart[$this->getCartId($prod->getProd()->getId(), 0)] = [
  155.                 'cid' => $prod->getId(),
  156.                 'id' => $prod->getProd()->getId(),
  157.                 'var' => $prod->getVar(),
  158.                 'num' => $prod->getNum(),
  159.                 'baseprice' => (new Money($prod->getPrice()))->getAmount(),
  160.                 'price' => (new Money($prod->getPrice()))->getAmount(),
  161.                 'skidka' => $prod->getSkidka(),
  162.                 'numdiscount' => $prod->getNumdiscount(),
  163.                 'userdiscount' => $prod->getUserdiscount(),
  164.             ];                       
  165.         }
  166.         $cart $this->recount($cart);
  167.         return $cart;
  168.     }
  169.     public function getCartId(int $prod_idint $var 0, array $chars = [], int $user_id 0) {
  170.         $id $prod_id."_".$var;
  171.             
  172.         if (!empty($chars)) {
  173.             ksort($chars);
  174.             $id .= "_".json_encode($chars);                
  175.         }
  176.             
  177.         if ($user_id) {
  178.             $id .= "_".$user_id;
  179.         }
  180.             
  181.         return md5($id);
  182.     }
  183.     public function addItem($id 0$var 0$num 1$price 0$skidka 0$numdiscount = [], $weight 0){
  184.         $cart_id $this->getCartId($id$var);
  185.             
  186.         if(isset($this->cart[$cart_id])){
  187.             $this->cart[$cart_id]['num'] += $num;
  188.             if($this->cart[$cart_id]['skidka'] == 0){
  189.                 $this->cart[$cart_id]['numdiscount'] = $this->NumDiscount->getDiscount($num$numdiscount);
  190.                 $this->cart[$cart_id]['userdiscount'] = $this->UserDiscount->getValue();
  191.             }else{
  192.                 $this->cart[$cart_id]['numdiscount'] = 0;
  193.                 $this->cart[$cart_id]['userdiscount'] = $this->UserDiscount->getValue();
  194.             }
  195.         }else{
  196.             $this->cart array_merge(
  197.                 [
  198.                     $cart_id => [
  199.                         'id'       => intval($id),
  200.                         'var'      => intval($var),
  201.                         'num'      => intval($num),
  202.                         'baseprice'=> floatval($price),
  203.                         'price'    => floatval($price),
  204.                         'skidka'   => floatval($skidka),
  205.                         'weight'   => floatval($weight),
  206.                     ]
  207.                 ],
  208.                 $this->cart
  209.             );
  210.             if($this->cart[$cart_id]['skidka'] == 0){
  211.                 $this->cart[$cart_id]['numdiscount'] = $this->NumDiscount->getDiscount($num$numdiscount);
  212.                 $this->cart[$cart_id]['userdiscount'] = $this->UserDiscount->getValue();
  213.             }else{
  214.                 $this->cart[$cart_id]['numdiscount'] = 0;
  215.                 $this->cart[$cart_id]['userdiscount'] = $this->UserDiscount->getValue();
  216.             }
  217.         }
  218.         $this->recount();
  219.         $this->save_session();
  220.         $this->flush();
  221.     }
  222.     public function updateItem($cart_id ''$num 0$numdiscount = []){
  223.         if($num == 0){
  224.             $prod $this->cart[$cart_id]['id'];
  225.             $prodvar $this->cart[$cart_id]['var'];
  226.             unset($this->cart[$cart_id]);
  227.         }else{
  228.             $this->cart[$cart_id]['num'] = intval($num);
  229.             if($this->order_id == 0) {
  230.                 if($this->cart[$cart_id]['skidka'] == 0){
  231.                     $this->cart[$cart_id]['numdiscount'] = $this->NumDiscount->getDiscount($num$numdiscount);
  232.                     $this->cart[$cart_id]['userdiscount'] = $this->UserDiscount->getValue();
  233.                 }else{
  234.                     $this->cart[$cart_id]['numdiscount'] = 0;
  235.                     $this->cart[$cart_id]['userdiscount'] = $this->UserDiscount->getValue();
  236.                 }
  237.             } else {
  238.                 if($this->cart[$cart_id]['skidka'] == 0){
  239.                     $this->cart[$cart_id]['numdiscount'] = $this->NumDiscount->getDiscount($num$numdiscount);
  240.                     $this->cart[$cart_id]['userdiscount'] = $this->UserDiscount->getValue();
  241.                 }else{
  242.                     $this->cart[$cart_id]['numdiscount'] = 0;
  243.                     $this->cart[$cart_id]['userdiscount'] = 0;
  244.                 }
  245.             }
  246.                 
  247.             $this->recount();
  248.             $prod intval($this->cart[$cart_id]['id']);
  249.             $prodvar intval($this->cart[$cart_id]['var']);
  250.         }
  251.         $this->save_session();
  252.         $this->flush();
  253.     }
  254.     public function deleteItem(string $cart_id)
  255.     {
  256.         $prod $this->cart[$cart_id]['id'];
  257.         $prodvar $this->cart[$cart_id]['var'];
  258.         unset($this->cart[$cart_id]);
  259.         $this->recount();
  260.         $this->save_session();
  261.         $this->flush();
  262.     }
  263.     public function deleteAll()
  264.     {
  265.         $this->cart = [];
  266.         $this->delete_session();
  267.         $this->flush();
  268.     }    
  269.     public function cart_id($prod 0$var 0$chars = array(), $user_id 0)
  270.     {
  271.         $this->getCartId($prod$var$chars$user_id);        
  272.     }
  273.                 
  274.     public function getAmount(): float
  275.     {
  276.         $amount 0;
  277.         foreach($this->cart as $k => $v)
  278.             $amount += round($v['price'], Env::price_precission(), PHP_ROUND_HALF_UP) * $v['num'];
  279.             
  280.         return $amount;
  281.     }
  282.     public function getBaseAmount(): float 
  283.     {
  284.         $amount 0;
  285.         foreach($this->cart as $k => $v)
  286.             $amount += round($v['baseprice'], Env::price_precission(), PHP_ROUND_HALF_UP) * $v['num'];
  287.             
  288.         return $amount;
  289.     }
  290.     public function getAmountWithoutDiscount()
  291.     {
  292.         $amount 0;
  293.             
  294.         foreach ($this->cart as $k => $v) {
  295.             $amount += round($v['baseprice'], Env::price_precission(), PHP_ROUND_HALF_UP) * $v['num'];
  296.         }
  297.             
  298.         return $amount;
  299.     }
  300.     public function getAmountDelivery()
  301.     {
  302.         return (float)@$_SESSION['_sf2_attributes']['checkout']['delivery_cost'];
  303.     }
  304.     public function getAmountWithDelivery()
  305.     {
  306.         if (($this->getAmount() < $this->app->sett->get('free_delivery_amount')) || ($this->Auth->isOpt())) {
  307.             return $this->getAmount() + $this->getAmountDelivery();
  308.         } else {
  309.             return $this->getAmount();
  310.         }
  311.     }
  312.     public function userLogin($user_id)
  313.     {
  314.         $this->load_session($user_id);
  315.         $discount $this->UserDiscount->getValue();
  316.         if ($discount >= 0) {
  317.             foreach ($this->cart as $k => $v) {
  318.                 $prod $this->Prods->find((int)$v['id']);
  319.                 if (!$prod) {
  320.                     unset($this->cart[$k]);
  321.                     continue;
  322.                 }
  323.                 $numdiscount $prod->getNumdiscount();
  324.         
  325.                 if($v['var'] == 2){
  326.                     $numdiscount $prod->getNumdiscount2();
  327.                 }
  328.     
  329.                 if($v['var'] == 3){
  330.                     $numdiscount $prod->getNumdiscount3();
  331.                 }
  332.                 
  333.                 $this->cart[$k]['userdiscount'] = $discount;
  334.                 if($this->Auth->isOpt()) {
  335.                     $this->cart[$k]['numdiscount'] = $this->NumDiscount->getDiscount((int) $this->cart[$k]['num'], $numdiscount);
  336.                 }
  337.             }
  338.         }
  339.         $this->recount();
  340.         $this->save_session();
  341.         $this->em->createQuery("DELETE App\Entity\CartUnsaved c WHERE c.user_id = '".$this->Auth->guestId()."'")->getResult();
  342.         $this->flush();
  343.     }
  344.         
  345.     public function setUserDiscount($discount){
  346.         if($discount){
  347.             foreach($this->cart as $k => $v){
  348.                 $this->cart[$k]['userdiscount'] = $discount;
  349.             }
  350.         }
  351.         $this->recount();
  352.         $this->save_session();
  353.         $this->flush();
  354.     }
  355.         
  356.     protected function recount($cart = [])
  357.     {
  358.         if (!empty($cart)) {
  359.             foreach ($cart as $k => $v) {
  360.                 if (!isset($v['userdiscount'])) $cart[$k]['userdiscount'] = 0;
  361.                 if (!isset($v['numdiscount'])) $cart[$k]['numdiscount'] = 0;
  362.                 if (!isset($v['skidka'])) $cart[$k]['skidka'] = 0;                
  363.                 
  364.                 $cart[$k]['baseprice'] = (new Money($v['baseprice']))->getAmount();
  365.                 if ($v['skidka']) {
  366.                     $cart[$k]['price'] = (new Money(($v['baseprice']) * (100 $v['skidka']) / 100))->getAmount();
  367.                 } else {
  368.                     $cart[$k]['price'] = (new Money((($v['baseprice']) * (100 $v['userdiscount']) * (100 $v['numdiscount']) / 100 100)))->getAmount();
  369.                 }                
  370.             }
  371.             return $cart;
  372.         }
  373.         foreach ($this->cart as $k => $v) {
  374.             if (!isset($v['userdiscount'])) $this->cart[$k]['userdiscount'] = 0;
  375.             if (!isset($v['numdiscount'])) $this->cart[$k]['numdiscount'] = 0;
  376.             if (!isset($v['skidka'])) $this->cart[$k]['skidka'] = 0;
  377.             
  378.             if ($this->order_id == 0) {
  379.                 $prod $this->Prods->find((int) $v['id']);
  380.                 if ($prod) {
  381.                     $skidka $prod->getSkidka();
  382.             
  383.                     if ($v['var'] == 2) {
  384.                         $skidka $prod->getSkidka2();
  385.                     }
  386.     
  387.                     if ($v['var'] == 3) {
  388.                         $skidka $prod->getSkidka3();
  389.                     }
  390.                 
  391.                     $this->cart[$k]['skidka'] = $skidka;
  392.                 }                
  393.             }
  394.             
  395.             $this->cart[$k]['baseprice'] = (new Money($v['baseprice']))->getAmount();
  396.             if ($v['skidka']) {
  397.                 $this->cart[$k]['price'] = (new Money(($v['baseprice']) * (100 $v['skidka']) / 100))->getAmount();
  398.             } else {
  399.                 $this->cart[$k]['price'] = (new Money((($v['baseprice']) * (100 $v['userdiscount']) * (100 $v['numdiscount']) / 100 100)))->getAmount();
  400.             }                
  401.         }    
  402.     }
  403.         
  404.     public function getProdNum()
  405.     {
  406.         return (empty($this->cart)) ? count($this->cart);
  407.     }
  408.     public function getPackNum()
  409.     {
  410.         $num 0;
  411.         foreach($this->cart as $k => $v)
  412.             $num += $v['num'];
  413.         return $num;
  414.     }
  415.     public function getWeight()
  416.     {
  417.         $weight 0;
  418.         foreach($this->cart as $k => $v)
  419.         {
  420.             $n $v['num'] ?? 0;
  421.             $w $v['weight'] ?? 0;
  422.             $weight += $n $w;
  423.         }
  424.             
  425.         return round($weight 10002);
  426.     }
  427.     protected function load_session()
  428.     {
  429.         $uid $this->Auth->getUserId() ? $this->Auth->getUserId(): $this->Auth->guestId();
  430.         $unsaved_cart $this->CartUnsaved->findOneBy(["user_id" => $uid]);
  431.         if ($unsaved_cart) {
  432.             $cart json_decode($unsaved_cart->getCart(), true);    
  433.             foreach ($cart as $k => $v) {
  434.                 $prod $this->Prods->find((int) $v['id']);
  435.                 
  436.                 if (!$prod) {
  437.                     $this->cart[$k] = $v;
  438.                     continue;
  439.                 }
  440.                 $v['baseprice'] = $prod->getPrice();
  441.                 if ($v['var'] == 2) { 
  442.                     $v['baseprice'] = $prod->getPrice2();
  443.                 } elseif ($v['var'] == 3) {
  444.                     $v['baseprice'] = $prod->getPrice3();
  445.                 }
  446.                 
  447.                 if (!isset($this->cart[$k])) {
  448.                     $this->cart[$k] = $v;
  449.                 }                
  450.             }
  451.         }
  452.         $this->flush();
  453.     }
  454.     private function flush()
  455.     {
  456.         $this->Session->set('cart'$this->cart);
  457.     }
  458.     public function save_session()
  459.     {
  460.         $uid $this->Auth->getUserId() ? $this->Auth->getUserId(): $this->Auth->guestId();
  461.         $cart json_encode($this->cartJSON_UNESCAPED_UNICODE);
  462.         $unsaved_cart $this->CartUnsaved->findOneBy(["user_id" => $uid]);
  463.         if ($unsaved_cart) {
  464.             $unsaved_cart->setCart($cart);
  465.         } else {
  466.             $unsaved_cart = new CartUnsaved();
  467.             $unsaved_cart->setUserId($uid);
  468.             $unsaved_cart->setCart($cart);
  469.             $this->em->persist($unsaved_cart);
  470.         }
  471.         $this->em->flush();
  472.     }
  473.     public function delete_session()
  474.     {
  475.         $uid $this->Auth->getUserId() ? $this->Auth->getUserId(): $this->Auth->guestId();
  476.         $unsaved_cart $this->CartUnsaved->findOneBy(["user_id" => $uid]);
  477.         if ($unsaved_cart) {
  478.             $this->em->remove($unsaved_cart);
  479.             $this->em->flush();
  480.         }
  481.     }
  482.         
  483.     public function saveCart(int $order_id) {
  484.         // if ($this->Auth->isAuth() || !$this->Auth->isOpt()) {
  485.         //     $userdiscount = $this->UserDiscount->calculateUserDiscount(new Model_Discount, new Model_Order(), new Model_User(), Auth::userid());
  486.         // } else {
  487.         //     $userdiscount = 0;
  488.         // }
  489.         
  490.         foreach ($this->cart as $k => $v) {
  491.             $prod $this->Prods->find((int) $v['id']);
  492.             $price $prod->getPrice();
  493.             $num $prod->getNum();
  494.             
  495.             if ($v['var'] == 2) {
  496.                 $price $prod->getPrice2();
  497.             } elseif($v['var'] == 3) {
  498.                 $price $prod->getPrice3();
  499.             }
  500.             if($v['skidka']){
  501.                 $v['numdiscount'] = 0;
  502.             }
  503.                 
  504.             if ($v['skidka']) {
  505.                 $v['numdiscount'] = 0;
  506.             }
  507.                 
  508.             $Cart = new EntityCart();
  509.             $Cart->setOrderId($order_id);
  510.             $Cart->setProd($prod);
  511.             $Cart->setVar((int) $v['var']);
  512.             $Cart->setNum((int) $v['num']);
  513.             $Cart->setPrice(round($priceEnv::price_precission(), PHP_ROUND_HALF_UP));
  514.             $Cart->setSkidka((int) $v['skidka']);
  515.             $Cart->setNumdiscount((int) $v['numdiscount']);
  516.             $Cart->setUserdiscount((int) $v['userdiscount']);
  517.             //$Cart->setSumdiscount((int) $v['sumdiscount']);
  518.             $this->em->persist($Cart);                
  519.         }
  520.         $this->em->flush();
  521.         $this->flush();
  522.     }
  523.     //Удалить товары с нулевыми остатками из цветов
  524.     public function deleteNullFromColors()
  525.     {
  526.         foreach ($this->cart as $k => $v) {
  527.             $prod $this->Prods->find((int) $v['id']);
  528.             $prod_num $prod->getNum();
  529.             if ($v['var'] == 2$prod_num $prod->getNum2();
  530.             if ($v['var'] == 3$prod_num $prod->getNum3();
  531.             if ($prod->getId() == $v['id'] && $prod_num && $prod_num $v['num']) {
  532.                 $this->prods_limited[] = $v['id'];
  533.                 $this->cart[$k]['num'] = $prod_num;
  534.             }
  535.             if ($prod->getId() == $v['id'] && $prod_num <= 0) {
  536.                 $this->prodColor->deleteColor($prod->getId());
  537.             }
  538.         }
  539.         $this->flush();
  540.     }
  541.     public function save_cart_admin($order_id) {
  542.         $this->em->createQuery("DELETE App\Entity\Cart c WHERE c.order = ".$order_id)->getResult();
  543.         
  544.         foreach ($this->cart as $v) {
  545.             $prod $this->Prods->find((int) $v['id']);
  546.             if ($v['skidka']) {
  547.                 $v['numdiscount'] = 0;
  548.             }
  549.             $Cart = new EntityCart();
  550.             $Cart->setOrderId($order_id);
  551.             $Cart->setProd($prod);
  552.             $Cart->setVar((int) $v['var']);
  553.             $Cart->setNum((int) $v['num']);
  554.             $Cart->setPrice(round($v['baseprice'], Env::price_precission(), PHP_ROUND_HALF_UP));
  555.             $Cart->setSkidka((int) $v['skidka']);
  556.             $Cart->setNumdiscount((int) $v['numdiscount']);
  557.             $Cart->setUserdiscount((int) $v['userdiscount']);
  558.             $Cart->setSumdiscount((int) $v['sumdiscount']);
  559.             $this->em->persist($Cart);
  560.         }
  561.         $this->em->flush();
  562.         $this->flush();
  563.     }
  564.     
  565.     public function prods_limited() {
  566.         foreach ($this->cart as $k => $v) {
  567.             $prod $this->Prods->find((int) $v['id']);
  568.             $prod_num $prod->getNum();
  569.             if ($v['var'] == 2$prod_num $prod->getNum2();
  570.             if ($v['var'] == 3$prod_num $prod->getNum3();
  571.         
  572.             if ($prod->getId() == $v['id'] && $prod_num && $prod_num $v['num']) {
  573.                 $this->prods_limited[] = $v['id'];
  574.                 $this->cart[$k]['num'] = $prod_num;
  575.             }
  576.             if ($prod->getId() == $v['id'] && $prod_num <= 0) {
  577.                 unset($this->cart[$k]);
  578.             }
  579.         }
  580.         $this->flush();
  581.         $this->save_session();
  582.         if (!empty($this->prods_limited)) return true;
  583.         else return false;
  584.     }
  585.     public function getProdsLimited (): array
  586.     {
  587.         return $this->prods_limited;
  588.     }
  589. }