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                 if ( !$this->isAdmin() || $this->_blLoadParentData ) {
02236                     $this->_oLongDesc->setValue( $this->getParentArticle()->getArticleLongDesc()->getRawValue(), oxField::T_RAW );
02237                 }
02238             }
02239         }
02240         return $this->_oLongDesc;
02241     }
02242 
02252     protected function _setLongDesc( $sDbValue )
02253     {
02254         $this->setArticleLongDesc( $sDbValue );
02255     }
02256 
02263     public function getLongDesc()
02264     {
02265         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getArticleLongDesc()->getRawValue(), $this->getId().$this->getLanguage() );
02266     }
02267 
02276     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02277     {
02278 
02279         // setting current value
02280         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02281 
02282         // setting original value?
02283         //deprecated since 2012-02-13 in v.4.5.7
02284         if ( $sOrigValue ) {
02285             $this->_oLongDesc->orignalValue = $sOrigValue;
02286         }
02287     }
02288 
02294     public function getAttributes()
02295     {
02296         if ( $this->_oAttributeList === null ) {
02297             $this->_oAttributeList = oxNew( 'oxattributelist' );
02298             $this->_oAttributeList->loadAttributes( $this->getId() );
02299         }
02300 
02301         return $this->_oAttributeList;
02302     }
02303 
02312     public function appendLink( $sAddParams, $iLang = null )
02313     {
02314         if ( $sAddParams ) {
02315             if ( $iLang === null ) {
02316                 $iLang = $this->getLanguage();
02317             }
02318 
02319             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02320             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02321         }
02322     }
02323 
02332     public function getBaseSeoLink( $iLang, $blMain = false )
02333     {
02334         $oEncoder = oxSeoEncoderArticle::getInstance();
02335         if ( !$blMain ) {
02336             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02337         }
02338         return $oEncoder->getArticleMainUrl( $this, $iLang );
02339     }
02340 
02349     public function getLink( $iLang = null, $blMain = false  )
02350     {
02351         if ( !oxUtils::getInstance()->seoIsActive() ) {
02352             return $this->getStdLink( $iLang );
02353         }
02354 
02355         if ( $iLang === null ) {
02356             $iLang = $this->getLanguage();
02357         }
02358 
02359         $iLinkType = $this->getLinkType();
02360         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02361             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02362         }
02363 
02364         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02365         if ( isset($this->_aSeoAddParams[$iLang])) {
02366             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02367         }
02368 
02369         return $sUrl;
02370     }
02371 
02380     public function getMainLink( $iLang = null )
02381     {
02382         return $this->getLink( $iLang, true );
02383     }
02384 
02392     public function setLinkType( $iType )
02393     {
02394         // resetting detaisl link, to force new
02395         $this->_sDetailLink = null;
02396 
02397         // setting link type
02398         $this->_iLinkType = (int) $iType;
02399     }
02400 
02406     public function getLinkType()
02407     {
02408         return $this->_iLinkType;
02409     }
02410 
02419     public function appendStdLink( $sAddParams, $iLang = null )
02420     {
02421         if ( $sAddParams ) {
02422             if ( $iLang === null ) {
02423                 $iLang = $this->getLanguage();
02424             }
02425 
02426             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02427             $this->_aStdAddParams[$iLang] .= $sAddParams;
02428         }
02429     }
02430 
02440     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02441     {
02442         $sUrl = '';
02443         if ( $blFull ) {
02444             //always returns shop url, not admin
02445             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02446         }
02447 
02448         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02449         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02450     }
02451 
02460     public function getStdLink( $iLang = null, $aParams = array() )
02461     {
02462         if ( $iLang === null ) {
02463             $iLang = $this->getLanguage();
02464         }
02465 
02466         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02467             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02468         }
02469 
02470         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02471     }
02472 
02480     public function getStdTagLink( $sTag )
02481     {
02482         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02483         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02484     }
02485 
02491     public function getTags()
02492     {
02493         $oDb = oxDb::getDb();
02494         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02495         $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02496         $oTagCloud = oxNew('oxtagcloud');
02497         return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02498     }
02499 
02507     public function saveTags($sTags)
02508     {
02509         //do not allow derived update
02510         if ( !$this->allowDerivedUpdate() ) {
02511             return false;
02512         }
02513 
02514 
02515         $oTagCloud = oxNew( 'oxtagcloud' );
02516         $oTagCloud->resetTagCache();
02517         $sTags = mysql_real_escape_string( $oTagCloud->prepareTags( $sTags ) );
02518         $oDb = oxDb::getDb();
02519 
02520         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02521         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02522         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02523                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02524         return $oDb->execute( $sQ );
02525     }
02526 
02534     public function addTag($sTag)
02535     {
02536         $oDb = oxDb::getDb();
02537 
02538         $oTagCloud = oxNew('oxtagcloud');
02539         $oTagCloud->resetTagCache();
02540         $sTag = $oTagCloud->prepareTags($sTag);
02541         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02542 
02543         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02544         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02545         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02546             $sTailTag = $sTagSeparator . $sTag;
02547         } else {
02548             $sTailTag = $sTag;
02549         }
02550 
02551         $sTag = mysql_real_escape_string($sTag);
02552         $sTailTag = mysql_real_escape_string($sTailTag);
02553 
02554         $sTag = mysql_real_escape_string($sTag);
02555         $sTailTag = mysql_real_escape_string($sTailTag);
02556 
02557         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02558                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02559 
02560         return $oDb->execute( $sQ );
02561     }
02562 
02568     public function getMediaUrls()
02569     {
02570         if ( $this->_aMediaUrls === null ) {
02571             $this->_aMediaUrls = oxNew("oxlist");
02572             $this->_aMediaUrls->init("oxmediaurl");
02573             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02574 
02575             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02576             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02577             $this->_aMediaUrls->selectString($sQ);
02578         }
02579         return $this->_aMediaUrls;
02580     }
02581 
02587     public function getDynImageDir()
02588     {
02589         return $this->_sDynImageDir;
02590     }
02591 
02597     public function getDispSelList()
02598     {
02599         if ($this->_aDispSelList === null) {
02600             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02601                 $this->_aDispSelList = $this->getSelectLists();
02602             }
02603         }
02604         return $this->_aDispSelList;
02605     }
02606 
02612     public function getMoreDetailLink()
02613     {
02614         if ( $this->_sMoreDetailLink == null ) {
02615 
02616             // and assign special article values
02617             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02618 
02619             // not always it is okey, as not all the time active category is the same as primary article cat.
02620             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02621                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02622             }
02623             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02624             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02625         }
02626 
02627         return $this->_sMoreDetailLink;
02628     }
02629 
02635     public function getToBasketLink()
02636     {
02637         if ( $this->_sToBasketLink == null ) {
02638             $myConfig = $this->getConfig();
02639 
02640             if ( oxUtils::getInstance()->isSearchEngine() ) {
02641                 $this->_sToBasketLink = $this->getLink();
02642             } else {
02643                 // and assign special article values
02644                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02645 
02646                 // override some classes as these should never showup
02647                 $sActClass = oxConfig::getParameter( 'cl' );
02648                 if ( $sActClass == 'thankyou') {
02649                     $sActClass = 'basket';
02650                 }
02651                 $this->_sToBasketLink .= 'cl='.$sActClass;
02652 
02653                 // this is not very correct
02654                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02655                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02656                 }
02657 
02658                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02659 
02660                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02661                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02662                 }
02663             }
02664         }
02665 
02666         return $this->_sToBasketLink;
02667     }
02668 
02674     public function getStockStatus()
02675     {
02676         return $this->_iStockStatus;
02677     }
02678 
02684     public function getDeliveryDate()
02685     {
02686         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02687             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02688         }
02689         return false;
02690     }
02691 
02697     public function getFTPrice()
02698     {
02699         if ( $oPrice = $this->getTPrice() ) {
02700             if ( $oPrice->getBruttoPrice() ) {
02701                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02702             }
02703         }
02704     }
02705 
02711     public function getFPrice()
02712     {
02713         if ( $oPrice = $this->getPrice() ) {
02714             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02715         }
02716     }
02717 
02723     public function getFNetPrice()
02724     {
02725         if ( $oPrice = $this->getPrice() ) {
02726             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02727         }
02728     }
02729 
02735     public function getPricePerUnit()
02736     {
02737         return $this->_fPricePerUnit;
02738     }
02739 
02745     public function isParentNotBuyable()
02746     {
02747         return $this->_blNotBuyableParent;
02748     }
02749 
02755     public function isNotBuyable()
02756     {
02757         return $this->_blNotBuyable;
02758     }
02759 
02767     public function setBuyableState( $blBuyable = false )
02768     {
02769         $this->_blNotBuyable = !$blBuyable;
02770     }
02771 
02780     public function getVariantList()
02781     {
02782         return $this->getVariants();
02783     }
02784 
02792     public function setSelectlist( $aSelList )
02793     {
02794         $this->_aDispSelList = $aSelList;
02795     }
02796 
02804     public function getPictureUrl( $iIndex = 1 )
02805     {
02806         if ( $iIndex ) {
02807             $sImgName = false;
02808             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02809                 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02810             }
02811 
02812             $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02813             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02814         }
02815     }
02816 
02825     public function getIconUrl( $iIndex = 0 )
02826     {
02827         $sImgName = false;
02828         $sDirname = "product/1/";
02829         if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02830             $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02831             $sDirname = "product/{$iIndex}/";
02832         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02833             $sImgName = basename( $this->oxarticles__oxicon->value );
02834             $sDirname = "product/icon/";
02835         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02836             $sImgName = basename( $this->oxarticles__oxpic1->value );
02837         }
02838 
02839         $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02840         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02841     }
02842 
02848     public function getThumbnailUrl()
02849     {
02850         $sImgName = false;
02851         $sDirname = "product/1/";
02852         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02853             $sImgName = basename( $this->oxarticles__oxthumb->value );
02854             $sDirname = "product/thumb/";
02855         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02856             $sImgName = basename( $this->oxarticles__oxpic1->value );
02857         }
02858 
02859         $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02860         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0 );
02861     }
02862 
02870     public function getZoomPictureUrl( $iIndex = '' )
02871     {
02872         $iIndex = (int) $iIndex;
02873         if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02874             $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02875             $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02876             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02877         }
02878     }
02879 
02885     public function getFileUrl()
02886     {
02887         return $this->getConfig()->getPictureUrl( 'media/' );
02888     }
02889 
02895     public function getPriceFromPrefix()
02896     {
02897         $sPricePrefix = '';
02898         if ( $this->_blIsRangePrice) {
02899             $sPricePrefix = oxLang::getInstance()->translateString('priceFrom').' ';
02900         }
02901 
02902         return $sPricePrefix;
02903     }
02904 
02910     protected function _saveArtLongDesc()
02911     {
02912         $myConfig = $this->getConfig();
02913         $sShopId = $myConfig->getShopID();
02914         if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02915             return;
02916         }
02917 
02918         if ($this->_blEmployMultilanguage) {
02919             $sValue = $this->getArticleLongDesc()->getRawValue();
02920             if ( $sValue !== null ) {
02921                 $oArtExt = oxNew('oxI18n');
02922                 $oArtExt->init('oxartextends');
02923                 $oArtExt->setLanguage((int) $this->getLanguage());
02924                 if (!$oArtExt->load($this->getId())) {
02925                     $oArtExt->setId($this->getId());
02926                 }
02927                 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02928                 $oArtExt->save();
02929             }
02930         } else {
02931             $oArtExt = oxNew('oxI18n');
02932             $oArtExt->setEnableMultilang(false);
02933             $oArtExt->init('oxartextends');
02934             $aObjFields = $oArtExt->_getAllFields(true);
02935             if (!$oArtExt->load($this->getId())) {
02936                 $oArtExt->setId($this->getId());
02937             }
02938 
02939             foreach ($aObjFields as $sKey => $sValue ) {
02940                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02941                     $sField = $this->_getFieldLongName($sKey);
02942 
02943                     if (isset($this->$sField)) {
02944                         $sLongDesc = null;
02945                         if ($this->$sField instanceof oxField) {
02946                             $sLongDesc = $this->$sField->getRawValue();
02947                         } elseif (is_object($this->$sField)) {
02948                             $sLongDesc = $this->$sField->value;
02949                         }
02950                         if (isset($sLongDesc)) {
02951                             $sAEField = $oArtExt->_getFieldLongName($sKey);
02952                             $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
02953                         }
02954                     }
02955                 }
02956             }
02957             $oArtExt->save();
02958         }
02959     }
02960 
02966     protected function _skipSaveFields()
02967     {
02968         $myConfig = $this->getConfig();
02969 
02970         $this->_aSkipSaveFields = array();
02971 
02972         $this->_aSkipSaveFields[] = 'oxtimestamp';
02973        // $this->_aSkipSaveFields[] = 'oxlongdesc';
02974         $this->_aSkipSaveFields[] = 'oxinsert';
02975 
02976         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02977             $this->_aSkipSaveFields[] = 'oxparentid';
02978         }
02979 
02980     }
02981 
02991     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02992     {
02993         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02994             // add prices of the same discounts
02995             if ( array_key_exists ($sKey, $aDiscounts) ) {
02996                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02997             } else {
02998                 $aDiscounts[$sKey] = $oDiscount;
02999             }
03000         }
03001         return $aDiscounts;
03002     }
03003 
03009     protected function _getGroupPrice()
03010     {
03011         $dPrice = $this->oxarticles__oxprice->value;
03012 
03013         $oUser = $this->getArticleUser();
03014         if ( $oUser ) {
03015             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03016                 $dPrice = $this->oxarticles__oxpricea->value;
03017             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03018                 $dPrice = $this->oxarticles__oxpriceb->value;
03019             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03020                 $dPrice = $this->oxarticles__oxpricec->value;
03021             }
03022         }
03023 
03024         // #1437/1436C - added config option, and check for zero A,B,C price values
03025         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03026             $dPrice = $this->oxarticles__oxprice->value;
03027         }
03028 
03029         return $dPrice;
03030     }
03031 
03040     protected function _getAmountPrice($dAmount = 1)
03041     {
03042         $myConfig = $this->getConfig();
03043 
03044         startProfile( "_getAmountPrice" );
03045 
03046         $dPrice = $this->_getGroupPrice();
03047         $oAmtPrices = $this->_getAmountPriceList();
03048         foreach ($oAmtPrices as $oAmPrice) {
03049             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03050                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03051                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03052                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03053             }
03054         }
03055 
03056         stopProfile( "_getAmountPrice" );
03057         return $dPrice;
03058     }
03059 
03068     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03069     {
03070         $myConfig = $this->getConfig();
03071         // #690
03072         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03073 
03074             $aSelLists = $this->getSelectLists();
03075 
03076             foreach ( $aSelLists as $key => $aSel) {
03077                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03078                     $oSel = $aSel[$aChosenList[$key]];
03079                     if ( $oSel->priceUnit =='abs' ) {
03080                         $dPrice += $oSel->price;
03081                     } elseif ( $oSel->priceUnit =='%' ) {
03082                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03083                     }
03084                 }
03085             }
03086         }
03087         return $dPrice;
03088     }
03089 
03090 
03098     protected function _fillAmountPriceList($oAmPriceList)
03099     {
03100         $myConfig = $this->getConfig();
03101         $myUtils  = oxUtils::getInstance();
03102 
03103         //modifying price
03104         $oCur = $myConfig->getActShopCurrencyObject();
03105 
03106         $oUser = $this->getArticleUser();
03107 
03108         $oDiscountList = oxDiscountList::getInstance();
03109         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03110 
03111         $oLowestPrice = null;
03112 
03113         $dBasePrice = $this->_getGroupPrice();
03114         $oLang = oxLang::getInstance();
03115 
03116         $dArticleVat = null;
03117         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03118             $dArticleVat = $this->getArticleVat();
03119         }
03120 
03121         // trying to find lowest price value
03122         foreach ($oAmPriceList as $sId => $oItem) {
03123             $oItemPrice = oxNew( 'oxprice' );
03124             if ( $oItem->oxprice2article__oxaddabs->value) {
03125                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03126                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03127                 $this->_applyCurrency( $oItemPrice, $oCur );
03128             } else {
03129                 $oItemPrice->setPrice( $dBasePrice );
03130                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03131             }
03132 
03133             if (isset($dArticleVat)) {
03134                 $this->_applyVAT($oItemPrice, $dArticleVat);
03135             }
03136 
03137             if (!$oLowestPrice) {
03138                 $oLowestPrice = $oItemPrice;
03139             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03140                 $oLowestPrice = $oItemPrice;
03141             }
03142 
03143             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03144             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03145             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03146         }
03147 
03148         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03149         return $oAmPriceList;
03150     }
03151 
03157     protected function _getVariantsIds()
03158     {
03159         $aSelect = array();
03160         if ( ( $sId = $this->getId() ) ) {
03161             $oDb = oxDb::getDb(true);
03162             $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03163                    $this->getSqlActiveSnippet( true );
03164 
03165             $oRs = $oDb->execute( $sQ );
03166             if ( $oRs != false && $oRs->recordCount() > 0 ) {
03167                 while (!$oRs->EOF) {
03168                     $aSelect[] = reset( $oRs->fields );
03169                     $oRs->moveNext();
03170                 }
03171             }
03172         }
03173         return $aSelect;
03174     }
03175 
03181     public function getArticleVat()
03182     {
03183         if (!isset($this->_dArticleVat)) {
03184             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03185         }
03186         return $this->_dArticleVat;
03187     }
03188 
03197     protected function _applyVAT( oxPrice $oPrice, $dVat )
03198     {
03199         startProfile(__FUNCTION__);
03200         $oPrice->setVAT( $dVat );
03201         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03202             $oPrice->setUserVat( $dVat );
03203         }
03204         stopProfile(__FUNCTION__);
03205     }
03206 
03214     public function applyVats( oxPrice $oPrice )
03215     {
03216         $this->_applyVAT($oPrice, $this->getArticleVat() );
03217     }
03218 
03229     protected function _applyDiscounts( $oPrice, $aDiscounts )
03230     {
03231         $oDiscountList = oxDiscountList::getInstance();
03232         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03233     }
03234 
03242     public function applyDiscountsForVariant( $oPrice )
03243     {
03244         // apply discounts
03245         if ( !$this->skipDiscounts() ) {
03246             $oDiscountList = oxDiscountList::getInstance();
03247             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03248         }
03249     }
03250 
03259     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03260     {
03261         if ( !$oCur ) {
03262             $oCur = $this->getConfig()->getActShopCurrencyObject();
03263         }
03264 
03265         $oPrice->multiply($oCur->rate);
03266     }
03267 
03268 
03277     protected function _getAttribsString(&$sAttribs, &$iCnt)
03278     {
03279         // we do not use lists here as we dont need this overhead right now
03280         $oDB = oxDb::getDb(true);
03281         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDB->quote( $this->getId() );
03282         $sAttribs = '';
03283         $blSep = false;
03284         $rs = $oDB->execute( $sSelect);
03285         $iCnt = 0;
03286         if ($rs != false && $rs->recordCount() > 0) {
03287             while (!$rs->EOF) {
03288                 if ( $blSep) {
03289                     $sAttribs .= ' or ';
03290                 }
03291                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03292                 $blSep = true;
03293                 $iCnt++;
03294                 $rs->moveNext();
03295             }
03296         }
03297     }
03298 
03307     protected function _getSimList($sAttribs, $iCnt)
03308     {
03309         $myConfig = $this->getConfig();
03310         $oDB      = oxDb::getDb(true);
03311 
03312         // #523A
03313         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03314         // 70% same attributes
03315         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03316             $iAttrPercent = 0.70;
03317         }
03318         // #1137V iAttributesPercent = 100 doesnt work
03319         $iHitMin = ceil( $iCnt * $iAttrPercent );
03320 
03321         // we do not use lists here as we dont need this overhead right now
03322         $aList= array();
03323         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03324                     ( $sAttribs )
03325                     and t1.oxobjectid != ".$oDB->quote( $this->oxarticles__oxid->value )."
03326                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03327 
03328         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03329         if ($rs != false && $rs->recordCount() > 0) {
03330             while (!$rs->EOF) {
03331                 $oTemp = new stdClass();    // #663
03332                 $oTemp->cnt = $rs->fields['cnt'];
03333                 $oTemp->id  = $rs->fields['oxobjectid'];
03334                 $aList[] = $oTemp;
03335                 $rs->moveNext();
03336             }
03337         }
03338         return $aList;
03339     }
03340 
03349     protected function _generateSimListSearchStr($sArticleTable, $aList)
03350     {
03351         $myConfig = $this->getConfig();
03352         $sFieldList = $this->getSelectFields();
03353         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03354         $blSep = false;
03355         $iCnt = 0;
03356         $oDb = oxDb::getDb();
03357         foreach ( $aList as $oTemp) {
03358             if ( $blSep) {
03359                 $sSearch .= ',';
03360             }
03361             $sSearch .= $oDb->quote($oTemp->id);
03362             $blSep = true;
03363             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03364                 break;
03365             }
03366             $iCnt++;
03367         }
03368 
03369         //#1741T
03370         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03371         $sSearch .= ') ';
03372 
03373         // #524A -- randomizing articles in attribute list
03374         $sSearch .= ' order by rand() ';
03375 
03376         return $sSearch;
03377     }
03378 
03387     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03388     {
03389 
03390         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03391         $sO2CView = getViewName( 'oxobject2category' );
03392 
03393         // we do not use lists here as we dont need this overhead right now
03394         if ( !$blSearchPriceCat ) {
03395             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03396                          {$sCatView}.oxid = oxobject2category.oxcatnid
03397                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03398         } else {
03399             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03400                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03401                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03402         }
03403         return $sSelect;
03404     }
03405 
03411     protected function _generateSearchStrForCustomerBought()
03412     {
03413         $sArtTable = $this->getViewName();
03414         $sOrderArtTable = getViewName( 'oxorderarticles' );
03415 
03416         // fetching filter params
03417         $sIn = " '{$this->oxarticles__oxid->value}' ";
03418         if ( $this->oxarticles__oxparentid->value ) {
03419 
03420             // adding article parent
03421             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03422             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03423 
03424         } else {
03425             $sParentIdForVariants = $this->getId();
03426         }
03427 
03428         // adding variants
03429         $oDb = oxDb::getDb(true);
03430         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03431         if ( $oRs != false && $oRs->recordCount() > 0) {
03432             while ( !$oRs->EOF ) {
03433                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03434                 $oRs->moveNext();
03435             }
03436         }
03437 
03438         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03439         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03440 
03441         // building sql (optimized)
03442         $sQ = "select distinct {$sArtTable}.* from (
03443                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03444                ) as suborder
03445                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03446                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03447                where {$sArtTable}.oxid not in ( {$sIn} )
03448                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03449 
03450         /* non optimized, but could be used if index forcing is not supported
03451         // building sql
03452         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03453                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03454                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03455                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03456                and ".$this->getSqlActiveSnippet();
03457         */
03458 
03459         return $sQ;
03460     }
03461 
03471     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03472     {
03473         $sCategoryView = getViewName('oxcategories');
03474         $sO2CView = getViewName('oxobject2category');
03475 
03476         $oDb    = oxDb::getDb();
03477         $sOXID  = $oDb->quote($sOXID);
03478         $sCatId = $oDb->quote($sCatId);
03479 
03480         if (!$dPriceFromTo) {
03481             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03482             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03483             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03484             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03485         } else {
03486             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03487             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03488             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03489             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03490         }
03491         return $sSelect;
03492     }
03493 
03499     protected function _getAmountPriceList()
03500     {
03501         if ( $this->_oAmountPriceList === null ) {
03502             $this->_oAmountPriceList = array();
03503             if ( !$this->skipDiscounts() ) {
03504                 $myConfig = $this->getConfig();
03505                 $sArtId   = $this->getId();
03506 
03507                 // #1690C - Scale prices and variants
03508                 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03509                     $sArtId = $this->oxarticles__oxparentid->value;
03510                 }
03511 
03512                 //collecting assigned to article amount-price list
03513                 $oAmPriceList = oxNew( 'oxlist' );
03514                 $oAmPriceList->init( 'oxbase', 'oxprice2article' );
03515 
03516                 $sShopID = $myConfig->getShopID();
03517                 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03518                     $sShopSelect = '1';
03519                 } else {
03520                     $sShopSelect = " oxshopid =  '$sShopID' ";
03521                 }
03522 
03523                 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = " . oxDb::getDb()->quote( $sArtId ) . " and $sShopSelect order by oxamount ");
03524 
03525                 // prepare abs prices if currently having percentages
03526                 $oBasePrice = $this->_getGroupPrice();
03527                 foreach ( $oAmPriceList as $oAmPrice ) {
03528                     if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03529                         $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03530                     }
03531                 }
03532 
03533                 $this->_oAmountPriceList = $oAmPriceList;
03534             }
03535         }
03536 
03537         return $this->_oAmountPriceList;
03538     }
03539 
03547     protected function _isFieldEmpty( $sFieldName )
03548     {
03549         $mValue = $this->$sFieldName->value;
03550 
03551         if ( is_null( $mValue ) ) {
03552             return true;
03553         }
03554 
03555         if ( $mValue === '' ) {
03556             return true;
03557         }
03558 
03559         $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03560 
03561         if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03562             return true;
03563         }
03564 
03565 
03566         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03567             return true;
03568         }
03569 
03570         $sFieldName = strtolower($sFieldName);
03571 
03572         if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03573             return true;
03574         }
03575 
03576         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03577             return true;
03578         }
03579 
03580         return false;
03581     }
03582 
03590     protected function _assignParentFieldValue($sFieldName)
03591     {
03592         if (!($oParentArticle = $this->getParentArticle())) {
03593             return;
03594         }
03595 
03596         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03597 
03598         // assigning only theese which parent article has
03599         if ( $oParentArticle->$sCopyFieldName != null ) {
03600 
03601             // only overwrite database values
03602             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03603                 return;
03604             }
03605 
03606             //do not copy certain fields
03607             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03608                 return;
03609             }
03610 
03611             //COPY THE VALUE
03612             // assigning images from parent only if variant has no master image (#1807)
03613             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03614                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03615                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03616                 }
03617             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03618                 // for zoom images checking master image with specified index
03619                 // assign from parent only if no pictures to variant are added
03620                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03621                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03622                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03623                 }
03624             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03625                 // if no pics generated for variants, load all from
03626                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03627             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03628                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03629             }
03630         }
03631     }
03632 
03638     public function getParentArticle()
03639     {
03640         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03641             $sIndex = $sParentId . "_" . $this->getLanguage();
03642             if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03643                 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03644                 self::$_aLoadedParents[$sIndex]->_blSkipAbPrice  = true;
03645                 self::$_aLoadedParents[$sIndex]->_blLoadPrice    = false;
03646                 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03647                 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03648             }
03649             return self::$_aLoadedParents[$sIndex];
03650         }
03651     }
03652 
03660     protected function _getParentAricle()
03661     {
03662         return $this->getParentArticle();
03663     }
03664 
03670     protected function _assignParentFieldValues()
03671     {
03672         startProfile('articleAssignParentInternal');
03673         if ( $this->oxarticles__oxparentid->value ) {
03674             // yes, we are in fact a variant
03675             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03676                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03677                     $this->_assignParentFieldValue( $sFieldName );
03678                 }
03679             }
03680         }
03681         stopProfile('articleAssignParentInternal');
03682     }
03683 
03689     protected function _assignNotBuyableParent()
03690     {
03691         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03692              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03693             $this->_blNotBuyableParent = true;
03694 
03695         }
03696     }
03697 
03703     protected function _assignStock()
03704     {
03705         $myConfig = $this->getConfig();
03706         // -----------------------------------
03707         // stock
03708         // -----------------------------------
03709 
03710         // #1125 A. must round (using floor()) value taken from database and cast to int
03711         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03712             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03713         }
03714         //GREEN light
03715         $this->_iStockStatus = 0;
03716 
03717         // if we have flag /*1 or*/ 4 - we show always green light
03718         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03719             //ORANGE light
03720             $iStock = $this->oxarticles__oxstock->value;
03721 
03722             if ($this->_blNotBuyableParent) {
03723                 $iStock = $this->oxarticles__oxvarstock->value;
03724             }
03725 
03726 
03727             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03728                 $this->_iStockStatus = 1;
03729             }
03730 
03731             //RED light
03732             if ($iStock <= 0) {
03733                 $this->_iStockStatus = -1;
03734             }
03735         }
03736 
03737 
03738         // stock
03739         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03740             $iOnStock = $this->oxarticles__oxstock->value;
03741             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03742                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03743             }
03744             if ($iOnStock <= 0) {
03745                 $this->setBuyableState( false );
03746             }
03747         }
03748 
03749         //exceptional handling for variant parent stock:
03750         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03751             $this->setBuyableState( true );
03752             //but then at least setting notBuaybleParent to true
03753             $this->_blNotBuyableParent = true;
03754         }
03755 
03756         //special treatment for lists when blVariantParentBuyable config option is set to false
03757         //then we just hide "to basket" button.
03758         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03759         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03760             $this->setBuyableState( false );
03761         }
03762 
03763         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03764         if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03765             $this->setBuyableState( false );
03766         }
03767     }
03768 
03774     protected function _assignPrices()
03775     {
03776         $myConfig = $this->getConfig();
03777 
03778         // Performance
03779         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03780             return;
03781         }
03782 
03783         //price per unit handling
03784         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03785             // compute price
03786             $dPrice = $this->getPrice()->getBruttoPrice();
03787             $oCur = $myConfig->getActShopCurrencyObject();
03788             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03789         }
03790 
03791         //getting min and max prices of variants
03792         if ( $this->_hasAnyVariant() ) {
03793             $this->_applyRangePrice();
03794         }
03795     }
03796 
03802     protected function _assignPersistentParam()
03803     {
03804         // Persistent Parameter Handling
03805         $aPersParam     = oxSession::getVar( 'persparam');
03806         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03807             $this->_aPersistParam = $aPersParam[$this->getId()];
03808         }
03809     }
03810 
03816     protected function _assignDynImageDir()
03817     {
03818         $myConfig = $this->getConfig();
03819 
03820         $sThisShop = $this->oxarticles__oxshopid->value;
03821 
03822         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03823         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03824         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03825         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03826     }
03827 
03833     protected function _assignComparisonListFlag()
03834     {
03835         // #657 add a flag if article is on comparisonlist
03836 
03837         $aItems = oxSession::getVar('aFiltcompproducts');
03838         if ( isset( $aItems[$this->getId()])) {
03839             $this->_blIsOnComparisonList = true;
03840         }
03841     }
03842 
03848     protected function _assignAttributes()
03849     {
03850         //#1029T load attributes
03851         //#1078S removed check for module "Produktvergleich"
03852         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03853             $this->getAttributes();
03854         }
03855     }
03856 
03857 
03865     protected function _insert()
03866     {
03867         // set oxinsert
03868         $iInsertTime = time();
03869         $now = date('Y-m-d H:i:s', $iInsertTime);
03870         $this->oxarticles__oxinsert    = new oxField( $now );
03871         $this->oxarticles__oxtimestamp = new oxField( $now );
03872         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03873             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03874         }
03875 
03876         return parent::_insert();
03877     }
03878 
03884     protected function _update()
03885     {
03886 
03887         $this->_skipSaveFields();
03888 
03889         $myConfig = $this->getConfig();
03890 
03891 
03892         return parent::_update();
03893     }
03894 
03902     protected function _deleteRecords($sOXID)
03903     {
03904         $oDB = oxDb::getDb();
03905 
03906         $sOXID = $oDB->quote($sOXID);
03907 
03908         //remove other records
03909         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03910         $oDB->execute( $sDelete);
03911 
03912         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03913         $oDB->execute( $sDelete);
03914 
03915         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03916         $oDB->execute( $sDelete);
03917 
03918         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03919         $oDB->execute( $sDelete);
03920 
03921         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03922         $oDB->execute( $sDelete);
03923 
03924         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03925         $oDB->execute( $sDelete);
03926 
03927         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03928         $oDB->execute( $sDelete);
03929 
03930         //#1508C - deleting oxobject2delivery entries added
03931         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03932         $oDB->execute( $sDelete);
03933 
03934         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03935         $oDB->execute( $sDelete);
03936 
03937         //delete the record
03938         foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03939             $oDB->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03940         }
03941 
03942         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03943         $rs = $oDB->execute( $sDelete );
03944 
03945         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03946         $rs = $oDB->execute( $sDelete );
03947 
03948 
03949         return $rs;
03950     }
03951 
03959     protected function _deleteVariantRecords( $sOXID )
03960     {
03961         if ( $sOXID ) {
03962             $oDb = oxDb::getDb();
03963             //collect variants to remove recursively
03964             $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03965             $rs = $oDb->execute( $sQ );
03966             if ($rs != false && $rs->recordCount() > 0) {
03967                 while (!$rs->EOF) {
03968                     $this->delete( $rs->fields[0] );
03969                     $rs->moveNext();
03970                 }
03971             }
03972         }
03973     }
03974 
03984     protected function _resetCacheAndArticleCount( $sOxid )
03985     {
03986         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03987     }
03988 
03994     protected function _deletePics()
03995     {
03996         $myUtilsPic = oxUtilsPic::getInstance();
03997         $myConfig   = $this->getConfig();
03998         $oPictureHandler = oxPictureHandler::getInstance();
03999 
04000         //deleting custom main icon
04001         $oPictureHandler->deleteMainIcon( $this );
04002 
04003         //deleting custom thumbnail
04004         $oPictureHandler->deleteThumbnail( $this );
04005 
04006         $sAbsDynImageDir = $myConfig->getPictureDir(false);
04007 
04008         // deleting master image and all generated images
04009         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04010         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04011             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04012         }
04013     }
04014 
04024     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04025     {
04026 
04027         $myUtilsCount = oxUtilsCount::getInstance();
04028 
04029         if ( $sVendorId ) {
04030             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04031         }
04032 
04033         if ( $sManufacturerId ) {
04034             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04035         }
04036 
04037         //also reseting category counts
04038         $oDb = oxDb::getDb();
04039         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04040         $oRs = $oDb->execute( $sQ );
04041         if ( $oRs !== false && $oRs->recordCount() > 0) {
04042             while ( !$oRs->EOF ) {
04043                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04044                 $oRs->moveNext();
04045             }
04046         }
04047     }
04048 
04056     protected function _onChangeUpdateStock( $sParentID )
04057     {
04058         if ( $sParentID ) {
04059             $oDb = oxDb::getDb();
04060             $sParentIdQuoted = $oDb->quote($sParentID);
04061             $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04062             $rs = $oDb->execute($sQ);
04063             $iOldStock = $rs->fields[0];
04064             $iVendorID = $rs->fields[1];
04065             $iManufacturerID = $rs->fields[2];
04066 
04067             $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04068             $iStock = (float) $oDb->getOne( $sQ );
04069 
04070             $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04071             $oDb->execute( $sQ );
04072 
04073                 //now lets update category counts
04074                 //first detect stock status change for this article (to or from 0)
04075                 if ( $iStock < 0 ) {
04076                     $iStock = 0;
04077                 }
04078                 if ( $iOldStock < 0 ) {
04079                     $iOldStock = 0;
04080                 }
04081                 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04082                     //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04083                     // so far we leave it like this but later we could move all count resets to one or two functions
04084                     $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04085                 }
04086         }
04087     }
04088 
04096     protected function _onChangeStockResetCount( $sOxid )
04097     {
04098         $myConfig = $this->getConfig();
04099 
04100         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04101            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04102 
04103                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04104         }
04105     }
04106 
04114     protected function _onChangeUpdateVarCount( $sParentID )
04115     {
04116         if ( $sParentID ) {
04117             $oDb = oxDb::getDb();
04118             $sParentIdQuoted = $oDb->quote( $sParentID );
04119             $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04120             $iVarCount = (int) $oDb->getOne( $sQ );
04121 
04122             $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04123             $oDb->execute( $sQ );
04124         }
04125     }
04126 
04134     protected function _onChangeUpdateMinVarPrice( $sParentID )
04135     {
04136         if ( $sParentID ) {
04137             $oDb = oxDb::getDb();
04138             $sParentIdQuoted = $oDb->quote($sParentID);
04139             //#M0000883 (Sarunas)
04140             $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04141             $dVarMinPrice = $oDb->getOne($sQ);
04142 
04143             $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04144 
04145             $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04146 
04147             if ($dVarMinPrice) {
04148                 if ($blParentBuyable) {
04149                     $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04150                 }
04151 
04152             } else {
04153                 $dVarMinPrice = $dParentPrice;
04154             }
04155 
04156             if ( $dVarMinPrice ) {
04157                 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04158                 $oDb->execute($sQ);
04159             }
04160         }
04161     }
04162 
04163 
04169     protected function _applyRangePrice()
04170     {
04171         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04172         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04173             return;
04174         }
04175 
04176         $this->_blIsRangePrice = false;
04177 
04178         // if parent is buyable - do not apply range price calcculations
04179         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04180             return;
04181         }
04182 
04183         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04184             //#2509 we cannot force brutto price here, as netto price can be added to DB
04185             // $this->getPrice()->setBruttoPriceMode();
04186             $dPrice = $this->oxarticles__oxvarminprice->value;
04187             $this->getPrice()->setPrice($dPrice);
04188             $this->_blIsRangePrice = true;
04189             $this->_calculatePrice( $this->getPrice() );
04190             return;
04191         }
04192 
04193         $aPrices = array();
04194 
04195         if (!$this->_blNotBuyableParent) {
04196             $aPrices[] = $this->getPrice()->getBruttoPrice();
04197         }
04198 
04199         $aVariants = $this->getVariants(false);
04200 
04201         if (count($aVariants)) {
04202             foreach ($aVariants as $sKey => $oVariant) {
04203                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04204             }
04205         }
04206 
04207         if ( count( $aPrices ) ) {
04208             $dMinPrice = min( $aPrices );
04209             $dMaxPrice = max( $aPrices );
04210         }
04211 
04212         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04213             $this->getPrice()->setBruttoPriceMode();
04214             $this->getPrice()->setPrice($dMinPrice);
04215         }
04216 
04217         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04218             $this->getPrice()->setBruttoPriceMode();
04219             $this->getPrice()->setPrice($dMinPrice);
04220             $this->_blIsRangePrice = true;
04221         }
04222     }
04223 
04230     public function getProductId()
04231     {
04232         return $this->getId();
04233     }
04234 
04240     public function getProductParentId()
04241     {
04242         return $this->oxarticles__oxparentid->value;
04243     }
04244 
04250     public function isOrderArticle()
04251     {
04252         return false;
04253     }
04254 
04260     public function isVariant()
04261     {
04262         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04263     }
04264 
04270     public function isMdVariant()
04271     {
04272         $oMdVariant = oxNew( "oxVariantHandler" );
04273 
04274         return $oMdVariant->isMdVariant($this);
04275     }
04276 
04284     public function getSqlForPriceCategories($sFields = '')
04285     {
04286         if (!$sFields) {
04287             $sFields = 'oxid';
04288         }
04289         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04290         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04291         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04292                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04293                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04294     }
04295 
04303     public function inPriceCategory( $sCatNid )
04304     {
04305         $oDb = oxDb::getDb();
04306 
04307         $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04308         $sQuotedCnid = $oDb->quote( $sCatNid );
04309         return (bool) $oDb->getOne(
04310             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04311            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04312            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04313            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04314            .")"
04315         );
04316     }
04317 
04323     public function getMdVariants()
04324     {
04325         if ( $this->_oMdVariants ) {
04326             return $this->_oMdVariants;
04327         }
04328 
04329         $oParentArticle = $this->getParentArticle();
04330         if ( $oParentArticle ) {
04331             $oVariants = $oParentArticle->getVariants();
04332         } else {
04333             $oVariants = $this->getVariants();
04334         }
04335 
04336         $oVariantHandler = oxNew( "oxVariantHandler" );
04337         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04338 
04339         return $this->_oMdVariants;
04340     }
04341 
04347     public function getMdSubvariants()
04348     {
04349         return $this->getMdVariants()->getMdSubvariants();
04350     }
04351 
04359     protected function _hasMasterImage( $iIndex )
04360     {
04361         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04362 
04363         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04364             return false;
04365         }
04366         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04367             return false;
04368         }
04369 
04370         $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04371 
04372         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04373             return true;
04374         }
04375 
04376         return false;
04377     }
04378 
04387     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04388     {
04389         if ( $sFieldName ) {
04390             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04391             return $this->$sFieldName->value;
04392         }
04393     }
04394 
04402     public function getMasterZoomPictureUrl( $iIndex )
04403     {
04404         $sPicUrl  = false;
04405         $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04406 
04407         if ( $sPicName && $sPicName != "nopic.jpg" ) {
04408             $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04409             if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04410                 $sPicUrl = false;
04411             }
04412         }
04413 
04414         return $sPicUrl;
04415     }
04416 
04422     public function hasAmountPrice()
04423     {
04424         if ( self::$_blHasAmountPrice === null ) {
04425 
04426             self::$_blHasAmountPrice = false;
04427 
04428             $oDb = oxDb::getDb();
04429             $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04430 
04431             if ( $oDb->getOne( $sQ ) ) {
04432                 self::$_blHasAmountPrice = true;
04433             }
04434         }
04435 
04436         return self::$_blHasAmountPrice;
04437     }
04438 }