Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

602 lines
29KB

  1. <?php
  2. namespace Lc\ShopBundle\Services\Order;
  3. use App\Entity\OrderProductReductionCatalog;
  4. use App\Entity\OrderShop;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Lc\ShopBundle\Context\DocumentInterface;
  7. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  8. use Lc\ShopBundle\Context\OrderPaymentInterface;
  9. use Lc\ShopBundle\Context\OrderReductionCartInterface;
  10. use Lc\ShopBundle\Context\OrderProductInterface;
  11. use Lc\ShopBundle\Context\OrderReductionCreditInterface;
  12. use Lc\ShopBundle\Context\OrderShopInterface;
  13. use Lc\ShopBundle\Context\OrderStatusHistoryInterface;
  14. use Lc\ShopBundle\Context\OrderStatusInterface;
  15. use Lc\ShopBundle\Context\PriceUtilsInterface;
  16. use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
  17. use Lc\ShopBundle\Context\ReductionCartInterface;
  18. use Lc\ShopBundle\Context\ReductionCreditInterface;
  19. use Lc\ShopBundle\Context\UserInterface;
  20. use Lc\ShopBundle\Model\Document;
  21. use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
  22. use Lc\ShopBundle\Model\Product;
  23. use Lc\ShopBundle\Model\ProductFamily;
  24. use Lc\ShopBundle\Services\CreditUtils;
  25. use Lc\ShopBundle\Services\DocumentUtils;
  26. use Lc\ShopBundle\Services\Price\OrderShopPriceUtils;
  27. use Lc\ShopBundle\Services\UserUtils;
  28. use Lc\ShopBundle\Services\Utils;
  29. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  30. use Symfony\Component\Security\Core\Security;
  31. class OrderUtils
  32. {
  33. use OrderUtilsReductionTrait;
  34. protected $em;
  35. protected $security;
  36. protected $userUtils;
  37. protected $merchantUtils;
  38. protected $orderShopRepo;
  39. protected $reductionCreditRepo ;
  40. protected $orderReductionCreditRepo ;
  41. protected $priceUtils;
  42. protected $productFamilyUtils;
  43. protected $documentUtils;
  44. protected $utils;
  45. protected $creditUtils;
  46. public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils,
  47. MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils,
  48. DocumentUtils $documentUtils, Utils $utils, CreditUtils $creditUtils)
  49. {
  50. $this->em = $em;
  51. $this->security = $security;
  52. $this->userUtils = $userUtils;
  53. $this->merchantUtils = $merchantUtils;
  54. $this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName());
  55. $this->reductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(ReductionCreditInterface::class)->getName());
  56. $this->orderReductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(OrderReductionCreditInterface::class)->getName());
  57. $this->priceUtils = $priceUtils;
  58. $this->productFamilyUtils = $productFamilyUtils;
  59. $this->documentUtils = $documentUtils;
  60. $this->utils = $utils;
  61. $this->creditUtils = $creditUtils;
  62. }
  63. public function getCartCurrent()
  64. {
  65. $paramsSearchOrderShop = [];
  66. $user = $this->security->getUser();
  67. $visitor = $this->userUtils->getVisitorCurrent();
  68. $orderShop = null;
  69. $orderShopUser = null;
  70. $orderShopVisitor = null;
  71. if ($user) {
  72. $orderShopUser = $this->orderShopRepo->findCartCurrent([
  73. 'user' => $user
  74. ]);
  75. }
  76. if ($visitor) {
  77. $orderShopVisitor = $this->orderShopRepo->findCartCurrent([
  78. 'visitor' => $visitor
  79. ]);
  80. }
  81. if ($orderShopUser || $orderShopVisitor) {
  82. // merge
  83. if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
  84. && $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) {
  85. $orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
  86. $this->utils->addFlash('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
  87. } else {
  88. $orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
  89. }
  90. // set user
  91. if ($orderShop && $user && !$orderShop->getUser()) {
  92. $orderShop->setUser($user);
  93. $this->em->persist($orderShop);
  94. $this->em->flush();
  95. }
  96. }
  97. return $orderShop;
  98. }
  99. public function createOrderShop($params)
  100. {
  101. //TODO vérifier que l'utilisateur n'a pas déjà une commande en cours
  102. $orderShop = new OrderShop();
  103. $orderShopBelongTo = false;
  104. if (isset($params['user']) && $params['user']) {
  105. $orderShopBelongTo = true;
  106. $orderShop->setUser($params['user']);
  107. }
  108. if (isset($params['visitor']) && $params['visitor']) {
  109. $orderShopBelongTo = true;
  110. $orderShop->setVisitor($params['visitor']);
  111. }
  112. if (!$orderShopBelongTo) {
  113. throw new \ErrorException('La commande doit être liée à un utilisateur ou à un visiteur.');
  114. }
  115. if (isset($params['merchant']) && $params['merchant']) {
  116. $orderShop->setMerchant($params['merchant']);
  117. } else {
  118. throw new \ErrorException('La commande doit être liée à un merchant.');
  119. }
  120. $orderShop = $this->changeOrderStatus('cart', $orderShop);
  121. return $orderShop;
  122. }
  123. public function addOrderProduct($orderShop, $orderProductAdd, $persist = true)
  124. {
  125. $return = false;
  126. $user = $this->security->getUser();
  127. $visitor = $this->userUtils->getVisitorCurrent();
  128. if (!$orderShop) {
  129. $orderShop = $this->createOrderShop([
  130. 'user' => $user,
  131. 'visitor' => $visitor,
  132. 'merchant' => $this->merchantUtils->getMerchantCurrent()
  133. ]);
  134. }
  135. if($this->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) {
  136. if ($orderProductAdd->getQuantityOrder() > 0) {
  137. $updated = false;
  138. $orderProductAdd->setTitle($orderProductAdd->getTitleOrderShop());
  139. $orderProductAdd->setPrice($this->priceUtils->getPrice($orderProductAdd->getProduct()));
  140. $orderProductAdd->setUnit($orderProductAdd->getProduct()->getUnitInherited());
  141. $orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited());
  142. $orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited());
  143. $productFamily = $this->productFamilyUtils->getProductFamilyBySlug($orderProductAdd->getProduct()->getProductFamily()->getSlug());
  144. $reductionCatalog = $productFamily->getReductionCatalog();
  145. if ($reductionCatalog) {
  146. $orderProductReductionCatalog = new OrderProductReductionCatalog();
  147. $orderProductReductionCatalog->setTitle($reductionCatalog->getTitle());
  148. $orderProductReductionCatalog->setValue($reductionCatalog->getValue());
  149. $orderProductReductionCatalog->setUnit($reductionCatalog->getUnit());
  150. $orderProductReductionCatalog->setBehaviorTaxRate($reductionCatalog->getBehaviorTaxRate());
  151. $orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog);
  152. }
  153. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  154. if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId()
  155. && (string)$this->priceUtils->getPrice($orderProduct) == (string)$this->priceUtils->getPrice($orderProductAdd)
  156. && $this->compareOrderProductReductionCatalog($orderProduct->getOrderProductReductionCatalog(), $orderProductAdd->getOrderProductReductionCatalog())) {
  157. $orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder());
  158. if ($persist) {
  159. $this->em->persist($orderProduct);
  160. }
  161. $updated = true;
  162. $return = true;
  163. break;
  164. }
  165. }
  166. if (!$updated) {
  167. $orderShop->addOrderProduct($orderProductAdd);
  168. if (isset($orderProductReductionCatalog)) {
  169. $this->em->persist($orderProductReductionCatalog);
  170. if ($persist) {
  171. if (isset($orderProductReductionCatalog)) {
  172. $this->em->persist($orderProductReductionCatalog);
  173. }
  174. $this->em->persist($orderProductAdd);
  175. $this->em->persist($orderShop);
  176. }
  177. }
  178. $return = true;
  179. }
  180. if ($persist) {
  181. $this->em->flush();
  182. }
  183. }
  184. }
  185. else {
  186. $availableQuantity = $orderProductAdd->getProduct()->getAvailableQuantityInherited() ;
  187. $textError = "Le produit <strong>".$orderProductAdd->getTitleOrderShop()."</strong> n'est pas disponible" ;
  188. if($availableQuantity !== false && $availableQuantity > 0) {
  189. $unit = '' ;
  190. if($orderProductAdd->getProduct()->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
  191. $unit = $orderProductAdd->getProduct()->getUnitInherited()->getUnit() ;
  192. }
  193. $textError .= ' dans cette quantité ' ;
  194. $textError .= '<br />'.$availableQuantity.$unit.' disponible(s) dont '.$this->getQuantityOrderByProduct($orderShop, $orderProductAdd->getProduct()).$unit.' déjà dans votre panier.' ;
  195. }
  196. $this->utils->addFlash('error', $textError);
  197. }
  198. return $return ;
  199. }
  200. public function countQuantities($orderShop)
  201. {
  202. return $this->countQuantitiesByOrderProducts($orderShop->getOrderProducts());
  203. }
  204. public function countQuantitiesByOrderProducts($orderProducts = [])
  205. {
  206. $count = 0;
  207. foreach ($orderProducts as $orderProduct) {
  208. $count += $orderProduct->getQuantityOrder();
  209. }
  210. return $count;
  211. }
  212. public function getOrderProductsByParentCategory($orderShop = null)
  213. {
  214. $categoriesArray = [];
  215. if ($orderShop) {
  216. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  217. $productCategories = $orderProduct->getProduct()->getProductFamily()->getProductCategories();
  218. $category = $productCategories[0]->getParentCategory();
  219. $labelCategory = $category->getTitle();
  220. if (!isset($categoriesArray[$labelCategory])) {
  221. $categoriesArray[$labelCategory] = [];
  222. }
  223. $categoriesArray[$labelCategory][] = $orderProduct;
  224. }
  225. }
  226. return $categoriesArray;
  227. }
  228. public function getOrderDatas($order = null)
  229. {
  230. $data = [];
  231. if (!$order) {
  232. $order = $this->getCartCurrent();
  233. }
  234. $data['order'] = $order;
  235. if ($order) {
  236. $data['count'] = $this->countQuantities($order);
  237. $data['total_with_tax'] = $this->priceUtils->getTotalWithTax($order);
  238. $data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order);
  239. }
  240. return $data;
  241. }
  242. public function getOrderAsJsonObject(OrderShopInterface $order)
  243. {
  244. $data['id'] = $order->getId();
  245. $data['user'] = $order->getUser()->getSummary();
  246. $data['orderStatus'] = $order->getOrderStatus()->__tosString();
  247. $data['deliveryAddress'] = $order->getDeliveryAddress()->getSummary();
  248. $data['invoiceAddress'] = $order->getInvoiceAddress()->getSummary();
  249. $data['total'] = $this->priceUtils->getTotal($order);
  250. $data['totalWithTax'] = $this->priceUtils->getTotalWithTax($order);
  251. $data['totalWithTaxAndReduction'] = $this->priceUtils->getTotalWithTax($order);
  252. $i = 0;
  253. foreach ($this->getOrderProductsByParentCategory($order) as $labelCategory => $orderProducts) {
  254. foreach ($orderProducts as $orderProduct) {
  255. $data['orderProducts'][$i]['id'] = $orderProduct->getId();
  256. $data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId();
  257. $data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder();
  258. $data['orderProducts'][$i]['labelCategory'] = $labelCategory;
  259. $data['orderProducts'][$i]['title'] = $orderProduct->getTitle();
  260. $data['orderProducts'][$i]['price'] = $this->priceUtils->getPrice($orderProduct);
  261. $data['orderProducts'][$i]['priceWithTax'] = $this->priceUtils->getPriceWithTax($orderProduct);
  262. $data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceUtils->getPriceWithTaxAndReduction($orderProduct);
  263. $data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
  264. $data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceUtils->getTotalOrderProductsWithTaxAndReduction(array($orderProduct));
  265. $i++;
  266. }
  267. }
  268. return $data;
  269. }
  270. public function newOrderStatusHistory($order, $status, $origin = 'user')
  271. {
  272. $orderStatusHistoryClass = $this->em->getClassMetadata(OrderStatusHistoryInterface::class);
  273. $orderStatusHistory = new $orderStatusHistoryClass->name;
  274. $orderStatusHistory->setOrderShop($order);
  275. $orderStatusHistory->setOrderStatus($status);
  276. $orderStatusHistory->setOrigin($origin);
  277. $this->em->persist($orderStatusHistory);
  278. }
  279. public function mergeOrderShops($orderShop1, $orderShop2)
  280. {
  281. if ($orderShop1 && $orderShop2) {
  282. foreach ($orderShop2->getOrderProducts() as $orderProduct) {
  283. $this->addOrderProduct($orderShop1, $orderProduct);
  284. $this->em->remove($orderProduct);
  285. }
  286. $this->em->remove($orderShop2);
  287. $this->em->persist($orderShop1);
  288. $this->em->flush();
  289. return $orderShop1;
  290. }
  291. }
  292. public function createDocumentInvoice(OrderShopInterface $orderShop)
  293. {
  294. $merchantAddress = $orderShop->getMerchant()->getAddress();
  295. $buyerAddress = $orderShop->getInvoiceAddress();
  296. $document = $this->documentUtils->createDocument([
  297. 'type' => Document::TYPE_INVOICE,
  298. 'title' => '',
  299. 'status' => 1,
  300. 'order_shops' => [$orderShop],
  301. 'merchant_address' => $merchantAddress,
  302. 'buyer_address' => $buyerAddress,
  303. 'created_by' => $orderShop->getUser()
  304. ]);
  305. return $document;
  306. }
  307. public function groupOrderProductsByProductFamily($orderProducts)
  308. {
  309. $orderProductsByProductFamily = [];
  310. foreach ($orderProducts as $orderProduct) {
  311. if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
  312. $productFamily = $orderProduct->getProduct()->getProductFamily();
  313. if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
  314. $orderProductsByProductFamily[$productFamily->getId()] = [
  315. 'order_products' => [],
  316. 'total_quantity_weight' => 0,
  317. ];
  318. }
  319. $orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
  320. $orderProductsByProductFamily[$productFamily->getId()]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()) * $orderProduct->getQuantityOrder();
  321. }
  322. }
  323. return $orderProductsByProductFamily;
  324. }
  325. public function createOrderPayment($orderShop, $meanPayment, $amount, $reference = null, $comment = null, $paidAt = null)
  326. {
  327. $classOrderPayment = $this->em->getClassMetadata(OrderPaymentInterface::class)->getName();
  328. $orderPayment = new $classOrderPayment;
  329. $orderPayment->setOrderShop($orderShop);
  330. $orderPayment->setMeanPayment($meanPayment);
  331. $orderPayment->setAmount($amount);
  332. $orderPayment->setReference($reference);
  333. $orderPayment->setComment($comment);
  334. $orderPayment->setEditable(false);
  335. if ($paidAt) {
  336. $orderPayment->setPaidAt($paidAt);
  337. } else {
  338. $orderPayment->setPaidAt(new \DateTime('now'));
  339. }
  340. $this->em->persist($orderPayment);
  341. $this->em->flush();
  342. return $orderPayment ;
  343. }
  344. public function isOrderPaid($order)
  345. {
  346. if ($this->getTotalOrderPayments($order) >= $this->priceUtils->getTotalWithTax($order)) {
  347. return true;
  348. } else {
  349. return false;
  350. }
  351. }
  352. public function getTotalOrderPayments($order): float
  353. {
  354. $totalAmount = floatval(0);
  355. foreach ($order->getOrderPayments() as $orderPayment) {
  356. $totalAmount = $orderPayment->getAmount() + $totalAmount;
  357. }
  358. return $totalAmount;
  359. }
  360. public function deductAvailabilityProduct(\Lc\ShopBundle\Model\OrderShop $orderShop)
  361. {
  362. //TODO ne pas déduire des stocks les orderProduct marqué en relivraison
  363. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  364. switch ($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock()) {
  365. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  366. //Disponibilité par unité de référence
  367. $oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited();
  368. $newAvailability = $oldAvailability - ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient());
  369. $orderProduct->getProduct()->getProductFamily()->setAvailableQuantity($newAvailability);
  370. $this->em->persist($orderProduct->getProduct()->getProductFamily());
  371. break;
  372. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  373. $oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited();
  374. $newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
  375. $orderProduct->getProduct()->getProductFamily()->setAvailableQuantity($newAvailability);
  376. $this->em->persist($orderProduct->getProduct()->getProductFamily());
  377. break;
  378. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  379. $oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited();
  380. $newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
  381. $orderProduct->getProduct()->setAvailableQuantity($newAvailability);
  382. $this->em->persist($orderProduct->getProduct());
  383. break;
  384. }
  385. $this->em->flush();
  386. }
  387. }
  388. public function isCartAllowToBeOrder($order){
  389. return true;
  390. }
  391. public function getReductionCreditsAvailableByUser($user)
  392. {
  393. $reductionCredits = $this->reductionCreditRepo->findReductionCreditsByUser($user) ;
  394. $reductionCreditsArray = [] ;
  395. foreach($reductionCredits as $reductionCredit) {
  396. if(!$this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user)) {
  397. $reductionCreditsArray[] = $reductionCredit ;
  398. }
  399. }
  400. return $reductionCreditsArray ;
  401. }
  402. public function isReductionCreditAddedToOrder($orderShop, $reductionCredit)
  403. {
  404. foreach($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
  405. if($orderReductionCredit->getReductionCredit() == $reductionCredit) {
  406. return true ;
  407. }
  408. }
  409. return false ;
  410. }
  411. public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null)
  412. {
  413. if(!$orderShop) {
  414. $orderShop = $this->getCartCurrent() ;
  415. }
  416. $productFamily = $product->getProductFamily() ;
  417. $quantityAsked = $quantityOrder;
  418. if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
  419. if(!$quantityOrder) {
  420. $quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product, true) ;
  421. }
  422. else {
  423. $quantityAsked = ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()) * $quantityOrder;
  424. }
  425. if($checkCart) {
  426. $quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product, true) ;
  427. }
  428. }
  429. if(($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  430. || $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) {
  431. if(!$quantityOrder) {
  432. $quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product) ;
  433. }
  434. if($checkCart) {
  435. $quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product) ;
  436. }
  437. }
  438. if ($product->getAvailableQuantityInherited() >= $quantityAsked
  439. || $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED) {
  440. return true;
  441. }
  442. else {
  443. return false;
  444. }
  445. }
  446. public function isOneProductAvailableAddCart($products): bool
  447. {
  448. $orderShop = $this->getCartCurrent() ;
  449. foreach($products as $product) {
  450. if($this->isProductAvailable($product, 1, true)) {
  451. return true ;
  452. }
  453. }
  454. return false ;
  455. }
  456. public function isOrderProductAvailable(OrderProductInterface $orderProduct)
  457. {
  458. return $this->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder()) ;
  459. }
  460. public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, $orderShop = null)
  461. {
  462. $product = $orderProduct->getProduct() ;
  463. return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true, $orderShop);
  464. }
  465. public function getQuantityOrderByProduct($orderShop, $product, $byWeight = false)
  466. {
  467. $quantity = 0 ;
  468. $productFamily = $product->getProductFamily() ;
  469. $behaviorCountStock = $productFamily->getBehaviorCountStock() ;
  470. if($orderShop) {
  471. foreach($orderShop->getOrderProducts() as $orderProduct) {
  472. if($orderProduct->getProduct()->getId() == $product->getId()
  473. || ( ($behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE)
  474. && $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) {
  475. if($byWeight) {
  476. $quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $product->getUnitInherited()->getCoefficient()) ;
  477. }
  478. else {
  479. $quantity += $orderProduct->getQuantityOrder() ;
  480. }
  481. }
  482. }
  483. }
  484. return $quantity ;
  485. }
  486. public function getProductQuantityMaxAddCart($product)
  487. {
  488. $orderShop = $this->getCartCurrent() ;
  489. $productFamily = $product->getProductFamily() ;
  490. $byWeight = false ;
  491. if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
  492. $byWeight = true ;
  493. }
  494. return $product->getAvailableQuantityInherited() - $this->getQuantityOrderByProduct($orderShop, $product, $byWeight) ;
  495. }
  496. }