oxarticle.php

Go to the documentation of this file.
00001 <?php
00002 
00003 // defining supported link types
00004 define( 'OXARTICLE_LINKTYPE_CATEGORY', 0 );
00005 define( 'OXARTICLE_LINKTYPE_VENDOR', 1 );
00006 define( 'OXARTICLE_LINKTYPE_MANUFACTURER', 2 );
00007 define( 'OXARTICLE_LINKTYPE_PRICECATEGORY', 3 );
00008 define( 'OXARTICLE_LINKTYPE_TAG', 4 );
00009 define( 'OXARTICLE_LINKTYPE_RECOMM', 5 );
00010 
00017 class oxArticle extends oxI18n implements oxIArticle, oxIUrl
00018 {
00024     protected $_sCoreTbl = 'oxarticles';
00025 
00031     protected $_sClassName = 'oxarticle';
00032 
00038     protected $_blUseLazyLoading = true;
00039 
00045     protected $_sItemKey;
00046 
00052     protected $_blCalcPrice    = true;
00053 
00058     protected $_oPrice      = null;
00059 
00065     protected $_dArticleVat = null;
00066 
00072     protected $_aPersistParam  = null;
00073 
00079     protected $_blNotBuyable   = false;
00080 
00087     protected $_blLoadVariants = true;
00088 
00094     protected $_aVariants = null;
00095 
00101     protected $_aVariantsWithNotOrderables = null;
00102 
00111     protected $_blNotBuyableParent  = false;
00112 
00116     protected $_blHasVariants = false;
00117 
00121     protected $_blHasMdVariants = false;
00122 
00127     protected $_blIsOnComparisonList = false;
00128 
00133     protected $_oUser = null;
00134 
00140     protected $_blLoadPrice = true;
00141 
00145     protected $_blSkipAbPrice = false;
00146 
00153     protected $_fPricePerUnit = null;
00154 
00158     protected $_blLoadParentData = false;
00159 
00163     protected $_blSkipAssign = false;
00164 
00170     protected $_blSkipDiscounts = null;
00171 
00176     protected $_oAttributeList = null;
00177 
00178 
00184     protected $_blIsRangePrice = false;
00185 
00191     protected $_aMediaUrls = null;
00192 
00198     static protected $_aLoadedParents;
00199 
00205     static protected $_aSelList;
00206 
00212     protected $_aDispSelList;
00213 
00219     protected $_blIsSeoObject = true;
00220 
00226     protected $_oAmountPriceList = null;
00227 
00236     protected $_iLinkType = 0;
00237 
00243     protected $_aStdUrls = array();
00244 
00250     protected $_aSeoUrls = array();
00251 
00257     protected $_aSeoAddParams = array();
00258 
00264     protected $_aStdAddParams = array();
00265 
00271     protected $_sDynImageDir = null;
00272 
00278     protected $_sMoreDetailLink = null;
00279 
00285     protected $_sToBasketLink = null;
00286 
00292     protected $_iStockStatus = null;
00293 
00299     protected $_oTPrice = null;
00300 
00306     protected $_oAmountPriceInfo = null;
00307 
00313     protected $_dAmountPrice = null;
00314 
00320     protected static $_aArticleManufacturers = array();
00321 
00327     protected static $_aArticleVendors = array();
00328 
00334     protected static $_aArticleCats = array();
00335 
00341     protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00342                                              'oxarticles__oxtimestamp',
00343                                              'oxarticles__oxnid',
00344                                              'oxarticles__oxid',
00345                                              'oxarticles__oxparentid');
00346 
00352     protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00353                                          'oxarticles__oxfreeshipping',
00354                                          'oxarticles__oxremindactive');
00355 
00361     protected $_oMdVariants = null;
00362 
00368     protected $_oLongDesc = null;
00369 
00377     protected $_aVariantSelections = array();
00378 
00383     protected static $_aSelections = array();
00384 
00389     protected static $_aCategoryCache = null;
00398     public function __construct($aParams = null)
00399     {
00400         if ( $aParams && is_array($aParams)) {
00401             foreach ( $aParams as $sParam => $mValue) {
00402                 $this->$sParam = $mValue;
00403             }
00404         }
00405         parent::__construct();
00406         $this->init( 'oxarticles' );
00407 
00408         $this->_blIsRangePrice = false;
00409     }
00410 
00419     public function __get($sName)
00420     {
00421         $myUtils = oxUtils::getInstance();
00422         // deprecated since 2011.03.10, should be used getArticleLongDesc() / getLongDesc()
00423         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00424             return $this->getArticleLongDesc();
00425         }
00426 
00427         $this->$sName = parent::__get($sName);
00428         if ( $this->$sName ) {
00429             // since the field could have been loaded via lazyloading
00430             $this->_assignParentFieldValue($sName);
00431         }
00432 
00433         return $this->$sName;
00434     }
00435 
00444     public function __set( $sName, $sValue )
00445     {
00446         // deprecated since 2011.03.14, should be used setArticleLongDesc()
00447         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00448             if ($this->_blEmployMultilanguage) {
00449                 $sValue = ( $sValue instanceof oxField ) ? $sValue->getRawValue() : $sValue;
00450                 $this->setArticleLongDesc( $sValue );
00451             } else {
00452                 $this->$sName = $sValue;
00453             }
00454         } else {
00455             parent::__set( $sName, $sValue );
00456         }
00457     }
00458 
00466     public function setId( $sId = null )
00467     {
00468         $sId = parent::setId( $sId );
00469 
00470         // TODO: in oxbase::setId make it to check if exists and update, not recreate, then delete this overload
00471         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00472 
00473         return $sId;
00474     }
00475 
00485     public function getActiveCheckQuery( $blForceCoreTable = null )
00486     {
00487         $sTable = $this->getViewName( $blForceCoreTable );
00488 
00489         // check if article is still active
00490         $sQ = " $sTable.oxactive = 1 ";
00491 
00492         // enabled time range check ?
00493         if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00494             $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00495             $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00496         }
00497 
00498         return $sQ;
00499     }
00500 
00514     public function getStockCheckQuery( $blForceCoreTable = null )
00515     {
00516         $myConfig = $this->getConfig();
00517         $sTable = $this->getViewName( $blForceCoreTable );
00518 
00519         $sQ = "";
00520 
00521         //do not check for variants
00522         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00523             $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0  ) ";
00524             //V #M513: When Parent article is not purchaseble, it's visibility should be displayed in shop only if any of Variants is available.
00525             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00526                 $sTimeCheckQ = '';
00527                 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00528                      $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00529                      $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00530                 }
00531                 $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 ) ) ";
00532             }
00533         }
00534 
00535         return $sQ;
00536     }
00537 
00549     public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null  )
00550     {
00551         $sTable = $this->getViewName( $blForceCoreTable );
00552         $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00553 
00554         //checking if variant is active and stock status
00555         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00556             $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00557             if ( $blRemoveNotOrderables ) {
00558                 $sQ .= " and $sTable.oxstockflag != 3 ";
00559             }
00560             $sQ .= " ) ) ";
00561         }
00562 
00563         return $sQ;
00564     }
00565 
00573     public function getSqlActiveSnippet( $blForceCoreTable = null )
00574     {
00575         $myConfig = $this->getConfig();
00576 
00577         // check if article is still active
00578         $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00579 
00580         // stock and variants check
00581         $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00582 
00583 
00584         return "( $sQ ) ";
00585     }
00586 
00594     public function setSkipAssign($blSkipAssign)
00595     {
00596         $this->_blSkipAssign = $blSkipAssign;
00597     }
00598 
00604     public function disablePriceLoad()
00605     {
00606         $this->_blLoadPrice = false;
00607     }
00608 
00614     public function getItemKey()
00615     {
00616         return $this->_sItemKey;
00617     }
00618 
00626     public function setItemKey($sItemKey)
00627     {
00628         $this->_sItemKey = $sItemKey;
00629     }
00630 
00638     public function setNoVariantLoading( $blLoadVariants )
00639     {
00640         $this->_blLoadVariants = !$blLoadVariants;
00641     }
00642 
00648     public function isBuyable()
00649     {
00650         if ($this->_blNotBuyableParent) {
00651             return false;
00652         }
00653 
00654         return !$this->_blNotBuyable;
00655     }
00656 
00662     public function getPersParams()
00663     {
00664         return $this->_aPersistParam;
00665     }
00666 
00672     public function isOnComparisonList()
00673     {
00674         return $this->_blIsOnComparisonList;
00675     }
00676 
00684     public function setOnComparisonList( $blOnList )
00685     {
00686         $this->_blIsOnComparisonList = $blOnList;
00687     }
00688 
00696     public function setLoadParentData($blLoadParentData)
00697     {
00698         $this->_blLoadParentData = $blLoadParentData;
00699     }
00700 
00708     public function setSkipAbPrice( $blSkipAbPrice = null )
00709     {
00710         $this->_blSkipAbPrice = $blSkipAbPrice;
00711     }
00712 
00720     public function getSearchableFields()
00721     {
00722         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00723         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00724 
00725         return $aFields;
00726     }
00727 
00728 
00736     public function isMultilingualField($sFieldName)
00737     {
00738         switch ($sFieldName) {
00739             case "oxlongdesc":
00740             case "oxtags":
00741                 return true;
00742         }
00743 
00744         return parent::isMultilingualField($sFieldName);
00745     }
00746 
00752     public function isVisible()
00753     {
00754 
00755         // admin preview mode
00756         if ( ( $blCanPreview = oxUtils::getInstance()->canPreview() ) !== null ) {
00757             return $blCanPreview;
00758         }
00759 
00760         // active ?
00761         $sNow = date('Y-m-d H:i:s');
00762         if ( !$this->oxarticles__oxactive->value &&
00763              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00764                 $this->oxarticles__oxactiveto->value < $sNow
00765              )) {
00766             return false;
00767         }
00768 
00769         // stock flags
00770         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00771             $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00772             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00773                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00774             }
00775             if ( $iOnStock <= 0 ) {
00776                 return false;
00777             }
00778         }
00779 
00780         return true;
00781     }
00782 
00791     public function assign( $aRecord)
00792     {
00793         startProfile('articleAssign');
00794 
00795 
00796         // load object from database
00797         parent::assign( $aRecord);
00798 
00799         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00800 
00801         // check for simple article.
00802         if ($this->_blSkipAssign) {
00803             return;
00804         }
00805 
00806         $this->_assignParentFieldValues();
00807         $this->_assignNotBuyableParent();
00808 
00809         $this->_assignStock();
00810         startProfile('articleAssignPrices');
00811         $this->_assignPrices();
00812         stopProfile('articleAssignPrices');
00813         $this->_assignPersistentParam();
00814         $this->_assignDynImageDir();
00815         $this->_assignComparisonListFlag();
00816         $this->_assignAttributes();
00817 
00818 
00819         //$this->_seoAssign();
00820 
00821         stopProfile('articleAssign');
00822     }
00823 
00834     public function load( $oxID)
00835     {
00836         // A. #1325 resetting to avoid problems when reloading (details etc)
00837         $this->_blNotBuyableParent = false;
00838 
00839         $blRet = parent::load( $oxID);
00840 
00841         // convert date's to international format
00842         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00843         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00844 
00845         return $blRet;
00846     }
00847 
00855     public function addToRatingAverage( $iRating)
00856     {
00857         $dOldRating = $this->oxarticles__oxrating->value;
00858         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00859         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00860         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00861         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00862         $dRatingCnt = (int) ($dOldCnt + 1);
00863         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00864         $oDb = oxDb::getDb();
00865         $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00866     }
00867 
00873     public function getArticleRatingAverage()
00874     {
00875         return round( $this->oxarticles__oxrating->value, 1);
00876     }
00877 
00883     public function getReviews()
00884     {
00885         $aIds = array($this->getId());
00886 
00887         if ( $this->oxarticles__oxparentid->value ) {
00888             $aIds[] = $this->oxarticles__oxparentid->value;
00889         }
00890 
00891         // showing variant reviews ..
00892         if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00893             $aAdd = $this->_getVariantsIds();
00894             if (is_array($aAdd)) {
00895                 $aIds = array_merge($aIds, $aAdd);
00896             }
00897         }
00898 
00899         $oReview = oxNew('oxreview');
00900         $oRevs = $oReview->loadList('oxarticle', $aIds);
00901 
00902         //if no review found, return null
00903         if ( $oRevs->count() < 1 ) {
00904             return null;
00905         }
00906 
00907         return $oRevs;
00908     }
00909 
00915     public function getCrossSelling()
00916     {
00917         $oCrosslist = oxNew( "oxarticlelist");
00918         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00919         if ( $oCrosslist->count() ) {
00920             return $oCrosslist;
00921         }
00922     }
00923 
00929     public function getAccessoires()
00930     {
00931         $myConfig = $this->getConfig();
00932 
00933         // Performance
00934         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00935             return;
00936         }
00937 
00938         $oAcclist = oxNew( "oxarticlelist");
00939         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00940         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00941 
00942         if ( $oAcclist->count()) {
00943             return $oAcclist;
00944         }
00945     }
00946 
00952     public function getSimilarProducts()
00953     {
00954         // Performance
00955         $myConfig = $this->getConfig();
00956         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
00957             return;
00958         }
00959 
00960         $sArticleTable = $this->getViewName();
00961 
00962         $sAttribs = '';
00963         $iCnt = 0;
00964         $this->_getAttribsString($sAttribs, $iCnt);
00965 
00966         if ( !$sAttribs) {
00967             return null;
00968         }
00969 
00970         $aList = $this->_getSimList($sAttribs, $iCnt);
00971 
00972         if ( count( $aList ) ) {
00973             uasort( $aList, 'cmpart');
00974 
00975             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
00976 
00977             $oSimilarlist = oxNew( 'oxarticlelist' );
00978             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
00979             $oSimilarlist->selectString( $sSearch);
00980 
00981             return $oSimilarlist;
00982         }
00983     }
00984 
00990     public function getCustomerAlsoBoughtThisProducts()
00991     {
00992         // Performance
00993         $myConfig = $this->getConfig();
00994         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
00995             return;
00996         }
00997 
00998         // selecting products that fits
00999         $sQ = $this->_generateSearchStrForCustomerBought();
01000 
01001         $oArticles = oxNew( 'oxarticlelist' );
01002         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01003         $oArticles->selectString( $sQ );
01004         if ( $oArticles->count() ) {
01005             return $oArticles;
01006         }
01007     }
01008 
01015     public function loadAmountPriceInfo()
01016     {
01017         $myConfig = $this->getConfig();
01018         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01019             return array();
01020         }
01021 
01022         if ( $this->_oAmountPriceInfo === null ) {
01023             $this->_oAmountPriceInfo = array();
01024             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01025                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01026 
01027             }
01028         }
01029         return $this->_oAmountPriceInfo;
01030     }
01031 
01039     public function getSelectLists($sKeyPrefix = null)
01040     {
01041         //#1468C - more then one article in basket with different selectlist...
01042         //optionall function parameter $sKeyPrefix added, used only in basket.php
01043         $sKey = $this->getId();
01044         if ( isset( $sKeyPrefix ) ) {
01045             $sKey = $sKeyPrefix.'__'.$this->getId();
01046         }
01047 
01048         if ( !isset( self::$_aSelList[$sKey] ) ) {
01049             $oDb = oxDb::getDb();
01050             $sSLViewName = getViewName( 'oxselectlist' );
01051 
01052             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01053                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01054 
01055             // all selectlists this article has
01056             $oLists = oxNew( 'oxlist' );
01057             $oLists->init( 'oxselectlist' );
01058             $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01059 
01060             //#1104S if this is variant ant it has no selectlists, trying with parent
01061             if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01062                 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01063             }
01064 
01065             $dVat = 0;
01066             if ( $this->getPrice() != null ) {
01067                 $dVat = $this->getPrice()->getVat();
01068             }
01069 
01070             $iCnt = 0;
01071             self::$_aSelList[$sKey] = array();
01072             foreach ( $oLists as $oSelectlist ) {
01073                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01074                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01075                 $iCnt++;
01076             }
01077         }
01078         return self::$_aSelList[$sKey];
01079     }
01080 
01088     protected function _hasAnyVariant( $blForceCoreTable = null )
01089     {
01090         $blHas = false;
01091         if ( ( $sId = $this->getId() ) ) {
01092             $sArticleTable = $this->getViewName( $blForceCoreTable );
01093             $oDb = oxDb::getDb();
01094             $blHas = (bool) $oDb->getOne( "select 1 from $sArticleTable where oxparentid=".$oDb->quote( $sId ) );
01095         }
01096         return $blHas;
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 ( $this->oxarticles__oxvarcount->value ) {
01124                 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $this->getVariants(), $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 
01199     protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01200     {
01201         $oVariants = array();
01202         if ( ( $sId = $this->getId() ) ) {
01203             //do not load me as a parent later
01204             self::$_aLoadedParents[$sId] = $this;
01205 
01206             $myConfig = $this->getConfig();
01207 
01208             if ( !$this->_blLoadVariants ||
01209                 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01210                 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01211                 return $oVariants;
01212             }
01213 
01214             // cache
01215             $sCacheKey = $blSimple ? "simple" : "full";
01216             if ( $blRemoveNotOrderables ) {
01217                 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01218                    return $this->_aVariants[$sCacheKey];
01219                 } else {
01220                     $this->_aVariants[$sCacheKey] = & $oVariants;
01221                 }
01222             } elseif ( !$blRemoveNotOrderables ) {
01223                 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01224                     return $this->_aVariantsWithNotOrderables[$sCacheKey];
01225                 } else {
01226                     $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01227                 }
01228             }
01229 
01230             if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01231 
01232                 //load simple variants for lists
01233                 if ( $blSimple ) {
01234                     $oVariants = oxNew( 'oxsimplevariantlist' );
01235                     $oVariants->setParent( $this );
01236                 } else {
01237                     //loading variants
01238                     $oVariants = oxNew( 'oxarticlelist' );
01239                     $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01240                 }
01241 
01242                 startProfile("selectVariants");
01243                 $blUseCoreTable = (bool) $blForceCoreTable;
01244                 $oBaseObject = $oVariants->getBaseObject();
01245                 $oBaseObject->setLanguage( $this->getLanguage() );
01246 
01247 
01248                 $sArticleTable = $this->getViewName( $blUseCoreTable );
01249 
01250                 $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01251                            $this->getActiveCheckQuery( $blUseCoreTable ) .
01252                            $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01253                            " order by $sArticleTable.oxsort";
01254 
01255                 $oVariants->selectString( $sSelect );
01256 
01257                 //if this is multidimensional variants, make additional processing
01258                 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01259                     $oMdVariants = oxNew( "oxVariantHandler" );
01260                     $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01261                 }
01262                 stopProfile("selectVariants");
01263             }
01264 
01265             //if we have variants then depending on config option the parent may be non buyable
01266             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01267                 $this->_blNotBuyableParent = true;
01268             }
01269 
01270             //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01271             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01272                 $this->_blNotBuyable = true;
01273             }
01274         }
01275         return $oVariants;
01276     }
01277 
01286     public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01287     {
01288         return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01289     }
01290 
01299     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null  )
01300     {
01301         return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01302     }
01303 
01309     public function getSimpleVariants()
01310     {
01311         if ( $this->oxarticles__oxvarcount->value) {
01312             return $this->getVariants();
01313         }
01314     }
01315 
01324     public function getAdminVariants( $sLanguage = null )
01325     {
01326         $oVariants = oxNew( 'oxarticlelist');
01327         if ( ( $sId = $this->getId() ) ) {
01328 
01329             $oBaseObj = $oVariants->getBaseObject();
01330 
01331             if ( is_null( $sLanguage ) ) {
01332                 $oBaseObj->setLanguage( oxLang::getInstance()->getBaseLanguage() );
01333             } else {
01334                 $oBaseObj->setLanguage( $sLanguage );
01335             }
01336 
01337             $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01338             $oVariants->selectString( $sSql );
01339 
01340             //if we have variants then depending on config option the parent may be non buyable
01341             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01342                 //$this->blNotBuyable = true;
01343                 $this->_blNotBuyableParent = true;
01344             }
01345         }
01346 
01347         return $oVariants;
01348     }
01349 
01357     public function getCategory()
01358     {
01359         $oCategory = oxNew( 'oxcategory' );
01360         $oCategory->setLanguage( $this->getLanguage() );
01361 
01362         // variant handling
01363         $sOXID = $this->getId();
01364         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01365             $sOXID = $this->oxarticles__oxparentid->value;
01366         }
01367 
01368         if ( $sOXID ) {
01369             // if the oxcategory instance of this article is not cached
01370             if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01371                 startPRofile( 'getCategory' );
01372                 $oStr = getStr();
01373                 $sWhere   = $oCategory->getSqlActiveSnippet();
01374                 $sSelect  = $this->_generateSearchStr( $sOXID );
01375                 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01376 
01377                 // category not found ?
01378                 if ( !$oCategory->assignRecord( $sSelect ) ) {
01379 
01380                     $sSelect  = $this->_generateSearchStr( $sOXID, true );
01381                     $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01382 
01383                     // looking for price category
01384                     if ( !$oCategory->assignRecord( $sSelect ) ) {
01385                         $oCategory = null;
01386                     }
01387                 }
01388                 // add the category instance to cache
01389                 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01390                 stopPRofile( 'getCategory' );
01391             } else {
01392                // if the oxcategory instance is cached
01393                $oCategory = $this->_aCategoryCache[ $sOXID ];
01394             }
01395         }
01396 
01397         return $oCategory;
01398     }
01399 
01408     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01409     {
01410         $myConfig = $this->getConfig();
01411         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01412             return self::$_aArticleCats[$this->getId()];
01413         }
01414 
01415         // variant handling
01416         $sOXID = $this->getId();
01417         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01418             $sOXID = $this->oxarticles__oxparentid->value;
01419         }
01420 
01421         // we do not use lists here as we dont need this overhead right now
01422         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01423         $oDB = oxDb::getDb(true);
01424         $rs = $oDB->execute( $sSql );
01425 
01426 
01427         $aRet = array();
01428 
01429         if ($rs != false && $rs->recordCount() > 0) {
01430             while (!$rs->EOF) {
01431                 $aRet[] = $rs->fields['oxcatnid'];
01432                 $rs->moveNext();
01433             }
01434         }
01435 
01436         // adding price categories if such exists
01437         $sSql = $this->getSqlForPriceCategories();
01438 
01439         $oDB = oxDb::getDb( true );
01440         $rs = $oDB->execute( $sSql );
01441 
01442         if ($rs != false && $rs->recordCount() > 0) {
01443             while (!$rs->EOF) {
01444 
01445                 if ( is_array( $rs->fields ) ) {
01446                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01447                 }
01448 
01449 
01450                 if ( !$aRet[$rs->fields['oxid']] ) {
01451                     $aRet[] = $rs->fields['oxid'];
01452                 }
01453                 $rs->moveNext();
01454             }
01455         }
01456 
01457         return self::$_aArticleCats[$this->getId()] = $aRet;
01458     }
01459 
01468     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01469     {
01470         $sO2CView = $this->_getObjectViewName('oxobject2category');
01471         $sCatView = $this->_getObjectViewName('oxcategories');
01472         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01473         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01474         if ( $blActCats ) {
01475             $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 ";
01476         }
01477         $sSelect .= 'order by oxobject2category.oxtime ';
01478         return $sSelect;
01479     }
01480 
01490     public function getVendor( $blShopCheck = true )
01491     {
01492         if ( ( $sVendorId = $this->getVendorId() ) ) {
01493             $oVendor = oxNew( 'oxvendor' );
01494         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01495                 $oVendor = oxNew( 'oxi18n' );
01496                 $oVendor->init('oxvendor');
01497                 $oVendor->setReadOnly( true );
01498             $sVendorId = $this->oxarticles__oxvendorid->value;
01499         }
01500         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01501             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01502                 $oVendor->setReadOnly( true );
01503             }
01504             return $oVendor;
01505         }
01506         return null;
01507     }
01508 
01516     public function getVendorId( $blForceReload = false )
01517     {
01518         $sVendorId = false;
01519         if ( $this->oxarticles__oxvendorid->value ) {
01520                 $sVendorId = $this->oxarticles__oxvendorid->value;
01521 
01522         }
01523         return $sVendorId;
01524     }
01525 
01533     public function getManufacturerId( $blForceReload = false )
01534     {
01535         $sManufacturerId = false;
01536         if ( $this->oxarticles__oxmanufacturerid->value ) {
01537 
01538                 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01539 
01540         }
01541         return $sManufacturerId;
01542     }
01543 
01553     public function getManufacturer( $blShopCheck = true )
01554     {
01555             $oManufacturer = oxNew( 'oxmanufacturer' );;
01556         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01557              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01558             $oManufacturer->setReadOnly( true );
01559             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01560         }
01561 
01562         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01563             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01564                 $oManufacturer->setReadOnly( true );
01565             }
01566             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01567         } else {
01568             $oManufacturer = null;
01569         }
01570 
01571         return $oManufacturer;
01572     }
01573 
01581     public function inCategory( $sCatNid)
01582     {
01583         return in_array( $sCatNid, $this->getCategoryIds());
01584     }
01585 
01594     public function isAssignedToCategory( $sCatId )
01595     {
01596         // variant handling
01597         $sOXID = $this->getId();
01598         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01599             $sOXID = $this->oxarticles__oxparentid->value;
01600         }
01601 
01602         $oDB = oxDb::getDb();
01603         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01604         $sOXID = $oDB->getOne( $sSelect);
01605         // article is assigned to passed category!
01606         if ( isset( $sOXID) && $sOXID) {
01607             return true;
01608         }
01609 
01610         // maybe this category is price category ?
01611         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01612             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01613             if ( $dPriceFromTo > 0) {
01614                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01615                 $sOXID = $oDB->getOne( $sSelect);
01616                 // article is assigned to passed category!
01617                 if ( isset( $sOXID) && $sOXID) {
01618                     return true;
01619                 }
01620             }
01621         }
01622         return false;
01623     }
01624 
01630     public function getTPrice()
01631     {
01632         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01633             return;
01634         }
01635         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01636         if ( $this->_oTPrice !== null ) {
01637             return $this->_oTPrice;
01638         }
01639 
01640         $this->_oTPrice = oxNew( 'oxPrice' );
01641         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01642 
01643         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01644         $this->_applyCurrency( $this->_oTPrice );
01645 
01646         return $this->_oTPrice;
01647     }
01648 
01654     public function skipDiscounts()
01655     {
01656         // allready loaded skip discounts config
01657         if ( $this->_blSkipDiscounts !== null )
01658             return $this->_blSkipDiscounts;
01659 
01660         if ( $this->oxarticles__oxskipdiscounts->value )
01661             return true;
01662 
01663         $oDb = oxDb::getDb();
01664         $sO2CView  = getViewName( 'oxobject2category', $this->getLanguage() );
01665         $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01666         $sSelect =  "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01667                      where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01668         return $this->_blSkipDiscounts = ( $oDb->getOne($sSelect) == 1 );
01669     }
01670 
01678     public function setPrice(oxPrice $oPrice)
01679     {
01680         $this->_oPrice = $oPrice;
01681     }
01682 
01691     public function getBasePrice( $dAmount = 1 )
01692     {
01693         // override this function if you want e.g. different prices
01694         // for diff. usergroups.
01695 
01696         // Performance
01697         $myConfig = $this->getConfig();
01698         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01699             return;
01700 
01701         // GroupPrice or DB price ajusted by AmountPrice
01702         $dPrice = $this->_getAmountPrice( $dAmount );
01703 
01704 
01705         return $dPrice;
01706     }
01707 
01715     public function getPrice( $dAmount = 1 )
01716     {
01717         $myConfig = $this->getConfig();
01718         // Performance
01719         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01720             return;
01721         }
01722 
01723         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01724         if ( $dAmount != 1 || $this->_oPrice === null ) {
01725             $oPrice = oxNew( 'oxPrice' );
01726 
01727             // get base
01728             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01729 
01730             // price handling
01731             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01732                 return $this->_oPrice = $oPrice;
01733             }
01734 
01735             $this->_calculatePrice( $oPrice );
01736             if ( $dAmount != 1 ) {
01737                 return $oPrice;
01738             }
01739 
01740             $this->_oPrice = $oPrice;
01741         }
01742         return $this->_oPrice;
01743     }
01744 
01753     protected function _calculatePrice( $oPrice, $dVat = null )
01754     {
01755         // apply VAT only if configuration requires it
01756         if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01757             $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01758         }
01759 
01760         // apply currency
01761         $this->_applyCurrency( $oPrice );
01762         // apply discounts
01763         if ( !$this->skipDiscounts() ) {
01764             $oDiscountList = oxDiscountList::getInstance();
01765             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
01766         }
01767 
01768         return $oPrice;
01769     }
01770 
01778     public function setArticleUser($oUser)
01779     {
01780         $this->_oUser = $oUser;
01781     }
01782 
01788     public function getArticleUser()
01789     {
01790         if ($this->_oUser) {
01791             return $this->_oUser;
01792         }
01793         return $this->getUser();
01794     }
01795 
01805     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01806     {
01807         $oUser = $oBasket->getBasketUser();
01808         $this->setArticleUser( $oUser );
01809 
01810         $oBasketPrice = oxNew( 'oxPrice' );
01811 
01812         // get base price
01813         $dBasePrice = $this->getBasePrice( $dAmount );
01814 
01815         // applying select list price
01816         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01817 
01818         // setting price
01819         $oBasketPrice->setPrice( $dBasePrice );
01820 
01821         $dVat = oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket );
01822         $this->_calculatePrice( $oBasketPrice, $dVat );
01823 
01824         // returning final price object
01825         return $oBasketPrice;
01826     }
01827 
01840     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01841     {
01842         $oDiscountList = oxDiscountList::getInstance();
01843         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01844     }
01845 
01854     public function delete( $sOXID = null )
01855     {
01856         if ( !$sOXID ) {
01857             $sOXID = $this->getId();
01858         }
01859         if ( !$sOXID ) {
01860             return false;
01861         }
01862 
01863 
01864         // #2339 delete first variants before deleting parent product
01865         $this->_deleteVariantRecords( $sOXID );
01866         $this->load( $sOXID );
01867         $this->_deletePics();
01868         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01869 
01870         // delete self
01871         parent::delete( $sOXID );
01872 
01873         $rs = $this->_deleteRecords( $sOXID );
01874 
01875         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01876 
01877         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01878 
01879         return $rs->EOF;
01880     }
01881 
01890     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01891     {
01892         $this->beforeUpdate();
01893 
01894         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01895         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01896             $dAmount += $iStockCount;
01897             $iStockCount = 0;
01898         }
01899         $this->oxarticles__oxstock = new oxField($iStockCount);
01900 
01901         $oDb = oxDb::getDb();
01902         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01903         $this->onChange( ACTION_UPDATE_STOCK );
01904         return $dAmount;
01905     }
01906 
01915     public function updateSoldAmount( $dAmount = 0 )
01916     {
01917         if ( !$dAmount ) {
01918             return;
01919         }
01920 
01921         $this->beforeUpdate();
01922 
01923         // article is not variant - should be updated current amount
01924         if ( !$this->oxarticles__oxparentid->value ) {
01925             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01926             $dAmount = (double) $dAmount;
01927             $oDb = oxDb::getDb();
01928             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01929         } elseif ( $this->oxarticles__oxparentid->value) {
01930             // article is variant - should be updated this article parent amount
01931             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01932             $oUpdateArticle->updateSoldAmount( $dAmount );
01933         }
01934 
01935         $this->onChange( ACTION_UPDATE );
01936 
01937         return $rs;
01938     }
01939 
01945     public function disableReminder()
01946     {
01947         $oDB = oxDb::getDb(true);
01948         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01949     }
01950 
01958     public function save()
01959     {
01960         // @deprecated since 20110821. folders are no more written, getters must be user for urls
01961         $this->oxarticles__oxthumb = new oxField( basename( $this->oxarticles__oxthumb->value ), oxField::T_RAW );
01962         $this->oxarticles__oxicon  = new oxField( basename( $this->oxarticles__oxicon->value ), oxField::T_RAW );
01963         $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
01964         for ( $i = 1; $i <= $iPicCount; $i++ ) {
01965             $sFieldName = 'oxarticles__oxpic' . $i;
01966             if ( isset( $this->$sFieldName ) ) {
01967                 $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );
01968             }
01969         }
01970         // @end deprecated
01971 
01972         if ( ( $blRet = parent::save() ) ) {
01973             // saving long descrition
01974             $this->_saveArtLongDesc();
01975         }
01976 
01977         return $blRet;
01978     }
01979 
01980 
01987     public function getPictureGallery()
01988     {
01989         $myConfig = $this->getConfig();
01990 
01991         //initialize
01992         $blMorePic = false;
01993         $aArtPics  = array();
01994         $aArtIcons = array();
01995         $iActPicId = 1;
01996         $sActPic = $this->getPictureUrl( $iActPicId );
01997 
01998         if ( oxConfig::getParameter( 'actpicid' ) ) {
01999             $iActPicId = oxConfig::getParameter('actpicid');
02000         }
02001 
02002         $oStr = getStr();
02003         $iCntr = 0;
02004         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02005         $blCheckActivePicId = true;
02006 
02007         for ( $i = 1; $i <= $iPicCount; $i++) {
02008             $sPicVal = $this->getPictureUrl( $i );
02009             $sIcoVal = $this->getIconUrl( $i );
02010             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02011                  !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02012                 if ($iCntr) {
02013                     $blMorePic = true;
02014                 }
02015                 $aArtIcons[$i]= $sIcoVal;
02016                 $aArtPics[$i]= $sPicVal;
02017                 $iCntr++;
02018 
02019                 if ($iActPicId == $i) {
02020                     $sActPic = $sPicVal;
02021                     $blCheckActivePicId = false;
02022                 }
02023 
02024             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02025                 // if picture is empty, setting active pic id to next
02026                 // picture
02027                 $iActPicId++;
02028             }
02029         }
02030 
02031         $blZoomPic  = false;
02032         $aZoomPics = array();
02033         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02034 
02035         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02036             $sVal = $this->getZoomPictureUrl($j);
02037 
02038             if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02039                 $blZoomPic = true;
02040                 $aZoomPics[$c]['id'] = $c;
02041                 $aZoomPics[$c]['file'] = $sVal;
02042                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02043                 if (!$sVal) {
02044                     $aZoomPics[$c]['file'] = "nopic.jpg";
02045                 }
02046                 $c++;
02047             }
02048         }
02049 
02050         $aPicGallery = array('ActPicID' => $iActPicId,
02051                              'ActPic' => $sActPic,
02052                              'MorePics' => $blMorePic,
02053                              'Pics' => $aArtPics,
02054                              'Icons' => $aArtIcons,
02055                              'ZoomPic' => $blZoomPic,
02056                              'ZoomPics' => $aZoomPics);
02057 
02058         return $aPicGallery;
02059     }
02060 
02074     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02075     {
02076         $myConfig = $this->getConfig();
02077 
02078         if (!isset($sOXID)) {
02079             if ( $this->getId()) {
02080                 $sOXID = $this->getId();
02081             }
02082             if (!isset ($sOXID)) {
02083                 $sOXID = $this->oxarticles__oxid->value;
02084             }
02085             if ($this->oxarticles__oxparentid->value) {
02086                 $sParentID = $this->oxarticles__oxparentid->value;
02087             }
02088         }
02089         if (!isset($sOXID)) {
02090             return;
02091         }
02092 
02093         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02094         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02095             //if article has variants then updating oxvarstock field
02096             //getting parent id
02097             if (!isset($sParentID)) {
02098                 $oDb = oxDb::getDb();
02099                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02100                 $sParentID = $oDb->getOne($sQ);
02101             }
02102             //if we have parent id then update stock
02103             if ($sParentID) {
02104                 $this->_onChangeUpdateStock($sParentID);
02105             }
02106         }
02107         //if we have parent id then update count
02108         //update count even if blUseStock is not active
02109         if ($sParentID) {
02110             $this->_onChangeUpdateVarCount($sParentID);
02111         }
02112 
02113         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02114         $this->_onChangeUpdateMinVarPrice( $sId );
02115 
02116             // reseting articles count cache if stock has changed and some
02117             // articles goes offline (M:1448)
02118             if ( $sAction === ACTION_UPDATE_STOCK ) {
02119                 $this->_onChangeStockResetCount( $sOXID );
02120             }
02121 
02122     }
02123 
02130     public function getCustomVAT()
02131     {
02132         if ( isset($this->oxarticles__oxvat->value) ) {
02133             return $this->oxarticles__oxvat->value;
02134         }
02135     }
02136 
02145     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02146     {
02147         $myConfig = $this->getConfig();
02148         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02149             return true;
02150         }
02151 
02152         $oDb = oxDb::getDb(true);
02153         // fetching DB info as its up-to-date
02154         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.oxDb::getDb(true)->quote( $this->getId() );
02155         $rs = oxDb::getDb(true)->execute( $sQ );
02156 
02157         $iOnStock   = 0;
02158         $iStockFlag = 0;
02159         if ( $rs !== false && $rs->recordCount() > 0 ) {
02160             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02161             $iStockFlag = $rs->fields['oxstockflag'];
02162 
02163             // dodger : fremdlager is also always considered as on stock
02164             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02165                 return true;
02166             }
02167             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02168                 $iOnStock = floor( $iOnStock );
02169             }
02170         }
02171         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02172             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02173         }
02174         if ( $iOnStock >= $dAmount ) {
02175             return true;
02176         } else {
02177             if ( $iOnStock > 0 ) {
02178                 return $iOnStock;
02179             } else {
02180                 $oEx = oxNew( 'oxArticleInputException' );
02181                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02182                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02183                 return false;
02184             }
02185         }
02186     }
02187 
02188 
02196     public function getArticleLongDesc( $sOxid = null )
02197     {
02198         if ( $this->_oLongDesc === null ) {
02199 
02200             // initializing
02201             $this->_oLongDesc = new oxField();
02202 
02203 
02204             // choosing which to get..
02205             $sOxid = $sOxid === null ? $this->getId() : $sOxid;
02206             $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02207             if ( ( $sDbValue = oxDb::getDb()->getOne( "select oxlongdesc from {$sViewName} where oxid = ?", array( $sOxid ) ) ) !== false ) {
02208                 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02209             }
02210         }
02211 
02212         return $this->_oLongDesc;
02213     }
02214 
02224     protected function _setLongDesc( $sDbValue )
02225     {
02226         $this->setArticleLongDesc( $sDbValue );
02227     }
02228 
02235     public function getLongDesc()
02236     {
02237         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getArticleLongDesc()->getRawValue(), $this->getId().$this->getLanguage() );
02238     }
02239 
02248     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02249     {
02250 
02251         // setting current value
02252         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02253 
02254         // setting original value?
02255         if ( $sOrigValue ) {
02256             $this->_oLongDesc->orignalValue = $sOrigValue;
02257         }
02258     }
02259 
02265     public function getAttributes()
02266     {
02267         if ( $this->_oAttributeList === null ) {
02268             $this->_oAttributeList = oxNew( 'oxattributelist' );
02269             $this->_oAttributeList->loadAttributes( $this->getId() );
02270         }
02271 
02272         return $this->_oAttributeList;
02273     }
02274 
02283     public function appendLink( $sAddParams, $iLang = null )
02284     {
02285         if ( $sAddParams ) {
02286             if ( $iLang === null ) {
02287                 $iLang = $this->getLanguage();
02288             }
02289 
02290             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02291             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02292         }
02293     }
02294 
02303     public function getBaseSeoLink( $iLang, $blMain = false )
02304     {
02305         $oEncoder = oxSeoEncoderArticle::getInstance();
02306         if ( !$blMain ) {
02307             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02308         }
02309         return $oEncoder->getArticleMainUrl( $this, $iLang );
02310     }
02311 
02320     public function getLink( $iLang = null, $blMain = false  )
02321     {
02322         if ( !oxUtils::getInstance()->seoIsActive() ) {
02323             return $this->getStdLink( $iLang );
02324         }
02325 
02326         if ( $iLang === null ) {
02327             $iLang = $this->getLanguage();
02328         }
02329 
02330         $iLinkType = $this->getLinkType();
02331         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02332             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02333         }
02334 
02335         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02336         if ( isset($this->_aSeoAddParams[$iLang])) {
02337             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02338         }
02339 
02340         return $sUrl;
02341     }
02342 
02351     public function getMainLink( $iLang = null )
02352     {
02353         return $this->getLink( $iLang, true );
02354     }
02355 
02363     public function setLinkType( $iType )
02364     {
02365         // resetting detaisl link, to force new
02366         $this->_sDetailLink = null;
02367 
02368         // setting link type
02369         $this->_iLinkType = (int) $iType;
02370     }
02371 
02377     public function getLinkType()
02378     {
02379         return $this->_iLinkType;
02380     }
02381 
02390     public function appendStdLink( $sAddParams, $iLang = null )
02391     {
02392         if ( $sAddParams ) {
02393             if ( $iLang === null ) {
02394                 $iLang = $this->getLanguage();
02395             }
02396 
02397             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02398             $this->_aStdAddParams[$iLang] .= $sAddParams;
02399         }
02400     }
02401 
02411     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02412     {
02413         $sUrl = '';
02414         if ( $blFull ) {
02415             //always returns shop url, not admin
02416             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02417         }
02418 
02419         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02420         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02421     }
02422 
02431     public function getStdLink( $iLang = null, $aParams = array() )
02432     {
02433         if ( $iLang === null ) {
02434             $iLang = $this->getLanguage();
02435         }
02436 
02437         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02438             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02439         }
02440 
02441         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02442     }
02443 
02451     public function getStdTagLink( $sTag )
02452     {
02453         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02454         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02455     }
02456 
02462     public function getTags()
02463     {
02464         $oDb = oxDb::getDb();
02465         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02466         $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02467         $oTagCloud = oxNew('oxtagcloud');
02468         return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02469     }
02470 
02478     public function saveTags($sTags)
02479     {
02480         //do not allow derived update
02481         if ( !$this->allowDerivedUpdate() ) {
02482             return false;
02483         }
02484 
02485 
02486         $oTagCloud = oxNew( 'oxtagcloud' );
02487         $oTagCloud->resetTagCache();
02488         $sTags = mysql_real_escape_string( $oTagCloud->prepareTags( $sTags ) );
02489         $oDb = oxDb::getDb();
02490 
02491         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02492         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02493         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02494                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02495         return $oDb->execute( $sQ );
02496     }
02497 
02505     public function addTag($sTag)
02506     {
02507         $oDb = oxDb::getDb();
02508 
02509         $oTagCloud = oxNew('oxtagcloud');
02510         $oTagCloud->resetTagCache();
02511         $sTag = $oTagCloud->prepareTags($sTag);
02512         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02513 
02514         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02515         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02516         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02517             $sTailTag = $sTagSeparator . $sTag;
02518         } else {
02519             $sTailTag = $sTag;
02520         }
02521 
02522         $sTag = mysql_real_escape_string($sTag);
02523         $sTailTag = mysql_real_escape_string($sTailTag);
02524 
02525         $sTag = mysql_real_escape_string($sTag);
02526         $sTailTag = mysql_real_escape_string($sTailTag);
02527 
02528         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02529                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02530 
02531         return $oDb->execute( $sQ );
02532     }
02533 
02539     public function getMediaUrls()
02540     {
02541         if ( $this->_aMediaUrls === null ) {
02542             $this->_aMediaUrls = oxNew("oxlist");
02543             $this->_aMediaUrls->init("oxmediaurl");
02544             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02545 
02546             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02547             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02548             $this->_aMediaUrls->selectString($sQ);
02549         }
02550         return $this->_aMediaUrls;
02551     }
02552 
02558     public function getDynImageDir()
02559     {
02560         return $this->_sDynImageDir;
02561     }
02562 
02568     public function getDispSelList()
02569     {
02570         if ($this->_aDispSelList === null) {
02571             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02572                 $this->_aDispSelList = $this->getSelectLists();
02573             }
02574         }
02575         return $this->_aDispSelList;
02576     }
02577 
02583     public function getMoreDetailLink()
02584     {
02585         if ( $this->_sMoreDetailLink == null ) {
02586 
02587             // and assign special article values
02588             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02589 
02590             // not always it is okey, as not all the time active category is the same as primary article cat.
02591             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02592                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02593             }
02594             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02595             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02596         }
02597 
02598         return $this->_sMoreDetailLink;
02599     }
02600 
02606     public function getToBasketLink()
02607     {
02608         if ( $this->_sToBasketLink == null ) {
02609             $myConfig = $this->getConfig();
02610 
02611             if ( oxUtils::getInstance()->isSearchEngine() ) {
02612                 $this->_sToBasketLink = $this->getLink();
02613             } else {
02614                 // and assign special article values
02615                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02616 
02617                 // override some classes as these should never showup
02618                 $sActClass = oxConfig::getParameter( 'cl' );
02619                 if ( $sActClass == 'thankyou') {
02620                     $sActClass = 'basket';
02621                 }
02622                 $this->_sToBasketLink .= 'cl='.$sActClass;
02623 
02624                 // this is not very correct
02625                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02626                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02627                 }
02628 
02629                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02630 
02631                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02632                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02633                 }
02634             }
02635         }
02636 
02637         return $this->_sToBasketLink;
02638     }
02639 
02645     public function getStockStatus()
02646     {
02647         return $this->_iStockStatus;
02648     }
02649 
02655     public function getDeliveryDate()
02656     {
02657         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02658             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02659         }
02660         return false;
02661     }
02662 
02668     public function getFTPrice()
02669     {
02670         if ( $oPrice = $this->getTPrice() ) {
02671             if ( $oPrice->getBruttoPrice() ) {
02672                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02673             }
02674         }
02675     }
02676 
02682     public function getFPrice()
02683     {
02684         if ( $oPrice = $this->getPrice() ) {
02685             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02686         }
02687     }
02688 
02694     public function getFNetPrice()
02695     {
02696         if ( $oPrice = $this->getPrice() ) {
02697             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02698         }
02699     }
02700 
02706     public function getPricePerUnit()
02707     {
02708         return $this->_fPricePerUnit;
02709     }
02710 
02716     public function isParentNotBuyable()
02717     {
02718         return $this->_blNotBuyableParent;
02719     }
02720 
02726     public function isNotBuyable()
02727     {
02728         return $this->_blNotBuyable;
02729     }
02730 
02738     public function setBuyableState( $blBuyable = false )
02739     {
02740         $this->_blNotBuyable = !$blBuyable;
02741     }
02742 
02751     public function getVariantList()
02752     {
02753         return $this->getVariants();
02754     }
02755 
02763     public function setSelectlist( $aSelList )
02764     {
02765         $this->_aDispSelList = $aSelList;
02766     }
02767 
02775     public function getPictureUrl( $iIndex = 1 )
02776     {
02777         if ( $iIndex ) {
02778             $sImgName = false;
02779             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02780                 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02781             }
02782 
02783             $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02784             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02785         }
02786     }
02787 
02796     public function getIconUrl( $iIndex = 0 )
02797     {
02798         $sImgName = false;
02799         $sDirname = "product/1/";
02800         if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02801             $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02802             $sDirname = "product/{$iIndex}/";
02803         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02804             $sImgName = basename( $this->oxarticles__oxicon->value );
02805             $sDirname = "product/icon/";
02806         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02807             $sImgName = basename( $this->oxarticles__oxpic1->value );
02808         }
02809 
02810         $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02811         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02812     }
02813 
02819     public function getThumbnailUrl()
02820     {
02821         $sImgName = false;
02822         $sDirname = "product/1/";
02823         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02824             $sImgName = basename( $this->oxarticles__oxthumb->value );
02825             $sDirname = "product/thumb/";
02826         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02827             $sImgName = basename( $this->oxarticles__oxpic1->value );
02828         }
02829 
02830         $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02831         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0 );
02832     }
02833 
02841     public function getZoomPictureUrl( $iIndex = '' )
02842     {
02843         $iIndex = (int) $iIndex;
02844         if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02845             $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02846             $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02847             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02848         }
02849     }
02850 
02856     public function getFileUrl()
02857     {
02858         return $this->getConfig()->getPictureUrl( 'media/' );
02859     }
02860 
02866     public function getPriceFromPrefix()
02867     {
02868         $sPricePrefics = '';
02869         if ( $this->_blIsRangePrice) {
02870             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02871         }
02872 
02873         return $sPricePrefics;
02874     }
02875 
02881     protected function _saveArtLongDesc()
02882     {
02883         $myConfig = $this->getConfig();
02884         $sShopId = $myConfig->getShopID();
02885         if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02886             return;
02887         }
02888 
02889         if ($this->_blEmployMultilanguage) {
02890             $sValue = $this->getArticleLongDesc()->getRawValue();
02891             if ( $sValue !== null ) {
02892                 $oArtExt = oxNew('oxI18n');
02893                 $oArtExt->init('oxartextends');
02894                 $oArtExt->setLanguage((int) $this->getLanguage());
02895                 if (!$oArtExt->load($this->getId())) {
02896                     $oArtExt->setId($this->getId());
02897                 }
02898                 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02899                 $oArtExt->save();
02900             }
02901         } else {
02902             $oArtExt = oxNew('oxI18n');
02903             $oArtExt->setEnableMultilang(false);
02904             $oArtExt->init('oxartextends');
02905             $aObjFields = $oArtExt->_getAllFields(true);
02906             if (!$oArtExt->load($this->getId())) {
02907                 $oArtExt->setId($this->getId());
02908             }
02909 
02910             foreach ($aObjFields as $sKey => $sValue ) {
02911                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02912                     $sField = $this->_getFieldLongName($sKey);
02913 
02914                     if (isset($this->$sField)) {
02915                         $sLongDesc = null;
02916                         if ($this->$sField instanceof oxField) {
02917                             $sLongDesc = $this->$sField->getRawValue();
02918                         } elseif (is_object($this->$sField)) {
02919                             $sLongDesc = $this->$sField->value;
02920                         }
02921                         if (isset($sLongDesc)) {
02922                             $sAEField = $oArtExt->_getFieldLongName($sKey);
02923                             $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
02924                         }
02925                     }
02926                 }
02927             }
02928             $oArtExt->save();
02929         }
02930     }
02931 
02937     protected function _skipSaveFields()
02938     {
02939         $myConfig = $this->getConfig();
02940 
02941         $this->_aSkipSaveFields = array();
02942 
02943         $this->_aSkipSaveFields[] = 'oxtimestamp';
02944        // $this->_aSkipSaveFields[] = 'oxlongdesc';
02945         $this->_aSkipSaveFields[] = 'oxinsert';
02946 
02947         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02948             $this->_aSkipSaveFields[] = 'oxparentid';
02949         }
02950 
02951     }
02952 
02962     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02963     {
02964         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02965             // add prices of the same discounts
02966             if ( array_key_exists ($sKey, $aDiscounts) ) {
02967                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02968             } else {
02969                 $aDiscounts[$sKey] = $oDiscount;
02970             }
02971         }
02972         return $aDiscounts;
02973     }
02974 
02980     protected function _getGroupPrice()
02981     {
02982         $dPrice = $this->oxarticles__oxprice->value;
02983 
02984         $oUser = $this->getArticleUser();
02985         if ( $oUser ) {
02986             if ( $oUser->inGroup( 'oxidpricea' ) ) {
02987                 $dPrice = $this->oxarticles__oxpricea->value;
02988             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
02989                 $dPrice = $this->oxarticles__oxpriceb->value;
02990             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
02991                 $dPrice = $this->oxarticles__oxpricec->value;
02992             }
02993         }
02994 
02995         // #1437/1436C - added config option, and check for zero A,B,C price values
02996         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
02997             $dPrice = $this->oxarticles__oxprice->value;
02998         }
02999 
03000         return $dPrice;
03001     }
03002 
03011     protected function _getAmountPrice($dAmount = 1)
03012     {
03013         $myConfig = $this->getConfig();
03014 
03015         startProfile( "_getAmountPrice" );
03016 
03017         $dPrice = $this->_getGroupPrice();
03018         $oAmtPrices = $this->_getAmountPriceList();
03019         foreach ($oAmtPrices as $oAmPrice) {
03020             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03021                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03022                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03023                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03024             }
03025         }
03026 
03027         stopProfile( "_getAmountPrice" );
03028         return $dPrice;
03029     }
03030 
03039     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03040     {
03041         $myConfig = $this->getConfig();
03042         // #690
03043         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03044 
03045             $aSelLists = $this->getSelectLists();
03046 
03047             foreach ( $aSelLists as $key => $aSel) {
03048                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03049                     $oSel = $aSel[$aChosenList[$key]];
03050                     if ( $oSel->priceUnit =='abs' ) {
03051                         $dPrice += $oSel->price;
03052                     } elseif ( $oSel->priceUnit =='%' ) {
03053                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03054                     }
03055                 }
03056             }
03057         }
03058         return $dPrice;
03059     }
03060 
03061 
03069     protected function _fillAmountPriceList($oAmPriceList)
03070     {
03071         $myConfig = $this->getConfig();
03072         $myUtils  = oxUtils::getInstance();
03073 
03074         //modifying price
03075         $oCur = $myConfig->getActShopCurrencyObject();
03076 
03077         $oUser = $this->getArticleUser();
03078 
03079         $oDiscountList = oxDiscountList::getInstance();
03080         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03081 
03082         $oLowestPrice = null;
03083 
03084         $dBasePrice = $this->_getGroupPrice();
03085         $oLang = oxLang::getInstance();
03086 
03087         $dArticleVat = null;
03088         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03089             $dArticleVat = $this->getArticleVat();
03090         }
03091 
03092         // trying to find lowest price value
03093         foreach ($oAmPriceList as $sId => $oItem) {
03094             $oItemPrice = oxNew( 'oxprice' );
03095             if ( $oItem->oxprice2article__oxaddabs->value) {
03096                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03097                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03098                 $this->_applyCurrency( $oItemPrice, $oCur );
03099             } else {
03100                 $oItemPrice->setPrice( $dBasePrice );
03101                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03102             }
03103 
03104             if (isset($dArticleVat)) {
03105                 $this->_applyVAT($oItemPrice, $dArticleVat);
03106             }
03107 
03108             if (!$oLowestPrice) {
03109                 $oLowestPrice = $oItemPrice;
03110             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03111                 $oLowestPrice = $oItemPrice;
03112             }
03113 
03114             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03115             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03116             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03117         }
03118 
03119         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03120         return $oAmPriceList;
03121     }
03122 
03128     protected function _getVariantsIds()
03129     {
03130         $aSelect = array();
03131         if ( ( $sId = $this->getId() ) ) {
03132             $oDb = oxDb::getDb(true);
03133             $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03134                    $this->getSqlActiveSnippet( true );
03135 
03136             $oRs = $oDb->execute( $sQ );
03137             if ( $oRs != false && $oRs->recordCount() > 0 ) {
03138                 while (!$oRs->EOF) {
03139                     $aSelect[] = reset( $oRs->fields );
03140                     $oRs->moveNext();
03141                 }
03142             }
03143         }
03144         return $aSelect;
03145     }
03146 
03152     public function getArticleVat()
03153     {
03154         if (!isset($this->_dArticleVat)) {
03155             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03156         }
03157         return $this->_dArticleVat;
03158     }
03159 
03168     protected function _applyVAT( oxPrice $oPrice, $dVat )
03169     {
03170         startProfile(__FUNCTION__);
03171         $oPrice->setVAT( $dVat );
03172         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03173             $oPrice->setUserVat( $dVat );
03174         }
03175         stopProfile(__FUNCTION__);
03176     }
03177 
03185     public function applyVats( oxPrice $oPrice )
03186     {
03187         $this->_applyVAT($oPrice, $this->getArticleVat() );
03188     }
03189 
03200     protected function _applyDiscounts( $oPrice, $aDiscounts )
03201     {
03202         $oDiscountList = oxDiscountList::getInstance();
03203         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03204     }
03205 
03213     public function applyDiscountsForVariant( $oPrice )
03214     {
03215         // apply discounts
03216         if ( !$this->skipDiscounts() ) {
03217             $oDiscountList = oxDiscountList::getInstance();
03218             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03219         }
03220     }
03221 
03230     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03231     {
03232         if ( !$oCur ) {
03233             $oCur = $this->getConfig()->getActShopCurrencyObject();
03234         }
03235 
03236         $oPrice->multiply($oCur->rate);
03237     }
03238 
03239 
03248     protected function _getAttribsString(&$sAttribs, &$iCnt)
03249     {
03250         // we do not use lists here as we dont need this overhead right now
03251         $oDB = oxDb::getDb(true);
03252         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDB->quote( $this->getId() );
03253         $sAttribs = '';
03254         $blSep = false;
03255         $rs = $oDB->execute( $sSelect);
03256         $iCnt = 0;
03257         if ($rs != false && $rs->recordCount() > 0) {
03258             while (!$rs->EOF) {
03259                 if ( $blSep) {
03260                     $sAttribs .= ' or ';
03261                 }
03262                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03263                 $blSep = true;
03264                 $iCnt++;
03265                 $rs->moveNext();
03266             }
03267         }
03268     }
03269 
03278     protected function _getSimList($sAttribs, $iCnt)
03279     {
03280         $myConfig = $this->getConfig();
03281         $oDB      = oxDb::getDb(true);
03282 
03283         // #523A
03284         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03285         // 70% same attributes
03286         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03287             $iAttrPercent = 0.70;
03288         }
03289         // #1137V iAttributesPercent = 100 doesnt work
03290         $iHitMin = ceil( $iCnt * $iAttrPercent );
03291 
03292         // we do not use lists here as we dont need this overhead right now
03293         $aList= array();
03294         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03295                     ( $sAttribs )
03296                     and t1.oxobjectid != ".$oDB->quote( $this->oxarticles__oxid->value )."
03297                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03298 
03299         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03300         if ($rs != false && $rs->recordCount() > 0) {
03301             while (!$rs->EOF) {
03302                 $oTemp = new stdClass();    // #663
03303                 $oTemp->cnt = $rs->fields['cnt'];
03304                 $oTemp->id  = $rs->fields['oxobjectid'];
03305                 $aList[] = $oTemp;
03306                 $rs->moveNext();
03307             }
03308         }
03309         return $aList;
03310     }
03311 
03320     protected function _generateSimListSearchStr($sArticleTable, $aList)
03321     {
03322         $myConfig = $this->getConfig();
03323         $sFieldList = $this->getSelectFields();
03324         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03325         $blSep = false;
03326         $iCnt = 0;
03327         $oDb = oxDb::getDb();
03328         foreach ( $aList as $oTemp) {
03329             if ( $blSep) {
03330                 $sSearch .= ',';
03331             }
03332             $sSearch .= $oDb->quote($oTemp->id);
03333             $blSep = true;
03334             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03335                 break;
03336             }
03337             $iCnt++;
03338         }
03339 
03340         //#1741T
03341         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03342         $sSearch .= ') ';
03343 
03344         // #524A -- randomizing articles in attribute list
03345         $sSearch .= ' order by rand() ';
03346 
03347         return $sSearch;
03348     }
03349 
03358     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03359     {
03360 
03361         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03362         $sO2CView = getViewName( 'oxobject2category' );
03363 
03364         // we do not use lists here as we dont need this overhead right now
03365         if ( !$blSearchPriceCat ) {
03366             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03367                          {$sCatView}.oxid = oxobject2category.oxcatnid
03368                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03369         } else {
03370             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03371                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03372                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03373         }
03374         return $sSelect;
03375     }
03376 
03382     protected function _generateSearchStrForCustomerBought()
03383     {
03384         $sArtTable = $this->getViewName();
03385         $sOrderArtTable = getViewName( 'oxorderarticles' );
03386 
03387         // fetching filter params
03388         $sIn = " '{$this->oxarticles__oxid->value}' ";
03389         if ( $this->oxarticles__oxparentid->value ) {
03390 
03391             // adding article parent
03392             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03393             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03394 
03395         } else {
03396             $sParentIdForVariants = $this->getId();
03397         }
03398 
03399         // adding variants
03400         $oDb = oxDb::getDb(true);
03401         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03402         if ( $oRs != false && $oRs->recordCount() > 0) {
03403             while ( !$oRs->EOF ) {
03404                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03405                 $oRs->moveNext();
03406             }
03407         }
03408 
03409         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03410         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03411 
03412         // building sql (optimized)
03413         $sQ = "select distinct {$sArtTable}.* from (
03414                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03415                ) as suborder
03416                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03417                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03418                where {$sArtTable}.oxid not in ( {$sIn} )
03419                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03420 
03421         /* non optimized, but could be used if index forcing is not supported
03422         // building sql
03423         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03424                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03425                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03426                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03427                and ".$this->getSqlActiveSnippet();
03428         */
03429 
03430         return $sQ;
03431     }
03432 
03442     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03443     {
03444         $sCategoryView = getViewName('oxcategories');
03445         $sO2CView = getViewName('oxobject2category');
03446 
03447         $oDb    = oxDb::getDb();
03448         $sOXID  = $oDb->quote($sOXID);
03449         $sCatId = $oDb->quote($sCatId);
03450 
03451         if (!$dPriceFromTo) {
03452             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03453             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03454             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03455             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03456         } else {
03457             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03458             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03459             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03460             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03461         }
03462         return $sSelect;
03463     }
03464 
03470     protected function _getAmountPriceList()
03471     {
03472         if ( $this->_oAmountPriceList === null ) {
03473             $this->_oAmountPriceList = array();
03474             if ( !$this->skipDiscounts() ) {
03475                 $myConfig = $this->getConfig();
03476                 $sArtId   = $this->getId();
03477 
03478                 // #1690C - Scale prices and variants
03479                 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03480                     $sArtId = $this->oxarticles__oxparentid->value;
03481                 }
03482 
03483                 //collecting assigned to article amount-price list
03484                 $oAmPriceList = oxNew( 'oxlist' );
03485                 $oAmPriceList->init( 'oxbase', 'oxprice2article' );
03486 
03487                 $sShopID = $myConfig->getShopID();
03488                 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03489                     $sShopSelect = '1';
03490                 } else {
03491                     $sShopSelect = " oxshopid =  '$sShopID' ";
03492                 }
03493 
03494                 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = " . oxDb::getDb()->quote( $sArtId ) . " and $sShopSelect order by oxamount ");
03495 
03496                 // prepare abs prices if currently having percentages
03497                 $oBasePrice = $this->_getGroupPrice();
03498                 foreach ( $oAmPriceList as $oAmPrice ) {
03499                     if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03500                         $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03501                     }
03502                 }
03503 
03504                 $this->_oAmountPriceList = $oAmPriceList;
03505             }
03506         }
03507 
03508         return $this->_oAmountPriceList;
03509     }
03510 
03518     protected function _isFieldEmpty( $sFieldName )
03519     {
03520         $mValue = $this->$sFieldName->value;
03521 
03522         if ( is_null( $mValue ) ) {
03523             return true;
03524         }
03525 
03526         if ( $mValue === '' ) {
03527             return true;
03528         }
03529 
03530         $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03531 
03532         if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03533             return true;
03534         }
03535 
03536 
03537         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03538             return true;
03539         }
03540 
03541         $sFieldName = strtolower($sFieldName);
03542 
03543         if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03544             return true;
03545         }
03546 
03547         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03548             return true;
03549         }
03550 
03551         return false;
03552     }
03553 
03561     protected function _assignParentFieldValue($sFieldName)
03562     {
03563         if (!($oParentArticle = $this->getParentArticle())) {
03564             return;
03565         }
03566 
03567         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03568 
03569         // assigning only theese which parent article has
03570         if ( $oParentArticle->$sCopyFieldName != null ) {
03571 
03572             // only overwrite database values
03573             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03574                 return;
03575             }
03576 
03577             //do not copy certain fields
03578             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03579                 return;
03580             }
03581 
03582             //COPY THE VALUE
03583             // assigning images from parent only if variant has no master image (#1807)
03584             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03585                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03586                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03587                 }
03588             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03589                 // for zoom images checking master image with specified index
03590                 // assign from parent only if no pictures to variant are added
03591                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03592                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03593                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03594                 }
03595             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03596                 // if no pics generated for variants, load all from
03597                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03598             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03599                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03600             }
03601         }
03602     }
03603 
03609     public function getParentArticle()
03610     {
03611         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03612             $sIndex = $sParentId . "_" . $this->getLanguage();
03613             if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03614                 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03615                 self::$_aLoadedParents[$sIndex]->_blSkipAbPrice  = true;
03616                 self::$_aLoadedParents[$sIndex]->_blLoadPrice    = false;
03617                 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03618                 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03619             }
03620             return self::$_aLoadedParents[$sIndex];
03621         }
03622     }
03623 
03631     protected function _getParentAricle()
03632     {
03633         return $this->getParentArticle();
03634     }
03635 
03641     protected function _assignParentFieldValues()
03642     {
03643         startProfile('articleAssignParentInternal');
03644         if ( $this->oxarticles__oxparentid->value ) {
03645             // yes, we are in fact a variant
03646             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03647                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03648                     $this->_assignParentFieldValue( $sFieldName );
03649                 }
03650 
03651                 //assing long description
03652                 $sLongDesc = $this->getArticleLongDesc()->getRawValue();
03653                 if ( $sLongDesc === null || $sLongDesc == '' ) {
03654                     $this->setArticleLongDesc( $this->getParentArticle()->getArticleLongDesc()->getRawValue() );
03655                 }
03656             }
03657         }
03658         stopProfile('articleAssignParentInternal');
03659     }
03660 
03666     protected function _assignNotBuyableParent()
03667     {
03668         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03669              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03670             $this->_blNotBuyableParent = true;
03671 
03672         }
03673     }
03674 
03680     protected function _assignStock()
03681     {
03682         $myConfig = $this->getConfig();
03683         // -----------------------------------
03684         // stock
03685         // -----------------------------------
03686 
03687         // #1125 A. must round (using floor()) value taken from database and cast to int
03688         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03689             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03690         }
03691         //GREEN light
03692         $this->_iStockStatus = 0;
03693 
03694         // if we have flag /*1 or*/ 4 - we show always green light
03695         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03696             //ORANGE light
03697             $iStock = $this->oxarticles__oxstock->value;
03698 
03699             if ($this->_blNotBuyableParent) {
03700                 $iStock = $this->oxarticles__oxvarstock->value;
03701             }
03702 
03703 
03704             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03705                 $this->_iStockStatus = 1;
03706             }
03707 
03708             //RED light
03709             if ($iStock <= 0) {
03710                 $this->_iStockStatus = -1;
03711             }
03712         }
03713 
03714 
03715         // stock
03716         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03717             $iOnStock = $this->oxarticles__oxstock->value;
03718             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03719                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03720             }
03721             if ($iOnStock <= 0) {
03722                 $this->_blNotBuyable = true;
03723             }
03724         }
03725 
03726         //exceptional handling for variant parent stock:
03727         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03728             $this->_blNotBuyable = false;
03729             //but then at least setting notBuaybleParent to true
03730             $this->_blNotBuyableParent = true;
03731         }
03732 
03733         //special treatment for lists when blVariantParentBuyable config option is set to false
03734         //then we just hide "to basket" button.
03735         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03736         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03737             $this->_blNotBuyable = true;
03738         }
03739 
03740         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03741         if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03742             $this->_blNotBuyable = true;
03743         }
03744     }
03745 
03751     protected function _assignPrices()
03752     {
03753         $myConfig = $this->getConfig();
03754 
03755         // Performance
03756         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03757             return;
03758         }
03759 
03760         // compute price
03761         $dPrice = $this->getPrice()->getBruttoPrice();
03762 
03763         $oCur = $myConfig->getActShopCurrencyObject();
03764         //price per unit handling
03765         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03766             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03767         }
03768 
03769         //getting min and max prices of variants
03770         if ( $this->_hasAnyVariant() ) {
03771             $this->_applyRangePrice();
03772         }
03773     }
03774 
03780     protected function _assignPersistentParam()
03781     {
03782         // Persistent Parameter Handling
03783         $aPersParam     = oxSession::getVar( 'persparam');
03784         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03785             $this->_aPersistParam = $aPersParam[$this->getId()];
03786         }
03787     }
03788 
03794     protected function _assignDynImageDir()
03795     {
03796         $myConfig = $this->getConfig();
03797 
03798         $sThisShop = $this->oxarticles__oxshopid->value;
03799 
03800         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03801         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03802         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03803         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03804     }
03805 
03811     protected function _assignComparisonListFlag()
03812     {
03813         // #657 add a flag if article is on comparisonlist
03814 
03815         $aItems = oxSession::getVar('aFiltcompproducts');
03816         if ( isset( $aItems[$this->getId()])) {
03817             $this->_blIsOnComparisonList = true;
03818         }
03819     }
03820 
03826     protected function _assignAttributes()
03827     {
03828         //#1029T load attributes
03829         //#1078S removed check for module "Produktvergleich"
03830         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03831             $this->getAttributes();
03832         }
03833     }
03834 
03835 
03843     protected function _insert()
03844     {
03845         // set oxinsert
03846         $iInsertTime = time();
03847         $now = date('Y-m-d H:i:s', $iInsertTime);
03848         $this->oxarticles__oxinsert    = new oxField( $now );
03849         $this->oxarticles__oxtimestamp = new oxField( $now );
03850         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03851             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03852         }
03853 
03854         return parent::_insert();
03855     }
03856 
03862     protected function _update()
03863     {
03864 
03865         $this->_skipSaveFields();
03866 
03867         $myConfig = $this->getConfig();
03868 
03869 
03870         return parent::_update();
03871     }
03872 
03880     protected function _deleteRecords($sOXID)
03881     {
03882         $oDB = oxDb::getDb();
03883 
03884         $sOXID = $oDB->quote($sOXID);
03885 
03886         //remove other records
03887         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03888         $oDB->execute( $sDelete);
03889 
03890         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03891         $oDB->execute( $sDelete);
03892 
03893         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03894         $oDB->execute( $sDelete);
03895 
03896         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03897         $oDB->execute( $sDelete);
03898 
03899         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03900         $oDB->execute( $sDelete);
03901 
03902         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03903         $oDB->execute( $sDelete);
03904 
03905         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03906         $oDB->execute( $sDelete);
03907 
03908         //#1508C - deleting oxobject2delivery entries added
03909         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03910         $oDB->execute( $sDelete);
03911 
03912         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03913         $oDB->execute( $sDelete);
03914 
03915         //delete the record
03916         foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03917             $oDB->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03918         }
03919 
03920         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03921         $rs = $oDB->execute( $sDelete );
03922 
03923         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03924         $rs = $oDB->execute( $sDelete );
03925 
03926 
03927         return $rs;
03928     }
03929 
03937     protected function _deleteVariantRecords( $sOXID )
03938     {
03939         if ( $sOXID ) {
03940             $oDb = oxDb::getDb();
03941             //collect variants to remove recursively
03942             $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03943             $rs = $oDb->execute( $sQ );
03944             if ($rs != false && $rs->recordCount() > 0) {
03945                 while (!$rs->EOF) {
03946                     $this->delete( $rs->fields[0] );
03947                     $rs->moveNext();
03948                 }
03949             }
03950         }
03951     }
03952 
03962     protected function _resetCacheAndArticleCount( $sOxid )
03963     {
03964         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03965     }
03966 
03972     protected function _deletePics()
03973     {
03974         $myUtilsPic = oxUtilsPic::getInstance();
03975         $myConfig   = $this->getConfig();
03976         $oPictureHandler = oxPictureHandler::getInstance();
03977 
03978         //deleting custom main icon
03979         $oPictureHandler->deleteMainIcon( $this );
03980 
03981         //deleting custom thumbnail
03982         $oPictureHandler->deleteThumbnail( $this );
03983 
03984         $sAbsDynImageDir = $myConfig->getPictureDir(false);
03985 
03986         // deleting master image and all generated images
03987         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03988         for ( $i = 1; $i <= $iPicCount; $i++ ) {
03989             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
03990         }
03991     }
03992 
04002     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04003     {
04004 
04005         $myUtilsCount = oxUtilsCount::getInstance();
04006 
04007         if ( $sVendorId ) {
04008             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04009         }
04010 
04011         if ( $sManufacturerId ) {
04012             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04013         }
04014 
04015         //also reseting category counts
04016         $oDb = oxDb::getDb();
04017         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04018         $oRs = $oDb->execute( $sQ );
04019         if ( $oRs !== false && $oRs->recordCount() > 0) {
04020             while ( !$oRs->EOF ) {
04021                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04022                 $oRs->moveNext();
04023             }
04024         }
04025     }
04026 
04034     protected function _onChangeUpdateStock( $sParentID )
04035     {
04036         if ( $sParentID ) {
04037             $oDb = oxDb::getDb();
04038             $sParentIdQuoted = $oDb->quote($sParentID);
04039             $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04040             $rs = $oDb->execute($sQ);
04041             $iOldStock = $rs->fields[0];
04042             $iVendorID = $rs->fields[1];
04043             $iManufacturerID = $rs->fields[2];
04044 
04045             $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04046             $iStock = (float) $oDb->getOne( $sQ );
04047 
04048             $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04049             $oDb->execute( $sQ );
04050 
04051                 //now lets update category counts
04052                 //first detect stock status change for this article (to or from 0)
04053                 if ( $iStock < 0 ) {
04054                     $iStock = 0;
04055                 }
04056                 if ( $iOldStock < 0 ) {
04057                     $iOldStock = 0;
04058                 }
04059                 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04060                     //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04061                     // so far we leave it like this but later we could move all count resets to one or two functions
04062                     $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04063                 }
04064         }
04065     }
04066 
04074     protected function _onChangeStockResetCount( $sOxid )
04075     {
04076         $myConfig = $this->getConfig();
04077 
04078         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04079            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04080 
04081                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04082         }
04083     }
04084 
04092     protected function _onChangeUpdateVarCount( $sParentID )
04093     {
04094         if ( $sParentID ) {
04095             $oDb = oxDb::getDb();
04096             $sParentIdQuoted = $oDb->quote( $sParentID );
04097             $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04098             $iVarCount = (int) $oDb->getOne( $sQ );
04099 
04100             $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04101             $oDb->execute( $sQ );
04102         }
04103     }
04104 
04112     protected function _onChangeUpdateMinVarPrice( $sParentID )
04113     {
04114         if ( $sParentID ) {
04115             $oDb = oxDb::getDb();
04116             $sParentIdQuoted = $oDb->quote($sParentID);
04117             //#M0000883 (Sarunas)
04118             $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04119             $dVarMinPrice = $oDb->getOne($sQ);
04120 
04121             $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04122 
04123             $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04124 
04125             if ($dVarMinPrice) {
04126                 if ($blParentBuyable) {
04127                     $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04128                 }
04129 
04130             } else {
04131                 $dVarMinPrice = $dParentPrice;
04132             }
04133 
04134             if ( $dVarMinPrice ) {
04135                 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04136                 $oDb->execute($sQ);
04137             }
04138         }
04139     }
04140 
04141 
04147     protected function _applyRangePrice()
04148     {
04149         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04150         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04151             return;
04152         }
04153 
04154         $this->_blIsRangePrice = false;
04155 
04156         // if parent is buyable - do not apply range price calcculations
04157         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04158             return;
04159         }
04160 
04161         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04162             //#2509 we cannot force brutto price here, as netto price can be added to DB
04163             // $this->getPrice()->setBruttoPriceMode();
04164             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04165             $this->_blIsRangePrice = true;
04166             $this->_calculatePrice( $this->getPrice() );
04167             return;
04168         }
04169 
04170         $aPrices = array();
04171 
04172         if (!$this->_blNotBuyableParent) {
04173             $aPrices[] = $this->getPrice()->getBruttoPrice();
04174         }
04175 
04176         $aVariants = $this->getVariants(false);
04177 
04178         if (count($aVariants)) {
04179             foreach ($aVariants as $sKey => $oVariant) {
04180                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04181             }
04182         }
04183 
04184         if ( count( $aPrices ) ) {
04185             $dMinPrice = min( $aPrices );
04186             $dMaxPrice = max( $aPrices );
04187         }
04188 
04189         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04190             $this->getPrice()->setBruttoPriceMode();
04191             $this->getPrice()->setPrice($dMinPrice);
04192         }
04193 
04194         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04195             $this->getPrice()->setBruttoPriceMode();
04196             $this->getPrice()->setPrice($dMinPrice);
04197             $this->_blIsRangePrice = true;
04198         }
04199     }
04200 
04207     public function getProductId()
04208     {
04209         return $this->getId();
04210     }
04211 
04217     public function getProductParentId()
04218     {
04219         return $this->oxarticles__oxparentid->value;
04220     }
04221 
04227     public function isOrderArticle()
04228     {
04229         return false;
04230     }
04231 
04237     public function isVariant()
04238     {
04239         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04240     }
04241 
04247     public function isMdVariant()
04248     {
04249         $oMdVariant = oxNew( "oxVariantHandler" );
04250 
04251         return $oMdVariant->isMdVariant($this);
04252     }
04253 
04261     public function getSqlForPriceCategories($sFields = '')
04262     {
04263         if (!$sFields) {
04264             $sFields = 'oxid';
04265         }
04266         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04267         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04268         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04269                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04270                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04271     }
04272 
04280     public function inPriceCategory( $sCatNid )
04281     {
04282         $oDb = oxDb::getDb();
04283 
04284         $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04285         $sQuotedCnid = $oDb->quote( $sCatNid );
04286         return (bool) $oDb->getOne(
04287             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04288            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04289            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04290            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04291            .")"
04292         );
04293     }
04294 
04300     public function getMdVariants()
04301     {
04302         if ( $this->_oMdVariants ) {
04303             return $this->_oMdVariants;
04304         }
04305 
04306         $oParentArticle = $this->getParentArticle();
04307         if ( $oParentArticle ) {
04308             $oVariants = $oParentArticle->getVariants();
04309         } else {
04310             $oVariants = $this->getVariants();
04311         }
04312 
04313         $oVariantHandler = oxNew( "oxVariantHandler" );
04314         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04315 
04316         return $this->_oMdVariants;
04317     }
04318 
04324     public function getMdSubvariants()
04325     {
04326         return $this->getMdVariants()->getMdSubvariants();
04327     }
04328 
04336     protected function _hasMasterImage( $iIndex )
04337     {
04338         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04339 
04340         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04341             return false;
04342         }
04343         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04344             return false;
04345         }
04346 
04347         $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04348 
04349         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04350             return true;
04351         }
04352 
04353         return false;
04354     }
04355 
04364     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04365     {
04366         if ( $sFieldName ) {
04367             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04368             return $this->$sFieldName->value;
04369         }
04370     }
04371 
04379     public function getMasterZoomPictureUrl( $iIndex )
04380     {
04381         $sPicUrl  = false;
04382         $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04383 
04384         if ( $sPicName && $sPicName != "nopic.jpg" ) {
04385             $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04386             if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04387                 $sPicUrl = false;
04388             }
04389         }
04390 
04391         return $sPicUrl;
04392     }
04393 }