query = $query; $this->priceResolver = $priceResolver; } public function getDatas(OrderShopInterface $orderShop = null): array { $data = []; if (is_null($orderShop)) { $orderShop = $this->getCartCurrent(); } $data['order'] = $orderShop; if ($orderShop) { $data['count'] = $orderShop->countQuantities(); $data['total_with_tax'] = $this->priceResolver->getTotalWithTax($orderShop); $data['order_products_by_category'] = $orderShop->getOrderProductsByParentCategory(); $data['total_remaining_to_be_paid'] = $this->getTotalRemainingToBePaid($orderShop); } return $data; } public function getAsJsonObject(OrderShopInterface $orderShop): array { $data['id'] = $orderShop->getId(); $data['user'] = $orderShop->getUser()->getSummary(); $data['orderStatus'] = $orderShop->getOrderStatus()->__toString(); $data['deliveryAddress'] = $orderShop->getDeliveryAddress()->getSummary(); $data['invoiceAddress'] = $orderShop->getInvoiceAddress()->getSummary(); $data['total'] = $this->priceResolver->getTotal($orderShop); $data['totalWithTax'] = $this->priceResolver->getTotalWithTax($orderShop); $data['totalWithTaxAndReduction'] = $this->priceResolver->getTotalWithTax($orderShop); $i = 0; foreach ($orderShop->getOrderProductsByParentCategory() as $labelCategory => $orderProducts) { foreach ($orderProducts as $orderProduct) { $data['orderProducts'][$i]['id'] = $orderProduct->getId(); $data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId(); $data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder(); $data['orderProducts'][$i]['labelCategory'] = $labelCategory; $data['orderProducts'][$i]['title'] = $orderProduct->getTitle(); $data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct); $data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct); $data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction( $orderProduct ); $data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder(); $data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction( array($orderProduct) ); $i++; } } return $data; } public function groupOrderProductsByProductFamily(array $orderProducts): array { $orderProductsByProductFamily = []; foreach ($orderProducts as $orderProduct) { if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) { $productFamily = $orderProduct->getProduct()->getProductFamily(); if (!isset($orderProductsByProductFamily[$productFamily->getId()])) { $orderProductsByProductFamily[$productFamily->getId()] = [ 'order_products' => [], 'total_quantity_weight' => 0, ]; } $orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct; $orderProductsByProductFamily[$productFamily->getId( )]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit( )->getCoefficient()) * $orderProduct->getQuantityOrder(); } } return $orderProductsByProductFamily; } public function isPositiveAmount(OrderShopInterface $orderShop) { return $this->priceResolver->getTotalWithTax($orderShop) >= 0; } public function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false) { $totalOrderPayments = $this->getTotalOrderPayments($orderShop, $mergeComplementaryOrderShop); $totalOrder = $this->priceResolver->getTotalWithTax($orderShop); if ((abs($totalOrderPayments - $totalOrder) < 0.00001 || $totalOrderPayments >= $totalOrder) && $totalOrder > 0) { return true; } else { return false; } } public function getTotalOrderPayments(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): float { $totalAmount = floatval(0); foreach ($orderShop->getOrderPayments() as $orderPayment) { $totalAmount = $orderPayment->getAmount() + $totalAmount; } if ($mergeComplementaryOrderShop) { foreach ($orderShop->getComplementaryOrderShops() as $complementaryOrderShop) { foreach ($complementaryOrderShop->getOrderPayments() as $orderPayment) { $totalAmount = $orderPayment->getAmount() + $totalAmount; } } } return $totalAmount; } public function getTotalRemainingToBePaid(OrderShopInterface $orderShop): float { return $this->priceResolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop); } public function isOrderShopPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool { return $this->getTotalRemainingToBePaid($orderShop) > 0; } }