Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * 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);
 }
Exemple #3
0
 /**
  * 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();
     }
 }
Exemple #4
0
 /**
  * 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();
 }
Exemple #5
0
 /**
  * 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();
     $aPosition = $aMethod->getPosition();
     $bPosition = $bMethod->getPosition();
     if ('offline' !== $aMethod->getProcessor() && 'offline' !== $bMethod->getProcessor()) {
         if ($aMethod->getProcessor() !== $bMethod->getProcessor()) {
             $aPosition = $aMethod->getParentMethod()->getPosition();
             $bPosition = $bMethod->getParentMethod()->getPosition();
         }
     } elseif ('offline' !== $aMethod->getProcessor()) {
         $aPosition = $aMethod->getParentMethod()->getPosition();
     } elseif ('offline' !== $bMethod->getProcessor()) {
         $bPosition = $bMethod->getParentMethod()->getPosition();
     }
     return $aPosition === $bPosition ? 0 : ($aPosition < $bPosition ? -1 : 1);
 }
Exemple #6
0
 /**
  * Returns delivery time for method
  *
  * @param \XLite\Model\Shipping\Rate $rate Shipping rate
  *
  * @return string
  */
 protected function getMethodDeliveryTime(\XLite\Model\Shipping\Rate $rate)
 {
     return $rate->getMethod() && 'offline' === $rate->getMethod()->getProcessor() ? $rate->getMethod()->getDeliveryTime() : '';
 }
Exemple #7
0
 /**
  * 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)
 {
     $result = 0;
     $sa = $a->getMethod();
     $sb = $b->getMethod();
     if (isset($sa) && isset($sb)) {
         if ($sa->getPosition() > $sb->getPosition()) {
             $result = 1;
         } elseif ($sa->getPosition() < $sb->getPosition()) {
             $result = -1;
         }
     }
     return $result;
 }
Exemple #8
0
 /**
  * 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;
 }