Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

592 lines
28KB

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