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             $this->_aDynValues = oxUtils::getInstance()->assignValuesFromText( $this->oxpayments__oxvaldesc->value );
00103         }
00104         return $this->_aDynValues;
00105     }
00106 
00114     public function getPaymentValue( $dBaseprice )
00115     {
00116         $dRet = 0;
00117 
00118         if ( $this->oxpayments__oxaddsumtype->value == "%") {
00119             $dRet = $dBaseprice * $this->oxpayments__oxaddsum->value/100;
00120         } else {
00121             $oCur = $this->getConfig()->getActShopCurrencyObject();
00122             $dRet = $this->oxpayments__oxaddsum->value * $oCur->rate;
00123         }
00124 
00125         if ( ($dRet * -1 ) > $dBaseprice ) {
00126             $dRet = $dBaseprice;
00127         }
00128 
00129         return $dRet;
00130     }
00131 
00139     public function getPaymentPrice( $oBasket )
00140     {
00141         $dBasketPrice = $oBasket->getDiscountProductsPrice()->getBruttoSum();
00142         $dPrice = $this->getPaymentValue( $dBasketPrice );
00143 
00144         // calculating total price
00145         $oPrice = oxNew( 'oxPrice' );
00146         $oPrice->setBruttoPriceMode();
00147         $oPrice->setPrice( $dPrice );
00148 
00149         if ( $this->getConfig()->getConfigParam( 'blCalcVATForPayCharge' ) && $dPrice > 0 ) {
00150             $oPrice->setVat( $oBasket->getMostUsedVatPercent() );
00151         }
00152 
00153         return $oPrice;
00154     }
00155 
00161     public function getCountries()
00162     {
00163         if ( $this->_aCountries === null ) {
00164 
00165             $this->_aCountries = array();
00166             $sSelect = 'select oxobjectid from oxobject2payment where oxpaymentid="'.$this->getId().'" and oxtype = "oxcountry" ';
00167             $rs = oxDb::getDb()->Execute( $sSelect );
00168             if ( $rs && $rs->recordCount()) {
00169                 while ( !$rs->EOF ) {
00170                     $this->_aCountries[] = $rs->fields[0];
00171                     $rs->moveNext();
00172                 }
00173             }
00174         }
00175         return $this->_aCountries;
00176     }
00177 
00185     public function delete( $sOXID = null )
00186     {
00187         if ( parent::delete( $sOXID ) ) {
00188 
00189             $sOXID = $sOXID?$sOXID:$this->getId();
00190 
00191             // deleting payment related data
00192             $rs = oxDb::getDb()->execute( "delete from oxobject2payment where oxpaymentid = '$sOXID' " );
00193             return $rs->EOF;
00194         }
00195 
00196         return false;
00197     }
00198 
00210     public function isValidPayment( $aDynvalue, $sShopId, $oUser, $dBasketPrice, $sShipSetId )
00211     {
00212         if ( $this->oxpayments__oxid->value == 'oxempty' ) {
00213             return true;
00214         }
00215 
00216         $oValidator = oxNew( 'oxinputvalidator' );
00217         if ( !$oValidator->validatePaymentInputData( $this->oxpayments__oxid->value, $aDynvalue ) ) {
00218             return false;
00219         }
00220 
00221         $oCur = $this->getConfig()->getActShopCurrencyObject();
00222         $dBasketPrice = $dBasketPrice / $oCur->rate;
00223 
00224         if ( $sShipSetId ) {
00225             $aPaymentList = oxPaymentList::getInstance()->getPaymentList( $sShipSetId, $dBasketPrice, $oUser );
00226 
00227             if ( !array_key_exists( $this->getId(), $aPaymentList ) ) {
00228                 return false;
00229             }
00230         } else {
00231             return false;
00232         }
00233 
00234         return true;
00235     }
00236 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5