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                 $oVariants->selectString( $sSelect );
01323 
01324                 //if this is multidimensional variants, make additional processing
01325                 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01326                     $oMdVariants = oxNew( "oxVariantHandler" );
01327                     $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01328                 }
01329                 stopProfile("selectVariants");
01330             }
01331 
01332             //if we have variants then depending on config option the parent may be non buyable
01333             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01334                 $this->_blNotBuyableParent = true;
01335             }
01336 
01337             //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01338             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01339                 $this->_blNotBuyable = true;
01340             }
01341         }
01342 
01343         return $oVariants;
01344     }
01345 
01354     public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01355     {
01356         return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01357     }
01358 
01367     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null  )
01368     {
01369         return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01370     }
01371 
01377     public function getSimpleVariants()
01378     {
01379         if ( $this->oxarticles__oxvarcount->value) {
01380             return $this->getVariants();
01381         }
01382     }
01383 
01392     public function getAdminVariants( $sLanguage = null )
01393     {
01394         $oVariants = oxNew( 'oxarticlelist');
01395         if ( ( $sId = $this->getId() ) ) {
01396 
01397             $oBaseObj = $oVariants->getBaseObject();
01398 
01399             if ( is_null( $sLanguage ) ) {
01400                 $oBaseObj->setLanguage( oxLang::getInstance()->getBaseLanguage() );
01401             } else {
01402                 $oBaseObj->setLanguage( $sLanguage );
01403             }
01404 
01405             $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01406             $oVariants->selectString( $sSql );
01407 
01408             //if we have variants then depending on config option the parent may be non buyable
01409             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01410                 //$this->blNotBuyable = true;
01411                 $this->_blNotBuyableParent = true;
01412             }
01413         }
01414 
01415         return $oVariants;
01416     }
01417 
01425     public function getCategory()
01426     {
01427         $oCategory = oxNew( 'oxcategory' );
01428         $oCategory->setLanguage( $this->getLanguage() );
01429 
01430         // variant handling
01431         $sOXID = $this->getId();
01432         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01433             $sOXID = $this->oxarticles__oxparentid->value;
01434         }
01435 
01436         if ( $sOXID ) {
01437             // if the oxcategory instance of this article is not cached
01438             if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01439                 startPRofile( 'getCategory' );
01440                 $oStr = getStr();
01441                 $sWhere   = $oCategory->getSqlActiveSnippet();
01442                 $sSelect  = $this->_generateSearchStr( $sOXID );
01443                 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01444 
01445                 // category not found ?
01446                 if ( !$oCategory->assignRecord( $sSelect ) ) {
01447 
01448                     $sSelect  = $this->_generateSearchStr( $sOXID, true );
01449                     $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01450 
01451                     // looking for price category
01452                     if ( !$oCategory->assignRecord( $sSelect ) ) {
01453                         $oCategory = null;
01454                     }
01455                 }
01456                 // add the category instance to cache
01457                 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01458                 stopPRofile( 'getCategory' );
01459             } else {
01460                // if the oxcategory instance is cached
01461                $oCategory = $this->_aCategoryCache[ $sOXID ];
01462             }
01463         }
01464 
01465         return $oCategory;
01466     }
01467 
01476     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01477     {
01478         $myConfig = $this->getConfig();
01479         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01480             return self::$_aArticleCats[$this->getId()];
01481         }
01482 
01483         // variant handling
01484         $sOXID = $this->getId();
01485         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01486             $sOXID = $this->oxarticles__oxparentid->value;
01487         }
01488 
01489         // we do not use lists here as we dont need this overhead right now
01490         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01491         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01492         $rs = $oDb->select( $sSql );
01493 
01494 
01495         $aRet = array();
01496 
01497         if ($rs != false && $rs->recordCount() > 0) {
01498             while (!$rs->EOF) {
01499                 $aRet[] = $rs->fields['oxcatnid'];
01500                 $rs->moveNext();
01501             }
01502         }
01503 
01504         // adding price categories if such exists
01505         $sSql = $this->getSqlForPriceCategories();
01506         $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
01507         $rs = $oDb->select( $sSql );
01508 
01509         if ($rs != false && $rs->recordCount() > 0) {
01510             while (!$rs->EOF) {
01511 
01512                 if ( is_array( $rs->fields ) ) {
01513                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01514                 }
01515 
01516 
01517                 if ( !$aRet[$rs->fields['oxid']] ) {
01518                     $aRet[] = $rs->fields['oxid'];
01519                 }
01520                 $rs->moveNext();
01521             }
01522         }
01523 
01524         return self::$_aArticleCats[$this->getId()] = $aRet;
01525     }
01526 
01535     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01536     {
01537         $sO2CView = $this->_getObjectViewName('oxobject2category');
01538         $sCatView = $this->_getObjectViewName('oxcategories');
01539         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01540         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01541         if ( $blActCats ) {
01542             $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 ";
01543         }
01544         $sSelect .= 'order by oxobject2category.oxtime ';
01545         return $sSelect;
01546     }
01547 
01557     public function getVendor( $blShopCheck = true )
01558     {
01559         if ( ( $sVendorId = $this->getVendorId() ) ) {
01560             $oVendor = oxNew( 'oxvendor' );
01561         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01562                 $oVendor = oxNew( 'oxi18n' );
01563                 $oVendor->init('oxvendor');
01564                 $oVendor->setReadOnly( true );
01565             $sVendorId = $this->oxarticles__oxvendorid->value;
01566         }
01567         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01568 
01569             //@deprecated in v.4.5.7, since 2012-02-15; config option removed bug #0003385
01570             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01571                 $oVendor->setReadOnly( true );
01572             }
01573             return $oVendor;
01574         }
01575         return null;
01576     }
01577 
01585     public function getVendorId( $blForceReload = false )
01586     {
01587         $sVendorId = false;
01588         if ( $this->oxarticles__oxvendorid->value ) {
01589                 $sVendorId = $this->oxarticles__oxvendorid->value;
01590 
01591         }
01592         return $sVendorId;
01593     }
01594 
01602     public function getManufacturerId( $blForceReload = false )
01603     {
01604         $sManufacturerId = false;
01605         if ( $this->oxarticles__oxmanufacturerid->value ) {
01606 
01607                 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01608 
01609         }
01610         return $sManufacturerId;
01611     }
01612 
01622     public function getManufacturer( $blShopCheck = true )
01623     {
01624             $oManufacturer = oxNew( 'oxmanufacturer' );;
01625         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01626              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01627             $oManufacturer->setReadOnly( true );
01628             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01629         }
01630 
01631         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01632             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01633                 $oManufacturer->setReadOnly( true );
01634             }
01635             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01636         } else {
01637             $oManufacturer = null;
01638         }
01639 
01640         return $oManufacturer;
01641     }
01642 
01650     public function inCategory( $sCatNid)
01651     {
01652         return in_array( $sCatNid, $this->getCategoryIds());
01653     }
01654 
01663     public function isAssignedToCategory( $sCatId )
01664     {
01665         // variant handling
01666         $sOXID = $this->getId();
01667         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01668             $sOXID = $this->oxarticles__oxparentid->value;
01669         }
01670 
01671         $oDb = oxDb::getDb();
01672         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01673         $sOXID = $oDb->getOne( $sSelect );
01674         // article is assigned to passed category!
01675         if ( isset( $sOXID) && $sOXID) {
01676             return true;
01677         }
01678 
01679         // maybe this category is price category ?
01680         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01681             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01682             if ( $dPriceFromTo > 0) {
01683                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01684                 $sOXID = $oDb->getOne( $sSelect );
01685                 // article is assigned to passed category!
01686                 if ( isset( $sOXID) && $sOXID) {
01687                     return true;
01688                 }
01689             }
01690         }
01691         return false;
01692     }
01693 
01699     public function getTPrice()
01700     {
01701         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01702             return;
01703         }
01704         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01705         if ( $this->_oTPrice !== null ) {
01706             return $this->_oTPrice;
01707         }
01708 
01709         $this->_oTPrice = oxNew( 'oxPrice' );
01710         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01711 
01712         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01713         $this->_applyCurrency( $this->_oTPrice );
01714 
01715         return $this->_oTPrice;
01716     }
01717 
01723     public function skipDiscounts()
01724     {
01725         // allready loaded skip discounts config
01726         if ( $this->_blSkipDiscounts !== null ) {
01727             return $this->_blSkipDiscounts;
01728         }
01729 
01730         if ( $this->oxarticles__oxskipdiscounts->value ) {
01731             return true;
01732         }
01733 
01734 
01735         $this->_blSkipDiscounts = false;
01736         if ( oxDiscountList::getInstance()->hasSkipDiscountCategories() ) {
01737 
01738             $oDb = oxDb::getDb();
01739             $sO2CView  = getViewName( 'oxobject2category', $this->getLanguage() );
01740             $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01741             $sSelect =  "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01742                          where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01743             $this->_blSkipDiscounts = ( $oDb->getOne( $sSelect ) == 1 );
01744         }
01745 
01746         return $this->_blSkipDiscounts;
01747     }
01748 
01756     public function setPrice(oxPrice $oPrice)
01757     {
01758         $this->_oPrice = $oPrice;
01759     }
01760 
01769     public function getBasePrice( $dAmount = 1 )
01770     {
01771         // override this function if you want e.g. different prices
01772         // for diff. usergroups.
01773 
01774         // Performance
01775         $myConfig = $this->getConfig();
01776         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01777             return;
01778 
01779         // GroupPrice or DB price ajusted by AmountPrice
01780         $dPrice = $this->_getAmountPrice( $dAmount );
01781 
01782 
01783         return $dPrice;
01784     }
01785 
01793     public function getPrice( $dAmount = 1 )
01794     {
01795         $myConfig = $this->getConfig();
01796         // Performance
01797         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01798             return;
01799         }
01800 
01801         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01802         if ( $dAmount != 1 || $this->_oPrice === null ) {
01803             $oPrice = oxNew( 'oxPrice' );
01804 
01805             // get base
01806             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01807 
01808             // price handling
01809             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01810                 return $this->_oPrice = $oPrice;
01811             }
01812 
01813             $this->_calculatePrice( $oPrice );
01814             if ( $dAmount != 1 ) {
01815                 return $oPrice;
01816             }
01817 
01818             $this->_oPrice = $oPrice;
01819         }
01820         return $this->_oPrice;
01821     }
01822 
01831     protected function _calculatePrice( $oPrice, $dVat = null )
01832     {
01833         // apply VAT only if configuration requires it
01834         if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01835             $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01836         }
01837 
01838         // apply currency
01839         $this->_applyCurrency( $oPrice );
01840         // apply discounts
01841         if ( !$this->skipDiscounts() ) {
01842             $oDiscountList = oxDiscountList::getInstance();
01843             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
01844         }
01845 
01846         return $oPrice;
01847     }
01848 
01856     public function setArticleUser($oUser)
01857     {
01858         $this->_oUser = $oUser;
01859     }
01860 
01866     public function getArticleUser()
01867     {
01868         if ($this->_oUser) {
01869             return $this->_oUser;
01870         }
01871         return $this->getUser();
01872     }
01873 
01883     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01884     {
01885         $oUser = $oBasket->getBasketUser();
01886         $this->setArticleUser( $oUser );
01887 
01888         $oBasketPrice = oxNew( 'oxPrice' );
01889 
01890         // get base price
01891         $dBasePrice = $this->getBasePrice( $dAmount );
01892 
01893         // applying select list price
01894         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01895 
01896         // setting price
01897         $oBasketPrice->setPrice( $dBasePrice );
01898 
01899         $dVat = oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket );
01900         $this->_calculatePrice( $oBasketPrice, $dVat );
01901 
01902         // returning final price object
01903         return $oBasketPrice;
01904     }
01905 
01918     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01919     {
01920         $oDiscountList = oxDiscountList::getInstance();
01921         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01922     }
01923 
01932     public function delete( $sOXID = null )
01933     {
01934         if ( !$sOXID ) {
01935             $sOXID = $this->getId();
01936         }
01937         if ( !$sOXID ) {
01938             return false;
01939         }
01940 
01941 
01942         // #2339 delete first variants before deleting parent product
01943         $this->_deleteVariantRecords( $sOXID );
01944         $this->load( $sOXID );
01945         $this->_deletePics();
01946         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01947 
01948         // delete self
01949         parent::delete( $sOXID );
01950 
01951         $rs = $this->_deleteRecords( $sOXID );
01952 
01953         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01954 
01955         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01956 
01957         return $rs->EOF;
01958     }
01959 
01968     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01969     {
01970         $this->beforeUpdate();
01971 
01972         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01973         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01974             $dAmount += $iStockCount;
01975             $iStockCount = 0;
01976         }
01977         $this->oxarticles__oxstock = new oxField($iStockCount);
01978 
01979         $oDb = oxDb::getDb();
01980         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01981         $this->onChange( ACTION_UPDATE_STOCK );
01982         return $dAmount;
01983     }
01984 
01993     public function updateSoldAmount( $dAmount = 0 )
01994     {
01995         if ( !$dAmount ) {
01996             return;
01997         }
01998 
01999         $this->beforeUpdate();
02000 
02001         // article is not variant - should be updated current amount
02002         if ( !$this->oxarticles__oxparentid->value ) {
02003             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
02004             $dAmount = (double) $dAmount;
02005             $oDb = oxDb::getDb();
02006             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02007         } elseif ( $this->oxarticles__oxparentid->value) {
02008             // article is variant - should be updated this article parent amount
02009             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
02010             $oUpdateArticle->updateSoldAmount( $dAmount );
02011         }
02012 
02013         $this->onChange( ACTION_UPDATE );
02014 
02015         return $rs;
02016     }
02017 
02023     public function disableReminder()
02024     {
02025         $oDb = oxDb::getDb();
02026         return $oDb->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02027     }
02028 
02036     public function save()
02037     {
02038         // @deprecated since 20110821. folders are no more written, getters must be user for urls
02039         $this->oxarticles__oxthumb = new oxField( basename( $this->oxarticles__oxthumb->value ), oxField::T_RAW );
02040         $this->oxarticles__oxicon  = new oxField( basename( $this->oxarticles__oxicon->value ), oxField::T_RAW );
02041         $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
02042         for ( $i = 1; $i <= $iPicCount; $i++ ) {
02043             $sFieldName = 'oxarticles__oxpic' . $i;
02044             if ( isset( $this->$sFieldName ) ) {
02045                 $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );
02046             }
02047         }
02048         // @end deprecated
02049 
02050         if ( ( $blRet = parent::save() ) ) {
02051             // saving long descrition
02052             $this->_saveArtLongDesc();
02053         }
02054 
02055         return $blRet;
02056     }
02057 
02058 
02065     public function getPictureGallery()
02066     {
02067         $myConfig = $this->getConfig();
02068 
02069         //initialize
02070         $blMorePic = false;
02071         $aArtPics  = array();
02072         $aArtIcons = array();
02073         $iActPicId = 1;
02074         $sActPic = $this->getPictureUrl( $iActPicId );
02075 
02076         if ( oxConfig::getParameter( 'actpicid' ) ) {
02077             $iActPicId = oxConfig::getParameter('actpicid');
02078         }
02079 
02080         $oStr = getStr();
02081         $iCntr = 0;
02082         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02083         $blCheckActivePicId = true;
02084 
02085         for ( $i = 1; $i <= $iPicCount; $i++) {
02086             $sPicVal = $this->getPictureUrl( $i );
02087             $sIcoVal = $this->getIconUrl( $i );
02088             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02089                  !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02090                 if ($iCntr) {
02091                     $blMorePic = true;
02092                 }
02093                 $aArtIcons[$i]= $sIcoVal;
02094                 $aArtPics[$i]= $sPicVal;
02095                 $iCntr++;
02096 
02097                 if ($iActPicId == $i) {
02098                     $sActPic = $sPicVal;
02099                     $blCheckActivePicId = false;
02100                 }
02101 
02102             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02103                 // if picture is empty, setting active pic id to next
02104                 // picture
02105                 $iActPicId++;
02106             }
02107         }
02108 
02109         $blZoomPic  = false;
02110         $aZoomPics = array();
02111         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02112 
02113         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02114             $sVal = $this->getZoomPictureUrl($j);
02115 
02116             if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02117                 $blZoomPic = true;
02118                 $aZoomPics[$c]['id'] = $c;
02119                 $aZoomPics[$c]['file'] = $sVal;
02120                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02121                 if (!$sVal) {
02122                     $aZoomPics[$c]['file'] = "nopic.jpg";
02123                 }
02124                 $c++;
02125             }
02126         }
02127 
02128         $aPicGallery = array('ActPicID' => $iActPicId,
02129                              'ActPic' => $sActPic,
02130                              'MorePics' => $blMorePic,
02131                              'Pics' => $aArtPics,
02132                              'Icons' => $aArtIcons,
02133                              'ZoomPic' => $blZoomPic,
02134                              'ZoomPics' => $aZoomPics);
02135 
02136         return $aPicGallery;
02137     }
02138 
02152     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02153     {
02154         $myConfig = $this->getConfig();
02155 
02156         if (!isset($sOXID)) {
02157             if ( $this->getId()) {
02158                 $sOXID = $this->getId();
02159             }
02160             if (!isset ($sOXID)) {
02161                 $sOXID = $this->oxarticles__oxid->value;
02162             }
02163             if ($this->oxarticles__oxparentid->value) {
02164                 $sParentID = $this->oxarticles__oxparentid->value;
02165             }
02166         }
02167         if (!isset($sOXID)) {
02168             return;
02169         }
02170 
02171         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02172         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02173             //if article has variants then updating oxvarstock field
02174             //getting parent id
02175             if (!isset($sParentID)) {
02176                 $oDb = oxDb::getDb();
02177                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02178                 $sParentID = $oDb->getOne( $sQ );
02179             }
02180             //if we have parent id then update stock
02181             if ($sParentID) {
02182                 $this->_onChangeUpdateStock($sParentID);
02183             }
02184         }
02185         //if we have parent id then update count
02186         //update count even if blUseStock is not active
02187         if ($sParentID) {
02188             $this->_onChangeUpdateVarCount($sParentID);
02189         }
02190 
02191         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02192         $this->_onChangeUpdateMinVarPrice( $sId );
02193 
02194             // reseting articles count cache if stock has changed and some
02195             // articles goes offline (M:1448)
02196             if ( $sAction === ACTION_UPDATE_STOCK ) {
02197                 $this->_onChangeStockResetCount( $sOXID );
02198             }
02199 
02200     }
02201 
02208     public function getCustomVAT()
02209     {
02210         if ( isset($this->oxarticles__oxvat->value) ) {
02211             return $this->oxarticles__oxvat->value;
02212         }
02213     }
02214 
02223     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02224     {
02225         $myConfig = $this->getConfig();
02226         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02227             return true;
02228         }
02229 
02230         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
02231         // fetching DB info as its up-to-date
02232         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.$oDb->quote( $this->getId() );
02233         $rs = $oDb->select( $sQ );
02234 
02235         $iOnStock   = 0;
02236         $iStockFlag = 0;
02237         if ( $rs !== false && $rs->recordCount() > 0 ) {
02238             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02239             $iStockFlag = $rs->fields['oxstockflag'];
02240 
02241             // dodger : fremdlager is also always considered as on stock
02242             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02243                 return true;
02244             }
02245             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02246                 $iOnStock = floor( $iOnStock );
02247             }
02248         }
02249         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02250             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02251         }
02252         if ( $iOnStock >= $dAmount ) {
02253             return true;
02254         } else {
02255             if ( $iOnStock > 0 ) {
02256                 return $iOnStock;
02257             } else {
02258                 $oEx = oxNew( 'oxArticleInputException' );
02259                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02260                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02261                 return false;
02262             }
02263         }
02264     }
02265 
02266 
02276     public function getArticleLongDesc( $sOxid = null )
02277     {
02278         return $this->getLongDescription();
02279     }
02280 
02286     public function getLongDescription()
02287     {
02288         if ( $this->_oLongDesc === null ) {
02289             // initializing
02290             $this->_oLongDesc = new oxField();
02291 
02292 
02293             // choosing which to get..
02294             $sOxid = $this->getId();
02295             $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02296 
02297             $oDb = oxDb::getDb();
02298             $sDbValue = $oDb->getOne( "select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote( $sOxid ) );
02299 
02300             if ( $sDbValue != false ) {
02301                 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02302             } elseif ( $this->oxarticles__oxparentid->value ) {
02303                 if ( !$this->isAdmin() || $this->_blLoadParentData ) {
02304                     $this->_oLongDesc->setValue( $this->getParentArticle()->getLongDescription()->getRawValue(), oxField::T_RAW );
02305                 }
02306             }
02307         }
02308         return $this->_oLongDesc;
02309     }
02310 
02320     protected function _setLongDesc( $sDbValue )
02321     {
02322         $this->setArticleLongDesc( $sDbValue );
02323     }
02324 
02331     public function getLongDesc()
02332     {
02333         return oxUtilsView::getInstance()->parseThroughSmarty( $this->getLongDescription()->getRawValue(), $this->getId().$this->getLanguage() );
02334     }
02335 
02344     public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02345     {
02346 
02347         // setting current value
02348         $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02349 
02350         // setting original value?
02351         //deprecated since 2012-02-13 in v.4.5.7
02352         if ( $sOrigValue ) {
02353             $this->_oLongDesc->orignalValue = $sOrigValue;
02354         }
02355     }
02356 
02362     public function getAttributes()
02363     {
02364         if ( $this->_oAttributeList === null ) {
02365             $this->_oAttributeList = oxNew( 'oxattributelist' );
02366             $this->_oAttributeList->loadAttributes( $this->getId() );
02367         }
02368 
02369         return $this->_oAttributeList;
02370     }
02371 
02380     public function appendLink( $sAddParams, $iLang = null )
02381     {
02382         if ( $sAddParams ) {
02383             if ( $iLang === null ) {
02384                 $iLang = $this->getLanguage();
02385             }
02386 
02387             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02388             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02389         }
02390     }
02391 
02400     public function getBaseSeoLink( $iLang, $blMain = false )
02401     {
02402         $oEncoder = oxSeoEncoderArticle::getInstance();
02403         if ( !$blMain ) {
02404             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02405         }
02406         return $oEncoder->getArticleMainUrl( $this, $iLang );
02407     }
02408 
02417     public function getLink( $iLang = null, $blMain = false  )
02418     {
02419         if ( !oxUtils::getInstance()->seoIsActive() ) {
02420             return $this->getStdLink( $iLang );
02421         }
02422 
02423         if ( $iLang === null ) {
02424             $iLang = $this->getLanguage();
02425         }
02426 
02427         $iLinkType = $this->getLinkType();
02428         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02429             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02430         }
02431 
02432         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02433         if ( isset($this->_aSeoAddParams[$iLang])) {
02434             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02435         }
02436 
02437         return $sUrl;
02438     }
02439 
02448     public function getMainLink( $iLang = null )
02449     {
02450         return $this->getLink( $iLang, true );
02451     }
02452 
02460     public function setLinkType( $iType )
02461     {
02462         // resetting detaisl link, to force new
02463         $this->_sDetailLink = null;
02464 
02465         // setting link type
02466         $this->_iLinkType = (int) $iType;
02467     }
02468 
02474     public function getLinkType()
02475     {
02476         return $this->_iLinkType;
02477     }
02478 
02487     public function appendStdLink( $sAddParams, $iLang = null )
02488     {
02489         if ( $sAddParams ) {
02490             if ( $iLang === null ) {
02491                 $iLang = $this->getLanguage();
02492             }
02493 
02494             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02495             $this->_aStdAddParams[$iLang] .= $sAddParams;
02496         }
02497     }
02498 
02508     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02509     {
02510         $sUrl = '';
02511         if ( $blFull ) {
02512             //always returns shop url, not admin
02513             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02514         }
02515 
02516         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02517         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02518     }
02519 
02528     public function getStdLink( $iLang = null, $aParams = array() )
02529     {
02530         if ( $iLang === null ) {
02531             $iLang = $this->getLanguage();
02532         }
02533 
02534         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02535             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02536         }
02537 
02538         return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02539     }
02540 
02548     public function getStdTagLink( $sTag )
02549     {
02550         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02551         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02552     }
02553 
02559     public function getTags()
02560     {
02561         $oDb = oxDb::getDb();
02562         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02563         $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02564         $oTagCloud = oxNew('oxtagcloud');
02565         return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02566     }
02567 
02575     public function saveTags($sTags)
02576     {
02577         //do not allow derived update
02578         if ( !$this->allowDerivedUpdate() ) {
02579             return false;
02580         }
02581 
02582 
02583         $oTagCloud = oxNew( 'oxtagcloud' );
02584         $oTagCloud->resetTagCache();
02585         $sTags = oxDb::getInstance()->escapeString( $oTagCloud->prepareTags( $sTags ) );
02586         $oDb = oxDb::getDb();
02587 
02588         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02589         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02590         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02591                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02592         return $oDb->execute( $sQ );
02593     }
02594 
02602     public function addTag($sTag)
02603     {
02604         $oDb = oxDb::getDb();
02605 
02606         $oTagCloud = oxNew('oxtagcloud');
02607         $oTagCloud->resetTagCache();
02608         $sTag = $oTagCloud->prepareTags($sTag);
02609         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02610 
02611         $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02612         $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02613         if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02614             $sTailTag = $sTagSeparator . $sTag;
02615         } else {
02616             $sTailTag = $sTag;
02617         }
02618 
02619         $sTag = oxDb::getInstance()->escapeString($sTag);
02620         $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02621 
02622         $sTag = oxDb::getInstance()->escapeString($sTag);
02623         $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02624 
02625         $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02626                        ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02627 
02628         return $oDb->execute( $sQ );
02629     }
02630 
02636     public function getMediaUrls()
02637     {
02638         if ( $this->_aMediaUrls === null ) {
02639             $this->_aMediaUrls = oxNew("oxlist");
02640             $this->_aMediaUrls->init("oxmediaurl");
02641             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02642 
02643             $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02644             $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02645             $this->_aMediaUrls->selectString($sQ);
02646         }
02647         return $this->_aMediaUrls;
02648     }
02649 
02655     public function getDynImageDir()
02656     {
02657         return $this->_sDynImageDir;
02658     }
02659 
02665     public function getDispSelList()
02666     {
02667         if ($this->_aDispSelList === null) {
02668             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02669                 $this->_aDispSelList = $this->getSelectLists();
02670             }
02671         }
02672         return $this->_aDispSelList;
02673     }
02674 
02680     public function getMoreDetailLink()
02681     {
02682         if ( $this->_sMoreDetailLink == null ) {
02683 
02684             // and assign special article values
02685             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02686 
02687             // not always it is okey, as not all the time active category is the same as primary article cat.
02688             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02689                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02690             }
02691             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02692             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02693         }
02694 
02695         return $this->_sMoreDetailLink;
02696     }
02697 
02703     public function getToBasketLink()
02704     {
02705         if ( $this->_sToBasketLink == null ) {
02706             $myConfig = $this->getConfig();
02707 
02708             if ( oxUtils::getInstance()->isSearchEngine() ) {
02709                 $this->_sToBasketLink = $this->getLink();
02710             } else {
02711                 // and assign special article values
02712                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02713 
02714                 // override some classes as these should never showup
02715                 $sActClass = oxConfig::getParameter( 'cl' );
02716                 if ( $sActClass == 'thankyou') {
02717                     $sActClass = 'basket';
02718                 }
02719                 $this->_sToBasketLink .= 'cl='.$sActClass;
02720 
02721                 // this is not very correct
02722                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02723                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02724                 }
02725 
02726                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02727 
02728                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02729                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02730                 }
02731             }
02732         }
02733 
02734         return $this->_sToBasketLink;
02735     }
02736 
02742     public function getStockStatus()
02743     {
02744         return $this->_iStockStatus;
02745     }
02746 
02752     public function getDeliveryDate()
02753     {
02754         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02755             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02756         }
02757         return false;
02758     }
02759 
02765     public function getFTPrice()
02766     {
02767         if ( $oPrice = $this->getTPrice() ) {
02768             if ( $oPrice->getBruttoPrice() ) {
02769                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02770             }
02771         }
02772     }
02773 
02779     public function getFPrice()
02780     {
02781         if ( $oPrice = $this->getPrice() ) {
02782             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02783         }
02784     }
02785 
02791     public function getFNetPrice()
02792     {
02793         if ( $oPrice = $this->getPrice() ) {
02794             return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02795         }
02796     }
02797 
02803     public function getPricePerUnit()
02804     {
02805         return $this->_fPricePerUnit;
02806     }
02807 
02813     public function isParentNotBuyable()
02814     {
02815         return $this->_blNotBuyableParent;
02816     }
02817 
02823     public function isNotBuyable()
02824     {
02825         return $this->_blNotBuyable;
02826     }
02827 
02835     public function setBuyableState( $blBuyable = false )
02836     {
02837         $this->_blNotBuyable = !$blBuyable;
02838     }
02839 
02848     public function getVariantList()
02849     {
02850         return $this->getVariants();
02851     }
02852 
02860     public function setSelectlist( $aSelList )
02861     {
02862         $this->_aDispSelList = $aSelList;
02863     }
02864 
02872     public function getPictureUrl( $iIndex = 1 )
02873     {
02874         if ( $iIndex ) {
02875             $sImgName = false;
02876             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02877                 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02878             }
02879 
02880             $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02881             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02882         }
02883     }
02884 
02893     public function getIconUrl( $iIndex = 0 )
02894     {
02895         $sImgName = false;
02896         $sDirname = "product/1/";
02897         if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02898             $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02899             $sDirname = "product/{$iIndex}/";
02900         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02901             $sImgName = basename( $this->oxarticles__oxicon->value );
02902             $sDirname = "product/icon/";
02903         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02904             $sImgName = basename( $this->oxarticles__oxpic1->value );
02905         }
02906 
02907         $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02908         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02909     }
02910 
02918     public function getThumbnailUrl( $bSsl = null )
02919     {
02920         $sImgName = false;
02921         $sDirname = "product/1/";
02922         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02923             $sImgName = basename( $this->oxarticles__oxthumb->value );
02924             $sDirname = "product/thumb/";
02925         } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02926             $sImgName = basename( $this->oxarticles__oxpic1->value );
02927         }
02928 
02929         $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02930         return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
02931     }
02932 
02940     public function getZoomPictureUrl( $iIndex = '' )
02941     {
02942         $iIndex = (int) $iIndex;
02943         if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02944             $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02945             $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02946             return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02947         }
02948     }
02949 
02955     public function getFileUrl()
02956     {
02957         return $this->getConfig()->getPictureUrl( 'media/' );
02958     }
02959 
02965     public function getPriceFromPrefix()
02966     {
02967         $sPricePrefix = '';
02968         if ( $this->_blIsRangePrice) {
02969             $sPricePrefix = oxLang::getInstance()->translateString('priceFrom').' ';
02970         }
02971 
02972         return $sPricePrefix;
02973     }
02974 
02980     protected function _saveArtLongDesc()
02981     {
02982         $myConfig = $this->getConfig();
02983         $sShopId = $myConfig->getShopID();
02984         if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02985             return;
02986         }
02987 
02988         if ($this->_blEmployMultilanguage) {
02989             $sValue = $this->getLongDescription()->getRawValue();
02990             if ( $sValue !== null ) {
02991                 $oArtExt = oxNew('oxI18n');
02992                 $oArtExt->init('oxartextends');
02993                 $oArtExt->setLanguage((int) $this->getLanguage());
02994                 if (!$oArtExt->load($this->getId())) {
02995                     $oArtExt->setId($this->getId());
02996                 }
02997                 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02998                 $oArtExt->save();
02999             }
03000         } else {
03001             $oArtExt = oxNew('oxI18n');
03002             $oArtExt->setEnableMultilang(false);
03003             $oArtExt->init('oxartextends');
03004             $aObjFields = $oArtExt->_getAllFields(true);
03005             if (!$oArtExt->load($this->getId())) {
03006                 $oArtExt->setId($this->getId());
03007             }
03008 
03009             foreach ($aObjFields as $sKey => $sValue ) {
03010                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
03011                     $sField = $this->_getFieldLongName($sKey);
03012 
03013                     if (isset($this->$sField)) {
03014                         $sLongDesc = null;
03015                         if ($this->$sField instanceof oxField) {
03016                             $sLongDesc = $this->$sField->getRawValue();
03017                         } elseif (is_object($this->$sField)) {
03018                             $sLongDesc = $this->$sField->value;
03019                         }
03020                         if (isset($sLongDesc)) {
03021                             $sAEField = $oArtExt->_getFieldLongName($sKey);
03022                             $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
03023                         }
03024                     }
03025                 }
03026             }
03027             $oArtExt->save();
03028         }
03029     }
03030 
03036     protected function _skipSaveFields()
03037     {
03038         $myConfig = $this->getConfig();
03039 
03040         $this->_aSkipSaveFields = array();
03041 
03042         $this->_aSkipSaveFields[] = 'oxtimestamp';
03043        // $this->_aSkipSaveFields[] = 'oxlongdesc';
03044         $this->_aSkipSaveFields[] = 'oxinsert';
03045 
03046         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
03047             $this->_aSkipSaveFields[] = 'oxparentid';
03048         }
03049 
03050     }
03051 
03061     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03062     {
03063         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03064             // add prices of the same discounts
03065             if ( array_key_exists ($sKey, $aDiscounts) ) {
03066                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03067             } else {
03068                 $aDiscounts[$sKey] = $oDiscount;
03069             }
03070         }
03071         return $aDiscounts;
03072     }
03073 
03079     protected function _getGroupPrice()
03080     {
03081         $dPrice = $this->oxarticles__oxprice->value;
03082 
03083         $oUser = $this->getArticleUser();
03084         if ( $oUser ) {
03085             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03086                 $dPrice = $this->oxarticles__oxpricea->value;
03087             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03088                 $dPrice = $this->oxarticles__oxpriceb->value;
03089             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03090                 $dPrice = $this->oxarticles__oxpricec->value;
03091             }
03092         }
03093 
03094         // #1437/1436C - added config option, and check for zero A,B,C price values
03095         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03096             $dPrice = $this->oxarticles__oxprice->value;
03097         }
03098 
03099         return $dPrice;
03100     }
03101 
03110     protected function _getAmountPrice($dAmount = 1)
03111     {
03112         $myConfig = $this->getConfig();
03113 
03114         startProfile( "_getAmountPrice" );
03115 
03116         $dPrice = $this->_getGroupPrice();
03117         $oAmtPrices = $this->_getAmountPriceList();
03118         foreach ($oAmtPrices as $oAmPrice) {
03119             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03120                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03121                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03122                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03123             }
03124         }
03125 
03126         stopProfile( "_getAmountPrice" );
03127         return $dPrice;
03128     }
03129 
03138     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03139     {
03140         $myConfig = $this->getConfig();
03141         // #690
03142         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03143 
03144             $aSelLists = $this->getSelectLists();
03145 
03146             foreach ( $aSelLists as $key => $aSel) {
03147                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03148                     $oSel = $aSel[$aChosenList[$key]];
03149                     if ( $oSel->priceUnit =='abs' ) {
03150                         $dPrice += $oSel->price;
03151                     } elseif ( $oSel->priceUnit =='%' ) {
03152                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03153                     }
03154                 }
03155             }
03156         }
03157         return $dPrice;
03158     }
03159 
03160 
03168     protected function _fillAmountPriceList($oAmPriceList)
03169     {
03170         $myConfig = $this->getConfig();
03171         $myUtils  = oxUtils::getInstance();
03172 
03173         //modifying price
03174         $oCur = $myConfig->getActShopCurrencyObject();
03175 
03176         $oUser = $this->getArticleUser();
03177 
03178         $oDiscountList = oxDiscountList::getInstance();
03179         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03180 
03181         $oLowestPrice = null;
03182 
03183         $dBasePrice = $this->_getGroupPrice();
03184         $oLang = oxLang::getInstance();
03185 
03186         $dArticleVat = null;
03187         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03188             $dArticleVat = $this->getArticleVat();
03189         }
03190 
03191         // trying to find lowest price value
03192         foreach ($oAmPriceList as $sId => $oItem) {
03193             $oItemPrice = oxNew( 'oxprice' );
03194             if ( $oItem->oxprice2article__oxaddabs->value) {
03195                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03196                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03197                 $this->_applyCurrency( $oItemPrice, $oCur );
03198             } else {
03199                 $oItemPrice->setPrice( $dBasePrice );
03200                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03201             }
03202 
03203             if (isset($dArticleVat)) {
03204                 $this->_applyVAT($oItemPrice, $dArticleVat);
03205             }
03206 
03207             if (!$oLowestPrice) {
03208                 $oLowestPrice = $oItemPrice;
03209             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03210                 $oLowestPrice = $oItemPrice;
03211             }
03212 
03213             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03214             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03215             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03216         }
03217 
03218         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03219         return $oAmPriceList;
03220     }
03221 
03227     protected function _getVariantsIds()
03228     {
03229         $aSelect = array();
03230         if ( ( $sId = $this->getId() ) ) {
03231             $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03232             $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03233                    $this->getSqlActiveSnippet( true ) . " order by oxsort";
03234             $oRs = $oDb->select( $sQ );
03235             if ( $oRs != false && $oRs->recordCount() > 0 ) {
03236                 while (!$oRs->EOF) {
03237                     $aSelect[] = reset( $oRs->fields );
03238                     $oRs->moveNext();
03239                 }
03240             }
03241         }
03242         return $aSelect;
03243     }
03244 
03250     public function getArticleVat()
03251     {
03252         if (!isset($this->_dArticleVat)) {
03253             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03254         }
03255         return $this->_dArticleVat;
03256     }
03257 
03266     protected function _applyVAT( oxPrice $oPrice, $dVat )
03267     {
03268         startProfile(__FUNCTION__);
03269         $oPrice->setVAT( $dVat );
03270         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03271             $oPrice->setUserVat( $dVat );
03272         }
03273         stopProfile(__FUNCTION__);
03274     }
03275 
03283     public function applyVats( oxPrice $oPrice )
03284     {
03285         $this->_applyVAT($oPrice, $this->getArticleVat() );
03286     }
03287 
03298     protected function _applyDiscounts( $oPrice, $aDiscounts )
03299     {
03300         $oDiscountList = oxDiscountList::getInstance();
03301         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03302     }
03303 
03311     public function applyDiscountsForVariant( $oPrice )
03312     {
03313         // apply discounts
03314         if ( !$this->skipDiscounts() ) {
03315             $oDiscountList = oxDiscountList::getInstance();
03316             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03317         }
03318     }
03319 
03328     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03329     {
03330         if ( !$oCur ) {
03331             $oCur = $this->getConfig()->getActShopCurrencyObject();
03332         }
03333 
03334         $oPrice->multiply($oCur->rate);
03335     }
03336 
03337 
03346     protected function _getAttribsString(&$sAttribs, &$iCnt)
03347     {
03348         // we do not use lists here as we dont need this overhead right now
03349         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03350         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03351         $sAttribs = '';
03352         $blSep = false;
03353         $rs = $oDb->select( $sSelect);
03354         $iCnt = 0;
03355         if ($rs != false && $rs->recordCount() > 0) {
03356             while (!$rs->EOF) {
03357                 if ( $blSep) {
03358                     $sAttribs .= ' or ';
03359                 }
03360                 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03361                 $blSep = true;
03362                 $iCnt++;
03363                 $rs->moveNext();
03364             }
03365         }
03366     }
03367 
03376     protected function _getSimList($sAttribs, $iCnt)
03377     {
03378         $myConfig = $this->getConfig();
03379         $oDb      = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03380 
03381         // #523A
03382         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03383         // 70% same attributes
03384         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03385             $iAttrPercent = 0.70;
03386         }
03387         // #1137V iAttributesPercent = 100 doesnt work
03388         $iHitMin = ceil( $iCnt * $iAttrPercent );
03389 
03390         // we do not use lists here as we dont need this overhead right now
03391         $aList= array();
03392         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03393                     ( $sAttribs )
03394                     and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03395                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03396 
03397         $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03398         if ($rs != false && $rs->recordCount() > 0) {
03399             while (!$rs->EOF) {
03400                 $oTemp = new stdClass();    // #663
03401                 $oTemp->cnt = $rs->fields['cnt'];
03402                 $oTemp->id  = $rs->fields['oxobjectid'];
03403                 $aList[] = $oTemp;
03404                 $rs->moveNext();
03405             }
03406         }
03407         return $aList;
03408     }
03409 
03418     protected function _generateSimListSearchStr($sArticleTable, $aList)
03419     {
03420         $myConfig = $this->getConfig();
03421         $sFieldList = $this->getSelectFields();
03422         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03423         $blSep = false;
03424         $iCnt = 0;
03425         $oDb = oxDb::getDb();
03426         foreach ( $aList as $oTemp) {
03427             if ( $blSep) {
03428                 $sSearch .= ',';
03429             }
03430             $sSearch .= $oDb->quote($oTemp->id);
03431             $blSep = true;
03432             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03433                 break;
03434             }
03435             $iCnt++;
03436         }
03437 
03438         //#1741T
03439         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03440         $sSearch .= ') ';
03441 
03442         // #524A -- randomizing articles in attribute list
03443         $sSearch .= ' order by rand() ';
03444 
03445         return $sSearch;
03446     }
03447 
03456     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03457     {
03458 
03459         $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03460         $sO2CView = getViewName( 'oxobject2category' );
03461 
03462         // we do not use lists here as we dont need this overhead right now
03463         if ( !$blSearchPriceCat ) {
03464             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03465                          {$sCatView}.oxid = oxobject2category.oxcatnid
03466                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03467         } else {
03468             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03469                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03470                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03471         }
03472         return $sSelect;
03473     }
03474 
03480     protected function _generateSearchStrForCustomerBought()
03481     {
03482         $sArtTable = $this->getViewName();
03483         $sOrderArtTable = getViewName( 'oxorderarticles' );
03484 
03485         // fetching filter params
03486         $sIn = " '{$this->oxarticles__oxid->value}' ";
03487         if ( $this->oxarticles__oxparentid->value ) {
03488 
03489             // adding article parent
03490             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03491             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03492 
03493         } else {
03494             $sParentIdForVariants = $this->getId();
03495         }
03496 
03497         // adding variants
03498         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03499         $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03500         if ( $oRs != false && $oRs->recordCount() > 0) {
03501             while ( !$oRs->EOF ) {
03502                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03503                 $oRs->moveNext();
03504             }
03505         }
03506 
03507         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03508         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03509 
03510         // building sql (optimized)
03511         $sQ = "select distinct {$sArtTable}.* from (
03512                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03513                ) as suborder
03514                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03515                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03516                where {$sArtTable}.oxid not in ( {$sIn} )
03517                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03518 
03519         /* non optimized, but could be used if index forcing is not supported
03520         // building sql
03521         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03522                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03523                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03524                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03525                and ".$this->getSqlActiveSnippet();
03526         */
03527 
03528         return $sQ;
03529     }
03530 
03540     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03541     {
03542         $sCategoryView = getViewName('oxcategories');
03543         $sO2CView = getViewName('oxobject2category');
03544 
03545         $oDb    = oxDb::getDb();
03546         $sOXID  = $oDb->quote($sOXID);
03547         $sCatId = $oDb->quote($sCatId);
03548 
03549         if (!$dPriceFromTo) {
03550             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03551             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03552             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03553             $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03554         } else {
03555             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03556             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03557             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03558             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03559         }
03560         return $sSelect;
03561     }
03562 
03568     protected function _getAmountPriceList()
03569     {
03570         if ( $this->_oAmountPriceList === null ) {
03571             $this->_oAmountPriceList = array();
03572             if ( !$this->skipDiscounts() ) {
03573                 $myConfig = $this->getConfig();
03574                 $sArtId   = $this->getId();
03575 
03576                 // #1690C - Scale prices and variants
03577                 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03578                     $sArtId = $this->oxarticles__oxparentid->value;
03579                 }
03580 
03581                 //collecting assigned to article amount-price list
03582                 $oAmPriceList = oxNew( 'oxlist' );
03583                 $oAmPriceList->init( 'oxbase', 'oxprice2article' );
03584 
03585                 $sShopID = $myConfig->getShopID();
03586                 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03587                     $sShopSelect = '1';
03588                 } else {
03589                     $sShopSelect = " oxshopid =  '$sShopID' ";
03590                 }
03591 
03592                 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = " . oxDb::getDb()->quote( $sArtId ) . " and $sShopSelect order by oxamount ");
03593 
03594                 // prepare abs prices if currently having percentages
03595                 $oBasePrice = $this->_getGroupPrice();
03596                 foreach ( $oAmPriceList as $oAmPrice ) {
03597                     if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03598                         $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03599                     }
03600                 }
03601 
03602                 $this->_oAmountPriceList = $oAmPriceList;
03603             }
03604         }
03605 
03606         return $this->_oAmountPriceList;
03607     }
03608 
03616     protected function _isFieldEmpty( $sFieldName )
03617     {
03618         $mValue = $this->$sFieldName->value;
03619 
03620         if ( is_null( $mValue ) ) {
03621             return true;
03622         }
03623 
03624         if ( $mValue === '' ) {
03625             return true;
03626         }
03627 
03628         $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03629 
03630         if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03631             return true;
03632         }
03633 
03634 
03635         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03636             return true;
03637         }
03638 
03639         $sFieldName = strtolower($sFieldName);
03640 
03641         if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03642             return true;
03643         }
03644 
03645         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03646             return true;
03647         }
03648 
03649         return false;
03650     }
03651 
03659     protected function _assignParentFieldValue($sFieldName)
03660     {
03661         if (!($oParentArticle = $this->getParentArticle())) {
03662             return;
03663         }
03664 
03665         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03666 
03667         // assigning only theese which parent article has
03668         if ( $oParentArticle->$sCopyFieldName != null ) {
03669 
03670             // only overwrite database values
03671             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03672                 return;
03673             }
03674 
03675             //do not copy certain fields
03676             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03677                 return;
03678             }
03679 
03680             //COPY THE VALUE
03681             // assigning images from parent only if variant has no master image (#1807)
03682             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03683                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03684                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03685                 }
03686             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03687                 // for zoom images checking master image with specified index
03688                 // assign from parent only if no pictures to variant are added
03689                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03690                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03691                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03692                 }
03693             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03694                 // if no pics generated for variants, load all from
03695                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03696             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03697                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03698             }
03699         }
03700     }
03701 
03707     public function getParentArticle()
03708     {
03709         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03710             $sIndex = $sParentId . "_" . $this->getLanguage();
03711             if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03712                 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03713                 self::$_aLoadedParents[$sIndex]->_blSkipAbPrice  = true;
03714                 self::$_aLoadedParents[$sIndex]->_blLoadPrice    = false;
03715                 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03716                 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03717             }
03718             return self::$_aLoadedParents[$sIndex];
03719         }
03720     }
03721 
03729     protected function _getParentAricle()
03730     {
03731         return $this->getParentArticle();
03732     }
03733 
03739     protected function _assignParentFieldValues()
03740     {
03741         startProfile('articleAssignParentInternal');
03742         if ( $this->oxarticles__oxparentid->value ) {
03743             // yes, we are in fact a variant
03744             if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03745                 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03746                     $this->_assignParentFieldValue( $sFieldName );
03747                 }
03748             }
03749         }
03750         stopProfile('articleAssignParentInternal');
03751     }
03752 
03758     protected function _assignNotBuyableParent()
03759     {
03760         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03761              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03762             $this->_blNotBuyableParent = true;
03763 
03764         }
03765     }
03766 
03772     protected function _assignStock()
03773     {
03774         $myConfig = $this->getConfig();
03775         // -----------------------------------
03776         // stock
03777         // -----------------------------------
03778 
03779         // #1125 A. must round (using floor()) value taken from database and cast to int
03780         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03781             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03782         }
03783         //GREEN light
03784         $this->_iStockStatus = 0;
03785 
03786         // if we have flag /*1 or*/ 4 - we show always green light
03787         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03788             //ORANGE light
03789             $iStock = $this->oxarticles__oxstock->value;
03790 
03791             if ($this->_blNotBuyableParent) {
03792                 $iStock = $this->oxarticles__oxvarstock->value;
03793             }
03794 
03795 
03796             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03797                 $this->_iStockStatus = 1;
03798             }
03799 
03800             //RED light
03801             if ($iStock <= 0) {
03802                 $this->_iStockStatus = -1;
03803             }
03804         }
03805 
03806 
03807         // stock
03808         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03809             $iOnStock = $this->oxarticles__oxstock->value;
03810             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03811                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03812             }
03813             if ($iOnStock <= 0) {
03814                 $this->setBuyableState( false );
03815             }
03816         }
03817 
03818         //exceptional handling for variant parent stock:
03819         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03820             $this->setBuyableState( true );
03821             //but then at least setting notBuaybleParent to true
03822             $this->_blNotBuyableParent = true;
03823         }
03824 
03825         //special treatment for lists when blVariantParentBuyable config option is set to false
03826         //then we just hide "to basket" button.
03827         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03828         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03829             $this->setBuyableState( false );
03830         }
03831 
03832         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03833         if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03834             $this->setBuyableState( false );
03835         }
03836     }
03837 
03843     protected function _assignPrices()
03844     {
03845         $myConfig = $this->getConfig();
03846 
03847         // Performance
03848         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03849             return;
03850         }
03851 
03852         //price per unit handling
03853         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03854             // compute price
03855             $dPrice = $this->getPrice()->getBruttoPrice();
03856             $oCur = $myConfig->getActShopCurrencyObject();
03857             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03858         }
03859 
03860         //getting min and max prices of variants
03861         if ( $this->_hasAnyVariant() ) {
03862             $this->_applyRangePrice();
03863         }
03864     }
03865 
03871     protected function _assignPersistentParam()
03872     {
03873         // Persistent Parameter Handling
03874         $aPersParam     = oxSession::getVar( 'persparam');
03875         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03876             $this->_aPersistParam = $aPersParam[$this->getId()];
03877         }
03878     }
03879 
03885     protected function _assignDynImageDir()
03886     {
03887         $myConfig = $this->getConfig();
03888 
03889         $sThisShop = $this->oxarticles__oxshopid->value;
03890 
03891         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03892         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03893         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03894         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03895     }
03896 
03902     protected function _assignComparisonListFlag()
03903     {
03904         // #657 add a flag if article is on comparisonlist
03905 
03906         $aItems = oxSession::getVar('aFiltcompproducts');
03907         if ( isset( $aItems[$this->getId()])) {
03908             $this->_blIsOnComparisonList = true;
03909         }
03910     }
03911 
03917     protected function _assignAttributes()
03918     {
03919         //#1029T load attributes
03920         //#1078S removed check for module "Produktvergleich"
03921         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03922             $this->getAttributes();
03923         }
03924     }
03925 
03926 
03934     protected function _insert()
03935     {
03936         // set oxinsert
03937         $iInsertTime = time();
03938         $now = date('Y-m-d H:i:s', $iInsertTime);
03939         $this->oxarticles__oxinsert    = new oxField( $now );
03940         $this->oxarticles__oxtimestamp = new oxField( $now );
03941         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03942             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03943         }
03944 
03945         return parent::_insert();
03946     }
03947 
03953     protected function _update()
03954     {
03955 
03956         $this->_skipSaveFields();
03957 
03958         $myConfig = $this->getConfig();
03959 
03960 
03961         return parent::_update();
03962     }
03963 
03971     protected function _deleteRecords($sOXID)
03972     {
03973         $oDb = oxDb::getDb();
03974 
03975         $sOXID = $oDb->quote($sOXID);
03976 
03977         //remove other records
03978         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03979         $oDb->execute( $sDelete);
03980 
03981         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03982         $oDb->execute( $sDelete);
03983 
03984         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03985         $oDb->execute( $sDelete);
03986 
03987         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03988         $oDb->execute( $sDelete);
03989 
03990         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03991         $oDb->execute( $sDelete);
03992 
03993         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03994         $oDb->execute( $sDelete);
03995 
03996         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03997         $oDb->execute( $sDelete);
03998 
03999         //#1508C - deleting oxobject2delivery entries added
04000         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04001         $oDb->execute( $sDelete);
04002 
04003         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04004         $oDb->execute( $sDelete);
04005 
04006         //delete the record
04007         foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
04008             $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
04009         }
04010 
04011         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04012         $rs = $oDb->execute( $sDelete );
04013 
04014         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04015         $rs = $oDb->execute( $sDelete );
04016 
04017 
04018         return $rs;
04019     }
04020 
04028     protected function _deleteVariantRecords( $sOXID )
04029     {
04030         if ( $sOXID ) {
04031             $oDb = oxDb::getDb();
04032             //collect variants to remove recursively
04033             $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
04034             $rs = $oDb->select( $sQ, false, false );
04035             if ($rs != false && $rs->recordCount() > 0) {
04036                 while (!$rs->EOF) {
04037                     $this->delete( $rs->fields[0] );
04038                     $rs->moveNext();
04039                 }
04040             }
04041         }
04042     }
04043 
04053     protected function _resetCacheAndArticleCount( $sOxid )
04054     {
04055         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04056     }
04057 
04063     protected function _deletePics()
04064     {
04065         $myUtilsPic = oxUtilsPic::getInstance();
04066         $myConfig   = $this->getConfig();
04067         $oPictureHandler = oxPictureHandler::getInstance();
04068 
04069         //deleting custom main icon
04070         $oPictureHandler->deleteMainIcon( $this );
04071 
04072         //deleting custom thumbnail
04073         $oPictureHandler->deleteThumbnail( $this );
04074 
04075         $sAbsDynImageDir = $myConfig->getPictureDir(false);
04076 
04077         // deleting master image and all generated images
04078         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04079         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04080             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04081         }
04082     }
04083 
04093     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04094     {
04095 
04096         $myUtilsCount = oxUtilsCount::getInstance();
04097 
04098         if ( $sVendorId ) {
04099             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04100         }
04101 
04102         if ( $sManufacturerId ) {
04103             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04104         }
04105 
04106         //also reseting category counts
04107         $oDb = oxDb::getDb();
04108         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04109         $oRs = $oDb->select( $sQ, false, false );
04110         if ( $oRs !== false && $oRs->recordCount() > 0) {
04111             while ( !$oRs->EOF ) {
04112                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04113                 $oRs->moveNext();
04114             }
04115         }
04116     }
04117 
04125     protected function _onChangeUpdateStock( $sParentID )
04126     {
04127         if ( $sParentID ) {
04128             $oDb = oxDb::getDb();
04129             $sParentIdQuoted = $oDb->quote($sParentID);
04130             $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04131             $rs = $oDb->select( $sQ, false, false );
04132             $iOldStock = $rs->fields[0];
04133             $iVendorID = $rs->fields[1];
04134             $iManufacturerID = $rs->fields[2];
04135 
04136             $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04137             $iStock = (float) $oDb->getOne( $sQ, false, false );
04138 
04139             $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04140             $oDb->execute( $sQ );
04141 
04142                 //now lets update category counts
04143                 //first detect stock status change for this article (to or from 0)
04144                 if ( $iStock < 0 ) {
04145                     $iStock = 0;
04146                 }
04147                 if ( $iOldStock < 0 ) {
04148                     $iOldStock = 0;
04149                 }
04150                 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04151                     //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04152                     // so far we leave it like this but later we could move all count resets to one or two functions
04153                     $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04154                 }
04155         }
04156     }
04157 
04165     protected function _onChangeStockResetCount( $sOxid )
04166     {
04167         $myConfig = $this->getConfig();
04168 
04169         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04170            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04171 
04172                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04173         }
04174     }
04175 
04183     protected function _onChangeUpdateVarCount( $sParentID )
04184     {
04185         if ( $sParentID ) {
04186             $oDb = oxDb::getDb();
04187             $sParentIdQuoted = $oDb->quote( $sParentID );
04188             $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04189             $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04190 
04191             $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04192             $oDb->execute( $sQ );
04193         }
04194     }
04195 
04203     protected function _onChangeUpdateMinVarPrice( $sParentID )
04204     {
04205         if ( $sParentID ) {
04206             $oDb = oxDb::getDb();
04207             $sParentIdQuoted = $oDb->quote($sParentID);
04208             //#M0000883 (Sarunas)
04209             $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04210             $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04211 
04212             $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04213 
04214             $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04215 
04216             if ($dVarMinPrice) {
04217                 if ($blParentBuyable) {
04218                     $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04219                 }
04220 
04221             } else {
04222                 $dVarMinPrice = $dParentPrice;
04223             }
04224 
04225             if ( $dVarMinPrice ) {
04226                 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04227                 $oDb->execute($sQ);
04228             }
04229         }
04230     }
04231 
04232 
04238     protected function _applyRangePrice()
04239     {
04240         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04241         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04242             return;
04243         }
04244 
04245         $this->_blIsRangePrice = false;
04246 
04247         // if parent is buyable - do not apply range price calcculations
04248         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04249             return;
04250         }
04251 
04252         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04253             //#2509 we cannot force brutto price here, as netto price can be added to DB
04254             // $this->getPrice()->setBruttoPriceMode();
04255             $dPrice = $this->oxarticles__oxvarminprice->value;
04256             $this->getPrice()->setPrice($dPrice);
04257             $this->_blIsRangePrice = true;
04258             $this->_calculatePrice( $this->getPrice() );
04259             return;
04260         }
04261 
04262         $aPrices = array();
04263 
04264         if (!$this->_blNotBuyableParent) {
04265             $aPrices[] = $this->getPrice()->getBruttoPrice();
04266         }
04267 
04268         $aVariants = $this->getVariants(false);
04269 
04270         if (count($aVariants)) {
04271             foreach ($aVariants as $sKey => $oVariant) {
04272                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04273             }
04274         }
04275 
04276         if ( count( $aPrices ) ) {
04277             $dMinPrice = min( $aPrices );
04278             $dMaxPrice = max( $aPrices );
04279         }
04280 
04281         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04282             $this->getPrice()->setBruttoPriceMode();
04283             $this->getPrice()->setPrice($dMinPrice);
04284         }
04285 
04286         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04287             $this->getPrice()->setBruttoPriceMode();
04288             $this->getPrice()->setPrice($dMinPrice);
04289             $this->_blIsRangePrice = true;
04290         }
04291     }
04292 
04299     public function getProductId()
04300     {
04301         return $this->getId();
04302     }
04303 
04309     public function getProductParentId()
04310     {
04311         return $this->oxarticles__oxparentid->value;
04312     }
04313 
04319     public function isOrderArticle()
04320     {
04321         return false;
04322     }
04323 
04329     public function isVariant()
04330     {
04331         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04332     }
04333 
04339     public function isMdVariant()
04340     {
04341         $oMdVariant = oxNew( "oxVariantHandler" );
04342 
04343         return $oMdVariant->isMdVariant($this);
04344     }
04345 
04353     public function getSqlForPriceCategories($sFields = '')
04354     {
04355         if (!$sFields) {
04356             $sFields = 'oxid';
04357         }
04358         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04359         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04360         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04361                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04362                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04363     }
04364 
04372     public function inPriceCategory( $sCatNid )
04373     {
04374         $oDb = oxDb::getDb();
04375 
04376         $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04377         $sQuotedCnid = $oDb->quote( $sCatNid );
04378         return (bool) $oDb->getOne(
04379             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04380            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04381            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04382            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04383            .")"
04384         );
04385     }
04386 
04392     public function getMdVariants()
04393     {
04394         if ( $this->_oMdVariants ) {
04395             return $this->_oMdVariants;
04396         }
04397 
04398         $oParentArticle = $this->getParentArticle();
04399         if ( $oParentArticle ) {
04400             $oVariants = $oParentArticle->getVariants();
04401         } else {
04402             $oVariants = $this->getVariants();
04403         }
04404 
04405         $oVariantHandler = oxNew( "oxVariantHandler" );
04406         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04407 
04408         return $this->_oMdVariants;
04409     }
04410 
04416     public function getMdSubvariants()
04417     {
04418         return $this->getMdVariants()->getMdSubvariants();
04419     }
04420 
04428     protected function _hasMasterImage( $iIndex )
04429     {
04430         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04431 
04432         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04433             return false;
04434         }
04435         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04436             return false;
04437         }
04438 
04439         $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04440 
04441         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04442             return true;
04443         }
04444 
04445         return false;
04446     }
04447 
04456     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04457     {
04458         if ( $sFieldName ) {
04459             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04460             return $this->$sFieldName->value;
04461         }
04462     }
04463 
04471     public function getMasterZoomPictureUrl( $iIndex )
04472     {
04473         $sPicUrl  = false;
04474         $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04475 
04476         if ( $sPicName && $sPicName != "nopic.jpg" ) {
04477             $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04478             if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04479                 $sPicUrl = false;
04480             }
04481         }
04482 
04483         return $sPicUrl;
04484     }
04485 
04491     public function getUnitName()
04492     {
04493         if ( $this->oxarticles__oxunitname->value ) {
04494             return oxLang::getInstance()->translateString( $this->oxarticles__oxunitname->value );
04495         }
04496     }
04497 
04505     public function getArticleFiles( $blAddFromParent=false )
04506     {
04507         if ( $this->_aArticleFiles === null) {
04508 
04509             $this->_aArticleFiles = false;
04510 
04511             $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04512 
04513             if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04514                 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04515             }
04516 
04517             $oArticleFiles = oxNew("oxlist");
04518             $oArticleFiles->init("oxfile");
04519             $oArticleFiles->selectString( $sQ );
04520             $this->_aArticleFiles  = $oArticleFiles;
04521 
04522         }
04523 
04524         return $this->_aArticleFiles;
04525     }
04526 
04532     public function isDownloadable()
04533     {
04534         return $this->oxarticles__oxisdownloadable->value;
04535     }
04536 
04542     public function hasAmountPrice()
04543     {
04544         if ( self::$_blHasAmountPrice === null ) {
04545 
04546             self::$_blHasAmountPrice = false;
04547 
04548             $oDb = oxDb::getDb();
04549             $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04550 
04551             if ( $oDb->getOne( $sQ ) ) {
04552                 self::$_blHasAmountPrice = true;
04553             }
04554         }
04555 
04556         return self::$_blHasAmountPrice;
04557     }
04558 }