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         $dBasketPrice = $oBasket->getDiscountProductsPrice()->getBruttoSum();
00147         $dPrice = $this->getPaymentValue( $dBasketPrice );
00148 
00149         // calculating total price
00150         $oPrice = oxNew( 'oxPrice' );
00151         $oPrice->setBruttoPriceMode();
00152         $oPrice->setPrice( $dPrice );
00153 
00154         if ( $this->getConfig()->getConfigParam( 'blCalcVATForPayCharge' ) && $dPrice > 0 ) {
00155             $oPrice->setVat( $oBasket->getMostUsedVatPercent() );
00156         }
00157 
00158         return $oPrice;
00159     }
00160 
00166     public function getCountries()
00167     {
00168         if ( $this->_aCountries === null ) {
00169 
00170             $this->_aCountries = array();
00171             $sSelect = 'select oxobjectid from oxobject2payment where oxpaymentid="'.$this->getId().'" and oxtype = "oxcountry" ';
00172             $rs = oxDb::getDb()->Execute( $sSelect );
00173             if ( $rs && $rs->recordCount()) {
00174                 while ( !$rs->EOF ) {
00175                     $this->_aCountries[] = $rs->fields[0];
00176                     $rs->moveNext();
00177                 }
00178             }
00179         }
00180         return $this->_aCountries;
00181     }
00182 
00190     public function delete( $sOXID = null )
00191     {
00192         if ( parent::delete( $sOXID ) ) {
00193 
00194             $sOXID = $sOXID?$sOXID:$this->getId();
00195 
00196             // deleting payment related data
00197             $rs = oxDb::getDb()->execute( "delete from oxobject2payment where oxpaymentid = '$sOXID' " );
00198             return $rs->EOF;
00199         }
00200 
00201         return false;
00202     }
00203 
00215     public function isValidPayment( $aDynvalue, $sShopId, $oUser, $dBasketPrice, $sShipSetId )
00216     {
00217         if ( $this->oxpayments__oxid->value == 'oxempty' ) {
00218             return true;
00219         }
00220 
00221         $oValidator = oxNew( 'oxinputvalidator' );
00222         if ( !$oValidator->validatePaymentInputData( $this->oxpayments__oxid->value, $aDynvalue ) ) {
00223             return false;
00224         }
00225 
00226         $oCur = $this->getConfig()->getActShopCurrencyObject();
00227         $dBasketPrice = $dBasketPrice / $oCur->rate;
00228 
00229         if ( $sShipSetId ) {
00230             $aPaymentList = oxPaymentList::getInstance()->getPaymentList( $sShipSetId, $dBasketPrice, $oUser );
00231 
00232             if ( !array_key_exists( $this->getId(), $aPaymentList ) ) {
00233                 return false;
00234             }
00235         } else {
00236             return false;
00237         }
00238 
00239         return true;
00240     }
00241 }

Generated on Tue Aug 4 09:09:57 2009 for OXID eShop CE by  doxygen 1.5.5