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         oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00865     }
00866 
00872     public function getArticleRatingAverage()
00873     {
00874         return round( $this->oxarticles__oxrating->value, 1);
00875     }
00876 
00882     public function getReviews()
00883     {
00884         $aIds = array($this->getId());
00885 
00886         if ( $this->oxarticles__oxparentid->value ) {
00887             $aIds[] = $this->oxarticles__oxparentid->value;
00888         }
00889 
00890         // showing variant reviews ..
00891         if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00892             $aAdd = $this->_getVariantsIds();
00893             if (is_array($aAdd)) {
00894                 $aIds = array_merge($aIds, $aAdd);
00895             }
00896         }
00897 
00898         $oReview = oxNew('oxreview');
00899         $oRevs = $oReview->loadList('oxarticle', $aIds);
00900 
00901         //if no review found, return null
00902         if ( $oRevs->count() < 1 ) {
00903             return null;
00904         }
00905 
00906         return $oRevs;
00907     }
00908 
00914     public function getCrossSelling()
00915     {
00916         $oCrosslist = oxNew( "oxarticlelist");
00917         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00918         if ( $oCrosslist->count() ) {
00919             return $oCrosslist;
00920         }
00921     }
00922 
00928     public function getAccessoires()
00929     {
00930         $myConfig = $this->getConfig();
00931 
00932         // Performance
00933         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00934             return;
00935         }
00936 
00937         $oAcclist = oxNew( "oxarticlelist");
00938         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00939         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00940 
00941         if ( $oAcclist->count()) {
00942             return $oAcclist;
00943         }
00944     }
00945 
00951     public function getSimilarProducts()
00952     {
00953         // Performance
00954         $myConfig = $this->getConfig();
00955         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
00956             return;
00957         }
00958 
00959         $sArticleTable = $this->getViewName();
00960 
00961         $sAttribs = '';
00962         $iCnt = 0;
00963         $this->_getAttribsString($sAttribs, $iCnt);
00964 
00965         if ( !$sAttribs) {
00966             return null;
00967         }
00968 
00969         $aList = $this->_getSimList($sAttribs, $iCnt);
00970 
00971         if ( count( $aList ) ) {
00972             uasort( $aList, 'cmpart');
00973 
00974             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
00975 
00976             $oSimilarlist = oxNew( 'oxarticlelist' );
00977             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
00978             $oSimilarlist->selectString( $sSearch);
00979 
00980             return $oSimilarlist;
00981         }
00982     }
00983 
00989     public function getCustomerAlsoBoughtThisProducts()
00990     {
00991         // Performance
00992         $myConfig = $this->getConfig();
00993         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
00994             return;
00995         }
00996 
00997         // selecting products that fits
00998         $sQ = $this->_generateSearchStrForCustomerBought();
00999 
01000         $oArticles = oxNew( 'oxarticlelist' );
01001         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01002         $oArticles->selectString( $sQ );
01003         if ( $oArticles->count() ) {
01004             return $oArticles;
01005         }
01006     }
01007 
01014     public function loadAmountPriceInfo()
01015     {
01016         $myConfig = $this->getConfig();
01017         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01018             return array();
01019         }
01020 
01021         if ( $this->_oAmountPriceInfo === null ) {
01022             $this->_oAmountPriceInfo = array();
01023             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01024                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01025 
01026             }
01027         }
01028         return $this->_oAmountPriceInfo;
01029     }
01030 
01038     public function getSelectLists($sKeyPrefix = null)
01039     {
01040         //#1468C - more then one article in basket with different selectlist...
01041         //optionall function parameter $sKeyPrefix added, used only in basket.php
01042         $sKey = $this->getId();
01043         if ( isset( $sKeyPrefix ) ) {
01044             $sKey = $sKeyPrefix.'__'.$this->getId();
01045         }
01046 
01047         if ( !isset( self::$_aSelList[$sKey] ) ) {
01048             $oDb = oxDb::getDb();
01049             $sSLViewName = getViewName( 'oxselectlist' );
01050 
01051             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01052                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01053 
01054             // all selectlists this article has
01055             $oLists = oxNew( 'oxlist' );
01056             $oLists->init( 'oxselectlist' );
01057             $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01058 
01059             //#1104S if this is variant ant it has no selectlists, trying with parent
01060             if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01061                 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01062             }
01063 
01064             $dVat = 0;
01065             if ( $this->getPrice() != null ) {
01066                 $dVat = $this->getPrice()->getVat();
01067             }
01068 
01069             $iCnt = 0;
01070             self::$_aSelList[$sKey] = array();
01071             foreach ( $oLists as $oSelectlist ) {
01072                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01073                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01074                 $iCnt++;
01075             }
01076         }
01077         return self::$_aSelList[$sKey];
01078     }
01079 
01087     protected function _hasAnyVariant( $blForceCoreTable = null )
01088     {
01089         $blHas = false;
01090         if ( ( $sId = $this->getId() ) ) {
01091             $sArticleTable = $this->getViewName( $blForceCoreTable );
01092             $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01093         }
01094         return $blHas;
01095     }
01096 
01102     public function hasMdVariants()
01103     {
01104         return $this->_blHasMdVariants;
01105     }
01106 
01116     public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01117     {
01118         $iLimit = (int) $iLimit;
01119         if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01120             $this->_aVariantSelections[$iLimit] = false;
01121             if ( $this->oxarticles__oxvarcount->value ) {
01122                 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $this->getVariants(), $aFilterIds, $sActVariantId, $iLimit );
01123             }
01124         }
01125         return $this->_aVariantSelections[$iLimit];
01126     }
01127 
01136     public function getSelections( $iLimit = null, $aFilter = null )
01137     {
01138         $sId = $this->getId() . ( (int) $iLimit );
01139         if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01140 
01141             $oDb = oxDb::getDb();
01142             $sSLViewName = getViewName( 'oxselectlist' );
01143 
01144             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01145                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01146 
01147             if ( ( $iLimit = (int) $iLimit ) ) {
01148                 $sQ .= " limit $iLimit ";
01149             }
01150 
01151             // vat value for price
01152             $dVat = 0;
01153             if ( ( $oPrice = $this->getPrice() ) != null ) {
01154                 $dVat = $oPrice->getVat();
01155             }
01156 
01157             // all selectlists this article has
01158             $oList = oxNew( 'oxlist' );
01159             $oList->init( 'oxselectlist' );
01160             $oList->getBaseObject()->setVat( $dVat );
01161             $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01162 
01163             //#1104S if this is variant and it has no selectlists, trying with parent
01164             if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01165                 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01166             }
01167 
01168             self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01169         }
01170 
01171         if ( self::$_aSelections[$sId] ) {
01172             // marking active from filter
01173             $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01174             if ( $aFilter ) {
01175                 $iSelIdx = 0;
01176                 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01177                     if ( isset( $aFilter[$iSelIdx] ) ) {
01178                         $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01179                     }
01180                     $iSelIdx++;
01181                 }
01182             }
01183         }
01184 
01185         return self::$_aSelections[$sId];
01186     }
01187 
01197     protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01198     {
01199         $oVariants = array();
01200         if ( ( $sId = $this->getId() ) ) {
01201             //do not load me as a parent later
01202             self::$_aLoadedParents[$sId] = $this;
01203 
01204             $myConfig = $this->getConfig();
01205 
01206             if ( !$this->_blLoadVariants ||
01207                 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01208                 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01209                 return $oVariants;
01210             }
01211 
01212             // cache
01213             $sCacheKey = $blSimple ? "simple" : "full";
01214             if ( $blRemoveNotOrderables ) {
01215                 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01216                    return $this->_aVariants[$sCacheKey];
01217                 } else {
01218                     $this->_aVariants[$sCacheKey] = & $oVariants;
01219                 }
01220             } elseif ( !$blRemoveNotOrderables ) {
01221                 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01222                     return $this->_aVariantsWithNotOrderables[$sCacheKey];
01223                 } else {
01224                     $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01225                 }
01226             }
01227 
01228             if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01229 
01230                 //load simple variants for lists
01231                 if ( $blSimple ) {
01232                     $oVariants = oxNew( 'oxsimplevariantlist' );
01233                     $oVariants->setParent( $this );
01234                 } else {
01235                     //loading variants
01236                     $oVariants = oxNew( 'oxarticlelist' );
01237                     $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01238                 }
01239 
01240                 startProfile("selectVariants");
01241                 $blUseCoreTable = (bool) $blForceCoreTable;
01242                 $oBaseObject = $oVariants->getBaseObject();
01243                 $oBaseObject->setLanguage( $this->getLanguage() );
01244 
01245 
01246                 $sArticleTable = $this->getViewName( $blUseCoreTable );
01247 
01248                 $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01249                            $this->getActiveCheckQuery( $blUseCoreTable ) .
01250                            $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01251                            " order by $sArticleTable.oxsort";
01252 
01253                 $oVariants->selectString( $sSelect );
01254 
01255                 //if this is multidimensional variants, make additional processing
01256                 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01257                     $oMdVariants = oxNew( "oxVariantHandler" );
01258                     $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01259                 }
01260                 stopProfile("selectVariants");
01261             }
01262 
01263             //if we have variants then depending on config option the parent may be non buyable
01264             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01265                 $this->_blNotBuyableParent = true;
01266             }
01267 
01268             //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01269             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01270                 $this->_blNotBuyable = true;
01271             }
01272         }
01273         return $oVariants;
01274     }
01275 
01284     public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01285     {
01286         return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01287     }
01288 
01297     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null  )
01298     {
01299         return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01300     }
01301 
01307     public function getSimpleVariants()
01308     {
01309         if ( $this->oxarticles__oxvarcount->value) {
01310             return $this->getVariants();
01311         }
01312     }
01313 
01322     public function getAdminVariants( $sLanguage = null )
01323     {
01324         $oVariants = oxNew( 'oxarticlelist');
01325         if ( ( $sId = $this->getId() ) ) {
01326 
01327             $oBaseObj = $oVariants->getBaseObject();
01328 
01329             if ( is_null( $sLanguage ) ) {
01330                 $oBaseObj->setLanguage( oxLang::getInstance()->getBaseLanguage() );
01331             } else {
01332                 $oBaseObj->setLanguage( $sLanguage );
01333             }
01334 
01335             $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01336             $oVariants->selectString( $sSql );
01337 
01338             //if we have variants then depending on config option the parent may be non buyable
01339             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01340                 //$this->blNotBuyable = true;
01341                 $this->_blNotBuyableParent = true;
01342             }
01343         }
01344 
01345         return $oVariants;
01346     }
01347 
01355     public function getCategory()
01356     {
01357         $oCategory = oxNew( 'oxcategory' );
01358         $oCategory->setLanguage( $this->getLanguage() );
01359 
01360         // variant handling
01361         $sOXID = $this->getId();
01362         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01363             $sOXID = $this->oxarticles__oxparentid->value;
01364         }
01365 
01366         if ( $sOXID ) {
01367             // if the oxcategory instance of this article is not cached
01368             if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01369                 startPRofile( 'getCategory' );
01370                 $oStr = getStr();
01371                 $sWhere   = $oCategory->getSqlActiveSnippet();
01372                 $sSelect  = $this->_generateSearchStr( $sOXID );
01373                 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01374 
01375                 // category not found ?
01376                 if ( !$oCategory->assignRecord( $sSelect ) ) {
01377 
01378                     $sSelect  = $this->_generateSearchStr( $sOXID, true );
01379                     $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01380 
01381                     // looking for price category
01382                     if ( !$oCategory->assignRecord( $sSelect ) ) {
01383                         $oCategory = null;
01384                     }
01385                 }
01386                 // add the category instance to cache
01387                 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01388                 stopPRofile( 'getCategory' );
01389             } else {
01390                // if the oxcategory instance is cached
01391                $oCategory = $this->_aCategoryCache[ $sOXID ];
01392             }
01393         }
01394 
01395         return $oCategory;
01396     }
01397 
01406     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01407     {
01408         $myConfig = $this->getConfig();
01409         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01410             return self::$_aArticleCats[$this->getId()];
01411         }
01412 
01413         // variant handling
01414         $sOXID = $this->getId();
01415         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01416             $sOXID = $this->oxarticles__oxparentid->value;
01417         }
01418 
01419         // we do not use lists here as we dont need this overhead right now
01420         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01421         $oDB = oxDb::getDb(true);
01422         $rs = $oDB->execute( $sSql );
01423 
01424 
01425         $aRet = array();
01426 
01427         if ($rs != false && $rs->recordCount() > 0) {
01428             while (!$rs->EOF) {
01429                 $aRet[] = $rs->fields['oxcatnid'];
01430                 $rs->moveNext();
01431             }
01432         }
01433 
01434         // adding price categories if such exists
01435         $sSql = $this->getSqlForPriceCategories();
01436 
01437         $oDB = oxDb::getDb( true );
01438         $rs = $oDB->execute( $sSql );
01439 
01440         if ($rs != false && $rs->recordCount() > 0) {
01441             while (!$rs->EOF) {
01442 
01443                 if ( is_array( $rs->fields ) ) {
01444                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01445                 }
01446 
01447 
01448                 if ( !$aRet[$rs->fields['oxid']] ) {
01449                     $aRet[] = $rs->fields['oxid'];
01450                 }
01451                 $rs->moveNext();
01452             }
01453         }
01454 
01455         return self::$_aArticleCats[$this->getId()] = $aRet;
01456     }
01457 
01466     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01467     {
01468         $sO2CView = $this->_getObjectViewName('oxobject2category');
01469         $sCatView = $this->_getObjectViewName('oxcategories');
01470         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01471         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01472         if ( $blActCats ) {
01473             $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 ";
01474         }
01475         $sSelect .= 'order by oxobject2category.oxtime ';
01476         return $sSelect;
01477     }
01478 
01488     public function getVendor( $blShopCheck = true )
01489     {
01490         if ( ( $sVendorId = $this->getVendorId() ) ) {
01491             $oVendor = oxNew( 'oxvendor' );
01492         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01493                 $oVendor = oxNew( 'oxi18n' );
01494                 $oVendor->init('oxvendor');
01495                 $oVendor->setReadOnly( true );
01496             $sVendorId = $this->oxarticles__oxvendorid->value;
01497         }
01498         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01499             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01500                 $oVendor->setReadOnly( true );
01501             }
01502             return $oVendor;
01503         }
01504         return null;
01505     }
01506 
01514     public function getVendorId( $blForceReload = false )
01515     {
01516         $sVendorId = false;
01517         if ( $this->oxarticles__oxvendorid->value ) {
01518                 $sVendorId = $this->oxarticles__oxvendorid->value;
01519 
01520         }
01521         return $sVendorId;
01522     }
01523 
01531     public function getManufacturerId( $blForceReload = false )
01532     {
01533         $sManufacturerId = false;
01534         if ( $this->oxarticles__oxmanufacturerid->value ) {
01535 
01536                 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01537 
01538         }
01539         return $sManufacturerId;
01540     }
01541 
01551     public function getManufacturer( $blShopCheck = true )
01552     {
01553             $oManufacturer = oxNew( 'oxmanufacturer' );;
01554         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01555              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01556             $oManufacturer->setReadOnly( true );
01557             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01558         }
01559 
01560         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01561             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01562                 $oManufacturer->setReadOnly( true );
01563             }
01564             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01565         } else {
01566             $oManufacturer = null;
01567         }
01568 
01569         return $oManufacturer;
01570     }
01571 
01579     public function inCategory( $sCatNid)
01580     {
01581         return in_array( $sCatNid, $this->getCategoryIds());
01582     }
01583 
01592     public function isAssignedToCategory( $sCatId )
01593     {
01594         // variant handling
01595         $sOXID = $this->getId();
01596         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01597             $sOXID = $this->oxarticles__oxparentid->value;
01598         }
01599 
01600         $oDB = oxDb::getDb();
01601         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01602         $sOXID = $oDB->getOne( $sSelect);
01603         // article is assigned to passed category!
01604         if ( isset( $sOXID) && $sOXID) {
01605             return true;
01606         }
01607 
01608         // maybe this category is price category ?
01609         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01610             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01611             if ( $dPriceFromTo > 0) {
01612                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01613                 $sOXID = $oDB->getOne( $sSelect);
01614                 // article is assigned to passed category!
01615                 if ( isset( $sOXID) && $sOXID) {
01616                     return true;
01617                 }
01618             }
01619         }
01620         return false;
01621     }
01622 
01628     public function getTPrice()
01629     {
01630         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01631             return;
01632         }
01633         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01634         if ( $this->_oTPrice !== null ) {
01635             return $this->_oTPrice;
01636         }
01637 
01638         $this->_oTPrice = oxNew( 'oxPrice' );
01639         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01640 
01641         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01642         $this->_applyCurrency( $this->_oTPrice );
01643 
01644         return $this->_oTPrice;
01645     }
01646 
01652     public function skipDiscounts()
01653     {
01654         // allready loaded skip discounts config
01655         if ( $this->_blSkipDiscounts !== null )
01656             return $this->_blSkipDiscounts;
01657 
01658         if ( $this->oxarticles__oxskipdiscounts->value )
01659             return true;
01660 
01661         $sO2CView  = getViewName( 'oxobject2category', $this->getLanguage() );
01662         $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01663         $sSelect =  "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01664                      where $sO2CView.oxobjectid='".$this->getId()."' and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01665         return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01666     }
01667 
01675     public function setPrice(oxPrice $oPrice)
01676     {
01677         $this->_oPrice = $oPrice;
01678     }
01679 
01688     public function getBasePrice( $dAmount = 1 )
01689     {
01690         // override this function if you want e.g. different prices
01691         // for diff. usergroups.
01692 
01693         // Performance
01694         $myConfig = $this->getConfig();
01695         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01696             return;
01697 
01698         // GroupPrice or DB price ajusted by AmountPrice
01699         $dPrice = $this->_getAmountPrice( $dAmount );
01700 
01701 
01702         return $dPrice;
01703     }
01704 
01712     public function getPrice( $dAmount = 1 )
01713     {
01714         $myConfig = $this->getConfig();
01715         // Performance
01716         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01717             return;
01718         }
01719 
01720         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01721         if ( $dAmount != 1 || $this->_oPrice === null ) {
01722             $oPrice = oxNew( 'oxPrice' );
01723 
01724             // get base
01725             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01726 
01727             // price handling
01728             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01729                 return $this->_oPrice = $oPrice;
01730             }
01731 
01732             $this->_calculatePrice( $oPrice );
01733             if ( $dAmount != 1 ) {
01734                 return $oPrice;
01735             }
01736 
01737             $this->_oPrice = $oPrice;
01738         }
01739         return $this->_oPrice;
01740     }
01741 
01750     protected function _calculatePrice( $oPrice, $dVat = null )
01751     {
01752         // apply VAT only if configuration requires it
01753         if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01754             $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01755         }
01756 
01757         // apply currency
01758         $this->_applyCurrency( $oPrice );
01759         // apply discounts
01760         if ( !$this->skipDiscounts() ) {
01761             $oDiscountList = oxDiscountList::getInstance();
01762             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
01763         }
01764 
01765         return $oPrice;
01766     }
01767 
01775     public function setArticleUser($oUser)
01776     {
01777         $this->_oUser = $oUser;
01778     }
01779 
01785     public function getArticleUser()
01786     {
01787         if ($this->_oUser) {
01788             return $this->_oUser;
01789         }
01790         return $this->getUser();
01791     }
01792 
01802     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01803     {
01804         $oUser = $oBasket->getBasketUser();
01805         $this->setArticleUser( $oUser );
01806 
01807         $oBasketPrice = oxNew( 'oxPrice' );
01808 
01809         // get base price
01810         $dBasePrice = $this->getBasePrice( $dAmount );
01811 
01812         // applying select list price
01813         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01814 
01815         // setting price
01816         $oBasketPrice->setPrice( $dBasePrice );
01817 
01818         $dVat = oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket );
01819         $this->_calculatePrice( $oBasketPrice, $dVat );
01820 
01821         // returning final price object
01822         return $oBasketPrice;
01823     }
01824 
01837     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01838     {
01839         $oDiscountList = oxDiscountList::getInstance();
01840         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01841     }
01842 
01851     public function delete( $sOXID = null )
01852     {
01853         if ( !$sOXID ) {
01854             $sOXID = $this->getId();
01855         }
01856         if ( !$sOXID ) {
01857             return false;
01858         }
01859 
01860 
01861         // #2339 delete first variants before deleting parent product
01862         $this->_deleteVariantRecords( $sOXID );
01863         $this->load( $sOXID );
01864         $this->_deletePics();
01865         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01866 
01867         $rs = $this->_deleteRecords( $sOXID );
01868 
01869         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01870 
01871         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01872 
01873         return $rs->EOF;
01874     }
01875 
01884     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01885     {
01886         $this->beforeUpdate();
01887 
01888         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01889         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01890             $dAmount += $iStockCount;
01891             $iStockCount = 0;
01892         }
01893         $this->oxarticles__oxstock = new oxField($iStockCount);
01894 
01895         $oDb = oxDb::getDb();
01896         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01897         $this->onChange( ACTION_UPDATE_STOCK );
01898         return $dAmount;
01899     }
01900 
01909     public function updateSoldAmount( $dAmount = 0 )
01910     {
01911         if ( !$dAmount ) {
01912             return;
01913         }
01914 
01915         $this->beforeUpdate();
01916 
01917         // article is not variant - should be updated current amount
01918         if ( !$this->oxarticles__oxparentid->value ) {
01919             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01920             $dAmount = (double) $dAmount;
01921             $oDb = oxDb::getDb();
01922             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01923         } elseif ( $this->oxarticles__oxparentid->value) {
01924             // article is variant - should be updated this article parent amount
01925             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01926             $oUpdateArticle->updateSoldAmount( $dAmount );
01927         }
01928 
01929         $this->onChange( ACTION_UPDATE );
01930 
01931         return $rs;
01932     }
01933 
01939     public function disableReminder()
01940     {
01941         $oDB = oxDb::getDb(true);
01942         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01943     }
01944 
01952     public function save()
01953     {
01954         // @deprecated since 20110821. folders are no more written, getters must be user for urls
01955         $this->oxarticles__oxthumb = new oxField( basename( $this->oxarticles__oxthumb->value ), oxField::T_RAW );
01956         $this->oxarticles__oxicon  = new oxField( basename( $this->oxarticles__oxicon->value ), oxField::T_RAW );
01957         $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
01958         for ( $i = 1; $i <= $iPicCount; $i++ ) {
01959             $sFieldName = 'oxarticles__oxpic' . $i;
01960             if ( isset( $this->$sFieldName ) ) {
01961                 $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );
01962             }
01963         }
01964         // @end deprecated
01965 
01966         if ( ( $blRet = parent::save() ) ) {
01967             // saving long descrition
01968             $this->_saveArtLongDesc();
01969         }
01970 
01971         return $blRet;
01972     }
01973 
01974 
01981     public function getPictureGallery()
01982     {
01983         $myConfig = $this->getConfig();
01984 
01985         //initialize
01986         $blMorePic = false;
01987         $aArtPics  = array();
01988         $aArtIcons = array();
01989         $iActPicId = 1;
01990         $sActPic = $this->getPictureUrl( $iActPicId );
01991 
01992         if ( oxConfig::getParameter( 'actpicid' ) ) {
01993             $iActPicId = oxConfig::getParameter('actpicid');
01994         }
01995 
01996         $oStr = getStr();
01997         $iCntr = 0;
01998         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01999         $blCheckActivePicId = true;
02000 
02001         for ( $i = 1; $i <= $iPicCount; $i++) {
02002             $sPicVal = $this->getPictureUrl( $i );
02003             $sIcoVal = $this->getIconUrl( $i );
02004             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02005                  !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02006                 if ($iCntr) {
02007                     $blMorePic = true;
02008                 }
02009                 $aArtIcons[$i]= $sIcoVal;
02010                 $aArtPics[$i]= $sPicVal;
02011                 $iCntr++;
02012 
02013                 if ($iActPicId == $i) {
02014                     $sActPic = $sPicVal;
02015                     $blCheckActivePicId = false;
02016                 }
02017 
02018             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02019                 // if picture is empty, setting active pic id to next
02020                 // picture
02021                 $iActPicId++;
02022             }
02023         }
02024 
02025         $blZoomPic  = false;
02026         $aZoomPics = array();
02027         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02028 
02029         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02030             $sVal = $this->getZoomPictureUrl($j);
02031 
02032             if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02033                 $blZoomPic = true;
02034                 $aZoomPics[$c]['id'] = $c;
02035                 $aZoomPics[$c]['file'] = $sVal;
02036                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02037                 if (!$sVal) {
02038                     $aZoomPics[$c]['file'] = "nopic.jpg";
02039                 }
02040                 $c++;
02041             }
02042         }
02043 
02044         $aPicGallery = array('ActPicID' => $iActPicId,
02045                              'ActPic' => $sActPic,
02046                              'MorePics' => $blMorePic,
02047                              'Pics' => $aArtPics,
02048                              'Icons' => $aArtIcons,
02049                              'ZoomPic' => $blZoomPic,
02050                              'ZoomPics' => $aZoomPics);
02051 
02052         return $aPicGallery;
02053     }
02054 
02068     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02069     {
02070         $myConfig = $this->getConfig();
02071 
02072         if (!isset($sOXID)) {
02073             if ( $this->getId()) {
02074                 $sOXID = $this->getId();
02075             }
02076             if (!isset ($sOXID)) {
02077                 $sOXID = $this->oxarticles__oxid->value;
02078             }
02079             if ($this->oxarticles__oxparentid->value) {
02080                 $sParentID = $this->oxarticles__oxparentid->value;
02081             }
02082         }
02083         if (!isset($sOXID)) {
02084             return;
02085         }
02086 
02087         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02088         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02089             //if article has variants then updating oxvarstock field
02090             //getting parent id
02091             if (!isset($sParentID)) {
02092                 $oDb = oxDb::getDb();
02093                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02094                 $sParentID = $oDb->getOne($sQ);
02095             }
02096             //if we have parent id then update stock
02097             if ($sParentID) {
02098                 $this->_onChangeUpdateStock($sParentID);
02099             }
02100         }
02101         //if we have parent id then update count
02102         //update count even if blUseStock is not active
02103         if ($sParentID) {
02104             $this->_onChangeUpdateVarCount($sParentID);
02105         }
02106 
02107         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02108         $this->_onChangeUpdateMinVarPrice( $sId );
02109 
02110             // reseting articles count cache if stock has changed and some
02111             // articles goes offline (M:1448)
02112             if ( $sAction === ACTION_UPDATE_STOCK ) {
02113                 $this->_onChangeStockResetCount( $sOXID );
02114             }
02115 
02116     }
02117 
02124     public function getCustomVAT()
02125     {
02126         if ( isset($this->oxarticles__oxvat->value) ) {
02127             return $this->oxarticles__oxvat->value;
02128         }
02129     }
02130 
02139     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02140     {
02141         $myConfig = $this->getConfig();
02142         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02143             return true;
02144         }
02145 
02146         // fetching DB info as its up-to-date
02147         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02148         $rs = oxDb::getDb(true)->Execute( $sQ );
02149 
02150         $iOnStock   = 0;
02151         $iStockFlag = 0;
02152         if ( $rs !== false && $rs->recordCount() > 0 ) {
02153             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02154             $iStockFlag = $rs->fields['oxstockflag'];
02155 
02156             // dodger : fremdlager is also always considered as on stock
02157             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02158                 return true;
02159             }
02160             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02161                 $iOnStock = floor( $iOnStock );
02162             }
02163         }
02164         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02165             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02166         }
02167         if ( $iOnStock >= $dAmount ) {
02168             return true;
02169         } else {
02170             if ( $iOnStock > 0 ) {
02171                 return $iOnStock;
02172             } else {
02173                 $oEx = oxNew( 'oxArticleInputException' );
02174                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02175                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02176                 return false;
02177             }
02178         }
02179     }
02180 
02181 
02189     public function getArticleLongDesc( $sOxid = null )
02190     {
02191         if ( $this->_oLongDesc === null ) {
02192 
02193             // initializing
02194             $this->_oLongDesc = new oxField();
02195 
02196 
02197             // choosing which to get..
02198             $sOxid = $sOxid === null ? $this->getId() : $sOxid;
02199             $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02200             if ( ( $sDbValue = oxDb::getDb()->getOne( "select oxlongdesc from {$sViewName} where oxid = ?", array( $sOxid ) ) ) !== false ) {
02201                 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02202             }
02203         }
02204 
02205         return $this->_oLongDesc;
02206     }
02207 
02217     protected function _setLongDesc( $sDbValue )
02218     {
02219         $this->setArticleLongDesc( $sDbValue );
02220     }
02221 
02228     public function getLongDesc()
02229     {
02230         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getArticleLongDesc()->getRawValue(), $this->getId().$this->getLanguage() );
02231     }
02232 
02241     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02242     {
02243 
02244         // setting current value
02245         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02246 
02247         // setting original value?
02248         if ( $sOrigValue ) {
02249             $this->_oLongDesc->orignalValue = $sOrigValue;
02250         }
02251     }
02252 
02258     public function getAttributes()
02259     {
02260         if ( $this->_oAttributeList === null ) {
02261             $this->_oAttributeList = oxNew( 'oxattributelist' );
02262             $this->_oAttributeList->loadAttributes( $this->getId() );
02263         }
02264 
02265         return $this->_oAttributeList;
02266     }
02267 
02276     public function appendLink( $sAddParams, $iLang = null )
02277     {
02278         if ( $sAddParams ) {
02279             if ( $iLang === null ) {
02280                 $iLang = $this->getLanguage();
02281             }
02282 
02283             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02284             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02285         }
02286     }
02287 
02296     public function getBaseSeoLink( $iLang, $blMain = false )
02297     {
02298         $oEncoder = oxSeoEncoderArticle::getInstance();
02299         if ( !$blMain ) {
02300             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02301         }
02302         return $oEncoder->getArticleMainUrl( $this, $iLang );
02303     }
02304 
02313     public function getLink( $iLang = null, $blMain = false  )
02314     {
02315         if ( !oxUtils::getInstance()->seoIsActive() ) {
02316             return $this->getStdLink( $iLang );
02317         }
02318 
02319         if ( $iLang === null ) {
02320             $iLang = $this->getLanguage();
02321         }
02322 
02323         $iLinkType = $this->getLinkType();
02324         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02325             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02326         }
02327 
02328         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02329         if ( isset($this->_aSeoAddParams[$iLang])) {
02330             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02331         }
02332 
02333         return $sUrl;
02334     }
02335 
02344     public function getMainLink( $iLang = null )
02345     {
02346         return $this->getLink( $iLang, true );
02347     }
02348 
02356     public function setLinkType( $iType )
02357     {
02358         // resetting detaisl link, to force new
02359         $this->_sDetailLink = null;
02360 
02361         // setting link type
02362         $this->_iLinkType = (int) $iType;
02363     }
02364 
02370     public function getLinkType()
02371     {
02372         return $this->_iLinkType;
02373     }
02374 
02383     public function appendStdLink( $sAddParams, $iLang = null )
02384     {
02385         if ( $sAddParams ) {
02386             if ( $iLang === null ) {
02387                 $iLang = $this->getLanguage();
02388             }
02389 
02390             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02391             $this->_aStdAddParams[$iLang] .= $sAddParams;
02392         }
02393     }
02394 
02404     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02405     {
02406         $sUrl = '';
02407         if ( $blFull ) {
02408             //always returns shop url, not admin
02409             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02410         }
02411 
02412         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02413         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02414     }
02415 
02424     public function getStdLink( $iLang = null, $aParams = array() )
02425     {
02426         if ( $iLang === null ) {
02427             $iLang = $this->getLanguage();
02428         }
02429 
02430         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02431             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02432         }
02433 
02434         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02435     }
02436 
02444     public function getStdTagLink( $sTag )
02445     {
02446         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02447         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02448     }
02449 
02455     public function getTags()
02456     {
02457         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02458         $sQ = "select oxtags from {$sViewName} where oxid = '".$this->getId()."'";
02459         $oTagCloud = oxNew('oxtagcloud');
02460         return $oTagCloud->trimTags( oxDb::getDb()->getOne( $sQ ) );
02461     }
02462 
02470     public function saveTags($sTags)
02471     {
02472         //do not allow derived update
02473         if ( !$this->allowDerivedUpdate() ) {
02474             return false;
02475         }
02476 
02477 
02478         $oTagCloud = oxNew( 'oxtagcloud' );
02479         $oTagCloud->resetTagCache();
02480         $sTags = mysql_real_escape_string( $oTagCloud->prepareTags( $sTags ) );
02481 
02482         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02483         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02484         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value ('".$this->getId()."', '{$sTags}')
02485                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02486         return oxDb::getDb()->execute( $sQ );
02487     }
02488 
02496     public function addTag($sTag)
02497     {
02498         $oDb = oxDb::getDb();
02499 
02500         $oTagCloud = oxNew('oxtagcloud');
02501         $oTagCloud->resetTagCache();
02502         $sTag = $oTagCloud->prepareTags($sTag);
02503         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02504 
02505         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02506         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02507         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = '".$this->getId()."'" ) ) {
02508             $sTailTag = $sTagSeparator . $sTag;
02509         } else {
02510             $sTailTag = $sTag;
02511         }
02512 
02513         $sTag = mysql_real_escape_string($sTag);
02514         $sTailTag = mysql_real_escape_string($sTailTag);
02515 
02516         $sTag = mysql_real_escape_string($sTag);
02517         $sTailTag = mysql_real_escape_string($sTailTag);
02518 
02519         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values ('".$this->getId()."', '{$sTag}')
02520                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02521 
02522         return $oDb->execute( $sQ );
02523     }
02524 
02530     public function getMediaUrls()
02531     {
02532         if ( $this->_aMediaUrls === null ) {
02533             $this->_aMediaUrls = oxNew("oxlist");
02534             $this->_aMediaUrls->init("oxmediaurl");
02535             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02536 
02537             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02538             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02539             $this->_aMediaUrls->selectString($sQ);
02540         }
02541         return $this->_aMediaUrls;
02542     }
02543 
02549     public function getDynImageDir()
02550     {
02551         return $this->_sDynImageDir;
02552     }
02553 
02559     public function getDispSelList()
02560     {
02561         if ($this->_aDispSelList === null) {
02562             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02563                 $this->_aDispSelList = $this->getSelectLists();
02564             }
02565         }
02566         return $this->_aDispSelList;
02567     }
02568 
02574     public function getMoreDetailLink()
02575     {
02576         if ( $this->_sMoreDetailLink == null ) {
02577 
02578             // and assign special article values
02579             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02580 
02581             // not always it is okey, as not all the time active category is the same as primary article cat.
02582             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02583                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02584             }
02585             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02586             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02587         }
02588 
02589         return $this->_sMoreDetailLink;
02590     }
02591 
02597     public function getToBasketLink()
02598     {
02599         if ( $this->_sToBasketLink == null ) {
02600             $myConfig = $this->getConfig();
02601 
02602             if ( oxUtils::getInstance()->isSearchEngine() ) {
02603                 $this->_sToBasketLink = $this->getLink();
02604             } else {
02605                 // and assign special article values
02606                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02607 
02608                 // override some classes as these should never showup
02609                 $sActClass = oxConfig::getParameter( 'cl' );
02610                 if ( $sActClass == 'thankyou') {
02611                     $sActClass = 'basket';
02612                 }
02613                 $this->_sToBasketLink .= 'cl='.$sActClass;
02614 
02615                 // this is not very correct
02616                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02617                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02618                 }
02619 
02620                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02621 
02622                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02623                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02624                 }
02625             }
02626         }
02627 
02628         return $this->_sToBasketLink;
02629     }
02630 
02636     public function getStockStatus()
02637     {
02638         return $this->_iStockStatus;
02639     }
02640 
02646     public function getDeliveryDate()
02647     {
02648         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02649             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02650         }
02651         return false;
02652     }
02653 
02659     public function getFTPrice()
02660     {
02661         if ( $oPrice = $this->getTPrice() ) {
02662             if ( $oPrice->getBruttoPrice() ) {
02663                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02664             }
02665         }
02666     }
02667 
02673     public function getFPrice()
02674     {
02675         if ( $oPrice = $this->getPrice() ) {
02676             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02677         }
02678     }
02679 
02685     public function getFNetPrice()
02686     {
02687         if ( $oPrice = $this->getPrice() ) {
02688             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02689         }
02690     }
02691 
02697     public function getPricePerUnit()
02698     {
02699         return $this->_fPricePerUnit;
02700     }
02701 
02707     public function isParentNotBuyable()
02708     {
02709         return $this->_blNotBuyableParent;
02710     }
02711 
02717     public function isNotBuyable()
02718     {
02719         return $this->_blNotBuyable;
02720     }
02721 
02729     public function setBuyableState( $blBuyable = false )
02730     {
02731         $this->_blNotBuyable = !$blBuyable;
02732     }
02733 
02742     public function getVariantList()
02743     {
02744         return $this->getVariants();
02745     }
02746 
02754     public function setSelectlist( $aSelList )
02755     {
02756         $this->_aDispSelList = $aSelList;
02757     }
02758 
02766     public function getPictureUrl( $iIndex = 1 )
02767     {
02768         if ( $iIndex ) {
02769             $sImgName = false;
02770             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02771                 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02772             }
02773 
02774             $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02775             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02776         }
02777     }
02778 
02787     public function getIconUrl( $iIndex = 0 )
02788     {
02789         $sImgName = false;
02790         $sDirname = "product/1/";
02791         if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02792             $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02793             $sDirname = "product/{$iIndex}/";
02794         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02795             $sImgName = basename( $this->oxarticles__oxicon->value );
02796             $sDirname = "product/icon/";
02797         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02798             $sImgName = basename( $this->oxarticles__oxpic1->value );
02799         }
02800 
02801         $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02802         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02803     }
02804 
02810     public function getThumbnailUrl()
02811     {
02812         $sImgName = false;
02813         $sDirname = "product/1/";
02814         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02815             $sImgName = basename( $this->oxarticles__oxthumb->value );
02816             $sDirname = "product/thumb/";
02817         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02818             $sImgName = basename( $this->oxarticles__oxpic1->value );
02819         }
02820 
02821         $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02822         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0 );
02823     }
02824 
02832     public function getZoomPictureUrl( $iIndex = '' )
02833     {
02834         $iIndex = (int) $iIndex;
02835         if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02836             $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02837             $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02838             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02839         }
02840     }
02841 
02847     public function getFileUrl()
02848     {
02849         return $this->getConfig()->getPictureUrl( 'media/' );
02850     }
02851 
02857     public function getPriceFromPrefix()
02858     {
02859         $sPricePrefics = '';
02860         if ( $this->_blIsRangePrice) {
02861             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02862         }
02863 
02864         return $sPricePrefics;
02865     }
02866 
02872     protected function _saveArtLongDesc()
02873     {
02874         $myConfig = $this->getConfig();
02875         $sShopId = $myConfig->getShopID();
02876         if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02877             return;
02878         }
02879 
02880         if ($this->_blEmployMultilanguage) {
02881             $sValue = $this->getArticleLongDesc()->getRawValue();
02882             if ( $sValue !== null ) {
02883                 $oArtExt = oxNew('oxI18n');
02884                 $oArtExt->init('oxartextends');
02885                 $oArtExt->setLanguage((int) $this->getLanguage());
02886                 if (!$oArtExt->load($this->getId())) {
02887                     $oArtExt->setId($this->getId());
02888                 }
02889                 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02890                 $oArtExt->save();
02891             }
02892         } else {
02893             $oArtExt = oxNew('oxI18n');
02894             $oArtExt->setEnableMultilang(false);
02895             $oArtExt->init('oxartextends');
02896             $aObjFields = $oArtExt->_getAllFields(true);
02897             if (!$oArtExt->load($this->getId())) {
02898                 $oArtExt->setId($this->getId());
02899             }
02900 
02901             foreach ($aObjFields as $sKey => $sValue ) {
02902                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02903                     $sField = $this->_getFieldLongName($sKey);
02904 
02905                     if (isset($this->$sField)) {
02906                         $sLongDesc = null;
02907                         if ($this->$sField instanceof oxField) {
02908                             $sLongDesc = $this->$sField->getRawValue();
02909                         } elseif (is_object($this->$sField)) {
02910                             $sLongDesc = $this->$sField->value;
02911                         }
02912                         if (isset($sLongDesc)) {
02913                             $sAEField = $oArtExt->_getFieldLongName($sKey);
02914                             $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
02915                         }
02916                     }
02917                 }
02918             }
02919             $oArtExt->save();
02920         }
02921     }
02922 
02928     protected function _skipSaveFields()
02929     {
02930         $myConfig = $this->getConfig();
02931 
02932         $this->_aSkipSaveFields = array();
02933 
02934         $this->_aSkipSaveFields[] = 'oxtimestamp';
02935        // $this->_aSkipSaveFields[] = 'oxlongdesc';
02936         $this->_aSkipSaveFields[] = 'oxinsert';
02937 
02938         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02939             $this->_aSkipSaveFields[] = 'oxparentid';
02940         }
02941 
02942     }
02943 
02953     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02954     {
02955         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02956             // add prices of the same discounts
02957             if ( array_key_exists ($sKey, $aDiscounts) ) {
02958                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02959             } else {
02960                 $aDiscounts[$sKey] = $oDiscount;
02961             }
02962         }
02963         return $aDiscounts;
02964     }
02965 
02971     protected function _getGroupPrice()
02972     {
02973         $dPrice = $this->oxarticles__oxprice->value;
02974 
02975         $oUser = $this->getArticleUser();
02976         if ( $oUser ) {
02977             if ( $oUser->inGroup( 'oxidpricea' ) ) {
02978                 $dPrice = $this->oxarticles__oxpricea->value;
02979             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
02980                 $dPrice = $this->oxarticles__oxpriceb->value;
02981             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
02982                 $dPrice = $this->oxarticles__oxpricec->value;
02983             }
02984         }
02985 
02986         // #1437/1436C - added config option, and check for zero A,B,C price values
02987         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
02988             $dPrice = $this->oxarticles__oxprice->value;
02989         }
02990 
02991         return $dPrice;
02992     }
02993 
03002     protected function _getAmountPrice($dAmount = 1)
03003     {
03004         $myConfig = $this->getConfig();
03005 
03006         startProfile( "_getAmountPrice" );
03007 
03008         $dPrice = $this->_getGroupPrice();
03009         $oAmtPrices = $this->_getAmountPriceList();
03010         foreach ($oAmtPrices as $oAmPrice) {
03011             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03012                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03013                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03014                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03015             }
03016         }
03017 
03018         stopProfile( "_getAmountPrice" );
03019         return $dPrice;
03020     }
03021 
03030     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03031     {
03032         $myConfig = $this->getConfig();
03033         // #690
03034         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03035 
03036             $aSelLists = $this->getSelectLists();
03037 
03038             foreach ( $aSelLists as $key => $aSel) {
03039                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03040                     $oSel = $aSel[$aChosenList[$key]];
03041                     if ( $oSel->priceUnit =='abs' ) {
03042                         $dPrice += $oSel->price;
03043                     } elseif ( $oSel->priceUnit =='%' ) {
03044                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03045                     }
03046                 }
03047             }
03048         }
03049         return $dPrice;
03050     }
03051 
03052 
03060     protected function _fillAmountPriceList($oAmPriceList)
03061     {
03062         $myConfig = $this->getConfig();
03063         $myUtils  = oxUtils::getInstance();
03064 
03065         //modifying price
03066         $oCur = $myConfig->getActShopCurrencyObject();
03067 
03068         $oUser = $this->getArticleUser();
03069 
03070         $oDiscountList = oxDiscountList::getInstance();
03071         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03072 
03073         $oLowestPrice = null;
03074 
03075         $dBasePrice = $this->_getGroupPrice();
03076         $oLang = oxLang::getInstance();
03077 
03078         $dArticleVat = null;
03079         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03080             $dArticleVat = $this->getArticleVat();
03081         }
03082 
03083         // trying to find lowest price value
03084         foreach ($oAmPriceList as $sId => $oItem) {
03085             $oItemPrice = oxNew( 'oxprice' );
03086             if ( $oItem->oxprice2article__oxaddabs->value) {
03087                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03088                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03089                 $this->_applyCurrency( $oItemPrice, $oCur );
03090             } else {
03091                 $oItemPrice->setPrice( $dBasePrice );
03092                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03093             }
03094 
03095             if (isset($dArticleVat)) {
03096                 $this->_applyVAT($oItemPrice, $dArticleVat);
03097             }
03098 
03099             if (!$oLowestPrice) {
03100                 $oLowestPrice = $oItemPrice;
03101             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03102                 $oLowestPrice = $oItemPrice;
03103             }
03104 
03105             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03106             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03107             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03108         }
03109 
03110         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03111         return $oAmPriceList;
03112     }
03113 
03119     protected function _getVariantsIds()
03120     {
03121         $aSelect = array();
03122         if ( ( $sId = $this->getId() ) ) {
03123             $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = '{$sId}' and " .
03124                    $this->getSqlActiveSnippet( true );
03125 
03126             $oRs = oxDb::getDb(true)->execute( $sQ );
03127             if ( $oRs != false && $oRs->recordCount() > 0 ) {
03128                 while (!$oRs->EOF) {
03129                     $aSelect[] = reset( $oRs->fields );
03130                     $oRs->moveNext();
03131                 }
03132             }
03133         }
03134         return $aSelect;
03135     }
03136 
03142     public function getArticleVat()
03143     {
03144         if (!isset($this->_dArticleVat)) {
03145             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03146         }
03147         return $this->_dArticleVat;
03148     }
03149 
03158     protected function _applyVAT( oxPrice $oPrice, $dVat )
03159     {
03160         startProfile(__FUNCTION__);
03161         $oPrice->setVAT( $dVat );
03162         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03163             $oPrice->setUserVat( $dVat );
03164         }
03165         stopProfile(__FUNCTION__);
03166     }
03167 
03175     public function applyVats( oxPrice $oPrice )
03176     {
03177         $this->_applyVAT($oPrice, $this->getArticleVat() );
03178     }
03179 
03190     protected function _applyDiscounts( $oPrice, $aDiscounts )
03191     {
03192         $oDiscountList = oxDiscountList::getInstance();
03193         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03194     }
03195 
03203     public function applyDiscountsForVariant( $oPrice )
03204     {
03205         // apply discounts
03206         if ( !$this->skipDiscounts() ) {
03207             $oDiscountList = oxDiscountList::getInstance();
03208             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03209         }
03210     }
03211 
03220     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03221     {
03222         if ( !$oCur ) {
03223             $oCur = $this->getConfig()->getActShopCurrencyObject();
03224         }
03225 
03226         $oPrice->multiply($oCur->rate);
03227     }
03228 
03229 
03238     protected function _getAttribsString(&$sAttribs, &$iCnt)
03239     {
03240         // we do not use lists here as we dont need this overhead right now
03241         $oDB = oxDb::getDb(true);
03242         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03243         $sAttribs = '';
03244         $blSep = false;
03245         $rs = $oDB->execute( $sSelect);
03246         $iCnt = 0;
03247         if ($rs != false && $rs->recordCount() > 0) {
03248             while (!$rs->EOF) {
03249                 if ( $blSep) {
03250                     $sAttribs .= ' or ';
03251                 }
03252                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03253                 $blSep = true;
03254                 $iCnt++;
03255                 $rs->moveNext();
03256             }
03257         }
03258     }
03259 
03268     protected function _getSimList($sAttribs, $iCnt)
03269     {
03270         $myConfig = $this->getConfig();
03271         $oDB      = oxDb::getDb(true);
03272 
03273         // #523A
03274         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03275         // 70% same attributes
03276         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03277             $iAttrPercent = 0.70;
03278         }
03279         // #1137V iAttributesPercent = 100 doesnt work
03280         $iHitMin = ceil( $iCnt * $iAttrPercent );
03281 
03282         // we do not use lists here as we dont need this overhead right now
03283         $aList= array();
03284         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03285                     ( $sAttribs )
03286                     and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03287                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03288 
03289         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03290         if ($rs != false && $rs->recordCount() > 0) {
03291             while (!$rs->EOF) {
03292                 $oTemp = new stdClass();    // #663
03293                 $oTemp->cnt = $rs->fields['cnt'];
03294                 $oTemp->id  = $rs->fields['oxobjectid'];
03295                 $aList[] = $oTemp;
03296                 $rs->moveNext();
03297             }
03298         }
03299         return $aList;
03300     }
03301 
03310     protected function _generateSimListSearchStr($sArticleTable, $aList)
03311     {
03312         $myConfig = $this->getConfig();
03313         $sFieldList = $this->getSelectFields();
03314         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03315         $blSep = false;
03316         $iCnt = 0;
03317         $oDb = oxDb::getDb();
03318         foreach ( $aList as $oTemp) {
03319             if ( $blSep) {
03320                 $sSearch .= ',';
03321             }
03322             $sSearch .= $oDb->quote($oTemp->id);
03323             $blSep = true;
03324             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03325                 break;
03326             }
03327             $iCnt++;
03328         }
03329 
03330         //#1741T
03331         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03332         $sSearch .= ') ';
03333 
03334         // #524A -- randomizing articles in attribute list
03335         $sSearch .= ' order by rand() ';
03336 
03337         return $sSearch;
03338     }
03339 
03348     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03349     {
03350 
03351         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03352         $sO2CView = getViewName( 'oxobject2category' );
03353 
03354         // we do not use lists here as we dont need this overhead right now
03355         if ( !$blSearchPriceCat ) {
03356             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03357                          {$sCatView}.oxid = oxobject2category.oxcatnid
03358                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03359         } else {
03360             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03361                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03362                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03363         }
03364         return $sSelect;
03365     }
03366 
03372     protected function _generateSearchStrForCustomerBought()
03373     {
03374         $sArtTable = $this->getViewName();
03375         $sOrderArtTable = getViewName( 'oxorderarticles' );
03376 
03377         // fetching filter params
03378         $sIn = " '{$this->oxarticles__oxid->value}' ";
03379         if ( $this->oxarticles__oxparentid->value ) {
03380 
03381             // adding article parent
03382             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03383             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03384 
03385         } else {
03386             $sParentIdForVariants = $this->getId();
03387         }
03388 
03389         // adding variants
03390         $oDb = oxDb::getDb(true);
03391         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03392         if ( $oRs != false && $oRs->recordCount() > 0) {
03393             while ( !$oRs->EOF ) {
03394                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03395                 $oRs->moveNext();
03396             }
03397         }
03398 
03399         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03400         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03401 
03402         // building sql (optimized)
03403         $sQ = "select distinct {$sArtTable}.* from (
03404                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03405                ) as suborder
03406                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03407                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03408                where {$sArtTable}.oxid not in ( {$sIn} )
03409                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03410 
03411         /* non optimized, but could be used if index forcing is not supported
03412         // building sql
03413         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03414                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03415                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03416                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03417                and ".$this->getSqlActiveSnippet();
03418         */
03419 
03420         return $sQ;
03421     }
03422 
03432     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03433     {
03434         $sCategoryView = getViewName('oxcategories');
03435         $sO2CView = getViewName('oxobject2category');
03436 
03437         $oDb    = oxDb::getDb();
03438         $sOXID  = $oDb->quote($sOXID);
03439         $sCatId = $oDb->quote($sCatId);
03440 
03441         if (!$dPriceFromTo) {
03442             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03443             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03444             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03445             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03446         } else {
03447             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03448             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03449             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03450             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03451         }
03452         return $sSelect;
03453     }
03454 
03460     protected function _getAmountPriceList()
03461     {
03462         if ( $this->_oAmountPriceList === null ) {
03463             $this->_oAmountPriceList = array();
03464             if ( !$this->skipDiscounts() ) {
03465                 $myConfig = $this->getConfig();
03466                 $sArtId   = $this->getId();
03467 
03468                 // #1690C - Scale prices and variants
03469                 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03470                     $sArtId = $this->oxarticles__oxparentid->value;
03471                 }
03472 
03473                 //collecting assigned to article amount-price list
03474                 $oAmPriceList = oxNew( 'oxlist' );
03475                 $oAmPriceList->init( 'oxbase', 'oxprice2article' );
03476 
03477                 $sShopID = $myConfig->getShopID();
03478                 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03479                     $sShopSelect = '1';
03480                 } else {
03481                     $sShopSelect = " oxshopid =  '$sShopID' ";
03482                 }
03483 
03484                 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = " . oxDb::getDb()->quote( $sArtId ) . " and $sShopSelect order by oxamount ");
03485 
03486                 // prepare abs prices if currently having percentages
03487                 $oBasePrice = $this->_getGroupPrice();
03488                 foreach ( $oAmPriceList as $oAmPrice ) {
03489                     if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03490                         $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03491                     }
03492                 }
03493 
03494                 $this->_oAmountPriceList = $oAmPriceList;
03495             }
03496         }
03497 
03498         return $this->_oAmountPriceList;
03499     }
03500 
03508     protected function _isFieldEmpty( $sFieldName )
03509     {
03510         $mValue = $this->$sFieldName->value;
03511 
03512         if ( is_null( $mValue ) ) {
03513             return true;
03514         }
03515 
03516         if ( $mValue === '' ) {
03517             return true;
03518         }
03519 
03520         $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03521 
03522         if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03523             return true;
03524         }
03525 
03526 
03527         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03528             return true;
03529         }
03530 
03531         $sFieldName = strtolower($sFieldName);
03532 
03533         if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03534             return true;
03535         }
03536 
03537         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03538             return true;
03539         }
03540 
03541         return false;
03542     }
03543 
03551     protected function _assignParentFieldValue($sFieldName)
03552     {
03553         if (!($oParentArticle = $this->getParentArticle())) {
03554             return;
03555         }
03556 
03557         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03558 
03559         // assigning only theese which parent article has
03560         if ( $oParentArticle->$sCopyFieldName != null ) {
03561 
03562             // only overwrite database values
03563             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03564                 return;
03565             }
03566 
03567             //do not copy certain fields
03568             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03569                 return;
03570             }
03571 
03572             //COPY THE VALUE
03573             // assigning images from parent only if variant has no master image (#1807)
03574             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03575                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03576                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03577                 }
03578             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03579                 // for zoom images checking master image with specified index
03580                 // assign from parent only if no pictures to variant are added
03581                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03582                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03583                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03584                 }
03585             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03586                 // if no pics generated for variants, load all from
03587                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03588             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03589                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03590             }
03591         }
03592     }
03593 
03599     public function getParentArticle()
03600     {
03601         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03602             $sIndex = $sParentId . "_" . $this->getLanguage();
03603             if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03604                 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03605                 self::$_aLoadedParents[$sIndex]->_blSkipAbPrice  = true;
03606                 self::$_aLoadedParents[$sIndex]->_blLoadPrice    = false;
03607                 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03608                 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03609             }
03610             return self::$_aLoadedParents[$sIndex];
03611         }
03612     }
03613 
03621     protected function _getParentAricle()
03622     {
03623         return $this->getParentArticle();
03624     }
03625 
03631     protected function _assignParentFieldValues()
03632     {
03633         startProfile('articleAssignParentInternal');
03634         if ( $this->oxarticles__oxparentid->value ) {
03635             // yes, we are in fact a variant
03636             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03637                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03638                     $this->_assignParentFieldValue( $sFieldName );
03639                 }
03640 
03641                 //assing long description
03642                 $sLongDesc = $this->getArticleLongDesc()->getRawValue();
03643                 if ( $sLongDesc === null || $sLongDesc == '' ) {
03644                     $this->setArticleLongDesc( $this->getParentArticle()->getArticleLongDesc()->getRawValue() );
03645                 }
03646             }
03647         }
03648         stopProfile('articleAssignParentInternal');
03649     }
03650 
03656     protected function _assignNotBuyableParent()
03657     {
03658         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03659              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03660             $this->_blNotBuyableParent = true;
03661 
03662         }
03663     }
03664 
03670     protected function _assignStock()
03671     {
03672         $myConfig = $this->getConfig();
03673         // -----------------------------------
03674         // stock
03675         // -----------------------------------
03676 
03677         // #1125 A. must round (using floor()) value taken from database and cast to int
03678         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03679             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03680         }
03681         //GREEN light
03682         $this->_iStockStatus = 0;
03683 
03684         // if we have flag /*1 or*/ 4 - we show always green light
03685         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03686             //ORANGE light
03687             $iStock = $this->oxarticles__oxstock->value;
03688 
03689             if ($this->_blNotBuyableParent) {
03690                 $iStock = $this->oxarticles__oxvarstock->value;
03691             }
03692 
03693 
03694             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03695                 $this->_iStockStatus = 1;
03696             }
03697 
03698             //RED light
03699             if ($iStock <= 0) {
03700                 $this->_iStockStatus = -1;
03701             }
03702         }
03703 
03704 
03705         // stock
03706         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03707             $iOnStock = $this->oxarticles__oxstock->value;
03708             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03709                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03710             }
03711             if ($iOnStock <= 0) {
03712                 $this->_blNotBuyable = true;
03713             }
03714         }
03715 
03716         //exceptional handling for variant parent stock:
03717         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03718             $this->_blNotBuyable = false;
03719             //but then at least setting notBuaybleParent to true
03720             $this->_blNotBuyableParent = true;
03721         }
03722 
03723         //special treatment for lists when blVariantParentBuyable config option is set to false
03724         //then we just hide "to basket" button.
03725         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03726         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03727             $this->_blNotBuyable = true;
03728         }
03729 
03730         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03731         if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03732             $this->_blNotBuyable = true;
03733         }
03734     }
03735 
03741     protected function _assignPrices()
03742     {
03743         $myConfig = $this->getConfig();
03744 
03745         // Performance
03746         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03747             return;
03748         }
03749 
03750         // compute price
03751         $dPrice = $this->getPrice()->getBruttoPrice();
03752 
03753         $oCur = $myConfig->getActShopCurrencyObject();
03754         //price per unit handling
03755         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03756             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03757         }
03758 
03759         //getting min and max prices of variants
03760         if ( $this->_hasAnyVariant() ) {
03761             $this->_applyRangePrice();
03762         }
03763     }
03764 
03770     protected function _assignPersistentParam()
03771     {
03772         // Persistent Parameter Handling
03773         $aPersParam     = oxSession::getVar( 'persparam');
03774         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03775             $this->_aPersistParam = $aPersParam[$this->getId()];
03776         }
03777     }
03778 
03784     protected function _assignDynImageDir()
03785     {
03786         $myConfig = $this->getConfig();
03787 
03788         $sThisShop = $this->oxarticles__oxshopid->value;
03789 
03790         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03791         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03792         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03793         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03794     }
03795 
03801     protected function _assignComparisonListFlag()
03802     {
03803         // #657 add a flag if article is on comparisonlist
03804 
03805         $aItems = oxSession::getVar('aFiltcompproducts');
03806         if ( isset( $aItems[$this->getId()])) {
03807             $this->_blIsOnComparisonList = true;
03808         }
03809     }
03810 
03816     protected function _assignAttributes()
03817     {
03818         //#1029T load attributes
03819         //#1078S removed check for module "Produktvergleich"
03820         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03821             $this->getAttributes();
03822         }
03823     }
03824 
03825 
03833     protected function _insert()
03834     {
03835         // set oxinsert
03836         $iInsertTime = time();
03837         $now = date('Y-m-d H:i:s', $iInsertTime);
03838         $this->oxarticles__oxinsert    = new oxField( $now );
03839         $this->oxarticles__oxtimestamp = new oxField( $now );
03840         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03841             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03842         }
03843 
03844         return parent::_insert();
03845     }
03846 
03852     protected function _update()
03853     {
03854 
03855         $this->_skipSaveFields();
03856 
03857         $myConfig = $this->getConfig();
03858 
03859 
03860         return parent::_update();
03861     }
03862 
03870     protected function _deleteRecords($sOXID)
03871     {
03872         $oDB = oxDb::getDb();
03873 
03874         $sOXID = $oDB->quote($sOXID);
03875 
03876         //delete the record
03877         $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
03878         $oDB->execute( $sDelete);
03879 
03880         //remove other records
03881         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03882         $oDB->execute( $sDelete);
03883 
03884         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03885         $oDB->execute( $sDelete);
03886 
03887         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03888         $oDB->execute( $sDelete);
03889 
03890         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03891         $oDB->execute( $sDelete);
03892 
03893         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03894         $oDB->execute( $sDelete);
03895 
03896         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03897         $oDB->execute( $sDelete);
03898 
03899         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03900         $oDB->execute( $sDelete);
03901 
03902         //#1508C - deleting oxobject2delivery entries added
03903         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03904         $oDB->execute( $sDelete);
03905 
03906         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03907         $oDB->execute( $sDelete);
03908 
03909         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03910         $rs = $oDB->execute( $sDelete );
03911 
03912         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03913         $rs = $oDB->execute( $sDelete );
03914 
03915 
03916         return $rs;
03917     }
03918 
03926     protected function _deleteVariantRecords( $sOXID )
03927     {
03928         if ( $sOXID ) {
03929             $oDb = oxDb::getDb();
03930             //collect variants to remove recursively
03931             $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03932             $rs = $oDb->execute( $sQ );
03933             if ($rs != false && $rs->recordCount() > 0) {
03934                 while (!$rs->EOF) {
03935                     $this->delete( $rs->fields[0] );
03936                     $rs->moveNext();
03937                 }
03938             }
03939         }
03940     }
03941 
03951     protected function _resetCacheAndArticleCount( $sOxid )
03952     {
03953         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03954     }
03955 
03961     protected function _deletePics()
03962     {
03963         $myUtilsPic = oxUtilsPic::getInstance();
03964         $myConfig   = $this->getConfig();
03965         $oPictureHandler = oxPictureHandler::getInstance();
03966 
03967         //deleting custom main icon
03968         $oPictureHandler->deleteMainIcon( $this );
03969 
03970         //deleting custom thumbnail
03971         $oPictureHandler->deleteThumbnail( $this );
03972 
03973         $sAbsDynImageDir = $myConfig->getPictureDir(false);
03974 
03975         // deleting master image and all generated images
03976         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03977         for ( $i = 1; $i <= $iPicCount; $i++ ) {
03978             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
03979         }
03980     }
03981 
03991     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
03992     {
03993 
03994         $myUtilsCount = oxUtilsCount::getInstance();
03995 
03996         if ( $sVendorId ) {
03997             $myUtilsCount->resetVendorArticleCount( $sVendorId );
03998         }
03999 
04000         if ( $sManufacturerId ) {
04001             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04002         }
04003 
04004         //also reseting category counts
04005         $oDb = oxDb::getDb();
04006         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04007         $oRs = $oDb->execute( $sQ );
04008         if ( $oRs !== false && $oRs->recordCount() > 0) {
04009             while ( !$oRs->EOF ) {
04010                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04011                 $oRs->moveNext();
04012             }
04013         }
04014     }
04015 
04023     protected function _onChangeUpdateStock( $sParentID )
04024     {
04025         if ( $sParentID ) {
04026             $oDb = oxDb::getDb();
04027             $sParentIdQuoted = $oDb->quote($sParentID);
04028             $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04029             $rs = $oDb->execute($sQ);
04030             $iOldStock = $rs->fields[0];
04031             $iVendorID = $rs->fields[1];
04032             $iManufacturerID = $rs->fields[2];
04033 
04034             $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04035             $iStock = (float) $oDb->getOne( $sQ );
04036 
04037             $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04038             $oDb->execute( $sQ );
04039 
04040                 //now lets update category counts
04041                 //first detect stock status change for this article (to or from 0)
04042                 if ( $iStock < 0 ) {
04043                     $iStock = 0;
04044                 }
04045                 if ( $iOldStock < 0 ) {
04046                     $iOldStock = 0;
04047                 }
04048                 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04049                     //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04050                     // so far we leave it like this but later we could move all count resets to one or two functions
04051                     $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04052                 }
04053         }
04054     }
04055 
04063     protected function _onChangeStockResetCount( $sOxid )
04064     {
04065         $myConfig = $this->getConfig();
04066 
04067         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04068            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04069 
04070                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04071         }
04072     }
04073 
04081     protected function _onChangeUpdateVarCount( $sParentID )
04082     {
04083         if ( $sParentID ) {
04084             $oDb = oxDb::getDb();
04085             $sParentIdQuoted = $oDb->quote( $sParentID );
04086             $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04087             $iVarCount = (int) $oDb->getOne( $sQ );
04088 
04089             $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04090             $oDb->execute( $sQ );
04091         }
04092     }
04093 
04101     protected function _onChangeUpdateMinVarPrice( $sParentID )
04102     {
04103         if ( $sParentID ) {
04104             $oDb = oxDb::getDb();
04105             $sParentIdQuoted = $oDb->quote($sParentID);
04106             //#M0000883 (Sarunas)
04107             $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04108             $dVarMinPrice = $oDb->getOne($sQ);
04109 
04110             $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04111 
04112             $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04113 
04114             if ($dVarMinPrice) {
04115                 if ($blParentBuyable) {
04116                     $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04117                 }
04118 
04119             } else {
04120                 $dVarMinPrice = $dParentPrice;
04121             }
04122 
04123             if ( $dVarMinPrice ) {
04124                 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04125                 $oDb->execute($sQ);
04126             }
04127         }
04128     }
04129 
04130 
04136     protected function _applyRangePrice()
04137     {
04138         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04139         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04140             return;
04141         }
04142 
04143         $this->_blIsRangePrice = false;
04144 
04145         // if parent is buyable - do not apply range price calcculations
04146         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04147             return;
04148         }
04149 
04150         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04151             //#2509 we cannot force brutto price here, as netto price can be added to DB
04152             // $this->getPrice()->setBruttoPriceMode();
04153             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04154             $this->_blIsRangePrice = true;
04155             $this->_calculatePrice( $this->getPrice() );
04156             return;
04157         }
04158 
04159         $aPrices = array();
04160 
04161         if (!$this->_blNotBuyableParent) {
04162             $aPrices[] = $this->getPrice()->getBruttoPrice();
04163         }
04164 
04165         $aVariants = $this->getVariants(false);
04166 
04167         if (count($aVariants)) {
04168             foreach ($aVariants as $sKey => $oVariant) {
04169                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04170             }
04171         }
04172 
04173         if ( count( $aPrices ) ) {
04174             $dMinPrice = min( $aPrices );
04175             $dMaxPrice = max( $aPrices );
04176         }
04177 
04178         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04179             $this->getPrice()->setBruttoPriceMode();
04180             $this->getPrice()->setPrice($dMinPrice);
04181         }
04182 
04183         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04184             $this->getPrice()->setBruttoPriceMode();
04185             $this->getPrice()->setPrice($dMinPrice);
04186             $this->_blIsRangePrice = true;
04187         }
04188     }
04189 
04196     public function getProductId()
04197     {
04198         return $this->getId();
04199     }
04200 
04206     public function getProductParentId()
04207     {
04208         return $this->oxarticles__oxparentid->value;
04209     }
04210 
04216     public function isOrderArticle()
04217     {
04218         return false;
04219     }
04220 
04226     public function isVariant()
04227     {
04228         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04229     }
04230 
04236     public function isMdVariant()
04237     {
04238         $oMdVariant = oxNew( "oxVariantHandler" );
04239 
04240         return $oMdVariant->isMdVariant($this);
04241     }
04242 
04250     public function getSqlForPriceCategories($sFields = '')
04251     {
04252         if (!$sFields) {
04253             $sFields = 'oxid';
04254         }
04255         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04256         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04257         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04258                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04259                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04260     }
04261 
04269     public function inPriceCategory( $sCatNid )
04270     {
04271         $oDb = oxDb::getDb();
04272 
04273         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04274         $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04275         return (bool) $oDb->getOne(
04276             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04277            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04278            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04279            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04280            .")"
04281         );
04282     }
04283 
04289     public function getMdVariants()
04290     {
04291         if ( $this->_oMdVariants ) {
04292             return $this->_oMdVariants;
04293         }
04294 
04295         $oParentArticle = $this->getParentArticle();
04296         if ( $oParentArticle ) {
04297             $oVariants = $oParentArticle->getVariants();
04298         } else {
04299             $oVariants = $this->getVariants();
04300         }
04301 
04302         $oVariantHandler = oxNew( "oxVariantHandler" );
04303         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04304 
04305         return $this->_oMdVariants;
04306     }
04307 
04313     public function getMdSubvariants()
04314     {
04315         return $this->getMdVariants()->getMdSubvariants();
04316     }
04317 
04325     protected function _hasMasterImage( $iIndex )
04326     {
04327         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04328 
04329         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04330             return false;
04331         }
04332         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04333             return false;
04334         }
04335 
04336         $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04337 
04338         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04339             return true;
04340         }
04341 
04342         return false;
04343     }
04344 
04353     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04354     {
04355         if ( $sFieldName ) {
04356             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04357             return $this->$sFieldName->value;
04358         }
04359     }
04360 
04368     public function getMasterZoomPictureUrl( $iIndex )
04369     {
04370         $sPicUrl  = false;
04371         $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04372 
04373         if ( $sPicName && $sPicName != "nopic.jpg" ) {
04374             $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04375             if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04376                 $sPicUrl = false;
04377             }
04378         }
04379 
04380         return $sPicUrl;
04381     }
04382 }