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 $_sClassName = 'oxarticle';
00025 
00031     protected $_blUseLazyLoading = true;
00032 
00038     protected $_sItemKey;
00039 
00045     protected $_blCalcPrice    = true;
00046 
00051     protected $_oPrice      = null;
00052 
00058     protected $_dArticleVat = null;
00059 
00065     protected $_aPersistParam  = null;
00066 
00072     protected $_blNotBuyable   = false;
00073 
00080     protected $_blLoadVariants = true;
00081 
00087     protected $_aVariants = null;
00088 
00094     protected $_aVariantsWithNotOrderables = null;
00095 
00104     protected $_blNotBuyableParent  = false;
00105 
00106 
00110     protected $_blHasVariants = false;
00111 
00115     protected $_blHasMdVariants = false;
00116 
00121     protected $_blIsOnComparisonList = false;
00122 
00127     protected $_oUser = null;
00128 
00134     protected $_blLoadPrice = true;
00135 
00139     protected $_blSkipAbPrice = false;
00140 
00147     protected $_fPricePerUnit = null;
00148 
00152     protected $_blLoadParentData = false;
00153 
00157     protected $_blSkipAssign = false;
00158 
00164     protected $_blSkipDiscounts = null;
00165 
00170     protected $_oAttributeList = null;
00171 
00172 
00178     protected $_blIsRangePrice = false;
00179 
00185     protected $_aMediaUrls = null;
00186 
00192     static protected $_aLoadedParents;
00193 
00199     static protected $_aSelList;
00200 
00206     protected $_aDispSelList;
00207 
00213     protected $_blIsSeoObject = true;
00214 
00220     protected $_oAmountPriceList = null;
00221 
00230     protected $_iLinkType = 0;
00231 
00237     protected $_aStdUrls = array();
00238 
00244     protected $_aSeoUrls = array();
00245 
00251     protected $_aSeoAddParams = array();
00252 
00258     protected $_aStdAddParams = array();
00259 
00265     protected $_sDynImageDir = null;
00266 
00272     protected $_sMoreDetailLink = null;
00273 
00279     protected $_sToBasketLink = null;
00280 
00286     protected $_iStockStatus = null;
00287 
00293     protected $_oTPrice = null;
00294 
00300     protected $_oAmountPriceInfo = null;
00301 
00307     protected $_dAmountPrice = null;
00308 
00314     protected static $_aArticleManufacturers = array();
00315 
00321     protected static $_aArticleVendors = array();
00322 
00328     protected static $_aArticleCats = array();
00329 
00335     protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00336                                              'oxarticles__oxtimestamp',
00337                                              'oxarticles__oxnid',
00338                                              'oxarticles__oxid',
00339                                              'oxarticles__oxparentid');
00340 
00346     protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00347                                          'oxarticles__oxfreeshipping',
00348                                          'oxarticles__oxremindactive',
00349                                          'oxarticles__oxisdownloadable');
00350 
00356     protected $_oMdVariants = null;
00357 
00363     protected $_oLongDesc = null;
00364 
00372     protected $_aVariantSelections = array();
00373 
00378     protected static $_aSelections = array();
00379 
00384     protected static $_aCategoryCache = null;
00385 
00390     protected static $_blHasAmountPrice = null;
00391 
00396     protected $_aArticleFiles = null;
00397 
00398 
00407     public function __construct($aParams = null)
00408     {
00409         if ( $aParams && is_array($aParams)) {
00410             foreach ( $aParams as $sParam => $mValue) {
00411                 $this->$sParam = $mValue;
00412             }
00413         }
00414         parent::__construct();
00415         $this->init( 'oxarticles' );
00416 
00417         $this->_blIsRangePrice = false;
00418     }
00419 
00428     public function __get($sName)
00429     {
00430         $myUtils = oxUtils::getInstance();
00431         // deprecated since 2011.03.10, should be used getLongDescription() / getLongDesc()
00432         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00433             return $this->getLongDescription();
00434         }
00435 
00436         $this->$sName = parent::__get($sName);
00437         if ( $this->$sName ) {
00438             // since the field could have been loaded via lazyloading
00439             $this->_assignParentFieldValue($sName);
00440         }
00441 
00442         return $this->$sName;
00443     }
00444 
00453     public function __set( $sName, $sValue )
00454     {
00455         // deprecated since 2011.03.14, should be used setArticleLongDesc()
00456         if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00457             if ($this->_blEmployMultilanguage) {
00458                 $sValue = ( $sValue instanceof oxField ) ? $sValue->getRawValue() : $sValue;
00459                 $this->setArticleLongDesc( $sValue );
00460             } else {
00461                 $this->$sName = $sValue;
00462             }
00463         } else {
00464             parent::__set( $sName, $sValue );
00465         }
00466     }
00467 
00475     public function setId( $sId = null )
00476     {
00477         $sId = parent::setId( $sId );
00478 
00479         // TODO: in oxbase::setId make it to check if exists and update, not recreate, then delete this overload
00480         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00481 
00482         return $sId;
00483     }
00484 
00494     public function getActiveCheckQuery( $blForceCoreTable = null )
00495     {
00496         $sTable = $this->getViewName( $blForceCoreTable );
00497 
00498         // check if article is still active
00499         $sQ = " $sTable.oxactive = 1 ";
00500 
00501         // enabled time range check ?
00502         if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00503             $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00504             $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00505         }
00506 
00507         return $sQ;
00508     }
00509 
00523     public function getStockCheckQuery( $blForceCoreTable = null )
00524     {
00525         $myConfig = $this->getConfig();
00526         $sTable = $this->getViewName( $blForceCoreTable );
00527 
00528         $sQ = "";
00529 
00530         //do not check for variants
00531         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00532             $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0  ) ";
00533             //V #M513: When Parent article is not purchaseble, it's visibility should be displayed in shop only if any of Variants is available.
00534             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00535                 $sTimeCheckQ = '';
00536                 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00537                      $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00538                      $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00539                 }
00540                 $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 ) ) ";
00541             }
00542         }
00543 
00544         return $sQ;
00545     }
00546 
00558     public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null  )
00559     {
00560         $sTable = $this->getViewName( $blForceCoreTable );
00561         $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00562 
00563         //checking if variant is active and stock status
00564         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00565             $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00566             if ( $blRemoveNotOrderables ) {
00567                 $sQ .= " and $sTable.oxstockflag != 3 ";
00568             }
00569             $sQ .= " ) ) ";
00570         }
00571 
00572         return $sQ;
00573     }
00574 
00582     public function getSqlActiveSnippet( $blForceCoreTable = null )
00583     {
00584         $myConfig = $this->getConfig();
00585 
00586         // check if article is still active
00587         $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00588 
00589         // stock and variants check
00590         $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00591 
00592 
00593         return "( $sQ ) ";
00594     }
00595 
00603     public function setSkipAssign($blSkipAssign)
00604     {
00605         $this->_blSkipAssign = $blSkipAssign;
00606     }
00607 
00613     public function disablePriceLoad()
00614     {
00615         $this->_blLoadPrice = false;
00616     }
00617 
00623     public function getItemKey()
00624     {
00625         return $this->_sItemKey;
00626     }
00627 
00635     public function setItemKey($sItemKey)
00636     {
00637         $this->_sItemKey = $sItemKey;
00638     }
00639 
00647     public function setNoVariantLoading( $blLoadVariants )
00648     {
00649         $this->_blLoadVariants = !$blLoadVariants;
00650     }
00651 
00657     public function isBuyable()
00658     {
00659         if ($this->_blNotBuyableParent) {
00660             return false;
00661         }
00662 
00663         return !$this->_blNotBuyable;
00664     }
00665 
00671     public function getPersParams()
00672     {
00673         return $this->_aPersistParam;
00674     }
00675 
00681     public function isOnComparisonList()
00682     {
00683         return $this->_blIsOnComparisonList;
00684     }
00685 
00693     public function setOnComparisonList( $blOnList )
00694     {
00695         $this->_blIsOnComparisonList = $blOnList;
00696     }
00697 
00705     public function setLoadParentData($blLoadParentData)
00706     {
00707         $this->_blLoadParentData = $blLoadParentData;
00708     }
00709 
00717     public function setSkipAbPrice( $blSkipAbPrice = null )
00718     {
00719         $this->_blSkipAbPrice = $blSkipAbPrice;
00720     }
00721 
00729     public function getSearchableFields()
00730     {
00731         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00732         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00733 
00734         return $aFields;
00735     }
00736 
00737 
00745     public function isMultilingualField($sFieldName)
00746     {
00747         switch ($sFieldName) {
00748             case "oxlongdesc":
00749             case "oxtags":
00750                 return true;
00751         }
00752 
00753         return parent::isMultilingualField($sFieldName);
00754     }
00755 
00761     public function isVisible()
00762     {
00763 
00764         // admin preview mode
00765         if ( ( $blCanPreview = oxUtils::getInstance()->canPreview() ) !== null ) {
00766             return $blCanPreview;
00767         }
00768 
00769         // active ?
00770         $sNow = date('Y-m-d H:i:s');
00771         if ( !$this->oxarticles__oxactive->value &&
00772              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00773                 $this->oxarticles__oxactiveto->value < $sNow
00774              )) {
00775             return false;
00776         }
00777 
00778         // stock flags
00779         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00780             $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00781             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00782                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00783             }
00784             if ( $iOnStock <= 0 ) {
00785                 return false;
00786             }
00787         }
00788 
00789         return true;
00790     }
00791 
00800     public function assign( $aRecord)
00801     {
00802         startProfile('articleAssign');
00803 
00804 
00805         // load object from database
00806         parent::assign( $aRecord);
00807 
00808         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00809 
00810         // check for simple article.
00811         if ($this->_blSkipAssign) {
00812             return;
00813         }
00814 
00815         $this->_assignParentFieldValues();
00816         $this->_assignNotBuyableParent();
00817 
00818         $this->_assignStock();
00819         startProfile('articleAssignPrices');
00820         $this->_assignPrices();
00821         stopProfile('articleAssignPrices');
00822         $this->_assignPersistentParam();
00823         $this->_assignDynImageDir();
00824         $this->_assignComparisonListFlag();
00825         $this->_assignAttributes();
00826 
00827 
00828         //$this->_seoAssign();
00829 
00830         stopProfile('articleAssign');
00831     }
00832 
00843     public function load( $oxID)
00844     {
00845         // A. #1325 resetting to avoid problems when reloading (details etc)
00846         $this->_blNotBuyableParent = false;
00847 
00848         $blRet = parent::load( $oxID);
00849 
00850         // convert date's to international format
00851         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00852         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00853 
00854         return $blRet;
00855     }
00856 
00864     public function addToRatingAverage( $iRating )
00865     {
00866         $dOldRating = $this->oxarticles__oxrating->value;
00867         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00868         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00869         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00870         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00871         $dRatingCnt = (int) ($dOldCnt + 1);
00872         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00873         $oDb = oxDb::getDb();
00874         $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00875     }
00876 
00884     public function setRatingAverage( $iRating )
00885     {
00886          $this->oxarticles__oxrating = new oxField( $iRating );
00887     }
00888 
00896     public function setRatingCount( $iRatingCnt )
00897     {
00898          $this->oxarticles__oxratingcnt = new oxField( $iRatingCnt );
00899     }
00900 
00908     public function getArticleRatingAverage( $blIncludeVariants = false )
00909     {
00910         if ( !$blIncludeVariants ) {
00911             return round( $this->oxarticles__oxrating->value, 1);
00912         } else {
00913             $oRating = oxNew( 'oxRating' );
00914             return $oRating->getRatingAverage( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00915         }
00916     }
00917 
00925     public function getArticleRatingCount( $blIncludeVariants = false )
00926     {
00927         if ( !$blIncludeVariants ) {
00928             return $this->oxarticles__oxratingcnt->value;
00929         } else {
00930             $oRating = oxNew( 'oxRating' );
00931             return $oRating->getRatingCount( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00932         }
00933     }
00934 
00935 
00941     public function getReviews()
00942     {
00943         $aIds = array($this->getId());
00944 
00945         if ( $this->oxarticles__oxparentid->value ) {
00946             $aIds[] = $this->oxarticles__oxparentid->value;
00947         }
00948 
00949         // showing variant reviews ..
00950         if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00951             $aAdd = $this->_getVariantsIds();
00952             if (is_array($aAdd)) {
00953                 $aIds = array_merge($aIds, $aAdd);
00954             }
00955         }
00956 
00957         $oReview = oxNew('oxreview');
00958         $oRevs = $oReview->loadList('oxarticle', $aIds);
00959 
00960         //if no review found, return null
00961         if ( $oRevs->count() < 1 ) {
00962             return null;
00963         }
00964 
00965         return $oRevs;
00966     }
00967 
00973     public function getCrossSelling()
00974     {
00975         $oCrosslist = oxNew( "oxarticlelist");
00976         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00977         if ( $oCrosslist->count() ) {
00978             return $oCrosslist;
00979         }
00980     }
00981 
00987     public function getAccessoires()
00988     {
00989         $myConfig = $this->getConfig();
00990 
00991         // Performance
00992         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00993             return;
00994         }
00995 
00996         $oAcclist = oxNew( "oxarticlelist");
00997         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00998         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00999 
01000         if ( $oAcclist->count()) {
01001             return $oAcclist;
01002         }
01003     }
01004 
01010     public function getSimilarProducts()
01011     {
01012         // Performance
01013         $myConfig = $this->getConfig();
01014         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01015             return;
01016         }
01017 
01018         $sArticleTable = $this->getViewName();
01019 
01020         $sAttribs = '';
01021         $iCnt = 0;
01022         $this->_getAttribsString($sAttribs, $iCnt);
01023 
01024         if ( !$sAttribs) {
01025             return null;
01026         }
01027 
01028         $aList = $this->_getSimList($sAttribs, $iCnt);
01029 
01030         if ( count( $aList ) ) {
01031             uasort( $aList, 'cmpart');
01032 
01033             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01034 
01035             $oSimilarlist = oxNew( 'oxarticlelist' );
01036             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01037             $oSimilarlist->selectString( $sSearch);
01038 
01039             return $oSimilarlist;
01040         }
01041     }
01042 
01048     public function getCustomerAlsoBoughtThisProducts()
01049     {
01050         // Performance
01051         $myConfig = $this->getConfig();
01052         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01053             return;
01054         }
01055 
01056         // selecting products that fits
01057         $sQ = $this->_generateSearchStrForCustomerBought();
01058 
01059         $oArticles = oxNew( 'oxarticlelist' );
01060         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01061         $oArticles->selectString( $sQ );
01062         if ( $oArticles->count() ) {
01063             return $oArticles;
01064         }
01065     }
01066 
01073     public function loadAmountPriceInfo()
01074     {
01075         $myConfig = $this->getConfig();
01076         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice || !$this->hasAmountPrice() ) {
01077             return array();
01078         }
01079 
01080         if ( $this->_oAmountPriceInfo === null ) {
01081             $this->_oAmountPriceInfo = array();
01082             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01083                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01084             }
01085         }
01086         return $this->_oAmountPriceInfo;
01087     }
01088 
01096     public function getSelectLists($sKeyPrefix = null)
01097     {
01098         //#1468C - more then one article in basket with different selectlist...
01099         //optionall function parameter $sKeyPrefix added, used only in basket.php
01100         $sKey = $this->getId();
01101         if ( isset( $sKeyPrefix ) ) {
01102             $sKey = $sKeyPrefix.'__'.$this->getId();
01103         }
01104 
01105         if ( !isset( self::$_aSelList[$sKey] ) ) {
01106             $oDb = oxDb::getDb();
01107             $sSLViewName = getViewName( 'oxselectlist' );
01108 
01109             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01110                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01111 
01112             // all selectlists this article has
01113             $oLists = oxNew( 'oxlist' );
01114             $oLists->init( 'oxselectlist' );
01115             $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01116 
01117             //#1104S if this is variant ant it has no selectlists, trying with parent
01118             if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01119                 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01120             }
01121 
01122             $dVat = 0;
01123             if ( $this->getPrice() != null ) {
01124                 $dVat = $this->getPrice()->getVat();
01125             }
01126 
01127             $iCnt = 0;
01128             self::$_aSelList[$sKey] = array();
01129             foreach ( $oLists as $oSelectlist ) {
01130                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01131                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01132                 $iCnt++;
01133             }
01134         }
01135         return self::$_aSelList[$sKey];
01136     }
01137 
01145     protected function _hasAnyVariant( $blForceCoreTable = null )
01146     {
01147         $blHas = false;
01148         if ( ( $sId = $this->getId() ) ) {
01149             if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01150                 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01151             } else {
01152                 $sArticleTable = $this->getViewName( $blForceCoreTable );
01153                 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01154             }
01155 
01156         }
01157         return $blHas;
01158     }
01159 
01165     public function hasMdVariants()
01166     {
01167         return $this->_blHasMdVariants;
01168     }
01169 
01179     public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01180     {
01181 
01182         $iLimit = (int) $iLimit;
01183         if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01184             $this->_aVariantSelections[$iLimit] = false;
01185 
01186 
01187 
01188             if ( $this->oxarticles__oxvarcount->value ) {
01189 
01190                 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $this->getVariants(), $aFilterIds, $sActVariantId, $iLimit );
01191             }
01192         }
01193 
01194         return $this->_aVariantSelections[$iLimit];
01195     }
01196 
01205     public function getSelections( $iLimit = null, $aFilter = null )
01206     {
01207         $sId = $this->getId() . ( (int) $iLimit );
01208         if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01209 
01210             $oDb = oxDb::getDb();
01211             $sSLViewName = getViewName( 'oxselectlist' );
01212 
01213             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01214                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01215 
01216             if ( ( $iLimit = (int) $iLimit ) ) {
01217                 $sQ .= " limit $iLimit ";
01218             }
01219 
01220             // vat value for price
01221             $dVat = 0;
01222             if ( ( $oPrice = $this->getPrice() ) != null ) {
01223                 $dVat = $oPrice->getVat();
01224             }
01225 
01226             // all selectlists this article has
01227             $oList = oxNew( 'oxlist' );
01228             $oList->init( 'oxselectlist' );
01229             $oList->getBaseObject()->setVat( $dVat );
01230             $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01231 
01232             //#1104S if this is variant and it has no selectlists, trying with parent
01233             if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01234                 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01235             }
01236 
01237             self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01238         }
01239 
01240         if ( self::$_aSelections[$sId] ) {
01241             // marking active from filter
01242             $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01243             if ( $aFilter ) {
01244                 $iSelIdx = 0;
01245                 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01246                     if ( isset( $aFilter[$iSelIdx] ) ) {
01247                         $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01248                     }
01249                     $iSelIdx++;
01250                 }
01251             }
01252         }
01253 
01254         return self::$_aSelections[$sId];
01255     }
01256 
01266     protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01267     {
01268         $oVariants = array();
01269         if ( ( $sId = $this->getId() ) ) {
01270             //do not load me as a parent later
01271             self::$_aLoadedParents[$sId] = $this;
01272 
01273             $myConfig = $this->getConfig();
01274 
01275             if ( !$this->_blLoadVariants ||
01276                 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01277                 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01278                 return $oVariants;
01279             }
01280 
01281             // cache
01282             $sCacheKey = $blSimple ? "simple" : "full";
01283             if ( $blRemoveNotOrderables ) {
01284                 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01285                    return $this->_aVariants[$sCacheKey];
01286                 } else {
01287                     $this->_aVariants[$sCacheKey] = & $oVariants;
01288                 }
01289             } elseif ( !$blRemoveNotOrderables ) {
01290                 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01291                     return $this->_aVariantsWithNotOrderables[$sCacheKey];
01292                 } else {
01293                     $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01294                 }
01295             }
01296 
01297             if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01298 
01299                 //load simple variants for lists
01300                 if ( $blSimple ) {
01301                     $oVariants = oxNew( 'oxsimplevariantlist' );
01302                     $oVariants->setParent( $this );
01303                 } else {
01304                     //loading variants
01305                     $oVariants = oxNew( 'oxarticlelist' );
01306                     $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01307                 }
01308 
01309                 startProfile("selectVariants");
01310                 $blUseCoreTable = (bool) $blForceCoreTable;
01311                 $oBaseObject = $oVariants->getBaseObject();
01312                 $oBaseObject->setLanguage( $this->getLanguage() );
01313 
01314 
01315                 $sArticleTable = $this->getViewName( $blUseCoreTable );
01316 
01317                 $sSelect = "select ".$oBaseObject->getSelectFields( $blUseCoreTable )." from $sArticleTable where " .
01318                            $this->getActiveCheckQuery( $blUseCoreTable ) .
01319                            $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01320                            " order by $sArticleTable.oxsort";
01321 
01322 
01323                 $oVariants->selectString( $sSelect );
01324 
01325                 //if this is multidimensional variants, make additional processing
01326                 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01327                     $oMdVariants = oxNew( "oxVariantHandler" );
01328                     $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01329                 }
01330                 stopProfile("selectVariants");
01331             }
01332 
01333             //if we have variants then depending on config option the parent may be non buyable
01334             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01335                 $this->_blNotBuyableParent = true;
01336             }
01337 
01338             //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01339             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01340                 $this->_blNotBuyable = true;
01341             }
01342         }
01343 
01344         return $oVariants;
01345     }
01346 
01355     public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01356     {
01357         return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01358     }
01359 
01368     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null  )
01369     {
01370         return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01371     }
01372 
01378     public function getSimpleVariants()
01379     {
01380         if ( $this->oxarticles__oxvarcount->value) {
01381             return $this->getVariants();
01382         }
01383     }
01384 
01393     public function getAdminVariants( $sLanguage = null )
01394     {
01395         $oVariants = oxNew( 'oxarticlelist');
01396         if ( ( $sId = $this->getId() ) ) {
01397 
01398             $oBaseObj = $oVariants->getBaseObject();
01399 
01400             if ( is_null( $sLanguage ) ) {
01401                 $oBaseObj->setLanguage( oxLang::getInstance()->getBaseLanguage() );
01402             } else {
01403                 $oBaseObj->setLanguage( $sLanguage );
01404             }
01405 
01406             $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01407             $oVariants->selectString( $sSql );
01408 
01409             //if we have variants then depending on config option the parent may be non buyable
01410             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01411                 //$this->blNotBuyable = true;
01412                 $this->_blNotBuyableParent = true;
01413             }
01414         }
01415 
01416         return $oVariants;
01417     }
01418 
01426     public function getCategory()
01427     {
01428         $oCategory = oxNew( 'oxcategory' );
01429         $oCategory->setLanguage( $this->getLanguage() );
01430 
01431         // variant handling
01432         $sOXID = $this->getId();
01433         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01434             $sOXID = $this->oxarticles__oxparentid->value;
01435         }
01436 
01437         if ( $sOXID ) {
01438             // if the oxcategory instance of this article is not cached
01439             if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01440                 startPRofile( 'getCategory' );
01441                 $oStr = getStr();
01442                 $sWhere   = $oCategory->getSqlActiveSnippet();
01443                 $sSelect  = $this->_generateSearchStr( $sOXID );
01444                 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01445 
01446                 // category not found ?
01447                 if ( !$oCategory->assignRecord( $sSelect ) ) {
01448 
01449                     $sSelect  = $this->_generateSearchStr( $sOXID, true );
01450                     $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01451 
01452                     // looking for price category
01453                     if ( !$oCategory->assignRecord( $sSelect ) ) {
01454                         $oCategory = null;
01455                     }
01456                 }
01457                 // add the category instance to cache
01458                 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01459                 stopPRofile( 'getCategory' );
01460             } else {
01461                // if the oxcategory instance is cached
01462                $oCategory = $this->_aCategoryCache[ $sOXID ];
01463             }
01464         }
01465 
01466         return $oCategory;
01467     }
01468 
01477     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01478     {
01479         $myConfig = $this->getConfig();
01480         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01481             return self::$_aArticleCats[$this->getId()];
01482         }
01483 
01484         // variant handling
01485         $sOXID = $this->getId();
01486         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01487             $sOXID = $this->oxarticles__oxparentid->value;
01488         }
01489 
01490         // we do not use lists here as we dont need this overhead right now
01491         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01492         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01493         $rs = $oDb->select( $sSql );
01494 
01495 
01496         $aRet = array();
01497 
01498         if ($rs != false && $rs->recordCount() > 0) {
01499             while (!$rs->EOF) {
01500                 $aRet[] = $rs->fields['oxcatnid'];
01501                 $rs->moveNext();
01502             }
01503         }
01504 
01505         // adding price categories if such exists
01506         $sSql = $this->getSqlForPriceCategories();
01507         $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
01508         $rs = $oDb->select( $sSql );
01509 
01510         if ($rs != false && $rs->recordCount() > 0) {
01511             while (!$rs->EOF) {
01512 
01513                 if ( is_array( $rs->fields ) ) {
01514                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01515                 }
01516 
01517 
01518                 if ( !$aRet[$rs->fields['oxid']] ) {
01519                     $aRet[] = $rs->fields['oxid'];
01520                 }
01521                 $rs->moveNext();
01522             }
01523         }
01524 
01525         return self::$_aArticleCats[$this->getId()] = $aRet;
01526     }
01527 
01536     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01537     {
01538         $sO2CView = $this->_getObjectViewName('oxobject2category');
01539         $sCatView = $this->_getObjectViewName('oxcategories');
01540         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01541         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01542         if ( $blActCats ) {
01543             $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 ";
01544         }
01545         $sSelect .= 'order by oxobject2category.oxtime ';
01546         return $sSelect;
01547     }
01548 
01558     public function getVendor( $blShopCheck = true )
01559     {
01560         if ( ( $sVendorId = $this->getVendorId() ) ) {
01561             $oVendor = oxNew( 'oxvendor' );
01562         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01563                 $oVendor = oxNew( 'oxi18n' );
01564                 $oVendor->init('oxvendor');
01565                 $oVendor->setReadOnly( true );
01566             $sVendorId = $this->oxarticles__oxvendorid->value;
01567         }
01568         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01569 
01570             //@deprecated in v.4.5.7, since 2012-02-15; config option removed bug #0003385
01571             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01572                 $oVendor->setReadOnly( true );
01573             }
01574             return $oVendor;
01575         }
01576         return null;
01577     }
01578 
01586     public function getVendorId( $blForceReload = false )
01587     {
01588         $sVendorId = false;
01589         if ( $this->oxarticles__oxvendorid->value ) {
01590                 $sVendorId = $this->oxarticles__oxvendorid->value;
01591 
01592         }
01593         return $sVendorId;
01594     }
01595 
01603     public function getManufacturerId( $blForceReload = false )
01604     {
01605         $sManufacturerId = false;
01606         if ( $this->oxarticles__oxmanufacturerid->value ) {
01607 
01608                 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01609 
01610         }
01611         return $sManufacturerId;
01612     }
01613 
01623     public function getManufacturer( $blShopCheck = true )
01624     {
01625             $oManufacturer = oxNew( 'oxmanufacturer' );;
01626         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01627              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01628             $oManufacturer->setReadOnly( true );
01629             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01630         }
01631 
01632         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01633             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01634                 $oManufacturer->setReadOnly( true );
01635             }
01636             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01637         } else {
01638             $oManufacturer = null;
01639         }
01640 
01641         return $oManufacturer;
01642     }
01643 
01651     public function inCategory( $sCatNid)
01652     {
01653         return in_array( $sCatNid, $this->getCategoryIds());
01654     }
01655 
01664     public function isAssignedToCategory( $sCatId )
01665     {
01666         // variant handling
01667         $sOXID = $this->getId();
01668         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01669             $sOXID = $this->oxarticles__oxparentid->value;
01670         }
01671 
01672         $oDb = oxDb::getDb();
01673         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01674         $sOXID = $oDb->getOne( $sSelect );
01675         // article is assigned to passed category!
01676         if ( isset( $sOXID) && $sOXID) {
01677             return true;
01678         }
01679 
01680         // maybe this category is price category ?
01681         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01682             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01683             if ( $dPriceFromTo > 0) {
01684                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01685                 $sOXID = $oDb->getOne( $sSelect );
01686                 // article is assigned to passed category!
01687                 if ( isset( $sOXID) && $sOXID) {
01688                     return true;
01689                 }
01690             }
01691         }
01692         return false;
01693     }
01694 
01700     public function getTPrice()
01701     {
01702         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01703             return;
01704         }
01705         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01706         if ( $this->_oTPrice !== null ) {
01707             return $this->_oTPrice;
01708         }
01709 
01710         $this->_oTPrice = oxNew( 'oxPrice' );
01711         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01712 
01713         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01714         $this->_applyCurrency( $this->_oTPrice );
01715 
01716         return $this->_oTPrice;
01717     }
01718 
01724     public function skipDiscounts()
01725     {
01726         // allready loaded skip discounts config
01727         if ( $this->_blSkipDiscounts !== null ) {
01728             return $this->_blSkipDiscounts;
01729         }
01730 
01731         if ( $this->oxarticles__oxskipdiscounts->value ) {
01732             return true;
01733         }
01734 
01735 
01736         $this->_blSkipDiscounts = false;
01737         if ( oxDiscountList::getInstance()->hasSkipDiscountCategories() ) {
01738 
01739             $oDb = oxDb::getDb();
01740             $sO2CView  = getViewName( 'oxobject2category', $this->getLanguage() );
01741             $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01742             $sSelect =  "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01743                          where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01744             $this->_blSkipDiscounts = ( $oDb->getOne( $sSelect ) == 1 );
01745         }
01746 
01747         return $this->_blSkipDiscounts;
01748     }
01749 
01757     public function setPrice(oxPrice $oPrice)
01758     {
01759         $this->_oPrice = $oPrice;
01760     }
01761 
01770     public function getBasePrice( $dAmount = 1 )
01771     {
01772         // override this function if you want e.g. different prices
01773         // for diff. usergroups.
01774 
01775         // Performance
01776         $myConfig = $this->getConfig();
01777         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01778             return;
01779 
01780         // GroupPrice or DB price ajusted by AmountPrice
01781         $dPrice = $this->_getAmountPrice( $dAmount );
01782 
01783 
01784         return $dPrice;
01785     }
01786 
01794     public function getPrice( $dAmount = 1 )
01795     {
01796         $myConfig = $this->getConfig();
01797         // Performance
01798         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01799             return;
01800         }
01801 
01802         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01803         if ( $dAmount != 1 || $this->_oPrice === null ) {
01804             $oPrice = oxNew( 'oxPrice' );
01805 
01806             // get base
01807             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01808 
01809             // price handling
01810             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01811                 return $this->_oPrice = $oPrice;
01812             }
01813 
01814             $this->_calculatePrice( $oPrice );
01815             if ( $dAmount != 1 ) {
01816                 return $oPrice;
01817             }
01818 
01819             $this->_oPrice = $oPrice;
01820         }
01821         return $this->_oPrice;
01822     }
01823 
01832     protected function _calculatePrice( $oPrice, $dVat = null )
01833     {
01834         // apply VAT only if configuration requires it
01835         if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01836             $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01837         }
01838 
01839         // apply currency
01840         $this->_applyCurrency( $oPrice );
01841         // apply discounts
01842         if ( !$this->skipDiscounts() ) {
01843             $oDiscountList = oxDiscountList::getInstance();
01844             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
01845         }
01846 
01847         return $oPrice;
01848     }
01849 
01857     public function setArticleUser($oUser)
01858     {
01859         $this->_oUser = $oUser;
01860     }
01861 
01867     public function getArticleUser()
01868     {
01869         if ($this->_oUser) {
01870             return $this->_oUser;
01871         }
01872         return $this->getUser();
01873     }
01874 
01884     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01885     {
01886         $oUser = $oBasket->getBasketUser();
01887         $this->setArticleUser( $oUser );
01888 
01889         $oBasketPrice = oxNew( 'oxPrice' );
01890 
01891         // get base price
01892         $dBasePrice = $this->getBasePrice( $dAmount );
01893 
01894         // applying select list price
01895         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01896 
01897         // setting price
01898         $oBasketPrice->setPrice( $dBasePrice );
01899 
01900         $dVat = oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket );
01901         $this->_calculatePrice( $oBasketPrice, $dVat );
01902 
01903         // returning final price object
01904         return $oBasketPrice;
01905     }
01906 
01919     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01920     {
01921         $oDiscountList = oxDiscountList::getInstance();
01922         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01923     }
01924 
01933     public function delete( $sOXID = null )
01934     {
01935         if ( !$sOXID ) {
01936             $sOXID = $this->getId();
01937         }
01938         if ( !$sOXID ) {
01939             return false;
01940         }
01941 
01942 
01943         // #2339 delete first variants before deleting parent product
01944         $this->_deleteVariantRecords( $sOXID );
01945         $this->load( $sOXID );
01946         $this->_deletePics();
01947         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01948 
01949         // delete self
01950         parent::delete( $sOXID );
01951 
01952         $rs = $this->_deleteRecords( $sOXID );
01953 
01954         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01955 
01956         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01957 
01958         return $rs->EOF;
01959     }
01960 
01969     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01970     {
01971         $this->beforeUpdate();
01972 
01973         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01974         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01975             $dAmount += $iStockCount;
01976             $iStockCount = 0;
01977         }
01978         $this->oxarticles__oxstock = new oxField($iStockCount);
01979 
01980         $oDb = oxDb::getDb();
01981         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01982         $this->onChange( ACTION_UPDATE_STOCK );
01983         return $dAmount;
01984     }
01985 
01994     public function updateSoldAmount( $dAmount = 0 )
01995     {
01996         if ( !$dAmount ) {
01997             return;
01998         }
01999 
02000         $this->beforeUpdate();
02001 
02002         // article is not variant - should be updated current amount
02003         if ( !$this->oxarticles__oxparentid->value ) {
02004             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
02005             $dAmount = (double) $dAmount;
02006             $oDb = oxDb::getDb();
02007             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02008         } elseif ( $this->oxarticles__oxparentid->value) {
02009             // article is variant - should be updated this article parent amount
02010             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
02011             $oUpdateArticle->updateSoldAmount( $dAmount );
02012         }
02013 
02014         $this->onChange( ACTION_UPDATE );
02015 
02016         return $rs;
02017     }
02018 
02024     public function disableReminder()
02025     {
02026         $oDb = oxDb::getDb();
02027         return $oDb->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02028     }
02029 
02037     public function save()
02038     {
02039         // @deprecated since 20110821. folders are no more written, getters must be user for urls
02040         $this->oxarticles__oxthumb = new oxField( basename( $this->oxarticles__oxthumb->value ), oxField::T_RAW );
02041         $this->oxarticles__oxicon  = new oxField( basename( $this->oxarticles__oxicon->value ), oxField::T_RAW );
02042         $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
02043         for ( $i = 1; $i <= $iPicCount; $i++ ) {
02044             $sFieldName = 'oxarticles__oxpic' . $i;
02045             if ( isset( $this->$sFieldName ) ) {
02046                 $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );
02047             }
02048         }
02049         // @end deprecated
02050 
02051         if ( ( $blRet = parent::save() ) ) {
02052             // saving long descrition
02053             $this->_saveArtLongDesc();
02054         }
02055 
02056         return $blRet;
02057     }
02058 
02059 
02066     public function getPictureGallery()
02067     {
02068         $myConfig = $this->getConfig();
02069 
02070         //initialize
02071         $blMorePic = false;
02072         $aArtPics  = array();
02073         $aArtIcons = array();
02074         $iActPicId = 1;
02075         $sActPic = $this->getPictureUrl( $iActPicId );
02076 
02077         if ( oxConfig::getParameter( 'actpicid' ) ) {
02078             $iActPicId = oxConfig::getParameter('actpicid');
02079         }
02080 
02081         $oStr = getStr();
02082         $iCntr = 0;
02083         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02084         $blCheckActivePicId = true;
02085 
02086         for ( $i = 1; $i <= $iPicCount; $i++) {
02087             $sPicVal = $this->getPictureUrl( $i );
02088             $sIcoVal = $this->getIconUrl( $i );
02089             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02090                  !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02091                 if ($iCntr) {
02092                     $blMorePic = true;
02093                 }
02094                 $aArtIcons[$i]= $sIcoVal;
02095                 $aArtPics[$i]= $sPicVal;
02096                 $iCntr++;
02097 
02098                 if ($iActPicId == $i) {
02099                     $sActPic = $sPicVal;
02100                     $blCheckActivePicId = false;
02101                 }
02102 
02103             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02104                 // if picture is empty, setting active pic id to next
02105                 // picture
02106                 $iActPicId++;
02107             }
02108         }
02109 
02110         $blZoomPic  = false;
02111         $aZoomPics = array();
02112         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02113 
02114         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02115             $sVal = $this->getZoomPictureUrl($j);
02116 
02117             if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02118                 $blZoomPic = true;
02119                 $aZoomPics[$c]['id'] = $c;
02120                 $aZoomPics[$c]['file'] = $sVal;
02121                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02122                 if (!$sVal) {
02123                     $aZoomPics[$c]['file'] = "nopic.jpg";
02124                 }
02125                 $c++;
02126             }
02127         }
02128 
02129         $aPicGallery = array('ActPicID' => $iActPicId,
02130                              'ActPic' => $sActPic,
02131                              'MorePics' => $blMorePic,
02132                              'Pics' => $aArtPics,
02133                              'Icons' => $aArtIcons,
02134                              'ZoomPic' => $blZoomPic,
02135                              'ZoomPics' => $aZoomPics);
02136 
02137         return $aPicGallery;
02138     }
02139 
02153     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02154     {
02155         $myConfig = $this->getConfig();
02156 
02157         if (!isset($sOXID)) {
02158             if ( $this->getId()) {
02159                 $sOXID = $this->getId();
02160             }
02161             if (!isset ($sOXID)) {
02162                 $sOXID = $this->oxarticles__oxid->value;
02163             }
02164             if ($this->oxarticles__oxparentid->value) {
02165                 $sParentID = $this->oxarticles__oxparentid->value;
02166             }
02167         }
02168         if (!isset($sOXID)) {
02169             return;
02170         }
02171 
02172         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02173         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02174             //if article has variants then updating oxvarstock field
02175             //getting parent id
02176             if (!isset($sParentID)) {
02177                 $oDb = oxDb::getDb();
02178                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02179                 $sParentID = $oDb->getOne( $sQ );
02180             }
02181             //if we have parent id then update stock
02182             if ($sParentID) {
02183                 $this->_onChangeUpdateStock($sParentID);
02184             }
02185         }
02186         //if we have parent id then update count
02187         //update count even if blUseStock is not active
02188         if ($sParentID) {
02189             $this->_onChangeUpdateVarCount($sParentID);
02190         }
02191 
02192         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02193         $this->_onChangeUpdateMinVarPrice( $sId );
02194 
02195             // reseting articles count cache if stock has changed and some
02196             // articles goes offline (M:1448)
02197             if ( $sAction === ACTION_UPDATE_STOCK ) {
02198                 $this->_onChangeStockResetCount( $sOXID );
02199             }
02200 
02201     }
02202 
02209     public function getCustomVAT()
02210     {
02211         if ( isset($this->oxarticles__oxvat->value) ) {
02212             return $this->oxarticles__oxvat->value;
02213         }
02214     }
02215 
02224     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02225     {
02226         $myConfig = $this->getConfig();
02227         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02228             return true;
02229         }
02230 
02231         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
02232         // fetching DB info as its up-to-date
02233         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.$oDb->quote( $this->getId() );
02234         $rs = $oDb->select( $sQ );
02235 
02236         $iOnStock   = 0;
02237         $iStockFlag = 0;
02238         if ( $rs !== false && $rs->recordCount() > 0 ) {
02239             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02240             $iStockFlag = $rs->fields['oxstockflag'];
02241 
02242             // dodger : fremdlager is also always considered as on stock
02243             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02244                 return true;
02245             }
02246             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02247                 $iOnStock = floor( $iOnStock );
02248             }
02249         }
02250         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02251             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02252         }
02253         if ( $iOnStock >= $dAmount ) {
02254             return true;
02255         } else {
02256             if ( $iOnStock > 0 ) {
02257                 return $iOnStock;
02258             } else {
02259                 $oEx = oxNew( 'oxArticleInputException' );
02260                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02261                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02262                 return false;
02263             }
02264         }
02265     }
02266 
02267 
02277     public function getArticleLongDesc( $sOxid = null )
02278     {
02279         return $this->getLongDescription();
02280     }
02281 
02287     public function getLongDescription()
02288     {
02289         if ( $this->_oLongDesc === null ) {
02290             // initializing
02291             $this->_oLongDesc = new oxField();
02292 
02293 
02294             // choosing which to get..
02295             $sOxid = $this->getId();
02296             $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02297 
02298             $oDb = oxDb::getDb();
02299             $sDbValue = $oDb->getOne( "select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote( $sOxid ) );
02300 
02301             if ( $sDbValue != false ) {
02302                 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02303             } elseif ( $this->oxarticles__oxparentid->value ) {
02304                 $this->_oLongDesc->setValue( $this->getParentArticle()->getLongDescription()->getRawValue(), oxField::T_RAW );
02305             }
02306         }
02307         return $this->_oLongDesc;
02308     }
02309 
02319     protected function _setLongDesc( $sDbValue )
02320     {
02321         $this->setArticleLongDesc( $sDbValue );
02322     }
02323 
02330     public function getLongDesc()
02331     {
02332         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getLongDescription()->getRawValue(), $this->getId().$this->getLanguage() );
02333     }
02334 
02343     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02344     {
02345 
02346         // setting current value
02347         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02348 
02349         // setting original value?
02350         //deprecated since 2012-02-13 in v.4.5.7
02351         if ( $sOrigValue ) {
02352             $this->_oLongDesc->orignalValue = $sOrigValue;
02353         }
02354     }
02355 
02361     public function getAttributes()
02362     {
02363         if ( $this->_oAttributeList === null ) {
02364             $this->_oAttributeList = oxNew( 'oxattributelist' );
02365             $this->_oAttributeList->loadAttributes( $this->getId() );
02366         }
02367 
02368         return $this->_oAttributeList;
02369     }
02370 
02379     public function appendLink( $sAddParams, $iLang = null )
02380     {
02381         if ( $sAddParams ) {
02382             if ( $iLang === null ) {
02383                 $iLang = $this->getLanguage();
02384             }
02385 
02386             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02387             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02388         }
02389     }
02390 
02399     public function getBaseSeoLink( $iLang, $blMain = false )
02400     {
02401         $oEncoder = oxSeoEncoderArticle::getInstance();
02402         if ( !$blMain ) {
02403             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02404         }
02405         return $oEncoder->getArticleMainUrl( $this, $iLang );
02406     }
02407 
02416     public function getLink( $iLang = null, $blMain = false  )
02417     {
02418         if ( !oxUtils::getInstance()->seoIsActive() ) {
02419             return $this->getStdLink( $iLang );
02420         }
02421 
02422         if ( $iLang === null ) {
02423             $iLang = $this->getLanguage();
02424         }
02425 
02426         $iLinkType = $this->getLinkType();
02427         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02428             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02429         }
02430 
02431         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02432         if ( isset($this->_aSeoAddParams[$iLang])) {
02433             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02434         }
02435 
02436         return $sUrl;
02437     }
02438 
02447     public function getMainLink( $iLang = null )
02448     {
02449         return $this->getLink( $iLang, true );
02450     }
02451 
02459     public function setLinkType( $iType )
02460     {
02461         // resetting detaisl link, to force new
02462         $this->_sDetailLink = null;
02463 
02464         // setting link type
02465         $this->_iLinkType = (int) $iType;
02466     }
02467 
02473     public function getLinkType()
02474     {
02475         return $this->_iLinkType;
02476     }
02477 
02486     public function appendStdLink( $sAddParams, $iLang = null )
02487     {
02488         if ( $sAddParams ) {
02489             if ( $iLang === null ) {
02490                 $iLang = $this->getLanguage();
02491             }
02492 
02493             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02494             $this->_aStdAddParams[$iLang] .= $sAddParams;
02495         }
02496     }
02497 
02507     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02508     {
02509         $sUrl = '';
02510         if ( $blFull ) {
02511             //always returns shop url, not admin
02512             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02513         }
02514 
02515         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02516         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02517     }
02518 
02527     public function getStdLink( $iLang = null, $aParams = array() )
02528     {
02529         if ( $iLang === null ) {
02530             $iLang = $this->getLanguage();
02531         }
02532 
02533         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02534             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02535         }
02536 
02537         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02538     }
02539 
02547     public function getStdTagLink( $sTag )
02548     {
02549         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02550         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02551     }
02552 
02558     public function getTags()
02559     {
02560         $oDb = oxDb::getDb();
02561         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02562         $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02563         $oTagCloud = oxNew('oxtagcloud');
02564         return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02565     }
02566 
02574     public function saveTags($sTags)
02575     {
02576         //do not allow derived update
02577         if ( !$this->allowDerivedUpdate() ) {
02578             return false;
02579         }
02580 
02581 
02582         $oTagCloud = oxNew( 'oxtagcloud' );
02583         $oTagCloud->resetTagCache();
02584         $sTags = oxDb::getInstance()->escapeString( $oTagCloud->prepareTags( $sTags ) );
02585         $oDb = oxDb::getDb();
02586 
02587         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02588         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02589         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02590                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02591         return $oDb->execute( $sQ );
02592     }
02593 
02601     public function addTag($sTag)
02602     {
02603         $oDb = oxDb::getDb();
02604 
02605         $oTagCloud = oxNew('oxtagcloud');
02606         $oTagCloud->resetTagCache();
02607         $sTag = $oTagCloud->prepareTags($sTag);
02608         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02609 
02610         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02611         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02612         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02613             $sTailTag = $sTagSeparator . $sTag;
02614         } else {
02615             $sTailTag = $sTag;
02616         }
02617 
02618         $sTag = oxDb::getInstance()->escapeString($sTag);
02619         $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02620 
02621         $sTag = oxDb::getInstance()->escapeString($sTag);
02622         $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02623 
02624         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02625                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02626 
02627         return $oDb->execute( $sQ );
02628     }
02629 
02635     public function getMediaUrls()
02636     {
02637         if ( $this->_aMediaUrls === null ) {
02638             $this->_aMediaUrls = oxNew("oxlist");
02639             $this->_aMediaUrls->init("oxmediaurl");
02640             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02641 
02642             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02643             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02644             $this->_aMediaUrls->selectString($sQ);
02645         }
02646         return $this->_aMediaUrls;
02647     }
02648 
02654     public function getDynImageDir()
02655     {
02656         return $this->_sDynImageDir;
02657     }
02658 
02664     public function getDispSelList()
02665     {
02666         if ($this->_aDispSelList === null) {
02667             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02668                 $this->_aDispSelList = $this->getSelectLists();
02669             }
02670         }
02671         return $this->_aDispSelList;
02672     }
02673 
02679     public function getMoreDetailLink()
02680     {
02681         if ( $this->_sMoreDetailLink == null ) {
02682 
02683             // and assign special article values
02684             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02685 
02686             // not always it is okey, as not all the time active category is the same as primary article cat.
02687             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02688                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02689             }
02690             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02691             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02692         }
02693 
02694         return $this->_sMoreDetailLink;
02695     }
02696 
02702     public function getToBasketLink()
02703     {
02704         if ( $this->_sToBasketLink == null ) {
02705             $myConfig = $this->getConfig();
02706 
02707             if ( oxUtils::getInstance()->isSearchEngine() ) {
02708                 $this->_sToBasketLink = $this->getLink();
02709             } else {
02710                 // and assign special article values
02711                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02712 
02713                 // override some classes as these should never showup
02714                 $sActClass = oxConfig::getParameter( 'cl' );
02715                 if ( $sActClass == 'thankyou') {
02716                     $sActClass = 'basket';
02717                 }
02718                 $this->_sToBasketLink .= 'cl='.$sActClass;
02719 
02720                 // this is not very correct
02721                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02722                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02723                 }
02724 
02725                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02726 
02727                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02728                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02729                 }
02730             }
02731         }
02732 
02733         return $this->_sToBasketLink;
02734     }
02735 
02741     public function getStockStatus()
02742     {
02743         return $this->_iStockStatus;
02744     }
02745 
02751     public function getDeliveryDate()
02752     {
02753         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02754             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02755         }
02756         return false;
02757     }
02758 
02764     public function getFTPrice()
02765     {
02766         if ( $oPrice = $this->getTPrice() ) {
02767             if ( $oPrice->getBruttoPrice() ) {
02768                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02769             }
02770         }
02771     }
02772 
02778     public function getFPrice()
02779     {
02780         if ( $oPrice = $this->getPrice() ) {
02781             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02782         }
02783     }
02784 
02790     public function getFNetPrice()
02791     {
02792         if ( $oPrice = $this->getPrice() ) {
02793             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02794         }
02795     }
02796 
02802     public function getPricePerUnit()
02803     {
02804         return $this->_fPricePerUnit;
02805     }
02806 
02812     public function isParentNotBuyable()
02813     {
02814         return $this->_blNotBuyableParent;
02815     }
02816 
02822     public function isNotBuyable()
02823     {
02824         return $this->_blNotBuyable;
02825     }
02826 
02834     public function setBuyableState( $blBuyable = false )
02835     {
02836         $this->_blNotBuyable = !$blBuyable;
02837     }
02838 
02847     public function getVariantList()
02848     {
02849         return $this->getVariants();
02850     }
02851 
02859     public function setSelectlist( $aSelList )
02860     {
02861         $this->_aDispSelList = $aSelList;
02862     }
02863 
02871     public function getPictureUrl( $iIndex = 1 )
02872     {
02873         if ( $iIndex ) {
02874             $sImgName = false;
02875             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02876                 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02877             }
02878 
02879             $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02880             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02881         }
02882     }
02883 
02892     public function getIconUrl( $iIndex = 0 )
02893     {
02894         $sImgName = false;
02895         $sDirname = "product/1/";
02896         if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02897             $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02898             $sDirname = "product/{$iIndex}/";
02899         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02900             $sImgName = basename( $this->oxarticles__oxicon->value );
02901             $sDirname = "product/icon/";
02902         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02903             $sImgName = basename( $this->oxarticles__oxpic1->value );
02904         }
02905 
02906         $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02907         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02908     }
02909 
02917     public function getThumbnailUrl( $bSsl = null )
02918     {
02919         $sImgName = false;
02920         $sDirname = "product/1/";
02921         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02922             $sImgName = basename( $this->oxarticles__oxthumb->value );
02923             $sDirname = "product/thumb/";
02924         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02925             $sImgName = basename( $this->oxarticles__oxpic1->value );
02926         }
02927 
02928         $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02929         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
02930     }
02931 
02939     public function getZoomPictureUrl( $iIndex = '' )
02940     {
02941         $iIndex = (int) $iIndex;
02942         if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02943             $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02944             $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02945             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02946         }
02947     }
02948 
02954     public function getFileUrl()
02955     {
02956         return $this->getConfig()->getPictureUrl( 'media/' );
02957     }
02958 
02964     public function getPriceFromPrefix()
02965     {
02966         $sPricePrefix = '';
02967         if ( $this->_blIsRangePrice) {
02968             $sPricePrefix = oxLang::getInstance()->translateString('priceFrom').' ';
02969         }
02970 
02971         return $sPricePrefix;
02972     }
02973 
02979     protected function _saveArtLongDesc()
02980     {
02981         $myConfig = $this->getConfig();
02982         $sShopId = $myConfig->getShopID();
02983         if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02984             return;
02985         }
02986 
02987         if ($this->_blEmployMultilanguage) {
02988             $sValue = $this->getLongDescription()->getRawValue();
02989             if ( $sValue !== null ) {
02990                 $oArtExt = oxNew('oxI18n');
02991                 $oArtExt->init('oxartextends');
02992                 $oArtExt->setLanguage((int) $this->getLanguage());
02993                 if (!$oArtExt->load($this->getId())) {
02994                     $oArtExt->setId($this->getId());
02995                 }
02996                 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02997                 $oArtExt->save();
02998             }
02999         } else {
03000             $oArtExt = oxNew('oxI18n');
03001             $oArtExt->setEnableMultilang(false);
03002             $oArtExt->init('oxartextends');
03003             $aObjFields = $oArtExt->_getAllFields(true);
03004             if (!$oArtExt->load($this->getId())) {
03005                 $oArtExt->setId($this->getId());
03006             }
03007 
03008             foreach ($aObjFields as $sKey => $sValue ) {
03009                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
03010                     $sField = $this->_getFieldLongName($sKey);
03011 
03012                     if (isset($this->$sField)) {
03013                         $sLongDesc = null;
03014                         if ($this->$sField instanceof oxField) {
03015                             $sLongDesc = $this->$sField->getRawValue();
03016                         } elseif (is_object($this->$sField)) {
03017                             $sLongDesc = $this->$sField->value;
03018                         }
03019                         if (isset($sLongDesc)) {
03020                             $sAEField = $oArtExt->_getFieldLongName($sKey);
03021                             $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
03022                         }
03023                     }
03024                 }
03025             }
03026             $oArtExt->save();
03027         }
03028     }
03029 
03035     protected function _skipSaveFields()
03036     {
03037         $myConfig = $this->getConfig();
03038 
03039         $this->_aSkipSaveFields = array();
03040 
03041         $this->_aSkipSaveFields[] = 'oxtimestamp';
03042        // $this->_aSkipSaveFields[] = 'oxlongdesc';
03043         $this->_aSkipSaveFields[] = 'oxinsert';
03044 
03045         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
03046             $this->_aSkipSaveFields[] = 'oxparentid';
03047         }
03048 
03049     }
03050 
03060     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03061     {
03062         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03063             // add prices of the same discounts
03064             if ( array_key_exists ($sKey, $aDiscounts) ) {
03065                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03066             } else {
03067                 $aDiscounts[$sKey] = $oDiscount;
03068             }
03069         }
03070         return $aDiscounts;
03071     }
03072 
03078     protected function _getGroupPrice()
03079     {
03080         $dPrice = $this->oxarticles__oxprice->value;
03081 
03082         $oUser = $this->getArticleUser();
03083         if ( $oUser ) {
03084             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03085                 $dPrice = $this->oxarticles__oxpricea->value;
03086             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03087                 $dPrice = $this->oxarticles__oxpriceb->value;
03088             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03089                 $dPrice = $this->oxarticles__oxpricec->value;
03090             }
03091         }
03092 
03093         // #1437/1436C - added config option, and check for zero A,B,C price values
03094         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03095             $dPrice = $this->oxarticles__oxprice->value;
03096         }
03097 
03098         return $dPrice;
03099     }
03100 
03109     protected function _getAmountPrice($dAmount = 1)
03110     {
03111         $myConfig = $this->getConfig();
03112 
03113         startProfile( "_getAmountPrice" );
03114 
03115         $dPrice = $this->_getGroupPrice();
03116         $oAmtPrices = $this->_getAmountPriceList();
03117         foreach ($oAmtPrices as $oAmPrice) {
03118             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03119                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03120                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03121                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03122             }
03123         }
03124 
03125         stopProfile( "_getAmountPrice" );
03126         return $dPrice;
03127     }
03128 
03137     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03138     {
03139         $myConfig = $this->getConfig();
03140         // #690
03141         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03142 
03143             $aSelLists = $this->getSelectLists();
03144 
03145             foreach ( $aSelLists as $key => $aSel) {
03146                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03147                     $oSel = $aSel[$aChosenList[$key]];
03148                     if ( $oSel->priceUnit =='abs' ) {
03149                         $dPrice += $oSel->price;
03150                     } elseif ( $oSel->priceUnit =='%' ) {
03151                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03152                     }
03153                 }
03154             }
03155         }
03156         return $dPrice;
03157     }
03158 
03159 
03167     protected function _fillAmountPriceList($oAmPriceList)
03168     {
03169         $myConfig = $this->getConfig();
03170         $myUtils  = oxUtils::getInstance();
03171 
03172         //modifying price
03173         $oCur = $myConfig->getActShopCurrencyObject();
03174 
03175         $oUser = $this->getArticleUser();
03176 
03177         $oDiscountList = oxDiscountList::getInstance();
03178         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03179 
03180         $oLowestPrice = null;
03181 
03182         $dBasePrice = $this->_getGroupPrice();
03183         $oLang = oxLang::getInstance();
03184 
03185         $dArticleVat = null;
03186         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03187             $dArticleVat = $this->getArticleVat();
03188         }
03189 
03190         // trying to find lowest price value
03191         foreach ($oAmPriceList as $sId => $oItem) {
03192             $oItemPrice = oxNew( 'oxprice' );
03193             if ( $oItem->oxprice2article__oxaddabs->value) {
03194                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03195                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03196                 $this->_applyCurrency( $oItemPrice, $oCur );
03197             } else {
03198                 $oItemPrice->setPrice( $dBasePrice );
03199                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03200             }
03201 
03202             if (isset($dArticleVat)) {
03203                 $this->_applyVAT($oItemPrice, $dArticleVat);
03204             }
03205 
03206             if (!$oLowestPrice) {
03207                 $oLowestPrice = $oItemPrice;
03208             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03209                 $oLowestPrice = $oItemPrice;
03210             }
03211 
03212             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03213             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03214             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03215         }
03216 
03217         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03218         return $oAmPriceList;
03219     }
03220 
03226     protected function _getVariantsIds()
03227     {
03228         $aSelect = array();
03229         if ( ( $sId = $this->getId() ) ) {
03230             $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03231             $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03232                    $this->getSqlActiveSnippet( true ) . " order by oxsort";
03233             $oRs = $oDb->select( $sQ );
03234             if ( $oRs != false && $oRs->recordCount() > 0 ) {
03235                 while (!$oRs->EOF) {
03236                     $aSelect[] = reset( $oRs->fields );
03237                     $oRs->moveNext();
03238                 }
03239             }
03240         }
03241         return $aSelect;
03242     }
03243 
03249     public function getArticleVat()
03250     {
03251         if (!isset($this->_dArticleVat)) {
03252             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03253         }
03254         return $this->_dArticleVat;
03255     }
03256 
03265     protected function _applyVAT( oxPrice $oPrice, $dVat )
03266     {
03267         startProfile(__FUNCTION__);
03268         $oPrice->setVAT( $dVat );
03269         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03270             $oPrice->setUserVat( $dVat );
03271         }
03272         stopProfile(__FUNCTION__);
03273     }
03274 
03282     public function applyVats( oxPrice $oPrice )
03283     {
03284         $this->_applyVAT($oPrice, $this->getArticleVat() );
03285     }
03286 
03297     protected function _applyDiscounts( $oPrice, $aDiscounts )
03298     {
03299         $oDiscountList = oxDiscountList::getInstance();
03300         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03301     }
03302 
03310     public function applyDiscountsForVariant( $oPrice )
03311     {
03312         // apply discounts
03313         if ( !$this->skipDiscounts() ) {
03314             $oDiscountList = oxDiscountList::getInstance();
03315             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03316         }
03317     }
03318 
03327     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03328     {
03329         if ( !$oCur ) {
03330             $oCur = $this->getConfig()->getActShopCurrencyObject();
03331         }
03332 
03333         $oPrice->multiply($oCur->rate);
03334     }
03335 
03336 
03345     protected function _getAttribsString(&$sAttribs, &$iCnt)
03346     {
03347         // we do not use lists here as we dont need this overhead right now
03348         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03349         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03350         $sAttribs = '';
03351         $blSep = false;
03352         $rs = $oDb->select( $sSelect);
03353         $iCnt = 0;
03354         if ($rs != false && $rs->recordCount() > 0) {
03355             while (!$rs->EOF) {
03356                 if ( $blSep) {
03357                     $sAttribs .= ' or ';
03358                 }
03359                 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03360                 $blSep = true;
03361                 $iCnt++;
03362                 $rs->moveNext();
03363             }
03364         }
03365     }
03366 
03375     protected function _getSimList($sAttribs, $iCnt)
03376     {
03377         $myConfig = $this->getConfig();
03378         $oDb      = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03379 
03380         // #523A
03381         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03382         // 70% same attributes
03383         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03384             $iAttrPercent = 0.70;
03385         }
03386         // #1137V iAttributesPercent = 100 doesnt work
03387         $iHitMin = ceil( $iCnt * $iAttrPercent );
03388 
03389         // we do not use lists here as we dont need this overhead right now
03390         $aList= array();
03391         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03392                     ( $sAttribs )
03393                     and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03394                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03395 
03396         $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03397         if ($rs != false && $rs->recordCount() > 0) {
03398             while (!$rs->EOF) {
03399                 $oTemp = new stdClass();    // #663
03400                 $oTemp->cnt = $rs->fields['cnt'];
03401                 $oTemp->id  = $rs->fields['oxobjectid'];
03402                 $aList[] = $oTemp;
03403                 $rs->moveNext();
03404             }
03405         }
03406         return $aList;
03407     }
03408 
03417     protected function _generateSimListSearchStr($sArticleTable, $aList)
03418     {
03419         $myConfig = $this->getConfig();
03420         $sFieldList = $this->getSelectFields();
03421         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03422         $blSep = false;
03423         $iCnt = 0;
03424         $oDb = oxDb::getDb();
03425         foreach ( $aList as $oTemp) {
03426             if ( $blSep) {
03427                 $sSearch .= ',';
03428             }
03429             $sSearch .= $oDb->quote($oTemp->id);
03430             $blSep = true;
03431             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03432                 break;
03433             }
03434             $iCnt++;
03435         }
03436 
03437         //#1741T
03438         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03439         $sSearch .= ') ';
03440 
03441         // #524A -- randomizing articles in attribute list
03442         $sSearch .= ' order by rand() ';
03443 
03444         return $sSearch;
03445     }
03446 
03455     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03456     {
03457 
03458         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03459         $sO2CView = getViewName( 'oxobject2category' );
03460 
03461         // we do not use lists here as we dont need this overhead right now
03462         if ( !$blSearchPriceCat ) {
03463             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03464                          {$sCatView}.oxid = oxobject2category.oxcatnid
03465                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03466         } else {
03467             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03468                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03469                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03470         }
03471         return $sSelect;
03472     }
03473 
03479     protected function _generateSearchStrForCustomerBought()
03480     {
03481         $sArtTable = $this->getViewName();
03482         $sOrderArtTable = getViewName( 'oxorderarticles' );
03483 
03484         // fetching filter params
03485         $sIn = " '{$this->oxarticles__oxid->value}' ";
03486         if ( $this->oxarticles__oxparentid->value ) {
03487 
03488             // adding article parent
03489             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03490             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03491 
03492         } else {
03493             $sParentIdForVariants = $this->getId();
03494         }
03495 
03496         // adding variants
03497         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03498         $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03499         if ( $oRs != false && $oRs->recordCount() > 0) {
03500             while ( !$oRs->EOF ) {
03501                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03502                 $oRs->moveNext();
03503             }
03504         }
03505 
03506         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03507         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03508 
03509         // building sql (optimized)
03510         $sQ = "select distinct {$sArtTable}.* from (
03511                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03512                ) as suborder
03513                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03514                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03515                where {$sArtTable}.oxid not in ( {$sIn} )
03516                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03517 
03518         /* non optimized, but could be used if index forcing is not supported
03519         // building sql
03520         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03521                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03522                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03523                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03524                and ".$this->getSqlActiveSnippet();
03525         */
03526 
03527         return $sQ;
03528     }
03529 
03539     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03540     {
03541         $sCategoryView = getViewName('oxcategories');
03542         $sO2CView = getViewName('oxobject2category');
03543 
03544         $oDb    = oxDb::getDb();
03545         $sOXID  = $oDb->quote($sOXID);
03546         $sCatId = $oDb->quote($sCatId);
03547 
03548         if (!$dPriceFromTo) {
03549             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03550             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03551             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03552             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03553         } else {
03554             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03555             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03556             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03557             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03558         }
03559         return $sSelect;
03560     }
03561 
03567     protected function _getAmountPriceList()
03568     {
03569         if ( $this->_oAmountPriceList === null ) {
03570             $this->_oAmountPriceList = array();
03571             if ( !$this->skipDiscounts() ) {
03572                 $myConfig = $this->getConfig();
03573                 $sArtId   = $this->getId();
03574 
03575                 // #1690C - Scale prices and variants
03576                 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03577                     $sArtId = $this->oxarticles__oxparentid->value;
03578                 }
03579 
03580                 //collecting assigned to article amount-price list
03581                 $oAmPriceList = oxNew( 'oxlist' );
03582                 $oAmPriceList->init( 'oxbase', 'oxprice2article' );
03583 
03584                 $sShopID = $myConfig->getShopID();
03585                 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03586                     $sShopSelect = '1';
03587                 } else {
03588                     $sShopSelect = " oxshopid =  '$sShopID' ";
03589                 }
03590 
03591                 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = " . oxDb::getDb()->quote( $sArtId ) . " and $sShopSelect order by oxamount ");
03592 
03593                 // prepare abs prices if currently having percentages
03594                 $oBasePrice = $this->_getGroupPrice();
03595                 foreach ( $oAmPriceList as $oAmPrice ) {
03596                     if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03597                         $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03598                     }
03599                 }
03600 
03601                 $this->_oAmountPriceList = $oAmPriceList;
03602             }
03603         }
03604 
03605         return $this->_oAmountPriceList;
03606     }
03607 
03615     protected function _isFieldEmpty( $sFieldName )
03616     {
03617         $mValue = $this->$sFieldName->value;
03618 
03619         if ( is_null( $mValue ) ) {
03620             return true;
03621         }
03622 
03623         if ( $mValue === '' ) {
03624             return true;
03625         }
03626 
03627         $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03628 
03629         if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03630             return true;
03631         }
03632 
03633 
03634         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03635             return true;
03636         }
03637 
03638         $sFieldName = strtolower($sFieldName);
03639 
03640         if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03641             return true;
03642         }
03643 
03644         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03645             return true;
03646         }
03647 
03648         return false;
03649     }
03650 
03658     protected function _assignParentFieldValue($sFieldName)
03659     {
03660         if (!($oParentArticle = $this->getParentArticle())) {
03661             return;
03662         }
03663 
03664         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03665 
03666         // assigning only theese which parent article has
03667         if ( $oParentArticle->$sCopyFieldName != null ) {
03668 
03669             // only overwrite database values
03670             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03671                 return;
03672             }
03673 
03674             //do not copy certain fields
03675             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03676                 return;
03677             }
03678 
03679             //COPY THE VALUE
03680             // assigning images from parent only if variant has no master image (#1807)
03681             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03682                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03683                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03684                 }
03685             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03686                 // for zoom images checking master image with specified index
03687                 // assign from parent only if no pictures to variant are added
03688                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03689                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03690                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03691                 }
03692             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03693                 // if no pics generated for variants, load all from
03694                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03695             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03696                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03697             }
03698         }
03699     }
03700 
03706     public function getParentArticle()
03707     {
03708         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03709             $sIndex = $sParentId . "_" . $this->getLanguage();
03710             if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03711                 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03712                 self::$_aLoadedParents[$sIndex]->_blSkipAbPrice  = true;
03713                 self::$_aLoadedParents[$sIndex]->_blLoadPrice    = false;
03714                 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03715                 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03716             }
03717             return self::$_aLoadedParents[$sIndex];
03718         }
03719     }
03720 
03728     protected function _getParentAricle()
03729     {
03730         return $this->getParentArticle();
03731     }
03732 
03738     protected function _assignParentFieldValues()
03739     {
03740         startProfile('articleAssignParentInternal');
03741         if ( $this->oxarticles__oxparentid->value ) {
03742             // yes, we are in fact a variant
03743             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03744                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03745                     $this->_assignParentFieldValue( $sFieldName );
03746                 }
03747             }
03748         }
03749         stopProfile('articleAssignParentInternal');
03750     }
03751 
03757     protected function _assignNotBuyableParent()
03758     {
03759         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03760              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03761             $this->_blNotBuyableParent = true;
03762 
03763         }
03764     }
03765 
03771     protected function _assignStock()
03772     {
03773         $myConfig = $this->getConfig();
03774         // -----------------------------------
03775         // stock
03776         // -----------------------------------
03777 
03778         // #1125 A. must round (using floor()) value taken from database and cast to int
03779         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03780             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03781         }
03782         //GREEN light
03783         $this->_iStockStatus = 0;
03784 
03785         // if we have flag /*1 or*/ 4 - we show always green light
03786         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03787             //ORANGE light
03788             $iStock = $this->oxarticles__oxstock->value;
03789 
03790             if ($this->_blNotBuyableParent) {
03791                 $iStock = $this->oxarticles__oxvarstock->value;
03792             }
03793 
03794 
03795             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03796                 $this->_iStockStatus = 1;
03797             }
03798 
03799             //RED light
03800             if ($iStock <= 0) {
03801                 $this->_iStockStatus = -1;
03802             }
03803         }
03804 
03805 
03806         // stock
03807         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03808             $iOnStock = $this->oxarticles__oxstock->value;
03809             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03810                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03811             }
03812             if ($iOnStock <= 0) {
03813                 $this->setBuyableState( false );
03814             }
03815         }
03816 
03817         //exceptional handling for variant parent stock:
03818         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03819             $this->setBuyableState( true );
03820             //but then at least setting notBuaybleParent to true
03821             $this->_blNotBuyableParent = true;
03822         }
03823 
03824         //special treatment for lists when blVariantParentBuyable config option is set to false
03825         //then we just hide "to basket" button.
03826         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03827         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03828             $this->setBuyableState( false );
03829         }
03830 
03831         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03832         if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03833             $this->setBuyableState( false );
03834         }
03835     }
03836 
03842     protected function _assignPrices()
03843     {
03844         $myConfig = $this->getConfig();
03845 
03846         // Performance
03847         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03848             return;
03849         }
03850 
03851         //price per unit handling
03852         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03853             // compute price
03854             $dPrice = $this->getPrice()->getBruttoPrice();
03855             $oCur = $myConfig->getActShopCurrencyObject();
03856             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03857         }
03858 
03859         //getting min and max prices of variants
03860         if ( $this->_hasAnyVariant() ) {
03861             $this->_applyRangePrice();
03862         }
03863     }
03864 
03870     protected function _assignPersistentParam()
03871     {
03872         // Persistent Parameter Handling
03873         $aPersParam     = oxSession::getVar( 'persparam');
03874         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03875             $this->_aPersistParam = $aPersParam[$this->getId()];
03876         }
03877     }
03878 
03884     protected function _assignDynImageDir()
03885     {
03886         $myConfig = $this->getConfig();
03887 
03888         $sThisShop = $this->oxarticles__oxshopid->value;
03889 
03890         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03891         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03892         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03893         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03894     }
03895 
03901     protected function _assignComparisonListFlag()
03902     {
03903         // #657 add a flag if article is on comparisonlist
03904 
03905         $aItems = oxSession::getVar('aFiltcompproducts');
03906         if ( isset( $aItems[$this->getId()])) {
03907             $this->_blIsOnComparisonList = true;
03908         }
03909     }
03910 
03916     protected function _assignAttributes()
03917     {
03918         //#1029T load attributes
03919         //#1078S removed check for module "Produktvergleich"
03920         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03921             $this->getAttributes();
03922         }
03923     }
03924 
03925 
03933     protected function _insert()
03934     {
03935         // set oxinsert
03936         $iInsertTime = time();
03937         $now = date('Y-m-d H:i:s', $iInsertTime);
03938         $this->oxarticles__oxinsert    = new oxField( $now );
03939         $this->oxarticles__oxtimestamp = new oxField( $now );
03940         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03941             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03942         }
03943 
03944         return parent::_insert();
03945     }
03946 
03952     protected function _update()
03953     {
03954 
03955         $this->_skipSaveFields();
03956 
03957         $myConfig = $this->getConfig();
03958 
03959 
03960         return parent::_update();
03961     }
03962 
03970     protected function _deleteRecords($sOXID)
03971     {
03972         $oDb = oxDb::getDb();
03973 
03974         $sOXID = $oDb->quote($sOXID);
03975 
03976         //remove other records
03977         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03978         $oDb->execute( $sDelete);
03979 
03980         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03981         $oDb->execute( $sDelete);
03982 
03983         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03984         $oDb->execute( $sDelete);
03985 
03986         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03987         $oDb->execute( $sDelete);
03988 
03989         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03990         $oDb->execute( $sDelete);
03991 
03992         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03993         $oDb->execute( $sDelete);
03994 
03995         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03996         $oDb->execute( $sDelete);
03997 
03998         //#1508C - deleting oxobject2delivery entries added
03999         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04000         $oDb->execute( $sDelete);
04001 
04002         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04003         $oDb->execute( $sDelete);
04004 
04005         //delete the record
04006         foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
04007             $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
04008         }
04009 
04010         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04011         $rs = $oDb->execute( $sDelete );
04012 
04013         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04014         $rs = $oDb->execute( $sDelete );
04015 
04016 
04017         return $rs;
04018     }
04019 
04027     protected function _deleteVariantRecords( $sOXID )
04028     {
04029         if ( $sOXID ) {
04030             $oDb = oxDb::getDb();
04031             //collect variants to remove recursively
04032             $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
04033             $rs = $oDb->select( $sQ, false, false );
04034             if ($rs != false && $rs->recordCount() > 0) {
04035                 while (!$rs->EOF) {
04036                     $this->delete( $rs->fields[0] );
04037                     $rs->moveNext();
04038                 }
04039             }
04040         }
04041     }
04042 
04052     protected function _resetCacheAndArticleCount( $sOxid )
04053     {
04054         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04055     }
04056 
04062     protected function _deletePics()
04063     {
04064         $myUtilsPic = oxUtilsPic::getInstance();
04065         $myConfig   = $this->getConfig();
04066         $oPictureHandler = oxPictureHandler::getInstance();
04067 
04068         //deleting custom main icon
04069         $oPictureHandler->deleteMainIcon( $this );
04070 
04071         //deleting custom thumbnail
04072         $oPictureHandler->deleteThumbnail( $this );
04073 
04074         $sAbsDynImageDir = $myConfig->getPictureDir(false);
04075 
04076         // deleting master image and all generated images
04077         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04078         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04079             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04080         }
04081     }
04082 
04092     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04093     {
04094 
04095         $myUtilsCount = oxUtilsCount::getInstance();
04096 
04097         if ( $sVendorId ) {
04098             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04099         }
04100 
04101         if ( $sManufacturerId ) {
04102             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04103         }
04104 
04105         //also reseting category counts
04106         $oDb = oxDb::getDb();
04107         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04108         $oRs = $oDb->select( $sQ, false, false );
04109         if ( $oRs !== false && $oRs->recordCount() > 0) {
04110             while ( !$oRs->EOF ) {
04111                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04112                 $oRs->moveNext();
04113             }
04114         }
04115     }
04116 
04124     protected function _onChangeUpdateStock( $sParentID )
04125     {
04126         if ( $sParentID ) {
04127             $oDb = oxDb::getDb();
04128             $sParentIdQuoted = $oDb->quote($sParentID);
04129             $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04130             $rs = $oDb->select( $sQ, false, false );
04131             $iOldStock = $rs->fields[0];
04132             $iVendorID = $rs->fields[1];
04133             $iManufacturerID = $rs->fields[2];
04134 
04135             $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04136             $iStock = (float) $oDb->getOne( $sQ, false, false );
04137 
04138             $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04139             $oDb->execute( $sQ );
04140 
04141                 //now lets update category counts
04142                 //first detect stock status change for this article (to or from 0)
04143                 if ( $iStock < 0 ) {
04144                     $iStock = 0;
04145                 }
04146                 if ( $iOldStock < 0 ) {
04147                     $iOldStock = 0;
04148                 }
04149                 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04150                     //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04151                     // so far we leave it like this but later we could move all count resets to one or two functions
04152                     $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04153                 }
04154         }
04155     }
04156 
04164     protected function _onChangeStockResetCount( $sOxid )
04165     {
04166         $myConfig = $this->getConfig();
04167 
04168         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04169            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04170 
04171                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04172         }
04173     }
04174 
04182     protected function _onChangeUpdateVarCount( $sParentID )
04183     {
04184         if ( $sParentID ) {
04185             $oDb = oxDb::getDb();
04186             $sParentIdQuoted = $oDb->quote( $sParentID );
04187             $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04188             $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04189 
04190             $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04191             $oDb->execute( $sQ );
04192         }
04193     }
04194 
04202     protected function _onChangeUpdateMinVarPrice( $sParentID )
04203     {
04204         if ( $sParentID ) {
04205             $oDb = oxDb::getDb();
04206             $sParentIdQuoted = $oDb->quote($sParentID);
04207             //#M0000883 (Sarunas)
04208             $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04209             $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04210 
04211             $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04212 
04213             $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04214 
04215             if ($dVarMinPrice) {
04216                 if ($blParentBuyable) {
04217                     $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04218                 }
04219 
04220             } else {
04221                 $dVarMinPrice = $dParentPrice;
04222             }
04223 
04224             if ( $dVarMinPrice ) {
04225                 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04226                 $oDb->execute($sQ);
04227             }
04228         }
04229     }
04230 
04231 
04237     protected function _applyRangePrice()
04238     {
04239         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04240         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04241             return;
04242         }
04243 
04244         $this->_blIsRangePrice = false;
04245 
04246         // if parent is buyable - do not apply range price calcculations
04247         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04248             return;
04249         }
04250 
04251         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04252             //#2509 we cannot force brutto price here, as netto price can be added to DB
04253             // $this->getPrice()->setBruttoPriceMode();
04254             $dPrice = $this->oxarticles__oxvarminprice->value;
04255             $this->getPrice()->setPrice($dPrice);
04256             $this->_blIsRangePrice = true;
04257             $this->_calculatePrice( $this->getPrice() );
04258             return;
04259         }
04260 
04261         $aPrices = array();
04262 
04263         if (!$this->_blNotBuyableParent) {
04264             $aPrices[] = $this->getPrice()->getBruttoPrice();
04265         }
04266 
04267         $aVariants = $this->getVariants(false);
04268 
04269         if (count($aVariants)) {
04270             foreach ($aVariants as $sKey => $oVariant) {
04271                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04272             }
04273         }
04274 
04275         if ( count( $aPrices ) ) {
04276             $dMinPrice = min( $aPrices );
04277             $dMaxPrice = max( $aPrices );
04278         }
04279 
04280         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04281             $this->getPrice()->setBruttoPriceMode();
04282             $this->getPrice()->setPrice($dMinPrice);
04283         }
04284 
04285         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04286             $this->getPrice()->setBruttoPriceMode();
04287             $this->getPrice()->setPrice($dMinPrice);
04288             $this->_blIsRangePrice = true;
04289         }
04290     }
04291 
04298     public function getProductId()
04299     {
04300         return $this->getId();
04301     }
04302 
04308     public function getProductParentId()
04309     {
04310         return $this->oxarticles__oxparentid->value;
04311     }
04312 
04318     public function isOrderArticle()
04319     {
04320         return false;
04321     }
04322 
04328     public function isVariant()
04329     {
04330         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04331     }
04332 
04338     public function isMdVariant()
04339     {
04340         $oMdVariant = oxNew( "oxVariantHandler" );
04341 
04342         return $oMdVariant->isMdVariant($this);
04343     }
04344 
04352     public function getSqlForPriceCategories($sFields = '')
04353     {
04354         if (!$sFields) {
04355             $sFields = 'oxid';
04356         }
04357         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04358         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04359         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04360                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04361                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04362     }
04363 
04371     public function inPriceCategory( $sCatNid )
04372     {
04373         $oDb = oxDb::getDb();
04374 
04375         $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04376         $sQuotedCnid = $oDb->quote( $sCatNid );
04377         return (bool) $oDb->getOne(
04378             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04379            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04380            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04381            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04382            .")"
04383         );
04384     }
04385 
04391     public function getMdVariants()
04392     {
04393         if ( $this->_oMdVariants ) {
04394             return $this->_oMdVariants;
04395         }
04396 
04397         $oParentArticle = $this->getParentArticle();
04398         if ( $oParentArticle ) {
04399             $oVariants = $oParentArticle->getVariants();
04400         } else {
04401             $oVariants = $this->getVariants();
04402         }
04403 
04404         $oVariantHandler = oxNew( "oxVariantHandler" );
04405         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04406 
04407         return $this->_oMdVariants;
04408     }
04409 
04415     public function getMdSubvariants()
04416     {
04417         return $this->getMdVariants()->getMdSubvariants();
04418     }
04419 
04427     protected function _hasMasterImage( $iIndex )
04428     {
04429         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04430 
04431         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04432             return false;
04433         }
04434         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04435             return false;
04436         }
04437 
04438         $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04439 
04440         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04441             return true;
04442         }
04443 
04444         return false;
04445     }
04446 
04455     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04456     {
04457         if ( $sFieldName ) {
04458             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04459             return $this->$sFieldName->value;
04460         }
04461     }
04462 
04470     public function getMasterZoomPictureUrl( $iIndex )
04471     {
04472         $sPicUrl  = false;
04473         $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04474 
04475         if ( $sPicName && $sPicName != "nopic.jpg" ) {
04476             $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04477             if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04478                 $sPicUrl = false;
04479             }
04480         }
04481 
04482         return $sPicUrl;
04483     }
04484 
04490     public function getUnitName()
04491     {
04492         if ( $this->oxarticles__oxunitname->value ) {
04493             return oxLang::getInstance()->translateString( $this->oxarticles__oxunitname->value );
04494         }
04495     }
04496 
04504     public function getArticleFiles( $blAddFromParent=false )
04505     {
04506         if ( $this->_aArticleFiles === null) {
04507 
04508             $this->_aArticleFiles = false;
04509 
04510             $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04511 
04512             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04513                 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04514             }
04515 
04516             $oArticleFiles = oxNew("oxlist");
04517             $oArticleFiles->init("oxfile");
04518             $oArticleFiles->selectString( $sQ );
04519             $this->_aArticleFiles  = $oArticleFiles;
04520 
04521         }
04522 
04523         return $this->_aArticleFiles;
04524     }
04525 
04531     public function isDownloadable()
04532     {
04533         return $this->oxarticles__oxisdownloadable->value;
04534     }
04535 
04541     public function hasAmountPrice()
04542     {
04543         if ( self::$_blHasAmountPrice === null ) {
04544 
04545             self::$_blHasAmountPrice = false;
04546 
04547             $oDb = oxDb::getDb();
04548             $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04549 
04550             if ( $oDb->getOne( $sQ ) ) {
04551                 self::$_blHasAmountPrice = true;
04552             }
04553         }
04554 
04555         return self::$_blHasAmountPrice;
04556     }
04557 }