src/Service/Cart/Cart.php line 66

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.         if (isset($this->cart[$cart_id])) {
  257.             unset($this->cart[$cart_id]);
  258.         }
  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.     public function setPromoDiscount($discount)
  357.     {
  358.         if($discount){
  359.             foreach($this->cart as $k => $v){
  360.                 $this->cart[$k]['promodiscount'] = $discount;
  361.             }
  362.         }
  363.         $this->recount();
  364.         $this->save_session();
  365.         $this->flush();
  366.     }
  367.     protected function recount($cart = [])
  368.     {
  369.         if (!empty($cart)) {
  370.             foreach ($cart as $k => $v) {
  371.                 if (!isset($v['userdiscount'])) $cart[$k]['userdiscount'] = 0;
  372.                 if (!isset($v['numdiscount'])) $cart[$k]['numdiscount'] = 0;
  373.                 if (!isset($v['skidka'])) $cart[$k]['skidka'] = 0;                
  374.                 
  375.                 $cart[$k]['baseprice'] = (new Money($v['baseprice']))->getAmount();
  376.                 if ($v['skidka']) {
  377.                     $cart[$k]['price'] = (new Money(($v['baseprice']) * (100 $v['skidka']) / 100))->getAmount();
  378.                 } else {
  379.                     $cart[$k]['price'] = (new Money((($v['baseprice']) * (100 $v['userdiscount']) * (100 $v['numdiscount']) / 100 100)))->getAmount();
  380.                 }                
  381.             }
  382.             return $cart;
  383.         }
  384.         foreach ($this->cart as $k => $v) {
  385.             if (!isset($v['userdiscount'])) $this->cart[$k]['userdiscount'] = 0;
  386.             if (!isset($v['numdiscount'])) $this->cart[$k]['numdiscount'] = 0;
  387.             if (!isset($v['skidka'])) $this->cart[$k]['skidka'] = 0;
  388.             
  389.             if ($this->order_id == 0) {
  390.                 $prod $this->Prods->find((int) $v['id']);
  391.                 if ($prod) {
  392.                     $skidka $prod->getSkidka();
  393.             
  394.                     if ($v['var'] == 2) {
  395.                         $skidka $prod->getSkidka2();
  396.                     }
  397.     
  398.                     if ($v['var'] == 3) {
  399.                         $skidka $prod->getSkidka3();
  400.                     }
  401.                 
  402.                     $this->cart[$k]['skidka'] = $skidka;
  403.                 }                
  404.             }
  405.             
  406.             $this->cart[$k]['baseprice'] = (new Money($v['baseprice']))->getAmount();
  407.             if ($v['skidka']) {
  408.                 $this->cart[$k]['price'] = (new Money(($v['baseprice']) * (100 $v['skidka']) / 100))->getAmount();
  409.             } else {
  410.                 $this->cart[$k]['price'] = (new Money((($v['baseprice']) * (100 $v['userdiscount']) * (100 $v['numdiscount']) / 100 100)))->getAmount();
  411.             }                
  412.         }    
  413.     }
  414.         
  415.     public function getProdNum()
  416.     {
  417.         return (empty($this->cart)) ? count($this->cart);
  418.     }
  419.     public function getPackNum()
  420.     {
  421.         $num 0;
  422.         foreach($this->cart as $k => $v)
  423.             $num += $v['num'];
  424.         return $num;
  425.     }
  426.     public function getWeight()
  427.     {
  428.         $weight 0;
  429.         foreach($this->cart as $k => $v)
  430.         {
  431.             $n $v['num'] ?? 0;
  432.             $w $v['weight'] ?? 0;
  433.             $weight += $n $w;
  434.         }
  435.             
  436.         return round($weight 10002);
  437.     }
  438.     protected function load_session()
  439.     {
  440.         $uid $this->Auth->getUserId() ? $this->Auth->getUserId(): $this->Auth->guestId();
  441.         $unsaved_cart $this->CartUnsaved->findOneBy(["user_id" => $uid]);
  442.         if ($unsaved_cart) {
  443.             $cart json_decode($unsaved_cart->getCart(), true);    
  444.             foreach ($cart as $k => $v) {
  445.                 $prod $this->Prods->find((int) $v['id']);
  446.                 
  447.                 if (!$prod) {
  448.                     $this->cart[$k] = $v;
  449.                     continue;
  450.                 }
  451.                 $v['baseprice'] = $prod->getPrice();
  452.                 if ($v['var'] == 2) { 
  453.                     $v['baseprice'] = $prod->getPrice2();
  454.                 } elseif ($v['var'] == 3) {
  455.                     $v['baseprice'] = $prod->getPrice3();
  456.                 }
  457.                 
  458.                 if (!isset($this->cart[$k])) {
  459.                     $this->cart[$k] = $v;
  460.                 }                
  461.             }
  462.         }
  463.         $this->flush();
  464.     }
  465.     private function flush()
  466.     {
  467.         $this->Session->set('cart'$this->cart);
  468.     }
  469.     public function save_session()
  470.     {
  471.         $uid $this->Auth->getUserId() ? $this->Auth->getUserId(): $this->Auth->guestId();
  472.         $cart json_encode($this->cartJSON_UNESCAPED_UNICODE);
  473.         $unsaved_cart $this->CartUnsaved->findOneBy(["user_id" => $uid]);
  474.         if ($unsaved_cart) {
  475.             $unsaved_cart->setCart($cart);
  476.         } else {
  477.             $unsaved_cart = new CartUnsaved();
  478.             $unsaved_cart->setUserId($uid);
  479.             $unsaved_cart->setCart($cart);
  480.             $this->em->persist($unsaved_cart);
  481.         }
  482.         $this->em->flush();
  483.     }
  484.     public function delete_session()
  485.     {
  486.         $uid $this->Auth->getUserId() ? $this->Auth->getUserId(): $this->Auth->guestId();
  487.         $unsaved_cart $this->CartUnsaved->findOneBy(["user_id" => $uid]);
  488.         if ($unsaved_cart) {
  489.             $this->em->remove($unsaved_cart);
  490.             $this->em->flush();
  491.         }
  492.     }
  493.         
  494.     public function saveCart(int $order_id) {
  495.         // if ($this->Auth->isAuth() || !$this->Auth->isOpt()) {
  496.         //     $userdiscount = $this->UserDiscount->calculateUserDiscount(new Model_Discount, new Model_Order(), new Model_User(), Auth::userid());
  497.         // } else {
  498.         //     $userdiscount = 0;
  499.         // }
  500.         
  501.         foreach ($this->cart as $k => $v) {
  502.             $prod $this->Prods->find((int) $v['id']);
  503.             $price $prod->getPrice();
  504.             $num $prod->getNum();
  505.             
  506.             if ($v['var'] == 2) {
  507.                 $price $prod->getPrice2();
  508.             } elseif($v['var'] == 3) {
  509.                 $price $prod->getPrice3();
  510.             }
  511.             if($v['skidka']){
  512.                 $v['numdiscount'] = 0;
  513.             }
  514.                 
  515.             if ($v['skidka']) {
  516.                 $v['numdiscount'] = 0;
  517.             }
  518.                 
  519.             $Cart = new EntityCart();
  520.             $Cart->setOrderId($order_id);
  521.             $Cart->setProd($prod);
  522.             $Cart->setVar((int) $v['var']);
  523.             $Cart->setNum((int) $v['num']);
  524.             $Cart->setPrice(round($priceEnv::price_precission(), PHP_ROUND_HALF_UP));
  525.             $Cart->setSkidka((int) $v['skidka']);
  526.             $Cart->setNumdiscount((int) $v['numdiscount']);
  527.             $Cart->setUserdiscount((int) $v['userdiscount']);
  528.             //$Cart->setSumdiscount((int) $v['sumdiscount']);
  529.             $this->em->persist($Cart);                
  530.         }
  531.         $this->em->flush();
  532.         $this->flush();
  533.     }
  534.     //Удалить товары с нулевыми остатками из цветов
  535.     public function deleteNullFromColors()
  536.     {
  537.         foreach ($this->cart as $k => $v) {
  538.             $prod $this->Prods->find((int) $v['id']);
  539.             $prod_num $prod->getNum();
  540.             if ($v['var'] == 2$prod_num $prod->getNum2();
  541.             if ($v['var'] == 3$prod_num $prod->getNum3();
  542.             if ($prod->getId() == $v['id'] && $prod_num && $prod_num $v['num']) {
  543.                 $this->prods_limited[] = $v['id'];
  544.                 $this->cart[$k]['num'] = $prod_num;
  545.             }
  546.             if ($prod->getId() == $v['id'] && $prod_num <= 0) {
  547.                 $this->prodColor->deleteColor($prod->getId());
  548.             }
  549.         }
  550.         $this->flush();
  551.     }
  552.     public function save_cart_admin($order_id) {
  553.         $this->em->createQuery("DELETE App\Entity\Cart c WHERE c.order = ".$order_id)->getResult();
  554.         
  555.         foreach ($this->cart as $v) {
  556.             $prod $this->Prods->find((int) $v['id']);
  557.             if ($v['skidka']) {
  558.                 $v['numdiscount'] = 0;
  559.             }
  560.             $Cart = new EntityCart();
  561.             $Cart->setOrderId($order_id);
  562.             $Cart->setProd($prod);
  563.             $Cart->setVar((int) $v['var']);
  564.             $Cart->setNum((int) $v['num']);
  565.             $Cart->setPrice(round($v['baseprice'], Env::price_precission(), PHP_ROUND_HALF_UP));
  566.             $Cart->setSkidka((int) $v['skidka']);
  567.             $Cart->setNumdiscount((int) $v['numdiscount']);
  568.             $Cart->setUserdiscount((int) $v['userdiscount']);
  569.             $Cart->setSumdiscount((int) $v['sumdiscount']);
  570.             $this->em->persist($Cart);
  571.         }
  572.         $this->em->flush();
  573.         $this->flush();
  574.     }
  575.     
  576.     public function prods_limited() {
  577.         foreach ($this->cart as $k => $v) {
  578.             $prod $this->Prods->find((int) $v['id']);
  579.             $prod_num $prod->getNum();
  580.             if ($v['var'] == 2$prod_num $prod->getNum2();
  581.             if ($v['var'] == 3$prod_num $prod->getNum3();
  582.         
  583.             if ($prod->getId() == $v['id'] && $prod_num && $prod_num $v['num']) {
  584.                 $this->prods_limited[] = $v['id'];
  585.                 $this->cart[$k]['num'] = $prod_num;
  586.             }
  587.             if ($prod->getId() == $v['id'] && $prod_num <= 0) {
  588.                 unset($this->cart[$k]);
  589.             }
  590.         }
  591.         $this->flush();
  592.         $this->save_session();
  593.         if (!empty($this->prods_limited)) return true;
  594.         else return false;
  595.     }
  596.     public function getProdsLimited (): array
  597.     {
  598.         return $this->prods_limited;
  599.     }
  600. }