oxpayment.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxPayment extends oxI18n
00008 {
00014     protected $_oGroups = null;
00015 
00022     protected $_aCountries = null;
00023 
00029     protected $_sClassName = 'oxpayment';
00030 
00036     protected $_aDynValues = null;
00037 
00041     public function __construct()
00042     {
00043         parent::__construct();
00044         $this->init( 'oxpayments' );
00045     }
00046 
00052     public function getGroups()
00053     {
00054         if ( $this->_oGroups == null && ( $sOxid = $this->getId() ) ) {
00055 
00056             // usergroups
00057             $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00058 
00059             // performance
00060             $sSelect  = 'select oxgroups.* from oxgroups, oxobject2group ';
00061             $sSelect .= "where oxobject2group.oxobjectid = '$sOxid' ";
00062             $sSelect .= 'and oxobject2group.oxgroupsid=oxgroups.oxid ';
00063             $this->_oGroups->selectString( $sSelect );
00064         }
00065 
00066         return $this->_oGroups;
00067     }
00068 
00076     public function setDynValues( $aDynValues )
00077     {
00078         $this->_aDynValues = $aDynValues;
00079     }
00080 
00089     public function setDynValue( $oKey, $oVal )
00090     {
00091         $this->_aDynValues[$oKey] = $oVal;
00092     }
00093 
00099     public function getDynValues()
00100     {
00101         if ( !$this->_aDynValues ) {
00102             $sRawDynValue = null;
00103             if ( is_object($this->oxpayments__oxvaldesc ) ) {
00104                 $sRawDynValue = $this->oxpayments__oxvaldesc->getRawValue();
00105             }
00106 
00107             $this->_aDynValues = oxUtils::getInstance()->assignValuesFromText( $sRawDynValue );
00108         }
00109         return $this->_aDynValues;
00110     }
00111 
00119     public function getPaymentValue( $dBaseprice )
00120     {
00121         $dRet = 0;
00122 
00123         if ( $this->oxpayments__oxaddsumtype->value == "%") {
00124             $dRet = $dBaseprice * $this->oxpayments__oxaddsum->value/100;
00125         } else {
00126             $oCur = $this->getConfig()->getActShopCurrencyObject();
00127             $dRet = $this->oxpayments__oxaddsum->value * $oCur->rate;
00128         }
00129 
00130         if ( ($dRet * -1 ) > $dBaseprice ) {
00131             $dRet = $dBaseprice;
00132         }
00133 
00134         return $dRet;
00135     }
00136 
00144     public function getPaymentPrice( $oBasket )
00145     {
00146         //getting basket price with applied discounts and vouchers
00147         $dBasketPrice = $oBasket->getPriceForPayment();
00148         $dPrice = $this->getPaymentValue( $dBasketPrice );
00149 
00150         // calculating total price
00151         $oPrice = oxNew( 'oxPrice' );
00152         $oPrice->setBruttoPriceMode();
00153         $oPrice->setPrice( $dPrice );
00154 
00155         if ( $this->getConfig()->getConfigParam( 'blCalcVATForPayCharge' ) && $dPrice > 0 ) {
00156             $oPrice->setVat( $oBasket->getMostUsedVatPercent() );
00157         }
00158 
00159         return $oPrice;
00160     }
00161 
00167     public function getCountries()
00168     {
00169         if ( $this->_aCountries === null ) {
00170 
00171             $this->_aCountries = array();
00172             $sSelect = 'select oxobjectid from oxobject2payment where oxpaymentid="'.$this->getId().'" and oxtype = "oxcountry" ';
00173             $rs = oxDb::getDb()->Execute( $sSelect );
00174             if ( $rs && $rs->recordCount()) {
00175                 while ( !$rs->EOF ) {
00176                     $this->_aCountries[] = $rs->fields[0];
00177                     $rs->moveNext();
00178                 }
00179             }
00180         }
00181         return $this->_aCountries;
00182     }
00183 
00191     public function delete( $sOXID = null )
00192     {
00193         if ( parent::delete( $sOXID ) ) {
00194 
00195             $sOXID = $sOXID?$sOXID:$this->getId();
00196             $oDb = oxDb::getDb();
00197 
00198             // deleting payment related data
00199             $rs = $oDb->execute( "delete from oxobject2payment where oxpaymentid = ".$oDb->quote( $sOXID ) );
00200             return $rs->EOF;
00201         }
00202 
00203         return false;
00204     }
00205 
00217     public function isValidPayment( $aDynvalue, $sShopId, $oUser, $dBasketPrice, $sShipSetId )
00218     {
00219         if ( $this->oxpayments__oxid->value == 'oxempty' ) {
00220             return true;
00221         }
00222 
00223         $oValidator = oxNew( 'oxinputvalidator' );
00224         if ( !$oValidator->validatePaymentInputData( $this->oxpayments__oxid->value, $aDynvalue ) ) {
00225             return false;
00226         }
00227 
00228         $oCur = $this->getConfig()->getActShopCurrencyObject();
00229         $dBasketPrice = $dBasketPrice / $oCur->rate;
00230 
00231         if ( $sShipSetId ) {
00232             $aPaymentList = oxPaymentList::getInstance()->getPaymentList( $sShipSetId, $dBasketPrice, $oUser );
00233 
00234             if ( !array_key_exists( $this->getId(), $aPaymentList ) ) {
00235                 return false;
00236             }
00237         } else {
00238             return false;
00239         }
00240 
00241         return true;
00242     }
00243 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5