oxuserbasketitem.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxUserBasketItem extends oxBase
00008 {
00014     protected $_sClassName = 'oxuserbasketitem';
00015 
00021     protected $_oArticle = null;
00022 
00028     protected $_blParentBuyable = false;
00029 
00035     protected $_aSelList = null;
00036 
00042     protected $_aPersParam = null;
00043 
00047     public function __construct()
00048     {
00049         $this->setVariantParentBuyable( $this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) );
00050         parent::__construct();
00051         $this->init( 'oxuserbasketitems' );
00052     }
00053 
00061     public function setVariantParentBuyable( $blBuyable = false )
00062     {
00063         $this->_blParentBuyable = $blBuyable;
00064     }
00065 
00075     public function getArticle( $sItemKey )
00076     {
00077         if ( !$this->oxuserbasketitems__oxartid->value ) {
00078             //this excpetion may not be caught, anyhow this is a critical exception
00079             $oEx = oxNew( 'oxArticleException' );
00080             $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00081             throw $oEx;
00082         }
00083 
00084         if ( $this->_oArticle === null ) {
00085 
00086             $this->_oArticle = oxNew( 'oxarticle' );
00087 
00088             // performance
00089             if ( $this->_blParentBuyable ) {
00090                 $this->_oArticle->setSkipAbPrice( true );
00091                 $this->_oArticle->setNoVariantLoading( true );
00092             }
00093 
00094             if ( !$this->_oArticle->load( $this->oxuserbasketitems__oxartid->value ) ) {
00095                 return false;
00096             }
00097 
00098             $aSelList = $this->getSelList();
00099             if ( ( $aSelectlist = $this->_oArticle->getSelectLists() ) && is_array( $aSelList ) ) {
00100                 foreach ( $aSelList as $iKey => $iSel ) {
00101 
00102                     if ( isset( $aSelectlist[$iKey][$iSel] ) ) {
00103                         // cloning select list information
00104                         $aSelectlist[$iKey][$iSel] = clone $aSelectlist[$iKey][$iSel];
00105                         $aSelectlist[$iKey][$iSel]->selected = 1;
00106                     }
00107                 }
00108                 $this->_oArticle->setSelectlist( $aSelectlist );
00109             }
00110             // formatting title if variant
00111             if ( $this->_oArticle->oxarticles__oxparentid->value ) {
00112                 $oParent = oxNew( 'oxarticle' );
00113                 if ( $oParent->load( $this->_oArticle->oxarticles__oxparentid->value ) ) {
00114                     if ( $this->_oArticle->oxarticles__oxvarselect->value ) {
00115                         $this->_oArticle->oxarticles__oxtitle->value .= ', '.$this->_oArticle->oxarticles__oxvarselect->value;
00116                     }
00117                 }
00118             }
00119 
00120             // generating item key
00121             $this->_oArticle->setItemKey( $sItemKey );
00122         }
00123 
00124         return $this->_oArticle;
00125 
00126     }
00127 
00133     public function __sleep()
00134     {
00135         $aRet = array();
00136         foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00137             if ( $sKey != '_oArticle' ) {
00138                 $aRet[] = $sKey;
00139             }
00140         }
00141         return $aRet;
00142     }
00143 
00149     public function getSelList()
00150     {
00151         if ( $this->_aSelList == null && $this->oxuserbasketitems__oxsellist->value ) {
00152             $this->_aSelList = unserialize( $this->oxuserbasketitems__oxsellist->value );
00153         }
00154 
00155         return $this->_aSelList;
00156     }
00157 
00165     public function setSelList( $aSelList )
00166     {
00167         $this->oxuserbasketitems__oxsellist = new oxField(serialize( $aSelList ), oxField::T_RAW);
00168     }
00169 
00175     public function getPersParams()
00176     {
00177         if ( $this->_aPersParam == null && $this->oxuserbasketitems__oxpersparam->value ) {
00178             $this->_aPersParam = unserialize( $this->oxuserbasketitems__oxpersparam->value );
00179         }
00180 
00181         return $this->_aPersParam;
00182     }
00183 
00191     public function setPersParams( $sPersParams )
00192     {
00193         $this->oxuserbasketitems__oxpersparam = new oxField(serialize($sPersParams), oxField::T_RAW);
00194     }
00195 
00205     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00206     {
00207         if ('oxsellist' === strtolower($sFieldName) || 'oxuserbasketitems__oxsellist' === strtolower($sFieldName)
00208             || 'oxpersparam' === strtolower($sFieldName) || 'oxuserbasketitems__oxpersparam' === strtolower($sFieldName)) {
00209             $iDataType = oxField::T_RAW;
00210         }
00211         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00212     }
00213 }