/** * Determine if this tax rate is applicable * * @param float $fltPrice * @param array $arrAddresses * * @return bool */ public function isApplicable($fltPrice, $arrAddresses) { // Tax rate is limited to another store config if ($this->config > 0 && $this->config != Isotope::getConfig()->id) { return false; } // Tax rate is for guests only if ($this->guests && FE_USER_LOGGED_IN === true && !$this->protected) { return false; } // Tax rate is protected but no member is logged in if ($this->protected && FE_USER_LOGGED_IN !== true && !$this->guests) { return false; } // Tax rate is protected and member logged in, check member groups if ($this->protected && FE_USER_LOGGED_IN === true) { $groups = deserialize($this->groups); if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, \FrontendUser::getInstance()->groups))) { return false; } } // !HOOK: use tax rate if (isset($GLOBALS['ISO_HOOKS']['useTaxRate']) && is_array($GLOBALS['ISO_HOOKS']['useTaxRate'])) { foreach ($GLOBALS['ISO_HOOKS']['useTaxRate'] as $callback) { $objCallback = \System::importStatic($callback[0]); $varValue = $objCallback->{$callback}[1]($this, $fltPrice, $arrAddresses); if ($varValue !== true) { return false; } } } $arrAddress = deserialize($this->address); if (!empty($arrAddress) && is_array($arrAddress)) { foreach ($arrAddresses as $name => $objAddress) { if (!in_array($name, $arrAddress)) { continue; } if ($this->countries != '' && !in_array($objAddress->country, trimsplit(',', $this->countries))) { continue; } if ($this->subdivisions != '' && !in_array($objAddress->subdivision, trimsplit(',', $this->subdivisions))) { continue; } // Check if address has a valid postal code if ($this->postalCodes != '') { $arrCodes = \Isotope\Frontend::parsePostalCodes($this->postalCodes); if (!in_array($objAddress->postal, $arrCodes)) { continue; } } $arrPrice = deserialize($this->amount); if (is_array($arrPrice) && !empty($arrPrice) && strlen($arrPrice[0])) { if (strlen($arrPrice[1])) { if ($arrPrice[0] > $fltPrice || $arrPrice[1] < $fltPrice) { continue; } } else { if ($arrPrice[0] != $fltPrice) { continue; } } } if ($this->exemptOnValidVAT) { $validators = deserialize(Isotope::getConfig()->vatNoValidators); if (!empty($validators) && is_array($validators)) { foreach ($validators as $type) { /** @type IsotopeVatNoValidator $service */ $service = new $GLOBALS['ISO_VAT'][$type](); if ($service->exemptTax($objAddress, $this)) { continue 2; } } } } // 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 true or false depending on if shipping method is available * @return bool * @todo must check availability for a specific product collection (and not hardcoded to the current cart) */ public function isAvailable() { 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) { $arrGroups = deserialize($this->groups); if (!is_array($arrGroups) || empty($arrGroups) || !count(array_intersect($arrGroups, \FrontendUser::getInstance()->groups))) { return false; } } if ($this->minimum_total > 0 && $this->minimum_total > Isotope::getCart()->getSubtotal() || $this->maximum_total > 0 && $this->maximum_total < Isotope::getCart()->getSubtotal()) { return false; } $objScale = Isotope::getCart()->addToScale(); if (($minWeight = Weight::createFromTimePeriod($this->minimum_weight)) !== null && $objScale->isLessThan($minWeight)) { return false; } if (($maxWeight = Weight::createFromTimePeriod($this->maximum_weight)) !== null && $objScale->isMoreThan($maxWeight)) { return false; } $objAddress = Isotope::getCart()->getShippingAddress(); $arrCountries = deserialize($this->countries); if (is_array($arrCountries) && !empty($arrCountries) && !in_array($objAddress->country, $arrCountries)) { return false; } $arrSubdivisions = deserialize($this->subdivisions); if (is_array($arrSubdivisions) && !empty($arrSubdivisions) && !in_array($objAddress->subdivision, $arrSubdivisions)) { return false; } // Check if address has a valid postal code if ($this->postalCodes != '') { $arrCodes = \Isotope\Frontend::parsePostalCodes($this->postalCodes); if (!in_array($objAddress->postal, $arrCodes)) { return false; } } $arrTypes = deserialize($this->product_types); if (is_array($arrTypes) && !empty($arrTypes)) { $arrItems = Isotope::getCart()->getItems(); foreach ($arrItems as $objItem) { if (!$objItem->hasProduct() || !in_array($objItem->getProduct()->type, $arrTypes)) { return false; } } } return true; }
/** * Return true or false depending on if shipping method is available * @return bool * @todo must check availability for a specific product collection (and not hardcoded to the current cart) */ public function isAvailable() { 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) { $arrGroups = deserialize($this->groups); if (!is_array($arrGroups) || empty($arrGroups) || !count(array_intersect($arrGroups, \FrontendUser::getInstance()->groups))) { return false; } } if ($this->minimum_total > 0 && $this->minimum_total > Isotope::getCart()->getSubtotal() || $this->maximum_total > 0 && $this->maximum_total < Isotope::getCart()->getSubtotal()) { return false; } $objScale = Isotope::getCart()->addToScale(); if (($minWeight = Weight::createFromTimePeriod($this->minimum_weight)) !== null && $objScale->isLessThan($minWeight)) { return false; } if (($maxWeight = Weight::createFromTimePeriod($this->maximum_weight)) !== null && $objScale->isMoreThan($maxWeight)) { return false; } if ($this->minimum_quantity > 0 || $this->maximum_quantity > 0) { $quantity = 0; if ('cart_items' !== $this->quantity_mode && 'cart_products' !== $this->quantity_mode) { throw new \InvalidArgumentException(sprintf('Unknown quantity mode "%s"', $this->quantity_mode)); } foreach (Isotope::getCart()->getItems() as $item) { if (!$item->hasProduct() || !$item->getProduct()->isExemptFromShipping()) { $quantity += 'cart_items' === $this->quantity_mode ? $item->quantity : 1; } } if ($this->minimum_quantity > 0 && $this->minimum_quantity > $quantity || $this->maximum_quantity > 0 && $this->maximum_quantity < $quantity) { return false; } } $arrConfigs = deserialize($this->config_ids); if (is_array($arrConfigs) && !empty($arrConfigs) && !in_array(Isotope::getConfig()->id, $arrConfigs)) { return false; } $objAddress = Isotope::getCart()->getShippingAddress(); $arrCountries = deserialize($this->countries); if (is_array($arrCountries) && !empty($arrCountries)) { if (!in_array($objAddress->country, $arrCountries)) { return false; } $arrSubdivisions = deserialize($this->subdivisions); if (is_array($arrSubdivisions) && !empty($arrSubdivisions) && !in_array($objAddress->subdivision, $arrSubdivisions)) { return false; } } // Check if address has a valid postal code if ($this->postalCodes != '') { $arrCodes = \Isotope\Frontend::parsePostalCodes($this->postalCodes); if (!in_array($objAddress->postal, $arrCodes)) { return false; } } if ($this->product_types_condition != 'calculation') { $arrConfigTypes = deserialize($this->product_types); if (is_array($arrConfigTypes) && !empty($arrConfigTypes)) { $arrItems = Isotope::getCart()->getItems(); $arrItemTypes = array(); foreach ($arrItems as $objItem) { if ($objItem->hasProduct()) { $arrItemTypes[] = $objItem->getProduct()->type; } elseif ($this->product_types_condition == 'onlyAvailable') { // If one product in cart is not of given type, shipping method is not available return false; } } $arrItemTypes = array_unique($arrItemTypes); switch ($this->product_types_condition) { case 'onlyAvailable': if (count(array_diff($arrItemTypes, $arrConfigTypes)) > 0) { return false; } break; case 'oneAvailable': if (count(array_intersect($arrConfigTypes, $arrItemTypes)) == 0) { return false; } break; case 'allAvailable': if (count(array_intersect($arrConfigTypes, $arrItemTypes)) != count($arrConfigTypes)) { return false; } break; default: throw new \UnexpectedValueException('Unknown product type condition "' . $this->product_types_condition . '"'); } } } return true; }