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