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 $_sClassName = 'oxarticle';
00025 
00031     protected $_blUseLazyLoading = true;
00032 
00038     protected $_sItemKey;
00039 
00045     protected $_blCalcPrice    = true;
00046 
00051     protected $_oPrice      = null;
00052 
00058     protected $_dArticleVat = null;
00059 
00065     protected $_aPersistParam  = null;
00066 
00072     protected $_blNotBuyable   = false;
00073 
00080     protected $_blLoadVariants = true;
00081 
00087     protected $_aVariants = null;
00088 
00094     protected $_aVariantsWithNotOrderables = null;
00095 
00104     protected $_blNotBuyableParent  = false;
00105 
00106 
00110     protected $_blHasVariants = false;
00111 
00115     protected $_blHasMdVariants = false;
00116 
00121     protected $_blIsOnComparisonList = false;
00122 
00127     protected $_oUser = null;
00128 
00134     protected $_blLoadPrice = true;
00135 
00139     protected $_blSkipAbPrice = false;
00140 
00147     protected $_fPricePerUnit = null;
00148 
00152     protected $_blLoadParentData = false;
00153 
00157     protected $_blAllowEmptyParentId = false;
00158 
00162     protected $_blSkipAssign = false;
00163 
00169     protected $_blSkipDiscounts = null;
00170 
00175     protected $_oAttributeList = null;
00176 
00177 
00183     protected $_blIsRangePrice = false;
00184 
00190     protected $_aMediaUrls = null;
00191 
00197     static protected $_aLoadedParents;
00198 
00204     static protected $_aSelList;
00205 
00211     protected $_aDispSelList;
00212 
00218     protected $_blIsSeoObject = true;
00219 
00225     protected $_oAmountPriceList = null;
00226 
00235     protected $_iLinkType = 0;
00236 
00242     protected $_aStdUrls = array();
00243 
00249     protected $_aSeoUrls = array();
00250 
00256     protected $_aSeoAddParams = array();
00257 
00263     protected $_aStdAddParams = array();
00264 
00270     protected $_sDynImageDir = null;
00271 
00277     protected $_sMoreDetailLink = null;
00278 
00284     protected $_sToBasketLink = null;
00285 
00291     protected $_iStockStatus = null;
00292 
00298     protected $_oTPrice = null;
00299 
00305     protected $_oAmountPriceInfo = null;
00306 
00312     protected $_dAmountPrice = null;
00313 
00319     protected static $_aArticleManufacturers = array();
00320 
00326     protected static $_aArticleVendors = array();
00327 
00333     protected static $_aArticleCats = array();
00334 
00340     protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00341                                              'oxarticles__oxtimestamp',
00342                                              'oxarticles__oxnid',
00343                                              'oxarticles__oxid',
00344                                              'oxarticles__oxparentid');
00345 
00351     protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00352                                          'oxarticles__oxfreeshipping',
00353                                          //'oxarticles__oxremindactive',
00354                                          'oxarticles__oxisdownloadable');
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;
00390 
00395     protected static $_blHasAmountPrice = null;
00396 
00401     protected $_aArticleFiles = null;
00402 
00403 
00412     public function __construct($aParams = null)
00413     {
00414         if ( $aParams && is_array($aParams)) {
00415             foreach ( $aParams as $sParam => $mValue) {
00416                 $this->$sParam = $mValue;
00417             }
00418         }
00419         parent::__construct();
00420         $this->init( 'oxarticles' );
00421 
00422         $this->_blIsRangePrice = false;
00423     }
00424 
00433     public function __get($sName)
00434     {
00435         $myUtils = oxUtils::getInstance();
00436         // deprecated since 2011.03.10, should be used getLongDescription() / getLongDesc()
00437         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00438             return $this->getLongDescription();
00439         }
00440 
00441         $this->$sName = parent::__get($sName);
00442         if ( $this->$sName ) {
00443             // since the field could have been loaded via lazyloading
00444             $this->_assignParentFieldValue($sName);
00445         }
00446 
00447         return $this->$sName;
00448     }
00449 
00458     public function __set( $sName, $sValue )
00459     {
00460         // deprecated since 2011.03.14, should be used setArticleLongDesc()
00461         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00462             if ($this->_blEmployMultilanguage) {
00463                 $sValue = ( $sValue instanceof oxField ) ? $sValue->getRawValue() : $sValue;
00464                 $this->setArticleLongDesc( $sValue );
00465             } else {
00466                 $this->$sName = $sValue;
00467             }
00468         } else {
00469             parent::__set( $sName, $sValue );
00470         }
00471     }
00472 
00480     public function setId( $sId = null )
00481     {
00482         $sId = parent::setId( $sId );
00483 
00484         // TODO: in oxbase::setId make it to check if exists and update, not recreate, then delete this overload
00485         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00486 
00487         return $sId;
00488     }
00489 
00499     public function getActiveCheckQuery( $blForceCoreTable = null )
00500     {
00501         $sTable = $this->getViewName( $blForceCoreTable );
00502 
00503         // check if article is still active
00504         $sQ = " $sTable.oxactive = 1 ";
00505 
00506         // enabled time range check ?
00507         if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00508             $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00509             $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00510         }
00511 
00512         return $sQ;
00513     }
00514 
00528     public function getStockCheckQuery( $blForceCoreTable = null )
00529     {
00530         $myConfig = $this->getConfig();
00531         $sTable = $this->getViewName( $blForceCoreTable );
00532 
00533         $sQ = "";
00534 
00535         //do not check for variants
00536         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00537             $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0  ) ";
00538             //V #M513: When Parent article is not purchaseble, it's visibility should be displayed in shop only if any of Variants is available.
00539             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00540                 $sTimeCheckQ = '';
00541                 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00542                      $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00543                      $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00544                 }
00545                 $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 ) ) ";
00546             }
00547         }
00548 
00549         return $sQ;
00550     }
00551 
00563     public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null  )
00564     {
00565         $sTable = $this->getViewName( $blForceCoreTable );
00566         $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00567 
00568         //checking if variant is active and stock status
00569         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00570             $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00571             if ( $blRemoveNotOrderables ) {
00572                 $sQ .= " and $sTable.oxstockflag != 3 ";
00573             }
00574             $sQ .= " ) ) ";
00575         }
00576 
00577         return $sQ;
00578     }
00579 
00587     public function getSqlActiveSnippet( $blForceCoreTable = null )
00588     {
00589         $myConfig = $this->getConfig();
00590 
00591         // check if article is still active
00592         $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00593 
00594         // stock and variants check
00595         $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00596 
00597 
00598         return "( $sQ ) ";
00599     }
00600 
00608     public function setSkipAssign($blSkipAssign)
00609     {
00610         $this->_blSkipAssign = $blSkipAssign;
00611     }
00612 
00618     public function disablePriceLoad()
00619     {
00620         $this->_blLoadPrice = false;
00621     }
00622 
00628     public function enablePriceLoad()
00629     {
00630         $this->_blLoadPrice = true;
00631     }
00632 
00638     public function getItemKey()
00639     {
00640         return $this->_sItemKey;
00641     }
00642 
00650     public function setItemKey($sItemKey)
00651     {
00652         $this->_sItemKey = $sItemKey;
00653     }
00654 
00662     public function setNoVariantLoading( $blLoadVariants )
00663     {
00664         $this->_blLoadVariants = !$blLoadVariants;
00665     }
00666 
00672     public function isBuyable()
00673     {
00674         if ($this->_blNotBuyableParent) {
00675             return false;
00676         }
00677 
00678         return !$this->_blNotBuyable;
00679     }
00680 
00686     public function getPersParams()
00687     {
00688         return $this->_aPersistParam;
00689     }
00690 
00696     public function isOnComparisonList()
00697     {
00698         return $this->_blIsOnComparisonList;
00699     }
00700 
00708     public function setOnComparisonList( $blOnList )
00709     {
00710         $this->_blIsOnComparisonList = $blOnList;
00711     }
00712 
00720     public function setLoadParentData($blLoadParentData)
00721     {
00722         $this->_blLoadParentData = $blLoadParentData;
00723     }
00724 
00732     public function setSkipAbPrice( $blSkipAbPrice = null )
00733     {
00734         $this->_blSkipAbPrice = $blSkipAbPrice;
00735     }
00736 
00744     public function getSearchableFields()
00745     {
00746         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00747         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00748 
00749         return $aFields;
00750     }
00751 
00752 
00760     public function isMultilingualField($sFieldName)
00761     {
00762         switch ($sFieldName) {
00763             case "oxlongdesc":
00764             case "oxtags":
00765                 return true;
00766         }
00767 
00768         return parent::isMultilingualField($sFieldName);
00769     }
00770 
00776     public function isVisible()
00777     {
00778 
00779         // admin preview mode
00780         if ( ( $blCanPreview = oxUtils::getInstance()->canPreview() ) !== null ) {
00781             return $blCanPreview;
00782         }
00783 
00784         // active ?
00785         $sNow = date('Y-m-d H:i:s');
00786         if ( !$this->oxarticles__oxactive->value &&
00787              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00788                 $this->oxarticles__oxactiveto->value < $sNow
00789              )) {
00790             return false;
00791         }
00792 
00793         // stock flags
00794         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00795             $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00796             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00797                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00798             }
00799             if ( $iOnStock <= 0 ) {
00800                 return false;
00801             }
00802         }
00803 
00804         return true;
00805     }
00806 
00815     public function assign( $aRecord)
00816     {
00817         startProfile('articleAssign');
00818 
00819 
00820         // load object from database
00821         parent::assign( $aRecord);
00822 
00823         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00824 
00825         // check for simple article.
00826         if ($this->_blSkipAssign) {
00827             return;
00828         }
00829 
00830         $this->_assignParentFieldValues();
00831         $this->_assignNotBuyableParent();
00832 
00833         $this->_assignStock();
00834         startProfile('articleAssignPrices');
00835         $this->_assignPrices();
00836         stopProfile('articleAssignPrices');
00837         $this->_assignPersistentParam();
00838         $this->_assignDynImageDir();
00839         $this->_assignComparisonListFlag();
00840         $this->_assignAttributes();
00841 
00842 
00843         //$this->_seoAssign();
00844 
00845         stopProfile('articleAssign');
00846     }
00847 
00858     public function load( $oxID)
00859     {
00860         // A. #1325 resetting to avoid problems when reloading (details etc)
00861         $this->_blNotBuyableParent = false;
00862 
00863         $blRet = parent::load( $oxID);
00864 
00865         // convert date's to international format
00866         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00867         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00868 
00869         return $blRet;
00870     }
00871 
00879     public function addToRatingAverage( $iRating )
00880     {
00881         $dOldRating = $this->oxarticles__oxrating->value;
00882         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00883         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00884         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00885         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00886         $dRatingCnt = (int) ($dOldCnt + 1);
00887         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00888         $oDb = oxDb::getDb();
00889         $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00890     }
00891 
00899     public function setRatingAverage( $iRating )
00900     {
00901          $this->oxarticles__oxrating = new oxField( $iRating );
00902     }
00903 
00911     public function setRatingCount( $iRatingCnt )
00912     {
00913          $this->oxarticles__oxratingcnt = new oxField( $iRatingCnt );
00914     }
00915 
00923     public function getArticleRatingAverage( $blIncludeVariants = false )
00924     {
00925         if ( !$blIncludeVariants ) {
00926             return round( $this->oxarticles__oxrating->value, 1);
00927         } else {
00928             $oRating = oxNew( 'oxRating' );
00929             return $oRating->getRatingAverage( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00930         }
00931     }
00932 
00940     public function getArticleRatingCount( $blIncludeVariants = false )
00941     {
00942         if ( !$blIncludeVariants ) {
00943             return $this->oxarticles__oxratingcnt->value;
00944         } else {
00945             $oRating = oxNew( 'oxRating' );
00946             return $oRating->getRatingCount( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00947         }
00948     }
00949 
00950 
00956     public function getReviews()
00957     {
00958         $aIds = array($this->getId());
00959 
00960         if ( $this->oxarticles__oxparentid->value ) {
00961             $aIds[] = $this->oxarticles__oxparentid->value;
00962         }
00963 
00964         // showing variant reviews ..
00965         if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00966             $aAdd = $this->_getVariantsIds();
00967             if (is_array($aAdd)) {
00968                 $aIds = array_merge($aIds, $aAdd);
00969             }
00970         }
00971 
00972         $oReview = oxNew('oxreview');
00973         $oRevs = $oReview->loadList('oxarticle', $aIds);
00974 
00975         //if no review found, return null
00976         if ( $oRevs->count() < 1 ) {
00977             return null;
00978         }
00979 
00980         return $oRevs;
00981     }
00982 
00988     public function getCrossSelling()
00989     {
00990         $oCrosslist = oxNew( "oxarticlelist");
00991         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00992         if ( $oCrosslist->count() ) {
00993             return $oCrosslist;
00994         }
00995     }
00996 
01002     public function getAccessoires()
01003     {
01004         $myConfig = $this->getConfig();
01005 
01006         // Performance
01007         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01008             return;
01009         }
01010 
01011         $oAcclist = oxNew( "oxarticlelist");
01012         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01013         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01014 
01015         if ( $oAcclist->count()) {
01016             return $oAcclist;
01017         }
01018     }
01019 
01025     public function getSimilarProducts()
01026     {
01027         // Performance
01028         $myConfig = $this->getConfig();
01029         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01030             return;
01031         }
01032 
01033         $sArticleTable = $this->getViewName();
01034 
01035         $sAttribs = '';
01036         $iCnt = 0;
01037         $this->_getAttribsString($sAttribs, $iCnt);
01038 
01039         if ( !$sAttribs) {
01040             return null;
01041         }
01042 
01043         $aList = $this->_getSimList($sAttribs, $iCnt);
01044 
01045         if ( count( $aList ) ) {
01046             uasort( $aList, 'cmpart');
01047 
01048             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01049 
01050             $oSimilarlist = oxNew( 'oxarticlelist' );
01051             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01052             $oSimilarlist->selectString( $sSearch);
01053 
01054             return $oSimilarlist;
01055         }
01056     }
01057 
01063     public function getCustomerAlsoBoughtThisProducts()
01064     {
01065         // Performance
01066         $myConfig = $this->getConfig();
01067         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01068             return;
01069         }
01070 
01071         // selecting products that fits
01072         $sQ = $this->_generateSearchStrForCustomerBought();
01073 
01074         $oArticles = oxNew( 'oxarticlelist' );
01075         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01076         $oArticles->selectString( $sQ );
01077         if ( $oArticles->count() ) {
01078             return $oArticles;
01079         }
01080     }
01081 
01088     public function loadAmountPriceInfo()
01089     {
01090         $myConfig = $this->getConfig();
01091         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice || !$this->hasAmountPrice() ) {
01092             return array();
01093         }
01094 
01095         if ( $this->_oAmountPriceInfo === null ) {
01096             $this->_oAmountPriceInfo = array();
01097             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01098                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01099             }
01100         }
01101         return $this->_oAmountPriceInfo;
01102     }
01103 
01111     public function getSelectLists($sKeyPrefix = null)
01112     {
01113         //#1468C - more then one article in basket with different selectlist...
01114         //optionall function parameter $sKeyPrefix added, used only in basket.php
01115         $sKey = $this->getId();
01116         if ( isset( $sKeyPrefix ) ) {
01117             $sKey = $sKeyPrefix.'__'.$sKey;
01118         }
01119         if ( !isset( self::$_aSelList[$sKey] ) ) {
01120             $oDb = oxDb::getDb();
01121             $sSLViewName = getViewName( 'oxselectlist' );
01122 
01123             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01124                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01125 
01126             // all selectlists this article has
01127             $oLists = oxNew( 'oxlist' );
01128             $oLists->init( 'oxselectlist' );
01129             $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01130 
01131             //#1104S if this is variant ant it has no selectlists, trying with parent
01132             if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01133                 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01134             }
01135 
01136             $dVat = 0;
01137             if ( $this->getPrice() != null ) {
01138                 $dVat = $this->getPrice()->getVat();
01139             }
01140 
01141             $iCnt = 0;
01142             self::$_aSelList[$sKey] = array();
01143             foreach ( $oLists as $oSelectlist ) {
01144                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01145                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01146                 $iCnt++;
01147             }
01148         }
01149         return self::$_aSelList[$sKey];
01150     }
01151 
01159     protected function _hasAnyVariant( $blForceCoreTable = null )
01160     {
01161         $blHas = false;
01162         if ( ( $sId = $this->getId() ) ) {
01163             if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01164                 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01165             } else {
01166                 $sArticleTable = $this->getViewName( $blForceCoreTable );
01167                 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01168             }
01169 
01170         }
01171         return $blHas;
01172     }
01173 
01179     public function hasMdVariants()
01180     {
01181         return $this->_blHasMdVariants;
01182     }
01183 
01193     public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01194     {
01195 
01196         $iLimit = (int) $iLimit;
01197         if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01198             $aVariantSelections = false;
01199             if ( $this->oxarticles__oxvarcount->value ) {
01200                 $oVariants = $this->getVariants( false );
01201                 $aVariantSelections = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $oVariants, $aFilterIds, $sActVariantId, $iLimit );
01202 
01203                 if ( !empty($oVariants) && empty( $aVariantSelections['rawselections'] ) ) {
01204                     $aVariantSelections = false;
01205                 }
01206             }
01207             $this->_aVariantSelections[$iLimit] = $aVariantSelections;
01208         }
01209 
01210         return $this->_aVariantSelections[$iLimit];
01211     }
01212 
01221     public function getSelections( $iLimit = null, $aFilter = null )
01222     {
01223         $sId = $this->getId() . ( (int) $iLimit );
01224         if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01225 
01226             $oDb = oxDb::getDb();
01227             $sSLViewName = getViewName( 'oxselectlist' );
01228 
01229             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01230                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01231 
01232             if ( ( $iLimit = (int) $iLimit ) ) {
01233                 $sQ .= " limit $iLimit ";
01234             }
01235 
01236             // vat value for price
01237             $dVat = 0;
01238             if ( ( $oPrice = $this->getPrice() ) != null ) {
01239                 $dVat = $oPrice->getVat();
01240             }
01241 
01242             // all selectlists this article has
01243             $oList = oxNew( 'oxlist' );
01244             $oList->init( 'oxselectlist' );
01245             $oList->getBaseObject()->setVat( $dVat );
01246             $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01247 
01248             //#1104S if this is variant and it has no selectlists, trying with parent
01249             if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01250                 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01251             }
01252 
01253             self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01254         }
01255 
01256         if ( self::$_aSelections[$sId] ) {
01257             // marking active from filter
01258             $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01259             if ( $aFilter ) {
01260                 $iSelIdx = 0;
01261                 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01262                     if ( isset( $aFilter[$iSelIdx] ) ) {
01263                         $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01264                     }
01265                     $iSelIdx++;
01266                 }
01267             }
01268         }
01269 
01270         return self::$_aSelections[$sId];
01271     }
01272 
01282     protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01283     {
01284         $oVariants = array();
01285         if ( ( $sId = $this->getId() ) ) {
01286             //do not load me as a parent later
01287             self::$_aLoadedParents[$sId] = $this;
01288 
01289             $myConfig = $this->getConfig();
01290 
01291             if ( !$this->_blLoadVariants ||
01292                 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01293                 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01294                 return $oVariants;
01295             }
01296 
01297             // cache
01298             $sCacheKey = $blSimple ? "simple" : "full";
01299             if ( $blRemoveNotOrderables ) {
01300                 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01301                    return $this->_aVariants[$sCacheKey];
01302                 } else {
01303                     $this->_aVariants[$sCacheKey] = & $oVariants;
01304                 }
01305             } elseif ( !$blRemoveNotOrderables ) {
01306                 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01307                     return $this->_aVariantsWithNotOrderables[$sCacheKey];
01308                 } else {
01309                     $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01310                 }
01311             }
01312 
01313             if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01314 
01315                 //load simple variants for lists
01316                 if ( $blSimple ) {
01317                     $oVariants = oxNew( 'oxsimplevariantlist' );
01318                     $oVariants->setParent( $this );
01319                 } else {
01320                     //loading variants
01321                     $oVariants = oxNew( 'oxarticlelist' );
01322                     $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01323                 }
01324 
01325                 startProfile("selectVariants");
01326                 $blUseCoreTable = (bool) $blForceCoreTable;
01327                 $oBaseObject = $oVariants->getBaseObject();
01328                 $oBaseObject->setLanguage( $this->getLanguage() );
01329 
01330 
01331                 $sArticleTable = $this->getViewName( $blUseCoreTable );
01332 
01333                 $sSelect = "select ".$oBaseObject->getSelectFields( $blUseCoreTable )." from $sArticleTable where " .
01334                            $this->getActiveCheckQuery( $blUseCoreTable ) .
01335                            $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01336                            " order by $sArticleTable.oxsort";
01337 
01338                 $oVariants->selectString( $sSelect );
01339 
01340                 //if this is multidimensional variants, make additional processing
01341                 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01342                     $oMdVariants = oxNew( "oxVariantHandler" );
01343                     $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01344                 }
01345                 stopProfile("selectVariants");
01346             }
01347 
01348             //if we have variants then depending on config option the parent may be non buyable
01349             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01350                 $this->_blNotBuyableParent = true;
01351             }
01352 
01353             //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01354             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01355                 $this->_blNotBuyable = true;
01356             }
01357         }
01358 
01359         return $oVariants;
01360     }
01361 
01370     public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01371     {
01372         return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01373     }
01374 
01383     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null  )
01384     {
01385         return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01386     }
01387 
01393     public function getSimpleVariants()
01394     {
01395         if ( $this->oxarticles__oxvarcount->value) {
01396             return $this->getVariants();
01397         }
01398     }
01399 
01408     public function getAdminVariants( $sLanguage = null )
01409     {
01410         $oVariants = oxNew( 'oxarticlelist');
01411         if ( ( $sId = $this->getId() ) ) {
01412 
01413             $oBaseObj = $oVariants->getBaseObject();
01414 
01415             if ( is_null( $sLanguage ) ) {
01416                 $oBaseObj->setLanguage( oxLang::getInstance()->getBaseLanguage() );
01417             } else {
01418                 $oBaseObj->setLanguage( $sLanguage );
01419             }
01420 
01421             $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01422             $oVariants->selectString( $sSql );
01423 
01424             //if we have variants then depending on config option the parent may be non buyable
01425             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01426                 //$this->blNotBuyable = true;
01427                 $this->_blNotBuyableParent = true;
01428             }
01429         }
01430 
01431         return $oVariants;
01432     }
01433 
01441     public function getCategory()
01442     {
01443         $oCategory = oxNew( 'oxcategory' );
01444         $oCategory->setLanguage( $this->getLanguage() );
01445 
01446         // variant handling
01447         $sOXID = $this->getId();
01448         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01449             $sOXID = $this->oxarticles__oxparentid->value;
01450         }
01451 
01452         if ( $sOXID ) {
01453             // if the oxcategory instance of this article is not cached
01454             if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01455                 startPRofile( 'getCategory' );
01456                 $oStr = getStr();
01457                 $sWhere   = $oCategory->getSqlActiveSnippet();
01458                 $sSelect  = $this->_generateSearchStr( $sOXID );
01459                 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01460 
01461                 // category not found ?
01462                 if ( !$oCategory->assignRecord( $sSelect ) ) {
01463 
01464                     $sSelect  = $this->_generateSearchStr( $sOXID, true );
01465                     $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01466 
01467                     // looking for price category
01468                     if ( !$oCategory->assignRecord( $sSelect ) ) {
01469                         $oCategory = null;
01470                     }
01471                 }
01472                 // add the category instance to cache
01473                 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01474                 stopPRofile( 'getCategory' );
01475             } else {
01476                // if the oxcategory instance is cached
01477                $oCategory = $this->_aCategoryCache[ $sOXID ];
01478             }
01479         }
01480 
01481         return $oCategory;
01482     }
01483 
01492     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01493     {
01494         $myConfig = $this->getConfig();
01495         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01496             return self::$_aArticleCats[$this->getId()];
01497         }
01498 
01499         // variant handling
01500         $sOXID = $this->getId();
01501         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01502             $sOXID = $this->oxarticles__oxparentid->value;
01503         }
01504 
01505         // we do not use lists here as we dont need this overhead right now
01506         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01507         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01508         $rs = $oDb->select( $sSql );
01509 
01510 
01511         $aRet = array();
01512 
01513         if ($rs != false && $rs->recordCount() > 0) {
01514             while (!$rs->EOF) {
01515                 $aRet[] = $rs->fields['oxcatnid'];
01516                 $rs->moveNext();
01517             }
01518         }
01519 
01520         // adding price categories if such exists
01521         $sSql = $this->getSqlForPriceCategories();
01522         $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
01523         $rs = $oDb->select( $sSql );
01524 
01525         if ($rs != false && $rs->recordCount() > 0) {
01526             while (!$rs->EOF) {
01527 
01528                 if ( is_array( $rs->fields ) ) {
01529                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01530                 }
01531 
01532 
01533                 if ( !$aRet[$rs->fields['oxid']] ) {
01534                     $aRet[] = $rs->fields['oxid'];
01535                 }
01536                 $rs->moveNext();
01537             }
01538         }
01539 
01540         return self::$_aArticleCats[$this->getId()] = $aRet;
01541     }
01542 
01551     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01552     {
01553         $sO2CView = $this->_getObjectViewName('oxobject2category');
01554         $sCatView = $this->_getObjectViewName('oxcategories');
01555         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01556         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01557         if ( $blActCats ) {
01558             $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 ";
01559         }
01560         $sSelect .= 'order by oxobject2category.oxtime ';
01561         return $sSelect;
01562     }
01563 
01573     public function getVendor( $blShopCheck = true )
01574     {
01575         if ( ( $sVendorId = $this->getVendorId() ) ) {
01576             $oVendor = oxNew( 'oxvendor' );
01577         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01578                 $oVendor = oxNew( 'oxi18n' );
01579                 $oVendor->init('oxvendor');
01580                 $oVendor->setReadOnly( true );
01581             $sVendorId = $this->oxarticles__oxvendorid->value;
01582         }
01583         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01584 
01585             //@deprecated in v.4.5.7, since 2012-02-15; config option removed bug #0003385
01586             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01587                 $oVendor->setReadOnly( true );
01588             }
01589             return $oVendor;
01590         }
01591         return null;
01592     }
01593 
01601     public function getVendorId( $blForceReload = false )
01602     {
01603         $sVendorId = false;
01604         if ( $this->oxarticles__oxvendorid->value ) {
01605                 $sVendorId = $this->oxarticles__oxvendorid->value;
01606 
01607         }
01608         return $sVendorId;
01609     }
01610 
01618     public function getManufacturerId( $blForceReload = false )
01619     {
01620         $sManufacturerId = false;
01621         if ( $this->oxarticles__oxmanufacturerid->value ) {
01622 
01623                 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01624 
01625         }
01626         return $sManufacturerId;
01627     }
01628 
01638     public function getManufacturer( $blShopCheck = true )
01639     {
01640             $oManufacturer = oxNew( 'oxmanufacturer' );;
01641         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01642              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01643             $oManufacturer->setReadOnly( true );
01644             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01645         }
01646 
01647         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01648             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01649                 $oManufacturer->setReadOnly( true );
01650             }
01651             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01652         } else {
01653             $oManufacturer = null;
01654         }
01655 
01656         return $oManufacturer;
01657     }
01658 
01666     public function inCategory( $sCatNid)
01667     {
01668         return in_array( $sCatNid, $this->getCategoryIds());
01669     }
01670 
01679     public function isAssignedToCategory( $sCatId )
01680     {
01681         // variant handling
01682         $sOXID = $this->getId();
01683         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01684             $sOXID = $this->oxarticles__oxparentid->value;
01685         }
01686 
01687         $oDb = oxDb::getDb();
01688         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01689         $sOXID = $oDb->getOne( $sSelect );
01690         // article is assigned to passed category!
01691         if ( isset( $sOXID) && $sOXID) {
01692             return true;
01693         }
01694 
01695         // maybe this category is price category ?
01696         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01697             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01698             if ( $dPriceFromTo > 0) {
01699                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01700                 $sOXID = $oDb->getOne( $sSelect );
01701                 // article is assigned to passed category!
01702                 if ( isset( $sOXID) && $sOXID) {
01703                     return true;
01704                 }
01705             }
01706         }
01707         return false;
01708     }
01709 
01715     public function getTPrice()
01716     {
01717         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01718             return;
01719         }
01720         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01721         if ( $this->_oTPrice !== null ) {
01722             return $this->_oTPrice;
01723         }
01724 
01725         $this->_oTPrice = oxNew( 'oxPrice' );
01726         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01727 
01728         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01729         $this->_applyCurrency( $this->_oTPrice );
01730 
01731         return $this->_oTPrice;
01732     }
01733 
01739     public function skipDiscounts()
01740     {
01741         // allready loaded skip discounts config
01742         if ( $this->_blSkipDiscounts !== null ) {
01743             return $this->_blSkipDiscounts;
01744         }
01745 
01746         if ( $this->oxarticles__oxskipdiscounts->value ) {
01747             return true;
01748         }
01749 
01750 
01751         $this->_blSkipDiscounts = false;
01752         if ( oxDiscountList::getInstance()->hasSkipDiscountCategories() ) {
01753 
01754             $oDb = oxDb::getDb();
01755             $sO2CView  = getViewName( 'oxobject2category', $this->getLanguage() );
01756             $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01757             $sSelect =  "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01758                          where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01759             $this->_blSkipDiscounts = ( $oDb->getOne( $sSelect ) == 1 );
01760         }
01761 
01762         return $this->_blSkipDiscounts;
01763     }
01764 
01772     public function setPrice(oxPrice $oPrice)
01773     {
01774         $this->_oPrice = $oPrice;
01775     }
01776 
01785     public function getBasePrice( $dAmount = 1 )
01786     {
01787         // override this function if you want e.g. different prices
01788         // for diff. usergroups.
01789 
01790         // Performance
01791         $myConfig = $this->getConfig();
01792         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01793             return;
01794 
01795         // GroupPrice or DB price ajusted by AmountPrice
01796         $dPrice = $this->_getAmountPrice( $dAmount );
01797 
01798 
01799         return $dPrice;
01800     }
01801 
01809     public function getPrice( $dAmount = 1 )
01810     {
01811         $myConfig = $this->getConfig();
01812         // Performance
01813         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01814             return;
01815         }
01816 
01817         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01818         if ( $dAmount != 1 || $this->_oPrice === null ) {
01819             $oPrice = oxNew( 'oxPrice' );
01820 
01821             // get base
01822             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01823 
01824             // price handling
01825             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01826                 return $this->_oPrice = $oPrice;
01827             }
01828 
01829             $this->_calculatePrice( $oPrice );
01830             if ( $dAmount != 1 ) {
01831                 return $oPrice;
01832             }
01833 
01834             $this->_oPrice = $oPrice;
01835         }
01836         return $this->_oPrice;
01837     }
01838 
01847     protected function _calculatePrice( $oPrice, $dVat = null )
01848     {
01849         // apply VAT only if configuration requires it
01850         if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01851             $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01852         }
01853 
01854         // apply currency
01855         $this->_applyCurrency( $oPrice );
01856         // apply discounts
01857         if ( !$this->skipDiscounts() ) {
01858             $oDiscountList = oxDiscountList::getInstance();
01859             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
01860         }
01861 
01862         return $oPrice;
01863     }
01864 
01872     public function setArticleUser($oUser)
01873     {
01874         $this->_oUser = $oUser;
01875     }
01876 
01882     public function getArticleUser()
01883     {
01884         if ($this->_oUser) {
01885             return $this->_oUser;
01886         }
01887         return $this->getUser();
01888     }
01889 
01899     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01900     {
01901         $oUser = $oBasket->getBasketUser();
01902         $this->setArticleUser( $oUser );
01903 
01904         $oBasketPrice = oxNew( 'oxPrice' );
01905 
01906         // get base price
01907         $dBasePrice = $this->getBasePrice( $dAmount );
01908 
01909         // applying select list price
01910         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01911 
01912         // setting price
01913         $oBasketPrice->setPrice( $dBasePrice );
01914 
01915         $dVat = oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket );
01916         $this->_calculatePrice( $oBasketPrice, $dVat );
01917 
01918         // returning final price object
01919         return $oBasketPrice;
01920     }
01921 
01934     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01935     {
01936         $oDiscountList = oxDiscountList::getInstance();
01937         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01938     }
01939 
01948     public function delete( $sOXID = null )
01949     {
01950         if ( !$sOXID ) {
01951             $sOXID = $this->getId();
01952         }
01953         if ( !$sOXID ) {
01954             return false;
01955         }
01956 
01957 
01958         // #2339 delete first variants before deleting parent product
01959         $this->_deleteVariantRecords( $sOXID );
01960         $this->load( $sOXID );
01961         $this->_deletePics();
01962         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01963 
01964         // delete self
01965         parent::delete( $sOXID );
01966 
01967         $rs = $this->_deleteRecords( $sOXID );
01968 
01969         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01970 
01971         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01972 
01973         return $rs->EOF;
01974     }
01975 
01984     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01985     {
01986         $this->beforeUpdate();
01987 
01988         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01989         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01990             $dAmount += $iStockCount;
01991             $iStockCount = 0;
01992         }
01993         $this->oxarticles__oxstock = new oxField($iStockCount);
01994 
01995         $oDb = oxDb::getDb();
01996         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01997         $this->onChange( ACTION_UPDATE_STOCK );
01998         return $dAmount;
01999     }
02000 
02009     public function updateSoldAmount( $dAmount = 0 )
02010     {
02011         if ( !$dAmount ) {
02012             return;
02013         }
02014 
02015         $this->beforeUpdate();
02016 
02017         // article is not variant - should be updated current amount
02018         if ( !$this->oxarticles__oxparentid->value ) {
02019             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
02020             $dAmount = (double) $dAmount;
02021             $oDb = oxDb::getDb();
02022             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02023         } elseif ( $this->oxarticles__oxparentid->value) {
02024             // article is variant - should be updated this article parent amount
02025             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
02026             $oUpdateArticle->updateSoldAmount( $dAmount );
02027         }
02028 
02029         $this->onChange( ACTION_UPDATE );
02030 
02031         return $rs;
02032     }
02033 
02039     public function disableReminder()
02040     {
02041         $oDb = oxDb::getDb();
02042         return $oDb->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02043     }
02044 
02052     public function save()
02053     {
02054         // @deprecated since 20110821. folders are no more written, getters must be user for urls
02055         $this->oxarticles__oxthumb = new oxField( basename( $this->oxarticles__oxthumb->value ), oxField::T_RAW );
02056         $this->oxarticles__oxicon  = new oxField( basename( $this->oxarticles__oxicon->value ), oxField::T_RAW );
02057         $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
02058         for ( $i = 1; $i <= $iPicCount; $i++ ) {
02059             $sFieldName = 'oxarticles__oxpic' . $i;
02060             if ( isset( $this->$sFieldName ) ) {
02061                 $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );
02062             }
02063         }
02064         // @end deprecated
02065 
02066         if ( ( $blRet = parent::save() ) ) {
02067             // saving long descrition
02068             $this->_saveArtLongDesc();
02069         }
02070 
02071         return $blRet;
02072     }
02073 
02079     public function resetParent()
02080     {
02081         $sParentId = $this->oxarticles__oxparentid;
02082         $this->oxarticles__oxparentid = new oxField( '', oxField::T_RAW );
02083         $this->_blAllowEmptyParentId = true;
02084         $this->save();
02085         $this->_blAllowEmptyParentId = false;
02086 
02087         if ( $sParentId !== '' ) {
02088             $this->onChange( ACTION_UPDATE, null, $sParentId );
02089         }
02090     }
02091 
02092 
02099     public function getPictureGallery()
02100     {
02101         $myConfig = $this->getConfig();
02102 
02103         //initialize
02104         $blMorePic = false;
02105         $aArtPics  = array();
02106         $aArtIcons = array();
02107         $iActPicId = 1;
02108         $sActPic = $this->getPictureUrl( $iActPicId );
02109 
02110         if ( oxConfig::getParameter( 'actpicid' ) ) {
02111             $iActPicId = oxConfig::getParameter('actpicid');
02112         }
02113 
02114         $oStr = getStr();
02115         $iCntr = 0;
02116         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02117         $blCheckActivePicId = true;
02118 
02119         for ( $i = 1; $i <= $iPicCount; $i++) {
02120             $sPicVal = $this->getPictureUrl( $i );
02121             $sIcoVal = $this->getIconUrl( $i );
02122             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02123                  !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02124                 if ($iCntr) {
02125                     $blMorePic = true;
02126                 }
02127                 $aArtIcons[$i]= $sIcoVal;
02128                 $aArtPics[$i]= $sPicVal;
02129                 $iCntr++;
02130 
02131                 if ($iActPicId == $i) {
02132                     $sActPic = $sPicVal;
02133                     $blCheckActivePicId = false;
02134                 }
02135 
02136             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02137                 // if picture is empty, setting active pic id to next
02138                 // picture
02139                 $iActPicId++;
02140             }
02141         }
02142 
02143         $blZoomPic  = false;
02144         $aZoomPics = array();
02145         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02146 
02147         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02148             $sVal = $this->getZoomPictureUrl($j);
02149 
02150             if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02151                 $blZoomPic = true;
02152                 $aZoomPics[$c]['id'] = $c;
02153                 $aZoomPics[$c]['file'] = $sVal;
02154                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02155                 if (!$sVal) {
02156                     $aZoomPics[$c]['file'] = "nopic.jpg";
02157                 }
02158                 $c++;
02159             }
02160         }
02161 
02162         $aPicGallery = array('ActPicID' => $iActPicId,
02163                              'ActPic' => $sActPic,
02164                              'MorePics' => $blMorePic,
02165                              'Pics' => $aArtPics,
02166                              'Icons' => $aArtIcons,
02167                              'ZoomPic' => $blZoomPic,
02168                              'ZoomPics' => $aZoomPics);
02169 
02170         return $aPicGallery;
02171     }
02172 
02186     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02187     {
02188         $myConfig = $this->getConfig();
02189 
02190         if (!isset($sOXID)) {
02191             if ( $this->getId()) {
02192                 $sOXID = $this->getId();
02193             }
02194             if (!isset ($sOXID)) {
02195                 $sOXID = $this->oxarticles__oxid->value;
02196             }
02197             if ($this->oxarticles__oxparentid->value) {
02198                 $sParentID = $this->oxarticles__oxparentid->value;
02199             }
02200         }
02201         if (!isset($sOXID)) {
02202             return;
02203         }
02204 
02205         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02206         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02207             //if article has variants then updating oxvarstock field
02208             //getting parent id
02209             if (!isset($sParentID)) {
02210                 $oDb = oxDb::getDb();
02211                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02212                 $sParentID = $oDb->getOne( $sQ );
02213             }
02214             //if we have parent id then update stock
02215             if ($sParentID) {
02216                 $this->_onChangeUpdateStock($sParentID);
02217             }
02218         }
02219         //if we have parent id then update count
02220         //update count even if blUseStock is not active
02221         if ($sParentID) {
02222             $this->_onChangeUpdateVarCount($sParentID);
02223         }
02224 
02225         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02226         $this->_onChangeUpdateMinVarPrice( $sId );
02227 
02228         // reseting articles count cache if stock has changed and some
02229         // articles goes offline (M:1448)
02230         if ( $sAction === ACTION_UPDATE_STOCK ) {
02231             $this->_onChangeStockResetCount( $sOXID );
02232         }
02233 
02234     }
02235 
02242     public function getCustomVAT()
02243     {
02244         if ( isset($this->oxarticles__oxvat->value) ) {
02245             return $this->oxarticles__oxvat->value;
02246         }
02247     }
02248 
02257     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02258     {
02259         $myConfig = $this->getConfig();
02260         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02261             return true;
02262         }
02263 
02264         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
02265         // fetching DB info as its up-to-date
02266         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.$oDb->quote( $this->getId() );
02267         $rs = $oDb->select( $sQ );
02268 
02269         $iOnStock   = 0;
02270         $iStockFlag = 0;
02271         if ( $rs !== false && $rs->recordCount() > 0 ) {
02272             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02273             $iStockFlag = $rs->fields['oxstockflag'];
02274 
02275             // dodger : fremdlager is also always considered as on stock
02276             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02277                 return true;
02278             }
02279             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02280                 $iOnStock = floor( $iOnStock );
02281             }
02282         }
02283         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02284             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02285         }
02286         if ( $iOnStock >= $dAmount ) {
02287             return true;
02288         } else {
02289             if ( $iOnStock > 0 ) {
02290                 return $iOnStock;
02291             } else {
02292                 $oEx = oxNew( 'oxArticleInputException' );
02293                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02294                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02295                 return false;
02296             }
02297         }
02298     }
02299 
02300 
02310     public function getArticleLongDesc( $sOxid = null )
02311     {
02312         return $this->getLongDescription();
02313     }
02314 
02320     public function getLongDescription()
02321     {
02322         if ( $this->_oLongDesc === null ) {
02323             // initializing
02324             $this->_oLongDesc = new oxField();
02325 
02326 
02327             // choosing which to get..
02328             $sOxid = $this->getId();
02329             $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02330 
02331             $oDb = oxDb::getDb();
02332             $sDbValue = $oDb->getOne( "select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote( $sOxid ) );
02333 
02334             if ( $sDbValue != false ) {
02335                 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02336             } elseif ( $this->oxarticles__oxparentid->value ) {
02337                 if ( !$this->isAdmin() || $this->_blLoadParentData ) {
02338                     $this->_oLongDesc->setValue( $this->getParentArticle()->getLongDescription()->getRawValue(), oxField::T_RAW );
02339                 }
02340             }
02341         }
02342         return $this->_oLongDesc;
02343     }
02344 
02354     protected function _setLongDesc( $sDbValue )
02355     {
02356         $this->setArticleLongDesc( $sDbValue );
02357     }
02358 
02365     public function getLongDesc()
02366     {
02367         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getLongDescription()->getRawValue(), $this->getId().$this->getLanguage() );
02368     }
02369 
02378     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02379     {
02380 
02381         // setting current value
02382         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02383 
02384         // setting original value?
02385         //deprecated since 2012-02-13 in v.4.5.7
02386         if ( $sOrigValue ) {
02387             $this->_oLongDesc->orignalValue = $sOrigValue;
02388         }
02389     }
02390 
02396     public function getAttributes()
02397     {
02398         if ( $this->_oAttributeList === null ) {
02399             $this->_oAttributeList = oxNew( 'oxattributelist' );
02400             $this->_oAttributeList->loadAttributes( $this->getId() );
02401         }
02402 
02403         return $this->_oAttributeList;
02404     }
02405 
02414     public function appendLink( $sAddParams, $iLang = null )
02415     {
02416         if ( $sAddParams ) {
02417             if ( $iLang === null ) {
02418                 $iLang = $this->getLanguage();
02419             }
02420 
02421             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02422             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02423         }
02424     }
02425 
02434     public function getBaseSeoLink( $iLang, $blMain = false )
02435     {
02436         $oEncoder = oxSeoEncoderArticle::getInstance();
02437         if ( !$blMain ) {
02438             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02439         }
02440         return $oEncoder->getArticleMainUrl( $this, $iLang );
02441     }
02442 
02451     public function getLink( $iLang = null, $blMain = false  )
02452     {
02453         if ( !oxUtils::getInstance()->seoIsActive() ) {
02454             return $this->getStdLink( $iLang );
02455         }
02456 
02457         if ( $iLang === null ) {
02458             $iLang = $this->getLanguage();
02459         }
02460 
02461         $iLinkType = $this->getLinkType();
02462         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02463             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02464         }
02465 
02466         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02467         if ( isset($this->_aSeoAddParams[$iLang])) {
02468             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02469         }
02470 
02471         return $sUrl;
02472     }
02473 
02482     public function getMainLink( $iLang = null )
02483     {
02484         return $this->getLink( $iLang, true );
02485     }
02486 
02494     public function setLinkType( $iType )
02495     {
02496         // resetting detaisl link, to force new
02497         $this->_sDetailLink = null;
02498 
02499         // setting link type
02500         $this->_iLinkType = (int) $iType;
02501     }
02502 
02508     public function getLinkType()
02509     {
02510         return $this->_iLinkType;
02511     }
02512 
02521     public function appendStdLink( $sAddParams, $iLang = null )
02522     {
02523         if ( $sAddParams ) {
02524             if ( $iLang === null ) {
02525                 $iLang = $this->getLanguage();
02526             }
02527 
02528             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02529             $this->_aStdAddParams[$iLang] .= $sAddParams;
02530         }
02531     }
02532 
02542     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02543     {
02544         $sUrl = '';
02545         if ( $blFull ) {
02546             //always returns shop url, not admin
02547             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02548         }
02549 
02550         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02551         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02552     }
02553 
02562     public function getStdLink( $iLang = null, $aParams = array() )
02563     {
02564         if ( $iLang === null ) {
02565             $iLang = $this->getLanguage();
02566         }
02567 
02568         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02569             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02570         }
02571 
02572         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02573     }
02574 
02582     public function getStdTagLink( $sTag )
02583     {
02584         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02585         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02586     }
02587 
02593     public function getTags()
02594     {
02595         $oDb = oxDb::getDb();
02596         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02597         $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02598         $oTagCloud = oxNew('oxtagcloud');
02599         return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02600     }
02601 
02609     public function saveTags($sTags)
02610     {
02611         //do not allow derived update
02612         if ( !$this->allowDerivedUpdate() ) {
02613             return false;
02614         }
02615 
02616 
02617         $oTagCloud = oxNew( 'oxtagcloud' );
02618         $oTagCloud->resetTagCache($this->getLanguage());
02619         $sTags = oxDb::getInstance()->escapeString( $oTagCloud->prepareTags( $sTags ) );
02620         $oDb = oxDb::getDb();
02621 
02622         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02623         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02624         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02625                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02626         return $oDb->execute( $sQ );
02627     }
02628 
02636     public function addTag($sTag)
02637     {
02638         $oDb = oxDb::getDb();
02639 
02640         $oTagCloud = oxNew('oxtagcloud');
02641         $oTagCloud->resetTagCache();
02642         $sTag = $oTagCloud->prepareTags($sTag);
02643         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02644 
02645         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02646         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02647         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02648             $sTailTag = $sTagSeparator . $sTag;
02649         } else {
02650             $sTailTag = $sTag;
02651         }
02652 
02653         $sTag = oxDb::getInstance()->escapeString($sTag);
02654         $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02655 
02656         $sTag = oxDb::getInstance()->escapeString($sTag);
02657         $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02658 
02659         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02660                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02661 
02662         return $oDb->execute( $sQ );
02663     }
02664 
02670     public function getMediaUrls()
02671     {
02672         if ( $this->_aMediaUrls === null ) {
02673             $this->_aMediaUrls = oxNew("oxlist");
02674             $this->_aMediaUrls->init("oxmediaurl");
02675             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02676 
02677             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02678             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02679             $this->_aMediaUrls->selectString($sQ);
02680         }
02681         return $this->_aMediaUrls;
02682     }
02683 
02689     public function getDynImageDir()
02690     {
02691         return $this->_sDynImageDir;
02692     }
02693 
02699     public function getDispSelList()
02700     {
02701         if ($this->_aDispSelList === null) {
02702             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02703                 $this->_aDispSelList = $this->getSelectLists();
02704             }
02705         }
02706         return $this->_aDispSelList;
02707     }
02708 
02714     public function getMoreDetailLink()
02715     {
02716         if ( $this->_sMoreDetailLink == null ) {
02717 
02718             // and assign special article values
02719             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02720 
02721             // not always it is okey, as not all the time active category is the same as primary article cat.
02722             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02723                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02724             }
02725             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02726             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02727         }
02728 
02729         return $this->_sMoreDetailLink;
02730     }
02731 
02737     public function getToBasketLink()
02738     {
02739         if ( $this->_sToBasketLink == null ) {
02740             $myConfig = $this->getConfig();
02741 
02742             if ( oxUtils::getInstance()->isSearchEngine() ) {
02743                 $this->_sToBasketLink = $this->getLink();
02744             } else {
02745                 // and assign special article values
02746                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02747 
02748                 // override some classes as these should never showup
02749                 $sActClass = oxConfig::getParameter( 'cl' );
02750                 if ( $sActClass == 'thankyou') {
02751                     $sActClass = 'basket';
02752                 }
02753                 $this->_sToBasketLink .= 'cl='.$sActClass;
02754 
02755                 // this is not very correct
02756                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02757                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02758                 }
02759 
02760                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02761 
02762                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02763                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02764                 }
02765             }
02766         }
02767 
02768         return $this->_sToBasketLink;
02769     }
02770 
02776     public function getStockStatus()
02777     {
02778         return $this->_iStockStatus;
02779     }
02780 
02786     public function getDeliveryDate()
02787     {
02788         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02789             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02790         }
02791         return false;
02792     }
02793 
02799     public function getFTPrice()
02800     {
02801         if ( $oPrice = $this->getTPrice() ) {
02802             if ( $oPrice->getBruttoPrice() ) {
02803                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02804             }
02805         }
02806     }
02807 
02813     public function getFPrice()
02814     {
02815         if ( $oPrice = $this->getPrice() ) {
02816             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02817         }
02818     }
02819 
02826     public function resetRemindStatus()
02827     {
02828         if ( $this->oxarticles__oxremindactive->value == 2 &&
02829             $this->oxarticles__oxremindamount->value <= $this->oxarticles__oxstock->value ) {
02830             $this->oxarticles__oxremindactive->value = 1;
02831         }
02832     }
02833 
02839     public function getFNetPrice()
02840     {
02841         if ( $oPrice = $this->getPrice() ) {
02842             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02843         }
02844     }
02845 
02851     public function getPricePerUnit()
02852     {
02853         return $this->_fPricePerUnit;
02854     }
02855 
02861     public function isParentNotBuyable()
02862     {
02863         return $this->_blNotBuyableParent;
02864     }
02865 
02871     public function isNotBuyable()
02872     {
02873         return $this->_blNotBuyable;
02874     }
02875 
02883     public function setBuyableState( $blBuyable = false )
02884     {
02885         $this->_blNotBuyable = !$blBuyable;
02886     }
02887 
02896     public function getVariantList()
02897     {
02898         return $this->getVariants();
02899     }
02900 
02908     public function setSelectlist( $aSelList )
02909     {
02910         $this->_aDispSelList = $aSelList;
02911     }
02912 
02920     public function getPictureUrl( $iIndex = 1 )
02921     {
02922         if ( $iIndex ) {
02923             $sImgName = false;
02924             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02925                 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02926             }
02927 
02928             $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02929             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02930         }
02931     }
02932 
02941     public function getIconUrl( $iIndex = 0 )
02942     {
02943         $sImgName = false;
02944         $sDirname = "product/1/";
02945         if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02946             $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02947             $sDirname = "product/{$iIndex}/";
02948         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02949             $sImgName = basename( $this->oxarticles__oxicon->value );
02950             $sDirname = "product/icon/";
02951         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02952             $sImgName = basename( $this->oxarticles__oxpic1->value );
02953         }
02954 
02955         $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02956         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02957     }
02958 
02966     public function getThumbnailUrl( $bSsl = null )
02967     {
02968         $sImgName = false;
02969         $sDirname = "product/1/";
02970         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02971             $sImgName = basename( $this->oxarticles__oxthumb->value );
02972             $sDirname = "product/thumb/";
02973         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02974             $sImgName = basename( $this->oxarticles__oxpic1->value );
02975         }
02976 
02977         $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02978         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
02979     }
02980 
02988     public function getZoomPictureUrl( $iIndex = '' )
02989     {
02990         $iIndex = (int) $iIndex;
02991         if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02992             $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02993             $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02994             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02995         }
02996     }
02997 
03003     public function getFileUrl()
03004     {
03005         return $this->getConfig()->getPictureUrl( 'media/' );
03006     }
03007 
03013     public function getPriceFromPrefix()
03014     {
03015         $sPricePrefix = '';
03016         if ( $this->_blIsRangePrice) {
03017             $sPricePrefix = oxLang::getInstance()->translateString('priceFrom').' ';
03018         }
03019 
03020         return $sPricePrefix;
03021     }
03022 
03028     protected function _saveArtLongDesc()
03029     {
03030         $myConfig = $this->getConfig();
03031         $sShopId = $myConfig->getShopID();
03032         if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
03033             return;
03034         }
03035 
03036         if ($this->_blEmployMultilanguage) {
03037             $sValue = $this->getLongDescription()->getRawValue();
03038             if ( $sValue !== null ) {
03039                 $oArtExt = oxNew('oxI18n');
03040                 $oArtExt->init('oxartextends');
03041                 $oArtExt->setLanguage((int) $this->getLanguage());
03042                 if (!$oArtExt->load($this->getId())) {
03043                     $oArtExt->setId($this->getId());
03044                 }
03045                 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
03046                 $oArtExt->save();
03047             }
03048         } else {
03049             $oArtExt = oxNew('oxI18n');
03050             $oArtExt->setEnableMultilang(false);
03051             $oArtExt->init('oxartextends');
03052             $aObjFields = $oArtExt->_getAllFields(true);
03053             if (!$oArtExt->load($this->getId())) {
03054                 $oArtExt->setId($this->getId());
03055             }
03056 
03057             foreach ($aObjFields as $sKey => $sValue ) {
03058                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
03059                     $sField = $this->_getFieldLongName($sKey);
03060 
03061                     if (isset($this->$sField)) {
03062                         $sLongDesc = null;
03063                         if ($this->$sField instanceof oxField) {
03064                             $sLongDesc = $this->$sField->getRawValue();
03065                         } elseif (is_object($this->$sField)) {
03066                             $sLongDesc = $this->$sField->value;
03067                         }
03068                         if (isset($sLongDesc)) {
03069                             $sAEField = $oArtExt->_getFieldLongName($sKey);
03070                             $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
03071                         }
03072                     }
03073                 }
03074             }
03075             $oArtExt->save();
03076         }
03077     }
03078 
03084     protected function _skipSaveFields()
03085     {
03086         $myConfig = $this->getConfig();
03087 
03088         $this->_aSkipSaveFields = array();
03089 
03090         $this->_aSkipSaveFields[] = 'oxtimestamp';
03091        // $this->_aSkipSaveFields[] = 'oxlongdesc';
03092         $this->_aSkipSaveFields[] = 'oxinsert';
03093 
03094         if ( !$this->_blAllowEmptyParentId && (!isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') ) {
03095             $this->_aSkipSaveFields[] = 'oxparentid';
03096         }
03097 
03098     }
03099 
03109     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03110     {
03111         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03112             // add prices of the same discounts
03113             if ( array_key_exists ($sKey, $aDiscounts) ) {
03114                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03115             } else {
03116                 $aDiscounts[$sKey] = $oDiscount;
03117             }
03118         }
03119         return $aDiscounts;
03120     }
03121 
03127     protected function _getGroupPrice()
03128     {
03129         $dPrice = $this->oxarticles__oxprice->value;
03130 
03131         $oUser = $this->getArticleUser();
03132         if ( $oUser ) {
03133             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03134                 $dPrice = $this->oxarticles__oxpricea->value;
03135             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03136                 $dPrice = $this->oxarticles__oxpriceb->value;
03137             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03138                 $dPrice = $this->oxarticles__oxpricec->value;
03139             }
03140         }
03141 
03142         // #1437/1436C - added config option, and check for zero A,B,C price values
03143         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03144             $dPrice = $this->oxarticles__oxprice->value;
03145         }
03146 
03147         return $dPrice;
03148     }
03149 
03158     protected function _getAmountPrice($dAmount = 1)
03159     {
03160         $myConfig = $this->getConfig();
03161 
03162         startProfile( "_getAmountPrice" );
03163 
03164         $dPrice = $this->_getGroupPrice();
03165         $oAmtPrices = $this->_getAmountPriceList();
03166         foreach ($oAmtPrices as $oAmPrice) {
03167             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03168                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03169                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03170                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03171             }
03172         }
03173 
03174         stopProfile( "_getAmountPrice" );
03175         return $dPrice;
03176     }
03177 
03186     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03187     {
03188         $myConfig = $this->getConfig();
03189         // #690
03190         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03191 
03192             $aSelLists = $this->getSelectLists();
03193 
03194             foreach ( $aSelLists as $key => $aSel) {
03195                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03196                     $oSel = $aSel[$aChosenList[$key]];
03197                     if ( $oSel->priceUnit =='abs' ) {
03198                         $dPrice += $oSel->price;
03199                     } elseif ( $oSel->priceUnit =='%' ) {
03200                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03201                     }
03202                 }
03203             }
03204         }
03205         return $dPrice;
03206     }
03207 
03208 
03216     protected function _fillAmountPriceList($oAmPriceList)
03217     {
03218         $myConfig = $this->getConfig();
03219         $myUtils  = oxUtils::getInstance();
03220 
03221         //modifying price
03222         $oCur = $myConfig->getActShopCurrencyObject();
03223 
03224         $oUser = $this->getArticleUser();
03225 
03226         $oDiscountList = oxDiscountList::getInstance();
03227         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03228 
03229         $oLowestPrice = null;
03230 
03231         $dBasePrice = $this->_getGroupPrice();
03232         $oLang = oxLang::getInstance();
03233 
03234         $dArticleVat = null;
03235         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03236             $dArticleVat = $this->getArticleVat();
03237         }
03238 
03239         // trying to find lowest price value
03240         foreach ($oAmPriceList as $sId => $oItem) {
03241             $oItemPrice = oxNew( 'oxprice' );
03242             if ( $oItem->oxprice2article__oxaddabs->value) {
03243                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03244                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03245                 $this->_applyCurrency( $oItemPrice, $oCur );
03246             } else {
03247                 $oItemPrice->setPrice( $dBasePrice );
03248                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03249             }
03250 
03251             if (isset($dArticleVat)) {
03252                 $this->_applyVAT($oItemPrice, $dArticleVat);
03253             }
03254 
03255             if (!$oLowestPrice) {
03256                 $oLowestPrice = $oItemPrice;
03257             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03258                 $oLowestPrice = $oItemPrice;
03259             }
03260 
03261             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03262             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03263         }
03264 
03265         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03266         return $oAmPriceList;
03267     }
03268 
03274     protected function _getVariantsIds()
03275     {
03276         $aSelect = array();
03277         if ( ( $sId = $this->getId() ) ) {
03278             $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03279             $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03280                    $this->getSqlActiveSnippet( true ) . " order by oxsort";
03281             $oRs = $oDb->select( $sQ );
03282             if ( $oRs != false && $oRs->recordCount() > 0 ) {
03283                 while (!$oRs->EOF) {
03284                     $aSelect[] = reset( $oRs->fields );
03285                     $oRs->moveNext();
03286                 }
03287             }
03288         }
03289         return $aSelect;
03290     }
03291 
03297     public function getArticleVat()
03298     {
03299         if (!isset($this->_dArticleVat)) {
03300             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03301         }
03302         return $this->_dArticleVat;
03303     }
03304 
03313     protected function _applyVAT( oxPrice $oPrice, $dVat )
03314     {
03315         startProfile(__FUNCTION__);
03316         $oPrice->setVAT( $dVat );
03317         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03318             $oPrice->setUserVat( $dVat );
03319         }
03320         stopProfile(__FUNCTION__);
03321     }
03322 
03330     public function applyVats( oxPrice $oPrice )
03331     {
03332         $this->_applyVAT($oPrice, $this->getArticleVat() );
03333     }
03334 
03345     protected function _applyDiscounts( $oPrice, $aDiscounts )
03346     {
03347         $oDiscountList = oxDiscountList::getInstance();
03348         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03349     }
03350 
03358     public function applyDiscountsForVariant( $oPrice )
03359     {
03360         // apply discounts
03361         if ( !$this->skipDiscounts() ) {
03362             $oDiscountList = oxDiscountList::getInstance();
03363             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03364         }
03365     }
03366 
03375     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03376     {
03377         if ( !$oCur ) {
03378             $oCur = $this->getConfig()->getActShopCurrencyObject();
03379         }
03380 
03381         $oPrice->multiply($oCur->rate);
03382     }
03383 
03384 
03393     protected function _getAttribsString(&$sAttribs, &$iCnt)
03394     {
03395         // we do not use lists here as we dont need this overhead right now
03396         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03397         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03398         $sAttribs = '';
03399         $blSep = false;
03400         $rs = $oDb->select( $sSelect);
03401         $iCnt = 0;
03402         if ($rs != false && $rs->recordCount() > 0) {
03403             while (!$rs->EOF) {
03404                 if ( $blSep) {
03405                     $sAttribs .= ' or ';
03406                 }
03407                 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03408                 $blSep = true;
03409                 $iCnt++;
03410                 $rs->moveNext();
03411             }
03412         }
03413     }
03414 
03423     protected function _getSimList($sAttribs, $iCnt)
03424     {
03425         $myConfig = $this->getConfig();
03426         $oDb      = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03427 
03428         // #523A
03429         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03430         // 70% same attributes
03431         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03432             $iAttrPercent = 0.70;
03433         }
03434         // #1137V iAttributesPercent = 100 doesnt work
03435         $iHitMin = ceil( $iCnt * $iAttrPercent );
03436 
03437         // we do not use lists here as we dont need this overhead right now
03438         $aList= array();
03439         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03440                     ( $sAttribs )
03441                     and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03442                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03443 
03444         $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03445         if ($rs != false && $rs->recordCount() > 0) {
03446             while (!$rs->EOF) {
03447                 $oTemp = new stdClass();    // #663
03448                 $oTemp->cnt = $rs->fields['cnt'];
03449                 $oTemp->id  = $rs->fields['oxobjectid'];
03450                 $aList[] = $oTemp;
03451                 $rs->moveNext();
03452             }
03453         }
03454         return $aList;
03455     }
03456 
03465     protected function _generateSimListSearchStr($sArticleTable, $aList)
03466     {
03467         $myConfig = $this->getConfig();
03468         $sFieldList = $this->getSelectFields();
03469         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03470         $blSep = false;
03471         $iCnt = 0;
03472         $oDb = oxDb::getDb();
03473         foreach ( $aList as $oTemp) {
03474             if ( $blSep) {
03475                 $sSearch .= ',';
03476             }
03477             $sSearch .= $oDb->quote($oTemp->id);
03478             $blSep = true;
03479             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03480                 break;
03481             }
03482             $iCnt++;
03483         }
03484 
03485         //#1741T
03486         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03487         $sSearch .= ') ';
03488 
03489         // #524A -- randomizing articles in attribute list
03490         $sSearch .= ' order by rand() ';
03491 
03492         return $sSearch;
03493     }
03494 
03503     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03504     {
03505 
03506         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03507         $sO2CView = getViewName( 'oxobject2category' );
03508 
03509         // we do not use lists here as we dont need this overhead right now
03510         if ( !$blSearchPriceCat ) {
03511             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03512                          {$sCatView}.oxid = oxobject2category.oxcatnid
03513                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03514         } else {
03515             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03516                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03517                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03518         }
03519         return $sSelect;
03520     }
03521 
03527     protected function _generateSearchStrForCustomerBought()
03528     {
03529         $sArtTable = $this->getViewName();
03530         $sOrderArtTable = getViewName( 'oxorderarticles' );
03531 
03532         // fetching filter params
03533         $sIn = " '{$this->oxarticles__oxid->value}' ";
03534         if ( $this->oxarticles__oxparentid->value ) {
03535 
03536             // adding article parent
03537             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03538             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03539 
03540         } else {
03541             $sParentIdForVariants = $this->getId();
03542         }
03543 
03544         // adding variants
03545         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03546         $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03547         if ( $oRs != false && $oRs->recordCount() > 0) {
03548             while ( !$oRs->EOF ) {
03549                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03550                 $oRs->moveNext();
03551             }
03552         }
03553 
03554         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03555         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03556 
03557         // building sql (optimized)
03558         $sQ = "select distinct {$sArtTable}.* from (
03559                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03560                ) as suborder
03561                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03562                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03563                where {$sArtTable}.oxid not in ( {$sIn} )
03564                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03565 
03566         /* non optimized, but could be used if index forcing is not supported
03567         // building sql
03568         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03569                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03570                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03571                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03572                and ".$this->getSqlActiveSnippet();
03573         */
03574 
03575         return $sQ;
03576     }
03577 
03587     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03588     {
03589         $sCategoryView = getViewName('oxcategories');
03590         $sO2CView = getViewName('oxobject2category');
03591 
03592         $oDb    = oxDb::getDb();
03593         $sOXID  = $oDb->quote($sOXID);
03594         $sCatId = $oDb->quote($sCatId);
03595 
03596         if (!$dPriceFromTo) {
03597             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03598             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03599             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03600             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03601         } else {
03602             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03603             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03604             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03605             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03606         }
03607         return $sSelect;
03608     }
03609 
03615     protected function _getAmountPriceList()
03616     {
03617         if ( $this->_oAmountPriceList === null ) {
03618             $this->_oAmountPriceList = array();
03619             if ( !$this->skipDiscounts() ) {
03620                 $myConfig = $this->getConfig();
03621                 $sArtId   = $this->getId();
03622 
03623                 // #1690C - Scale prices and variants
03624                 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03625                     $sArtId = $this->oxarticles__oxparentid->value;
03626                 }
03627 
03628                 //collecting assigned to article amount-price list
03629                 $oAmPriceList = oxNew( 'oxlist' );
03630                 $oAmPriceList->init( 'oxbase', 'oxprice2article' );
03631 
03632                 $sShopID = $myConfig->getShopID();
03633                 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03634                     $sShopSelect = '1';
03635                 } else {
03636                     $sShopSelect = " oxshopid =  '$sShopID' ";
03637                 }
03638 
03639                 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = " . oxDb::getDb()->quote( $sArtId ) . " and $sShopSelect order by oxamount ");
03640 
03641                 // prepare abs prices if currently having percentages
03642                 $oBasePrice = $this->_getGroupPrice();
03643                 foreach ( $oAmPriceList as $oAmPrice ) {
03644                     if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03645                         $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03646                     }
03647                 }
03648 
03649                 $this->_oAmountPriceList = $oAmPriceList;
03650             }
03651         }
03652 
03653         return $this->_oAmountPriceList;
03654     }
03655 
03663     protected function _isFieldEmpty( $sFieldName )
03664     {
03665         $mValue = $this->$sFieldName->value;
03666 
03667         if ( is_null( $mValue ) ) {
03668             return true;
03669         }
03670 
03671         if ( $mValue === '' ) {
03672             return true;
03673         }
03674 
03675         // certain fields with zero value treat as empty
03676         $aZeroValueFields = array('oxarticles__oxprice', 'oxarticles__oxvat', 'oxarticles__oxunitquantity');
03677 
03678         if (!$mValue && in_array( $sFieldName, $aZeroValueFields ) ) {
03679             return true;
03680         }
03681 
03682 
03683         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03684             return true;
03685         }
03686 
03687         $sFieldName = strtolower($sFieldName);
03688 
03689         if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03690             return true;
03691         }
03692 
03693         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03694             return true;
03695         }
03696 
03697         return false;
03698     }
03699 
03707     protected function _assignParentFieldValue($sFieldName)
03708     {
03709         if (!($oParentArticle = $this->getParentArticle())) {
03710             return;
03711         }
03712         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03713 
03714         // assigning only theese which parent article has
03715         if ( $oParentArticle->$sCopyFieldName != null ) {
03716 
03717             // only overwrite database values
03718             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03719                 return;
03720             }
03721 
03722             //do not copy certain fields
03723             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03724                 return;
03725             }
03726 
03727             //COPY THE VALUE
03728             // assigning images from parent only if variant has no master image (#1807)
03729             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03730                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03731                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03732                 }
03733             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03734                 // for zoom images checking master image with specified index
03735                 // assign from parent only if no pictures to variant are added
03736                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03737                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03738                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03739                 }
03740             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03741                 // if no pics generated for variants, load all from
03742                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03743             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03744                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03745             }
03746         }
03747     }
03748 
03754     public function getParentArticle()
03755     {
03756         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03757             $sIndex = $sParentId . "_" . $this->getLanguage();
03758             if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03759                 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03760                 self::$_aLoadedParents[$sIndex]->_blSkipAbPrice  = true;
03761                 self::$_aLoadedParents[$sIndex]->_blLoadPrice    = false;
03762                 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03763                 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03764             }
03765             return self::$_aLoadedParents[$sIndex];
03766         }
03767     }
03768 
03776     protected function _getParentAricle()
03777     {
03778         return $this->getParentArticle();
03779     }
03780 
03786     protected function _assignParentFieldValues()
03787     {
03788         startProfile('articleAssignParentInternal');
03789         if ( $this->oxarticles__oxparentid->value ) {
03790             // yes, we are in fact a variant
03791             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03792                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03793                     $this->_assignParentFieldValue( $sFieldName );
03794                 }
03795             }
03796         }
03797         stopProfile('articleAssignParentInternal');
03798     }
03799 
03805     protected function _assignNotBuyableParent()
03806     {
03807         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03808              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03809             $this->_blNotBuyableParent = true;
03810 
03811         }
03812     }
03813 
03819     protected function _assignStock()
03820     {
03821         $myConfig = $this->getConfig();
03822         // -----------------------------------
03823         // stock
03824         // -----------------------------------
03825 
03826         // #1125 A. must round (using floor()) value taken from database and cast to int
03827         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03828             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03829         }
03830         //GREEN light
03831         $this->_iStockStatus = 0;
03832 
03833         // if we have flag /*1 or*/ 4 - we show always green light
03834         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03835             //ORANGE light
03836             $iStock = $this->oxarticles__oxstock->value;
03837 
03838             if ($this->_blNotBuyableParent) {
03839                 $iStock = $this->oxarticles__oxvarstock->value;
03840             }
03841 
03842 
03843             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03844                 $this->_iStockStatus = 1;
03845             }
03846 
03847             //RED light
03848             if ($iStock <= 0) {
03849                 $this->_iStockStatus = -1;
03850             }
03851         }
03852 
03853 
03854         // stock
03855         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03856             $iOnStock = $this->oxarticles__oxstock->value;
03857             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03858                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03859             }
03860             if ($iOnStock <= 0) {
03861                 $this->setBuyableState( false );
03862             }
03863         }
03864 
03865         //exceptional handling for variant parent stock:
03866         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03867             $this->setBuyableState( true );
03868             //but then at least setting notBuaybleParent to true
03869             $this->_blNotBuyableParent = true;
03870         }
03871 
03872         //special treatment for lists when blVariantParentBuyable config option is set to false
03873         //then we just hide "to basket" button.
03874         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03875         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03876             $this->setBuyableState( false );
03877         }
03878 
03879         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03880         if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03881             $this->setBuyableState( false );
03882         }
03883     }
03884 
03890     protected function _assignPrices()
03891     {
03892         $myConfig = $this->getConfig();
03893 
03894         // Performance
03895         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03896             return;
03897         }
03898 
03899         //price per unit handling
03900         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03901             // compute price
03902             $dPrice = $this->getPrice()->getBruttoPrice();
03903             $oCur = $myConfig->getActShopCurrencyObject();
03904             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03905         }
03906 
03907         //getting min and max prices of variants
03908         if ( $this->_hasAnyVariant() ) {
03909             $this->_applyRangePrice();
03910         }
03911     }
03912 
03918     protected function _assignPersistentParam()
03919     {
03920         // Persistent Parameter Handling
03921         $aPersParam     = oxSession::getVar( 'persparam');
03922         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03923             $this->_aPersistParam = $aPersParam[$this->getId()];
03924         }
03925     }
03926 
03932     protected function _assignDynImageDir()
03933     {
03934         $myConfig = $this->getConfig();
03935 
03936         $sThisShop = $this->oxarticles__oxshopid->value;
03937 
03938         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03939         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03940         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03941         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03942     }
03943 
03949     protected function _assignComparisonListFlag()
03950     {
03951         // #657 add a flag if article is on comparisonlist
03952 
03953         $aItems = oxSession::getVar('aFiltcompproducts');
03954         if ( isset( $aItems[$this->getId()])) {
03955             $this->_blIsOnComparisonList = true;
03956         }
03957     }
03958 
03964     protected function _assignAttributes()
03965     {
03966         //#1029T load attributes
03967         //#1078S removed check for module "Produktvergleich"
03968         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03969             $this->getAttributes();
03970         }
03971     }
03972 
03973 
03981     protected function _insert()
03982     {
03983         // set oxinsert
03984         $sNow = date('Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime());
03985         $this->oxarticles__oxinsert    = new oxField( $sNow );
03986         $this->oxarticles__oxtimestamp = new oxField( $sNow );
03987         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03988             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03989         }
03990 
03991         return parent::_insert();
03992     }
03993 
03999     protected function _update()
04000     {
04001 
04002         $this->_skipSaveFields();
04003 
04004         $myConfig = $this->getConfig();
04005 
04006 
04007         return parent::_update();
04008     }
04009 
04015     public function updateVariantsRemind()
04016     {
04017         // check if it is parent article
04018         if ( !$this->isVariant() && $this->_hasAnyVariant()) {
04019             $oDb = oxDb::getDb();
04020             $sOxId = $oDb->quote($this->getId());
04021             $sOxShopId = $oDb->quote($this->getShopId());
04022             $iRemindActive = $oDb->quote($this->oxarticles__oxremindactive->value);
04023             $sUpdate = "
04024                 update oxarticles
04025                     set oxremindactive = $iRemindActive
04026                     where oxparentid = $sOxId and
04027                           oxshopid = $sOxShopId
04028             ";
04029             $oDb->execute( $sUpdate );
04030         }
04031     }
04032 
04040     protected function _deleteRecords($sOXID)
04041     {
04042         $oDb = oxDb::getDb();
04043 
04044         $sOXID = $oDb->quote($sOXID);
04045 
04046         //remove other records
04047         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
04048         $oDb->execute( $sDelete);
04049 
04050         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
04051         $oDb->execute( $sDelete);
04052 
04053         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
04054         $oDb->execute( $sDelete);
04055 
04056         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
04057         $oDb->execute( $sDelete);
04058 
04059         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
04060         $oDb->execute( $sDelete);
04061 
04062         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
04063         $oDb->execute( $sDelete);
04064 
04065         $sDelete = 'delete from oxratings where oxobjectid = '.$sOXID.' ';
04066         $rs = $oDb->execute( $sDelete );
04067 
04068         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
04069         $oDb->execute( $sDelete);
04070 
04071         //#1508C - deleting oxobject2delivery entries added
04072         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04073         $oDb->execute( $sDelete);
04074 
04075         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04076         $oDb->execute( $sDelete);
04077 
04078         //delete the record
04079         foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
04080             $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
04081         }
04082 
04083         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04084         $rs = $oDb->execute( $sDelete );
04085 
04086         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04087         $rs = $oDb->execute( $sDelete );
04088 
04089 
04090         return $rs;
04091     }
04092 
04100     protected function _deleteVariantRecords( $sOXID )
04101     {
04102         if ( $sOXID ) {
04103             $oDb = oxDb::getDb();
04104             //collect variants to remove recursively
04105             $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
04106             $rs = $oDb->select( $sQ, false, false );
04107             if ($rs != false && $rs->recordCount() > 0) {
04108                 while (!$rs->EOF) {
04109                     $this->delete( $rs->fields[0] );
04110                     $rs->moveNext();
04111                 }
04112             }
04113         }
04114     }
04115 
04125     protected function _resetCacheAndArticleCount( $sOxid )
04126     {
04127         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04128     }
04129 
04135     protected function _deletePics()
04136     {
04137         $myUtilsPic = oxUtilsPic::getInstance();
04138         $myConfig   = $this->getConfig();
04139         $oPictureHandler = oxPictureHandler::getInstance();
04140 
04141         //deleting custom main icon
04142         $oPictureHandler->deleteMainIcon( $this );
04143 
04144         //deleting custom thumbnail
04145         $oPictureHandler->deleteThumbnail( $this );
04146 
04147         $sAbsDynImageDir = $myConfig->getPictureDir(false);
04148 
04149         // deleting master image and all generated images
04150         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04151         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04152             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04153         }
04154     }
04155 
04165     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04166     {
04167 
04168         $myUtilsCount = oxUtilsCount::getInstance();
04169 
04170         if ( $sVendorId ) {
04171             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04172         }
04173 
04174         if ( $sManufacturerId ) {
04175             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04176         }
04177 
04178         //also reseting category counts
04179         $oDb = oxDb::getDb();
04180         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04181         $oRs = $oDb->select( $sQ, false, false );
04182         if ( $oRs !== false && $oRs->recordCount() > 0) {
04183             while ( !$oRs->EOF ) {
04184                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04185                 $oRs->moveNext();
04186             }
04187         }
04188     }
04189 
04197     protected function _onChangeUpdateStock( $sParentID )
04198     {
04199         if ( $sParentID ) {
04200             $oDb = oxDb::getDb();
04201             $sParentIdQuoted = $oDb->quote($sParentID);
04202             $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04203             $rs = $oDb->select( $sQ, false, false );
04204             $iOldStock = $rs->fields[0];
04205             $iVendorID = $rs->fields[1];
04206             $iManufacturerID = $rs->fields[2];
04207 
04208             $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04209             $iStock = (float) $oDb->getOne( $sQ, false, false );
04210 
04211             $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04212             $oDb->execute( $sQ );
04213 
04214             //now lets update category counts
04215             //first detect stock status change for this article (to or from 0)
04216             if ( $iStock < 0 ) {
04217                 $iStock = 0;
04218             }
04219             if ( $iOldStock < 0 ) {
04220                 $iOldStock = 0;
04221             }
04222             if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04223                 //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04224                 // so far we leave it like this but later we could move all count resets to one or two functions
04225                 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04226             }
04227         }
04228     }
04229 
04237     protected function _onChangeStockResetCount( $sOxid )
04238     {
04239         $myConfig = $this->getConfig();
04240 
04241         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04242            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04243 
04244                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04245         }
04246     }
04247 
04255     protected function _onChangeUpdateVarCount( $sParentID )
04256     {
04257         if ( $sParentID ) {
04258             $oDb = oxDb::getDb();
04259             $sParentIdQuoted = $oDb->quote( $sParentID );
04260             $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04261             $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04262 
04263             $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04264             $oDb->execute( $sQ );
04265         }
04266     }
04267 
04275     protected function _onChangeUpdateMinVarPrice( $sParentID )
04276     {
04277         if ( $sParentID ) {
04278             $oDb = oxDb::getDb();
04279             $sParentIdQuoted = $oDb->quote($sParentID);
04280             //#M0000883 (Sarunas)
04281             $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04282             $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04283 
04284             $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04285 
04286             $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04287 
04288             if ($dVarMinPrice) {
04289                 if ($blParentBuyable) {
04290                     $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04291                 }
04292 
04293             } else {
04294                 $dVarMinPrice = $dParentPrice;
04295             }
04296 
04297             if ( $dVarMinPrice ) {
04298                 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04299                 $oDb->execute($sQ);
04300             }
04301         }
04302     }
04303 
04304 
04310     protected function _applyRangePrice()
04311     {
04312         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04313         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04314             return;
04315         }
04316 
04317         $this->_blIsRangePrice = false;
04318 
04319         // if parent is buyable - do not apply range price calcculations
04320         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04321             return;
04322         }
04323 
04324         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04325             //#2509 we cannot force brutto price here, as netto price can be added to DB
04326             // $this->getPrice()->setBruttoPriceMode();
04327             $dPrice = $this->oxarticles__oxvarminprice->value;
04328             $this->getPrice()->setPrice($dPrice);
04329             $this->_blIsRangePrice = true;
04330             $this->_calculatePrice( $this->getPrice() );
04331             return;
04332         }
04333 
04334         $aPrices = array();
04335 
04336         if (!$this->_blNotBuyableParent) {
04337             $aPrices[] = $this->getPrice()->getBruttoPrice();
04338         }
04339 
04340         $aVariants = $this->getVariants(false);
04341 
04342         if (count($aVariants)) {
04343             foreach ($aVariants as $sKey => $oVariant) {
04344                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04345             }
04346         }
04347 
04348         if ( count( $aPrices ) ) {
04349             $dMinPrice = min( $aPrices );
04350             $dMaxPrice = max( $aPrices );
04351         }
04352 
04353         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04354             $this->getPrice()->setBruttoPriceMode();
04355             $this->getPrice()->setPrice($dMinPrice);
04356         }
04357 
04358         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04359             $this->getPrice()->setBruttoPriceMode();
04360             $this->getPrice()->setPrice($dMinPrice);
04361             $this->_blIsRangePrice = true;
04362         }
04363     }
04364 
04371     public function getProductId()
04372     {
04373         return $this->getId();
04374     }
04375 
04381     public function getProductParentId()
04382     {
04383         return $this->oxarticles__oxparentid->value;
04384     }
04385 
04391     public function isOrderArticle()
04392     {
04393         return false;
04394     }
04395 
04401     public function isVariant()
04402     {
04403         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04404     }
04405 
04411     public function isMdVariant()
04412     {
04413         $oMdVariant = oxNew( "oxVariantHandler" );
04414 
04415         return $oMdVariant->isMdVariant($this);
04416     }
04417 
04425     public function getSqlForPriceCategories($sFields = '')
04426     {
04427         if (!$sFields) {
04428             $sFields = 'oxid';
04429         }
04430         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04431         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04432         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04433                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04434                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04435     }
04436 
04444     public function inPriceCategory( $sCatNid )
04445     {
04446         $oDb = oxDb::getDb();
04447 
04448         $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04449         $sQuotedCnid = $oDb->quote( $sCatNid );
04450         return (bool) $oDb->getOne(
04451             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04452            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04453            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04454            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04455            .")"
04456         );
04457     }
04458 
04464     public function getMdVariants()
04465     {
04466         if ( $this->_oMdVariants ) {
04467             return $this->_oMdVariants;
04468         }
04469 
04470         $oParentArticle = $this->getParentArticle();
04471         if ( $oParentArticle ) {
04472             $oVariants = $oParentArticle->getVariants();
04473         } else {
04474             $oVariants = $this->getVariants();
04475         }
04476 
04477         $oVariantHandler = oxNew( "oxVariantHandler" );
04478         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04479 
04480         return $this->_oMdVariants;
04481     }
04482 
04488     public function getMdSubvariants()
04489     {
04490         return $this->getMdVariants()->getMdSubvariants();
04491     }
04492 
04500     protected function _hasMasterImage( $iIndex )
04501     {
04502         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04503 
04504         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04505             return false;
04506         }
04507         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04508             return false;
04509         }
04510 
04511         $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04512 
04513         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04514             return true;
04515         }
04516 
04517         return false;
04518     }
04519 
04528     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04529     {
04530         if ( $sFieldName ) {
04531             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04532             return $this->$sFieldName->value;
04533         }
04534     }
04535 
04543     public function getMasterZoomPictureUrl( $iIndex )
04544     {
04545         $sPicUrl  = false;
04546         $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04547 
04548         if ( $sPicName && $sPicName != "nopic.jpg" ) {
04549             $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04550             if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04551                 $sPicUrl = false;
04552             }
04553         }
04554 
04555         return $sPicUrl;
04556     }
04557 
04563     public function getUnitName()
04564     {
04565         if ( $this->oxarticles__oxunitname->value ) {
04566             return oxLang::getInstance()->translateString( $this->oxarticles__oxunitname->value );
04567         }
04568     }
04569 
04577     public function getArticleFiles( $blAddFromParent=false )
04578     {
04579         if ( $this->_aArticleFiles === null) {
04580 
04581             $this->_aArticleFiles = false;
04582 
04583             $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04584 
04585             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04586                 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04587             }
04588 
04589             $oArticleFiles = oxNew("oxlist");
04590             $oArticleFiles->init("oxfile");
04591             $oArticleFiles->selectString( $sQ );
04592             $this->_aArticleFiles  = $oArticleFiles;
04593 
04594         }
04595 
04596         return $this->_aArticleFiles;
04597     }
04598 
04604     public function isDownloadable()
04605     {
04606         return $this->oxarticles__oxisdownloadable->value;
04607     }
04608 
04614     public function hasAmountPrice()
04615     {
04616         if ( self::$_blHasAmountPrice === null ) {
04617 
04618             self::$_blHasAmountPrice = false;
04619 
04620             $oDb = oxDb::getDb();
04621             $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04622 
04623             if ( $oDb->getOne( $sQ ) ) {
04624                 self::$_blHasAmountPrice = true;
04625             }
04626         }
04627 
04628         return self::$_blHasAmountPrice;
04629     }
04630 }