/** * Calculate price through hooks and foreign prices * * @param float $fltPrice * @param object $objSource * @param string $strField * @param int $intTaxClass * @param array $arrAddresses * @param array $arrOptions * * @return float */ public static function calculatePrice($fltPrice, $objSource, $strField, $intTaxClass = 0, array $arrAddresses = null, array $arrOptions = array()) { if (!is_numeric($fltPrice)) { return $fltPrice; } // !HOOK: calculate price if (isset($GLOBALS['ISO_HOOKS']['calculatePrice']) && is_array($GLOBALS['ISO_HOOKS']['calculatePrice'])) { foreach ($GLOBALS['ISO_HOOKS']['calculatePrice'] as $callback) { $objCallback = \System::importStatic($callback[0]); $fltPrice = $objCallback->{$callback}[1]($fltPrice, $objSource, $strField, $intTaxClass, $arrOptions); } } $objConfig = static::getConfig(); if ($objConfig->priceMultiplier != 1) { switch ($objConfig->priceCalculateMode) { case 'mul': $fltPrice = $fltPrice * $objConfig->priceCalculateFactor; break; case 'div': $fltPrice = $fltPrice / $objConfig->priceCalculateFactor; break; } } // Possibly add/subtract tax /** @var TaxClass $objTaxClass */ if ($intTaxClass > 0 && ($objTaxClass = TaxClass::findByPk($intTaxClass)) !== null) { $fltPrice = $objTaxClass->calculatePrice($fltPrice, $arrAddresses); } return $fltPrice; }
/** * Create or add taxes for pre-tax collection surcharges * * @param Tax[] $arrTaxes * @param ProductCollectionSurcharge[] $arrSurcharges * @param Address[] $arrAddresses */ private static function addTaxesForSurcharges(array &$arrTaxes, array $arrSurcharges, array $arrAddresses) { foreach ($arrSurcharges as $objSurcharge) { /** @var \Isotope\Model\TaxClass $objTaxClass */ $objTaxClass = TaxClass::findByPk($objSurcharge->tax_class); // Skip products without tax class if (null === $objTaxClass) { continue; } $fltPrice = $objSurcharge->total_price; /** @var \Isotope\Model\TaxRate $objIncludes */ if (($objIncludes = $objTaxClass->getRelated('includes')) !== null) { if ($objIncludes->isApplicable($fltPrice, $arrAddresses)) { $addToTotal = static::getTaxAddState(false); $fltPrice = $addToTotal ? $objIncludes->calculateAmountAddedToPrice($fltPrice) : $objIncludes->calculateAmountIncludedInPrice($fltPrice); $taxId = static::addTax($arrTaxes, $objTaxClass->id . '_' . $objIncludes->id, $objTaxClass->getLabel() ?: $objIncludes->getLabel(), $objIncludes->getAmount(), $objIncludes->isPercentage(), $fltPrice, $objTaxClass->applyRoundingIncrement, $addToTotal, $objTaxClass->notNegative); $objSurcharge->addTaxNumber($taxId); } } if (($objRates = $objTaxClass->getRelated('rates')) !== null) { /** @var \Isotope\Model\TaxRate $objTaxRate */ foreach ($objRates as $objTaxRate) { if ($objTaxRate->isApplicable($fltPrice, $arrAddresses)) { $addToTotal = static::getTaxAddState(true); $fltPrice = $addToTotal ? $objTaxRate->calculateAmountAddedToPrice($fltPrice) : $objTaxRate->calculateAmountIncludedInPrice($fltPrice); $taxId = static::addTax($arrTaxes, $objTaxRate->id, $objTaxRate->getLabel(), $objTaxRate->getAmount(), $objTaxRate->isPercentage(), $fltPrice, $objTaxClass->applyRoundingIncrement, $addToTotal, $objTaxClass->notNegative); $objSurcharge->addTaxNumber($taxId); if ($objTaxRate->stop) { break; } } } } } }
protected static function buildSurcharge($strClass, $strLabel, $objSource, IsotopeProductCollection $objCollection) { $intTaxClass = $objSource->tax_class; /** @var \Isotope\Model\ProductCollectionSurcharge $objSurcharge */ $objSurcharge = new $strClass(); $objSurcharge->label = $strLabel . ' (' . $objSource->getLabel() . ')'; $objSurcharge->price = $objSource->isPercentage() ? $objSource->getPercentage() . '%' : ' '; $objSurcharge->total_price = $objSource->getPrice(); $objSurcharge->tax_free_total_price = $objSource->total_price; $objSurcharge->tax_class = $intTaxClass; $objSurcharge->before_tax = $intTaxClass ? true : false; $objSurcharge->addToTotal = true; if ($intTaxClass == -1) { $objSurcharge->applySplittedTax($objCollection, $objSource); } elseif ($objSurcharge->tax_class > 0) { /** @var \Isotope\Model\TaxClass $objTaxClass */ if (($objTaxClass = TaxClass::findByPk($objSurcharge->tax_class)) !== null) { /** @var \Isotope\Model\TaxRate $objIncludes */ if (($objIncludes = $objTaxClass->getRelated('includes')) !== null) { $fltPrice = $objSurcharge->total_price; $arrAddresses = array('billing' => $objCollection->getBillingAddress(), 'shipping' => $objCollection->getShippingAddress()); if ($objIncludes->isApplicable($fltPrice, $arrAddresses)) { $fltTax = $objIncludes->calculateAmountIncludedInPrice($fltPrice); $objSurcharge->tax_free_total_price = $fltPrice - $fltTax; } } } } return $objSurcharge; }