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 
00111             // generating item key
00112             $this->_oArticle->setItemKey( $sItemKey );
00113         }
00114 
00115         return $this->_oArticle;
00116 
00117     }
00118 
00124     public function __sleep()
00125     {
00126         $aRet = array();
00127         foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00128             if ( $sKey != '_oArticle' ) {
00129                 $aRet[] = $sKey;
00130             }
00131         }
00132         return $aRet;
00133     }
00134 
00140     public function getSelList()
00141     {
00142         if ( $this->_aSelList == null && $this->oxuserbasketitems__oxsellist->value ) {
00143             $this->_aSelList = unserialize( $this->oxuserbasketitems__oxsellist->value );
00144         }
00145 
00146         return $this->_aSelList;
00147     }
00148 
00156     public function setSelList( $aSelList )
00157     {
00158         $this->oxuserbasketitems__oxsellist = new oxField(serialize( $aSelList ), oxField::T_RAW);
00159     }
00160 
00166     public function getPersParams()
00167     {
00168         if ( $this->_aPersParam == null && $this->oxuserbasketitems__oxpersparam->value ) {
00169             $this->_aPersParam = unserialize( $this->oxuserbasketitems__oxpersparam->value );
00170         }
00171 
00172         return $this->_aPersParam;
00173     }
00174 
00182     public function setPersParams( $sPersParams )
00183     {
00184         $this->oxuserbasketitems__oxpersparam = new oxField(serialize($sPersParams), oxField::T_RAW);
00185     }
00186 
00196     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00197     {
00198         if ('oxsellist' === strtolower($sFieldName) || 'oxuserbasketitems__oxsellist' === strtolower($sFieldName)
00199             || 'oxpersparam' === strtolower($sFieldName) || 'oxuserbasketitems__oxpersparam' === strtolower($sFieldName)) {
00200             $iDataType = oxField::T_RAW;
00201         }
00202         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00203     }
00204 }