/** * 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; }
/** * Get the weight of the product (as object) * * @return Weight */ public function getWeight() { if (!isset($this->arrData['shipping_weight'])) { return null; } return Weight::createFromTimePeriod($this->arrData['shipping_weight']); }
/** * 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; }