/** * Determine whether to use the tax rate or not * @param object * @param float * @param array * @return boolean */ public function useTaxRate($objRate, $fltPrice, $arrAddresses) { if ($objRate->config > 0 && $objRate->config != $this->Config->id) { return false; } $objRate->address = deserialize($objRate->address); // HOOK for altering taxes if (isset($GLOBALS['ISO_HOOKS']['useTaxRate']) && is_array($GLOBALS['ISO_HOOKS']['useTaxRate'])) { foreach ($GLOBALS['ISO_HOOKS']['useTaxRate'] as $callback) { $this->import($callback[0]); $varValue = $this->{$callback}[0]->{$callback}[1]($objRate, $fltPrice, $arrAddresses); if ($varValue !== true) { return false; } } } if (is_array($objRate->address) && count($objRate->address)) { foreach ($arrAddresses as $name => $arrAddress) { if (!in_array($name, $objRate->address)) { continue; } if (strlen($objRate->country) && $objRate->country != $arrAddress['country']) { continue; } if (strlen($objRate->subdivision) && $objRate->subdivision != $arrAddress['subdivision']) { continue; } // Check if address has a valid postal code if ($objRate->postalCodes != '') { $arrCodes = IsotopeFrontend::parsePostalCodes($objRate->postalCodes); if (!in_array($arrAddress['postal'], $arrCodes)) { continue; } } $arrPrice = deserialize($objRate->amount); if (is_array($arrPrice) && count($arrPrice) && strlen($arrPrice[0])) { if (strlen($arrPrice[1])) { if ($arrPrice[0] > $fltPrice || $arrPrice[1] < $fltPrice) { continue; } } else { if ($arrPrice[0] != $fltPrice) { continue; } } } // This address is valid, otherwise one of the check would have skipped this (continue) return true; } // No address has passed all checks and returned true return false; } // Addresses are not checked at all, return true return true; }
/** * Return an object property * @param string * @return mixed */ public function __get($strKey) { switch ($strKey) { case 'label': return $this->Isotope->translate($this->arrData['label'] ? $this->arrData['label'] : $this->arrData['name']); break; case 'available': if (!$this->enabled && BE_USER_LOGGED_IN !== true) { return false; } if ($this->guests && FE_USER_LOGGED_IN === true || $this->protected && FE_USER_LOGGED_IN !== true) { return false; } if ($this->protected) { $this->import('FrontendUser', 'User'); $arrGroups = deserialize($this->groups); if (!is_array($arrGroups) || !count($arrGroups) || !count(array_intersect($arrGroups, $this->User->groups))) { return false; } } if ($this->minimum_total > 0 && $this->minimum_total > $this->Isotope->Cart->subTotal || $this->maximum_total > 0 && $this->maximum_total < $this->Isotope->Cart->subTotal) { return false; } $arrCountries = deserialize($this->countries); if (is_array($arrCountries) && !empty($arrCountries) && !in_array($this->Isotope->Cart->shippingAddress['country'], $arrCountries)) { return false; } $arrSubdivisions = deserialize($this->subdivisions); if (is_array($arrSubdivisions) && !empty($arrSubdivisions) && !in_array($this->Isotope->Cart->shippingAddress['subdivision'], $arrSubdivisions)) { return false; } // Check if address has a valid postal code if ($this->postalCodes != '') { $arrCodes = IsotopeFrontend::parsePostalCodes($this->postalCodes); if (!in_array($this->Isotope->Cart->shippingAddress['postal'], $arrCodes)) { return false; } } $arrTypes = deserialize($this->product_types); if (is_array($arrTypes) && count($arrTypes)) { $arrProducts = $this->Isotope->Cart->getProducts(); foreach ($arrProducts as $objProduct) { if (!in_array($objProduct->type, $arrTypes)) { return false; } } } return true; break; case 'price': $strPrice = $this->arrData['price']; $blnPercentage = substr($strPrice, -1) == '%' ? true : false; if ($blnPercentage) { $fltSurcharge = (double) substr($strPrice, 0, -1); $fltPrice = $this->Isotope->Cart->subTotal / 100 * $fltSurcharge; } else { $fltPrice = (double) $strPrice; } return $this->Isotope->calculatePrice($fltPrice, $this, 'price', $this->arrData['tax_class']); break; case 'surcharge': return substr($this->arrData['price'], -1) == '%' ? $this->arrData['price'] : ''; break; } return $this->arrData[$strKey]; }