oxarticle.php

Go to the documentation of this file.
00001 <?php
00002 
00003 // defining supported link types
00004 define( 'OXARTICLE_LINKTYPE_CATEGORY', 0 );
00005 define( 'OXARTICLE_LINKTYPE_VENDOR', 1 );
00006 define( 'OXARTICLE_LINKTYPE_MANUFACTURER', 2 );
00007 define( 'OXARTICLE_LINKTYPE_PRICECATEGORY', 3 );
00008 define( 'OXARTICLE_LINKTYPE_TAG', 4 );
00009 define( 'OXARTICLE_LINKTYPE_RECOMM', 5 );
00010 
00017 class oxArticle extends oxI18n implements oxIArticle, oxIUrl
00018 {
00024     protected $_sCoreTbl = 'oxarticles';
00025 
00031     protected $_sClassName = 'oxarticle';
00032 
00038     protected $_blUseLazyLoading = true;
00039 
00045     protected $_sItemKey;
00046 
00052     protected $_blCalcPrice    = true;
00053 
00058     protected $_oPrice      = null;
00059 
00065     protected $_dArticleVat = null;
00066 
00072     protected $_aPersistParam  = null;
00073 
00079     protected $_blNotBuyable   = false;
00080 
00087     protected $_blLoadVariants = true;
00088 
00094     protected $_aVariants = null;
00095 
00101     protected $_aVariantsWithNotOrderables = null;
00102 
00111     protected $_blNotBuyableParent  = false;
00112 
00116     protected $_blHasVariants = false;
00117 
00121     protected $_blHasMdVariants = false;
00122 
00127     protected $_blIsOnComparisonList = false;
00128 
00133     protected $_oUser = null;
00134 
00140     protected $_blLoadPrice = true;
00141 
00145     protected $_blSkipAbPrice = false;
00146 
00153     protected $_fPricePerUnit = null;
00154 
00158     protected $_blLoadParentData = false;
00159 
00163     protected $_blSkipAssign = false;
00164 
00170     protected $_blSkipDiscounts = null;
00171 
00176     protected $_oAttributeList = null;
00177 
00178 
00184     protected $_blIsRangePrice = false;
00185 
00191     protected $_aMediaUrls = null;
00192 
00198     static protected $_aLoadedParents;
00199 
00205     static protected $_aSelList;
00206 
00212     protected $_aDispSelList;
00213 
00219     protected $_blIsSeoObject = true;
00220 
00226     protected $_oAmountPriceList = null;
00227 
00236     protected $_iLinkType = 0;
00237 
00243     protected $_aStdUrls = array();
00244 
00250     protected $_aSeoUrls = array();
00251 
00257     protected $_aSeoAddParams = array();
00258 
00264     protected $_aStdAddParams = array();
00265 
00271     protected $_sDynImageDir = null;
00272 
00278     protected $_sMoreDetailLink = null;
00279 
00285     protected $_sToBasketLink = null;
00286 
00292     protected $_iStockStatus = null;
00293 
00299     protected $_oTPrice = null;
00300 
00306     protected $_oAmountPriceInfo = null;
00307 
00313     protected $_dAmountPrice = null;
00314 
00320     protected static $_aArticleManufacturers = array();
00321 
00327     protected static $_aArticleVendors = array();
00328 
00334     protected static $_aArticleCats = array();
00335 
00341     protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00342                                              'oxarticles__oxtimestamp',
00343                                              'oxarticles__oxnid',
00344                                              'oxarticles__oxid',
00345                                              'oxarticles__oxparentid');
00346 
00352     protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00353                                          'oxarticles__oxfreeshipping',
00354                                          'oxarticles__oxremindactive');
00355 
00361     protected $_oMdVariants = null;
00362 
00368     protected $_oLongDesc = null;
00369 
00377     protected $_aVariantSelections = array();
00378 
00383     protected static $_aSelections = array();
00384 
00385 
00394     public function __construct($aParams = null)
00395     {
00396         if ( $aParams && is_array($aParams)) {
00397             foreach ( $aParams as $sParam => $mValue) {
00398                 $this->$sParam = $mValue;
00399             }
00400         }
00401         parent::__construct();
00402         $this->init( 'oxarticles' );
00403 
00404         $this->_blIsRangePrice = false;
00405     }
00406 
00415     public function __get($sName)
00416     {
00417         $myUtils = oxUtils::getInstance();
00418         // deprecated since 2011.03.10, should be used getArticleLongDesc() / getLongDesc()
00419         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00420             return $this->getArticleLongDesc();
00421         }
00422 
00423         //checking for zoom picture
00424         if ( strpos($sName, "oxarticles__oxzoom") === 0 ) {
00425             $this->_assignZoomPictureValues( $sName );
00426             return $this->$sName;
00427         }
00428 
00429         $this->$sName = parent::__get($sName);
00430         if ( $this->$sName ) {
00431             // since the field could have been loaded via lazyloading
00432             $this->_assignParentFieldValue($sName);
00433         }
00434 
00435         //checking for picture information
00436         if ( $sName == "oxarticles__oxthumb" || $sName == "oxarticles__oxicon" || (strpos($sName, "oxarticles__oxpic") === 0 && $sName != "oxarticles__oxpicsgenerated") ) {
00437             $this->_assignPictureValues( $sName );
00438             return $this->$sName;
00439         }
00440 
00441         return $this->$sName;
00442     }
00443 
00452     public function __set( $sName, $sValue )
00453     {
00454         // deprecated since 2011.03.14, should be used setArticleLongDesc()
00455         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00456             $sValue = ( $sValue instanceof oxField ) ? $sValue->getRawValue() : $sValue;
00457             $this->setArticleLongDesc( $sValue );
00458         } else {
00459             parent::__set( $sName, $sValue );
00460         }
00461     }
00462 
00470     public function setId( $sId = null )
00471     {
00472         $sId = parent::setId( $sId );
00473 
00474         // TODO: in oxbase::setId make it to check if exists and update, not recreate, then delete this overload
00475         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00476 
00477         return $sId;
00478     }
00479 
00489     public function getActiveCheckQuery( $blForceCoreTable = null )
00490     {
00491         $sTable = $this->getViewName( $blForceCoreTable );
00492 
00493         // check if article is still active
00494         $sQ = " $sTable.oxactive = 1 ";
00495 
00496         // enabled time range check ?
00497         if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00498             $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00499             $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00500         }
00501 
00502         return $sQ;
00503     }
00504 
00518     public function getStockCheckQuery( $blForceCoreTable = null )
00519     {
00520         $myConfig = $this->getConfig();
00521         $sTable = $this->getViewName( $blForceCoreTable );
00522 
00523         $sQ = "";
00524 
00525         //do not check for variants
00526         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00527             $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0  ) ";
00528             //V #M513: When Parent article is not purchaseble, it's visibility should be displayed in shop only if any of Variants is available.
00529             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00530                 $sTimeCheckQ = '';
00531                 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00532                      $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00533                      $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00534                 }
00535                 $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 ) ) ";
00536             }
00537         }
00538 
00539         return $sQ;
00540     }
00541 
00553     public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null  )
00554     {
00555         $sTable = $this->getViewName( $blForceCoreTable );
00556         $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00557 
00558         //checking if variant is active and stock status
00559         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00560             $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00561             if ( $blRemoveNotOrderables ) {
00562                 $sQ .= " and $sTable.oxstockflag != 3 ";
00563             }
00564             $sQ .= " ) ) ";
00565         }
00566 
00567         return $sQ;
00568     }
00569 
00577     public function getSqlActiveSnippet( $blForceCoreTable = null )
00578     {
00579         $myConfig = $this->getConfig();
00580 
00581         // check if article is still active
00582         $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00583 
00584         // stock and variants check
00585         $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00586 
00587 
00588         return "( $sQ ) ";
00589     }
00590 
00598     public function setSkipAssign($blSkipAssign)
00599     {
00600         $this->_blSkipAssign = $blSkipAssign;
00601     }
00602 
00608     public function disablePriceLoad()
00609     {
00610         $this->_blLoadPrice = false;
00611     }
00612 
00618     public function getItemKey()
00619     {
00620         return $this->_sItemKey;
00621     }
00622 
00630     public function setItemKey($sItemKey)
00631     {
00632         $this->_sItemKey = $sItemKey;
00633     }
00634 
00642     public function setNoVariantLoading( $blLoadVariants )
00643     {
00644         $this->_blLoadVariants = !$blLoadVariants;
00645     }
00646 
00652     public function isBuyable()
00653     {
00654         if ($this->_blNotBuyableParent) {
00655             return false;
00656         }
00657 
00658         return !$this->_blNotBuyable;
00659     }
00660 
00666     public function getPersParams()
00667     {
00668         return $this->_aPersistParam;
00669     }
00670 
00676     public function isOnComparisonList()
00677     {
00678         return $this->_blIsOnComparisonList;
00679     }
00680 
00688     public function setOnComparisonList( $blOnList )
00689     {
00690         $this->_blIsOnComparisonList = $blOnList;
00691     }
00692 
00700     public function setLoadParentData($blLoadParentData)
00701     {
00702         $this->_blLoadParentData = $blLoadParentData;
00703     }
00704 
00712     public function setSkipAbPrice( $blSkipAbPrice = null )
00713     {
00714         $this->_blSkipAbPrice = $blSkipAbPrice;
00715     }
00716 
00722     public function getSearchableFields()
00723     {
00724         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00725         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00726 
00727         return $aFields;
00728     }
00729 
00730 
00738     public function isMultilingualField($sFieldName)
00739     {
00740         switch ($sFieldName) {
00741             case "oxlongdesc":
00742             case "oxtags":
00743                 return true;
00744         }
00745 
00746         return parent::isMultilingualField($sFieldName);
00747     }
00748 
00754     public function isVisible()
00755     {
00756 
00757         // admin preview mode
00758         if ( ( $blCanPreview = oxUtils::getInstance()->canPreview() ) !== null ) {
00759             return $blCanPreview;
00760         }
00761 
00762         // active ?
00763         $sNow = date('Y-m-d H:i:s');
00764         if ( !$this->oxarticles__oxactive->value &&
00765              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00766                 $this->oxarticles__oxactiveto->value < $sNow
00767              )) {
00768             return false;
00769         }
00770 
00771         // stock flags
00772         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00773             $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00774             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00775                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00776             }
00777             if ( $iOnStock <= 0 ) {
00778                 return false;
00779             }
00780         }
00781 
00782         return true;
00783     }
00784 
00793     public function assign( $aRecord)
00794     {
00795         startProfile('articleAssign');
00796 
00797 
00798         // load object from database
00799         parent::assign( $aRecord);
00800 
00801         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00802 
00803         // check for simple article.
00804         if ($this->_blSkipAssign) {
00805             return;
00806         }
00807 
00808         $this->_assignParentFieldValues();
00809         $this->_assignNotBuyableParent();
00810 
00811         $this->_assignAllPictureValues();
00812 
00813         $this->_assignStock();
00814         startProfile('articleAssignPrices');
00815         $this->_assignPrices();
00816         stopProfile('articleAssignPrices');
00817         $this->_assignPersistentParam();
00818         $this->_assignDynImageDir();
00819         $this->_assignComparisonListFlag();
00820         $this->_assignAttributes();
00821 
00822 
00823         //$this->_seoAssign();
00824 
00825         stopProfile('articleAssign');
00826     }
00827 
00838     public function load( $oxID)
00839     {
00840         // A. #1325 resetting to avoid problems when reloading (details etc)
00841         $this->_blNotBuyableParent = false;
00842 
00843         $blRet = parent::load( $oxID);
00844 
00845         // convert date's to international format
00846         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00847         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00848 
00849         return $blRet;
00850     }
00851 
00859     public function addToRatingAverage( $iRating)
00860     {
00861         $dOldRating = $this->oxarticles__oxrating->value;
00862         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00863         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00864         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00865         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00866         $dRatingCnt = (int) ($dOldCnt + 1);
00867         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00868         oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00869     }
00870 
00876     public function getArticleRatingAverage()
00877     {
00878         return round( $this->oxarticles__oxrating->value, 1);
00879     }
00880 
00886     public function getReviews()
00887     {
00888         $myConfig  = $this->getConfig();
00889 
00890         $aIds = array($this->getId());
00891 
00892         if ( $this->oxarticles__oxparentid->value ) {
00893                 $aIds[] = $this->oxarticles__oxparentid->value;
00894         }
00895 
00896         // showing variant reviews ..
00897         if ( $myConfig->getConfigParam( 'blShowVariantReviews' ) ) {
00898             $aAdd = $this->_getVariantsIds();
00899             if (is_array($aAdd)) {
00900                 $aIds = array_merge($aIds, $aAdd);
00901             }
00902         }
00903 
00904         $oReview = oxNew('oxreview');
00905         $oRevs = $oReview->loadList('oxarticle', $aIds);
00906 
00907         //if no review found, return null
00908         if ( $oRevs->count() < 1 ) {
00909             return null;
00910         }
00911 
00912         return $oRevs;
00913     }
00914 
00920     public function getCrossSelling()
00921     {
00922         $oCrosslist = oxNew( "oxarticlelist");
00923         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00924         if ( $oCrosslist->count() ) {
00925             return $oCrosslist;
00926         }
00927     }
00928 
00934     public function getAccessoires()
00935     {
00936         $myConfig = $this->getConfig();
00937 
00938         // Performance
00939         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00940             return;
00941         }
00942 
00943         $oAcclist = oxNew( "oxarticlelist");
00944         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00945         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00946 
00947         if ( $oAcclist->count()) {
00948             return $oAcclist;
00949         }
00950     }
00951 
00957     public function getSimilarProducts()
00958     {
00959         // Performance
00960         $myConfig = $this->getConfig();
00961         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
00962             return;
00963         }
00964 
00965         $sArticleTable = $this->getViewName();
00966 
00967         $sAttribs = '';
00968         $iCnt = 0;
00969         $this->_getAttribsString($sAttribs, $iCnt);
00970 
00971         if ( !$sAttribs) {
00972             return null;
00973         }
00974 
00975         $aList = $this->_getSimList($sAttribs, $iCnt);
00976 
00977         if ( count( $aList ) ) {
00978             uasort( $aList, 'cmpart');
00979 
00980             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
00981 
00982             $oSimilarlist = oxNew( 'oxarticlelist' );
00983             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
00984             $oSimilarlist->selectString( $sSearch);
00985 
00986             return $oSimilarlist;
00987         }
00988     }
00989 
00995     public function getCustomerAlsoBoughtThisProducts()
00996     {
00997         // Performance
00998         $myConfig = $this->getConfig();
00999         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01000             return;
01001         }
01002 
01003         // selecting products that fits
01004         $sQ = $this->_generateSearchStrForCustomerBought();
01005 
01006         $oArticles = oxNew( 'oxarticlelist' );
01007         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01008         $oArticles->selectString( $sQ );
01009         if ( $oArticles->count() ) {
01010             return $oArticles;
01011         }
01012     }
01013 
01020     public function loadAmountPriceInfo()
01021     {
01022         $myConfig = $this->getConfig();
01023         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01024             return array();
01025         }
01026 
01027         if ( $this->_oAmountPriceInfo === null ) {
01028             $this->_oAmountPriceInfo = array();
01029             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01030                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01031 
01032             }
01033         }
01034         return $this->_oAmountPriceInfo;
01035     }
01036 
01044     public function getSelectLists($sKeyPrefix = null)
01045     {
01046         //#1468C - more then one article in basket with different selectlist...
01047         //optionall function parameter $sKeyPrefix added, used only in basket.php
01048         $sKey = $this->getId();
01049         if ( isset( $sKeyPrefix ) ) {
01050             $sKey = $sKeyPrefix.'__'.$this->getId();
01051         }
01052 
01053         if ( !isset( self::$_aSelList[$sKey] ) ) {
01054             $oDb = oxDb::getDb();
01055             $sSLViewName = getViewName( 'oxselectlist' );
01056 
01057             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01058                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01059 
01060             // all selectlists this article has
01061             $oLists = oxNew( 'oxlist' );
01062             $oLists->init( 'oxselectlist' );
01063             $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01064 
01065             //#1104S if this is variant ant it has no selectlists, trying with parent
01066             if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01067                 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01068             }
01069 
01070             $dVat = 0;
01071             if ( $this->getPrice() != null ) {
01072                 $dVat = $this->getPrice()->getVat();
01073             }
01074 
01075             $iCnt = 0;
01076             self::$_aSelList[$sKey] = array();
01077             foreach ( $oLists as $oSelectlist ) {
01078                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01079                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01080                 $iCnt++;
01081             }
01082         }
01083         return self::$_aSelList[$sKey];
01084     }
01085 
01093     protected function _hasAnyVariant( $blForceCoreTable = null )
01094     {
01095         $sArticleTable = $this->getViewName( $blForceCoreTable );
01096         return (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='".$this->getId()."'" );
01097     }
01098 
01104     public function hasMdVariants()
01105     {
01106         return $this->_blHasMdVariants;
01107     }
01108 
01118     public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01119     {
01120         $iLimit = (int) $iLimit;
01121         if ( !isset($this->_aVariantSelections[$iLimit])) {
01122             $this->_aVariantSelections[$iLimit] = false;
01123             if ( ( $oVariantList = $this->getVariants() ) ) {
01124                 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $oVariantList, $aFilterIds, $sActVariantId, $iLimit );
01125             }
01126         }
01127         return $this->_aVariantSelections[$iLimit];
01128     }
01129 
01138     public function getSelections( $iLimit = null, $aFilter = null )
01139     {
01140         $sId = $this->getId() . ( (int) $iLimit );
01141         if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01142 
01143             $oDb = oxDb::getDb();
01144             $sSLViewName = getViewName( 'oxselectlist' );
01145 
01146             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01147                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01148 
01149             if ( ( $iLimit = (int) $iLimit ) ) {
01150                 $sQ .= " limit $iLimit ";
01151             }
01152 
01153             // vat value for price
01154             $dVat = 0;
01155             if ( ( $oPrice = $this->getPrice() ) != null ) {
01156                 $dVat = $oPrice->getVat();
01157             }
01158 
01159             // all selectlists this article has
01160             $oList = oxNew( 'oxlist' );
01161             $oList->init( 'oxselectlist' );
01162             $oList->getBaseObject()->setVat( $dVat );
01163             $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01164 
01165             //#1104S if this is variant and it has no selectlists, trying with parent
01166             if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01167                 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01168             }
01169 
01170             self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01171         }
01172 
01173         if ( self::$_aSelections[$sId] ) {
01174             // marking active from filter
01175             $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01176             if ( $aFilter ) {
01177                 $iSelIdx = 0;
01178                 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01179                     if ( isset( $aFilter[$iSelIdx] ) ) {
01180                         $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01181                     }
01182                     $iSelIdx++;
01183                 }
01184             }
01185         }
01186 
01187         return self::$_aSelections[$sId];
01188     }
01189 
01198     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null  )
01199     {
01200         if ( $blRemoveNotOrderables && $this->_aVariants ) {
01201             return $this->_aVariants;
01202         } elseif ( !$blRemoveNotOrderables && $this->_aVariantsWithNotOrderables ) {
01203             return $this->_aVariantsWithNotOrderables;
01204         }
01205 
01206         $myConfig = $this->getConfig();
01207         if ( !$this->_blLoadVariants ||
01208             ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01209             ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01210             return array();
01211         }
01212 
01213         //do not load me as a parent later
01214         self::$_aLoadedParents[$this->getId()] = $this;
01215 
01216         //load simple variants for lists
01217         if ( $this->_isInList() ) {
01218             $oVariants = oxNew( 'oxsimplevariantlist' );
01219             $oVariants->setParent( $this );
01220         } else {
01221             //loading variants
01222             $oVariants = oxNew( 'oxarticlelist' );
01223             $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01224         }
01225 
01226         if ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) {
01227 
01228             startProfile("selectVariants");
01229             $blUseCoreTable = (bool)$blForceCoreTable;
01230             $oBaseObject = $oVariants->getBaseObject();
01231             $oBaseObject->setLanguage($this->getLanguage());
01232             $sArticleTable = $this->getViewName( $blUseCoreTable );
01233 
01234             $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01235                        $this->getActiveCheckQuery( $blUseCoreTable ) .
01236                        $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01237                        " order by $sArticleTable.oxsort";
01238 
01239             $oVariants->selectString( $sSelect );
01240 
01241             //if this is multidimensional variants, make additional processing
01242             if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01243                 $oMdVariants = oxNew( "oxVariantHandler" );
01244                 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01245             }
01246             stopProfile("selectVariants");
01247         }
01248 
01249         //if we have variants then depending on config option the parent may be non buyable
01250         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01251             $this->_blNotBuyableParent = true;
01252         }
01253 
01254         //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01255         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $oVariants->count() == 0 && $this->_blHasVariants ) {
01256             $this->_blNotBuyable = true;
01257         }
01258 
01259         // cache
01260         if ( $blRemoveNotOrderables ) {
01261             $this->_aVariants = $oVariants;
01262         } else {
01263             $this->_aVariantsWithNotOrderables = $oVariants;
01264         }
01265 
01266         return $oVariants;
01267     }
01268 
01274     public function getSimpleVariants()
01275     {
01276         if ( $this->oxarticles__oxvarcount->value) {
01277             return $this->getVariants();
01278         }
01279     }
01280 
01289     public function getAdminVariants( $sLanguage = null )
01290     {
01291         $myConfig = $this->getConfig();
01292 
01293         $oVariants = oxNew( 'oxarticlelist');
01294 
01295         $oBaseObj = $oVariants->getBaseObject();
01296 
01297         if ( is_null($sLanguage) ) {
01298             $oBaseObj->setLanguage(oxLang::getInstance()->getBaseLanguage());
01299         } else {
01300             $oBaseObj->setLanguage($sLanguage);
01301         }
01302 
01303         $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '".$this->getId()."' order by oxsort ";
01304 
01305         $oVariants->selectString( $sSql);
01306 
01307         //if we have variants then depending on config option the parent may be non buyable
01308         if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01309             //$this->blNotBuyable = true;
01310             $this->_blNotBuyableParent = true;
01311         }
01312 
01313         return $oVariants;
01314     }
01315 
01323     public function getCategory()
01324     {
01325         startPRofile( 'getCategory' );
01326 
01327         $oCategory = oxNew( 'oxcategory' );
01328         $oCategory->setLanguage( $this->getLanguage() );
01329 
01330         // variant handling
01331         $sOXID = $this->getId();
01332         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01333             $sOXID = $this->oxarticles__oxparentid->value;
01334         }
01335 
01336         $oStr = getStr();
01337         $sWhere   = $oCategory->getSqlActiveSnippet();
01338         $sSelect  = $this->_generateSearchStr( $sOXID );
01339         $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01340 
01341         // category not found ?
01342         if ( !$oCategory->assignRecord( $sSelect ) ) {
01343 
01344             $sSelect  = $this->_generateSearchStr( $sOXID, true );
01345             $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01346 
01347             // looking for price category
01348             if ( !$oCategory->assignRecord( $sSelect ) ) {
01349                 $oCategory = null;
01350             }
01351         }
01352 
01353         stopPRofile( 'getCategory' );
01354         return $oCategory;
01355     }
01356 
01365     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01366     {
01367         $myConfig = $this->getConfig();
01368         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01369             return self::$_aArticleCats[$this->getId()];
01370         }
01371 
01372         // variant handling
01373         $sOXID = $this->getId();
01374         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01375             $sOXID = $this->oxarticles__oxparentid->value;
01376         }
01377 
01378         // we do not use lists here as we dont need this overhead right now
01379         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01380         $oDB = oxDb::getDb(true);
01381         $rs = $oDB->execute( $sSql );
01382 
01383 
01384         $aRet = array();
01385 
01386         if ($rs != false && $rs->recordCount() > 0) {
01387             while (!$rs->EOF) {
01388                 $aRet[] = $rs->fields['oxcatnid'];
01389                 $rs->moveNext();
01390             }
01391         }
01392 
01393         // adding price categories if such exists
01394         $sSql = $this->getSqlForPriceCategories();
01395 
01396         $oDB = oxDb::getDb( true );
01397         $rs = $oDB->execute( $sSql );
01398 
01399         if ($rs != false && $rs->recordCount() > 0) {
01400             while (!$rs->EOF) {
01401 
01402                 if ( is_array( $rs->fields ) ) {
01403                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01404                 }
01405 
01406 
01407                 if ( !$aRet[$rs->fields['oxid']] ) {
01408                     $aRet[] = $rs->fields['oxid'];
01409                 }
01410                 $rs->moveNext();
01411             }
01412         }
01413 
01414         return self::$_aArticleCats[$this->getId()] = $aRet;
01415     }
01416 
01425     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01426     {
01427         $sO2CView = $this->_getObjectViewName('oxobject2category');
01428         $sCatView = $this->_getObjectViewName('oxcategories');
01429         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01430         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01431         if ( $blActCats ) {
01432             $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 ";
01433         }
01434         $sSelect .= 'order by oxobject2category.oxtime ';
01435         return $sSelect;
01436     }
01437 
01447     public function getVendor( $blShopCheck = true )
01448     {
01449         if ( ( $sVendorId = $this->getVendorId() ) ) {
01450             $oVendor = oxNew( 'oxvendor' );
01451         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01452             $oVendor = oxNew( 'oxi18n' );
01453             $oVendor->init('oxvendor');
01454             $oVendor->setReadOnly( true );
01455             $sVendorId = $this->oxarticles__oxvendorid->value;
01456         }
01457         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01458             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01459                 $oVendor->setReadOnly( true );
01460             }
01461             return $oVendor;
01462         }
01463         return null;
01464     }
01465 
01473     public function getVendorId( $blForceReload = false )
01474     {
01475         $sVendorId = false;
01476         if ( $this->oxarticles__oxvendorid->value ) {
01477             if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01478                 return self::$_aArticleVendors[$this->getId()];
01479             }
01480             $oDb = oxDb::getDb();
01481             $sVendorIdQuoted = $oDb->quote($this->oxarticles__oxvendorid->value);
01482             $sQ = "select oxid from ".getViewName('oxvendor')." where oxid=$sVendorIdQuoted";
01483             self::$_aArticleVendors[$this->getId()] = $sVendorId = $oDb->getOne( $sQ );
01484         }
01485         return $sVendorId;
01486     }
01487 
01495     public function getManufacturerId( $blForceReload = false )
01496     {
01497         $sManufacturerId = false;
01498         if ( $this->oxarticles__oxmanufacturerid->value ) {
01499             if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01500                 return self::$_aArticleManufacturers[$this->getId()];
01501             }
01502             $oDb = oxDb::getDb();
01503             $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid=".$oDb->quote($this->oxarticles__oxmanufacturerid->value);
01504             self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = $oDb->getOne( $sQ );
01505         }
01506         return $sManufacturerId;
01507     }
01508 
01518     public function getManufacturer( $blShopCheck = true )
01519     {
01520         $oManufacturer = oxNew( 'oxmanufacturer' );;
01521         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01522              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01523             $oManufacturer->setReadOnly( true );
01524             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01525         }
01526 
01527         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01528             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01529                 $oManufacturer->setReadOnly( true );
01530             }
01531             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01532         } else {
01533             $oManufacturer = null;
01534         }
01535 
01536         return $oManufacturer;
01537     }
01538 
01546     public function inCategory( $sCatNid)
01547     {
01548         return in_array( $sCatNid, $this->getCategoryIds());
01549     }
01550 
01559     public function isAssignedToCategory( $sCatId )
01560     {
01561         // variant handling
01562         $sOXID = $this->getId();
01563         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01564             $sOXID = $this->oxarticles__oxparentid->value;
01565         }
01566 
01567         $oDB = oxDb::getDb();
01568         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01569         $sOXID = $oDB->getOne( $sSelect);
01570         // article is assigned to passed category!
01571         if ( isset( $sOXID) && $sOXID) {
01572             return true;
01573         }
01574 
01575         // maybe this category is price category ?
01576         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01577             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01578             if ( $dPriceFromTo > 0) {
01579                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01580                 $sOXID = $oDB->getOne( $sSelect);
01581                 // article is assigned to passed category!
01582                 if ( isset( $sOXID) && $sOXID) {
01583                     return true;
01584                 }
01585             }
01586         }
01587         return false;
01588     }
01589 
01595     public function getTPrice()
01596     {
01597         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01598             return;
01599         }
01600         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01601         if ( $this->_oTPrice !== null ) {
01602             return $this->_oTPrice;
01603         }
01604 
01605         $this->_oTPrice = oxNew( 'oxPrice' );
01606         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01607 
01608         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01609         $this->_applyCurrency( $this->_oTPrice );
01610 
01611         return $this->_oTPrice;
01612     }
01613 
01619     public function skipDiscounts()
01620     {
01621         // allready loaded skip discounts config
01622         if ( $this->_blSkipDiscounts !== null )
01623             return $this->_blSkipDiscounts;
01624 
01625         if ( $this->oxarticles__oxskipdiscounts->value )
01626             return true;
01627 
01628         $sO2CView  = getViewName( 'oxobject2category', $this->getLanguage() );
01629         $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01630         $sSelect =  "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01631                      where $sO2CView.oxobjectid='".$this->getId()."' and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01632         return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01633     }
01634 
01642     public function setPrice(oxPrice $oPrice)
01643     {
01644         $this->_oPrice = $oPrice;
01645     }
01646 
01655     public function getBasePrice( $dAmount = 1 )
01656     {
01657         // override this function if you want e.g. different prices
01658         // for diff. usergroups.
01659 
01660         // Performance
01661         $myConfig = $this->getConfig();
01662         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01663             return;
01664 
01665         // GroupPrice or DB price ajusted by AmountPrice
01666         $dPrice = $this->_getAmountPrice( $dAmount );
01667 
01668 
01669         return $dPrice;
01670     }
01671 
01679     public function getPrice( $dAmount = 1 )
01680     {
01681         $myConfig = $this->getConfig();
01682         // Performance
01683         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01684             return;
01685         }
01686 
01687         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01688         if ( $dAmount != 1 || $this->_oPrice === null ) {
01689             $oPrice = oxNew( 'oxPrice' );
01690 
01691             // get base
01692             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01693 
01694             // price handling
01695             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01696                 return $this->_oPrice = $oPrice;
01697             }
01698 
01699             $this->_calculatePrice( $oPrice );
01700             if ( $dAmount != 1 ) {
01701                 return $oPrice;
01702             }
01703 
01704             $this->_oPrice = $oPrice;
01705         }
01706         return $this->_oPrice;
01707     }
01708 
01716     protected function _calculatePrice( $oPrice )
01717     {
01718         // apply VAT only if configuration requires it
01719         if ( !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01720             $this->_applyVAT( $oPrice, $this->getArticleVat() );
01721         }
01722 
01723         // apply currency
01724         $this->_applyCurrency( $oPrice );
01725         // apply discounts
01726         if ( !$this->skipDiscounts() ) {
01727             $oDiscountList = oxDiscountList::getInstance();
01728             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts($this, $this->getArticleUser() ) );
01729         }
01730 
01731         return $oPrice;
01732     }
01733 
01741     public function setArticleUser($oUser)
01742     {
01743         $this->_oUser = $oUser;
01744     }
01745 
01751     public function getArticleUser()
01752     {
01753         if ($this->_oUser) {
01754             return $this->_oUser;
01755         }
01756         return $this->getUser();
01757     }
01758 
01768     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01769     {
01770         $oUser = $oBasket->getBasketUser();
01771         $this->setArticleUser($oUser);
01772 
01773         $oBasketPrice = oxNew( 'oxPrice' );
01774 
01775         // get base price
01776         $dBasePrice = $this->getBasePrice( $dAmount );
01777 
01778         // applying select list price
01779         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01780 
01781         // setting price
01782         $oBasketPrice->setPrice( $dBasePrice );
01783 
01784         // apply VAT
01785         $this->_applyVat( $oBasketPrice, oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket ) );
01786 
01787         // apply currency
01788         $this->_applyCurrency( $oBasketPrice );
01789 
01790         // apply discounts
01791         if ( !$this->skipDiscounts() ) {
01792             // apply general discounts
01793             $oDiscountList = oxDiscountList::getInstance();
01794             $oDiscountList->applyDiscounts( $oBasketPrice, $oDiscountList->getArticleDiscounts( $this, $oUser ) );
01795         }
01796 
01797         // returning final price object
01798         return $oBasketPrice;
01799     }
01800 
01813     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01814     {
01815         $oDiscountList = oxDiscountList::getInstance();
01816         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01817     }
01818 
01827     public function delete( $sOXID = null )
01828     {
01829         if ( !$sOXID ) {
01830             $sOXID = $this->getId();
01831         }
01832         if ( !$sOXID ) {
01833             return false;
01834         }
01835 
01836 
01837         // #2339 delete first variants before deleting parent product
01838         $this->_deleteVariantRecords( $sOXID );
01839         $this->load( $sOXID );
01840         $this->_deletePics();
01841         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01842 
01843         $rs = $this->_deleteRecords( $sOXID );
01844 
01845         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01846 
01847         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01848 
01849         return $rs->EOF;
01850     }
01851 
01860     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01861     {
01862         $this->beforeUpdate();
01863 
01864         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01865         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01866             $dAmount += $iStockCount;
01867             $iStockCount = 0;
01868         }
01869         $this->oxarticles__oxstock = new oxField($iStockCount);
01870 
01871         $oDb = oxDb::getDb();
01872         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01873         $this->onChange( ACTION_UPDATE_STOCK );
01874         return $dAmount;
01875     }
01876 
01885     public function updateSoldAmount( $dAmount = 0 )
01886     {
01887         if ( !$dAmount ) {
01888             return;
01889         }
01890 
01891         $this->beforeUpdate();
01892 
01893         // article is not variant - should be updated current amount
01894         if ( !$this->oxarticles__oxparentid->value ) {
01895             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01896             $dAmount = (double) $dAmount;
01897             $oDb = oxDb::getDb();
01898             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01899         } elseif ( $this->oxarticles__oxparentid->value) {
01900             // article is variant - should be updated this article parent amount
01901             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01902             $oUpdateArticle->updateSoldAmount( $dAmount );
01903         }
01904 
01905         $this->onChange( ACTION_UPDATE );
01906 
01907         return $rs;
01908     }
01909 
01915     public function disableReminder()
01916     {
01917         $oDB = oxDb::getDb(true);
01918         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01919     }
01920 
01927     public function save()
01928     {
01929         $myConfig = $this->getConfig();
01930 
01931         $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01932         $this->oxarticles__oxicon  = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01933         $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01934         for ($i=1; $i <= $iPicCount; $i++) {
01935             if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01936                 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01937             }
01938         }
01939 
01940         if ( ( $blRet = parent::save() ) ) {
01941 
01942             // saving long descrition
01943             $this->_saveArtLongDesc();
01944 
01945             // load article images after save
01946             $this->_assignAllPictureValues();
01947         }
01948 
01949         return $blRet;
01950     }
01951 
01952 
01959     public function getPictureGallery()
01960     {
01961         $myConfig = $this->getConfig();
01962 
01963         //initialize
01964         $blMorePic = false;
01965         $aArtPics  = array();
01966         $aArtIcons = array();
01967         $iActPicId = 1;
01968         $sActPic = $this->getPictureUrl( $iActPicId );
01969 
01970         if ( oxConfig::getParameter( 'actpicid' ) ) {
01971             $iActPicId = oxConfig::getParameter('actpicid');
01972         }
01973 
01974         $oStr = getStr();
01975         $iCntr = 0;
01976         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01977         $blCheckActivePicId = true;
01978 
01979         for ( $i = 1; $i <= $iPicCount; $i++) {
01980             $sPicVal = $this->getPictureUrl( $i );
01981             $sIcoVal = $this->getIconUrl( $i );
01982             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') ) {
01983                 if ($iCntr) {
01984                     $blMorePic = true;
01985                 }
01986                 $aArtIcons[$i]= $sIcoVal;
01987                 $aArtPics[$i]= $sPicVal;
01988                 $iCntr++;
01989 
01990                 if ($iActPicId == $i) {
01991                     $sActPic = $sPicVal;
01992                     $blCheckActivePicId = false;
01993                 }
01994 
01995             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
01996                 // if picture is empty, setting active pic id to next
01997                 // picture
01998                 $iActPicId++;
01999             }
02000         }
02001 
02002         $blZoomPic  = false;
02003         $aZoomPics = array();
02004         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02005 
02006         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02007             $sVal = $this->getZoomPictureUrl($j);
02008 
02009             if ( !$oStr->strstr($sVal, 'nopic.jpg')) {
02010                 $blZoomPic = true;
02011                 $aZoomPics[$c]['id'] = $c;
02012                 $aZoomPics[$c]['file'] = $sVal;
02013                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02014                 if (!$sVal) {
02015                     $aZoomPics[$c]['file'] = "nopic.jpg";
02016                 }
02017                 $c++;
02018             }
02019         }
02020 
02021         $aPicGallery = array('ActPicID' => $iActPicId,
02022                              'ActPic' => $sActPic,
02023                              'MorePics' => $blMorePic,
02024                              'Pics' => $aArtPics,
02025                              'Icons' => $aArtIcons,
02026                              'ZoomPic' => $blZoomPic,
02027                              'ZoomPics' => $aZoomPics);
02028 
02029         return $aPicGallery;
02030     }
02031 
02045     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02046     {
02047         $myConfig = $this->getConfig();
02048 
02049         if (!isset($sOXID)) {
02050             if ( $this->getId()) {
02051                 $sOXID = $this->getId();
02052             }
02053             if (!isset ($sOXID)) {
02054                 $sOXID = $this->oxarticles__oxid->value;
02055             }
02056             if ($this->oxarticles__oxparentid->value) {
02057                 $sParentID = $this->oxarticles__oxparentid->value;
02058             }
02059         }
02060         if (!isset($sOXID)) {
02061             return;
02062         }
02063 
02064         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02065         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02066             //if article has variants then updating oxvarstock field
02067             //getting parent id
02068             if (!isset($sParentID)) {
02069                 $oDb = oxDb::getDb();
02070                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02071                 $sParentID = $oDb->getOne($sQ);
02072             }
02073             //if we have parent id then update stock
02074             if ($sParentID) {
02075                 $this->_onChangeUpdateStock($sParentID);
02076             }
02077         }
02078         //if we have parent id then update count
02079         //update count even if blUseStock is not active
02080         if ($sParentID) {
02081             $this->_onChangeUpdateVarCount($sParentID);
02082         }
02083 
02084         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02085         $this->_onChangeUpdateMinVarPrice( $sId );
02086 
02087             // reseting articles count cache if stock has changed and some
02088             // articles goes offline (M:1448)
02089             if ( $sAction === ACTION_UPDATE_STOCK ) {
02090                 $this->_onChangeStockResetCount( $sOXID );
02091             }
02092 
02093     }
02094 
02101     public function getCustomVAT()
02102     {
02103         if ( isset($this->oxarticles__oxvat->value) ) {
02104             return $this->oxarticles__oxvat->value;
02105         }
02106     }
02107 
02116     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02117     {
02118         $myConfig = $this->getConfig();
02119         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02120             return true;
02121         }
02122 
02123         // fetching DB info as its up-to-date
02124         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02125         $rs = oxDb::getDb(true)->Execute( $sQ );
02126 
02127         $iOnStock   = 0;
02128         $iStockFlag = 0;
02129         if ( $rs !== false && $rs->recordCount() > 0 ) {
02130             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02131             $iStockFlag = $rs->fields['oxstockflag'];
02132 
02133             // dodger : fremdlager is also always considered as on stock
02134             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02135                 return true;
02136             }
02137             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02138                 $iOnStock = floor( $iOnStock );
02139             }
02140         }
02141         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02142             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02143         }
02144         if ( $iOnStock >= $dAmount ) {
02145             return true;
02146         } else {
02147             if ( $iOnStock > 0 ) {
02148                 return $iOnStock;
02149             } else {
02150                 $oEx = oxNew( 'oxArticleInputException' );
02151                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02152                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02153                 return false;
02154             }
02155         }
02156     }
02157 
02158 
02166     public function getArticleLongDesc( $sOxid = null )
02167     {
02168         if ( $this->_oLongDesc === null ) {
02169 
02170             // initializing
02171             $this->_oLongDesc = new oxField();
02172 
02173 
02174             // choosing which to get..
02175             $sOxid = $sOxid === null ? $this->getId() : $sOxid;
02176             $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02177             if ( ( $sDbValue = oxDb::getDb()->getOne( "select oxlongdesc from {$sViewName} where oxid = ?", array( $sOxid ) ) ) !== false ) {
02178                 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02179             }
02180         }
02181 
02182         return $this->_oLongDesc;
02183     }
02184 
02194     protected function _setLongDesc( $sDbValue )
02195     {
02196         $this->setArticleLongDesc( $sDbValue );
02197     }
02198 
02205     public function getLongDesc()
02206     {
02207         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getArticleLongDesc()->getRawValue(), $this->getId().$this->getLanguage() );
02208     }
02209 
02218     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02219     {
02220 
02221         // setting current value
02222         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02223 
02224         // setting original value?
02225         if ( $sOrigValue ) {
02226             $this->_oLongDesc->orignalValue = $sOrigValue;
02227         }
02228     }
02229 
02235     public function getAttributes()
02236     {
02237         if ( $this->_oAttributeList === null ) {
02238             $this->_oAttributeList = oxNew( 'oxattributelist' );
02239             $this->_oAttributeList->loadAttributes( $this->getId() );
02240         }
02241 
02242         return $this->_oAttributeList;
02243     }
02244 
02253     public function appendLink( $sAddParams, $iLang = null )
02254     {
02255         if ( $sAddParams ) {
02256             if ( $iLang === null ) {
02257                 $iLang = $this->getLanguage();
02258             }
02259 
02260             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02261             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02262         }
02263     }
02264 
02273     public function getBaseSeoLink( $iLang, $blMain = false )
02274     {
02275         $oEncoder = oxSeoEncoderArticle::getInstance();
02276         if ( !$blMain ) {
02277             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02278         }
02279         return $oEncoder->getArticleMainUrl( $this, $iLang );
02280     }
02281 
02290     public function getLink( $iLang = null, $blMain = false  )
02291     {
02292         if ( !oxUtils::getInstance()->seoIsActive() ) {
02293             return $this->getStdLink( $iLang );
02294         }
02295 
02296         if ( $iLang === null ) {
02297             $iLang = $this->getLanguage();
02298         }
02299 
02300         $iLinkType = $this->getLinkType();
02301         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02302             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02303         }
02304 
02305         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02306         if ( isset($this->_aSeoAddParams[$iLang])) {
02307             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02308         }
02309 
02310         return $sUrl;
02311     }
02312 
02321     public function getMainLink( $iLang = null )
02322     {
02323         return $this->getLink( $iLang, true );
02324     }
02325 
02333     public function setLinkType( $iType )
02334     {
02335         // resetting detaisl link, to force new
02336         $this->_sDetailLink = null;
02337 
02338         // setting link type
02339         $this->_iLinkType = (int) $iType;
02340     }
02341 
02347     public function getLinkType()
02348     {
02349         return $this->_iLinkType;
02350     }
02351 
02360     public function appendStdLink( $sAddParams, $iLang = null )
02361     {
02362         if ( $sAddParams ) {
02363             if ( $iLang === null ) {
02364                 $iLang = $this->getLanguage();
02365             }
02366 
02367             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02368             $this->_aStdAddParams[$iLang] .= $sAddParams;
02369         }
02370     }
02371 
02381     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02382     {
02383         $sUrl = '';
02384         if ( $blFull ) {
02385             //always returns shop url, not admin
02386             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02387         }
02388 
02389         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02390         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02391     }
02392 
02401     public function getStdLink( $iLang = null, $aParams = array() )
02402     {
02403         if ( $iLang === null ) {
02404             $iLang = $this->getLanguage();
02405         }
02406 
02407         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02408             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02409         }
02410 
02411         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02412     }
02413 
02421     public function getStdTagLink( $sTag )
02422     {
02423         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02424         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02425     }
02426 
02432     public function getTags()
02433     {
02434         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02435         $sQ = "select oxtags from {$sViewName} where oxid = '".$this->getId()."'";
02436         $oTagCloud = oxNew('oxtagcloud');
02437         return $oTagCloud->trimTags( oxDb::getDb()->getOne( $sQ ) );
02438     }
02439 
02447     public function saveTags($sTags)
02448     {
02449         //do not allow derived update
02450         if ( !$this->allowDerivedUpdate() ) {
02451             return false;
02452         }
02453 
02454 
02455         $oTagCloud = oxNew( 'oxtagcloud' );
02456         $oTagCloud->resetTagCache();
02457         $sTags = mysql_real_escape_string( $oTagCloud->prepareTags( $sTags ) );
02458 
02459         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02460         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02461         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value ('".$this->getId()."', '{$sTags}')
02462                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02463         return oxDb::getDb()->execute( $sQ );
02464     }
02465 
02473     public function addTag($sTag)
02474     {
02475         $oDb = oxDb::getDb();
02476 
02477         $oTagCloud = oxNew('oxtagcloud');
02478         $oTagCloud->resetTagCache();
02479         $sTag = $oTagCloud->prepareTags($sTag);
02480         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02481 
02482         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02483         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02484         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = '".$this->getId()."'" ) ) {
02485             $sTailTag = $sTagSeparator . $sTag;
02486         } else {
02487             $sTailTag = $sTag;
02488         }
02489 
02490         $sTag = mysql_real_escape_string($sTag);
02491         $sTailTag = mysql_real_escape_string($sTailTag);
02492 
02493         $sTag = mysql_real_escape_string($sTag);
02494         $sTailTag = mysql_real_escape_string($sTailTag);
02495 
02496         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values ('".$this->getId()."', '{$sTag}')
02497                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02498 
02499         return $oDb->execute( $sQ );
02500     }
02501 
02507     public function getMediaUrls()
02508     {
02509         if ( $this->_aMediaUrls === null ) {
02510             $this->_aMediaUrls = oxNew("oxlist");
02511             $this->_aMediaUrls->init("oxmediaurl");
02512             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02513 
02514             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02515             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02516             $this->_aMediaUrls->selectString($sQ);
02517         }
02518         return $this->_aMediaUrls;
02519     }
02520 
02526     public function getDynImageDir()
02527     {
02528         return $this->_sDynImageDir;
02529     }
02530 
02536     public function getDispSelList()
02537     {
02538         if ($this->_aDispSelList === null) {
02539             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02540                 $this->_aDispSelList = $this->getSelectLists();
02541             }
02542         }
02543         return $this->_aDispSelList;
02544     }
02545 
02551     public function getMoreDetailLink()
02552     {
02553         if ( $this->_sMoreDetailLink == null ) {
02554 
02555             // and assign special article values
02556             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02557 
02558             // not always it is okey, as not all the time active category is the same as primary article cat.
02559             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02560                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02561             }
02562             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02563             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02564         }
02565 
02566         return $this->_sMoreDetailLink;
02567     }
02568 
02574     public function getToBasketLink()
02575     {
02576         if ( $this->_sToBasketLink == null ) {
02577             $myConfig = $this->getConfig();
02578 
02579             if ( oxUtils::getInstance()->isSearchEngine() ) {
02580                 $this->_sToBasketLink = $this->getLink();
02581             } else {
02582                 // and assign special article values
02583                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02584 
02585                 // override some classes as these should never showup
02586                 $sActClass = oxConfig::getParameter( 'cl' );
02587                 if ( $sActClass == 'thankyou') {
02588                     $sActClass = 'basket';
02589                 }
02590                 $this->_sToBasketLink .= 'cl='.$sActClass;
02591 
02592                 // this is not very correct
02593                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02594                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02595                 }
02596 
02597                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02598 
02599                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02600                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02601                 }
02602             }
02603         }
02604 
02605         return $this->_sToBasketLink;
02606     }
02607 
02613     public function getStockStatus()
02614     {
02615         return $this->_iStockStatus;
02616     }
02617 
02623     public function getDeliveryDate()
02624     {
02625         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02626             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02627         }
02628         return false;
02629     }
02630 
02636     public function getFTPrice()
02637     {
02638         if ( $oPrice = $this->getTPrice() ) {
02639             if ( $oPrice->getBruttoPrice() ) {
02640                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02641             }
02642         }
02643     }
02644 
02650     public function getFPrice()
02651     {
02652         if ( $oPrice = $this->getPrice() ) {
02653             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02654         }
02655     }
02656 
02662     public function getFNetPrice()
02663     {
02664         if ( $oPrice = $this->getPrice() ) {
02665             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02666         }
02667     }
02668 
02674     public function getPricePerUnit()
02675     {
02676         return $this->_fPricePerUnit;
02677     }
02678 
02684     public function isParentNotBuyable()
02685     {
02686         return $this->_blNotBuyableParent;
02687     }
02688 
02694     public function isNotBuyable()
02695     {
02696         return $this->_blNotBuyable;
02697     }
02698 
02706     public function setBuyableState( $blBuyable = false )
02707     {
02708         $this->_blNotBuyable = !$blBuyable;
02709     }
02710 
02719     public function getVariantList()
02720     {
02721         return $this->getVariants();
02722     }
02723 
02731     public function setSelectlist( $aSelList )
02732     {
02733         $this->_aDispSelList = $aSelList;
02734     }
02735 
02743     public function getPictureUrl( $iIndex = '' )
02744     {
02745         if ( $iIndex ) {
02746 
02747             if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02748                 $this->_generateImages( $iIndex );
02749             }
02750 
02751             $sPic = $iIndex . "/" . $this->_getPictureName( $iIndex );
02752 
02753             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02754         }
02755     }
02756 
02764     protected function _getPictureName( $iIndex = '' )
02765     {
02766         if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02767             $sPicName = basename($this->{"oxarticles__oxpic".$iIndex}->value);
02768         } else {
02769             $sPicName = "nopic.jpg";
02770         }
02771 
02772         return $sPicName;
02773     }
02774 
02783     public function getIconUrl( $iIndex = '')
02784     {
02785         if ( $this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02786 
02787             $iIconIndex = ( $iIndex ) ? $iIndex : 1;
02788             //generating new images if needed
02789             if ( !$this->_hasGeneratedImage( $iIconIndex ) ) {
02790                 $this->_generateImages( $iIconIndex );
02791             }
02792         }
02793 
02794         $sIconName = $this->_getIconName( $iIndex );
02795 
02796         if ( !$iIndex ) {
02797             $sPic = "icon/" . basename( $sIconName );
02798         } else {
02799             $sPic = $iIndex . "/" . basename( $sIconName );
02800         }
02801 
02802         return $this->getConfig()->getIconUrl( $sPic, $this->isAdmin() );
02803     }
02804 
02813     protected function _getIconName( $iIndex = '' )
02814     {
02815         $oPictureHandler = oxPictureHandler::getInstance();
02816         $sIconName = "nopic_ico.jpg";
02817 
02818         if ( !$iIndex ) {
02819             if ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02820                 $sIconName = basename( $this->oxarticles__oxicon->value );
02821             } elseif ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 )  && $this->oxarticles__oxpic1->value ) {
02822                 $sIconName = $oPictureHandler->getMainIconName( $this->oxarticles__oxpic1->value );
02823             }
02824         } else {
02825             if ( $this->_hasGeneratedImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02826                 $sIconName = $oPictureHandler->getIconName( $this->{"oxarticles__oxpic".$iIndex}->value );
02827             }
02828         }
02829 
02830         return $sIconName;
02831     }
02832 
02838     public function getThumbnailUrl()
02839     {
02840         if ( $this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02841             //generating new images if needed
02842             if ( !$this->_hasGeneratedImage( 1 ) ) {
02843                 $this->_generateImages( 1 );
02844             }
02845         }
02846 
02847         $sPic = "0/" . $this->_getThumbnailName();
02848 
02849         return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02850     }
02851 
02857     protected function _getThumbnailName()
02858     {
02859         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02860             $sThumbName = basename($this->oxarticles__oxthumb->value);
02861         } else {
02862             if ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 ) && $this->oxarticles__oxpic1->value ) {
02863                 $oPictureHandler = oxPictureHandler::getInstance();
02864                 $sThumbName = $oPictureHandler->getThumbName( $this->oxarticles__oxpic1->value );
02865             } else {
02866                 $sThumbName = "nopic.jpg";
02867             }
02868         }
02869 
02870         return $sThumbName;
02871     }
02872 
02880     public function getZoomPictureUrl( $iIndex = '' )
02881     {
02882         $iIndex = (int) $iIndex;
02883         if ( $iIndex > 0) {
02884             //generating new images if needed
02885             if ( $this->_isFieldEmpty( "oxarticles__oxzoom" . $iIndex ) ) {
02886                 //generating new images if needed
02887                 if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02888                     $this->_generateImages( $iIndex );
02889                 }
02890             }
02891 
02892             $sPic = "z{$iIndex}/" . $this->_getZoomPictureName( $iIndex );
02893 
02894             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02895         }
02896     }
02897 
02905     protected function _getZoomPictureName( $iIndex = '' )
02906     {
02907         $sZoomField = "oxarticles__oxzoom" . $iIndex;
02908 
02909         if ( !$this->_isFieldEmpty( $sZoomField ) ) {
02910             $sZoomName = basename( $this->$sZoomField->value );
02911         } else {
02912             if ( $this->_hasGeneratedImage( $iIndex ) && $this->_hasMasterImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02913                 $oPictureHandler = oxPictureHandler::getInstance();
02914                 $sZoomName = $oPictureHandler->getZoomName( $this->{"oxarticles__oxpic".$iIndex}->value, $iIndex );
02915             } else {
02916                 $sZoomName = "nopic.jpg";
02917             }
02918         }
02919 
02920         return $sZoomName;
02921     }
02922 
02928     public function getFileUrl()
02929     {
02930         return $this->getConfig()->getPictureUrl( '0/' );
02931     }
02932 
02938     public function getPriceFromPrefix()
02939     {
02940         $sPricePrefics = '';
02941         if ( $this->_blIsRangePrice) {
02942             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02943         }
02944 
02945         return $sPricePrefics;
02946     }
02947 
02953     protected function _saveArtLongDesc()
02954     {
02955         $myConfig = $this->getConfig();
02956         $sShopId = $myConfig->getShopID();
02957 
02958         $sValue = $this->getArticleLongDesc()->getRawValue();
02959         $blSave = $sValue !== null;
02960 
02961         if ( $blSave ) {
02962             $oArtExt = oxNew('oxI18n');
02963             $oArtExt->init('oxartextends');
02964             $oArtExt->setLanguage((int) $this->getLanguage());
02965             if (!$oArtExt->load($this->getId())) {
02966                 $oArtExt->setId($this->getId());
02967             }
02968             $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02969             $oArtExt->save();
02970         }
02971     }
02972 
02978     protected function _skipSaveFields()
02979     {
02980         $myConfig = $this->getConfig();
02981 
02982         $this->_aSkipSaveFields = array();
02983 
02984         $this->_aSkipSaveFields[] = 'oxtimestamp';
02985         $this->_aSkipSaveFields[] = 'oxlongdesc';
02986         $this->_aSkipSaveFields[] = 'oxinsert';
02987 
02988         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02989             $this->_aSkipSaveFields[] = 'oxparentid';
02990         }
02991 
02992     }
02993 
03003     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03004     {
03005         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03006             // add prices of the same discounts
03007             if ( array_key_exists ($sKey, $aDiscounts) ) {
03008                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03009             } else {
03010                 $aDiscounts[$sKey] = $oDiscount;
03011             }
03012         }
03013         return $aDiscounts;
03014     }
03015 
03021     protected function _getGroupPrice()
03022     {
03023         $dPrice = $this->oxarticles__oxprice->value;
03024 
03025         $oUser = $this->getArticleUser();
03026         if ( $oUser ) {
03027             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03028                 $dPrice = $this->oxarticles__oxpricea->value;
03029             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03030                 $dPrice = $this->oxarticles__oxpriceb->value;
03031             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03032                 $dPrice = $this->oxarticles__oxpricec->value;
03033             }
03034         }
03035 
03036         // #1437/1436C - added config option, and check for zero A,B,C price values
03037         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03038             $dPrice = $this->oxarticles__oxprice->value;
03039         }
03040 
03041         return $dPrice;
03042     }
03043 
03052     protected function _getAmountPrice($dAmount = 1)
03053     {
03054         $myConfig = $this->getConfig();
03055 
03056         startProfile( "_getAmountPrice" );
03057 
03058         $dPrice = $this->_getGroupPrice();
03059         $oAmtPrices = $this->_getAmountPriceList();
03060         foreach ($oAmtPrices as $oAmPrice) {
03061             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03062                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03063                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03064                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03065             }
03066         }
03067 
03068         stopProfile( "_getAmountPrice" );
03069         return $dPrice;
03070     }
03071 
03080     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03081     {
03082         $myConfig = $this->getConfig();
03083         // #690
03084         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03085 
03086             $aSelLists = $this->getSelectLists();
03087 
03088             foreach ( $aSelLists as $key => $aSel) {
03089                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03090                     $oSel = $aSel[$aChosenList[$key]];
03091                     if ( $oSel->priceUnit =='abs' ) {
03092                         $dPrice += $oSel->price;
03093                     } elseif ( $oSel->priceUnit =='%' ) {
03094                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03095                     }
03096                 }
03097             }
03098         }
03099         return $dPrice;
03100     }
03101 
03102 
03110     protected function _fillAmountPriceList($oAmPriceList)
03111     {
03112         $myConfig = $this->getConfig();
03113         $myUtils  = oxUtils::getInstance();
03114 
03115         //modifying price
03116         $oCur = $myConfig->getActShopCurrencyObject();
03117 
03118         $oUser = $this->getArticleUser();
03119 
03120         $oDiscountList = oxDiscountList::getInstance();
03121         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03122 
03123         $oLowestPrice = null;
03124 
03125         $dBasePrice = $this->_getGroupPrice();
03126         $oLang = oxLang::getInstance();
03127 
03128         $dArticleVat = null;
03129         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03130             $dArticleVat = $this->getArticleVat();
03131         }
03132 
03133         // trying to find lowest price value
03134         foreach ($oAmPriceList as $sId => $oItem) {
03135             $oItemPrice = oxNew( 'oxprice' );
03136             if ( $oItem->oxprice2article__oxaddabs->value) {
03137                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03138                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03139                 $this->_applyCurrency( $oItemPrice, $oCur );
03140             } else {
03141                 $oItemPrice->setPrice( $dBasePrice );
03142                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03143             }
03144 
03145             if (isset($dArticleVat)) {
03146                 $this->_applyVAT($oItemPrice, $dArticleVat);
03147             }
03148 
03149             if (!$oLowestPrice) {
03150                 $oLowestPrice = $oItemPrice;
03151             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03152                 $oLowestPrice = $oItemPrice;
03153             }
03154 
03155             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03156             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03157             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03158         }
03159 
03160         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03161         return $oAmPriceList;
03162     }
03163 
03169     protected function _getVariantsIds()
03170     {
03171         $aSelect = array();
03172         $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->getId()."' " );
03173         if ( $oRs != false && $oRs->recordCount() > 0 ) {
03174             while (!$oRs->EOF) {
03175                 $aSelect[] = $oRs->fields['oxid'];
03176                 $oRs->moveNext();
03177             }
03178         }
03179         return $aSelect;
03180     }
03181 
03187     public function getArticleVat()
03188     {
03189         if (!isset($this->_dArticleVat)) {
03190             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03191         }
03192         return $this->_dArticleVat;
03193     }
03194 
03203     protected function _applyVAT( oxPrice $oPrice, $dVat )
03204     {
03205         startProfile(__FUNCTION__);
03206         $oPrice->setVAT( $dVat );
03207         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03208             $oPrice->setUserVat( $dVat );
03209         }
03210         stopProfile(__FUNCTION__);
03211     }
03212 
03220     public function applyVats( oxPrice $oPrice )
03221     {
03222         $this->_applyVAT($oPrice, $this->getArticleVat() );
03223     }
03224 
03235     protected function _applyDiscounts( $oPrice, $aDiscounts )
03236     {
03237         $oDiscountList = oxDiscountList::getInstance();
03238         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03239     }
03240 
03248     public function applyDiscountsForVariant( $oPrice )
03249     {
03250         // apply discounts
03251         if ( !$this->skipDiscounts() ) {
03252             $oDiscountList = oxDiscountList::getInstance();
03253             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03254         }
03255     }
03256 
03265     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03266     {
03267         if ( !$oCur ) {
03268             $oCur = $this->getConfig()->getActShopCurrencyObject();
03269         }
03270 
03271         $oPrice->multiply($oCur->rate);
03272     }
03273 
03274 
03283     protected function _getAttribsString(&$sAttribs, &$iCnt)
03284     {
03285         // we do not use lists here as we dont need this overhead right now
03286         $oDB = oxDb::getDb(true);
03287         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03288         $sAttribs = '';
03289         $blSep = false;
03290         $rs = $oDB->execute( $sSelect);
03291         $iCnt = 0;
03292         if ($rs != false && $rs->recordCount() > 0) {
03293             while (!$rs->EOF) {
03294                 if ( $blSep) {
03295                     $sAttribs .= ' or ';
03296                 }
03297                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03298                 $blSep = true;
03299                 $iCnt++;
03300                 $rs->moveNext();
03301             }
03302         }
03303     }
03304 
03313     protected function _getSimList($sAttribs, $iCnt)
03314     {
03315         $myConfig = $this->getConfig();
03316         $oDB      = oxDb::getDb(true);
03317 
03318         // #523A
03319         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03320         // 70% same attributes
03321         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03322             $iAttrPercent = 0.70;
03323         }
03324         // #1137V iAttributesPercent = 100 doesnt work
03325         $iHitMin = ceil( $iCnt * $iAttrPercent );
03326 
03327         // we do not use lists here as we dont need this overhead right now
03328         $aList= array();
03329         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03330                     ( $sAttribs )
03331                     and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03332                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03333 
03334         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03335         if ($rs != false && $rs->recordCount() > 0) {
03336             while (!$rs->EOF) {
03337                 $oTemp = new stdClass();    // #663
03338                 $oTemp->cnt = $rs->fields['cnt'];
03339                 $oTemp->id  = $rs->fields['oxobjectid'];
03340                 $aList[] = $oTemp;
03341                 $rs->moveNext();
03342             }
03343         }
03344         return $aList;
03345     }
03346 
03355     protected function _generateSimListSearchStr($sArticleTable, $aList)
03356     {
03357         $myConfig = $this->getConfig();
03358         $sFieldList = $this->getSelectFields();
03359         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03360         $blSep = false;
03361         $iCnt = 0;
03362         $oDb = oxDb::getDb();
03363         foreach ( $aList as $oTemp) {
03364             if ( $blSep) {
03365                 $sSearch .= ',';
03366             }
03367             $sSearch .= $oDb->quote($oTemp->id);
03368             $blSep = true;
03369             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03370                 break;
03371             }
03372             $iCnt++;
03373         }
03374 
03375         //#1741T
03376         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03377         $sSearch .= ') ';
03378 
03379         // #524A -- randomizing articles in attribute list
03380         $sSearch .= ' order by rand() ';
03381 
03382         return $sSearch;
03383     }
03384 
03393     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03394     {
03395 
03396         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03397         $sO2CView = getViewName( 'oxobject2category' );
03398 
03399         // we do not use lists here as we dont need this overhead right now
03400         if ( !$blSearchPriceCat ) {
03401             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03402                          {$sCatView}.oxid = oxobject2category.oxcatnid
03403                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03404         } else {
03405             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03406                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03407                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03408         }
03409         return $sSelect;
03410     }
03411 
03417     protected function _generateSearchStrForCustomerBought()
03418     {
03419         $sArtTable = $this->getViewName();
03420         $sOrderArtTable = getViewName( 'oxorderarticles' );
03421 
03422         // fetching filter params
03423         $sIn = " '{$this->oxarticles__oxid->value}' ";
03424         if ( $this->oxarticles__oxparentid->value ) {
03425 
03426             // adding article parent
03427             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03428             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03429 
03430         } else {
03431             $sParentIdForVariants = $this->getId();
03432         }
03433 
03434         // adding variants
03435         $oDb = oxDb::getDb(true);
03436         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03437         if ( $oRs != false && $oRs->recordCount() > 0) {
03438             while ( !$oRs->EOF ) {
03439                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03440                 $oRs->moveNext();
03441             }
03442         }
03443 
03444         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03445         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03446 
03447         // building sql (optimized)
03448         $sQ = "select distinct {$sArtTable}.* from (
03449                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03450                ) as suborder
03451                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03452                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03453                where {$sArtTable}.oxid not in ( {$sIn} )
03454                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03455 
03456         /* non optimized, but could be used if index forcing is not supported
03457         // building sql
03458         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03459                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03460                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03461                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03462                and ".$this->getSqlActiveSnippet();
03463         */
03464 
03465         return $sQ;
03466     }
03467 
03477     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03478     {
03479         $sCategoryView = getViewName('oxcategories');
03480         $sO2CView = getViewName('oxobject2category');
03481 
03482         $oDb    = oxDb::getDb();
03483         $sOXID  = $oDb->quote($sOXID);
03484         $sCatId = $oDb->quote($sCatId);
03485 
03486         if (!$dPriceFromTo) {
03487             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03488             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03489             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03490             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03491         } else {
03492             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03493             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03494             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03495             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03496         }
03497         return $sSelect;
03498     }
03499 
03505     protected function _getAmountPriceList()
03506     {
03507         if ($this->_oAmountPriceList) {
03508             return $this->_oAmountPriceList;
03509         }
03510 
03511         $myConfig = $this->getConfig();
03512 
03513         $sArtID  = $this->getId();
03514 
03515         // #1690C - Scale prices and variants
03516         if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03517             $sArtID = $this->oxarticles__oxparentid->value;
03518         }
03519 
03520         $sArtID = mysql_real_escape_string($sArtID);
03521 
03522         //collecting assigned to article amount-price list
03523         $oAmPriceList = oxNew( 'oxlist');
03524         $oAmPriceList->init('oxbase', 'oxprice2article');
03525 
03526         $sShopID = $myConfig->getShopID();
03527         if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03528             $sShopSelect = '1';
03529         } else {
03530             $sShopSelect = " oxshopid =  '$sShopID' ";
03531         }
03532 
03533         $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03534 
03535         // prepare abs prices if currently having percentages
03536         $oBasePrice = $this->_getGroupPrice();
03537         foreach ($oAmPriceList as $oAmPrice) {
03538             if ($oAmPrice->oxprice2article__oxaddperc->value) {
03539                 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03540             }
03541         }
03542 
03543         $this->_oAmountPriceList = $oAmPriceList;
03544         return $oAmPriceList;
03545     }
03546 
03554     protected function _isFieldEmpty($sFieldName)
03555     {
03556         $mValue = $this->$sFieldName->value;
03557 
03558         if (is_null($mValue)) {
03559             return true;
03560         }
03561 
03562         if ($mValue === '') {
03563             return true;
03564         }
03565 
03566         $aDoubleCopyFields = array('oxarticles__oxprice',
03567                                        'oxarticles__oxvat');
03568 
03569         if (!$mValue && in_array($sFieldName, $aDoubleCopyFields)) {
03570             return true;
03571         }
03572 
03573 
03574         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03575             return true;
03576         }
03577 
03578         $sFieldName = strtolower($sFieldName);
03579 
03580         if ( $sFieldName == 'oxarticles__oxicon' && strpos($mValue, "nopic_ico.jpg") !== false ) {
03581             return true;
03582         }
03583 
03584         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03585             return true;
03586         }
03587 
03588         return false;
03589     }
03590 
03598     protected function _assignParentFieldValue($sFieldName)
03599     {
03600         if (!($oParentArticle = $this->getParentArticle())) {
03601             return;
03602         }
03603 
03604         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03605 
03606         // assigning only theese which parent article has
03607         if ( $oParentArticle->$sCopyFieldName != null ) {
03608 
03609             // only overwrite database values
03610             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03611                 continue;
03612             }
03613 
03614             //do not copy certain fields
03615             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03616                 return;
03617             }
03618 
03619             //COPY THE VALUE
03620             // assigning images from parent only if variant has no master image (#1807)
03621             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03622                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03623                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03624                 }
03625             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03626                 // for zoom images checking master image with specified index
03627                 // assign from parent only if no pictures to variant are added
03628                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03629                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03630                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03631                 }
03632             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03633                 // if no pics generated for variants, load all from
03634                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03635             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03636                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03637             }
03638         }
03639     }
03640 
03646     public function getParentArticle()
03647     {
03648         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03649             if ( !isset( self::$_aLoadedParents[$sParentId] ) ) {
03650                 self::$_aLoadedParents[$sParentId] = oxNew( 'oxarticle' );
03651                 self::$_aLoadedParents[$sParentId]->_blSkipAbPrice  = true;
03652                 self::$_aLoadedParents[$sParentId]->_blLoadPrice    = false;
03653                 self::$_aLoadedParents[$sParentId]->_blLoadVariants = false;
03654                 self::$_aLoadedParents[$sParentId]->load( $sParentId );
03655             }
03656             return self::$_aLoadedParents[$sParentId];
03657         }
03658     }
03659 
03667     protected function _getParentAricle()
03668     {
03669         return $this->getParentArticle();
03670     }
03671 
03677     protected function _assignParentFieldValues()
03678     {
03679         startProfile('articleAssignParentInternal');
03680         if ( $this->oxarticles__oxparentid->value ) {
03681             // yes, we are in fact a variant
03682             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03683                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03684                     $this->_assignParentFieldValue( $sFieldName );
03685                 }
03686 
03687                 //assing long description
03688                 if ( $this->getArticleLongDesc()->getRawValue() === null ) {
03689                     $this->setArticleLongDesc( $this->getParentArticle()->getArticleLongDesc()->getRawValue() );
03690                 }
03691             }
03692         }
03693         stopProfile('articleAssignParentInternal');
03694     }
03695 
03701     protected function _assignNotBuyableParent()
03702     {
03703         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03704              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03705             $this->_blNotBuyableParent = true;
03706 
03707         }
03708     }
03709 
03715     protected function _assignAllPictureValues()
03716     {
03717         $myConfig = $this->getConfig();
03718 
03719         $this->_assignPictureValues( "oxarticles__oxicon" );
03720         $this->_assignPictureValues( "oxarticles__oxthumb" );
03721 
03722         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03723 
03724         for ( $i=1; $i<= $iPicCount; $i++ ) {
03725             $this->_assignPictureValues( "oxarticles__oxpic".$i );
03726         }
03727 
03728         if ( $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' ) ) {
03729             for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03730                 $this->_assignZoomPictureValues( "oxarticles__oxzoom".$i );
03731             }
03732         }
03733     }
03734 
03742     protected function _assignZoomPictureValues( $sName='' )
03743     {
03744         if ( $this->isAdmin() ) {
03745             return;
03746         }
03747 
03748         $sFieldName = substr_replace( $sName, "", 0, 12);
03749 
03750         $aAllFields = $this->_getAllFields( true );
03751 
03752         if ( isset( $aAllFields[$sFieldName] ) ) {
03753             $this->$sName = parent::__get( $sName );
03754             $this->$sName->value;
03755         }
03756 
03757         $this->_assignParentFieldValue( $sName );
03758 
03759         $iIndex = (int) str_ireplace( "oxzoom", "", $sFieldName );
03760 
03761         if ( isset($this->_aFieldNames[$sFieldName]) || isset($this->_aFieldNames["oxpic".$iIndex]) ) {
03762             if ( $iIndex > 0 ) {
03763                 $this->$sName = new oxField( 'z' . $iIndex.'/'.$this->_getZoomPictureName($iIndex) );
03764             }
03765         }
03766     }
03767 
03775     protected function _assignPictureValues( $sName='' )
03776     {
03777         if ( $this->isAdmin() || !$sName ) {
03778             return;
03779         }
03780 
03781         $sFieldName = substr_replace( $sName, "", 0, 12);
03782         $myConfig = $this->getConfig();
03783 
03784         // add directories
03785         if ( $sFieldName == 'oxicon' && isset($this->_aFieldNames["oxicon"]) ) {
03786             $this->oxarticles__oxicon = new oxField('icon/'.$this->_getIconName());
03787             return;
03788         }
03789 
03790         if ( $sFieldName == 'oxthumb' && isset($this->_aFieldNames["oxthumb"]) ) {
03791             $this->oxarticles__oxthumb = new oxField('0/'.$this->_getThumbnailName());
03792             return;
03793         }
03794 
03795         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03796         if ( strpos($sFieldName, "oxpic") === 0 && isset($this->_aFieldNames[$sFieldName] ) ) {
03797 
03798             $iIndex = (int) str_ireplace( "oxpic", "", $sFieldName );
03799 
03800             if ( $iIndex > 0 && $iIndex < $iPicCount ) {
03801                 $this->$sName = new oxField( $iIndex . '/'.$this->_getPictureName($iIndex) );
03802                 $this->{$sName.'_ico'} = new oxField( $iIndex . '/'.$this->_getIconName($iIndex) );
03803                 return;
03804             }
03805         }
03806     }
03807 
03813     protected function _assignStock()
03814     {
03815         $myConfig = $this->getConfig();
03816         // -----------------------------------
03817         // stock
03818         // -----------------------------------
03819 
03820         // #1125 A. must round (using floor()) value taken from database and cast to int
03821         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03822             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03823         }
03824         //GREEN light
03825         $this->_iStockStatus = 0;
03826 
03827         // if we have flag /*1 or*/ 4 - we show always green light
03828         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03829             //ORANGE light
03830             $iStock = $this->oxarticles__oxstock->value;
03831 
03832             if ($this->_blNotBuyableParent) {
03833                 $iStock = $this->oxarticles__oxvarstock->value;
03834             }
03835 
03836 
03837             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03838                 $this->_iStockStatus = 1;
03839             }
03840 
03841             //RED light
03842             if ($iStock <= 0) {
03843                 $this->_iStockStatus = -1;
03844             }
03845         }
03846 
03847 
03848         // stock
03849         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03850             $iOnStock = $this->oxarticles__oxstock->value;
03851             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03852                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03853             }
03854             if ($iOnStock <= 0) {
03855                 $this->_blNotBuyable = true;
03856             }
03857         }
03858 
03859         //exceptional handling for variant parent stock:
03860         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03861             $this->_blNotBuyable = false;
03862             //but then at least setting notBuaybleParent to true
03863             $this->_blNotBuyableParent = true;
03864         }
03865 
03866         //special treatment for lists when blVariantParentBuyable config option is set to false
03867         //then we just hide "to basket" button.
03868         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03869         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03870             $this->_blNotBuyable = true;
03871         }
03872 
03873         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03874         if ($this->_blNotBuyableParent && count($this->getVariants()) == 0) {
03875             $this->_blNotBuyable = true;
03876         }
03877     }
03878 
03884     protected function _assignPrices()
03885     {
03886         $myConfig = $this->getConfig();
03887 
03888         // Performance
03889         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03890             return;
03891         }
03892 
03893         // compute price
03894         $dPrice = $this->getPrice()->getBruttoPrice();
03895 
03896         $oCur = $myConfig->getActShopCurrencyObject();
03897         //price per unit handling
03898         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03899             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03900         }
03901 
03902 
03903         //getting min and max prices of variants
03904         $this->_applyRangePrice();
03905     }
03906 
03912     protected function _assignPersistentParam()
03913     {
03914         // Persistent Parameter Handling
03915         $aPersParam     = oxSession::getVar( 'persparam');
03916         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03917             $this->_aPersistParam = $aPersParam[$this->getId()];
03918         }
03919     }
03920 
03926     protected function _assignDynImageDir()
03927     {
03928         $myConfig = $this->getConfig();
03929 
03930         $sThisShop = $this->oxarticles__oxshopid->value;
03931 
03932         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03933         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03934         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03935         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03936     }
03937 
03943     protected function _assignComparisonListFlag()
03944     {
03945         // #657 add a flag if article is on comparisonlist
03946 
03947         $aItems = oxSession::getVar('aFiltcompproducts');
03948         if ( isset( $aItems[$this->getId()])) {
03949             $this->_blIsOnComparisonList = true;
03950         }
03951     }
03952 
03958     protected function _assignAttributes()
03959     {
03960         //#1029T load attributes
03961         //#1078S removed check for module "Produktvergleich"
03962         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03963             $this->getAttributes();
03964         }
03965     }
03966 
03967 
03975     protected function _insert()
03976     {
03977         // set oxinsert
03978         $iInsertTime = time();
03979         $now = date('Y-m-d H:i:s', $iInsertTime);
03980         $this->oxarticles__oxinsert    = new oxField( $now );
03981         $this->oxarticles__oxtimestamp = new oxField( $now );
03982         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03983             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03984         }
03985 
03986         return parent::_insert();
03987     }
03988 
03994     protected function _update()
03995     {
03996 
03997         $this->_skipSaveFields();
03998 
03999         $myConfig = $this->getConfig();
04000 
04001 
04002         return parent::_update();
04003     }
04004 
04012     protected function _deleteRecords($sOXID)
04013     {
04014         $oDB = oxDb::getDb();
04015 
04016         $sOXID = $oDB->quote($sOXID);
04017 
04018         //delete the record
04019         $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
04020         $oDB->execute( $sDelete);
04021 
04022         //remove other records
04023         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
04024         $oDB->execute( $sDelete);
04025 
04026         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
04027         $oDB->execute( $sDelete);
04028 
04029         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
04030         $oDB->execute( $sDelete);
04031 
04032         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
04033         $oDB->execute( $sDelete);
04034 
04035         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
04036         $oDB->execute( $sDelete);
04037 
04038         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
04039         $oDB->execute( $sDelete);
04040 
04041         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
04042         $oDB->execute( $sDelete);
04043 
04044         //#1508C - deleting oxobject2delivery entries added
04045         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04046         $oDB->execute( $sDelete);
04047 
04048         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04049         $oDB->execute( $sDelete);
04050 
04051         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04052         $rs = $oDB->execute( $sDelete );
04053 
04054         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04055         $rs = $oDB->execute( $sDelete );
04056 
04057 
04058         return $rs;
04059     }
04060 
04068     protected function _deleteVariantRecords($sOXID)
04069     {
04070         $oDB = oxDb::getDb();
04071         //collect variants to remove recursively
04072         $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDB->quote($sOXID);
04073         $rs = $oDB->execute( $sVariants);
04074         if ($rs != false && $rs->recordCount() > 0) {
04075             while (!$rs->EOF) {
04076                 $this->delete( $rs->fields[0]);
04077                 $rs->moveNext();
04078             }
04079         }
04080     }
04081 
04091     protected function _resetCacheAndArticleCount( $sOxid )
04092     {
04093         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04094     }
04095 
04101     protected function _deletePics()
04102     {
04103         $myUtilsPic = oxUtilsPic::getInstance();
04104         $myConfig   = $this->getConfig();
04105         $oPictureHandler = oxPictureHandler::getInstance();
04106 
04107         //deleting custom main icon
04108         $oPictureHandler->deleteMainIcon( $this );
04109 
04110         //deleting custom thumbnail
04111         $oPictureHandler->deleteThumbnail( $this );
04112 
04113         $sAbsDynImageDir = $myConfig->getPictureDir(false);
04114 
04115         // deleting master image and all generated images
04116         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04117         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04118             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04119         }
04120     }
04121 
04131     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04132     {
04133 
04134         $myUtilsCount = oxUtilsCount::getInstance();
04135 
04136         if ( $sVendorId ) {
04137             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04138         }
04139 
04140         if ( $sManufacturerId ) {
04141             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04142         }
04143 
04144         //also reseting category counts
04145         $oDb = oxDb::getDb();
04146         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04147         $oRs = $oDb->execute( $sQ );
04148         if ( $oRs !== false && $oRs->recordCount() > 0) {
04149             while ( !$oRs->EOF ) {
04150                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04151                 $oRs->moveNext();
04152             }
04153         }
04154     }
04155 
04163     protected function _onChangeUpdateStock( $sParentID )
04164     {
04165         $oDb = oxDb::getDb();
04166         $sParentIdQuoted = $oDb->quote($sParentID);
04167         $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04168         $rs = $oDb->execute($sQ);
04169         $iOldStock = $rs->fields[0];
04170         $iVendorID = $rs->fields[1];
04171         $iManufacturerID = $rs->fields[2];
04172 
04173         $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04174         $iStock = (float) $oDb->getOne( $sQ );
04175 
04176         $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04177         $oDb->execute( $sQ );
04178 
04179             //now lets update category counts
04180             //first detect stock status change for this article (to or from 0)
04181             if ( $iStock < 0 ) {
04182                 $iStock = 0;
04183             }
04184             if ( $iOldStock < 0 ) {
04185                 $iOldStock = 0;
04186             }
04187             if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04188                 //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04189                 // so far we leave it like this but later we could move all count resets to one or two functions
04190                 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04191             }
04192     }
04193 
04201     protected function _onChangeStockResetCount( $sOxid )
04202     {
04203         $myConfig = $this->getConfig();
04204 
04205         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04206            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04207 
04208                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04209         }
04210     }
04211 
04219     protected function _onChangeUpdateVarCount( $sParentID )
04220     {
04221         $oDb = oxDb::getDb();
04222         $sParentIdQuoted = $oDb->quote($sParentID);
04223         $sQ = 'select count(*) as varcount from oxarticles where oxparentid = '.$sParentIdQuoted;
04224         $iVarCount = (int) $oDb->getOne($sQ);
04225 
04226         $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = '.$sParentIdQuoted;
04227         $oDb->execute($sQ);
04228     }
04229 
04237     protected function _onChangeUpdateMinVarPrice( $sParentID )
04238     {
04239         $oDb = oxDb::getDb();
04240         $sParentIdQuoted = $oDb->quote($sParentID);
04241         //#M0000883 (Sarunas)
04242         $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04243         $dVarMinPrice = $oDb->getOne($sQ);
04244 
04245         $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04246 
04247         $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04248 
04249         if ($dVarMinPrice) {
04250             if ($blParentBuyable) {
04251                 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04252             }
04253 
04254         } else {
04255             $dVarMinPrice = $dParentPrice;
04256         }
04257 
04258         if ( $dVarMinPrice ) {
04259             $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04260             $oDb->execute($sQ);
04261         }
04262     }
04263 
04264 
04270     protected function _applyRangePrice()
04271     {
04272         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04273         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04274             return;
04275         }
04276 
04277         $this->_blIsRangePrice = false;
04278 
04279         // if parent is buyable - do not apply range price calcculations
04280         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04281             return;
04282         }
04283 
04284         $aPrices = array();
04285 
04286         if (!$this->_blNotBuyableParent) {
04287             $aPrices[] = $this->getPrice()->getBruttoPrice();
04288         }
04289 
04290         $aVariants = $this->getVariants(false);
04291 
04292         if (count($aVariants)) {
04293             foreach ($aVariants as $sKey => $oVariant) {
04294                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04295             }
04296         }
04297 
04298         /*  $oAmPrices = $this->loadAmountPriceInfo();
04299         foreach ($oAmPrices as $oAmPrice) {
04300             $aPrices[] = $oAmPrice->oxprice2article__oxaddabs->value;
04301         }*/
04302 
04303         if (count($aPrices)) {
04304             $dMinPrice = $aPrices[0];
04305             $dMaxPrice = $aPrices[0];
04306             foreach ($aPrices as $dPrice) {
04307                 if ($dMinPrice > $dPrice) {
04308                     $dMinPrice = $dPrice;
04309                 }
04310 
04311                 if ($dMaxPrice < $dPrice) {
04312                     $dMaxPrice = $dPrice;
04313                 }
04314             }
04315         }
04316 
04317         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04318             $this->getPrice()->setBruttoPriceMode();
04319             $this->getPrice()->setPrice($dMinPrice);
04320         }
04321 
04322         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04323             $this->getPrice()->setBruttoPriceMode();
04324             $this->getPrice()->setPrice($dMinPrice);
04325             $this->_blIsRangePrice = true;
04326         }
04327 
04328         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04329             //#2509 we cannot force brutto price here, as netto price can be added to DB
04330             // $this->getPrice()->setBruttoPriceMode();
04331             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04332             $this->_blIsRangePrice = true;
04333             $this->_calculatePrice( $this->getPrice() );
04334         }
04335     }
04336 
04343     public function getProductId()
04344     {
04345         return $this->getId();
04346     }
04347 
04353     public function getProductParentId()
04354     {
04355         return $this->oxarticles__oxparentid->value;
04356     }
04357 
04363     public function isOrderArticle()
04364     {
04365         return false;
04366     }
04367 
04373     public function isVariant()
04374     {
04375         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04376     }
04377 
04383     public function isMdVariant()
04384     {
04385         $oMdVariant = oxNew( "oxVariantHandler" );
04386 
04387         return $oMdVariant->isMdVariant($this);
04388     }
04389 
04397     public function getSqlForPriceCategories($sFields = '')
04398     {
04399         if (!$sFields) {
04400             $sFields = 'oxid';
04401         }
04402         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04403         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04404         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04405                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04406                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04407     }
04408 
04416     public function inPriceCategory( $sCatNid )
04417     {
04418         $oDb = oxDb::getDb();
04419 
04420         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04421         $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04422         return (bool) $oDb->getOne(
04423             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04424            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04425            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04426            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04427            .")"
04428         );
04429     }
04430 
04436     public function getMdVariants()
04437     {
04438         if ( $this->_oMdVariants ) {
04439             return $this->_oMdVariants;
04440         }
04441 
04442         $oParentArticle = $this->getParentArticle();
04443         if ( $oParentArticle ) {
04444             $oVariants = $oParentArticle->getVariants();
04445         } else {
04446             $oVariants = $this->getVariants();
04447         }
04448 
04449         $oVariantHandler = oxNew( "oxVariantHandler" );
04450         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04451 
04452         return $this->_oMdVariants;
04453     }
04454 
04460     public function getMdSubvariants()
04461     {
04462         return $this->getMdVariants()->getMdSubvariants();
04463     }
04464 
04465 
04474     protected function _generateImages( $iIndex )
04475     {
04476         if ( isset($this->_aFieldNames["oxpic".$iIndex]) && !$this->_hasGeneratedImage( $iIndex ) ) {
04477             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) && $this->_hasMasterImage( $iIndex ) ) {
04478                 $oPictureHandler = oxPictureHandler::getInstance();
04479                 $oPictureHandler->generateArticlePictures( $this, $iIndex );
04480             }
04481         }
04482     }
04483 
04492     public function updateAmountOfGeneratedPictures( $iTotalGenerated )
04493     {
04494         $this->oxarticles__oxpicsgenerated = new oxField( $iTotalGenerated );
04495         $oDb = oxDb::getDb();
04496         $sIdQuoted = $oDb->quote($this->getId());
04497 
04498         $sQ = 'update oxarticles set oxpicsgenerated = '.$iTotalGenerated.' where oxid = '.$sIdQuoted;
04499         $oDb->execute( $sQ );
04500     }
04501 
04510     protected function _hasGeneratedImage( $iIndex )
04511     {
04512         if ( $iIndex > (int) $this->oxarticles__oxpicsgenerated->value ) {
04513             return false;
04514         }
04515 
04516         return true;
04517     }
04518 
04526     protected function _hasMasterImage( $iIndex )
04527     {
04528         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04529 
04530         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04531             return false;
04532         }
04533         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04534             return false;
04535         }
04536 
04537         $sMasterPic = $iIndex . "/" . $sPicName;
04538 
04539         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04540             return true;
04541         }
04542 
04543         return false;
04544     }
04545 
04554     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04555     {
04556         if ( $sFieldName ) {
04557             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04558             return $this->$sFieldName->value;
04559         }
04560     }
04561 
04569     public function getMasterZoomPictureUrl( $iIndex )
04570     {
04571         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04572 
04573         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04574             return false;
04575         }
04576 
04577         $sMasterPicPath = "master/" . $iIndex . "/" . $sPicName;
04578 
04579         if ( $sMasterZoomPicUrl = $this->getConfig()->getPictureUrl( $sMasterPicPath ) ) {
04580             if ( basename( $sMasterZoomPicUrl ) != "nopic.jpg" ) {
04581                 return $sMasterZoomPicUrl;
04582             } else {
04583                 return false;
04584             }
04585         }
04586 
04587         return false;
04588     }
04589 
04590 }