/** * Calculate the subtotal for each product in the cart * * @param integer $id * @param integer $qty * @param boolean $isvatfree * @return ArrayObject */ private function calcSubtotal(CartItem $item, $isvatfree = false) { foreach ($this->items as $item) { $isrecurring = false; $months = 0; $percentage = 0; $tax = 0; if ("domain" == $item->getType()) { $item->setIsrecurring(true); // Get the billyng cycle / term / recurring period price if ($item->getTerm()) { $priceInfo = ProductsTranches::getTranchebyId($item->getTerm()); $item->setBillingid($priceInfo['BillingCycle']['billing_cycle_id']); $months = $priceInfo['BillingCycle']['months']; } else { $priceInfo = BillingCycle::getDefaultDomainBillingCycle(); $item->setBillingid($priceInfo['billing_cycle_id']); $months = $priceInfo['months']; } $unitprice = $item->getUnitPrice(); $setupfee = 0; // Calculate the price per Quantity $subtotal = $unitprice * $item->getQty(); // check the taxes if (Taxes::get_percentage($item->getTaxId())) { $percentage = Taxes::get_percentage($item->getTaxId()); $tax = $subtotal * $percentage / 100; $price = $subtotal * (100 + $percentage) / 100; } } else { // Get all the product information $product = Products::getAllInfo($item->getId()); // Check the type of the product and get the price information if ($product['ProductsAttributesGroups']['isrecurring']) { $item->setIsrecurring(true); // Get the billyng cycle / term / recurring period price $priceInfo = ProductsTranches::getTranchebyId($item->getTerm()); // Price multiplier $months = $priceInfo['BillingCycle']['months']; $unitprice = $priceInfo['price']; $setupfee = $priceInfo['setupfee']; // Calculate the price per the months per Quantity $subtotal = $unitprice * $months * $item->getQty(); $item->setBillingid($priceInfo['BillingCycle']['billing_cycle_id']); } else { $item->setIsrecurring(false); $unitprice = $product['price_1']; $setupfee = $product['setupfee']; // Calculate the price per Quantity $subtotal = $unitprice * $item->getQty(); } // check the taxes for each product if (!empty($product['tax_id']) && !$isvatfree) { if (!empty($product['Taxes']['percentage']) && is_numeric($product['Taxes']['percentage'])) { $percentage = $product['Taxes']['percentage']; $tax = $subtotal * $percentage / 100; $price = $subtotal * (100 + $percentage) / 100; } } } // ... and add the setup fees $price = $subtotal + $setupfee; $item->setSubtotals(array('months' => $months, 'subtotal' => $subtotal, 'setupfee' => $setupfee, 'price' => $price, 'taxes' => $tax, 'percentage' => $percentage)); } return $this->items; }