/** * Shipping rates sorting callback * * @param \XLite\Model\Shipping\Rate $a First shipping rate * @param \XLite\Model\Shipping\Rate $b Second shipping rate * * @return integer */ protected function compareRates(\XLite\Model\Shipping\Rate $a, \XLite\Model\Shipping\Rate $b) { $aMethod = $a->getMethod(); $bMethod = $b->getMethod(); $aRate = $a->getTotalRate(); $bRate = $b->getTotalRate(); return 'auctionInc' === $aMethod->getProcessor() && 'auctionInc' === $bMethod->getProcessor() ? $aRate === $bRate ? 0 : ($aRate < $bRate ? -1 : 1) : parent::compareRates($a, $b); }
/** * Calculate shipping net price * * @param \XLite\Model\Shipping\Rate $rate Rate * @param float $price Price * * @return float */ public function deductTaxFromPrice(\XLite\Model\Shipping\Rate $rate, $price) { $classes = $rate->getMethod() ? $rate->getMethod()->getClasses() : null; foreach ($this->getTaxes() as $tax) { $includedZones = $tax->getVATZone() ? array($tax->getVATZone()->getZoneId()) : array(); $included = $tax->getFilteredRate($includedZones, $tax->getVATMembership(), $classes); if ($included) { $price -= $included->calculateValueExcludingTax($price); } } return $price; }
/** * Get total rate * * @return float */ public function getTotalRate() { $total = parent::getTotalRate(); if (!\XLite::isAdminZone() && $this->getMethod()) { $total = \XLite\Module\CDev\VAT\Logic\Shipping\Tax::getInstance()->calculateRateCost($this, $total); } return $total; }
/** * Set shipping rate and shipping method id * * @param \XLite\Model\Shipping\Rate $rate Shipping rate object OPTIONAL * * @return void */ public function setSelectedRate(\XLite\Model\Shipping\Rate $rate = null) { $newShippingId = $this->order->getShippingId(); $this->selectedRate = $rate; $newShippingId = $rate ? $rate->getMethodId() : 0; if ($this->order->getShippingId() != $newShippingId) { $this->order->setShippingId($newShippingId); $this->order->setShippingMethodName($rate ? $rate->getMethod()->getName() : null); \XLite\Core\Database::getEM()->flush(); } }
/** * Get rate markup * * @param \XLite\Model\Shipping\Rate $rate Shipping rate * * @return float */ protected function getTotalRate(\XLite\Model\Shipping\Rate $rate) { return $rate->getTotalRate(); }
/** * Get rate method name * * @param \XLite\Model\Shipping\Rate $rate Shipping rate * * @return string */ protected function getMethodName(\XLite\Model\Shipping\Rate $rate) { return $rate->getMethod()->getName(); }
/** * Shipping rates sorting callback * * @param \XLite\Model\Shipping\Rate $a First shipping rate * @param \XLite\Model\Shipping\Rate $b Second shipping rate * * @return integer */ protected function compareRates(\XLite\Model\Shipping\Rate $a, \XLite\Model\Shipping\Rate $b) { $aRate = $a->getTotalRate(); $bRate = $b->getTotalRate(); return $aRate == $bRate ? 0 : ($aRate < $bRate ? -1 : 1); }
/** * Get shipping tax rates * * @param \XLite\Model\Shipping\Rate $rate Shipping rate * @param array $zones Zones list * @param \XLite\Model\Membership $membership Membership OPTIONAL * * @return void */ protected function getShippingTaxRates(\XLite\Model\Shipping\Rate $rate, array $zones, \XLite\Model\Membership $membership = null) { $method = $rate->getMethod(); $taxes = array(); $price = $rate->getTaxableBasis(); foreach ($this->getTaxes() as $tax) { $includedZones = $tax->getVATZone() ? array($tax->getVATZone()->getZoneId()) : array(); $included = $tax->getFilteredRate($includedZones, $tax->getVATMembership(), $method->getClasses()); $r = $tax->getFilteredRate($zones, $membership, $method->getClasses()); if ($included) { $price -= $included->calculateValueExcludingTax($price); } if ($r) { $taxes[$tax->getId()] = array('rate' => $r, 'base' => $price); } } return $taxes; }