oxarticle.php

Go to the documentation of this file.
00001 <?php
00002 
00003 // defining supported link types
00004 define( 'OXARTICLE_LINKTYPE_CATEGORY', 0 );
00005 define( 'OXARTICLE_LINKTYPE_VENDOR', 1 );
00006 define( 'OXARTICLE_LINKTYPE_MANUFACTURER', 2 );
00007 define( 'OXARTICLE_LINKTYPE_PRICECATEGORY', 3 );
00008 define( 'OXARTICLE_LINKTYPE_TAG', 4 );
00009 define( 'OXARTICLE_LINKTYPE_RECOMM', 5 );
00010 
00017 class oxArticle extends oxI18n implements oxIArticle, oxIUrl
00018 {
00024     protected $_sCoreTbl = 'oxarticles';
00025 
00031     protected $_sClassName = 'oxarticle';
00032 
00038     protected $_blUseLazyLoading = true;
00039 
00045     protected $_sItemKey;
00046 
00052     protected $_blCalcPrice    = true;
00053 
00058     protected $_oPrice      = null;
00059 
00065     protected $_dArticleVat = null;
00066 
00072     protected $_aPersistParam  = null;
00073 
00079     protected $_blNotBuyable   = false;
00080 
00087     protected $_blLoadVariants = true;
00088 
00094     protected $_aVariants = null;
00095 
00101     protected $_aVariantsWithNotOrderables = null;
00102 
00111     protected $_blNotBuyableParent  = false;
00112 
00113 
00117     protected $_blHasVariants = false;
00118 
00122     protected $_blHasMdVariants = false;
00123 
00128     protected $_blIsOnComparisonList = false;
00129 
00134     protected $_oUser = null;
00135 
00141     protected $_blLoadPrice = true;
00142 
00146     protected $_blSkipAbPrice = false;
00147 
00154     protected $_fPricePerUnit = null;
00155 
00159     protected $_blLoadParentData = false;
00160 
00164     protected $_blSkipAssign = false;
00165 
00171     protected $_blSkipDiscounts = null;
00172 
00177     protected $_oAttributeList = null;
00178 
00179 
00185     protected $_blIsRangePrice = false;
00186 
00192     protected $_aMediaUrls = null;
00193 
00199     static protected $_aLoadedParents;
00200 
00206     static protected $_aSelList;
00207 
00213     protected $_aDispSelList;
00214 
00220     protected $_blIsSeoObject = true;
00221 
00227     protected $_oAmountPriceList = null;
00228 
00237     protected $_iLinkType = 0;
00238 
00244     protected $_aStdUrls = array();
00245 
00251     protected $_aSeoUrls = array();
00252 
00258     protected $_aSeoAddParams = array();
00259 
00265     protected $_aStdAddParams = array();
00266 
00272     protected $_sDynImageDir = null;
00273 
00279     protected $_sMoreDetailLink = null;
00280 
00286     protected $_sToBasketLink = null;
00287 
00293     protected $_iStockStatus = null;
00294 
00300     protected $_oTPrice = null;
00301 
00307     protected $_oAmountPriceInfo = null;
00308 
00314     protected $_dAmountPrice = null;
00315 
00321     protected static $_aArticleManufacturers = array();
00322 
00328     protected static $_aArticleVendors = array();
00329 
00335     protected static $_aArticleCats = array();
00336 
00342     protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00343                                              'oxarticles__oxtimestamp',
00344                                              'oxarticles__oxnid',
00345                                              'oxarticles__oxid',
00346                                              'oxarticles__oxparentid');
00347 
00353     protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00354                                          'oxarticles__oxfreeshipping',
00355                                          'oxarticles__oxremindactive');
00356 
00362     protected $_oMdVariants = null;
00363 
00369     protected $_oLongDesc = null;
00370 
00378     protected $_aVariantSelections = array();
00379 
00384     protected static $_aSelections = array();
00385 
00390     protected static $_aCategoryCache = null;
00395     protected static $_blHasAmountPrice = null;
00396 
00397 
00406     public function __construct($aParams = null)
00407     {
00408         if ( $aParams && is_array($aParams)) {
00409             foreach ( $aParams as $sParam => $mValue) {
00410                 $this->$sParam = $mValue;
00411             }
00412         }
00413         parent::__construct();
00414         $this->init( 'oxarticles' );
00415 
00416         $this->_blIsRangePrice = false;
00417     }
00418 
00427     public function __get($sName)
00428     {
00429         $myUtils = oxUtils::getInstance();
00430         // deprecated since 2011.03.10, should be used getArticleLongDesc() / getLongDesc()
00431         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00432             return $this->getArticleLongDesc();
00433         }
00434 
00435         $this->$sName = parent::__get($sName);
00436         if ( $this->$sName ) {
00437             // since the field could have been loaded via lazyloading
00438             $this->_assignParentFieldValue($sName);
00439         }
00440 
00441         return $this->$sName;
00442     }
00443 
00452     public function __set( $sName, $sValue )
00453     {
00454         // deprecated since 2011.03.14, should be used setArticleLongDesc()
00455         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00456             if ($this->_blEmployMultilanguage) {
00457                 $sValue = ( $sValue instanceof oxField ) ? $sValue->getRawValue() : $sValue;
00458                 $this->setArticleLongDesc( $sValue );
00459             } else {
00460                 $this->$sName = $sValue;
00461             }
00462         } else {
00463             parent::__set( $sName, $sValue );
00464         }
00465     }
00466 
00474     public function setId( $sId = null )
00475     {
00476         $sId = parent::setId( $sId );
00477 
00478         // TODO: in oxbase::setId make it to check if exists and update, not recreate, then delete this overload
00479         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00480 
00481         return $sId;
00482     }
00483 
00493     public function getActiveCheckQuery( $blForceCoreTable = null )
00494     {
00495         $sTable = $this->getViewName( $blForceCoreTable );
00496 
00497         // check if article is still active
00498         $sQ = " $sTable.oxactive = 1 ";
00499 
00500         // enabled time range check ?
00501         if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00502             $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00503             $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00504         }
00505 
00506         return $sQ;
00507     }
00508 
00522     public function getStockCheckQuery( $blForceCoreTable = null )
00523     {
00524         $myConfig = $this->getConfig();
00525         $sTable = $this->getViewName( $blForceCoreTable );
00526 
00527         $sQ = "";
00528 
00529         //do not check for variants
00530         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00531             $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0  ) ";
00532             //V #M513: When Parent article is not purchaseble, it's visibility should be displayed in shop only if any of Variants is available.
00533             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00534                 $sTimeCheckQ = '';
00535                 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00536                      $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00537                      $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00538                 }
00539                 $sQ = " $sQ and IF( $sTable.oxvarcount = 0, 1, ( select 1 from $sTable as art where art.oxparentid=$sTable.oxid and ( art.oxactive = 1 $sTimeCheckQ ) and ( art.oxstockflag != 2 or art.oxstock > 0 ) limit 1 ) ) ";
00540             }
00541         }
00542 
00543         return $sQ;
00544     }
00545 
00557     public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null  )
00558     {
00559         $sTable = $this->getViewName( $blForceCoreTable );
00560         $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00561 
00562         //checking if variant is active and stock status
00563         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00564             $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00565             if ( $blRemoveNotOrderables ) {
00566                 $sQ .= " and $sTable.oxstockflag != 3 ";
00567             }
00568             $sQ .= " ) ) ";
00569         }
00570 
00571         return $sQ;
00572     }
00573 
00581     public function getSqlActiveSnippet( $blForceCoreTable = null )
00582     {
00583         $myConfig = $this->getConfig();
00584 
00585         // check if article is still active
00586         $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00587 
00588         // stock and variants check
00589         $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00590 
00591 
00592         return "( $sQ ) ";
00593     }
00594 
00602     public function setSkipAssign($blSkipAssign)
00603     {
00604         $this->_blSkipAssign = $blSkipAssign;
00605     }
00606 
00612     public function disablePriceLoad()
00613     {
00614         $this->_blLoadPrice = false;
00615     }
00616 
00622     public function getItemKey()
00623     {
00624         return $this->_sItemKey;
00625     }
00626 
00634     public function setItemKey($sItemKey)
00635     {
00636         $this->_sItemKey = $sItemKey;
00637     }
00638 
00646     public function setNoVariantLoading( $blLoadVariants )
00647     {
00648         $this->_blLoadVariants = !$blLoadVariants;
00649     }
00650 
00656     public function isBuyable()
00657     {
00658         if ($this->_blNotBuyableParent) {
00659             return false;
00660         }
00661 
00662         return !$this->_blNotBuyable;
00663     }
00664 
00670     public function getPersParams()
00671     {
00672         return $this->_aPersistParam;
00673     }
00674 
00680     public function isOnComparisonList()
00681     {
00682         return $this->_blIsOnComparisonList;
00683     }
00684 
00692     public function setOnComparisonList( $blOnList )
00693     {
00694         $this->_blIsOnComparisonList = $blOnList;
00695     }
00696 
00704     public function setLoadParentData($blLoadParentData)
00705     {
00706         $this->_blLoadParentData = $blLoadParentData;
00707     }
00708 
00716     public function setSkipAbPrice( $blSkipAbPrice = null )
00717     {
00718         $this->_blSkipAbPrice = $blSkipAbPrice;
00719     }
00720 
00728     public function getSearchableFields()
00729     {
00730         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00731         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00732 
00733         return $aFields;
00734     }
00735 
00736 
00744     public function isMultilingualField($sFieldName)
00745     {
00746         switch ($sFieldName) {
00747             case "oxlongdesc":
00748             case "oxtags":
00749                 return true;
00750         }
00751 
00752         return parent::isMultilingualField($sFieldName);
00753     }
00754 
00760     public function isVisible()
00761     {
00762 
00763         // admin preview mode
00764         if ( ( $blCanPreview = oxUtils::getInstance()->canPreview() ) !== null ) {
00765             return $blCanPreview;
00766         }
00767 
00768         // active ?
00769         $sNow = date('Y-m-d H:i:s');
00770         if ( !$this->oxarticles__oxactive->value &&
00771              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00772                 $this->oxarticles__oxactiveto->value < $sNow
00773              )) {
00774             return false;
00775         }
00776 
00777         // stock flags
00778         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00779             $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00780             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00781                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00782             }
00783             if ( $iOnStock <= 0 ) {
00784                 return false;
00785             }
00786         }
00787 
00788         return true;
00789     }
00790 
00799     public function assign( $aRecord)
00800     {
00801         startProfile('articleAssign');
00802 
00803 
00804         // load object from database
00805         parent::assign( $aRecord);
00806 
00807         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00808 
00809         // check for simple article.
00810         if ($this->_blSkipAssign) {
00811             return;
00812         }
00813 
00814         $this->_assignParentFieldValues();
00815         $this->_assignNotBuyableParent();
00816 
00817         $this->_assignStock();
00818         startProfile('articleAssignPrices');
00819         $this->_assignPrices();
00820         stopProfile('articleAssignPrices');
00821         $this->_assignPersistentParam();
00822         $this->_assignDynImageDir();
00823         $this->_assignComparisonListFlag();
00824         $this->_assignAttributes();
00825 
00826 
00827         //$this->_seoAssign();
00828 
00829         stopProfile('articleAssign');
00830     }
00831 
00842     public function load( $oxID)
00843     {
00844         // A. #1325 resetting to avoid problems when reloading (details etc)
00845         $this->_blNotBuyableParent = false;
00846 
00847         $blRet = parent::load( $oxID);
00848 
00849         // convert date's to international format
00850         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00851         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00852 
00853         return $blRet;
00854     }
00855 
00863     public function addToRatingAverage( $iRating)
00864     {
00865         $dOldRating = $this->oxarticles__oxrating->value;
00866         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00867         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00868         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00869         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00870         $dRatingCnt = (int) ($dOldCnt + 1);
00871         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00872         $oDb = oxDb::getDb();
00873         $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00874     }
00875 
00881     public function getArticleRatingAverage()
00882     {
00883         return round( $this->oxarticles__oxrating->value, 1);
00884     }
00885 
00891     public function getReviews()
00892     {
00893         $aIds = array($this->getId());
00894 
00895         if ( $this->oxarticles__oxparentid->value ) {
00896             $aIds[] = $this->oxarticles__oxparentid->value;
00897         }
00898 
00899         // showing variant reviews ..
00900         if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00901             $aAdd = $this->_getVariantsIds();
00902             if (is_array($aAdd)) {
00903                 $aIds = array_merge($aIds, $aAdd);
00904             }
00905         }
00906 
00907         $oReview = oxNew('oxreview');
00908         $oRevs = $oReview->loadList('oxarticle', $aIds);
00909 
00910         //if no review found, return null
00911         if ( $oRevs->count() < 1 ) {
00912             return null;
00913         }
00914 
00915         return $oRevs;
00916     }
00917 
00923     public function getCrossSelling()
00924     {
00925         $oCrosslist = oxNew( "oxarticlelist");
00926         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00927         if ( $oCrosslist->count() ) {
00928             return $oCrosslist;
00929         }
00930     }
00931 
00937     public function getAccessoires()
00938     {
00939         $myConfig = $this->getConfig();
00940 
00941         // Performance
00942         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00943             return;
00944         }
00945 
00946         $oAcclist = oxNew( "oxarticlelist");
00947         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00948         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00949 
00950         if ( $oAcclist->count()) {
00951             return $oAcclist;
00952         }
00953     }
00954 
00960     public function getSimilarProducts()
00961     {
00962         // Performance
00963         $myConfig = $this->getConfig();
00964         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
00965             return;
00966         }
00967 
00968         $sArticleTable = $this->getViewName();
00969 
00970         $sAttribs = '';
00971         $iCnt = 0;
00972         $this->_getAttribsString($sAttribs, $iCnt);
00973 
00974         if ( !$sAttribs) {
00975             return null;
00976         }
00977 
00978         $aList = $this->_getSimList($sAttribs, $iCnt);
00979 
00980         if ( count( $aList ) ) {
00981             uasort( $aList, 'cmpart');
00982 
00983             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
00984 
00985             $oSimilarlist = oxNew( 'oxarticlelist' );
00986             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
00987             $oSimilarlist->selectString( $sSearch);
00988 
00989             return $oSimilarlist;
00990         }
00991     }
00992 
00998     public function getCustomerAlsoBoughtThisProducts()
00999     {
01000         // Performance
01001         $myConfig = $this->getConfig();
01002         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01003             return;
01004         }
01005 
01006         // selecting products that fits
01007         $sQ = $this->_generateSearchStrForCustomerBought();
01008 
01009         $oArticles = oxNew( 'oxarticlelist' );
01010         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01011         $oArticles->selectString( $sQ );
01012         if ( $oArticles->count() ) {
01013             return $oArticles;
01014         }
01015     }
01016 
01023     public function loadAmountPriceInfo()
01024     {
01025         $myConfig = $this->getConfig();
01026         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice || !$this->hasAmountPrice() ) {
01027             return array();
01028         }
01029 
01030         if ( $this->_oAmountPriceInfo === null ) {
01031             $this->_oAmountPriceInfo = array();
01032             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01033                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01034             }
01035         }
01036         return $this->_oAmountPriceInfo;
01037     }
01038 
01046     public function getSelectLists($sKeyPrefix = null)
01047     {
01048         //#1468C - more then one article in basket with different selectlist...
01049         //optionall function parameter $sKeyPrefix added, used only in basket.php
01050         $sKey = $this->getId();
01051         if ( isset( $sKeyPrefix ) ) {
01052             $sKey = $sKeyPrefix.'__'.$this->getId();
01053         }
01054 
01055         if ( !isset( self::$_aSelList[$sKey] ) ) {
01056             $oDb = oxDb::getDb();
01057             $sSLViewName = getViewName( 'oxselectlist' );
01058 
01059             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01060                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01061 
01062             // all selectlists this article has
01063             $oLists = oxNew( 'oxlist' );
01064             $oLists->init( 'oxselectlist' );
01065             $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01066 
01067             //#1104S if this is variant ant it has no selectlists, trying with parent
01068             if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01069                 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01070             }
01071 
01072             $dVat = 0;
01073             if ( $this->getPrice() != null ) {
01074                 $dVat = $this->getPrice()->getVat();
01075             }
01076 
01077             $iCnt = 0;
01078             self::$_aSelList[$sKey] = array();
01079             foreach ( $oLists as $oSelectlist ) {
01080                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01081                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01082                 $iCnt++;
01083             }
01084         }
01085         return self::$_aSelList[$sKey];
01086     }
01087 
01095     protected function _hasAnyVariant( $blForceCoreTable = null )
01096     {
01097         $blHas = false;
01098         if ( ( $sId = $this->getId() ) ) {
01099             if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01100                 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01101             } else {
01102                 $sArticleTable = $this->getViewName( $blForceCoreTable );
01103                 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01104             }
01105 
01106         }
01107         return $blHas;
01108     }
01109 
01115     public function hasMdVariants()
01116     {
01117         return $this->_blHasMdVariants;
01118     }
01119 
01129     public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01130     {
01131 
01132         $iLimit = (int) $iLimit;
01133         if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01134             $this->_aVariantSelections[$iLimit] = false;
01135             if ( $this->oxarticles__oxvarcount->value ) {
01136                 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $this->getVariants(), $aFilterIds, $sActVariantId, $iLimit );
01137             }
01138         }
01139         return $this->_aVariantSelections[$iLimit];
01140     }
01141 
01150     public function getSelections( $iLimit = null, $aFilter = null )
01151     {
01152         $sId = $this->getId() . ( (int) $iLimit );
01153         if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01154 
01155             $oDb = oxDb::getDb();
01156             $sSLViewName = getViewName( 'oxselectlist' );
01157 
01158             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01159                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01160 
01161             if ( ( $iLimit = (int) $iLimit ) ) {
01162                 $sQ .= " limit $iLimit ";
01163             }
01164 
01165             // vat value for price
01166             $dVat = 0;
01167             if ( ( $oPrice = $this->getPrice() ) != null ) {
01168                 $dVat = $oPrice->getVat();
01169             }
01170 
01171             // all selectlists this article has
01172             $oList = oxNew( 'oxlist' );
01173             $oList->init( 'oxselectlist' );
01174             $oList->getBaseObject()->setVat( $dVat );
01175             $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01176 
01177             //#1104S if this is variant and it has no selectlists, trying with parent
01178             if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01179                 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01180             }
01181 
01182             self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01183         }
01184 
01185         if ( self::$_aSelections[$sId] ) {
01186             // marking active from filter
01187             $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01188             if ( $aFilter ) {
01189                 $iSelIdx = 0;
01190                 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01191                     if ( isset( $aFilter[$iSelIdx] ) ) {
01192                         $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01193                     }
01194                     $iSelIdx++;
01195                 }
01196             }
01197         }
01198 
01199         return self::$_aSelections[$sId];
01200     }
01201 
01211     protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01212     {
01213         $oVariants = array();
01214         if ( ( $sId = $this->getId() ) ) {
01215             //do not load me as a parent later
01216             self::$_aLoadedParents[$sId] = $this;
01217 
01218             $myConfig = $this->getConfig();
01219 
01220             if ( !$this->_blLoadVariants ||
01221                 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01222                 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01223                 return $oVariants;
01224             }
01225 
01226             // cache
01227             $sCacheKey = $blSimple ? "simple" : "full";
01228             if ( $blRemoveNotOrderables ) {
01229                 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01230                    return $this->_aVariants[$sCacheKey];
01231                 } else {
01232                     $this->_aVariants[$sCacheKey] = & $oVariants;
01233                 }
01234             } elseif ( !$blRemoveNotOrderables ) {
01235                 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01236                     return $this->_aVariantsWithNotOrderables[$sCacheKey];
01237                 } else {
01238                     $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01239                 }
01240             }
01241 
01242             if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01243 
01244                 //load simple variants for lists
01245                 if ( $blSimple ) {
01246                     $oVariants = oxNew( 'oxsimplevariantlist' );
01247                     $oVariants->setParent( $this );
01248                 } else {
01249                     //loading variants
01250                     $oVariants = oxNew( 'oxarticlelist' );
01251                     $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01252                 }
01253 
01254                 startProfile("selectVariants");
01255                 $blUseCoreTable = (bool) $blForceCoreTable;
01256                 $oBaseObject = $oVariants->getBaseObject();
01257                 $oBaseObject->setLanguage( $this->getLanguage() );
01258 
01259 
01260                 $sArticleTable = $this->getViewName( $blUseCoreTable );
01261 
01262                 $sSelect = "select ".$oBaseObject->getSelectFields( $blUseCoreTable )." from $sArticleTable where " .
01263                            $this->getActiveCheckQuery( $blUseCoreTable ) .
01264                            $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01265                            " order by $sArticleTable.oxsort";
01266 
01267 
01268                 $oVariants->selectString( $sSelect );
01269 
01270                 //if this is multidimensional variants, make additional processing
01271                 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01272                     $oMdVariants = oxNew( "oxVariantHandler" );
01273                     $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01274                 }
01275                 stopProfile("selectVariants");
01276             }
01277 
01278             //if we have variants then depending on config option the parent may be non buyable
01279             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01280                 $this->_blNotBuyableParent = true;
01281             }
01282 
01283             //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01284             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01285                 $this->_blNotBuyable = true;
01286             }
01287         }
01288         return $oVariants;
01289     }
01290 
01299     public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01300     {
01301         return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01302     }
01303 
01312     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null  )
01313     {
01314         return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01315     }
01316 
01322     public function getSimpleVariants()
01323     {
01324         if ( $this->oxarticles__oxvarcount->value) {
01325             return $this->getVariants();
01326         }
01327     }
01328 
01337     public function getAdminVariants( $sLanguage = null )
01338     {
01339         $oVariants = oxNew( 'oxarticlelist');
01340         if ( ( $sId = $this->getId() ) ) {
01341 
01342             $oBaseObj = $oVariants->getBaseObject();
01343 
01344             if ( is_null( $sLanguage ) ) {
01345                 $oBaseObj->setLanguage( oxLang::getInstance()->getBaseLanguage() );
01346             } else {
01347                 $oBaseObj->setLanguage( $sLanguage );
01348             }
01349 
01350             $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01351             $oVariants->selectString( $sSql );
01352 
01353             //if we have variants then depending on config option the parent may be non buyable
01354             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01355                 //$this->blNotBuyable = true;
01356                 $this->_blNotBuyableParent = true;
01357             }
01358         }
01359 
01360         return $oVariants;
01361     }
01362 
01370     public function getCategory()
01371     {
01372         $oCategory = oxNew( 'oxcategory' );
01373         $oCategory->setLanguage( $this->getLanguage() );
01374 
01375         // variant handling
01376         $sOXID = $this->getId();
01377         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01378             $sOXID = $this->oxarticles__oxparentid->value;
01379         }
01380 
01381         if ( $sOXID ) {
01382             // if the oxcategory instance of this article is not cached
01383             if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01384                 startPRofile( 'getCategory' );
01385                 $oStr = getStr();
01386                 $sWhere   = $oCategory->getSqlActiveSnippet();
01387                 $sSelect  = $this->_generateSearchStr( $sOXID );
01388                 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01389 
01390                 // category not found ?
01391                 if ( !$oCategory->assignRecord( $sSelect ) ) {
01392 
01393                     $sSelect  = $this->_generateSearchStr( $sOXID, true );
01394                     $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01395 
01396                     // looking for price category
01397                     if ( !$oCategory->assignRecord( $sSelect ) ) {
01398                         $oCategory = null;
01399                     }
01400                 }
01401                 // add the category instance to cache
01402                 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01403                 stopPRofile( 'getCategory' );
01404             } else {
01405                // if the oxcategory instance is cached
01406                $oCategory = $this->_aCategoryCache[ $sOXID ];
01407             }
01408         }
01409 
01410         return $oCategory;
01411     }
01412 
01421     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01422     {
01423         $myConfig = $this->getConfig();
01424         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01425             return self::$_aArticleCats[$this->getId()];
01426         }
01427 
01428         // variant handling
01429         $sOXID = $this->getId();
01430         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01431             $sOXID = $this->oxarticles__oxparentid->value;
01432         }
01433 
01434         // we do not use lists here as we dont need this overhead right now
01435         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01436         $oDB = oxDb::getDb(true);
01437         $rs = $oDB->execute( $sSql );
01438 
01439 
01440         $aRet = array();
01441 
01442         if ($rs != false && $rs->recordCount() > 0) {
01443             while (!$rs->EOF) {
01444                 $aRet[] = $rs->fields['oxcatnid'];
01445                 $rs->moveNext();
01446             }
01447         }
01448 
01449         // adding price categories if such exists
01450         $sSql = $this->getSqlForPriceCategories();
01451 
01452         $oDB = oxDb::getDb( true );
01453         $rs = $oDB->execute( $sSql );
01454 
01455         if ($rs != false && $rs->recordCount() > 0) {
01456             while (!$rs->EOF) {
01457 
01458                 if ( is_array( $rs->fields ) ) {
01459                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01460                 }
01461 
01462 
01463                 if ( !$aRet[$rs->fields['oxid']] ) {
01464                     $aRet[] = $rs->fields['oxid'];
01465                 }
01466                 $rs->moveNext();
01467             }
01468         }
01469 
01470         return self::$_aArticleCats[$this->getId()] = $aRet;
01471     }
01472 
01481     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01482     {
01483         $sO2CView = $this->_getObjectViewName('oxobject2category');
01484         $sCatView = $this->_getObjectViewName('oxcategories');
01485         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01486         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01487         if ( $blActCats ) {
01488             $sSelect .= "and oxcategories.oxhidden = 0 and (select count(cats.oxid) from $sCatView as cats where cats.oxrootid = oxcategories.oxrootid and cats.oxleft < oxcategories.oxleft and cats.oxright > oxcategories.oxright and ( cats.oxhidden = 1 or cats.oxactive = 0 ) ) = 0 ";
01489         }
01490         $sSelect .= 'order by oxobject2category.oxtime ';
01491         return $sSelect;
01492     }
01493 
01503     public function getVendor( $blShopCheck = true )
01504     {
01505         if ( ( $sVendorId = $this->getVendorId() ) ) {
01506             $oVendor = oxNew( 'oxvendor' );
01507         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01508                 $oVendor = oxNew( 'oxi18n' );
01509                 $oVendor->init('oxvendor');
01510                 $oVendor->setReadOnly( true );
01511             $sVendorId = $this->oxarticles__oxvendorid->value;
01512         }
01513         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01514 
01515             //@deprecated in v.4.5.7, since 2012-02-15; config option removed bug #0003385
01516             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01517                 $oVendor->setReadOnly( true );
01518             }
01519             return $oVendor;
01520         }
01521         return null;
01522     }
01523 
01531     public function getVendorId( $blForceReload = false )
01532     {
01533         $sVendorId = false;
01534         if ( $this->oxarticles__oxvendorid->value ) {
01535                 $sVendorId = $this->oxarticles__oxvendorid->value;
01536 
01537         }
01538         return $sVendorId;
01539     }
01540 
01548     public function getManufacturerId( $blForceReload = false )
01549     {
01550         $sManufacturerId = false;
01551         if ( $this->oxarticles__oxmanufacturerid->value ) {
01552 
01553                 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01554 
01555         }
01556         return $sManufacturerId;
01557     }
01558 
01568     public function getManufacturer( $blShopCheck = true )
01569     {
01570             $oManufacturer = oxNew( 'oxmanufacturer' );;
01571         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01572              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01573             $oManufacturer->setReadOnly( true );
01574             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01575         }
01576 
01577         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01578             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01579                 $oManufacturer->setReadOnly( true );
01580             }
01581             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01582         } else {
01583             $oManufacturer = null;
01584         }
01585 
01586         return $oManufacturer;
01587     }
01588 
01596     public function inCategory( $sCatNid)
01597     {
01598         return in_array( $sCatNid, $this->getCategoryIds());
01599     }
01600 
01609     public function isAssignedToCategory( $sCatId )
01610     {
01611         // variant handling
01612         $sOXID = $this->getId();
01613         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01614             $sOXID = $this->oxarticles__oxparentid->value;
01615         }
01616 
01617         $oDB = oxDb::getDb();
01618         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01619         $sOXID = $oDB->getOne( $sSelect);
01620         // article is assigned to passed category!
01621         if ( isset( $sOXID) && $sOXID) {
01622             return true;
01623         }
01624 
01625         // maybe this category is price category ?
01626         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01627             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01628             if ( $dPriceFromTo > 0) {
01629                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01630                 $sOXID = $oDB->getOne( $sSelect);
01631                 // article is assigned to passed category!
01632                 if ( isset( $sOXID) && $sOXID) {
01633                     return true;
01634                 }
01635             }
01636         }
01637         return false;
01638     }
01639 
01645     public function getTPrice()
01646     {
01647         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01648             return;
01649         }
01650         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01651         if ( $this->_oTPrice !== null ) {
01652             return $this->_oTPrice;
01653         }
01654 
01655         $this->_oTPrice = oxNew( 'oxPrice' );
01656         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01657 
01658         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01659         $this->_applyCurrency( $this->_oTPrice );
01660 
01661         return $this->_oTPrice;
01662     }
01663 
01669     public function skipDiscounts()
01670     {
01671         // allready loaded skip discounts config
01672         if ( $this->_blSkipDiscounts !== null ) {
01673             return $this->_blSkipDiscounts;
01674         }
01675 
01676         if ( $this->oxarticles__oxskipdiscounts->value ) {
01677             return true;
01678         }
01679 
01680 
01681         $this->_blSkipDiscounts = false;
01682         if ( oxDiscountList::getInstance()->hasSkipDiscountCategories() ) {
01683 
01684             $oDb = oxDb::getDb();
01685             $sO2CView  = getViewName( 'oxobject2category', $this->getLanguage() );
01686             $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01687             $sSelect =  "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01688                          where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01689             $this->_blSkipDiscounts = ( $oDb->getOne($sSelect) == 1 );
01690         }
01691         return $this->_blSkipDiscounts;
01692     }
01693 
01701     public function setPrice(oxPrice $oPrice)
01702     {
01703         $this->_oPrice = $oPrice;
01704     }
01705 
01714     public function getBasePrice( $dAmount = 1 )
01715     {
01716         // override this function if you want e.g. different prices
01717         // for diff. usergroups.
01718 
01719         // Performance
01720         $myConfig = $this->getConfig();
01721         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01722             return;
01723 
01724         // GroupPrice or DB price ajusted by AmountPrice
01725         $dPrice = $this->_getAmountPrice( $dAmount );
01726 
01727 
01728         return $dPrice;
01729     }
01730 
01738     public function getPrice( $dAmount = 1 )
01739     {
01740         $myConfig = $this->getConfig();
01741         // Performance
01742         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01743             return;
01744         }
01745 
01746         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01747         if ( $dAmount != 1 || $this->_oPrice === null ) {
01748             $oPrice = oxNew( 'oxPrice' );
01749 
01750             // get base
01751             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01752 
01753             // price handling
01754             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01755                 return $this->_oPrice = $oPrice;
01756             }
01757 
01758             $this->_calculatePrice( $oPrice );
01759             if ( $dAmount != 1 ) {
01760                 return $oPrice;
01761             }
01762 
01763             $this->_oPrice = $oPrice;
01764         }
01765         return $this->_oPrice;
01766     }
01767 
01776     protected function _calculatePrice( $oPrice, $dVat = null )
01777     {
01778         // apply VAT only if configuration requires it
01779         if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01780             $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01781         }
01782 
01783         // apply currency
01784         $this->_applyCurrency( $oPrice );
01785         // apply discounts
01786         if ( !$this->skipDiscounts() ) {
01787             $oDiscountList = oxDiscountList::getInstance();
01788             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
01789         }
01790 
01791         return $oPrice;
01792     }
01793 
01801     public function setArticleUser($oUser)
01802     {
01803         $this->_oUser = $oUser;
01804     }
01805 
01811     public function getArticleUser()
01812     {
01813         if ($this->_oUser) {
01814             return $this->_oUser;
01815         }
01816         return $this->getUser();
01817     }
01818 
01828     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01829     {
01830         $oUser = $oBasket->getBasketUser();
01831         $this->setArticleUser( $oUser );
01832 
01833         $oBasketPrice = oxNew( 'oxPrice' );
01834 
01835         // get base price
01836         $dBasePrice = $this->getBasePrice( $dAmount );
01837 
01838         // applying select list price
01839         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01840 
01841         // setting price
01842         $oBasketPrice->setPrice( $dBasePrice );
01843 
01844         $dVat = oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket );
01845         $this->_calculatePrice( $oBasketPrice, $dVat );
01846 
01847         // returning final price object
01848         return $oBasketPrice;
01849     }
01850 
01863     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01864     {
01865         $oDiscountList = oxDiscountList::getInstance();
01866         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01867     }
01868 
01877     public function delete( $sOXID = null )
01878     {
01879         if ( !$sOXID ) {
01880             $sOXID = $this->getId();
01881         }
01882         if ( !$sOXID ) {
01883             return false;
01884         }
01885 
01886 
01887         // #2339 delete first variants before deleting parent product
01888         $this->_deleteVariantRecords( $sOXID );
01889         $this->load( $sOXID );
01890         $this->_deletePics();
01891         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01892 
01893         // delete self
01894         parent::delete( $sOXID );
01895 
01896         $rs = $this->_deleteRecords( $sOXID );
01897 
01898         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01899 
01900         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01901 
01902         return $rs->EOF;
01903     }
01904 
01913     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01914     {
01915         $this->beforeUpdate();
01916 
01917         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01918         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01919             $dAmount += $iStockCount;
01920             $iStockCount = 0;
01921         }
01922         $this->oxarticles__oxstock = new oxField($iStockCount);
01923 
01924         $oDb = oxDb::getDb();
01925         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01926         $this->onChange( ACTION_UPDATE_STOCK );
01927         return $dAmount;
01928     }
01929 
01938     public function updateSoldAmount( $dAmount = 0 )
01939     {
01940         if ( !$dAmount ) {
01941             return;
01942         }
01943 
01944         $this->beforeUpdate();
01945 
01946         // article is not variant - should be updated current amount
01947         if ( !$this->oxarticles__oxparentid->value ) {
01948             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01949             $dAmount = (double) $dAmount;
01950             $oDb = oxDb::getDb();
01951             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01952         } elseif ( $this->oxarticles__oxparentid->value) {
01953             // article is variant - should be updated this article parent amount
01954             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01955             $oUpdateArticle->updateSoldAmount( $dAmount );
01956         }
01957 
01958         $this->onChange( ACTION_UPDATE );
01959 
01960         return $rs;
01961     }
01962 
01968     public function disableReminder()
01969     {
01970         $oDB = oxDb::getDb(true);
01971         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01972     }
01973 
01981     public function save()
01982     {
01983         // @deprecated since 20110821. folders are no more written, getters must be user for urls
01984         $this->oxarticles__oxthumb = new oxField( basename( $this->oxarticles__oxthumb->value ), oxField::T_RAW );
01985         $this->oxarticles__oxicon  = new oxField( basename( $this->oxarticles__oxicon->value ), oxField::T_RAW );
01986         $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
01987         for ( $i = 1; $i <= $iPicCount; $i++ ) {
01988             $sFieldName = 'oxarticles__oxpic' . $i;
01989             if ( isset( $this->$sFieldName ) ) {
01990                 $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );
01991             }
01992         }
01993         // @end deprecated
01994 
01995         if ( ( $blRet = parent::save() ) ) {
01996             // saving long descrition
01997             $this->_saveArtLongDesc();
01998         }
01999 
02000         return $blRet;
02001     }
02002 
02003 
02010     public function getPictureGallery()
02011     {
02012         $myConfig = $this->getConfig();
02013 
02014         //initialize
02015         $blMorePic = false;
02016         $aArtPics  = array();
02017         $aArtIcons = array();
02018         $iActPicId = 1;
02019         $sActPic = $this->getPictureUrl( $iActPicId );
02020 
02021         if ( oxConfig::getParameter( 'actpicid' ) ) {
02022             $iActPicId = oxConfig::getParameter('actpicid');
02023         }
02024 
02025         $oStr = getStr();
02026         $iCntr = 0;
02027         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02028         $blCheckActivePicId = true;
02029 
02030         for ( $i = 1; $i <= $iPicCount; $i++) {
02031             $sPicVal = $this->getPictureUrl( $i );
02032             $sIcoVal = $this->getIconUrl( $i );
02033             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02034                  !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02035                 if ($iCntr) {
02036                     $blMorePic = true;
02037                 }
02038                 $aArtIcons[$i]= $sIcoVal;
02039                 $aArtPics[$i]= $sPicVal;
02040                 $iCntr++;
02041 
02042                 if ($iActPicId == $i) {
02043                     $sActPic = $sPicVal;
02044                     $blCheckActivePicId = false;
02045                 }
02046 
02047             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02048                 // if picture is empty, setting active pic id to next
02049                 // picture
02050                 $iActPicId++;
02051             }
02052         }
02053 
02054         $blZoomPic  = false;
02055         $aZoomPics = array();
02056         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02057 
02058         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02059             $sVal = $this->getZoomPictureUrl($j);
02060 
02061             if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02062                 $blZoomPic = true;
02063                 $aZoomPics[$c]['id'] = $c;
02064                 $aZoomPics[$c]['file'] = $sVal;
02065                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02066                 if (!$sVal) {
02067                     $aZoomPics[$c]['file'] = "nopic.jpg";
02068                 }
02069                 $c++;
02070             }
02071         }
02072 
02073         $aPicGallery = array('ActPicID' => $iActPicId,
02074                              'ActPic' => $sActPic,
02075                              'MorePics' => $blMorePic,
02076                              'Pics' => $aArtPics,
02077                              'Icons' => $aArtIcons,
02078                              'ZoomPic' => $blZoomPic,
02079                              'ZoomPics' => $aZoomPics);
02080 
02081         return $aPicGallery;
02082     }
02083 
02097     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02098     {
02099         $myConfig = $this->getConfig();
02100 
02101         if (!isset($sOXID)) {
02102             if ( $this->getId()) {
02103                 $sOXID = $this->getId();
02104             }
02105             if (!isset ($sOXID)) {
02106                 $sOXID = $this->oxarticles__oxid->value;
02107             }
02108             if ($this->oxarticles__oxparentid->value) {
02109                 $sParentID = $this->oxarticles__oxparentid->value;
02110             }
02111         }
02112         if (!isset($sOXID)) {
02113             return;
02114         }
02115 
02116         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02117         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02118             //if article has variants then updating oxvarstock field
02119             //getting parent id
02120             if (!isset($sParentID)) {
02121                 $oDb = oxDb::getDb();
02122                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02123                 $sParentID = $oDb->getOne($sQ);
02124             }
02125             //if we have parent id then update stock
02126             if ($sParentID) {
02127                 $this->_onChangeUpdateStock($sParentID);
02128             }
02129         }
02130         //if we have parent id then update count
02131         //update count even if blUseStock is not active
02132         if ($sParentID) {
02133             $this->_onChangeUpdateVarCount($sParentID);
02134         }
02135 
02136         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02137         $this->_onChangeUpdateMinVarPrice( $sId );
02138 
02139             // reseting articles count cache if stock has changed and some
02140             // articles goes offline (M:1448)
02141             if ( $sAction === ACTION_UPDATE_STOCK ) {
02142                 $this->_onChangeStockResetCount( $sOXID );
02143             }
02144 
02145     }
02146 
02153     public function getCustomVAT()
02154     {
02155         if ( isset($this->oxarticles__oxvat->value) ) {
02156             return $this->oxarticles__oxvat->value;
02157         }
02158     }
02159 
02168     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02169     {
02170         $myConfig = $this->getConfig();
02171         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02172             return true;
02173         }
02174 
02175         $oDb = oxDb::getDb(true);
02176         // fetching DB info as its up-to-date
02177         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.oxDb::getDb(true)->quote( $this->getId() );
02178         $rs = oxDb::getDb(true)->execute( $sQ );
02179 
02180         $iOnStock   = 0;
02181         $iStockFlag = 0;
02182         if ( $rs !== false && $rs->recordCount() > 0 ) {
02183             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02184             $iStockFlag = $rs->fields['oxstockflag'];
02185 
02186             // dodger : fremdlager is also always considered as on stock
02187             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02188                 return true;
02189             }
02190             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02191                 $iOnStock = floor( $iOnStock );
02192             }
02193         }
02194         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02195             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02196         }
02197         if ( $iOnStock >= $dAmount ) {
02198             return true;
02199         } else {
02200             if ( $iOnStock > 0 ) {
02201                 return $iOnStock;
02202             } else {
02203                 $oEx = oxNew( 'oxArticleInputException' );
02204                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02205                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02206                 return false;
02207             }
02208         }
02209     }
02210 
02211 
02219     public function getArticleLongDesc( $sOxid = null )
02220     {
02221         if ( $this->_oLongDesc === null ) {
02222             // initializing
02223             $this->_oLongDesc = new oxField();
02224 
02225 
02226             // choosing which to get..
02227             $sOxid = $sOxid === null ? $this->getId() : $sOxid;
02228             $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02229 
02230             $sDbValue = oxDb::getDb()->getOne( "select oxlongdesc from {$sViewName} where oxid = ?", array( $sOxid ) );
02231 
02232             if ( $sDbValue != false ) {
02233                 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02234             } elseif ( $this->oxarticles__oxparentid->value ) {
02235                 $this->_oLongDesc->setValue( $this->getParentArticle()->getArticleLongDesc()->getRawValue(), oxField::T_RAW );
02236             }
02237         }
02238         return $this->_oLongDesc;
02239     }
02240 
02250     protected function _setLongDesc( $sDbValue )
02251     {
02252         $this->setArticleLongDesc( $sDbValue );
02253     }
02254 
02261     public function getLongDesc()
02262     {
02263         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getArticleLongDesc()->getRawValue(), $this->getId().$this->getLanguage() );
02264     }
02265 
02274     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02275     {
02276 
02277         // setting current value
02278         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02279 
02280         // setting original value?
02281         //deprecated since 2012-02-13 in v.4.5.7
02282         if ( $sOrigValue ) {
02283             $this->_oLongDesc->orignalValue = $sOrigValue;
02284         }
02285     }
02286 
02292     public function getAttributes()
02293     {
02294         if ( $this->_oAttributeList === null ) {
02295             $this->_oAttributeList = oxNew( 'oxattributelist' );
02296             $this->_oAttributeList->loadAttributes( $this->getId(), $this->getProductParentId() );
02297         }
02298 
02299         return $this->_oAttributeList;
02300     }
02301 
02310     public function appendLink( $sAddParams, $iLang = null )
02311     {
02312         if ( $sAddParams ) {
02313             if ( $iLang === null ) {
02314                 $iLang = $this->getLanguage();
02315             }
02316 
02317             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02318             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02319         }
02320     }
02321 
02330     public function getBaseSeoLink( $iLang, $blMain = false )
02331     {
02332         $oEncoder = oxSeoEncoderArticle::getInstance();
02333         if ( !$blMain ) {
02334             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02335         }
02336         return $oEncoder->getArticleMainUrl( $this, $iLang );
02337     }
02338 
02347     public function getLink( $iLang = null, $blMain = false  )
02348     {
02349         if ( !oxUtils::getInstance()->seoIsActive() ) {
02350             return $this->getStdLink( $iLang );
02351         }
02352 
02353         if ( $iLang === null ) {
02354             $iLang = $this->getLanguage();
02355         }
02356 
02357         $iLinkType = $this->getLinkType();
02358         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02359             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02360         }
02361 
02362         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02363         if ( isset($this->_aSeoAddParams[$iLang])) {
02364             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02365         }
02366 
02367         return $sUrl;
02368     }
02369 
02378     public function getMainLink( $iLang = null )
02379     {
02380         return $this->getLink( $iLang, true );
02381     }
02382 
02390     public function setLinkType( $iType )
02391     {
02392         // resetting detaisl link, to force new
02393         $this->_sDetailLink = null;
02394 
02395         // setting link type
02396         $this->_iLinkType = (int) $iType;
02397     }
02398 
02404     public function getLinkType()
02405     {
02406         return $this->_iLinkType;
02407     }
02408 
02417     public function appendStdLink( $sAddParams, $iLang = null )
02418     {
02419         if ( $sAddParams ) {
02420             if ( $iLang === null ) {
02421                 $iLang = $this->getLanguage();
02422             }
02423 
02424             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02425             $this->_aStdAddParams[$iLang] .= $sAddParams;
02426         }
02427     }
02428 
02438     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02439     {
02440         $sUrl = '';
02441         if ( $blFull ) {
02442             //always returns shop url, not admin
02443             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02444         }
02445 
02446         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02447         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02448     }
02449 
02458     public function getStdLink( $iLang = null, $aParams = array() )
02459     {
02460         if ( $iLang === null ) {
02461             $iLang = $this->getLanguage();
02462         }
02463 
02464         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02465             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02466         }
02467 
02468         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02469     }
02470 
02478     public function getStdTagLink( $sTag )
02479     {
02480         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02481         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02482     }
02483 
02489     public function getTags()
02490     {
02491         $oDb = oxDb::getDb();
02492         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02493         $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02494         $oTagCloud = oxNew('oxtagcloud');
02495         return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02496     }
02497 
02505     public function saveTags($sTags)
02506     {
02507         //do not allow derived update
02508         if ( !$this->allowDerivedUpdate() ) {
02509             return false;
02510         }
02511 
02512 
02513         $oTagCloud = oxNew( 'oxtagcloud' );
02514         $oTagCloud->resetTagCache();
02515         $sTags = mysql_real_escape_string( $oTagCloud->prepareTags( $sTags ) );
02516         $oDb = oxDb::getDb();
02517 
02518         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02519         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02520         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02521                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02522         return $oDb->execute( $sQ );
02523     }
02524 
02532     public function addTag($sTag)
02533     {
02534         $oDb = oxDb::getDb();
02535 
02536         $oTagCloud = oxNew('oxtagcloud');
02537         $oTagCloud->resetTagCache();
02538         $sTag = $oTagCloud->prepareTags($sTag);
02539         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02540 
02541         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02542         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02543         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02544             $sTailTag = $sTagSeparator . $sTag;
02545         } else {
02546             $sTailTag = $sTag;
02547         }
02548 
02549         $sTag = mysql_real_escape_string($sTag);
02550         $sTailTag = mysql_real_escape_string($sTailTag);
02551 
02552         $sTag = mysql_real_escape_string($sTag);
02553         $sTailTag = mysql_real_escape_string($sTailTag);
02554 
02555         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02556                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02557 
02558         return $oDb->execute( $sQ );
02559     }
02560 
02566     public function getMediaUrls()
02567     {
02568         if ( $this->_aMediaUrls === null ) {
02569             $this->_aMediaUrls = oxNew("oxlist");
02570             $this->_aMediaUrls->init("oxmediaurl");
02571             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02572 
02573             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02574             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02575             $this->_aMediaUrls->selectString($sQ);
02576         }
02577         return $this->_aMediaUrls;
02578     }
02579 
02585     public function getDynImageDir()
02586     {
02587         return $this->_sDynImageDir;
02588     }
02589 
02595     public function getDispSelList()
02596     {
02597         if ($this->_aDispSelList === null) {
02598             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02599                 $this->_aDispSelList = $this->getSelectLists();
02600             }
02601         }
02602         return $this->_aDispSelList;
02603     }
02604 
02610     public function getMoreDetailLink()
02611     {
02612         if ( $this->_sMoreDetailLink == null ) {
02613 
02614             // and assign special article values
02615             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02616 
02617             // not always it is okey, as not all the time active category is the same as primary article cat.
02618             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02619                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02620             }
02621             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02622             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02623         }
02624 
02625         return $this->_sMoreDetailLink;
02626     }
02627 
02633     public function getToBasketLink()
02634     {
02635         if ( $this->_sToBasketLink == null ) {
02636             $myConfig = $this->getConfig();
02637 
02638             if ( oxUtils::getInstance()->isSearchEngine() ) {
02639                 $this->_sToBasketLink = $this->getLink();
02640             } else {
02641                 // and assign special article values
02642                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02643 
02644                 // override some classes as these should never showup
02645                 $sActClass = oxConfig::getParameter( 'cl' );
02646                 if ( $sActClass == 'thankyou') {
02647                     $sActClass = 'basket';
02648                 }
02649                 $this->_sToBasketLink .= 'cl='.$sActClass;
02650 
02651                 // this is not very correct
02652                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02653                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02654                 }
02655 
02656                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02657 
02658                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02659                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02660                 }
02661             }
02662         }
02663 
02664         return $this->_sToBasketLink;
02665     }
02666 
02672     public function getStockStatus()
02673     {
02674         return $this->_iStockStatus;
02675     }
02676 
02682     public function getDeliveryDate()
02683     {
02684         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02685             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02686         }
02687         return false;
02688     }
02689 
02695     public function getFTPrice()
02696     {
02697         if ( $oPrice = $this->getTPrice() ) {
02698             if ( $oPrice->getBruttoPrice() ) {
02699                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02700             }
02701         }
02702     }
02703 
02709     public function getFPrice()
02710     {
02711         if ( $oPrice = $this->getPrice() ) {
02712             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02713         }
02714     }
02715 
02721     public function getFNetPrice()
02722     {
02723         if ( $oPrice = $this->getPrice() ) {
02724             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02725         }
02726     }
02727 
02733     public function getPricePerUnit()
02734     {
02735         return $this->_fPricePerUnit;
02736     }
02737 
02743     public function isParentNotBuyable()
02744     {
02745         return $this->_blNotBuyableParent;
02746     }
02747 
02753     public function isNotBuyable()
02754     {
02755         return $this->_blNotBuyable;
02756     }
02757 
02765     public function setBuyableState( $blBuyable = false )
02766     {
02767         $this->_blNotBuyable = !$blBuyable;
02768     }
02769 
02778     public function getVariantList()
02779     {
02780         return $this->getVariants();
02781     }
02782 
02790     public function setSelectlist( $aSelList )
02791     {
02792         $this->_aDispSelList = $aSelList;
02793     }
02794 
02802     public function getPictureUrl( $iIndex = 1 )
02803     {
02804         if ( $iIndex ) {
02805             $sImgName = false;
02806             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02807                 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02808             }
02809 
02810             $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02811             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02812         }
02813     }
02814 
02823     public function getIconUrl( $iIndex = 0 )
02824     {
02825         $sImgName = false;
02826         $sDirname = "product/1/";
02827         if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02828             $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02829             $sDirname = "product/{$iIndex}/";
02830         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02831             $sImgName = basename( $this->oxarticles__oxicon->value );
02832             $sDirname = "product/icon/";
02833         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02834             $sImgName = basename( $this->oxarticles__oxpic1->value );
02835         }
02836 
02837         $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02838         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02839     }
02840 
02846     public function getThumbnailUrl()
02847     {
02848         $sImgName = false;
02849         $sDirname = "product/1/";
02850         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02851             $sImgName = basename( $this->oxarticles__oxthumb->value );
02852             $sDirname = "product/thumb/";
02853         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02854             $sImgName = basename( $this->oxarticles__oxpic1->value );
02855         }
02856 
02857         $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02858         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0 );
02859     }
02860 
02868     public function getZoomPictureUrl( $iIndex = '' )
02869     {
02870         $iIndex = (int) $iIndex;
02871         if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02872             $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02873             $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02874             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02875         }
02876     }
02877 
02883     public function getFileUrl()
02884     {
02885         return $this->getConfig()->getPictureUrl( 'media/' );
02886     }
02887 
02893     public function getPriceFromPrefix()
02894     {
02895         $sPricePrefix = '';
02896         if ( $this->_blIsRangePrice) {
02897             $sPricePrefix = oxLang::getInstance()->translateString('priceFrom').' ';
02898         }
02899 
02900         return $sPricePrefix;
02901     }
02902 
02908     protected function _saveArtLongDesc()
02909     {
02910         $myConfig = $this->getConfig();
02911         $sShopId = $myConfig->getShopID();
02912         if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02913             return;
02914         }
02915 
02916         if ($this->_blEmployMultilanguage) {
02917             $sValue = $this->getArticleLongDesc()->getRawValue();
02918             if ( $sValue !== null ) {
02919                 $oArtExt = oxNew('oxI18n');
02920                 $oArtExt->init('oxartextends');
02921                 $oArtExt->setLanguage((int) $this->getLanguage());
02922                 if (!$oArtExt->load($this->getId())) {
02923                     $oArtExt->setId($this->getId());
02924                 }
02925                 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02926                 $oArtExt->save();
02927             }
02928         } else {
02929             $oArtExt = oxNew('oxI18n');
02930             $oArtExt->setEnableMultilang(false);
02931             $oArtExt->init('oxartextends');
02932             $aObjFields = $oArtExt->_getAllFields(true);
02933             if (!$oArtExt->load($this->getId())) {
02934                 $oArtExt->setId($this->getId());
02935             }
02936 
02937             foreach ($aObjFields as $sKey => $sValue ) {
02938                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02939                     $sField = $this->_getFieldLongName($sKey);
02940 
02941                     if (isset($this->$sField)) {
02942                         $sLongDesc = null;
02943                         if ($this->$sField instanceof oxField) {
02944                             $sLongDesc = $this->$sField->getRawValue();
02945                         } elseif (is_object($this->$sField)) {
02946                             $sLongDesc = $this->$sField->value;
02947                         }
02948                         if (isset($sLongDesc)) {
02949                             $sAEField = $oArtExt->_getFieldLongName($sKey);
02950                             $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
02951                         }
02952                     }
02953                 }
02954             }
02955             $oArtExt->save();
02956         }
02957     }
02958 
02964     protected function _skipSaveFields()
02965     {
02966         $myConfig = $this->getConfig();
02967 
02968         $this->_aSkipSaveFields = array();
02969 
02970         $this->_aSkipSaveFields[] = 'oxtimestamp';
02971        // $this->_aSkipSaveFields[] = 'oxlongdesc';
02972         $this->_aSkipSaveFields[] = 'oxinsert';
02973 
02974         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02975             $this->_aSkipSaveFields[] = 'oxparentid';
02976         }
02977 
02978     }
02979 
02989     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02990     {
02991         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02992             // add prices of the same discounts
02993             if ( array_key_exists ($sKey, $aDiscounts) ) {
02994                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02995             } else {
02996                 $aDiscounts[$sKey] = $oDiscount;
02997             }
02998         }
02999         return $aDiscounts;
03000     }
03001 
03007     protected function _getGroupPrice()
03008     {
03009         $dPrice = $this->oxarticles__oxprice->value;
03010 
03011         $oUser = $this->getArticleUser();
03012         if ( $oUser ) {
03013             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03014                 $dPrice = $this->oxarticles__oxpricea->value;
03015             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03016                 $dPrice = $this->oxarticles__oxpriceb->value;
03017             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03018                 $dPrice = $this->oxarticles__oxpricec->value;
03019             }
03020         }
03021 
03022         // #1437/1436C - added config option, and check for zero A,B,C price values
03023         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03024             $dPrice = $this->oxarticles__oxprice->value;
03025         }
03026 
03027         return $dPrice;
03028     }
03029 
03038     protected function _getAmountPrice($dAmount = 1)
03039     {
03040         $myConfig = $this->getConfig();
03041 
03042         startProfile( "_getAmountPrice" );
03043 
03044         $dPrice = $this->_getGroupPrice();
03045         $oAmtPrices = $this->_getAmountPriceList();
03046         foreach ($oAmtPrices as $oAmPrice) {
03047             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03048                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03049                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03050                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03051             }
03052         }
03053 
03054         stopProfile( "_getAmountPrice" );
03055         return $dPrice;
03056     }
03057 
03066     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03067     {
03068         $myConfig = $this->getConfig();
03069         // #690
03070         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03071 
03072             $aSelLists = $this->getSelectLists();
03073 
03074             foreach ( $aSelLists as $key => $aSel) {
03075                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03076                     $oSel = $aSel[$aChosenList[$key]];
03077                     if ( $oSel->priceUnit =='abs' ) {
03078                         $dPrice += $oSel->price;
03079                     } elseif ( $oSel->priceUnit =='%' ) {
03080                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03081                     }
03082                 }
03083             }
03084         }
03085         return $dPrice;
03086     }
03087 
03088 
03096     protected function _fillAmountPriceList($oAmPriceList)
03097     {
03098         $myConfig = $this->getConfig();
03099         $myUtils  = oxUtils::getInstance();
03100 
03101         //modifying price
03102         $oCur = $myConfig->getActShopCurrencyObject();
03103 
03104         $oUser = $this->getArticleUser();
03105 
03106         $oDiscountList = oxDiscountList::getInstance();
03107         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03108 
03109         $oLowestPrice = null;
03110 
03111         $dBasePrice = $this->_getGroupPrice();
03112         $oLang = oxLang::getInstance();
03113 
03114         $dArticleVat = null;
03115         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03116             $dArticleVat = $this->getArticleVat();
03117         }
03118 
03119         // trying to find lowest price value
03120         foreach ($oAmPriceList as $sId => $oItem) {
03121             $oItemPrice = oxNew( 'oxprice' );
03122             if ( $oItem->oxprice2article__oxaddabs->value) {
03123                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03124                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03125                 $this->_applyCurrency( $oItemPrice, $oCur );
03126             } else {
03127                 $oItemPrice->setPrice( $dBasePrice );
03128                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03129             }
03130 
03131             if (isset($dArticleVat)) {
03132                 $this->_applyVAT($oItemPrice, $dArticleVat);
03133             }
03134 
03135             if (!$oLowestPrice) {
03136                 $oLowestPrice = $oItemPrice;
03137             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03138                 $oLowestPrice = $oItemPrice;
03139             }
03140 
03141             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03142             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03143             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03144         }
03145 
03146         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03147         return $oAmPriceList;
03148     }
03149 
03155     protected function _getVariantsIds()
03156     {
03157         $aSelect = array();
03158         if ( ( $sId = $this->getId() ) ) {
03159             $oDb = oxDb::getDb(true);
03160             $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03161                    $this->getSqlActiveSnippet( true );
03162 
03163             $oRs = $oDb->execute( $sQ );
03164             if ( $oRs != false && $oRs->recordCount() > 0 ) {
03165                 while (!$oRs->EOF) {
03166                     $aSelect[] = reset( $oRs->fields );
03167                     $oRs->moveNext();
03168                 }
03169             }
03170         }
03171         return $aSelect;
03172     }
03173 
03179     public function getArticleVat()
03180     {
03181         if (!isset($this->_dArticleVat)) {
03182             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03183         }
03184         return $this->_dArticleVat;
03185     }
03186 
03195     protected function _applyVAT( oxPrice $oPrice, $dVat )
03196     {
03197         startProfile(__FUNCTION__);
03198         $oPrice->setVAT( $dVat );
03199         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03200             $oPrice->setUserVat( $dVat );
03201         }
03202         stopProfile(__FUNCTION__);
03203     }
03204 
03212     public function applyVats( oxPrice $oPrice )
03213     {
03214         $this->_applyVAT($oPrice, $this->getArticleVat() );
03215     }
03216 
03227     protected function _applyDiscounts( $oPrice, $aDiscounts )
03228     {
03229         $oDiscountList = oxDiscountList::getInstance();
03230         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03231     }
03232 
03240     public function applyDiscountsForVariant( $oPrice )
03241     {
03242         // apply discounts
03243         if ( !$this->skipDiscounts() ) {
03244             $oDiscountList = oxDiscountList::getInstance();
03245             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03246         }
03247     }
03248 
03257     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03258     {
03259         if ( !$oCur ) {
03260             $oCur = $this->getConfig()->getActShopCurrencyObject();
03261         }
03262 
03263         $oPrice->multiply($oCur->rate);
03264     }
03265 
03266 
03275     protected function _getAttribsString(&$sAttribs, &$iCnt)
03276     {
03277         // we do not use lists here as we dont need this overhead right now
03278         $oDB = oxDb::getDb(true);
03279         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDB->quote( $this->getId() );
03280         $sAttribs = '';
03281         $blSep = false;
03282         $rs = $oDB->execute( $sSelect);
03283         $iCnt = 0;
03284         if ($rs != false && $rs->recordCount() > 0) {
03285             while (!$rs->EOF) {
03286                 if ( $blSep) {
03287                     $sAttribs .= ' or ';
03288                 }
03289                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03290                 $blSep = true;
03291                 $iCnt++;
03292                 $rs->moveNext();
03293             }
03294         }
03295     }
03296 
03305     protected function _getSimList($sAttribs, $iCnt)
03306     {
03307         $myConfig = $this->getConfig();
03308         $oDB      = oxDb::getDb(true);
03309 
03310         // #523A
03311         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03312         // 70% same attributes
03313         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03314             $iAttrPercent = 0.70;
03315         }
03316         // #1137V iAttributesPercent = 100 doesnt work
03317         $iHitMin = ceil( $iCnt * $iAttrPercent );
03318 
03319         // we do not use lists here as we dont need this overhead right now
03320         $aList= array();
03321         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03322                     ( $sAttribs )
03323                     and t1.oxobjectid != ".$oDB->quote( $this->oxarticles__oxid->value )."
03324                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03325 
03326         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03327         if ($rs != false && $rs->recordCount() > 0) {
03328             while (!$rs->EOF) {
03329                 $oTemp = new stdClass();    // #663
03330                 $oTemp->cnt = $rs->fields['cnt'];
03331                 $oTemp->id  = $rs->fields['oxobjectid'];
03332                 $aList[] = $oTemp;
03333                 $rs->moveNext();
03334             }
03335         }
03336         return $aList;
03337     }
03338 
03347     protected function _generateSimListSearchStr($sArticleTable, $aList)
03348     {
03349         $myConfig = $this->getConfig();
03350         $sFieldList = $this->getSelectFields();
03351         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03352         $blSep = false;
03353         $iCnt = 0;
03354         $oDb = oxDb::getDb();
03355         foreach ( $aList as $oTemp) {
03356             if ( $blSep) {
03357                 $sSearch .= ',';
03358             }
03359             $sSearch .= $oDb->quote($oTemp->id);
03360             $blSep = true;
03361             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03362                 break;
03363             }
03364             $iCnt++;
03365         }
03366 
03367         //#1741T
03368         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03369         $sSearch .= ') ';
03370 
03371         // #524A -- randomizing articles in attribute list
03372         $sSearch .= ' order by rand() ';
03373 
03374         return $sSearch;
03375     }
03376 
03385     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03386     {
03387 
03388         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03389         $sO2CView = getViewName( 'oxobject2category' );
03390 
03391         // we do not use lists here as we dont need this overhead right now
03392         if ( !$blSearchPriceCat ) {
03393             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03394                          {$sCatView}.oxid = oxobject2category.oxcatnid
03395                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03396         } else {
03397             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03398                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03399                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03400         }
03401         return $sSelect;
03402     }
03403 
03409     protected function _generateSearchStrForCustomerBought()
03410     {
03411         $sArtTable = $this->getViewName();
03412         $sOrderArtTable = getViewName( 'oxorderarticles' );
03413 
03414         // fetching filter params
03415         $sIn = " '{$this->oxarticles__oxid->value}' ";
03416         if ( $this->oxarticles__oxparentid->value ) {
03417 
03418             // adding article parent
03419             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03420             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03421 
03422         } else {
03423             $sParentIdForVariants = $this->getId();
03424         }
03425 
03426         // adding variants
03427         $oDb = oxDb::getDb(true);
03428         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03429         if ( $oRs != false && $oRs->recordCount() > 0) {
03430             while ( !$oRs->EOF ) {
03431                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03432                 $oRs->moveNext();
03433             }
03434         }
03435 
03436         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03437         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03438 
03439         // building sql (optimized)
03440         $sQ = "select distinct {$sArtTable}.* from (
03441                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03442                ) as suborder
03443                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03444                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03445                where {$sArtTable}.oxid not in ( {$sIn} )
03446                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03447 
03448         /* non optimized, but could be used if index forcing is not supported
03449         // building sql
03450         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03451                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03452                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03453                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03454                and ".$this->getSqlActiveSnippet();
03455         */
03456 
03457         return $sQ;
03458     }
03459 
03469     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03470     {
03471         $sCategoryView = getViewName('oxcategories');
03472         $sO2CView = getViewName('oxobject2category');
03473 
03474         $oDb    = oxDb::getDb();
03475         $sOXID  = $oDb->quote($sOXID);
03476         $sCatId = $oDb->quote($sCatId);
03477 
03478         if (!$dPriceFromTo) {
03479             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03480             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03481             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03482             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03483         } else {
03484             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03485             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03486             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03487             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03488         }
03489         return $sSelect;
03490     }
03491 
03497     protected function _getAmountPriceList()
03498     {
03499         if ( $this->_oAmountPriceList === null ) {
03500             $this->_oAmountPriceList = array();
03501             if ( !$this->skipDiscounts() ) {
03502                 $myConfig = $this->getConfig();
03503                 $sArtId   = $this->getId();
03504 
03505                 // #1690C - Scale prices and variants
03506                 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03507                     $sArtId = $this->oxarticles__oxparentid->value;
03508                 }
03509 
03510                 //collecting assigned to article amount-price list
03511                 $oAmPriceList = oxNew( 'oxlist' );
03512                 $oAmPriceList->init( 'oxbase', 'oxprice2article' );
03513 
03514                 $sShopID = $myConfig->getShopID();
03515                 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03516                     $sShopSelect = '1';
03517                 } else {
03518                     $sShopSelect = " oxshopid =  '$sShopID' ";
03519                 }
03520 
03521                 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = " . oxDb::getDb()->quote( $sArtId ) . " and $sShopSelect order by oxamount ");
03522 
03523                 // prepare abs prices if currently having percentages
03524                 $oBasePrice = $this->_getGroupPrice();
03525                 foreach ( $oAmPriceList as $oAmPrice ) {
03526                     if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03527                         $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03528                     }
03529                 }
03530 
03531                 $this->_oAmountPriceList = $oAmPriceList;
03532             }
03533         }
03534 
03535         return $this->_oAmountPriceList;
03536     }
03537 
03545     protected function _isFieldEmpty( $sFieldName )
03546     {
03547         $mValue = $this->$sFieldName->value;
03548 
03549         if ( is_null( $mValue ) ) {
03550             return true;
03551         }
03552 
03553         if ( $mValue === '' ) {
03554             return true;
03555         }
03556 
03557         $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03558 
03559         if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03560             return true;
03561         }
03562 
03563 
03564         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03565             return true;
03566         }
03567 
03568         $sFieldName = strtolower($sFieldName);
03569 
03570         if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03571             return true;
03572         }
03573 
03574         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03575             return true;
03576         }
03577 
03578         return false;
03579     }
03580 
03588     protected function _assignParentFieldValue($sFieldName)
03589     {
03590         if (!($oParentArticle = $this->getParentArticle())) {
03591             return;
03592         }
03593 
03594         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03595 
03596         // assigning only theese which parent article has
03597         if ( $oParentArticle->$sCopyFieldName != null ) {
03598 
03599             // only overwrite database values
03600             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03601                 return;
03602             }
03603 
03604             //do not copy certain fields
03605             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03606                 return;
03607             }
03608 
03609             //COPY THE VALUE
03610             // assigning images from parent only if variant has no master image (#1807)
03611             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03612                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03613                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03614                 }
03615             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03616                 // for zoom images checking master image with specified index
03617                 // assign from parent only if no pictures to variant are added
03618                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03619                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03620                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03621                 }
03622             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03623                 // if no pics generated for variants, load all from
03624                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03625             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03626                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03627             }
03628         }
03629     }
03630 
03636     public function getParentArticle()
03637     {
03638         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03639             $sIndex = $sParentId . "_" . $this->getLanguage();
03640             if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03641                 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03642                 self::$_aLoadedParents[$sIndex]->_blSkipAbPrice  = true;
03643                 self::$_aLoadedParents[$sIndex]->_blLoadPrice    = false;
03644                 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03645                 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03646             }
03647             return self::$_aLoadedParents[$sIndex];
03648         }
03649     }
03650 
03658     protected function _getParentAricle()
03659     {
03660         return $this->getParentArticle();
03661     }
03662 
03668     protected function _assignParentFieldValues()
03669     {
03670         startProfile('articleAssignParentInternal');
03671         if ( $this->oxarticles__oxparentid->value ) {
03672             // yes, we are in fact a variant
03673             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03674                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03675                     $this->_assignParentFieldValue( $sFieldName );
03676                 }
03677             }
03678         }
03679         stopProfile('articleAssignParentInternal');
03680     }
03681 
03687     protected function _assignNotBuyableParent()
03688     {
03689         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03690              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03691             $this->_blNotBuyableParent = true;
03692 
03693         }
03694     }
03695 
03701     protected function _assignStock()
03702     {
03703         $myConfig = $this->getConfig();
03704         // -----------------------------------
03705         // stock
03706         // -----------------------------------
03707 
03708         // #1125 A. must round (using floor()) value taken from database and cast to int
03709         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03710             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03711         }
03712         //GREEN light
03713         $this->_iStockStatus = 0;
03714 
03715         // if we have flag /*1 or*/ 4 - we show always green light
03716         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03717             //ORANGE light
03718             $iStock = $this->oxarticles__oxstock->value;
03719 
03720             if ($this->_blNotBuyableParent) {
03721                 $iStock = $this->oxarticles__oxvarstock->value;
03722             }
03723 
03724 
03725             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03726                 $this->_iStockStatus = 1;
03727             }
03728 
03729             //RED light
03730             if ($iStock <= 0) {
03731                 $this->_iStockStatus = -1;
03732             }
03733         }
03734 
03735 
03736         // stock
03737         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03738             $iOnStock = $this->oxarticles__oxstock->value;
03739             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03740                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03741             }
03742             if ($iOnStock <= 0) {
03743                 $this->setBuyableState( false );
03744             }
03745         }
03746 
03747         //exceptional handling for variant parent stock:
03748         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03749             $this->setBuyableState( true );
03750             //but then at least setting notBuaybleParent to true
03751             $this->_blNotBuyableParent = true;
03752         }
03753 
03754         //special treatment for lists when blVariantParentBuyable config option is set to false
03755         //then we just hide "to basket" button.
03756         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03757         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03758             $this->setBuyableState( false );
03759         }
03760 
03761         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03762         if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03763             $this->setBuyableState( false );
03764         }
03765     }
03766 
03772     protected function _assignPrices()
03773     {
03774         $myConfig = $this->getConfig();
03775 
03776         // Performance
03777         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03778             return;
03779         }
03780 
03781         //price per unit handling
03782         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03783             // compute price
03784             $dPrice = $this->getPrice()->getBruttoPrice();
03785             $oCur = $myConfig->getActShopCurrencyObject();
03786             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03787         }
03788 
03789         //getting min and max prices of variants
03790         if ( $this->_hasAnyVariant() ) {
03791             $this->_applyRangePrice();
03792         }
03793     }
03794 
03800     protected function _assignPersistentParam()
03801     {
03802         // Persistent Parameter Handling
03803         $aPersParam     = oxSession::getVar( 'persparam');
03804         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03805             $this->_aPersistParam = $aPersParam[$this->getId()];
03806         }
03807     }
03808 
03814     protected function _assignDynImageDir()
03815     {
03816         $myConfig = $this->getConfig();
03817 
03818         $sThisShop = $this->oxarticles__oxshopid->value;
03819 
03820         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03821         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03822         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03823         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03824     }
03825 
03831     protected function _assignComparisonListFlag()
03832     {
03833         // #657 add a flag if article is on comparisonlist
03834 
03835         $aItems = oxSession::getVar('aFiltcompproducts');
03836         if ( isset( $aItems[$this->getId()])) {
03837             $this->_blIsOnComparisonList = true;
03838         }
03839     }
03840 
03846     protected function _assignAttributes()
03847     {
03848         //#1029T load attributes
03849         //#1078S removed check for module "Produktvergleich"
03850         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03851             $this->getAttributes();
03852         }
03853     }
03854 
03855 
03863     protected function _insert()
03864     {
03865         // set oxinsert
03866         $iInsertTime = time();
03867         $now = date('Y-m-d H:i:s', $iInsertTime);
03868         $this->oxarticles__oxinsert    = new oxField( $now );
03869         $this->oxarticles__oxtimestamp = new oxField( $now );
03870         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03871             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03872         }
03873 
03874         return parent::_insert();
03875     }
03876 
03882     protected function _update()
03883     {
03884 
03885         $this->_skipSaveFields();
03886 
03887         $myConfig = $this->getConfig();
03888 
03889 
03890         return parent::_update();
03891     }
03892 
03900     protected function _deleteRecords($sOXID)
03901     {
03902         $oDB = oxDb::getDb();
03903 
03904         $sOXID = $oDB->quote($sOXID);
03905 
03906         //remove other records
03907         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03908         $oDB->execute( $sDelete);
03909 
03910         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03911         $oDB->execute( $sDelete);
03912 
03913         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03914         $oDB->execute( $sDelete);
03915 
03916         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03917         $oDB->execute( $sDelete);
03918 
03919         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03920         $oDB->execute( $sDelete);
03921 
03922         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03923         $oDB->execute( $sDelete);
03924 
03925         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03926         $oDB->execute( $sDelete);
03927 
03928         //#1508C - deleting oxobject2delivery entries added
03929         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03930         $oDB->execute( $sDelete);
03931 
03932         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03933         $oDB->execute( $sDelete);
03934 
03935         //delete the record
03936         foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03937             $oDB->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03938         }
03939 
03940         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03941         $rs = $oDB->execute( $sDelete );
03942 
03943         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03944         $rs = $oDB->execute( $sDelete );
03945 
03946 
03947         return $rs;
03948     }
03949 
03957     protected function _deleteVariantRecords( $sOXID )
03958     {
03959         if ( $sOXID ) {
03960             $oDb = oxDb::getDb();
03961             //collect variants to remove recursively
03962             $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03963             $rs = $oDb->execute( $sQ );
03964             if ($rs != false && $rs->recordCount() > 0) {
03965                 while (!$rs->EOF) {
03966                     $this->delete( $rs->fields[0] );
03967                     $rs->moveNext();
03968                 }
03969             }
03970         }
03971     }
03972 
03982     protected function _resetCacheAndArticleCount( $sOxid )
03983     {
03984         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03985     }
03986 
03992     protected function _deletePics()
03993     {
03994         $myUtilsPic = oxUtilsPic::getInstance();
03995         $myConfig   = $this->getConfig();
03996         $oPictureHandler = oxPictureHandler::getInstance();
03997 
03998         //deleting custom main icon
03999         $oPictureHandler->deleteMainIcon( $this );
04000 
04001         //deleting custom thumbnail
04002         $oPictureHandler->deleteThumbnail( $this );
04003 
04004         $sAbsDynImageDir = $myConfig->getPictureDir(false);
04005 
04006         // deleting master image and all generated images
04007         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04008         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04009             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04010         }
04011     }
04012 
04022     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04023     {
04024 
04025         $myUtilsCount = oxUtilsCount::getInstance();
04026 
04027         if ( $sVendorId ) {
04028             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04029         }
04030 
04031         if ( $sManufacturerId ) {
04032             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04033         }
04034 
04035         //also reseting category counts
04036         $oDb = oxDb::getDb();
04037         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04038         $oRs = $oDb->execute( $sQ );
04039         if ( $oRs !== false && $oRs->recordCount() > 0) {
04040             while ( !$oRs->EOF ) {
04041                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04042                 $oRs->moveNext();
04043             }
04044         }
04045     }
04046 
04054     protected function _onChangeUpdateStock( $sParentID )
04055     {
04056         if ( $sParentID ) {
04057             $oDb = oxDb::getDb();
04058             $sParentIdQuoted = $oDb->quote($sParentID);
04059             $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04060             $rs = $oDb->execute($sQ);
04061             $iOldStock = $rs->fields[0];
04062             $iVendorID = $rs->fields[1];
04063             $iManufacturerID = $rs->fields[2];
04064 
04065             $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04066             $iStock = (float) $oDb->getOne( $sQ );
04067 
04068             $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04069             $oDb->execute( $sQ );
04070 
04071                 //now lets update category counts
04072                 //first detect stock status change for this article (to or from 0)
04073                 if ( $iStock < 0 ) {
04074                     $iStock = 0;
04075                 }
04076                 if ( $iOldStock < 0 ) {
04077                     $iOldStock = 0;
04078                 }
04079                 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04080                     //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04081                     // so far we leave it like this but later we could move all count resets to one or two functions
04082                     $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04083                 }
04084         }
04085     }
04086 
04094     protected function _onChangeStockResetCount( $sOxid )
04095     {
04096         $myConfig = $this->getConfig();
04097 
04098         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04099            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04100 
04101                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04102         }
04103     }
04104 
04112     protected function _onChangeUpdateVarCount( $sParentID )
04113     {
04114         if ( $sParentID ) {
04115             $oDb = oxDb::getDb();
04116             $sParentIdQuoted = $oDb->quote( $sParentID );
04117             $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04118             $iVarCount = (int) $oDb->getOne( $sQ );
04119 
04120             $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04121             $oDb->execute( $sQ );
04122         }
04123     }
04124 
04132     protected function _onChangeUpdateMinVarPrice( $sParentID )
04133     {
04134         if ( $sParentID ) {
04135             $oDb = oxDb::getDb();
04136             $sParentIdQuoted = $oDb->quote($sParentID);
04137             //#M0000883 (Sarunas)
04138             $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04139             $dVarMinPrice = $oDb->getOne($sQ);
04140 
04141             $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04142 
04143             $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04144 
04145             if ($dVarMinPrice) {
04146                 if ($blParentBuyable) {
04147                     $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04148                 }
04149 
04150             } else {
04151                 $dVarMinPrice = $dParentPrice;
04152             }
04153 
04154             if ( $dVarMinPrice ) {
04155                 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04156                 $oDb->execute($sQ);
04157             }
04158         }
04159     }
04160 
04161 
04167     protected function _applyRangePrice()
04168     {
04169         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04170         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04171             return;
04172         }
04173 
04174         $this->_blIsRangePrice = false;
04175 
04176         // if parent is buyable - do not apply range price calcculations
04177         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04178             return;
04179         }
04180 
04181         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04182             //#2509 we cannot force brutto price here, as netto price can be added to DB
04183             // $this->getPrice()->setBruttoPriceMode();
04184             $dPrice = $this->oxarticles__oxvarminprice->value;
04185             $this->getPrice()->setPrice($dPrice);
04186             $this->_blIsRangePrice = true;
04187             $this->_calculatePrice( $this->getPrice() );
04188             return;
04189         }
04190 
04191         $aPrices = array();
04192 
04193         if (!$this->_blNotBuyableParent) {
04194             $aPrices[] = $this->getPrice()->getBruttoPrice();
04195         }
04196 
04197         $aVariants = $this->getVariants(false);
04198 
04199         if (count($aVariants)) {
04200             foreach ($aVariants as $sKey => $oVariant) {
04201                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04202             }
04203         }
04204 
04205         if ( count( $aPrices ) ) {
04206             $dMinPrice = min( $aPrices );
04207             $dMaxPrice = max( $aPrices );
04208         }
04209 
04210         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04211             $this->getPrice()->setBruttoPriceMode();
04212             $this->getPrice()->setPrice($dMinPrice);
04213         }
04214 
04215         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04216             $this->getPrice()->setBruttoPriceMode();
04217             $this->getPrice()->setPrice($dMinPrice);
04218             $this->_blIsRangePrice = true;
04219         }
04220     }
04221 
04228     public function getProductId()
04229     {
04230         return $this->getId();
04231     }
04232 
04238     public function getProductParentId()
04239     {
04240         return $this->oxarticles__oxparentid->value;
04241     }
04242 
04248     public function isOrderArticle()
04249     {
04250         return false;
04251     }
04252 
04258     public function isVariant()
04259     {
04260         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04261     }
04262 
04268     public function isMdVariant()
04269     {
04270         $oMdVariant = oxNew( "oxVariantHandler" );
04271 
04272         return $oMdVariant->isMdVariant($this);
04273     }
04274 
04282     public function getSqlForPriceCategories($sFields = '')
04283     {
04284         if (!$sFields) {
04285             $sFields = 'oxid';
04286         }
04287         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04288         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04289         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04290                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04291                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04292     }
04293 
04301     public function inPriceCategory( $sCatNid )
04302     {
04303         $oDb = oxDb::getDb();
04304 
04305         $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04306         $sQuotedCnid = $oDb->quote( $sCatNid );
04307         return (bool) $oDb->getOne(
04308             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04309            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04310            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04311            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04312            .")"
04313         );
04314     }
04315 
04321     public function getMdVariants()
04322     {
04323         if ( $this->_oMdVariants ) {
04324             return $this->_oMdVariants;
04325         }
04326 
04327         $oParentArticle = $this->getParentArticle();
04328         if ( $oParentArticle ) {
04329             $oVariants = $oParentArticle->getVariants();
04330         } else {
04331             $oVariants = $this->getVariants();
04332         }
04333 
04334         $oVariantHandler = oxNew( "oxVariantHandler" );
04335         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04336 
04337         return $this->_oMdVariants;
04338     }
04339 
04345     public function getMdSubvariants()
04346     {
04347         return $this->getMdVariants()->getMdSubvariants();
04348     }
04349 
04357     protected function _hasMasterImage( $iIndex )
04358     {
04359         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04360 
04361         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04362             return false;
04363         }
04364         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04365             return false;
04366         }
04367 
04368         $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04369 
04370         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04371             return true;
04372         }
04373 
04374         return false;
04375     }
04376 
04385     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04386     {
04387         if ( $sFieldName ) {
04388             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04389             return $this->$sFieldName->value;
04390         }
04391     }
04392 
04400     public function getMasterZoomPictureUrl( $iIndex )
04401     {
04402         $sPicUrl  = false;
04403         $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04404 
04405         if ( $sPicName && $sPicName != "nopic.jpg" ) {
04406             $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04407             if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04408                 $sPicUrl = false;
04409             }
04410         }
04411 
04412         return $sPicUrl;
04413     }
04414 
04420     public function hasAmountPrice()
04421     {
04422         if ( self::$_blHasAmountPrice === null ) {
04423 
04424             self::$_blHasAmountPrice = false;
04425 
04426             $oDb = oxDb::getDb();
04427             $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04428 
04429             if ( $oDb->getOne( $sQ ) ) {
04430                 self::$_blHasAmountPrice = true;
04431             }
04432         }
04433 
04434         return self::$_blHasAmountPrice;
04435     }
04436 }