/** * @param Product $product * @param $timeKey * @return int */ protected function getOrderTotal(Product $product, $timeKey) { $productOrders = $product->getProductOrders(); if (!$productOrders) { return 0; } if (!$productOrders->count()) { return 0; } $startDate = $this->getStartDateByTimeKey($timeKey); $finishDate = $this->getFinishDateByTimeKey($timeKey); $counter = 0; foreach ($productOrders->toArray() as $orderProduct) { if (!$startDate || !$finishDate) { $counter += $this->getTotal($orderProduct); continue; } $orderDate = $this->getOrderProductOrderDate($orderProduct); if ($orderDate >= $startDate && $orderDate <= $finishDate) { $counter += $this->getTotal($orderProduct); } } return round($counter); }