/** * Get shipping rates * * @return array(\XLite\Model\Shipping\Rate) */ public function getRates() { $rates = parent::getRates(); $unsetFree = true; // Get total fixed fees value $fixedFee = $this->getItemsFreightFixedFee(); // Get count of items $itemsCount = count($this->getItems()); if (0 == $itemsCount) { // There are no items if (0 < $fixedFee) { // There are items with fixed fee, remove all methods except 'Freight fixed fee' foreach ($rates as $k => $rate) { if (!$this->isFixedFeeMethod($rate->getMethod())) { unset($rates[$k]); } } } else { // There are no items with fixed fee, remove method 'Freight fixed fee' foreach ($rates as $k => $rate) { if ($this->isFixedFeeMethod($rate->getMethod())) { unset($rates[$k]); } } // Are all items marked as Free shipping? $unsetFree = false; foreach ($rates as $rate) { $rate->setBaseRate(0); $rate->setMarkupRate(0); if (!$rate->getMethod()->getFree()) { // Non free shipping method found $unsetFree = true; } } } } // Correct shipping rates list foreach ($rates as $k => $rate) { $doUnset = false; if ($unsetFree && $rate->getMethod()->getFree()) { // Unset 'Free shipping' method $doUnset = true; } elseif (0 < $fixedFee) { if (0 < $itemsCount && $this->isFixedFeeMethod($rate->getMethod())) { // Unset 'Freight fixed fee' method if there are other methods $doUnset = true; } else { // Add fixed fee value to the base rate value $rates[$k]->setBaseRate($rate->getBaseRate() + $fixedFee); } } elseif ($this->isFixedFeeMethod($rate->getMethod())) { $doUnset = true; } if ($doUnset) { unset($rates[$k]); } } return $rates; }