/**
  * Returns oxDeliveryList instance
  *
  * @return oxDeliveryList
  */
 static function getInstance()
 {
     if (defined('OXID_PHP_UNIT')) {
         if (($oClassMod = modInstances::getMod(__CLASS__)) && is_object($oClassMod)) {
             return $oClassMod;
         } else {
             $inst = oxNew('oxDeliveryList');
             modInstances::addMod(__CLASS__, $inst);
             return $inst;
         }
     }
     if (!isset(self::$_instance)) {
         // allow modules
         self::$_instance = oxNew('oxDeliveryList');
     }
     return self::$_instance;
 }
예제 #2
0
 /**
  * Iterates through basket items and calculates its delivery costs
  *
  * @return oxPrice
  */
 protected function _calcDeliveryCost()
 {
     if ($this->_oDeliveryPrice !== null) {
         return $this->_oDeliveryPrice;
     }
     $myConfig = $this->getConfig();
     $oDeliveryPrice = oxNew('oxprice');
     $oDeliveryPrice->setBruttoPriceMode();
     // don't calculate if not logged in
     $oUser = $this->getBasketUser();
     if (!$oUser && !$myConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn')) {
         return $oDeliveryPrice;
     }
     // VAT for delivery ?
     $fDelVATPercent = 0;
     if ($myConfig->getConfigParam('blCalcVATForDelivery')) {
         $fDelVATPercent = $this->getMostUsedVatPercent();
         $oDeliveryPrice->setVat($fDelVATPercent);
     }
     // list of active delivery costs
     if ($myConfig->getConfigParam('bl_perfLoadDelivery')) {
         $aDeliveryList = oxDeliveryList::getInstance()->getDeliveryList($this, $oUser, $this->_findDelivCountry(), $this->getShippingId());
         if (count($aDeliveryList) > 0) {
             foreach ($aDeliveryList as $oDelivery) {
                 //debug trace
                 if ($myConfig->getConfigParam('iDebug') == 5) {
                     echo "DelCost : " . $oDelivery->oxdelivery__oxtitle->value . "<br>";
                 }
                 $oDeliveryPrice->addPrice($oDelivery->getDeliveryPrice($fDelVATPercent));
             }
         }
     }
     return $oDeliveryPrice;
 }
 /**
  * Loads deliveryset data, checks if it has payments assigned. If active delivery set id
  * is passed - checks if it can be used, if not - takes first ship set id from list which
  * fits. For active ship set collects payment list info. Retuns array containing:
  *   1. all ship sets that has payment (array)
  *   2. active ship set id (string)
  *   3. payment list for active ship set (array)
  *
  * @param string $sShipSet current ship set id (can be null if not set yet)
  * @param oxuser $oUser    active user
  * @param double $oBasket  basket object
  *
  * @return array
  */
 public function getDeliverySetData($sShipSet, $oUser, $oBasket)
 {
     $sActShipSet = null;
     $aActSets = array();
     $aActPaymentList = array();
     if (!$oUser) {
         return;
     }
     $this->_getList($oUser, $oUser->getActiveCountry());
     // if there are no shipsets we dont need to load payments
     if ($this->count()) {
         // one selected ?
         if ($sShipSet && !isset($this->_aArray[$sShipSet])) {
             $sShipSet = null;
         }
         $oPayList = oxPaymentList::getInstance();
         $oDelList = oxDeliveryList::getInstance();
         $oCur = $this->getConfig()->getActShopCurrencyObject();
         $dBasketPrice = $oBasket->getPriceForPayment() / $oCur->rate;
         // checking if these ship sets available (number of possible payment methods > 0)
         foreach ($this as $sShipSetId => $oShipSet) {
             $aPaymentList = $oPayList->getPaymentList($sShipSetId, $dBasketPrice, $oUser);
             if (count($aPaymentList)) {
                 // now checking for deliveries
                 if ($oDelList->hasDeliveries($oBasket, $oUser, $oUser->getActiveCountry(), $sShipSetId)) {
                     $aActSets[$sShipSetId] = $oShipSet;
                     if (!$sShipSet || $sShipSetId == $sShipSet) {
                         $sActShipSet = $sShipSet = $sShipSetId;
                         $aActPaymentList = $aPaymentList;
                         $oShipSet->blSelected = true;
                     }
                 }
             }
         }
     }
     return array($aActSets, $sActShipSet, $aActPaymentList);
 }