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 
00718     public function getSearchableFields()
00719     {
00720         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00721         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00722 
00723         return $aFields;
00724     }
00725 
00726 
00734     public function isMultilingualField($sFieldName)
00735     {
00736         switch ($sFieldName) {
00737             case "oxlongdesc":
00738             case "oxtags":
00739                 return true;
00740         }
00741 
00742         return parent::isMultilingualField($sFieldName);
00743     }
00744 
00750     public function isVisible()
00751     {
00752 
00753         // admin preview mode
00754         if ( ( $blCanPreview = oxUtils::getInstance()->canPreview() ) !== null ) {
00755             return $blCanPreview;
00756         }
00757 
00758         // active ?
00759         $sNow = date('Y-m-d H:i:s');
00760         if ( !$this->oxarticles__oxactive->value &&
00761              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00762                 $this->oxarticles__oxactiveto->value < $sNow
00763              )) {
00764             return false;
00765         }
00766 
00767         // stock flags
00768         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00769             $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00770             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00771                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00772             }
00773             if ( $iOnStock <= 0 ) {
00774                 return false;
00775             }
00776         }
00777 
00778         return true;
00779     }
00780 
00789     public function assign( $aRecord)
00790     {
00791         startProfile('articleAssign');
00792 
00793 
00794         // load object from database
00795         parent::assign( $aRecord);
00796 
00797         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00798 
00799         // check for simple article.
00800         if ($this->_blSkipAssign) {
00801             return;
00802         }
00803 
00804         $this->_assignParentFieldValues();
00805         $this->_assignNotBuyableParent();
00806 
00807         $this->_assignStock();
00808         startProfile('articleAssignPrices');
00809         $this->_assignPrices();
00810         stopProfile('articleAssignPrices');
00811         $this->_assignPersistentParam();
00812         $this->_assignDynImageDir();
00813         $this->_assignComparisonListFlag();
00814         $this->_assignAttributes();
00815 
00816 
00817         //$this->_seoAssign();
00818 
00819         stopProfile('articleAssign');
00820     }
00821 
00832     public function load( $oxID)
00833     {
00834         // A. #1325 resetting to avoid problems when reloading (details etc)
00835         $this->_blNotBuyableParent = false;
00836 
00837         $blRet = parent::load( $oxID);
00838 
00839         // convert date's to international format
00840         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00841         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00842 
00843         return $blRet;
00844     }
00845 
00853     public function addToRatingAverage( $iRating)
00854     {
00855         $dOldRating = $this->oxarticles__oxrating->value;
00856         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00857         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00858         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00859         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00860         $dRatingCnt = (int) ($dOldCnt + 1);
00861         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00862         oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00863     }
00864 
00870     public function getArticleRatingAverage()
00871     {
00872         return round( $this->oxarticles__oxrating->value, 1);
00873     }
00874 
00880     public function getReviews()
00881     {
00882         $myConfig  = $this->getConfig();
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 ( $myConfig->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         $sArticleTable = $this->getViewName( $blForceCoreTable );
01090         return (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='".$this->getId()."'" );
01091     }
01092 
01098     public function hasMdVariants()
01099     {
01100         return $this->_blHasMdVariants;
01101     }
01102 
01112     public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01113     {
01114         $iLimit = (int) $iLimit;
01115         if ( !isset($this->_aVariantSelections[$iLimit])) {
01116             $this->_aVariantSelections[$iLimit] = false;
01117             if ( ( $oVariantList = $this->getVariants() ) ) {
01118                 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $oVariantList, $aFilterIds, $sActVariantId, $iLimit );
01119             }
01120         }
01121         return $this->_aVariantSelections[$iLimit];
01122     }
01123 
01132     public function getSelections( $iLimit = null, $aFilter = null )
01133     {
01134         $sId = $this->getId() . ( (int) $iLimit );
01135         if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01136 
01137             $oDb = oxDb::getDb();
01138             $sSLViewName = getViewName( 'oxselectlist' );
01139 
01140             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01141                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01142 
01143             if ( ( $iLimit = (int) $iLimit ) ) {
01144                 $sQ .= " limit $iLimit ";
01145             }
01146 
01147             // vat value for price
01148             $dVat = 0;
01149             if ( ( $oPrice = $this->getPrice() ) != null ) {
01150                 $dVat = $oPrice->getVat();
01151             }
01152 
01153             // all selectlists this article has
01154             $oList = oxNew( 'oxlist' );
01155             $oList->init( 'oxselectlist' );
01156             $oList->getBaseObject()->setVat( $dVat );
01157             $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01158 
01159             //#1104S if this is variant and it has no selectlists, trying with parent
01160             if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01161                 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01162             }
01163 
01164             self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01165         }
01166 
01167         if ( self::$_aSelections[$sId] ) {
01168             // marking active from filter
01169             $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01170             if ( $aFilter ) {
01171                 $iSelIdx = 0;
01172                 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01173                     if ( isset( $aFilter[$iSelIdx] ) ) {
01174                         $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01175                     }
01176                     $iSelIdx++;
01177                 }
01178             }
01179         }
01180 
01181         return self::$_aSelections[$sId];
01182     }
01183 
01193     protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01194     {
01195         //do not load me as a parent later
01196         self::$_aLoadedParents[$this->getId()] = $this;
01197 
01198         $myConfig  = $this->getConfig();
01199         $oVariants = array();
01200 
01201         if ( !$this->_blLoadVariants ||
01202             ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01203             ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01204             return $oVariants;
01205         }
01206 
01207         // cache
01208         $sCacheKey = $blSimple ? "simple" : "full";
01209         if ( $blRemoveNotOrderables ) {
01210             if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01211                return $this->_aVariants[$sCacheKey];
01212             } else {
01213                 $this->_aVariants[$sCacheKey] = & $oVariants;
01214             }
01215         } elseif ( !$blRemoveNotOrderables ) {
01216             if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01217                 return $this->_aVariantsWithNotOrderables[$sCacheKey];
01218             } else {
01219                 $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01220             }
01221         }
01222 
01223         if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01224 
01225             //load simple variants for lists
01226             if ( $blSimple ) {
01227                 $oVariants = oxNew( 'oxsimplevariantlist' );
01228                 $oVariants->setParent( $this );
01229             } else {
01230                 //loading variants
01231                 $oVariants = oxNew( 'oxarticlelist' );
01232                 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01233             }
01234 
01235             startProfile("selectVariants");
01236             $blUseCoreTable = (bool) $blForceCoreTable;
01237             $oBaseObject = $oVariants->getBaseObject();
01238             $oBaseObject->setLanguage( $this->getLanguage() );
01239 
01240 
01241             $sArticleTable = $this->getViewName( $blUseCoreTable );
01242 
01243             $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01244                        $this->getActiveCheckQuery( $blUseCoreTable ) .
01245                        $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01246                        " order by $sArticleTable.oxsort";
01247 
01248             $oVariants->selectString( $sSelect );
01249 
01250             //if this is multidimensional variants, make additional processing
01251             if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01252                 $oMdVariants = oxNew( "oxVariantHandler" );
01253                 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01254             }
01255             stopProfile("selectVariants");
01256         }
01257 
01258         //if we have variants then depending on config option the parent may be non buyable
01259         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01260             $this->_blNotBuyableParent = true;
01261         }
01262 
01263         //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01264         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01265             $this->_blNotBuyable = true;
01266         }
01267 
01268         return $oVariants;
01269     }
01270 
01279     public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01280     {
01281         return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01282     }
01283 
01292     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null  )
01293     {
01294         return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01295     }
01296 
01302     public function getSimpleVariants()
01303     {
01304         if ( $this->oxarticles__oxvarcount->value) {
01305             return $this->getVariants();
01306         }
01307     }
01308 
01317     public function getAdminVariants( $sLanguage = null )
01318     {
01319         $myConfig = $this->getConfig();
01320 
01321         $oVariants = oxNew( 'oxarticlelist');
01322 
01323         $oBaseObj = $oVariants->getBaseObject();
01324 
01325         if ( is_null($sLanguage) ) {
01326             $oBaseObj->setLanguage(oxLang::getInstance()->getBaseLanguage());
01327         } else {
01328             $oBaseObj->setLanguage($sLanguage);
01329         }
01330 
01331         $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '".$this->getId()."' order by oxsort ";
01332 
01333         $oVariants->selectString( $sSql);
01334 
01335         //if we have variants then depending on config option the parent may be non buyable
01336         if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01337             //$this->blNotBuyable = true;
01338             $this->_blNotBuyableParent = true;
01339         }
01340 
01341         return $oVariants;
01342     }
01343 
01351     public function getCategory()
01352     {
01353 
01354         $oCategory = oxNew( 'oxcategory' );
01355         $oCategory->setLanguage( $this->getLanguage() );
01356 
01357         // variant handling
01358         $sOXID = $this->getId();
01359         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01360             $sOXID = $this->oxarticles__oxparentid->value;
01361         }
01362         // if the oxcategory instance of this article is not cached
01363         if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01364             startPRofile( 'getCategory' );
01365             $oStr = getStr();
01366             $sWhere   = $oCategory->getSqlActiveSnippet();
01367             $sSelect  = $this->_generateSearchStr( $sOXID );
01368             $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01369 
01370             // category not found ?
01371             if ( !$oCategory->assignRecord( $sSelect ) ) {
01372 
01373                 $sSelect  = $this->_generateSearchStr( $sOXID, true );
01374                 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01375 
01376                 // looking for price category
01377                 if ( !$oCategory->assignRecord( $sSelect ) ) {
01378                     $oCategory = null;
01379                 }
01380             }
01381             // add the category instance to cache
01382             $this->_aCategoryCache[ $sOXID ] = $oCategory;
01383             stopPRofile( 'getCategory' );
01384         } else {
01385            // if the oxcategory instance is cached
01386            $oCategory = $this->_aCategoryCache[ $sOXID ];
01387         }
01388 
01389         return $oCategory;
01390     }
01391 
01400     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01401     {
01402         $myConfig = $this->getConfig();
01403         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01404             return self::$_aArticleCats[$this->getId()];
01405         }
01406 
01407         // variant handling
01408         $sOXID = $this->getId();
01409         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01410             $sOXID = $this->oxarticles__oxparentid->value;
01411         }
01412 
01413         // we do not use lists here as we dont need this overhead right now
01414         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01415         $oDB = oxDb::getDb(true);
01416         $rs = $oDB->execute( $sSql );
01417 
01418 
01419         $aRet = array();
01420 
01421         if ($rs != false && $rs->recordCount() > 0) {
01422             while (!$rs->EOF) {
01423                 $aRet[] = $rs->fields['oxcatnid'];
01424                 $rs->moveNext();
01425             }
01426         }
01427 
01428         // adding price categories if such exists
01429         $sSql = $this->getSqlForPriceCategories();
01430 
01431         $oDB = oxDb::getDb( true );
01432         $rs = $oDB->execute( $sSql );
01433 
01434         if ($rs != false && $rs->recordCount() > 0) {
01435             while (!$rs->EOF) {
01436 
01437                 if ( is_array( $rs->fields ) ) {
01438                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01439                 }
01440 
01441 
01442                 if ( !$aRet[$rs->fields['oxid']] ) {
01443                     $aRet[] = $rs->fields['oxid'];
01444                 }
01445                 $rs->moveNext();
01446             }
01447         }
01448 
01449         return self::$_aArticleCats[$this->getId()] = $aRet;
01450     }
01451 
01460     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01461     {
01462         $sO2CView = $this->_getObjectViewName('oxobject2category');
01463         $sCatView = $this->_getObjectViewName('oxcategories');
01464         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01465         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01466         if ( $blActCats ) {
01467             $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 ";
01468         }
01469         $sSelect .= 'order by oxobject2category.oxtime ';
01470         return $sSelect;
01471     }
01472 
01482     public function getVendor( $blShopCheck = true )
01483     {
01484         if ( ( $sVendorId = $this->getVendorId() ) ) {
01485             $oVendor = oxNew( 'oxvendor' );
01486         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01487             $oVendor = oxNew( 'oxi18n' );
01488             $oVendor->init('oxvendor');
01489             $oVendor->setReadOnly( true );
01490             $sVendorId = $this->oxarticles__oxvendorid->value;
01491         }
01492         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01493             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01494                 $oVendor->setReadOnly( true );
01495             }
01496             return $oVendor;
01497         }
01498         return null;
01499     }
01500 
01508     public function getVendorId( $blForceReload = false )
01509     {
01510         $sVendorId = false;
01511         if ( $this->oxarticles__oxvendorid->value ) {
01512             if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01513                 return self::$_aArticleVendors[$this->getId()];
01514             }
01515             $oDb = oxDb::getDb();
01516             $sVendorIdQuoted = $oDb->quote($this->oxarticles__oxvendorid->value);
01517             $sQ = "select oxid from ".getViewName('oxvendor')." where oxid=$sVendorIdQuoted";
01518             self::$_aArticleVendors[$this->getId()] = $sVendorId = $oDb->getOne( $sQ );
01519         }
01520         return $sVendorId;
01521     }
01522 
01530     public function getManufacturerId( $blForceReload = false )
01531     {
01532         $sManufacturerId = false;
01533         if ( $this->oxarticles__oxmanufacturerid->value ) {
01534             if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01535                 return self::$_aArticleManufacturers[$this->getId()];
01536             }
01537             $oDb = oxDb::getDb();
01538             $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid=".$oDb->quote($this->oxarticles__oxmanufacturerid->value);
01539             self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = $oDb->getOne( $sQ );
01540         }
01541         return $sManufacturerId;
01542     }
01543 
01553     public function getManufacturer( $blShopCheck = true )
01554     {
01555         $oManufacturer = oxNew( 'oxmanufacturer' );;
01556         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01557              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01558             $oManufacturer->setReadOnly( true );
01559             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01560         }
01561 
01562         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01563             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01564                 $oManufacturer->setReadOnly( true );
01565             }
01566             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01567         } else {
01568             $oManufacturer = null;
01569         }
01570 
01571         return $oManufacturer;
01572     }
01573 
01581     public function inCategory( $sCatNid)
01582     {
01583         return in_array( $sCatNid, $this->getCategoryIds());
01584     }
01585 
01594     public function isAssignedToCategory( $sCatId )
01595     {
01596         // variant handling
01597         $sOXID = $this->getId();
01598         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01599             $sOXID = $this->oxarticles__oxparentid->value;
01600         }
01601 
01602         $oDB = oxDb::getDb();
01603         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01604         $sOXID = $oDB->getOne( $sSelect);
01605         // article is assigned to passed category!
01606         if ( isset( $sOXID) && $sOXID) {
01607             return true;
01608         }
01609 
01610         // maybe this category is price category ?
01611         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01612             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01613             if ( $dPriceFromTo > 0) {
01614                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01615                 $sOXID = $oDB->getOne( $sSelect);
01616                 // article is assigned to passed category!
01617                 if ( isset( $sOXID) && $sOXID) {
01618                     return true;
01619                 }
01620             }
01621         }
01622         return false;
01623     }
01624 
01630     public function getTPrice()
01631     {
01632         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01633             return;
01634         }
01635         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01636         if ( $this->_oTPrice !== null ) {
01637             return $this->_oTPrice;
01638         }
01639 
01640         $this->_oTPrice = oxNew( 'oxPrice' );
01641         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01642 
01643         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01644         $this->_applyCurrency( $this->_oTPrice );
01645 
01646         return $this->_oTPrice;
01647     }
01648 
01654     public function skipDiscounts()
01655     {
01656         // allready loaded skip discounts config
01657         if ( $this->_blSkipDiscounts !== null )
01658             return $this->_blSkipDiscounts;
01659 
01660         if ( $this->oxarticles__oxskipdiscounts->value )
01661             return true;
01662 
01663         $sO2CView  = getViewName( 'oxobject2category', $this->getLanguage() );
01664         $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01665         $sSelect =  "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01666                      where $sO2CView.oxobjectid='".$this->getId()."' and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01667         return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01668     }
01669 
01677     public function setPrice(oxPrice $oPrice)
01678     {
01679         $this->_oPrice = $oPrice;
01680     }
01681 
01690     public function getBasePrice( $dAmount = 1 )
01691     {
01692         // override this function if you want e.g. different prices
01693         // for diff. usergroups.
01694 
01695         // Performance
01696         $myConfig = $this->getConfig();
01697         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01698             return;
01699 
01700         // GroupPrice or DB price ajusted by AmountPrice
01701         $dPrice = $this->_getAmountPrice( $dAmount );
01702 
01703 
01704         return $dPrice;
01705     }
01706 
01714     public function getPrice( $dAmount = 1 )
01715     {
01716         $myConfig = $this->getConfig();
01717         // Performance
01718         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01719             return;
01720         }
01721 
01722         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01723         if ( $dAmount != 1 || $this->_oPrice === null ) {
01724             $oPrice = oxNew( 'oxPrice' );
01725 
01726             // get base
01727             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01728 
01729             // price handling
01730             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01731                 return $this->_oPrice = $oPrice;
01732             }
01733 
01734             $this->_calculatePrice( $oPrice );
01735             if ( $dAmount != 1 ) {
01736                 return $oPrice;
01737             }
01738 
01739             $this->_oPrice = $oPrice;
01740         }
01741         return $this->_oPrice;
01742     }
01743 
01751     protected function _calculatePrice( $oPrice )
01752     {
01753         // apply VAT only if configuration requires it
01754         if ( !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01755             $this->_applyVAT( $oPrice, $this->getArticleVat() );
01756         }
01757 
01758         // apply currency
01759         $this->_applyCurrency( $oPrice );
01760         // apply discounts
01761         if ( !$this->skipDiscounts() ) {
01762             $oDiscountList = oxDiscountList::getInstance();
01763             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts($this, $this->getArticleUser() ) );
01764         }
01765 
01766         return $oPrice;
01767     }
01768 
01776     public function setArticleUser($oUser)
01777     {
01778         $this->_oUser = $oUser;
01779     }
01780 
01786     public function getArticleUser()
01787     {
01788         if ($this->_oUser) {
01789             return $this->_oUser;
01790         }
01791         return $this->getUser();
01792     }
01793 
01803     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01804     {
01805         $oUser = $oBasket->getBasketUser();
01806         $this->setArticleUser($oUser);
01807 
01808         $oBasketPrice = oxNew( 'oxPrice' );
01809 
01810         // get base price
01811         $dBasePrice = $this->getBasePrice( $dAmount );
01812 
01813         // applying select list price
01814         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01815 
01816         // setting price
01817         $oBasketPrice->setPrice( $dBasePrice );
01818 
01819         // apply VAT
01820         $this->_applyVat( $oBasketPrice, oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket ) );
01821 
01822         // apply currency
01823         $this->_applyCurrency( $oBasketPrice );
01824 
01825         // apply discounts
01826         if ( !$this->skipDiscounts() ) {
01827             // apply general discounts
01828             $oDiscountList = oxDiscountList::getInstance();
01829             $oDiscountList->applyDiscounts( $oBasketPrice, $oDiscountList->getArticleDiscounts( $this, $oUser ) );
01830         }
01831 
01832         // returning final price object
01833         return $oBasketPrice;
01834     }
01835 
01848     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01849     {
01850         $oDiscountList = oxDiscountList::getInstance();
01851         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01852     }
01853 
01862     public function delete( $sOXID = null )
01863     {
01864         if ( !$sOXID ) {
01865             $sOXID = $this->getId();
01866         }
01867         if ( !$sOXID ) {
01868             return false;
01869         }
01870 
01871 
01872         // #2339 delete first variants before deleting parent product
01873         $this->_deleteVariantRecords( $sOXID );
01874         $this->load( $sOXID );
01875         $this->_deletePics();
01876         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01877 
01878         $rs = $this->_deleteRecords( $sOXID );
01879 
01880         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01881 
01882         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01883 
01884         return $rs->EOF;
01885     }
01886 
01895     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01896     {
01897         $this->beforeUpdate();
01898 
01899         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01900         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01901             $dAmount += $iStockCount;
01902             $iStockCount = 0;
01903         }
01904         $this->oxarticles__oxstock = new oxField($iStockCount);
01905 
01906         $oDb = oxDb::getDb();
01907         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01908         $this->onChange( ACTION_UPDATE_STOCK );
01909         return $dAmount;
01910     }
01911 
01920     public function updateSoldAmount( $dAmount = 0 )
01921     {
01922         if ( !$dAmount ) {
01923             return;
01924         }
01925 
01926         $this->beforeUpdate();
01927 
01928         // article is not variant - should be updated current amount
01929         if ( !$this->oxarticles__oxparentid->value ) {
01930             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01931             $dAmount = (double) $dAmount;
01932             $oDb = oxDb::getDb();
01933             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01934         } elseif ( $this->oxarticles__oxparentid->value) {
01935             // article is variant - should be updated this article parent amount
01936             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01937             $oUpdateArticle->updateSoldAmount( $dAmount );
01938         }
01939 
01940         $this->onChange( ACTION_UPDATE );
01941 
01942         return $rs;
01943     }
01944 
01950     public function disableReminder()
01951     {
01952         $oDB = oxDb::getDb(true);
01953         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01954     }
01955 
01962     public function save()
01963     {
01964         $myConfig = $this->getConfig();
01965 
01966         $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01967         $this->oxarticles__oxicon  = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01968         $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01969         for ($i=1; $i <= $iPicCount; $i++) {
01970             if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01971                 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01972             }
01973         }
01974 
01975         if ( ( $blRet = parent::save() ) ) {
01976 
01977             // saving long descrition
01978             $this->_saveArtLongDesc();
01979         }
01980 
01981         return $blRet;
01982     }
01983 
01984 
01991     public function getPictureGallery()
01992     {
01993         $myConfig = $this->getConfig();
01994 
01995         //initialize
01996         $blMorePic = false;
01997         $aArtPics  = array();
01998         $aArtIcons = array();
01999         $iActPicId = 1;
02000         $sActPic = $this->getPictureUrl( $iActPicId );
02001 
02002         if ( oxConfig::getParameter( 'actpicid' ) ) {
02003             $iActPicId = oxConfig::getParameter('actpicid');
02004         }
02005 
02006         $oStr = getStr();
02007         $iCntr = 0;
02008         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02009         $blCheckActivePicId = true;
02010 
02011         for ( $i = 1; $i <= $iPicCount; $i++) {
02012             $sPicVal = $this->getPictureUrl( $i );
02013             $sIcoVal = $this->getIconUrl( $i );
02014             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02015                  !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02016                 if ($iCntr) {
02017                     $blMorePic = true;
02018                 }
02019                 $aArtIcons[$i]= $sIcoVal;
02020                 $aArtPics[$i]= $sPicVal;
02021                 $iCntr++;
02022 
02023                 if ($iActPicId == $i) {
02024                     $sActPic = $sPicVal;
02025                     $blCheckActivePicId = false;
02026                 }
02027 
02028             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02029                 // if picture is empty, setting active pic id to next
02030                 // picture
02031                 $iActPicId++;
02032             }
02033         }
02034 
02035         $blZoomPic  = false;
02036         $aZoomPics = array();
02037         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02038 
02039         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02040             $sVal = $this->getZoomPictureUrl($j);
02041 
02042             if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02043                 $blZoomPic = true;
02044                 $aZoomPics[$c]['id'] = $c;
02045                 $aZoomPics[$c]['file'] = $sVal;
02046                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02047                 if (!$sVal) {
02048                     $aZoomPics[$c]['file'] = "nopic.jpg";
02049                 }
02050                 $c++;
02051             }
02052         }
02053 
02054         $aPicGallery = array('ActPicID' => $iActPicId,
02055                              'ActPic' => $sActPic,
02056                              'MorePics' => $blMorePic,
02057                              'Pics' => $aArtPics,
02058                              'Icons' => $aArtIcons,
02059                              'ZoomPic' => $blZoomPic,
02060                              'ZoomPics' => $aZoomPics);
02061 
02062         return $aPicGallery;
02063     }
02064 
02078     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02079     {
02080         $myConfig = $this->getConfig();
02081 
02082         if (!isset($sOXID)) {
02083             if ( $this->getId()) {
02084                 $sOXID = $this->getId();
02085             }
02086             if (!isset ($sOXID)) {
02087                 $sOXID = $this->oxarticles__oxid->value;
02088             }
02089             if ($this->oxarticles__oxparentid->value) {
02090                 $sParentID = $this->oxarticles__oxparentid->value;
02091             }
02092         }
02093         if (!isset($sOXID)) {
02094             return;
02095         }
02096 
02097         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02098         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02099             //if article has variants then updating oxvarstock field
02100             //getting parent id
02101             if (!isset($sParentID)) {
02102                 $oDb = oxDb::getDb();
02103                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02104                 $sParentID = $oDb->getOne($sQ);
02105             }
02106             //if we have parent id then update stock
02107             if ($sParentID) {
02108                 $this->_onChangeUpdateStock($sParentID);
02109             }
02110         }
02111         //if we have parent id then update count
02112         //update count even if blUseStock is not active
02113         if ($sParentID) {
02114             $this->_onChangeUpdateVarCount($sParentID);
02115         }
02116 
02117         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02118         $this->_onChangeUpdateMinVarPrice( $sId );
02119 
02120             // reseting articles count cache if stock has changed and some
02121             // articles goes offline (M:1448)
02122             if ( $sAction === ACTION_UPDATE_STOCK ) {
02123                 $this->_onChangeStockResetCount( $sOXID );
02124             }
02125 
02126     }
02127 
02134     public function getCustomVAT()
02135     {
02136         if ( isset($this->oxarticles__oxvat->value) ) {
02137             return $this->oxarticles__oxvat->value;
02138         }
02139     }
02140 
02149     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02150     {
02151         $myConfig = $this->getConfig();
02152         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02153             return true;
02154         }
02155 
02156         // fetching DB info as its up-to-date
02157         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02158         $rs = oxDb::getDb(true)->Execute( $sQ );
02159 
02160         $iOnStock   = 0;
02161         $iStockFlag = 0;
02162         if ( $rs !== false && $rs->recordCount() > 0 ) {
02163             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02164             $iStockFlag = $rs->fields['oxstockflag'];
02165 
02166             // dodger : fremdlager is also always considered as on stock
02167             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02168                 return true;
02169             }
02170             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02171                 $iOnStock = floor( $iOnStock );
02172             }
02173         }
02174         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02175             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02176         }
02177         if ( $iOnStock >= $dAmount ) {
02178             return true;
02179         } else {
02180             if ( $iOnStock > 0 ) {
02181                 return $iOnStock;
02182             } else {
02183                 $oEx = oxNew( 'oxArticleInputException' );
02184                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02185                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02186                 return false;
02187             }
02188         }
02189     }
02190 
02191 
02199     public function getArticleLongDesc( $sOxid = null )
02200     {
02201         if ( $this->_oLongDesc === null ) {
02202 
02203             // initializing
02204             $this->_oLongDesc = new oxField();
02205 
02206 
02207             // choosing which to get..
02208             $sOxid = $sOxid === null ? $this->getId() : $sOxid;
02209             $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02210             if ( ( $sDbValue = oxDb::getDb()->getOne( "select oxlongdesc from {$sViewName} where oxid = ?", array( $sOxid ) ) ) !== false ) {
02211                 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02212             }
02213         }
02214 
02215         return $this->_oLongDesc;
02216     }
02217 
02227     protected function _setLongDesc( $sDbValue )
02228     {
02229         $this->setArticleLongDesc( $sDbValue );
02230     }
02231 
02238     public function getLongDesc()
02239     {
02240         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getArticleLongDesc()->getRawValue(), $this->getId().$this->getLanguage() );
02241     }
02242 
02251     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02252     {
02253 
02254         // setting current value
02255         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02256 
02257         // setting original value?
02258         if ( $sOrigValue ) {
02259             $this->_oLongDesc->orignalValue = $sOrigValue;
02260         }
02261     }
02262 
02268     public function getAttributes()
02269     {
02270         if ( $this->_oAttributeList === null ) {
02271             $this->_oAttributeList = oxNew( 'oxattributelist' );
02272             $this->_oAttributeList->loadAttributes( $this->getId() );
02273         }
02274 
02275         return $this->_oAttributeList;
02276     }
02277 
02286     public function appendLink( $sAddParams, $iLang = null )
02287     {
02288         if ( $sAddParams ) {
02289             if ( $iLang === null ) {
02290                 $iLang = $this->getLanguage();
02291             }
02292 
02293             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02294             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02295         }
02296     }
02297 
02306     public function getBaseSeoLink( $iLang, $blMain = false )
02307     {
02308         $oEncoder = oxSeoEncoderArticle::getInstance();
02309         if ( !$blMain ) {
02310             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02311         }
02312         return $oEncoder->getArticleMainUrl( $this, $iLang );
02313     }
02314 
02323     public function getLink( $iLang = null, $blMain = false  )
02324     {
02325         if ( !oxUtils::getInstance()->seoIsActive() ) {
02326             return $this->getStdLink( $iLang );
02327         }
02328 
02329         if ( $iLang === null ) {
02330             $iLang = $this->getLanguage();
02331         }
02332 
02333         $iLinkType = $this->getLinkType();
02334         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02335             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02336         }
02337 
02338         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02339         if ( isset($this->_aSeoAddParams[$iLang])) {
02340             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02341         }
02342 
02343         return $sUrl;
02344     }
02345 
02354     public function getMainLink( $iLang = null )
02355     {
02356         return $this->getLink( $iLang, true );
02357     }
02358 
02366     public function setLinkType( $iType )
02367     {
02368         // resetting detaisl link, to force new
02369         $this->_sDetailLink = null;
02370 
02371         // setting link type
02372         $this->_iLinkType = (int) $iType;
02373     }
02374 
02380     public function getLinkType()
02381     {
02382         return $this->_iLinkType;
02383     }
02384 
02393     public function appendStdLink( $sAddParams, $iLang = null )
02394     {
02395         if ( $sAddParams ) {
02396             if ( $iLang === null ) {
02397                 $iLang = $this->getLanguage();
02398             }
02399 
02400             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02401             $this->_aStdAddParams[$iLang] .= $sAddParams;
02402         }
02403     }
02404 
02414     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02415     {
02416         $sUrl = '';
02417         if ( $blFull ) {
02418             //always returns shop url, not admin
02419             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02420         }
02421 
02422         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02423         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02424     }
02425 
02434     public function getStdLink( $iLang = null, $aParams = array() )
02435     {
02436         if ( $iLang === null ) {
02437             $iLang = $this->getLanguage();
02438         }
02439 
02440         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02441             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02442         }
02443 
02444         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02445     }
02446 
02454     public function getStdTagLink( $sTag )
02455     {
02456         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02457         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02458     }
02459 
02465     public function getTags()
02466     {
02467         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02468         $sQ = "select oxtags from {$sViewName} where oxid = '".$this->getId()."'";
02469         $oTagCloud = oxNew('oxtagcloud');
02470         return $oTagCloud->trimTags( oxDb::getDb()->getOne( $sQ ) );
02471     }
02472 
02480     public function saveTags($sTags)
02481     {
02482         //do not allow derived update
02483         if ( !$this->allowDerivedUpdate() ) {
02484             return false;
02485         }
02486 
02487 
02488         $oTagCloud = oxNew( 'oxtagcloud' );
02489         $oTagCloud->resetTagCache();
02490         $sTags = mysql_real_escape_string( $oTagCloud->prepareTags( $sTags ) );
02491 
02492         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02493         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02494         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value ('".$this->getId()."', '{$sTags}')
02495                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02496         return oxDb::getDb()->execute( $sQ );
02497     }
02498 
02506     public function addTag($sTag)
02507     {
02508         $oDb = oxDb::getDb();
02509 
02510         $oTagCloud = oxNew('oxtagcloud');
02511         $oTagCloud->resetTagCache();
02512         $sTag = $oTagCloud->prepareTags($sTag);
02513         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02514 
02515         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02516         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02517         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = '".$this->getId()."'" ) ) {
02518             $sTailTag = $sTagSeparator . $sTag;
02519         } else {
02520             $sTailTag = $sTag;
02521         }
02522 
02523         $sTag = mysql_real_escape_string($sTag);
02524         $sTailTag = mysql_real_escape_string($sTailTag);
02525 
02526         $sTag = mysql_real_escape_string($sTag);
02527         $sTailTag = mysql_real_escape_string($sTailTag);
02528 
02529         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values ('".$this->getId()."', '{$sTag}')
02530                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02531 
02532         return $oDb->execute( $sQ );
02533     }
02534 
02540     public function getMediaUrls()
02541     {
02542         if ( $this->_aMediaUrls === null ) {
02543             $this->_aMediaUrls = oxNew("oxlist");
02544             $this->_aMediaUrls->init("oxmediaurl");
02545             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02546 
02547             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02548             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02549             $this->_aMediaUrls->selectString($sQ);
02550         }
02551         return $this->_aMediaUrls;
02552     }
02553 
02559     public function getDynImageDir()
02560     {
02561         return $this->_sDynImageDir;
02562     }
02563 
02569     public function getDispSelList()
02570     {
02571         if ($this->_aDispSelList === null) {
02572             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02573                 $this->_aDispSelList = $this->getSelectLists();
02574             }
02575         }
02576         return $this->_aDispSelList;
02577     }
02578 
02584     public function getMoreDetailLink()
02585     {
02586         if ( $this->_sMoreDetailLink == null ) {
02587 
02588             // and assign special article values
02589             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02590 
02591             // not always it is okey, as not all the time active category is the same as primary article cat.
02592             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02593                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02594             }
02595             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02596             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02597         }
02598 
02599         return $this->_sMoreDetailLink;
02600     }
02601 
02607     public function getToBasketLink()
02608     {
02609         if ( $this->_sToBasketLink == null ) {
02610             $myConfig = $this->getConfig();
02611 
02612             if ( oxUtils::getInstance()->isSearchEngine() ) {
02613                 $this->_sToBasketLink = $this->getLink();
02614             } else {
02615                 // and assign special article values
02616                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02617 
02618                 // override some classes as these should never showup
02619                 $sActClass = oxConfig::getParameter( 'cl' );
02620                 if ( $sActClass == 'thankyou') {
02621                     $sActClass = 'basket';
02622                 }
02623                 $this->_sToBasketLink .= 'cl='.$sActClass;
02624 
02625                 // this is not very correct
02626                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02627                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02628                 }
02629 
02630                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02631 
02632                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02633                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02634                 }
02635             }
02636         }
02637 
02638         return $this->_sToBasketLink;
02639     }
02640 
02646     public function getStockStatus()
02647     {
02648         return $this->_iStockStatus;
02649     }
02650 
02656     public function getDeliveryDate()
02657     {
02658         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02659             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02660         }
02661         return false;
02662     }
02663 
02669     public function getFTPrice()
02670     {
02671         if ( $oPrice = $this->getTPrice() ) {
02672             if ( $oPrice->getBruttoPrice() ) {
02673                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02674             }
02675         }
02676     }
02677 
02683     public function getFPrice()
02684     {
02685         if ( $oPrice = $this->getPrice() ) {
02686             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02687         }
02688     }
02689 
02695     public function getFNetPrice()
02696     {
02697         if ( $oPrice = $this->getPrice() ) {
02698             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02699         }
02700     }
02701 
02707     public function getPricePerUnit()
02708     {
02709         return $this->_fPricePerUnit;
02710     }
02711 
02717     public function isParentNotBuyable()
02718     {
02719         return $this->_blNotBuyableParent;
02720     }
02721 
02727     public function isNotBuyable()
02728     {
02729         return $this->_blNotBuyable;
02730     }
02731 
02739     public function setBuyableState( $blBuyable = false )
02740     {
02741         $this->_blNotBuyable = !$blBuyable;
02742     }
02743 
02752     public function getVariantList()
02753     {
02754         return $this->getVariants();
02755     }
02756 
02764     public function setSelectlist( $aSelList )
02765     {
02766         $this->_aDispSelList = $aSelList;
02767     }
02768 
02776     public function getPictureUrl( $iIndex = 1 )
02777     {
02778         if ( $iIndex ) {
02779             $sImgName = false;
02780             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02781                 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02782             }
02783 
02784             $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02785             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02786         }
02787     }
02788 
02797     public function getIconUrl( $iIndex = 0 )
02798     {
02799         $sImgName = false;
02800         $sDirname = "product/1/";
02801         if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02802             $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02803             $sDirname = "product/{$iIndex}/";
02804         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02805             $sImgName = basename( $this->oxarticles__oxicon->value );
02806             $sDirname = "product/icon/";
02807         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02808             $sImgName = basename( $this->oxarticles__oxpic1->value );
02809         }
02810 
02811         $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02812         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02813     }
02814 
02820     public function getThumbnailUrl()
02821     {
02822         $sImgName = false;
02823         $sDirname = "product/1/";
02824         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02825             $sImgName = basename( $this->oxarticles__oxthumb->value );
02826             $sDirname = "product/thumb/";
02827         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02828             $sImgName = basename( $this->oxarticles__oxpic1->value );
02829         }
02830 
02831         $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02832         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0 );
02833     }
02834 
02842     public function getZoomPictureUrl( $iIndex = '' )
02843     {
02844         $iIndex = (int) $iIndex;
02845         if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02846             $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02847             $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02848             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02849         }
02850     }
02851 
02857     public function getFileUrl()
02858     {
02859         return $this->getConfig()->getPictureUrl( 'media/' );
02860     }
02861 
02867     public function getPriceFromPrefix()
02868     {
02869         $sPricePrefics = '';
02870         if ( $this->_blIsRangePrice) {
02871             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02872         }
02873 
02874         return $sPricePrefics;
02875     }
02876 
02882     protected function _saveArtLongDesc()
02883     {
02884         $myConfig = $this->getConfig();
02885         $sShopId = $myConfig->getShopID();
02886 
02887 
02888         if ($this->_blEmployMultilanguage) {
02889             $sValue = $this->getArticleLongDesc()->getRawValue();
02890             if ( $sValue !== null ) {
02891                 $oArtExt = oxNew('oxI18n');
02892                 $oArtExt->init('oxartextends');
02893                 $oArtExt->setLanguage((int) $this->getLanguage());
02894                 if (!$oArtExt->load($this->getId())) {
02895                     $oArtExt->setId($this->getId());
02896                 }
02897                 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02898                 $oArtExt->save();
02899             }
02900         } else {
02901             $oArtExt = oxNew('oxI18n');
02902             $oArtExt->setEnableMultilang(false);
02903             $oArtExt->init('oxartextends');
02904             $aObjFields = $oArtExt->_getAllFields(true);
02905             if (!$oArtExt->load($this->getId())) {
02906                 $oArtExt->setId($this->getId());
02907             }
02908 
02909             foreach ($aObjFields as $sKey => $sValue ) {
02910                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02911                     $sField = $this->_getFieldLongName($sKey);
02912 
02913                     if (isset($this->$sField)) {
02914                         $sLongDesc = null;
02915                         if ($this->$sField instanceof oxField) {
02916                             $sLongDesc = $this->$sField->getRawValue();
02917                         } elseif (is_object($this->$sField)) {
02918                             $sLongDesc = $this->$sField->value;
02919                         }
02920                         if (isset($sLongDesc)) {
02921                             $sAEField = $oArtExt->_getFieldLongName($sKey);
02922                             $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
02923                         }
02924                     }
02925                 }
02926             }
02927             $oArtExt->save();
02928         }
02929     }
02930 
02936     protected function _skipSaveFields()
02937     {
02938         $myConfig = $this->getConfig();
02939 
02940         $this->_aSkipSaveFields = array();
02941 
02942         $this->_aSkipSaveFields[] = 'oxtimestamp';
02943         $this->_aSkipSaveFields[] = 'oxlongdesc';
02944         $this->_aSkipSaveFields[] = 'oxinsert';
02945 
02946         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02947             $this->_aSkipSaveFields[] = 'oxparentid';
02948         }
02949 
02950     }
02951 
02961     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02962     {
02963         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02964             // add prices of the same discounts
02965             if ( array_key_exists ($sKey, $aDiscounts) ) {
02966                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02967             } else {
02968                 $aDiscounts[$sKey] = $oDiscount;
02969             }
02970         }
02971         return $aDiscounts;
02972     }
02973 
02979     protected function _getGroupPrice()
02980     {
02981         $dPrice = $this->oxarticles__oxprice->value;
02982 
02983         $oUser = $this->getArticleUser();
02984         if ( $oUser ) {
02985             if ( $oUser->inGroup( 'oxidpricea' ) ) {
02986                 $dPrice = $this->oxarticles__oxpricea->value;
02987             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
02988                 $dPrice = $this->oxarticles__oxpriceb->value;
02989             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
02990                 $dPrice = $this->oxarticles__oxpricec->value;
02991             }
02992         }
02993 
02994         // #1437/1436C - added config option, and check for zero A,B,C price values
02995         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
02996             $dPrice = $this->oxarticles__oxprice->value;
02997         }
02998 
02999         return $dPrice;
03000     }
03001 
03010     protected function _getAmountPrice($dAmount = 1)
03011     {
03012         $myConfig = $this->getConfig();
03013 
03014         startProfile( "_getAmountPrice" );
03015 
03016         $dPrice = $this->_getGroupPrice();
03017         $oAmtPrices = $this->_getAmountPriceList();
03018         foreach ($oAmtPrices as $oAmPrice) {
03019             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03020                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03021                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03022                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03023             }
03024         }
03025 
03026         stopProfile( "_getAmountPrice" );
03027         return $dPrice;
03028     }
03029 
03038     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03039     {
03040         $myConfig = $this->getConfig();
03041         // #690
03042         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03043 
03044             $aSelLists = $this->getSelectLists();
03045 
03046             foreach ( $aSelLists as $key => $aSel) {
03047                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03048                     $oSel = $aSel[$aChosenList[$key]];
03049                     if ( $oSel->priceUnit =='abs' ) {
03050                         $dPrice += $oSel->price;
03051                     } elseif ( $oSel->priceUnit =='%' ) {
03052                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03053                     }
03054                 }
03055             }
03056         }
03057         return $dPrice;
03058     }
03059 
03060 
03068     protected function _fillAmountPriceList($oAmPriceList)
03069     {
03070         $myConfig = $this->getConfig();
03071         $myUtils  = oxUtils::getInstance();
03072 
03073         //modifying price
03074         $oCur = $myConfig->getActShopCurrencyObject();
03075 
03076         $oUser = $this->getArticleUser();
03077 
03078         $oDiscountList = oxDiscountList::getInstance();
03079         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03080 
03081         $oLowestPrice = null;
03082 
03083         $dBasePrice = $this->_getGroupPrice();
03084         $oLang = oxLang::getInstance();
03085 
03086         $dArticleVat = null;
03087         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03088             $dArticleVat = $this->getArticleVat();
03089         }
03090 
03091         // trying to find lowest price value
03092         foreach ($oAmPriceList as $sId => $oItem) {
03093             $oItemPrice = oxNew( 'oxprice' );
03094             if ( $oItem->oxprice2article__oxaddabs->value) {
03095                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03096                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03097                 $this->_applyCurrency( $oItemPrice, $oCur );
03098             } else {
03099                 $oItemPrice->setPrice( $dBasePrice );
03100                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03101             }
03102 
03103             if (isset($dArticleVat)) {
03104                 $this->_applyVAT($oItemPrice, $dArticleVat);
03105             }
03106 
03107             if (!$oLowestPrice) {
03108                 $oLowestPrice = $oItemPrice;
03109             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03110                 $oLowestPrice = $oItemPrice;
03111             }
03112 
03113             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03114             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03115             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03116         }
03117 
03118         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03119         return $oAmPriceList;
03120     }
03121 
03127     protected function _getVariantsIds()
03128     {
03129         $aSelect = array();
03130         $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->getId()."' " );
03131         if ( $oRs != false && $oRs->recordCount() > 0 ) {
03132             while (!$oRs->EOF) {
03133                 $aSelect[] = $oRs->fields['oxid'];
03134                 $oRs->moveNext();
03135             }
03136         }
03137         return $aSelect;
03138     }
03139 
03145     public function getArticleVat()
03146     {
03147         if (!isset($this->_dArticleVat)) {
03148             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03149         }
03150         return $this->_dArticleVat;
03151     }
03152 
03161     protected function _applyVAT( oxPrice $oPrice, $dVat )
03162     {
03163         startProfile(__FUNCTION__);
03164         $oPrice->setVAT( $dVat );
03165         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03166             $oPrice->setUserVat( $dVat );
03167         }
03168         stopProfile(__FUNCTION__);
03169     }
03170 
03178     public function applyVats( oxPrice $oPrice )
03179     {
03180         $this->_applyVAT($oPrice, $this->getArticleVat() );
03181     }
03182 
03193     protected function _applyDiscounts( $oPrice, $aDiscounts )
03194     {
03195         $oDiscountList = oxDiscountList::getInstance();
03196         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03197     }
03198 
03206     public function applyDiscountsForVariant( $oPrice )
03207     {
03208         // apply discounts
03209         if ( !$this->skipDiscounts() ) {
03210             $oDiscountList = oxDiscountList::getInstance();
03211             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03212         }
03213     }
03214 
03223     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03224     {
03225         if ( !$oCur ) {
03226             $oCur = $this->getConfig()->getActShopCurrencyObject();
03227         }
03228 
03229         $oPrice->multiply($oCur->rate);
03230     }
03231 
03232 
03241     protected function _getAttribsString(&$sAttribs, &$iCnt)
03242     {
03243         // we do not use lists here as we dont need this overhead right now
03244         $oDB = oxDb::getDb(true);
03245         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03246         $sAttribs = '';
03247         $blSep = false;
03248         $rs = $oDB->execute( $sSelect);
03249         $iCnt = 0;
03250         if ($rs != false && $rs->recordCount() > 0) {
03251             while (!$rs->EOF) {
03252                 if ( $blSep) {
03253                     $sAttribs .= ' or ';
03254                 }
03255                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03256                 $blSep = true;
03257                 $iCnt++;
03258                 $rs->moveNext();
03259             }
03260         }
03261     }
03262 
03271     protected function _getSimList($sAttribs, $iCnt)
03272     {
03273         $myConfig = $this->getConfig();
03274         $oDB      = oxDb::getDb(true);
03275 
03276         // #523A
03277         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03278         // 70% same attributes
03279         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03280             $iAttrPercent = 0.70;
03281         }
03282         // #1137V iAttributesPercent = 100 doesnt work
03283         $iHitMin = ceil( $iCnt * $iAttrPercent );
03284 
03285         // we do not use lists here as we dont need this overhead right now
03286         $aList= array();
03287         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03288                     ( $sAttribs )
03289                     and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03290                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03291 
03292         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03293         if ($rs != false && $rs->recordCount() > 0) {
03294             while (!$rs->EOF) {
03295                 $oTemp = new stdClass();    // #663
03296                 $oTemp->cnt = $rs->fields['cnt'];
03297                 $oTemp->id  = $rs->fields['oxobjectid'];
03298                 $aList[] = $oTemp;
03299                 $rs->moveNext();
03300             }
03301         }
03302         return $aList;
03303     }
03304 
03313     protected function _generateSimListSearchStr($sArticleTable, $aList)
03314     {
03315         $myConfig = $this->getConfig();
03316         $sFieldList = $this->getSelectFields();
03317         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03318         $blSep = false;
03319         $iCnt = 0;
03320         $oDb = oxDb::getDb();
03321         foreach ( $aList as $oTemp) {
03322             if ( $blSep) {
03323                 $sSearch .= ',';
03324             }
03325             $sSearch .= $oDb->quote($oTemp->id);
03326             $blSep = true;
03327             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03328                 break;
03329             }
03330             $iCnt++;
03331         }
03332 
03333         //#1741T
03334         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03335         $sSearch .= ') ';
03336 
03337         // #524A -- randomizing articles in attribute list
03338         $sSearch .= ' order by rand() ';
03339 
03340         return $sSearch;
03341     }
03342 
03351     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03352     {
03353 
03354         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03355         $sO2CView = getViewName( 'oxobject2category' );
03356 
03357         // we do not use lists here as we dont need this overhead right now
03358         if ( !$blSearchPriceCat ) {
03359             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03360                          {$sCatView}.oxid = oxobject2category.oxcatnid
03361                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03362         } else {
03363             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03364                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03365                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03366         }
03367         return $sSelect;
03368     }
03369 
03375     protected function _generateSearchStrForCustomerBought()
03376     {
03377         $sArtTable = $this->getViewName();
03378         $sOrderArtTable = getViewName( 'oxorderarticles' );
03379 
03380         // fetching filter params
03381         $sIn = " '{$this->oxarticles__oxid->value}' ";
03382         if ( $this->oxarticles__oxparentid->value ) {
03383 
03384             // adding article parent
03385             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03386             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03387 
03388         } else {
03389             $sParentIdForVariants = $this->getId();
03390         }
03391 
03392         // adding variants
03393         $oDb = oxDb::getDb(true);
03394         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03395         if ( $oRs != false && $oRs->recordCount() > 0) {
03396             while ( !$oRs->EOF ) {
03397                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03398                 $oRs->moveNext();
03399             }
03400         }
03401 
03402         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03403         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03404 
03405         // building sql (optimized)
03406         $sQ = "select distinct {$sArtTable}.* from (
03407                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03408                ) as suborder
03409                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03410                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03411                where {$sArtTable}.oxid not in ( {$sIn} )
03412                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03413 
03414         /* non optimized, but could be used if index forcing is not supported
03415         // building sql
03416         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03417                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03418                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03419                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03420                and ".$this->getSqlActiveSnippet();
03421         */
03422 
03423         return $sQ;
03424     }
03425 
03435     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03436     {
03437         $sCategoryView = getViewName('oxcategories');
03438         $sO2CView = getViewName('oxobject2category');
03439 
03440         $oDb    = oxDb::getDb();
03441         $sOXID  = $oDb->quote($sOXID);
03442         $sCatId = $oDb->quote($sCatId);
03443 
03444         if (!$dPriceFromTo) {
03445             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03446             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03447             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03448             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03449         } else {
03450             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03451             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03452             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03453             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03454         }
03455         return $sSelect;
03456     }
03457 
03463     protected function _getAmountPriceList()
03464     {
03465         if ($this->_oAmountPriceList) {
03466             return $this->_oAmountPriceList;
03467         }
03468 
03469         $myConfig = $this->getConfig();
03470 
03471         $sArtID  = $this->getId();
03472 
03473         // #1690C - Scale prices and variants
03474         if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03475             $sArtID = $this->oxarticles__oxparentid->value;
03476         }
03477 
03478         $sArtID = mysql_real_escape_string($sArtID);
03479 
03480         //collecting assigned to article amount-price list
03481         $oAmPriceList = oxNew( 'oxlist');
03482         $oAmPriceList->init('oxbase', 'oxprice2article');
03483 
03484         $sShopID = $myConfig->getShopID();
03485         if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03486             $sShopSelect = '1';
03487         } else {
03488             $sShopSelect = " oxshopid =  '$sShopID' ";
03489         }
03490 
03491         $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03492 
03493         // prepare abs prices if currently having percentages
03494         $oBasePrice = $this->_getGroupPrice();
03495         foreach ($oAmPriceList as $oAmPrice) {
03496             if ($oAmPrice->oxprice2article__oxaddperc->value) {
03497                 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03498             }
03499         }
03500 
03501         $this->_oAmountPriceList = $oAmPriceList;
03502         return $oAmPriceList;
03503     }
03504 
03512     protected function _isFieldEmpty( $sFieldName )
03513     {
03514         $mValue = $this->$sFieldName->value;
03515 
03516         if ( is_null( $mValue ) ) {
03517             return true;
03518         }
03519 
03520         if ( $mValue === '' ) {
03521             return true;
03522         }
03523 
03524         $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03525 
03526         if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03527             return true;
03528         }
03529 
03530 
03531         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03532             return true;
03533         }
03534 
03535         $sFieldName = strtolower($sFieldName);
03536 
03537         if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03538             return true;
03539         }
03540 
03541         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03542             return true;
03543         }
03544 
03545         return false;
03546     }
03547 
03555     protected function _assignParentFieldValue($sFieldName)
03556     {
03557         if (!($oParentArticle = $this->getParentArticle())) {
03558             return;
03559         }
03560 
03561         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03562 
03563         // assigning only theese which parent article has
03564         if ( $oParentArticle->$sCopyFieldName != null ) {
03565 
03566             // only overwrite database values
03567             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03568                 return;
03569             }
03570 
03571             //do not copy certain fields
03572             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03573                 return;
03574             }
03575 
03576             //COPY THE VALUE
03577             // assigning images from parent only if variant has no master image (#1807)
03578             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03579                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03580                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03581                 }
03582             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03583                 // for zoom images checking master image with specified index
03584                 // assign from parent only if no pictures to variant are added
03585                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03586                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03587                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03588                 }
03589             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03590                 // if no pics generated for variants, load all from
03591                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03592             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03593                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03594             }
03595         }
03596     }
03597 
03603     public function getParentArticle()
03604     {
03605         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03606             if ( !isset( self::$_aLoadedParents[$sParentId] ) ) {
03607                 self::$_aLoadedParents[$sParentId] = oxNew( 'oxarticle' );
03608                 self::$_aLoadedParents[$sParentId]->_blSkipAbPrice  = true;
03609                 self::$_aLoadedParents[$sParentId]->_blLoadPrice    = false;
03610                 self::$_aLoadedParents[$sParentId]->_blLoadVariants = false;
03611                 self::$_aLoadedParents[$sParentId]->load( $sParentId );
03612             }
03613             return self::$_aLoadedParents[$sParentId];
03614         }
03615     }
03616 
03624     protected function _getParentAricle()
03625     {
03626         return $this->getParentArticle();
03627     }
03628 
03634     protected function _assignParentFieldValues()
03635     {
03636         startProfile('articleAssignParentInternal');
03637         if ( $this->oxarticles__oxparentid->value ) {
03638             // yes, we are in fact a variant
03639             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03640                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03641                     $this->_assignParentFieldValue( $sFieldName );
03642                 }
03643 
03644                 //assing long description
03645                 $sLongDesc = $this->getArticleLongDesc()->getRawValue();
03646                 if ( $sLongDesc === null || $sLongDesc == '' ) {
03647                     $this->setArticleLongDesc( $this->getParentArticle()->getArticleLongDesc()->getRawValue() );
03648                 }
03649             }
03650         }
03651         stopProfile('articleAssignParentInternal');
03652     }
03653 
03659     protected function _assignNotBuyableParent()
03660     {
03661         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03662              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03663             $this->_blNotBuyableParent = true;
03664 
03665         }
03666     }
03667 
03673     protected function _assignStock()
03674     {
03675         $myConfig = $this->getConfig();
03676         // -----------------------------------
03677         // stock
03678         // -----------------------------------
03679 
03680         // #1125 A. must round (using floor()) value taken from database and cast to int
03681         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03682             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03683         }
03684         //GREEN light
03685         $this->_iStockStatus = 0;
03686 
03687         // if we have flag /*1 or*/ 4 - we show always green light
03688         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03689             //ORANGE light
03690             $iStock = $this->oxarticles__oxstock->value;
03691 
03692             if ($this->_blNotBuyableParent) {
03693                 $iStock = $this->oxarticles__oxvarstock->value;
03694             }
03695 
03696 
03697             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03698                 $this->_iStockStatus = 1;
03699             }
03700 
03701             //RED light
03702             if ($iStock <= 0) {
03703                 $this->_iStockStatus = -1;
03704             }
03705         }
03706 
03707 
03708         // stock
03709         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03710             $iOnStock = $this->oxarticles__oxstock->value;
03711             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03712                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03713             }
03714             if ($iOnStock <= 0) {
03715                 $this->_blNotBuyable = true;
03716             }
03717         }
03718 
03719         //exceptional handling for variant parent stock:
03720         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03721             $this->_blNotBuyable = false;
03722             //but then at least setting notBuaybleParent to true
03723             $this->_blNotBuyableParent = true;
03724         }
03725 
03726         //special treatment for lists when blVariantParentBuyable config option is set to false
03727         //then we just hide "to basket" button.
03728         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03729         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03730             $this->_blNotBuyable = true;
03731         }
03732 
03733         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03734         if ($this->_blNotBuyableParent && count($this->getVariants()) == 0) {
03735             $this->_blNotBuyable = true;
03736         }
03737     }
03738 
03744     protected function _assignPrices()
03745     {
03746         $myConfig = $this->getConfig();
03747 
03748         // Performance
03749         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03750             return;
03751         }
03752 
03753         // compute price
03754         $dPrice = $this->getPrice()->getBruttoPrice();
03755 
03756         $oCur = $myConfig->getActShopCurrencyObject();
03757         //price per unit handling
03758         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03759             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03760         }
03761 
03762         //getting min and max prices of variants
03763         if ( $this->_hasAnyVariant() ) {
03764             $this->_applyRangePrice();
03765         }
03766     }
03767 
03773     protected function _assignPersistentParam()
03774     {
03775         // Persistent Parameter Handling
03776         $aPersParam     = oxSession::getVar( 'persparam');
03777         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03778             $this->_aPersistParam = $aPersParam[$this->getId()];
03779         }
03780     }
03781 
03787     protected function _assignDynImageDir()
03788     {
03789         $myConfig = $this->getConfig();
03790 
03791         $sThisShop = $this->oxarticles__oxshopid->value;
03792 
03793         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03794         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03795         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03796         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03797     }
03798 
03804     protected function _assignComparisonListFlag()
03805     {
03806         // #657 add a flag if article is on comparisonlist
03807 
03808         $aItems = oxSession::getVar('aFiltcompproducts');
03809         if ( isset( $aItems[$this->getId()])) {
03810             $this->_blIsOnComparisonList = true;
03811         }
03812     }
03813 
03819     protected function _assignAttributes()
03820     {
03821         //#1029T load attributes
03822         //#1078S removed check for module "Produktvergleich"
03823         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03824             $this->getAttributes();
03825         }
03826     }
03827 
03828 
03836     protected function _insert()
03837     {
03838         // set oxinsert
03839         $iInsertTime = time();
03840         $now = date('Y-m-d H:i:s', $iInsertTime);
03841         $this->oxarticles__oxinsert    = new oxField( $now );
03842         $this->oxarticles__oxtimestamp = new oxField( $now );
03843         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03844             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03845         }
03846 
03847         return parent::_insert();
03848     }
03849 
03855     protected function _update()
03856     {
03857 
03858         $this->_skipSaveFields();
03859 
03860         $myConfig = $this->getConfig();
03861 
03862 
03863         return parent::_update();
03864     }
03865 
03873     protected function _deleteRecords($sOXID)
03874     {
03875         $oDB = oxDb::getDb();
03876 
03877         $sOXID = $oDB->quote($sOXID);
03878 
03879         //delete the record
03880         $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
03881         $oDB->execute( $sDelete);
03882 
03883         //remove other records
03884         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03885         $oDB->execute( $sDelete);
03886 
03887         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03888         $oDB->execute( $sDelete);
03889 
03890         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03891         $oDB->execute( $sDelete);
03892 
03893         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03894         $oDB->execute( $sDelete);
03895 
03896         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03897         $oDB->execute( $sDelete);
03898 
03899         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03900         $oDB->execute( $sDelete);
03901 
03902         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03903         $oDB->execute( $sDelete);
03904 
03905         //#1508C - deleting oxobject2delivery entries added
03906         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03907         $oDB->execute( $sDelete);
03908 
03909         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03910         $oDB->execute( $sDelete);
03911 
03912         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03913         $rs = $oDB->execute( $sDelete );
03914 
03915         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03916         $rs = $oDB->execute( $sDelete );
03917 
03918 
03919         return $rs;
03920     }
03921 
03929     protected function _deleteVariantRecords($sOXID)
03930     {
03931         $oDB = oxDb::getDb();
03932         //collect variants to remove recursively
03933         $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDB->quote($sOXID);
03934         $rs = $oDB->execute( $sVariants);
03935         if ($rs != false && $rs->recordCount() > 0) {
03936             while (!$rs->EOF) {
03937                 $this->delete( $rs->fields[0]);
03938                 $rs->moveNext();
03939             }
03940         }
03941     }
03942 
03952     protected function _resetCacheAndArticleCount( $sOxid )
03953     {
03954         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03955     }
03956 
03962     protected function _deletePics()
03963     {
03964         $myUtilsPic = oxUtilsPic::getInstance();
03965         $myConfig   = $this->getConfig();
03966         $oPictureHandler = oxPictureHandler::getInstance();
03967 
03968         //deleting custom main icon
03969         $oPictureHandler->deleteMainIcon( $this );
03970 
03971         //deleting custom thumbnail
03972         $oPictureHandler->deleteThumbnail( $this );
03973 
03974         $sAbsDynImageDir = $myConfig->getPictureDir(false);
03975 
03976         // deleting master image and all generated images
03977         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03978         for ( $i = 1; $i <= $iPicCount; $i++ ) {
03979             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
03980         }
03981     }
03982 
03992     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
03993     {
03994 
03995         $myUtilsCount = oxUtilsCount::getInstance();
03996 
03997         if ( $sVendorId ) {
03998             $myUtilsCount->resetVendorArticleCount( $sVendorId );
03999         }
04000 
04001         if ( $sManufacturerId ) {
04002             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04003         }
04004 
04005         //also reseting category counts
04006         $oDb = oxDb::getDb();
04007         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04008         $oRs = $oDb->execute( $sQ );
04009         if ( $oRs !== false && $oRs->recordCount() > 0) {
04010             while ( !$oRs->EOF ) {
04011                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04012                 $oRs->moveNext();
04013             }
04014         }
04015     }
04016 
04024     protected function _onChangeUpdateStock( $sParentID )
04025     {
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 
04062     protected function _onChangeStockResetCount( $sOxid )
04063     {
04064         $myConfig = $this->getConfig();
04065 
04066         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04067            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04068 
04069                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04070         }
04071     }
04072 
04080     protected function _onChangeUpdateVarCount( $sParentID )
04081     {
04082         $oDb = oxDb::getDb();
04083         $sParentIdQuoted = $oDb->quote($sParentID);
04084         $sQ = 'select count(*) as varcount from oxarticles where oxparentid = '.$sParentIdQuoted;
04085         $iVarCount = (int) $oDb->getOne($sQ);
04086 
04087         $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = '.$sParentIdQuoted;
04088         $oDb->execute($sQ);
04089     }
04090 
04098     protected function _onChangeUpdateMinVarPrice( $sParentID )
04099     {
04100         $oDb = oxDb::getDb();
04101         $sParentIdQuoted = $oDb->quote($sParentID);
04102         //#M0000883 (Sarunas)
04103         $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04104         $dVarMinPrice = $oDb->getOne($sQ);
04105 
04106         $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04107 
04108         $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04109 
04110         if ($dVarMinPrice) {
04111             if ($blParentBuyable) {
04112                 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04113             }
04114 
04115         } else {
04116             $dVarMinPrice = $dParentPrice;
04117         }
04118 
04119         if ( $dVarMinPrice ) {
04120             $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04121             $oDb->execute($sQ);
04122         }
04123     }
04124 
04125 
04131     protected function _applyRangePrice()
04132     {
04133         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04134         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04135             return;
04136         }
04137 
04138         $this->_blIsRangePrice = false;
04139 
04140         // if parent is buyable - do not apply range price calcculations
04141         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04142             return;
04143         }
04144 
04145         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04146             //#2509 we cannot force brutto price here, as netto price can be added to DB
04147             // $this->getPrice()->setBruttoPriceMode();
04148             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04149             $this->_blIsRangePrice = true;
04150             $this->_calculatePrice( $this->getPrice() );
04151             return;
04152         }
04153 
04154         $aPrices = array();
04155 
04156         if (!$this->_blNotBuyableParent) {
04157             $aPrices[] = $this->getPrice()->getBruttoPrice();
04158         }
04159 
04160         $aVariants = $this->getVariants(false);
04161 
04162         if (count($aVariants)) {
04163             foreach ($aVariants as $sKey => $oVariant) {
04164                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04165             }
04166         }
04167 
04168         if ( count( $aPrices ) ) {
04169             $dMinPrice = min( $aPrices );
04170             $dMaxPrice = max( $aPrices );
04171         }
04172 
04173         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04174             $this->getPrice()->setBruttoPriceMode();
04175             $this->getPrice()->setPrice($dMinPrice);
04176         }
04177 
04178         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04179             $this->getPrice()->setBruttoPriceMode();
04180             $this->getPrice()->setPrice($dMinPrice);
04181             $this->_blIsRangePrice = true;
04182         }
04183     }
04184 
04191     public function getProductId()
04192     {
04193         return $this->getId();
04194     }
04195 
04201     public function getProductParentId()
04202     {
04203         return $this->oxarticles__oxparentid->value;
04204     }
04205 
04211     public function isOrderArticle()
04212     {
04213         return false;
04214     }
04215 
04221     public function isVariant()
04222     {
04223         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04224     }
04225 
04231     public function isMdVariant()
04232     {
04233         $oMdVariant = oxNew( "oxVariantHandler" );
04234 
04235         return $oMdVariant->isMdVariant($this);
04236     }
04237 
04245     public function getSqlForPriceCategories($sFields = '')
04246     {
04247         if (!$sFields) {
04248             $sFields = 'oxid';
04249         }
04250         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04251         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04252         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04253                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04254                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04255     }
04256 
04264     public function inPriceCategory( $sCatNid )
04265     {
04266         $oDb = oxDb::getDb();
04267 
04268         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04269         $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04270         return (bool) $oDb->getOne(
04271             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04272            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04273            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04274            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04275            .")"
04276         );
04277     }
04278 
04284     public function getMdVariants()
04285     {
04286         if ( $this->_oMdVariants ) {
04287             return $this->_oMdVariants;
04288         }
04289 
04290         $oParentArticle = $this->getParentArticle();
04291         if ( $oParentArticle ) {
04292             $oVariants = $oParentArticle->getVariants();
04293         } else {
04294             $oVariants = $this->getVariants();
04295         }
04296 
04297         $oVariantHandler = oxNew( "oxVariantHandler" );
04298         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04299 
04300         return $this->_oMdVariants;
04301     }
04302 
04308     public function getMdSubvariants()
04309     {
04310         return $this->getMdVariants()->getMdSubvariants();
04311     }
04312 
04320     protected function _hasMasterImage( $iIndex )
04321     {
04322         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04323 
04324         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04325             return false;
04326         }
04327         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04328             return false;
04329         }
04330 
04331         $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04332 
04333         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04334             return true;
04335         }
04336 
04337         return false;
04338     }
04339 
04348     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04349     {
04350         if ( $sFieldName ) {
04351             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04352             return $this->$sFieldName->value;
04353         }
04354     }
04355 
04363     public function getMasterZoomPictureUrl( $iIndex )
04364     {
04365         $sPicUrl  = false;
04366         $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04367 
04368         if ( $sPicName && $sPicName != "nopic.jpg" ) {
04369             $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04370             if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04371                 $sPicUrl = false;
04372             }
04373         }
04374 
04375         return $sPicUrl;
04376     }
04377 }