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         $aIds = array($this->getId());
00883 
00884         if ( $this->oxarticles__oxparentid->value ) {
00885             $aIds[] = $this->oxarticles__oxparentid->value;
00886         }
00887 
00888         // showing variant reviews ..
00889         if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00890             $aAdd = $this->_getVariantsIds();
00891             if (is_array($aAdd)) {
00892                 $aIds = array_merge($aIds, $aAdd);
00893             }
00894         }
00895 
00896         $oReview = oxNew('oxreview');
00897         $oRevs = $oReview->loadList('oxarticle', $aIds);
00898 
00899         //if no review found, return null
00900         if ( $oRevs->count() < 1 ) {
00901             return null;
00902         }
00903 
00904         return $oRevs;
00905     }
00906 
00912     public function getCrossSelling()
00913     {
00914         $oCrosslist = oxNew( "oxarticlelist");
00915         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00916         if ( $oCrosslist->count() ) {
00917             return $oCrosslist;
00918         }
00919     }
00920 
00926     public function getAccessoires()
00927     {
00928         $myConfig = $this->getConfig();
00929 
00930         // Performance
00931         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00932             return;
00933         }
00934 
00935         $oAcclist = oxNew( "oxarticlelist");
00936         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00937         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00938 
00939         if ( $oAcclist->count()) {
00940             return $oAcclist;
00941         }
00942     }
00943 
00949     public function getSimilarProducts()
00950     {
00951         // Performance
00952         $myConfig = $this->getConfig();
00953         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
00954             return;
00955         }
00956 
00957         $sArticleTable = $this->getViewName();
00958 
00959         $sAttribs = '';
00960         $iCnt = 0;
00961         $this->_getAttribsString($sAttribs, $iCnt);
00962 
00963         if ( !$sAttribs) {
00964             return null;
00965         }
00966 
00967         $aList = $this->_getSimList($sAttribs, $iCnt);
00968 
00969         if ( count( $aList ) ) {
00970             uasort( $aList, 'cmpart');
00971 
00972             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
00973 
00974             $oSimilarlist = oxNew( 'oxarticlelist' );
00975             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
00976             $oSimilarlist->selectString( $sSearch);
00977 
00978             return $oSimilarlist;
00979         }
00980     }
00981 
00987     public function getCustomerAlsoBoughtThisProducts()
00988     {
00989         // Performance
00990         $myConfig = $this->getConfig();
00991         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
00992             return;
00993         }
00994 
00995         // selecting products that fits
00996         $sQ = $this->_generateSearchStrForCustomerBought();
00997 
00998         $oArticles = oxNew( 'oxarticlelist' );
00999         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01000         $oArticles->selectString( $sQ );
01001         if ( $oArticles->count() ) {
01002             return $oArticles;
01003         }
01004     }
01005 
01012     public function loadAmountPriceInfo()
01013     {
01014         $myConfig = $this->getConfig();
01015         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01016             return array();
01017         }
01018 
01019         if ( $this->_oAmountPriceInfo === null ) {
01020             $this->_oAmountPriceInfo = array();
01021             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01022                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01023 
01024             }
01025         }
01026         return $this->_oAmountPriceInfo;
01027     }
01028 
01036     public function getSelectLists($sKeyPrefix = null)
01037     {
01038         //#1468C - more then one article in basket with different selectlist...
01039         //optionall function parameter $sKeyPrefix added, used only in basket.php
01040         $sKey = $this->getId();
01041         if ( isset( $sKeyPrefix ) ) {
01042             $sKey = $sKeyPrefix.'__'.$this->getId();
01043         }
01044 
01045         if ( !isset( self::$_aSelList[$sKey] ) ) {
01046             $oDb = oxDb::getDb();
01047             $sSLViewName = getViewName( 'oxselectlist' );
01048 
01049             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01050                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01051 
01052             // all selectlists this article has
01053             $oLists = oxNew( 'oxlist' );
01054             $oLists->init( 'oxselectlist' );
01055             $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01056 
01057             //#1104S if this is variant ant it has no selectlists, trying with parent
01058             if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01059                 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01060             }
01061 
01062             $dVat = 0;
01063             if ( $this->getPrice() != null ) {
01064                 $dVat = $this->getPrice()->getVat();
01065             }
01066 
01067             $iCnt = 0;
01068             self::$_aSelList[$sKey] = array();
01069             foreach ( $oLists as $oSelectlist ) {
01070                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01071                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01072                 $iCnt++;
01073             }
01074         }
01075         return self::$_aSelList[$sKey];
01076     }
01077 
01085     protected function _hasAnyVariant( $blForceCoreTable = null )
01086     {
01087         $blHas = false;
01088         if ( ( $sId = $this->getId() ) ) {
01089             $sArticleTable = $this->getViewName( $blForceCoreTable );
01090             $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01091         }
01092         return $blHas;
01093     }
01094 
01100     public function hasMdVariants()
01101     {
01102         return $this->_blHasMdVariants;
01103     }
01104 
01114     public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01115     {
01116         $iLimit = (int) $iLimit;
01117         if ( !isset($this->_aVariantSelections[$iLimit])) {
01118             $this->_aVariantSelections[$iLimit] = false;
01119             if ( ( $oVariantList = $this->getVariants() ) ) {
01120                 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $oVariantList, $aFilterIds, $sActVariantId, $iLimit );
01121             }
01122         }
01123         return $this->_aVariantSelections[$iLimit];
01124     }
01125 
01134     public function getSelections( $iLimit = null, $aFilter = null )
01135     {
01136         $sId = $this->getId() . ( (int) $iLimit );
01137         if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01138 
01139             $oDb = oxDb::getDb();
01140             $sSLViewName = getViewName( 'oxselectlist' );
01141 
01142             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01143                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01144 
01145             if ( ( $iLimit = (int) $iLimit ) ) {
01146                 $sQ .= " limit $iLimit ";
01147             }
01148 
01149             // vat value for price
01150             $dVat = 0;
01151             if ( ( $oPrice = $this->getPrice() ) != null ) {
01152                 $dVat = $oPrice->getVat();
01153             }
01154 
01155             // all selectlists this article has
01156             $oList = oxNew( 'oxlist' );
01157             $oList->init( 'oxselectlist' );
01158             $oList->getBaseObject()->setVat( $dVat );
01159             $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01160 
01161             //#1104S if this is variant and it has no selectlists, trying with parent
01162             if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01163                 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01164             }
01165 
01166             self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01167         }
01168 
01169         if ( self::$_aSelections[$sId] ) {
01170             // marking active from filter
01171             $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01172             if ( $aFilter ) {
01173                 $iSelIdx = 0;
01174                 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01175                     if ( isset( $aFilter[$iSelIdx] ) ) {
01176                         $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01177                     }
01178                     $iSelIdx++;
01179                 }
01180             }
01181         }
01182 
01183         return self::$_aSelections[$sId];
01184     }
01185 
01195     protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01196     {
01197         $oVariants = array();
01198         if ( ( $sId = $this->getId() ) ) {
01199             //do not load me as a parent later
01200             self::$_aLoadedParents[$sId] = $this;
01201 
01202             $myConfig = $this->getConfig();
01203 
01204             if ( !$this->_blLoadVariants ||
01205                 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01206                 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01207                 return $oVariants;
01208             }
01209 
01210             // cache
01211             $sCacheKey = $blSimple ? "simple" : "full";
01212             if ( $blRemoveNotOrderables ) {
01213                 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01214                    return $this->_aVariants[$sCacheKey];
01215                 } else {
01216                     $this->_aVariants[$sCacheKey] = & $oVariants;
01217                 }
01218             } elseif ( !$blRemoveNotOrderables ) {
01219                 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01220                     return $this->_aVariantsWithNotOrderables[$sCacheKey];
01221                 } else {
01222                     $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01223                 }
01224             }
01225 
01226             if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01227 
01228                 //load simple variants for lists
01229                 if ( $blSimple ) {
01230                     $oVariants = oxNew( 'oxsimplevariantlist' );
01231                     $oVariants->setParent( $this );
01232                 } else {
01233                     //loading variants
01234                     $oVariants = oxNew( 'oxarticlelist' );
01235                     $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01236                 }
01237 
01238                 startProfile("selectVariants");
01239                 $blUseCoreTable = (bool) $blForceCoreTable;
01240                 $oBaseObject = $oVariants->getBaseObject();
01241                 $oBaseObject->setLanguage( $this->getLanguage() );
01242 
01243 
01244                 $sArticleTable = $this->getViewName( $blUseCoreTable );
01245 
01246                 $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01247                            $this->getActiveCheckQuery( $blUseCoreTable ) .
01248                            $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01249                            " order by $sArticleTable.oxsort";
01250 
01251                 $oVariants->selectString( $sSelect );
01252 
01253                 //if this is multidimensional variants, make additional processing
01254                 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01255                     $oMdVariants = oxNew( "oxVariantHandler" );
01256                     $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01257                 }
01258                 stopProfile("selectVariants");
01259             }
01260 
01261             //if we have variants then depending on config option the parent may be non buyable
01262             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01263                 $this->_blNotBuyableParent = true;
01264             }
01265 
01266             //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01267             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01268                 $this->_blNotBuyable = true;
01269             }
01270         }
01271         return $oVariants;
01272     }
01273 
01282     public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01283     {
01284         return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01285     }
01286 
01295     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null  )
01296     {
01297         return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01298     }
01299 
01305     public function getSimpleVariants()
01306     {
01307         if ( $this->oxarticles__oxvarcount->value) {
01308             return $this->getVariants();
01309         }
01310     }
01311 
01320     public function getAdminVariants( $sLanguage = null )
01321     {
01322         $oVariants = oxNew( 'oxarticlelist');
01323         if ( ( $sId = $this->getId() ) ) {
01324 
01325             $oBaseObj = $oVariants->getBaseObject();
01326 
01327             if ( is_null( $sLanguage ) ) {
01328                 $oBaseObj->setLanguage( oxLang::getInstance()->getBaseLanguage() );
01329             } else {
01330                 $oBaseObj->setLanguage( $sLanguage );
01331             }
01332 
01333             $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01334             $oVariants->selectString( $sSql );
01335 
01336             //if we have variants then depending on config option the parent may be non buyable
01337             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01338                 //$this->blNotBuyable = true;
01339                 $this->_blNotBuyableParent = true;
01340             }
01341         }
01342 
01343         return $oVariants;
01344     }
01345 
01353     public function getCategory()
01354     {
01355         $oCategory = oxNew( 'oxcategory' );
01356         $oCategory->setLanguage( $this->getLanguage() );
01357 
01358         // variant handling
01359         $sOXID = $this->getId();
01360         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01361             $sOXID = $this->oxarticles__oxparentid->value;
01362         }
01363 
01364         if ( $sOXID ) {
01365             // if the oxcategory instance of this article is not cached
01366             if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01367                 startPRofile( 'getCategory' );
01368                 $oStr = getStr();
01369                 $sWhere   = $oCategory->getSqlActiveSnippet();
01370                 $sSelect  = $this->_generateSearchStr( $sOXID );
01371                 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01372 
01373                 // category not found ?
01374                 if ( !$oCategory->assignRecord( $sSelect ) ) {
01375 
01376                     $sSelect  = $this->_generateSearchStr( $sOXID, true );
01377                     $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01378 
01379                     // looking for price category
01380                     if ( !$oCategory->assignRecord( $sSelect ) ) {
01381                         $oCategory = null;
01382                     }
01383                 }
01384                 // add the category instance to cache
01385                 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01386                 stopPRofile( 'getCategory' );
01387             } else {
01388                // if the oxcategory instance is cached
01389                $oCategory = $this->_aCategoryCache[ $sOXID ];
01390             }
01391         }
01392 
01393         return $oCategory;
01394     }
01395 
01404     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01405     {
01406         $myConfig = $this->getConfig();
01407         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01408             return self::$_aArticleCats[$this->getId()];
01409         }
01410 
01411         // variant handling
01412         $sOXID = $this->getId();
01413         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01414             $sOXID = $this->oxarticles__oxparentid->value;
01415         }
01416 
01417         // we do not use lists here as we dont need this overhead right now
01418         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01419         $oDB = oxDb::getDb(true);
01420         $rs = $oDB->execute( $sSql );
01421 
01422 
01423         $aRet = array();
01424 
01425         if ($rs != false && $rs->recordCount() > 0) {
01426             while (!$rs->EOF) {
01427                 $aRet[] = $rs->fields['oxcatnid'];
01428                 $rs->moveNext();
01429             }
01430         }
01431 
01432         // adding price categories if such exists
01433         $sSql = $this->getSqlForPriceCategories();
01434 
01435         $oDB = oxDb::getDb( true );
01436         $rs = $oDB->execute( $sSql );
01437 
01438         if ($rs != false && $rs->recordCount() > 0) {
01439             while (!$rs->EOF) {
01440 
01441                 if ( is_array( $rs->fields ) ) {
01442                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01443                 }
01444 
01445 
01446                 if ( !$aRet[$rs->fields['oxid']] ) {
01447                     $aRet[] = $rs->fields['oxid'];
01448                 }
01449                 $rs->moveNext();
01450             }
01451         }
01452 
01453         return self::$_aArticleCats[$this->getId()] = $aRet;
01454     }
01455 
01464     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01465     {
01466         $sO2CView = $this->_getObjectViewName('oxobject2category');
01467         $sCatView = $this->_getObjectViewName('oxcategories');
01468         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01469         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01470         if ( $blActCats ) {
01471             $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 ";
01472         }
01473         $sSelect .= 'order by oxobject2category.oxtime ';
01474         return $sSelect;
01475     }
01476 
01486     public function getVendor( $blShopCheck = true )
01487     {
01488         if ( ( $sVendorId = $this->getVendorId() ) ) {
01489             $oVendor = oxNew( 'oxvendor' );
01490         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01491             $oVendor = oxNew( 'oxi18n' );
01492             $oVendor->init('oxvendor');
01493             $oVendor->setReadOnly( true );
01494             $sVendorId = $this->oxarticles__oxvendorid->value;
01495         }
01496         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01497             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01498                 $oVendor->setReadOnly( true );
01499             }
01500             return $oVendor;
01501         }
01502         return null;
01503     }
01504 
01512     public function getVendorId( $blForceReload = false )
01513     {
01514         $sVendorId = false;
01515         if ( $this->oxarticles__oxvendorid->value ) {
01516             if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01517                 return self::$_aArticleVendors[$this->getId()];
01518             }
01519             $oDb = oxDb::getDb();
01520             $sVendorIdQuoted = $oDb->quote($this->oxarticles__oxvendorid->value);
01521             $sQ = "select oxid from ".getViewName('oxvendor')." where oxid=$sVendorIdQuoted";
01522             self::$_aArticleVendors[$this->getId()] = $sVendorId = $oDb->getOne( $sQ );
01523         }
01524         return $sVendorId;
01525     }
01526 
01534     public function getManufacturerId( $blForceReload = false )
01535     {
01536         $sManufacturerId = false;
01537         if ( $this->oxarticles__oxmanufacturerid->value ) {
01538             if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01539                 return self::$_aArticleManufacturers[$this->getId()];
01540             }
01541             $oDb = oxDb::getDb();
01542             $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid=".$oDb->quote($this->oxarticles__oxmanufacturerid->value);
01543             self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = $oDb->getOne( $sQ );
01544         }
01545         return $sManufacturerId;
01546     }
01547 
01557     public function getManufacturer( $blShopCheck = true )
01558     {
01559         $oManufacturer = oxNew( 'oxmanufacturer' );;
01560         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01561              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01562             $oManufacturer->setReadOnly( true );
01563             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01564         }
01565 
01566         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01567             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01568                 $oManufacturer->setReadOnly( true );
01569             }
01570             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01571         } else {
01572             $oManufacturer = null;
01573         }
01574 
01575         return $oManufacturer;
01576     }
01577 
01585     public function inCategory( $sCatNid)
01586     {
01587         return in_array( $sCatNid, $this->getCategoryIds());
01588     }
01589 
01598     public function isAssignedToCategory( $sCatId )
01599     {
01600         // variant handling
01601         $sOXID = $this->getId();
01602         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01603             $sOXID = $this->oxarticles__oxparentid->value;
01604         }
01605 
01606         $oDB = oxDb::getDb();
01607         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01608         $sOXID = $oDB->getOne( $sSelect);
01609         // article is assigned to passed category!
01610         if ( isset( $sOXID) && $sOXID) {
01611             return true;
01612         }
01613 
01614         // maybe this category is price category ?
01615         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01616             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01617             if ( $dPriceFromTo > 0) {
01618                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01619                 $sOXID = $oDB->getOne( $sSelect);
01620                 // article is assigned to passed category!
01621                 if ( isset( $sOXID) && $sOXID) {
01622                     return true;
01623                 }
01624             }
01625         }
01626         return false;
01627     }
01628 
01634     public function getTPrice()
01635     {
01636         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01637             return;
01638         }
01639         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01640         if ( $this->_oTPrice !== null ) {
01641             return $this->_oTPrice;
01642         }
01643 
01644         $this->_oTPrice = oxNew( 'oxPrice' );
01645         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01646 
01647         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01648         $this->_applyCurrency( $this->_oTPrice );
01649 
01650         return $this->_oTPrice;
01651     }
01652 
01658     public function skipDiscounts()
01659     {
01660         // allready loaded skip discounts config
01661         if ( $this->_blSkipDiscounts !== null )
01662             return $this->_blSkipDiscounts;
01663 
01664         if ( $this->oxarticles__oxskipdiscounts->value )
01665             return true;
01666 
01667         $sO2CView  = getViewName( 'oxobject2category', $this->getLanguage() );
01668         $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01669         $sSelect =  "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01670                      where $sO2CView.oxobjectid='".$this->getId()."' and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01671         return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01672     }
01673 
01681     public function setPrice(oxPrice $oPrice)
01682     {
01683         $this->_oPrice = $oPrice;
01684     }
01685 
01694     public function getBasePrice( $dAmount = 1 )
01695     {
01696         // override this function if you want e.g. different prices
01697         // for diff. usergroups.
01698 
01699         // Performance
01700         $myConfig = $this->getConfig();
01701         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01702             return;
01703 
01704         // GroupPrice or DB price ajusted by AmountPrice
01705         $dPrice = $this->_getAmountPrice( $dAmount );
01706 
01707 
01708         return $dPrice;
01709     }
01710 
01718     public function getPrice( $dAmount = 1 )
01719     {
01720         $myConfig = $this->getConfig();
01721         // Performance
01722         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01723             return;
01724         }
01725 
01726         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01727         if ( $dAmount != 1 || $this->_oPrice === null ) {
01728             $oPrice = oxNew( 'oxPrice' );
01729 
01730             // get base
01731             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01732 
01733             // price handling
01734             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01735                 return $this->_oPrice = $oPrice;
01736             }
01737 
01738             $this->_calculatePrice( $oPrice );
01739             if ( $dAmount != 1 ) {
01740                 return $oPrice;
01741             }
01742 
01743             $this->_oPrice = $oPrice;
01744         }
01745         return $this->_oPrice;
01746     }
01747 
01755     protected function _calculatePrice( $oPrice )
01756     {
01757         // apply VAT only if configuration requires it
01758         if ( !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01759             $this->_applyVAT( $oPrice, $this->getArticleVat() );
01760         }
01761 
01762         // apply currency
01763         $this->_applyCurrency( $oPrice );
01764         // apply discounts
01765         if ( !$this->skipDiscounts() ) {
01766             $oDiscountList = oxDiscountList::getInstance();
01767             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts($this, $this->getArticleUser() ) );
01768         }
01769 
01770         return $oPrice;
01771     }
01772 
01780     public function setArticleUser($oUser)
01781     {
01782         $this->_oUser = $oUser;
01783     }
01784 
01790     public function getArticleUser()
01791     {
01792         if ($this->_oUser) {
01793             return $this->_oUser;
01794         }
01795         return $this->getUser();
01796     }
01797 
01807     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01808     {
01809         $oUser = $oBasket->getBasketUser();
01810         $this->setArticleUser($oUser);
01811 
01812         $oBasketPrice = oxNew( 'oxPrice' );
01813 
01814         // get base price
01815         $dBasePrice = $this->getBasePrice( $dAmount );
01816 
01817         // applying select list price
01818         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01819 
01820         // setting price
01821         $oBasketPrice->setPrice( $dBasePrice );
01822 
01823         // apply VAT
01824         $this->_applyVat( $oBasketPrice, oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket ) );
01825 
01826         // apply currency
01827         $this->_applyCurrency( $oBasketPrice );
01828 
01829         // apply discounts
01830         if ( !$this->skipDiscounts() ) {
01831             // apply general discounts
01832             $oDiscountList = oxDiscountList::getInstance();
01833             $oDiscountList->applyDiscounts( $oBasketPrice, $oDiscountList->getArticleDiscounts( $this, $oUser ) );
01834         }
01835 
01836         // returning final price object
01837         return $oBasketPrice;
01838     }
01839 
01852     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01853     {
01854         $oDiscountList = oxDiscountList::getInstance();
01855         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01856     }
01857 
01866     public function delete( $sOXID = null )
01867     {
01868         if ( !$sOXID ) {
01869             $sOXID = $this->getId();
01870         }
01871         if ( !$sOXID ) {
01872             return false;
01873         }
01874 
01875 
01876         // #2339 delete first variants before deleting parent product
01877         $this->_deleteVariantRecords( $sOXID );
01878         $this->load( $sOXID );
01879         $this->_deletePics();
01880         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01881 
01882         $rs = $this->_deleteRecords( $sOXID );
01883 
01884         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01885 
01886         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01887 
01888         return $rs->EOF;
01889     }
01890 
01899     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01900     {
01901         $this->beforeUpdate();
01902 
01903         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01904         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01905             $dAmount += $iStockCount;
01906             $iStockCount = 0;
01907         }
01908         $this->oxarticles__oxstock = new oxField($iStockCount);
01909 
01910         $oDb = oxDb::getDb();
01911         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01912         $this->onChange( ACTION_UPDATE_STOCK );
01913         return $dAmount;
01914     }
01915 
01924     public function updateSoldAmount( $dAmount = 0 )
01925     {
01926         if ( !$dAmount ) {
01927             return;
01928         }
01929 
01930         $this->beforeUpdate();
01931 
01932         // article is not variant - should be updated current amount
01933         if ( !$this->oxarticles__oxparentid->value ) {
01934             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01935             $dAmount = (double) $dAmount;
01936             $oDb = oxDb::getDb();
01937             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01938         } elseif ( $this->oxarticles__oxparentid->value) {
01939             // article is variant - should be updated this article parent amount
01940             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01941             $oUpdateArticle->updateSoldAmount( $dAmount );
01942         }
01943 
01944         $this->onChange( ACTION_UPDATE );
01945 
01946         return $rs;
01947     }
01948 
01954     public function disableReminder()
01955     {
01956         $oDB = oxDb::getDb(true);
01957         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01958     }
01959 
01967     public function save()
01968     {
01969         // @deprecated since 20110821. folders are no more written, getters must be user for urls
01970         $this->oxarticles__oxthumb = new oxField( basename( $this->oxarticles__oxthumb->value ), oxField::T_RAW );
01971         $this->oxarticles__oxicon  = new oxField( basename( $this->oxarticles__oxicon->value ), oxField::T_RAW );
01972         $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
01973         for ( $i = 1; $i <= $iPicCount; $i++ ) {
01974             $sFieldName = 'oxarticles__oxpic' . $i;
01975             if ( isset( $this->$sFieldName ) ) {
01976                 $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );
01977             }
01978         }
01979         // @end deprecated
01980 
01981         if ( ( $blRet = parent::save() ) ) {
01982             // saving long descrition
01983             $this->_saveArtLongDesc();
01984         }
01985 
01986         return $blRet;
01987     }
01988 
01989 
01996     public function getPictureGallery()
01997     {
01998         $myConfig = $this->getConfig();
01999 
02000         //initialize
02001         $blMorePic = false;
02002         $aArtPics  = array();
02003         $aArtIcons = array();
02004         $iActPicId = 1;
02005         $sActPic = $this->getPictureUrl( $iActPicId );
02006 
02007         if ( oxConfig::getParameter( 'actpicid' ) ) {
02008             $iActPicId = oxConfig::getParameter('actpicid');
02009         }
02010 
02011         $oStr = getStr();
02012         $iCntr = 0;
02013         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02014         $blCheckActivePicId = true;
02015 
02016         for ( $i = 1; $i <= $iPicCount; $i++) {
02017             $sPicVal = $this->getPictureUrl( $i );
02018             $sIcoVal = $this->getIconUrl( $i );
02019             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02020                  !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02021                 if ($iCntr) {
02022                     $blMorePic = true;
02023                 }
02024                 $aArtIcons[$i]= $sIcoVal;
02025                 $aArtPics[$i]= $sPicVal;
02026                 $iCntr++;
02027 
02028                 if ($iActPicId == $i) {
02029                     $sActPic = $sPicVal;
02030                     $blCheckActivePicId = false;
02031                 }
02032 
02033             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02034                 // if picture is empty, setting active pic id to next
02035                 // picture
02036                 $iActPicId++;
02037             }
02038         }
02039 
02040         $blZoomPic  = false;
02041         $aZoomPics = array();
02042         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02043 
02044         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02045             $sVal = $this->getZoomPictureUrl($j);
02046 
02047             if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02048                 $blZoomPic = true;
02049                 $aZoomPics[$c]['id'] = $c;
02050                 $aZoomPics[$c]['file'] = $sVal;
02051                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02052                 if (!$sVal) {
02053                     $aZoomPics[$c]['file'] = "nopic.jpg";
02054                 }
02055                 $c++;
02056             }
02057         }
02058 
02059         $aPicGallery = array('ActPicID' => $iActPicId,
02060                              'ActPic' => $sActPic,
02061                              'MorePics' => $blMorePic,
02062                              'Pics' => $aArtPics,
02063                              'Icons' => $aArtIcons,
02064                              'ZoomPic' => $blZoomPic,
02065                              'ZoomPics' => $aZoomPics);
02066 
02067         return $aPicGallery;
02068     }
02069 
02083     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02084     {
02085         $myConfig = $this->getConfig();
02086 
02087         if (!isset($sOXID)) {
02088             if ( $this->getId()) {
02089                 $sOXID = $this->getId();
02090             }
02091             if (!isset ($sOXID)) {
02092                 $sOXID = $this->oxarticles__oxid->value;
02093             }
02094             if ($this->oxarticles__oxparentid->value) {
02095                 $sParentID = $this->oxarticles__oxparentid->value;
02096             }
02097         }
02098         if (!isset($sOXID)) {
02099             return;
02100         }
02101 
02102         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02103         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02104             //if article has variants then updating oxvarstock field
02105             //getting parent id
02106             if (!isset($sParentID)) {
02107                 $oDb = oxDb::getDb();
02108                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02109                 $sParentID = $oDb->getOne($sQ);
02110             }
02111             //if we have parent id then update stock
02112             if ($sParentID) {
02113                 $this->_onChangeUpdateStock($sParentID);
02114             }
02115         }
02116         //if we have parent id then update count
02117         //update count even if blUseStock is not active
02118         if ($sParentID) {
02119             $this->_onChangeUpdateVarCount($sParentID);
02120         }
02121 
02122         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02123         $this->_onChangeUpdateMinVarPrice( $sId );
02124 
02125             // reseting articles count cache if stock has changed and some
02126             // articles goes offline (M:1448)
02127             if ( $sAction === ACTION_UPDATE_STOCK ) {
02128                 $this->_onChangeStockResetCount( $sOXID );
02129             }
02130 
02131     }
02132 
02139     public function getCustomVAT()
02140     {
02141         if ( isset($this->oxarticles__oxvat->value) ) {
02142             return $this->oxarticles__oxvat->value;
02143         }
02144     }
02145 
02154     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02155     {
02156         $myConfig = $this->getConfig();
02157         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02158             return true;
02159         }
02160 
02161         // fetching DB info as its up-to-date
02162         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02163         $rs = oxDb::getDb(true)->Execute( $sQ );
02164 
02165         $iOnStock   = 0;
02166         $iStockFlag = 0;
02167         if ( $rs !== false && $rs->recordCount() > 0 ) {
02168             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02169             $iStockFlag = $rs->fields['oxstockflag'];
02170 
02171             // dodger : fremdlager is also always considered as on stock
02172             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02173                 return true;
02174             }
02175             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02176                 $iOnStock = floor( $iOnStock );
02177             }
02178         }
02179         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02180             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02181         }
02182         if ( $iOnStock >= $dAmount ) {
02183             return true;
02184         } else {
02185             if ( $iOnStock > 0 ) {
02186                 return $iOnStock;
02187             } else {
02188                 $oEx = oxNew( 'oxArticleInputException' );
02189                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02190                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02191                 return false;
02192             }
02193         }
02194     }
02195 
02196 
02204     public function getArticleLongDesc( $sOxid = null )
02205     {
02206         if ( $this->_oLongDesc === null ) {
02207 
02208             // initializing
02209             $this->_oLongDesc = new oxField();
02210 
02211 
02212             // choosing which to get..
02213             $sOxid = $sOxid === null ? $this->getId() : $sOxid;
02214             $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02215             if ( ( $sDbValue = oxDb::getDb()->getOne( "select oxlongdesc from {$sViewName} where oxid = ?", array( $sOxid ) ) ) !== false ) {
02216                 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02217             }
02218         }
02219 
02220         return $this->_oLongDesc;
02221     }
02222 
02232     protected function _setLongDesc( $sDbValue )
02233     {
02234         $this->setArticleLongDesc( $sDbValue );
02235     }
02236 
02243     public function getLongDesc()
02244     {
02245         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getArticleLongDesc()->getRawValue(), $this->getId().$this->getLanguage() );
02246     }
02247 
02256     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02257     {
02258 
02259         // setting current value
02260         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02261 
02262         // setting original value?
02263         if ( $sOrigValue ) {
02264             $this->_oLongDesc->orignalValue = $sOrigValue;
02265         }
02266     }
02267 
02273     public function getAttributes()
02274     {
02275         if ( $this->_oAttributeList === null ) {
02276             $this->_oAttributeList = oxNew( 'oxattributelist' );
02277             $this->_oAttributeList->loadAttributes( $this->getId() );
02278         }
02279 
02280         return $this->_oAttributeList;
02281     }
02282 
02291     public function appendLink( $sAddParams, $iLang = null )
02292     {
02293         if ( $sAddParams ) {
02294             if ( $iLang === null ) {
02295                 $iLang = $this->getLanguage();
02296             }
02297 
02298             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02299             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02300         }
02301     }
02302 
02311     public function getBaseSeoLink( $iLang, $blMain = false )
02312     {
02313         $oEncoder = oxSeoEncoderArticle::getInstance();
02314         if ( !$blMain ) {
02315             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02316         }
02317         return $oEncoder->getArticleMainUrl( $this, $iLang );
02318     }
02319 
02328     public function getLink( $iLang = null, $blMain = false  )
02329     {
02330         if ( !oxUtils::getInstance()->seoIsActive() ) {
02331             return $this->getStdLink( $iLang );
02332         }
02333 
02334         if ( $iLang === null ) {
02335             $iLang = $this->getLanguage();
02336         }
02337 
02338         $iLinkType = $this->getLinkType();
02339         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02340             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02341         }
02342 
02343         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02344         if ( isset($this->_aSeoAddParams[$iLang])) {
02345             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02346         }
02347 
02348         return $sUrl;
02349     }
02350 
02359     public function getMainLink( $iLang = null )
02360     {
02361         return $this->getLink( $iLang, true );
02362     }
02363 
02371     public function setLinkType( $iType )
02372     {
02373         // resetting detaisl link, to force new
02374         $this->_sDetailLink = null;
02375 
02376         // setting link type
02377         $this->_iLinkType = (int) $iType;
02378     }
02379 
02385     public function getLinkType()
02386     {
02387         return $this->_iLinkType;
02388     }
02389 
02398     public function appendStdLink( $sAddParams, $iLang = null )
02399     {
02400         if ( $sAddParams ) {
02401             if ( $iLang === null ) {
02402                 $iLang = $this->getLanguage();
02403             }
02404 
02405             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02406             $this->_aStdAddParams[$iLang] .= $sAddParams;
02407         }
02408     }
02409 
02419     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02420     {
02421         $sUrl = '';
02422         if ( $blFull ) {
02423             //always returns shop url, not admin
02424             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02425         }
02426 
02427         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02428         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02429     }
02430 
02439     public function getStdLink( $iLang = null, $aParams = array() )
02440     {
02441         if ( $iLang === null ) {
02442             $iLang = $this->getLanguage();
02443         }
02444 
02445         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02446             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02447         }
02448 
02449         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02450     }
02451 
02459     public function getStdTagLink( $sTag )
02460     {
02461         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02462         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02463     }
02464 
02470     public function getTags()
02471     {
02472         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02473         $sQ = "select oxtags from {$sViewName} where oxid = '".$this->getId()."'";
02474         $oTagCloud = oxNew('oxtagcloud');
02475         return $oTagCloud->trimTags( oxDb::getDb()->getOne( $sQ ) );
02476     }
02477 
02485     public function saveTags($sTags)
02486     {
02487         //do not allow derived update
02488         if ( !$this->allowDerivedUpdate() ) {
02489             return false;
02490         }
02491 
02492 
02493         $oTagCloud = oxNew( 'oxtagcloud' );
02494         $oTagCloud->resetTagCache();
02495         $sTags = mysql_real_escape_string( $oTagCloud->prepareTags( $sTags ) );
02496 
02497         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02498         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02499         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value ('".$this->getId()."', '{$sTags}')
02500                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02501         return oxDb::getDb()->execute( $sQ );
02502     }
02503 
02511     public function addTag($sTag)
02512     {
02513         $oDb = oxDb::getDb();
02514 
02515         $oTagCloud = oxNew('oxtagcloud');
02516         $oTagCloud->resetTagCache();
02517         $sTag = $oTagCloud->prepareTags($sTag);
02518         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02519 
02520         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02521         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02522         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = '".$this->getId()."'" ) ) {
02523             $sTailTag = $sTagSeparator . $sTag;
02524         } else {
02525             $sTailTag = $sTag;
02526         }
02527 
02528         $sTag = mysql_real_escape_string($sTag);
02529         $sTailTag = mysql_real_escape_string($sTailTag);
02530 
02531         $sTag = mysql_real_escape_string($sTag);
02532         $sTailTag = mysql_real_escape_string($sTailTag);
02533 
02534         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values ('".$this->getId()."', '{$sTag}')
02535                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02536 
02537         return $oDb->execute( $sQ );
02538     }
02539 
02545     public function getMediaUrls()
02546     {
02547         if ( $this->_aMediaUrls === null ) {
02548             $this->_aMediaUrls = oxNew("oxlist");
02549             $this->_aMediaUrls->init("oxmediaurl");
02550             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02551 
02552             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02553             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02554             $this->_aMediaUrls->selectString($sQ);
02555         }
02556         return $this->_aMediaUrls;
02557     }
02558 
02564     public function getDynImageDir()
02565     {
02566         return $this->_sDynImageDir;
02567     }
02568 
02574     public function getDispSelList()
02575     {
02576         if ($this->_aDispSelList === null) {
02577             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02578                 $this->_aDispSelList = $this->getSelectLists();
02579             }
02580         }
02581         return $this->_aDispSelList;
02582     }
02583 
02589     public function getMoreDetailLink()
02590     {
02591         if ( $this->_sMoreDetailLink == null ) {
02592 
02593             // and assign special article values
02594             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02595 
02596             // not always it is okey, as not all the time active category is the same as primary article cat.
02597             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02598                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02599             }
02600             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02601             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02602         }
02603 
02604         return $this->_sMoreDetailLink;
02605     }
02606 
02612     public function getToBasketLink()
02613     {
02614         if ( $this->_sToBasketLink == null ) {
02615             $myConfig = $this->getConfig();
02616 
02617             if ( oxUtils::getInstance()->isSearchEngine() ) {
02618                 $this->_sToBasketLink = $this->getLink();
02619             } else {
02620                 // and assign special article values
02621                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02622 
02623                 // override some classes as these should never showup
02624                 $sActClass = oxConfig::getParameter( 'cl' );
02625                 if ( $sActClass == 'thankyou') {
02626                     $sActClass = 'basket';
02627                 }
02628                 $this->_sToBasketLink .= 'cl='.$sActClass;
02629 
02630                 // this is not very correct
02631                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02632                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02633                 }
02634 
02635                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02636 
02637                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02638                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02639                 }
02640             }
02641         }
02642 
02643         return $this->_sToBasketLink;
02644     }
02645 
02651     public function getStockStatus()
02652     {
02653         return $this->_iStockStatus;
02654     }
02655 
02661     public function getDeliveryDate()
02662     {
02663         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02664             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02665         }
02666         return false;
02667     }
02668 
02674     public function getFTPrice()
02675     {
02676         if ( $oPrice = $this->getTPrice() ) {
02677             if ( $oPrice->getBruttoPrice() ) {
02678                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02679             }
02680         }
02681     }
02682 
02688     public function getFPrice()
02689     {
02690         if ( $oPrice = $this->getPrice() ) {
02691             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02692         }
02693     }
02694 
02700     public function getFNetPrice()
02701     {
02702         if ( $oPrice = $this->getPrice() ) {
02703             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02704         }
02705     }
02706 
02712     public function getPricePerUnit()
02713     {
02714         return $this->_fPricePerUnit;
02715     }
02716 
02722     public function isParentNotBuyable()
02723     {
02724         return $this->_blNotBuyableParent;
02725     }
02726 
02732     public function isNotBuyable()
02733     {
02734         return $this->_blNotBuyable;
02735     }
02736 
02744     public function setBuyableState( $blBuyable = false )
02745     {
02746         $this->_blNotBuyable = !$blBuyable;
02747     }
02748 
02757     public function getVariantList()
02758     {
02759         return $this->getVariants();
02760     }
02761 
02769     public function setSelectlist( $aSelList )
02770     {
02771         $this->_aDispSelList = $aSelList;
02772     }
02773 
02781     public function getPictureUrl( $iIndex = 1 )
02782     {
02783         if ( $iIndex ) {
02784             $sImgName = false;
02785             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02786                 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02787             }
02788 
02789             $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02790             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02791         }
02792     }
02793 
02802     public function getIconUrl( $iIndex = 0 )
02803     {
02804         $sImgName = false;
02805         $sDirname = "product/1/";
02806         if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02807             $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02808             $sDirname = "product/{$iIndex}/";
02809         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02810             $sImgName = basename( $this->oxarticles__oxicon->value );
02811             $sDirname = "product/icon/";
02812         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02813             $sImgName = basename( $this->oxarticles__oxpic1->value );
02814         }
02815 
02816         $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02817         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02818     }
02819 
02825     public function getThumbnailUrl()
02826     {
02827         $sImgName = false;
02828         $sDirname = "product/1/";
02829         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02830             $sImgName = basename( $this->oxarticles__oxthumb->value );
02831             $sDirname = "product/thumb/";
02832         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02833             $sImgName = basename( $this->oxarticles__oxpic1->value );
02834         }
02835 
02836         $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02837         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0 );
02838     }
02839 
02847     public function getZoomPictureUrl( $iIndex = '' )
02848     {
02849         $iIndex = (int) $iIndex;
02850         if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02851             $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02852             $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02853             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02854         }
02855     }
02856 
02862     public function getFileUrl()
02863     {
02864         return $this->getConfig()->getPictureUrl( 'media/' );
02865     }
02866 
02872     public function getPriceFromPrefix()
02873     {
02874         $sPricePrefics = '';
02875         if ( $this->_blIsRangePrice) {
02876             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02877         }
02878 
02879         return $sPricePrefics;
02880     }
02881 
02887     protected function _saveArtLongDesc()
02888     {
02889         $myConfig = $this->getConfig();
02890         $sShopId = $myConfig->getShopID();
02891         if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02892             return;
02893         }
02894 
02895         if ($this->_blEmployMultilanguage) {
02896             $sValue = $this->getArticleLongDesc()->getRawValue();
02897             if ( $sValue !== null ) {
02898                 $oArtExt = oxNew('oxI18n');
02899                 $oArtExt->init('oxartextends');
02900                 $oArtExt->setLanguage((int) $this->getLanguage());
02901                 if (!$oArtExt->load($this->getId())) {
02902                     $oArtExt->setId($this->getId());
02903                 }
02904                 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02905                 $oArtExt->save();
02906             }
02907         } else {
02908             $oArtExt = oxNew('oxI18n');
02909             $oArtExt->setEnableMultilang(false);
02910             $oArtExt->init('oxartextends');
02911             $aObjFields = $oArtExt->_getAllFields(true);
02912             if (!$oArtExt->load($this->getId())) {
02913                 $oArtExt->setId($this->getId());
02914             }
02915 
02916             foreach ($aObjFields as $sKey => $sValue ) {
02917                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02918                     $sField = $this->_getFieldLongName($sKey);
02919 
02920                     if (isset($this->$sField)) {
02921                         $sLongDesc = null;
02922                         if ($this->$sField instanceof oxField) {
02923                             $sLongDesc = $this->$sField->getRawValue();
02924                         } elseif (is_object($this->$sField)) {
02925                             $sLongDesc = $this->$sField->value;
02926                         }
02927                         if (isset($sLongDesc)) {
02928                             $sAEField = $oArtExt->_getFieldLongName($sKey);
02929                             $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
02930                         }
02931                     }
02932                 }
02933             }
02934             $oArtExt->save();
02935         }
02936     }
02937 
02943     protected function _skipSaveFields()
02944     {
02945         $myConfig = $this->getConfig();
02946 
02947         $this->_aSkipSaveFields = array();
02948 
02949         $this->_aSkipSaveFields[] = 'oxtimestamp';
02950        // $this->_aSkipSaveFields[] = 'oxlongdesc';
02951         $this->_aSkipSaveFields[] = 'oxinsert';
02952 
02953         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02954             $this->_aSkipSaveFields[] = 'oxparentid';
02955         }
02956 
02957     }
02958 
02968     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02969     {
02970         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02971             // add prices of the same discounts
02972             if ( array_key_exists ($sKey, $aDiscounts) ) {
02973                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02974             } else {
02975                 $aDiscounts[$sKey] = $oDiscount;
02976             }
02977         }
02978         return $aDiscounts;
02979     }
02980 
02986     protected function _getGroupPrice()
02987     {
02988         $dPrice = $this->oxarticles__oxprice->value;
02989 
02990         $oUser = $this->getArticleUser();
02991         if ( $oUser ) {
02992             if ( $oUser->inGroup( 'oxidpricea' ) ) {
02993                 $dPrice = $this->oxarticles__oxpricea->value;
02994             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
02995                 $dPrice = $this->oxarticles__oxpriceb->value;
02996             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
02997                 $dPrice = $this->oxarticles__oxpricec->value;
02998             }
02999         }
03000 
03001         // #1437/1436C - added config option, and check for zero A,B,C price values
03002         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03003             $dPrice = $this->oxarticles__oxprice->value;
03004         }
03005 
03006         return $dPrice;
03007     }
03008 
03017     protected function _getAmountPrice($dAmount = 1)
03018     {
03019         $myConfig = $this->getConfig();
03020 
03021         startProfile( "_getAmountPrice" );
03022 
03023         $dPrice = $this->_getGroupPrice();
03024         $oAmtPrices = $this->_getAmountPriceList();
03025         foreach ($oAmtPrices as $oAmPrice) {
03026             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03027                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03028                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03029                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03030             }
03031         }
03032 
03033         stopProfile( "_getAmountPrice" );
03034         return $dPrice;
03035     }
03036 
03045     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03046     {
03047         $myConfig = $this->getConfig();
03048         // #690
03049         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03050 
03051             $aSelLists = $this->getSelectLists();
03052 
03053             foreach ( $aSelLists as $key => $aSel) {
03054                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03055                     $oSel = $aSel[$aChosenList[$key]];
03056                     if ( $oSel->priceUnit =='abs' ) {
03057                         $dPrice += $oSel->price;
03058                     } elseif ( $oSel->priceUnit =='%' ) {
03059                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03060                     }
03061                 }
03062             }
03063         }
03064         return $dPrice;
03065     }
03066 
03067 
03075     protected function _fillAmountPriceList($oAmPriceList)
03076     {
03077         $myConfig = $this->getConfig();
03078         $myUtils  = oxUtils::getInstance();
03079 
03080         //modifying price
03081         $oCur = $myConfig->getActShopCurrencyObject();
03082 
03083         $oUser = $this->getArticleUser();
03084 
03085         $oDiscountList = oxDiscountList::getInstance();
03086         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03087 
03088         $oLowestPrice = null;
03089 
03090         $dBasePrice = $this->_getGroupPrice();
03091         $oLang = oxLang::getInstance();
03092 
03093         $dArticleVat = null;
03094         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03095             $dArticleVat = $this->getArticleVat();
03096         }
03097 
03098         // trying to find lowest price value
03099         foreach ($oAmPriceList as $sId => $oItem) {
03100             $oItemPrice = oxNew( 'oxprice' );
03101             if ( $oItem->oxprice2article__oxaddabs->value) {
03102                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03103                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03104                 $this->_applyCurrency( $oItemPrice, $oCur );
03105             } else {
03106                 $oItemPrice->setPrice( $dBasePrice );
03107                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03108             }
03109 
03110             if (isset($dArticleVat)) {
03111                 $this->_applyVAT($oItemPrice, $dArticleVat);
03112             }
03113 
03114             if (!$oLowestPrice) {
03115                 $oLowestPrice = $oItemPrice;
03116             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03117                 $oLowestPrice = $oItemPrice;
03118             }
03119 
03120             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03121             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03122             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03123         }
03124 
03125         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03126         return $oAmPriceList;
03127     }
03128 
03134     protected function _getVariantsIds()
03135     {
03136         $aSelect = array();
03137         if ( ( $sId = $this->getId() ) ) {
03138             $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '{$sId}' " );
03139             if ( $oRs != false && $oRs->recordCount() > 0 ) {
03140                 while (!$oRs->EOF) {
03141                     $aSelect[] = $oRs->fields['oxid'];
03142                     $oRs->moveNext();
03143                 }
03144             }
03145         }
03146         return $aSelect;
03147     }
03148 
03154     public function getArticleVat()
03155     {
03156         if (!isset($this->_dArticleVat)) {
03157             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03158         }
03159         return $this->_dArticleVat;
03160     }
03161 
03170     protected function _applyVAT( oxPrice $oPrice, $dVat )
03171     {
03172         startProfile(__FUNCTION__);
03173         $oPrice->setVAT( $dVat );
03174         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03175             $oPrice->setUserVat( $dVat );
03176         }
03177         stopProfile(__FUNCTION__);
03178     }
03179 
03187     public function applyVats( oxPrice $oPrice )
03188     {
03189         $this->_applyVAT($oPrice, $this->getArticleVat() );
03190     }
03191 
03202     protected function _applyDiscounts( $oPrice, $aDiscounts )
03203     {
03204         $oDiscountList = oxDiscountList::getInstance();
03205         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03206     }
03207 
03215     public function applyDiscountsForVariant( $oPrice )
03216     {
03217         // apply discounts
03218         if ( !$this->skipDiscounts() ) {
03219             $oDiscountList = oxDiscountList::getInstance();
03220             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03221         }
03222     }
03223 
03232     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03233     {
03234         if ( !$oCur ) {
03235             $oCur = $this->getConfig()->getActShopCurrencyObject();
03236         }
03237 
03238         $oPrice->multiply($oCur->rate);
03239     }
03240 
03241 
03250     protected function _getAttribsString(&$sAttribs, &$iCnt)
03251     {
03252         // we do not use lists here as we dont need this overhead right now
03253         $oDB = oxDb::getDb(true);
03254         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03255         $sAttribs = '';
03256         $blSep = false;
03257         $rs = $oDB->execute( $sSelect);
03258         $iCnt = 0;
03259         if ($rs != false && $rs->recordCount() > 0) {
03260             while (!$rs->EOF) {
03261                 if ( $blSep) {
03262                     $sAttribs .= ' or ';
03263                 }
03264                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03265                 $blSep = true;
03266                 $iCnt++;
03267                 $rs->moveNext();
03268             }
03269         }
03270     }
03271 
03280     protected function _getSimList($sAttribs, $iCnt)
03281     {
03282         $myConfig = $this->getConfig();
03283         $oDB      = oxDb::getDb(true);
03284 
03285         // #523A
03286         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03287         // 70% same attributes
03288         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03289             $iAttrPercent = 0.70;
03290         }
03291         // #1137V iAttributesPercent = 100 doesnt work
03292         $iHitMin = ceil( $iCnt * $iAttrPercent );
03293 
03294         // we do not use lists here as we dont need this overhead right now
03295         $aList= array();
03296         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03297                     ( $sAttribs )
03298                     and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03299                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03300 
03301         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03302         if ($rs != false && $rs->recordCount() > 0) {
03303             while (!$rs->EOF) {
03304                 $oTemp = new stdClass();    // #663
03305                 $oTemp->cnt = $rs->fields['cnt'];
03306                 $oTemp->id  = $rs->fields['oxobjectid'];
03307                 $aList[] = $oTemp;
03308                 $rs->moveNext();
03309             }
03310         }
03311         return $aList;
03312     }
03313 
03322     protected function _generateSimListSearchStr($sArticleTable, $aList)
03323     {
03324         $myConfig = $this->getConfig();
03325         $sFieldList = $this->getSelectFields();
03326         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03327         $blSep = false;
03328         $iCnt = 0;
03329         $oDb = oxDb::getDb();
03330         foreach ( $aList as $oTemp) {
03331             if ( $blSep) {
03332                 $sSearch .= ',';
03333             }
03334             $sSearch .= $oDb->quote($oTemp->id);
03335             $blSep = true;
03336             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03337                 break;
03338             }
03339             $iCnt++;
03340         }
03341 
03342         //#1741T
03343         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03344         $sSearch .= ') ';
03345 
03346         // #524A -- randomizing articles in attribute list
03347         $sSearch .= ' order by rand() ';
03348 
03349         return $sSearch;
03350     }
03351 
03360     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03361     {
03362 
03363         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03364         $sO2CView = getViewName( 'oxobject2category' );
03365 
03366         // we do not use lists here as we dont need this overhead right now
03367         if ( !$blSearchPriceCat ) {
03368             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03369                          {$sCatView}.oxid = oxobject2category.oxcatnid
03370                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03371         } else {
03372             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03373                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03374                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03375         }
03376         return $sSelect;
03377     }
03378 
03384     protected function _generateSearchStrForCustomerBought()
03385     {
03386         $sArtTable = $this->getViewName();
03387         $sOrderArtTable = getViewName( 'oxorderarticles' );
03388 
03389         // fetching filter params
03390         $sIn = " '{$this->oxarticles__oxid->value}' ";
03391         if ( $this->oxarticles__oxparentid->value ) {
03392 
03393             // adding article parent
03394             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03395             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03396 
03397         } else {
03398             $sParentIdForVariants = $this->getId();
03399         }
03400 
03401         // adding variants
03402         $oDb = oxDb::getDb(true);
03403         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03404         if ( $oRs != false && $oRs->recordCount() > 0) {
03405             while ( !$oRs->EOF ) {
03406                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03407                 $oRs->moveNext();
03408             }
03409         }
03410 
03411         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03412         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03413 
03414         // building sql (optimized)
03415         $sQ = "select distinct {$sArtTable}.* from (
03416                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03417                ) as suborder
03418                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03419                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03420                where {$sArtTable}.oxid not in ( {$sIn} )
03421                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03422 
03423         /* non optimized, but could be used if index forcing is not supported
03424         // building sql
03425         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03426                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03427                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03428                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03429                and ".$this->getSqlActiveSnippet();
03430         */
03431 
03432         return $sQ;
03433     }
03434 
03444     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03445     {
03446         $sCategoryView = getViewName('oxcategories');
03447         $sO2CView = getViewName('oxobject2category');
03448 
03449         $oDb    = oxDb::getDb();
03450         $sOXID  = $oDb->quote($sOXID);
03451         $sCatId = $oDb->quote($sCatId);
03452 
03453         if (!$dPriceFromTo) {
03454             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03455             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03456             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03457             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03458         } else {
03459             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03460             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03461             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03462             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03463         }
03464         return $sSelect;
03465     }
03466 
03472     protected function _getAmountPriceList()
03473     {
03474         if ($this->_oAmountPriceList) {
03475             return $this->_oAmountPriceList;
03476         }
03477 
03478         $myConfig = $this->getConfig();
03479 
03480         $sArtID  = $this->getId();
03481 
03482         // #1690C - Scale prices and variants
03483         if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03484             $sArtID = $this->oxarticles__oxparentid->value;
03485         }
03486 
03487         $sArtID = mysql_real_escape_string($sArtID);
03488 
03489         //collecting assigned to article amount-price list
03490         $oAmPriceList = oxNew( 'oxlist');
03491         $oAmPriceList->init('oxbase', 'oxprice2article');
03492 
03493         $sShopID = $myConfig->getShopID();
03494         if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03495             $sShopSelect = '1';
03496         } else {
03497             $sShopSelect = " oxshopid =  '$sShopID' ";
03498         }
03499 
03500         $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03501 
03502         // prepare abs prices if currently having percentages
03503         $oBasePrice = $this->_getGroupPrice();
03504         foreach ($oAmPriceList as $oAmPrice) {
03505             if ($oAmPrice->oxprice2article__oxaddperc->value) {
03506                 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03507             }
03508         }
03509 
03510         $this->_oAmountPriceList = $oAmPriceList;
03511         return $oAmPriceList;
03512     }
03513 
03521     protected function _isFieldEmpty( $sFieldName )
03522     {
03523         $mValue = $this->$sFieldName->value;
03524 
03525         if ( is_null( $mValue ) ) {
03526             return true;
03527         }
03528 
03529         if ( $mValue === '' ) {
03530             return true;
03531         }
03532 
03533         $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03534 
03535         if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03536             return true;
03537         }
03538 
03539 
03540         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03541             return true;
03542         }
03543 
03544         $sFieldName = strtolower($sFieldName);
03545 
03546         if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03547             return true;
03548         }
03549 
03550         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03551             return true;
03552         }
03553 
03554         return false;
03555     }
03556 
03564     protected function _assignParentFieldValue($sFieldName)
03565     {
03566         if (!($oParentArticle = $this->getParentArticle())) {
03567             return;
03568         }
03569 
03570         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03571 
03572         // assigning only theese which parent article has
03573         if ( $oParentArticle->$sCopyFieldName != null ) {
03574 
03575             // only overwrite database values
03576             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03577                 return;
03578             }
03579 
03580             //do not copy certain fields
03581             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03582                 return;
03583             }
03584 
03585             //COPY THE VALUE
03586             // assigning images from parent only if variant has no master image (#1807)
03587             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03588                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03589                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03590                 }
03591             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03592                 // for zoom images checking master image with specified index
03593                 // assign from parent only if no pictures to variant are added
03594                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03595                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03596                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03597                 }
03598             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03599                 // if no pics generated for variants, load all from
03600                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03601             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03602                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03603             }
03604         }
03605     }
03606 
03612     public function getParentArticle()
03613     {
03614         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03615             if ( !isset( self::$_aLoadedParents[$sParentId] ) ) {
03616                 self::$_aLoadedParents[$sParentId] = oxNew( 'oxarticle' );
03617                 self::$_aLoadedParents[$sParentId]->_blSkipAbPrice  = true;
03618                 self::$_aLoadedParents[$sParentId]->_blLoadPrice    = false;
03619                 self::$_aLoadedParents[$sParentId]->_blLoadVariants = false;
03620                 self::$_aLoadedParents[$sParentId]->load( $sParentId );
03621             }
03622             return self::$_aLoadedParents[$sParentId];
03623         }
03624     }
03625 
03633     protected function _getParentAricle()
03634     {
03635         return $this->getParentArticle();
03636     }
03637 
03643     protected function _assignParentFieldValues()
03644     {
03645         startProfile('articleAssignParentInternal');
03646         if ( $this->oxarticles__oxparentid->value ) {
03647             // yes, we are in fact a variant
03648             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03649                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03650                     $this->_assignParentFieldValue( $sFieldName );
03651                 }
03652 
03653                 //assing long description
03654                 $sLongDesc = $this->getArticleLongDesc()->getRawValue();
03655                 if ( $sLongDesc === null || $sLongDesc == '' ) {
03656                     $this->setArticleLongDesc( $this->getParentArticle()->getArticleLongDesc()->getRawValue() );
03657                 }
03658             }
03659         }
03660         stopProfile('articleAssignParentInternal');
03661     }
03662 
03668     protected function _assignNotBuyableParent()
03669     {
03670         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03671              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03672             $this->_blNotBuyableParent = true;
03673 
03674         }
03675     }
03676 
03682     protected function _assignStock()
03683     {
03684         $myConfig = $this->getConfig();
03685         // -----------------------------------
03686         // stock
03687         // -----------------------------------
03688 
03689         // #1125 A. must round (using floor()) value taken from database and cast to int
03690         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03691             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03692         }
03693         //GREEN light
03694         $this->_iStockStatus = 0;
03695 
03696         // if we have flag /*1 or*/ 4 - we show always green light
03697         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03698             //ORANGE light
03699             $iStock = $this->oxarticles__oxstock->value;
03700 
03701             if ($this->_blNotBuyableParent) {
03702                 $iStock = $this->oxarticles__oxvarstock->value;
03703             }
03704 
03705 
03706             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03707                 $this->_iStockStatus = 1;
03708             }
03709 
03710             //RED light
03711             if ($iStock <= 0) {
03712                 $this->_iStockStatus = -1;
03713             }
03714         }
03715 
03716 
03717         // stock
03718         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03719             $iOnStock = $this->oxarticles__oxstock->value;
03720             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03721                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03722             }
03723             if ($iOnStock <= 0) {
03724                 $this->_blNotBuyable = true;
03725             }
03726         }
03727 
03728         //exceptional handling for variant parent stock:
03729         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03730             $this->_blNotBuyable = false;
03731             //but then at least setting notBuaybleParent to true
03732             $this->_blNotBuyableParent = true;
03733         }
03734 
03735         //special treatment for lists when blVariantParentBuyable config option is set to false
03736         //then we just hide "to basket" button.
03737         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03738         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03739             $this->_blNotBuyable = true;
03740         }
03741 
03742         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03743         if ($this->_blNotBuyableParent && count($this->getVariants()) == 0) {
03744             $this->_blNotBuyable = true;
03745         }
03746     }
03747 
03753     protected function _assignPrices()
03754     {
03755         $myConfig = $this->getConfig();
03756 
03757         // Performance
03758         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03759             return;
03760         }
03761 
03762         // compute price
03763         $dPrice = $this->getPrice()->getBruttoPrice();
03764 
03765         $oCur = $myConfig->getActShopCurrencyObject();
03766         //price per unit handling
03767         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03768             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03769         }
03770 
03771         //getting min and max prices of variants
03772         if ( $this->_hasAnyVariant() ) {
03773             $this->_applyRangePrice();
03774         }
03775     }
03776 
03782     protected function _assignPersistentParam()
03783     {
03784         // Persistent Parameter Handling
03785         $aPersParam     = oxSession::getVar( 'persparam');
03786         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03787             $this->_aPersistParam = $aPersParam[$this->getId()];
03788         }
03789     }
03790 
03796     protected function _assignDynImageDir()
03797     {
03798         $myConfig = $this->getConfig();
03799 
03800         $sThisShop = $this->oxarticles__oxshopid->value;
03801 
03802         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03803         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03804         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03805         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03806     }
03807 
03813     protected function _assignComparisonListFlag()
03814     {
03815         // #657 add a flag if article is on comparisonlist
03816 
03817         $aItems = oxSession::getVar('aFiltcompproducts');
03818         if ( isset( $aItems[$this->getId()])) {
03819             $this->_blIsOnComparisonList = true;
03820         }
03821     }
03822 
03828     protected function _assignAttributes()
03829     {
03830         //#1029T load attributes
03831         //#1078S removed check for module "Produktvergleich"
03832         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03833             $this->getAttributes();
03834         }
03835     }
03836 
03837 
03845     protected function _insert()
03846     {
03847         // set oxinsert
03848         $iInsertTime = time();
03849         $now = date('Y-m-d H:i:s', $iInsertTime);
03850         $this->oxarticles__oxinsert    = new oxField( $now );
03851         $this->oxarticles__oxtimestamp = new oxField( $now );
03852         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03853             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03854         }
03855 
03856         return parent::_insert();
03857     }
03858 
03864     protected function _update()
03865     {
03866 
03867         $this->_skipSaveFields();
03868 
03869         $myConfig = $this->getConfig();
03870 
03871 
03872         return parent::_update();
03873     }
03874 
03882     protected function _deleteRecords($sOXID)
03883     {
03884         $oDB = oxDb::getDb();
03885 
03886         $sOXID = $oDB->quote($sOXID);
03887 
03888         //delete the record
03889         $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
03890         $oDB->execute( $sDelete);
03891 
03892         //remove other records
03893         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03894         $oDB->execute( $sDelete);
03895 
03896         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03897         $oDB->execute( $sDelete);
03898 
03899         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03900         $oDB->execute( $sDelete);
03901 
03902         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03903         $oDB->execute( $sDelete);
03904 
03905         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03906         $oDB->execute( $sDelete);
03907 
03908         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03909         $oDB->execute( $sDelete);
03910 
03911         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03912         $oDB->execute( $sDelete);
03913 
03914         //#1508C - deleting oxobject2delivery entries added
03915         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03916         $oDB->execute( $sDelete);
03917 
03918         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03919         $oDB->execute( $sDelete);
03920 
03921         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03922         $rs = $oDB->execute( $sDelete );
03923 
03924         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03925         $rs = $oDB->execute( $sDelete );
03926 
03927 
03928         return $rs;
03929     }
03930 
03938     protected function _deleteVariantRecords( $sOXID )
03939     {
03940         if ( $sOXID ) {
03941             $oDb = oxDb::getDb();
03942             //collect variants to remove recursively
03943             $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03944             $rs = $oDb->execute( $sQ );
03945             if ($rs != false && $rs->recordCount() > 0) {
03946                 while (!$rs->EOF) {
03947                     $this->delete( $rs->fields[0] );
03948                     $rs->moveNext();
03949                 }
03950             }
03951         }
03952     }
03953 
03963     protected function _resetCacheAndArticleCount( $sOxid )
03964     {
03965         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03966     }
03967 
03973     protected function _deletePics()
03974     {
03975         $myUtilsPic = oxUtilsPic::getInstance();
03976         $myConfig   = $this->getConfig();
03977         $oPictureHandler = oxPictureHandler::getInstance();
03978 
03979         //deleting custom main icon
03980         $oPictureHandler->deleteMainIcon( $this );
03981 
03982         //deleting custom thumbnail
03983         $oPictureHandler->deleteThumbnail( $this );
03984 
03985         $sAbsDynImageDir = $myConfig->getPictureDir(false);
03986 
03987         // deleting master image and all generated images
03988         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03989         for ( $i = 1; $i <= $iPicCount; $i++ ) {
03990             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
03991         }
03992     }
03993 
04003     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04004     {
04005 
04006         $myUtilsCount = oxUtilsCount::getInstance();
04007 
04008         if ( $sVendorId ) {
04009             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04010         }
04011 
04012         if ( $sManufacturerId ) {
04013             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04014         }
04015 
04016         //also reseting category counts
04017         $oDb = oxDb::getDb();
04018         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04019         $oRs = $oDb->execute( $sQ );
04020         if ( $oRs !== false && $oRs->recordCount() > 0) {
04021             while ( !$oRs->EOF ) {
04022                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04023                 $oRs->moveNext();
04024             }
04025         }
04026     }
04027 
04035     protected function _onChangeUpdateStock( $sParentID )
04036     {
04037         if ( $sParentID ) {
04038             $oDb = oxDb::getDb();
04039             $sParentIdQuoted = $oDb->quote($sParentID);
04040             $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04041             $rs = $oDb->execute($sQ);
04042             $iOldStock = $rs->fields[0];
04043             $iVendorID = $rs->fields[1];
04044             $iManufacturerID = $rs->fields[2];
04045 
04046             $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04047             $iStock = (float) $oDb->getOne( $sQ );
04048 
04049             $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04050             $oDb->execute( $sQ );
04051 
04052                 //now lets update category counts
04053                 //first detect stock status change for this article (to or from 0)
04054                 if ( $iStock < 0 ) {
04055                     $iStock = 0;
04056                 }
04057                 if ( $iOldStock < 0 ) {
04058                     $iOldStock = 0;
04059                 }
04060                 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04061                     //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04062                     // so far we leave it like this but later we could move all count resets to one or two functions
04063                     $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04064                 }
04065         }
04066     }
04067 
04075     protected function _onChangeStockResetCount( $sOxid )
04076     {
04077         $myConfig = $this->getConfig();
04078 
04079         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04080            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04081 
04082                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04083         }
04084     }
04085 
04093     protected function _onChangeUpdateVarCount( $sParentID )
04094     {
04095         if ( $sParentID ) {
04096             $oDb = oxDb::getDb();
04097             $sParentIdQuoted = $oDb->quote( $sParentID );
04098             $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04099             $iVarCount = (int) $oDb->getOne( $sQ );
04100 
04101             $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04102             $oDb->execute( $sQ );
04103         }
04104     }
04105 
04113     protected function _onChangeUpdateMinVarPrice( $sParentID )
04114     {
04115         if ( $sParentID ) {
04116             $oDb = oxDb::getDb();
04117             $sParentIdQuoted = $oDb->quote($sParentID);
04118             //#M0000883 (Sarunas)
04119             $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04120             $dVarMinPrice = $oDb->getOne($sQ);
04121 
04122             $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04123 
04124             $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04125 
04126             if ($dVarMinPrice) {
04127                 if ($blParentBuyable) {
04128                     $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04129                 }
04130 
04131             } else {
04132                 $dVarMinPrice = $dParentPrice;
04133             }
04134 
04135             if ( $dVarMinPrice ) {
04136                 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04137                 $oDb->execute($sQ);
04138             }
04139         }
04140     }
04141 
04142 
04148     protected function _applyRangePrice()
04149     {
04150         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04151         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04152             return;
04153         }
04154 
04155         $this->_blIsRangePrice = false;
04156 
04157         // if parent is buyable - do not apply range price calcculations
04158         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04159             return;
04160         }
04161 
04162         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04163             //#2509 we cannot force brutto price here, as netto price can be added to DB
04164             // $this->getPrice()->setBruttoPriceMode();
04165             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04166             $this->_blIsRangePrice = true;
04167             $this->_calculatePrice( $this->getPrice() );
04168             return;
04169         }
04170 
04171         $aPrices = array();
04172 
04173         if (!$this->_blNotBuyableParent) {
04174             $aPrices[] = $this->getPrice()->getBruttoPrice();
04175         }
04176 
04177         $aVariants = $this->getVariants(false);
04178 
04179         if (count($aVariants)) {
04180             foreach ($aVariants as $sKey => $oVariant) {
04181                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04182             }
04183         }
04184 
04185         if ( count( $aPrices ) ) {
04186             $dMinPrice = min( $aPrices );
04187             $dMaxPrice = max( $aPrices );
04188         }
04189 
04190         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04191             $this->getPrice()->setBruttoPriceMode();
04192             $this->getPrice()->setPrice($dMinPrice);
04193         }
04194 
04195         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04196             $this->getPrice()->setBruttoPriceMode();
04197             $this->getPrice()->setPrice($dMinPrice);
04198             $this->_blIsRangePrice = true;
04199         }
04200     }
04201 
04208     public function getProductId()
04209     {
04210         return $this->getId();
04211     }
04212 
04218     public function getProductParentId()
04219     {
04220         return $this->oxarticles__oxparentid->value;
04221     }
04222 
04228     public function isOrderArticle()
04229     {
04230         return false;
04231     }
04232 
04238     public function isVariant()
04239     {
04240         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04241     }
04242 
04248     public function isMdVariant()
04249     {
04250         $oMdVariant = oxNew( "oxVariantHandler" );
04251 
04252         return $oMdVariant->isMdVariant($this);
04253     }
04254 
04262     public function getSqlForPriceCategories($sFields = '')
04263     {
04264         if (!$sFields) {
04265             $sFields = 'oxid';
04266         }
04267         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04268         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04269         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04270                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04271                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04272     }
04273 
04281     public function inPriceCategory( $sCatNid )
04282     {
04283         $oDb = oxDb::getDb();
04284 
04285         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04286         $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04287         return (bool) $oDb->getOne(
04288             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04289            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04290            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04291            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04292            .")"
04293         );
04294     }
04295 
04301     public function getMdVariants()
04302     {
04303         if ( $this->_oMdVariants ) {
04304             return $this->_oMdVariants;
04305         }
04306 
04307         $oParentArticle = $this->getParentArticle();
04308         if ( $oParentArticle ) {
04309             $oVariants = $oParentArticle->getVariants();
04310         } else {
04311             $oVariants = $this->getVariants();
04312         }
04313 
04314         $oVariantHandler = oxNew( "oxVariantHandler" );
04315         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04316 
04317         return $this->_oMdVariants;
04318     }
04319 
04325     public function getMdSubvariants()
04326     {
04327         return $this->getMdVariants()->getMdSubvariants();
04328     }
04329 
04337     protected function _hasMasterImage( $iIndex )
04338     {
04339         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04340 
04341         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04342             return false;
04343         }
04344         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04345             return false;
04346         }
04347 
04348         $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04349 
04350         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04351             return true;
04352         }
04353 
04354         return false;
04355     }
04356 
04365     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04366     {
04367         if ( $sFieldName ) {
04368             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04369             return $this->$sFieldName->value;
04370         }
04371     }
04372 
04380     public function getMasterZoomPictureUrl( $iIndex )
04381     {
04382         $sPicUrl  = false;
04383         $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04384 
04385         if ( $sPicName && $sPicName != "nopic.jpg" ) {
04386             $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04387             if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04388                 $sPicUrl = false;
04389             }
04390         }
04391 
04392         return $sPicUrl;
04393     }
04394 }