oxuserbasketitem.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxUserBasketItem extends oxBase
00009 {
00015     protected $_sClassName = 'oxuserbasketitem';
00016 
00022     protected $_oArticle = null;
00023 
00029     protected $_blParentBuyable = false;
00030 
00036     protected $_aSelList = null;
00037 
00043     protected $_aPersParam = null;
00044 
00048     public function __construct()
00049     {
00050         $this->setVariantParentBuyable( $this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) );
00051         parent::__construct();
00052         $this->init( 'oxuserbasketitems' );
00053     }
00054 
00062     public function setVariantParentBuyable( $blBuyable = false )
00063     {
00064         $this->_blParentBuyable = $blBuyable;
00065     }
00066 
00076     public function getArticle( $sItemKey )
00077     {
00078         if ( !$this->oxuserbasketitems__oxartid->value ) {
00079             //this exception may not be caught, anyhow this is a critical exception
00080             $oEx = oxNew( 'oxArticleException' );
00081             $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00082             throw $oEx;
00083         }
00084 
00085         if ( $this->_oArticle === null ) {
00086 
00087             $this->_oArticle = oxNew( 'oxarticle' );
00088 
00089             // performance
00090             /* removed due to #4178
00091              if ( $this->_blParentBuyable ) {
00092                 $this->_oArticle->setNoVariantLoading( true );
00093             }
00094             */
00095 
00096             if ( !$this->_oArticle->load( $this->oxuserbasketitems__oxartid->value ) ) {
00097                 return false;
00098             }
00099 
00100             $aSelList = $this->getSelList();
00101             if ( ( $aSelectlist = $this->_oArticle->getSelectLists() ) && is_array( $aSelList ) ) {
00102                 foreach ( $aSelList as $iKey => $iSel ) {
00103 
00104                     if ( isset( $aSelectlist[$iKey][$iSel] ) ) {
00105                         // cloning select list information
00106                         $aSelectlist[$iKey][$iSel] = clone $aSelectlist[$iKey][$iSel];
00107                         $aSelectlist[$iKey][$iSel]->selected = 1;
00108                     }
00109                 }
00110                 $this->_oArticle->setSelectlist( $aSelectlist );
00111             }
00112 
00113             // generating item key
00114             $this->_oArticle->setItemKey( $sItemKey );
00115         }
00116 
00117         return $this->_oArticle;
00118 
00119     }
00120 
00126     public function __sleep()
00127     {
00128         $aRet = array();
00129         foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00130             if ( $sKey != '_oArticle' ) {
00131                 $aRet[] = $sKey;
00132             }
00133         }
00134         return $aRet;
00135     }
00136 
00142     public function getSelList()
00143     {
00144         if ( $this->_aSelList == null && $this->oxuserbasketitems__oxsellist->value ) {
00145             $this->_aSelList = unserialize( $this->oxuserbasketitems__oxsellist->value );
00146         }
00147 
00148         return $this->_aSelList;
00149     }
00150 
00158     public function setSelList( $aSelList )
00159     {
00160         $this->oxuserbasketitems__oxsellist = new oxField(serialize( $aSelList ), oxField::T_RAW);
00161     }
00162 
00168     public function getPersParams()
00169     {
00170         if ( $this->_aPersParam == null && $this->oxuserbasketitems__oxpersparam->value ) {
00171             $this->_aPersParam = unserialize( $this->oxuserbasketitems__oxpersparam->value );
00172         }
00173 
00174         return $this->_aPersParam;
00175     }
00176 
00184     public function setPersParams( $sPersParams )
00185     {
00186         $this->oxuserbasketitems__oxpersparam = new oxField(serialize($sPersParams), oxField::T_RAW);
00187     }
00188 
00198     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00199     {
00200         if ('oxsellist' === strtolower($sFieldName) || 'oxuserbasketitems__oxsellist' === strtolower($sFieldName)
00201             || 'oxpersparam' === strtolower($sFieldName) || 'oxuserbasketitems__oxpersparam' === strtolower($sFieldName)) {
00202             $iDataType = oxField::T_RAW;
00203         }
00204         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00205     }
00206 }