oxarticle.php

Go to the documentation of this file.
00001 <?php
00002 
00003 // defining supported link types
00004 define( 'OXARTICLE_LINKTYPE_CATEGORY', 0 );
00005 define( 'OXARTICLE_LINKTYPE_VENDOR', 1 );
00006 define( 'OXARTICLE_LINKTYPE_MANUFACTURER', 2 );
00007 define( 'OXARTICLE_LINKTYPE_PRICECATEGORY', 3 );
00008 define( 'OXARTICLE_LINKTYPE_TAG', 4 );
00009 define( 'OXARTICLE_LINKTYPE_RECOMM', 5 );
00010 
00017 class oxArticle extends oxI18n implements oxIArticle, oxIUrl
00018 {
00024     protected $_sCoreTbl = 'oxarticles';
00025 
00031     protected $_sClassName = 'oxarticle';
00032 
00038     protected $_blUseLazyLoading = true;
00039 
00045     protected $_sItemKey;
00046 
00052     protected $_blCalcPrice    = true;
00053 
00058     protected $_oPrice      = null;
00059 
00065     protected $_dArticleVat = null;
00066 
00072     protected $_aPersistParam  = null;
00073 
00079     protected $_blNotBuyable   = false;
00080 
00087     protected $_blLoadVariants = true;
00088 
00094     protected $_aVariants = null;
00095 
00101     protected $_aVariantsWithNotOrderables = null;
00102 
00111     protected $_blNotBuyableParent  = false;
00112 
00116     protected $_blHasVariants = false;
00117 
00121     protected $_blHasMdVariants = false;
00122 
00127     protected $_blIsOnComparisonList = false;
00128 
00133     protected $_oUser = null;
00134 
00140     protected $_blLoadPrice = true;
00141 
00145     protected $_blSkipAbPrice = false;
00146 
00153     protected $_fPricePerUnit = null;
00154 
00158     protected $_blLoadParentData = false;
00159 
00163     protected $_blSkipAssign = false;
00164 
00170     protected $_blSkipDiscounts = null;
00171 
00176     protected $_oAttributeList = null;
00177 
00178 
00184     protected $_blIsRangePrice = false;
00185 
00191     protected $_aMediaUrls = null;
00192 
00198     static protected $_aLoadedParents;
00199 
00205     static protected $_aSelList;
00206 
00212     protected $_aDispSelList;
00213 
00219     protected $_blIsSeoObject = true;
00220 
00226     protected $_oAmountPriceList = null;
00227 
00236     protected $_iLinkType = 0;
00237 
00243     protected $_aStdUrls = array();
00244 
00250     protected $_aSeoUrls = array();
00251 
00257     protected $_aSeoAddParams = array();
00258 
00264     protected $_aStdAddParams = array();
00265 
00271     protected $_sDynImageDir = null;
00272 
00278     protected $_sMoreDetailLink = null;
00279 
00285     protected $_sToBasketLink = null;
00286 
00292     protected $_iStockStatus = null;
00293 
00299     protected $_oTPrice = null;
00300 
00306     protected $_oAmountPriceInfo = null;
00307 
00313     protected $_dAmountPrice = null;
00314 
00320     protected static $_aArticleManufacturers = array();
00321 
00327     protected static $_aArticleVendors = array();
00328 
00334     protected static $_aArticleCats = array();
00335 
00341     protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00342                                              'oxarticles__oxtimestamp',
00343                                              'oxarticles__oxnid',
00344                                              'oxarticles__oxid',
00345                                              'oxarticles__oxparentid');
00346 
00352     protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00353                                          'oxarticles__oxfreeshipping',
00354                                          'oxarticles__oxremindactive');
00355 
00361     protected $_oMdVariants = null;
00362 
00371     public function __construct($aParams = null)
00372     {
00373         if ( $aParams && is_array($aParams)) {
00374             foreach ( $aParams as $sParam => $mValue) {
00375                 $this->$sParam = $mValue;
00376             }
00377         }
00378         parent::__construct();
00379         $this->init( 'oxarticles' );
00380 
00381         $this->_blIsRangePrice = false;
00382     }
00383 
00391     public function __isset( $sName )
00392     {
00393         if ( $sName == 'oxarticles__oxlongdesc' ) {
00394             //get empty oxlongdesc field
00395             $this->getArticleLongDesc();
00396             return true;
00397         }
00398         return isset( $this->$sName );
00399     }
00400 
00409     public function __get($sName)
00410     {
00411         $myUtils = oxUtils::getInstance();
00412         switch ($sName) {
00413             // NOT using caching here, because of these params should be used in templates ONLY
00414             // and in template files they are used not very much [once most of the time]
00415 
00416             // price related
00417             case 'netprice':
00418             case 'netPrice':
00419                 $mVal = $myUtils->fRound($this->getPrice()->getNettoPrice());
00420                 break;
00421             case 'brutPrice':
00422                 return $myUtils->fRound($this->getPrice()->getBruttoPrice());
00423                 break;
00424             case 'vatPercent':
00425                 return $this->getPrice()->getVAT();
00426                 break;
00427             case 'vat':
00428                 return $this->getPrice()->getVATValue();
00429                 break;
00430             case 'fnetprice':
00431                 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($this->getPrice()->getNettoPrice()));
00432                 break;
00433             case 'fprice':
00434                 return $this->getFPrice();
00435                 break;
00436 
00437             // t price related
00438             case 'dtprice':
00439                 if ( $oPrice = $this->getTPrice() ) {
00440                     return $myUtils->fRound($oPrice->getBruttoPrice());
00441                     break;
00442                 } else {
00443                     return null;
00444                     break;
00445                 }
00446             case 'tvat':
00447                 if ( $oPrice = $this->getTPrice() ) {
00448                     return $oPrice->getVATValue();
00449                     break;
00450                 } else {
00451                     return null;
00452                     break;
00453                 }
00454             case 'ftprice':
00455                 if ( $oPrice = $this->getTPrice() ) {
00456                     return oxLang::getInstance()->formatCurrency( $myUtils->fRound($oPrice->getBruttoPrice()) );
00457                     break;
00458                 } else {
00459                     return null;
00460                     break;
00461                 }
00462             case 'oxarticles__oxlongdesc':
00463                 return $this->getArticleLongDesc($this->getId());
00464                 break;
00465             case 'foxdelivery':
00466                 return $this->getDeliveryDate();
00467                 break;
00468             case 'sItemKey':
00469                 return $this->getItemKey();
00470                 break;
00471             case 'selectlist':
00472                 return $this->_aDispSelList = $this->getDispSelList();
00473                 break;
00474             case 'blNotBuyable':
00475                 return $this->isNotBuyable();
00476                 break;
00477             case 'blNotBuyableParent':
00478                 return $this->isParentNotBuyable();
00479                 break;
00480             case 'blIsOnComparisonList':
00481                 return $this->isOnComparisonList();
00482                 break;
00483             case 'oVariantlist' :
00484                 return $this->getVariants();
00485                 break;
00486             case 'fPricePerUnit' :
00487                 return $this->getPricePerUnit();
00488                 break;
00489             case 'dimagedir' :
00490                 return $this->_sDynImageDir = $this->getDynImageDir();
00491                 break;
00492             case 'oxmoredetaillink' :
00493                 return $this->_sMoreDetailLink = $this->getMoreDetailLink();
00494                 break;
00495             case 'amountpricelist' :
00496                 return $this->loadAmountPriceInfo();
00497                 break;
00498             case 'stockstatus' :
00499                 return $this->getStockStatus();
00500                 break;
00501             case 'tobasketlink' :
00502                 return $this->getToBasketLink();
00503                 break;
00504             case 'oxdetaillink' :
00505                 return $this->getLink();
00506                 break;
00507             case 'aSelectlist' :
00508                 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00509                     return $this->aSelectlist = $this->getSelectLists();
00510                 }
00511                 return;
00512                 break;
00513         }
00514 
00515         //checking for zoom picture
00516         if ( strpos($sName, "oxarticles__oxzoom") === 0 ) {
00517             $this->_assignZoomPictureValues( $sName );
00518             return $this->$sName;
00519         }
00520 
00521         $this->$sName = parent::__get($sName);
00522         if ( $this->$sName ) {
00523             $this->_assignParentFieldValue($sName);
00524         }
00525 
00526         //checking for picture information
00527         if ( $sName == "oxarticles__oxthumb" || $sName == "oxarticles__oxicon" || (strpos($sName, "oxarticles__oxpic") === 0 && $sName != "oxarticles__oxpicsgenerated") ) {
00528             $this->_assignPictureValues( $sName );
00529             return $this->$sName;
00530         }
00531 
00532         return $this->$sName;
00533     }
00534 
00542     public function setId( $sId = null )
00543     {
00544         $sId = parent::setId( $sId );
00545 
00546         // TODO: in oxbase::setId make it to check if exists and update, not recreate, then delete this overload
00547         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00548 
00549         return $sId;
00550     }
00551 
00559     public function getTableNameForActiveSnippet( $blForceCoreTable = false )
00560     {
00561             $sTable = $this->getCoreTableName();
00562 
00563         return $sTable;
00564     }
00565 
00575     public function getActiveCheckQuery( $blForceCoreTable = false )
00576     {
00577         $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00578 
00579         // check if article is still active
00580         $sQ = " $sTable.oxactive = 1 ";
00581 
00582         // enabled time range check ?
00583         if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00584             $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00585             $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00586         }
00587 
00588         return $sQ;
00589     }
00590 
00604     public function getStockCheckQuery( $blForceCoreTable = false )
00605     {
00606         $myConfig = $this->getConfig();
00607         $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00608 
00609         $sQ = "";
00610 
00611         //do not check for variants
00612         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00613             $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0  ) ";
00614             //V #M513: When Parent article is not purchaseble, it's visibility should be displayed in shop only if any of Variants is available.
00615             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00616                 $sTimeCheckQ = '';
00617                 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00618                      $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00619                      $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00620                 }
00621                 $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 ) ) ";
00622             }
00623         }
00624 
00625         return $sQ;
00626     }
00627 
00639     public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = false  )
00640     {
00641         $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00642         $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00643 
00644         //checking if variant is active and stock status
00645         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00646             $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00647             if ( $blRemoveNotOrderables ) {
00648                 $sQ .= " and $sTable.oxstockflag != 3 ";
00649             }
00650             $sQ .= " ) ) ";
00651         }
00652 
00653         return $sQ;
00654     }
00655 
00663     public function getSqlActiveSnippet( $blForceCoreTable = false )
00664     {
00665         $myConfig = $this->getConfig();
00666 
00667         // check if article is still active
00668         $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00669 
00670         // stock and variants check
00671         $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00672 
00673 
00674         return "( $sQ ) ";
00675     }
00676 
00684     public function setSkipAssign($blSkipAssign)
00685     {
00686         $this->_blSkipAssign = $blSkipAssign;
00687     }
00688 
00696     public function disablePriceLoad( $oArticle )
00697     {
00698         $oArticle->_blLoadPrice = false;
00699     }
00700 
00706     public function getItemKey()
00707     {
00708         return $this->_sItemKey;
00709     }
00710 
00718     public function setItemKey($sItemKey)
00719     {
00720         $this->_sItemKey = $sItemKey;
00721     }
00722 
00730     public function setNoVariantLoading( $blLoadVariants )
00731     {
00732         $this->_blLoadVariants = !$blLoadVariants;
00733     }
00734 
00740     public function isBuyable()
00741     {
00742         if ($this->_blNotBuyableParent) {
00743             return false;
00744         }
00745 
00746         return !$this->_blNotBuyable;
00747     }
00748 
00754     public function getPersParams()
00755     {
00756         return $this->_aPersistParam;
00757     }
00758 
00764     public function isOnComparisonList()
00765     {
00766         return $this->_blIsOnComparisonList;
00767     }
00768 
00776     public function setOnComparisonList( $blOnList )
00777     {
00778         $this->_blIsOnComparisonList = $blOnList;
00779     }
00780 
00788     public function setLoadParentData($blLoadParentData)
00789     {
00790         $this->_blLoadParentData = $blLoadParentData;
00791     }
00792 
00800     public function setSkipAbPrice( $blSkipAbPrice = null )
00801     {
00802         $this->_blSkipAbPrice = $blSkipAbPrice;
00803     }
00804 
00810     public function getSearchableFields()
00811     {
00812         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00813         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00814 
00815         return $aFields;
00816     }
00817 
00818 
00826     public function isMultilingualField($sFieldName)
00827     {
00828         switch ($sFieldName) {
00829             case "oxlongdesc":
00830             case "oxtags":
00831                 return true;
00832         }
00833 
00834         return parent::isMultilingualField($sFieldName);
00835     }
00836 
00842     public function isVisible()
00843     {
00844 
00845         // admin preview mode
00846         if ( ( $blCanPreview = oxUtils::getInstance()->canPreview() ) !== null ) {
00847             return $blCanPreview;
00848         }
00849 
00850         // active ?
00851         $sNow = date('Y-m-d H:i:s');
00852         if ( !$this->oxarticles__oxactive->value &&
00853              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00854                 $this->oxarticles__oxactiveto->value < $sNow
00855              )) {
00856             return false;
00857         }
00858 
00859         // stock flags
00860         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00861             $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00862             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00863                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00864             }
00865             if ( $iOnStock <= 0 ) {
00866                 return false;
00867             }
00868         }
00869 
00870         return true;
00871     }
00872 
00881     public function assign( $aRecord)
00882     {
00883         startProfile('articleAssign');
00884 
00885 
00886         // load object from database
00887         parent::assign( $aRecord);
00888 
00889         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00890 
00891         // check for simple article.
00892         if ($this->_blSkipAssign) {
00893             return;
00894         }
00895 
00896         $this->_assignParentFieldValues();
00897         $this->_assignNotBuyableParent();
00898 
00899         $this->_assignAllPictureValues();
00900 
00901         $this->_assignStock();
00902         startProfile('articleAssignPrices');
00903         $this->_assignPrices();
00904         stopProfile('articleAssignPrices');
00905         $this->_assignPersistentParam();
00906         $this->_assignDynImageDir();
00907         $this->_assignComparisonListFlag();
00908         $this->_assignAttributes();
00909 
00910 
00911         //$this->_seoAssign();
00912 
00913         stopProfile('articleAssign');
00914     }
00915 
00926     public function load( $oxID)
00927     {
00928         // A. #1325 resetting to avoid problems when reloading (details etc)
00929         $this->_blNotBuyableParent = false;
00930 
00931         $blRet = parent::load( $oxID);
00932 
00933         // convert date's to international format
00934         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00935         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00936 
00937         return $blRet;
00938     }
00939 
00947     public function addToRatingAverage( $iRating)
00948     {
00949         $dOldRating = $this->oxarticles__oxrating->value;
00950         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00951         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00952         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00953         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00954         $dRatingCnt = (int) ($dOldCnt + 1);
00955         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00956         oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00957     }
00958 
00964     public function getArticleRatingAverage()
00965     {
00966         return round( $this->oxarticles__oxrating->value, 1);
00967     }
00968 
00974     public function getReviews()
00975     {
00976         $myConfig  = $this->getConfig();
00977 
00978         $aIds = array($this->getId());
00979 
00980         if ( $this->oxarticles__oxparentid->value ) {
00981                 $aIds[] = $this->oxarticles__oxparentid->value;
00982         }
00983 
00984         // showing variant reviews ..
00985         if ( $myConfig->getConfigParam( 'blShowVariantReviews' ) ) {
00986             $aAdd = $this->_getVariantsIds();
00987             if (is_array($aAdd)) {
00988                 $aIds = array_merge($aIds, $aAdd);
00989             }
00990         }
00991 
00992         $oReview = oxNew('oxreview');
00993         $oRevs = $oReview->loadList('oxarticle', $aIds);
00994 
00995         //if no review found, return null
00996         if ( $oRevs->count() < 1 ) {
00997             return null;
00998         }
00999 
01000         return $oRevs;
01001     }
01002 
01008     public function getCrossSelling()
01009     {
01010         $oCrosslist = oxNew( "oxarticlelist");
01011         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
01012         if ( $oCrosslist->count() ) {
01013             return $oCrosslist;
01014         }
01015     }
01016 
01022     public function getAccessoires()
01023     {
01024         $myConfig = $this->getConfig();
01025 
01026         // Performance
01027         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01028             return;
01029         }
01030 
01031         $oAcclist = oxNew( "oxarticlelist");
01032         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01033         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01034 
01035         if ( $oAcclist->count()) {
01036             return $oAcclist;
01037         }
01038     }
01039 
01045     public function getSimilarProducts()
01046     {
01047         // Performance
01048         $myConfig = $this->getConfig();
01049         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01050             return;
01051         }
01052 
01053         $sArticleTable = $this->_getObjectViewName('oxarticles');
01054 
01055         $sAttribs = '';
01056         $iCnt = 0;
01057         $this->_getAttribsString($sAttribs, $iCnt);
01058 
01059         if ( !$sAttribs) {
01060             return null;
01061         }
01062 
01063         $aList = $this->_getSimList($sAttribs, $iCnt);
01064 
01065         if ( count( $aList ) ) {
01066             uasort( $aList, 'cmpart');
01067 
01068             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01069 
01070             $oSimilarlist = oxNew( 'oxarticlelist' );
01071             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01072             $oSimilarlist->selectString( $sSearch);
01073 
01074             return $oSimilarlist;
01075         }
01076     }
01077 
01083     public function getCustomerAlsoBoughtThisProducts()
01084     {
01085         // Performance
01086         $myConfig = $this->getConfig();
01087         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01088             return;
01089         }
01090 
01091         // selecting products that fits
01092         $sQ = $this->_generateSearchStrForCustomerBought();
01093 
01094         $oArticles = oxNew( 'oxarticlelist' );
01095         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01096         $oArticles->selectString( $sQ );
01097         if ( $oArticles->count() ) {
01098             return $oArticles;
01099         }
01100     }
01101 
01108     public function loadAmountPriceInfo()
01109     {
01110         $myConfig = $this->getConfig();
01111         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01112             return array();
01113         }
01114 
01115         if ( $this->_oAmountPriceInfo === null ) {
01116             $this->_oAmountPriceInfo = array();
01117             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01118                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01119 
01120             }
01121         }
01122         return $this->_oAmountPriceInfo;
01123     }
01124 
01132     public function getSelectLists($sKeyPrefix = null)
01133     {
01134         //#1468C - more then one article in basket with different selectlist...
01135         //optionall function parameter $sKeyPrefix added, used only in basket.php
01136         $sKey = $this->getId();
01137         if ( isset( $sKeyPrefix ) ) {
01138             $sKey = $sKeyPrefix.'__'.$this->getId();
01139         }
01140 
01141         if ( !isset( self::$_aSelList[$sKey] ) ) {
01142             $oDb = oxDb::getDb();
01143             $sSLViewName = getViewName( 'oxselectlist' );
01144 
01145             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01146                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01147 
01148             // all selectlists this article has
01149             $oLists = oxNew( 'oxlist' );
01150             $oLists->init( 'oxselectlist' );
01151             $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01152 
01153             //#1104S if this is variant ant it has no selectlists, trying with parent
01154             if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01155                 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01156             }
01157 
01158             $dVat = 0;
01159             if ( $this->getPrice() != null ) {
01160                 $dVat = $this->getPrice()->getVat();
01161             }
01162 
01163             $iCnt = 0;
01164             self::$_aSelList[$sKey] = array();
01165             foreach ( $oLists as $oSelectlist ) {
01166                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01167                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01168                 $iCnt++;
01169             }
01170         }
01171         return self::$_aSelList[$sKey];
01172     }
01173 
01181     protected function _hasAnyVariant( $blForceCoreTable = false )
01182     {
01183         $sArticleTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
01184         return (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='".$this->getId()."'" );
01185     }
01186 
01192     public function hasMdVariants()
01193     {
01194         return $this->_blHasMdVariants;
01195     }
01196 
01205     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = false  )
01206     {
01207         if ( $blRemoveNotOrderables && $this->_aVariants ) {
01208             return $this->_aVariants;
01209         } elseif ( !$blRemoveNotOrderables && $this->_aVariantsWithNotOrderables ) {
01210             return $this->_aVariantsWithNotOrderables;
01211         }
01212 
01213         $myConfig = $this->getConfig();
01214         if ( !$this->_blLoadVariants ||
01215             ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01216             ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01217             return array();
01218         }
01219 
01220         //do not load me as a parent later
01221         self::$_aLoadedParents[$this->getId()] = $this;
01222 
01223         //load simple variants for lists
01224         if ( $this->_isInList() ) {
01225             $oVariants = oxNew( 'oxsimplevariantlist' );
01226             $oVariants->setParent( $this );
01227         } else {
01228             //loading variants
01229             $oVariants = oxNew( 'oxarticlelist' );
01230             $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01231         }
01232 
01233         if ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) {
01234 
01235             startProfile("selectVariants");
01236             $blUseCoreTable = $blForceCoreTable;
01237             $oBaseObject = $oVariants->getBaseObject();
01238             $sArticleTable = $this->getTableNameForActiveSnippet( $blUseCoreTable );
01239 
01240             $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01241                        $this->getActiveCheckQuery( $blUseCoreTable ) .
01242                        $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01243                        " order by $sArticleTable.oxsort";
01244 
01245             $oVariants->selectString( $sSelect );
01246 
01247             //if this is multidimensional variants, make additional processing
01248             if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01249                 $oMdVariants = oxNew( "oxVariantHandler" );
01250                 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01251             }
01252             stopProfile("selectVariants");
01253         }
01254 
01255         //if we have variants then depending on config option the parent may be non buyable
01256         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01257             $this->_blNotBuyableParent = true;
01258         }
01259 
01260         //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01261         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $oVariants->count() == 0 && $this->_blHasVariants ) {
01262             $this->_blNotBuyable = true;
01263         }
01264 
01265         // cache
01266         if ( $blRemoveNotOrderables ) {
01267             $this->_aVariants = $oVariants;
01268         } else {
01269             $this->_aVariantsWithNotOrderables = $oVariants;
01270         }
01271 
01272         return $oVariants;
01273     }
01274 
01280     public function getSimpleVariants()
01281     {
01282         if ( $this->oxarticles__oxvarcount->value) {
01283             return $this->getVariants();
01284         }
01285     }
01286 
01295     public function getAdminVariants( $sLanguage = null )
01296     {
01297         $myConfig = $this->getConfig();
01298 
01299         $oVariants = oxNew( 'oxarticlelist');
01300 
01301         if ( is_null($sLanguage) ) {
01302             $oVariants->getBaseObject()->setLanguage(oxLang::getInstance()->getBaseLanguage());
01303         } else {
01304             $oVariants->getBaseObject()->setLanguage($sLanguage);
01305         }
01306 
01307         $sSql = 'select * from oxarticles where oxparentid = "'.$this->getId().'" order by oxsort ';
01308 
01309         $oVariants->selectString( $sSql);
01310 
01311         //if we have variants then depending on config option the parent may be non buyable
01312         if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01313             //$this->blNotBuyable = true;
01314             $this->_blNotBuyableParent = true;
01315         }
01316 
01317         return $oVariants;
01318     }
01319 
01327     public function getCategory()
01328     {
01329         startPRofile( 'getCategory' );
01330 
01331         $oCategory = oxNew( 'oxcategory' );
01332         $oCategory->setLanguage( $this->getLanguage() );
01333 
01334         // variant handling
01335         $sOXID = $this->getId();
01336         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01337             $sOXID = $this->oxarticles__oxparentid->value;
01338         }
01339 
01340         $oStr = getStr();
01341         $sWhere   = $oCategory->getSqlActiveSnippet();
01342         $sSelect  = $this->_generateSearchStr( $sOXID );
01343         $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01344 
01345         // category not found ?
01346         if ( !$oCategory->assignRecord( $sSelect ) ) {
01347 
01348             $sSelect  = $this->_generateSearchStr( $sOXID, true );
01349             $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01350 
01351             // looking for price category
01352             if ( !$oCategory->assignRecord( $sSelect ) ) {
01353                 $oCategory = null;
01354             }
01355         }
01356 
01357         stopPRofile( 'getCategory' );
01358         return $oCategory;
01359     }
01360 
01369     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01370     {
01371         $myConfig = $this->getConfig();
01372         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01373             return self::$_aArticleCats[$this->getId()];
01374         }
01375 
01376         // variant handling
01377         $sOXID = $this->getId();
01378         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01379             $sOXID = $this->oxarticles__oxparentid->value;
01380         }
01381 
01382         // we do not use lists here as we dont need this overhead right now
01383         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01384         $oDB = oxDb::getDb(true);
01385         $rs = $oDB->execute( $sSql );
01386 
01387 
01388         $aRet = array();
01389 
01390         if ($rs != false && $rs->recordCount() > 0) {
01391             while (!$rs->EOF) {
01392                 $aRet[] = $rs->fields['oxcatnid'];
01393                 $rs->moveNext();
01394             }
01395         }
01396 
01397         // adding price categories if such exists
01398         $sSql = $this->getSqlForPriceCategories();
01399 
01400         $oDB = oxDb::getDb( true );
01401         $rs = $oDB->execute( $sSql );
01402 
01403         if ($rs != false && $rs->recordCount() > 0) {
01404             while (!$rs->EOF) {
01405 
01406                 if ( is_array( $rs->fields ) ) {
01407                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01408                 }
01409 
01410 
01411                 if ( !$aRet[$rs->fields['oxid']] ) {
01412                     $aRet[] = $rs->fields['oxid'];
01413                 }
01414                 $rs->moveNext();
01415             }
01416         }
01417 
01418         return self::$_aArticleCats[$this->getId()] = $aRet;
01419     }
01420 
01429     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01430     {
01431         $sO2CView = $this->_getObjectViewName('oxobject2category');
01432         $sCatView = $this->_getObjectViewName('oxcategories');
01433         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01434         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 ';
01435         if ( $blActCats ) {
01436             $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".(($this->getLanguage())?"_".$this->getLanguage():"")." = 0 ) ) = 0 ";
01437         }
01438         $sSelect .= 'order by oxobject2category.oxtime ';
01439         return $sSelect;
01440     }
01441 
01451     public function getVendor( $blShopCheck = true )
01452     {
01453         if ( ( $sVendorId = $this->getVendorId() ) ) {
01454             $oVendor = oxNew( 'oxvendor' );
01455         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01456             $oVendor = oxNew( 'oxi18n' );
01457             $oVendor->init('oxvendor');
01458             $oVendor->setReadOnly( true );
01459             $sVendorId = $this->oxarticles__oxvendorid->value;
01460         }
01461         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01462             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01463                 $oVendor->setReadOnly( true );
01464             }
01465             return $oVendor;
01466         }
01467         return null;
01468     }
01469 
01477     public function getVendorId( $blForceReload = false )
01478     {
01479         $sVendorId = false;
01480         if ( $this->oxarticles__oxvendorid->value ) {
01481             if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01482                 return self::$_aArticleVendors[$this->getId()];
01483             }
01484             $oDb = oxDb::getDb();
01485             $sVendorIdQuoted = $oDb->quote($this->oxarticles__oxvendorid->value);
01486             $sQ = "select oxid from ".getViewName('oxvendor')." where oxid=$sVendorIdQuoted";
01487             self::$_aArticleVendors[$this->getId()] = $sVendorId = $oDb->getOne( $sQ );
01488         }
01489         return $sVendorId;
01490     }
01491 
01499     public function getManufacturerId( $blForceReload = false )
01500     {
01501         $sManufacturerId = false;
01502         if ( $this->oxarticles__oxmanufacturerid->value ) {
01503             if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01504                 return self::$_aArticleManufacturers[$this->getId()];
01505             }
01506             $oDb = oxDb::getDb();
01507             $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid=".$oDb->quote($this->oxarticles__oxmanufacturerid->value);
01508             self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = $oDb->getOne( $sQ );
01509         }
01510         return $sManufacturerId;
01511     }
01512 
01522     public function getManufacturer( $blShopCheck = true )
01523     {
01524         $oManufacturer = oxNew( 'oxmanufacturer' );;
01525         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01526              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01527             $oManufacturer->setReadOnly( true );
01528             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01529         }
01530 
01531         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01532             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01533                 $oManufacturer->setReadOnly( true );
01534             }
01535             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01536         } else {
01537             $oManufacturer = null;
01538         }
01539 
01540         return $oManufacturer;
01541     }
01542 
01550     public function inCategory( $sCatNid)
01551     {
01552         return in_array( $sCatNid, $this->getCategoryIds());
01553     }
01554 
01563     public function isAssignedToCategory( $sCatId )
01564     {
01565         // variant handling
01566         $sOXID = $this->getId();
01567         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01568             $sOXID = $this->oxarticles__oxparentid->value;
01569         }
01570 
01571         $oDB = oxDb::getDb();
01572         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01573         $sOXID = $oDB->getOne( $sSelect);
01574         // article is assigned to passed category!
01575         if ( isset( $sOXID) && $sOXID) {
01576             return true;
01577         }
01578 
01579         // maybe this category is price category ?
01580         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01581             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01582             if ( $dPriceFromTo > 0) {
01583                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01584                 $sOXID = $oDB->getOne( $sSelect);
01585                 // article is assigned to passed category!
01586                 if ( isset( $sOXID) && $sOXID) {
01587                     return true;
01588                 }
01589             }
01590         }
01591         return false;
01592     }
01593 
01599     public function getTPrice()
01600     {
01601         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01602             return;
01603         }
01604         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01605         if ( $this->_oTPrice !== null ) {
01606             return $this->_oTPrice;
01607         }
01608 
01609         $this->_oTPrice = oxNew( 'oxPrice' );
01610         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01611 
01612         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01613         $this->_applyCurrency( $this->_oTPrice );
01614 
01615         return $this->_oTPrice;
01616     }
01617 
01623     public function skipDiscounts()
01624     {
01625         // allready loaded skip discounts config
01626         if ( $this->_blSkipDiscounts !== null )
01627             return $this->_blSkipDiscounts;
01628 
01629         if ( $this->oxarticles__oxskipdiscounts->value )
01630             return true;
01631 
01632         $sO2CView = getViewName('oxobject2category');
01633         $sSelect =  "select 1 from $sO2CView as oxobject2category left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01634         $sSelect .= 'where oxobject2category.oxobjectid="'.$this->getId().'" and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 and oxcategories.oxskipdiscounts = "1" ';
01635 
01636         return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01637     }
01638 
01646     public function setPrice(oxPrice $oPrice)
01647     {
01648         $this->_oPrice = $oPrice;
01649     }
01650 
01659     public function getBasePrice( $dAmount = 1 )
01660     {
01661         // override this function if you want e.g. different prices
01662         // for diff. usergroups.
01663 
01664         // Performance
01665         $myConfig = $this->getConfig();
01666         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01667             return;
01668 
01669         // GroupPrice or DB price ajusted by AmountPrice
01670         $dPrice = $this->_getAmountPrice( $dAmount );
01671 
01672 
01673         return $dPrice;
01674     }
01675 
01683     public function getPrice( $dAmount = 1 )
01684     {
01685         $myConfig = $this->getConfig();
01686         // Performance
01687         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01688             return;
01689         }
01690 
01691         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01692         if ( $dAmount != 1 || $this->_oPrice === null ) {
01693             $oPrice = oxNew( 'oxPrice' );
01694 
01695             // get base
01696             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01697 
01698             // price handling
01699             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01700                 return $this->_oPrice = $oPrice;
01701             }
01702 
01703             $this->_calculatePrice( $oPrice );
01704             if ( $dAmount != 1 ) {
01705                 return $oPrice;
01706             }
01707 
01708             $this->_oPrice = $oPrice;
01709         }
01710         return $this->_oPrice;
01711     }
01712 
01720     protected function _calculatePrice( $oPrice )
01721     {
01722         // apply VAT only if configuration requires it
01723         if ( !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01724             $this->_applyVAT( $oPrice, $this->getArticleVat() );
01725         }
01726 
01727         // apply currency
01728         $this->_applyCurrency( $oPrice );
01729         // apply discounts
01730         if ( !$this->skipDiscounts() ) {
01731             $oDiscountList = oxDiscountList::getInstance();
01732             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts($this, $this->getArticleUser() ) );
01733         }
01734 
01735         return $oPrice;
01736     }
01737 
01745     public function setArticleUser($oUser)
01746     {
01747         $this->_oUser = $oUser;
01748     }
01749 
01755     public function getArticleUser()
01756     {
01757         if ($this->_oUser) {
01758             return $this->_oUser;
01759         }
01760         return $this->getUser();
01761     }
01762 
01772     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01773     {
01774         $oUser = $oBasket->getBasketUser();
01775         $this->setArticleUser($oUser);
01776 
01777         $oBasketPrice = oxNew( 'oxPrice' );
01778 
01779         // get base price
01780         $dBasePrice = $this->getBasePrice( $dAmount );
01781 
01782         // applying select list price
01783         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01784 
01785         // setting price
01786         $oBasketPrice->setPrice( $dBasePrice );
01787 
01788         // apply VAT
01789         $this->_applyVat( $oBasketPrice, oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket ) );
01790 
01791         // apply currency
01792         $this->_applyCurrency( $oBasketPrice );
01793 
01794         // apply discounts
01795         if ( !$this->skipDiscounts() ) {
01796             // apply general discounts
01797             $oDiscountList = oxDiscountList::getInstance();
01798             $oDiscountList->applyDiscounts( $oBasketPrice, $oDiscountList->getArticleDiscounts( $this, $oUser ) );
01799         }
01800 
01801         // returning final price object
01802         return $oBasketPrice;
01803     }
01804 
01817     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01818     {
01819         $oDiscountList = oxDiscountList::getInstance();
01820         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01821     }
01822 
01831     public function delete( $sOXID = null )
01832     {
01833         if ( !$sOXID ) {
01834             $sOXID = $this->getId();
01835         }
01836         if ( !$sOXID ) {
01837             return false;
01838         }
01839 
01840 
01841         $this->load( $sOXID );
01842         $this->_deletePics();
01843         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01844         $this->_deleteVariantRecords( $sOXID );
01845         $rs = $this->_deleteRecords( $sOXID );
01846 
01847         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01848 
01849         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01850 
01851         return $rs->EOF;
01852     }
01853 
01862     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01863     {
01864         $this->beforeUpdate();
01865 
01866         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01867         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01868             $dAmount += $iStockCount;
01869             $iStockCount = 0;
01870         }
01871         $this->oxarticles__oxstock = new oxField($iStockCount);
01872 
01873         $oDb = oxDb::getDb();
01874         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01875         $this->onChange( ACTION_UPDATE_STOCK );
01876         return $dAmount;
01877     }
01878 
01887     public function updateSoldAmount( $dAmount = 0 )
01888     {
01889         if ( !$dAmount ) {
01890             return;
01891         }
01892 
01893         $this->beforeUpdate();
01894 
01895         // article is not variant - should be updated current amount
01896         if ( !$this->oxarticles__oxparentid->value ) {
01897             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01898             $dAmount = (double) $dAmount;
01899             $oDb = oxDb::getDb();
01900             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01901         } elseif ( $this->oxarticles__oxparentid->value) {
01902             // article is variant - should be updated this article parent amount
01903             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01904             $oUpdateArticle->updateSoldAmount( $dAmount );
01905         }
01906 
01907         $this->onChange( ACTION_UPDATE );
01908 
01909         return $rs;
01910     }
01911 
01917     public function disableReminder()
01918     {
01919         $oDB = oxDb::getDb(true);
01920         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01921     }
01922 
01929     public function save()
01930     {
01931         $myConfig = $this->getConfig();
01932 
01933         $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01934         $this->oxarticles__oxicon  = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01935         $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01936         for ($i=1; $i <= $iPicCount; $i++) {
01937             if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01938                 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01939             }
01940         }
01941 
01942         $blRet = parent::save();
01943 
01944         // save article long description
01945         $this->setArticleLongDesc();
01946 
01947         // load article images after save
01948         $this->_assignAllPictureValues();
01949 
01950         return $blRet;
01951     }
01952 
01953 
01960     public function getPictureGallery()
01961     {
01962         $myConfig = $this->getConfig();
01963 
01964         //initialize
01965         $blMorePic = false;
01966         $aArtPics  = array();
01967         $aArtIcons = array();
01968         $iActPicId = 1;
01969         $sActPic = $this->getPictureUrl( $iActPicId );
01970 
01971         if ( oxConfig::getParameter( 'actpicid' ) ) {
01972             $iActPicId = oxConfig::getParameter('actpicid');
01973         }
01974 
01975         $oStr = getStr();
01976         $iCntr = 0;
01977         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01978         $blCheckActivePicId = true;
01979 
01980         for ( $i = 1; $i <= $iPicCount; $i++) {
01981             $sPicVal = $this->getPictureUrl( $i );
01982             $sIcoVal = $this->getIconUrl( $i );
01983             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') ) {
01984                 if ($iCntr) {
01985                     $blMorePic = true;
01986                 }
01987                 $aArtIcons[$i]= $sIcoVal;
01988                 $aArtPics[$i]= $sPicVal;
01989                 $iCntr++;
01990 
01991                 if ($iActPicId == $i) {
01992                     $sActPic = $sPicVal;
01993                     $blCheckActivePicId = false;
01994                 }
01995 
01996             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
01997                 // if picture is empty, setting active pic id to next
01998                 // picture
01999                 $iActPicId++;
02000             }
02001         }
02002 
02003         $blZoomPic  = false;
02004         $aZoomPics = array();
02005         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02006 
02007         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02008             $sVal = $this->getZoomPictureUrl($j);
02009 
02010             if ( !$oStr->strstr($sVal, 'nopic.jpg')) {
02011                 if ($this->getConfig()->getConfigParam('blFormerTplSupport')) {
02012                     $sVal = $this->_sDynImageDir."/".$sVal;
02013                 }
02014                 $blZoomPic = true;
02015                 $aZoomPics[$c]['id'] = $c;
02016                 $aZoomPics[$c]['file'] = $sVal;
02017                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02018                 if (!$sVal) {
02019                     $aZoomPics[$c]['file'] = "nopic.jpg";
02020                 }
02021                 $c++;
02022             }
02023         }
02024 
02025         $aPicGallery = array('ActPicID' => $iActPicId,
02026                              'ActPic' => $sActPic,
02027                              'MorePics' => $blMorePic,
02028                              'Pics' => $aArtPics,
02029                              'Icons' => $aArtIcons,
02030                              'ZoomPic' => $blZoomPic,
02031                              'ZoomPics' => $aZoomPics);
02032 
02033         return $aPicGallery;
02034     }
02035 
02049     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02050     {
02051         $myConfig = $this->getConfig();
02052 
02053         if (!isset($sOXID)) {
02054             if ( $this->getId()) {
02055                 $sOXID = $this->getId();
02056             }
02057             if (!isset ($sOXID)) {
02058                 $sOXID = $this->oxarticles__oxid->value;
02059             }
02060             if ($this->oxarticles__oxparentid->value) {
02061                 $sParentID = $this->oxarticles__oxparentid->value;
02062             }
02063         }
02064         if (!isset($sOXID)) {
02065             return;
02066         }
02067 
02068         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02069         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02070             //if article has variants then updating oxvarstock field
02071             //getting parent id
02072             if (!isset($sParentID)) {
02073                 $oDb = oxDb::getDb();
02074                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02075                 $sParentID = $oDb->getOne($sQ);
02076             }
02077             //if we have parent id then update stock
02078             if ($sParentID) {
02079                 $this->_onChangeUpdateStock($sParentID);
02080             }
02081         }
02082         //if we have parent id then update count
02083         //update count even if blUseStock is not active
02084         if ($sParentID) {
02085             $this->_onChangeUpdateVarCount($sParentID);
02086         }
02087 
02088         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02089         $this->_onChangeUpdateMinVarPrice( $sId );
02090 
02091             // reseting articles count cache if stock has changed and some
02092             // articles goes offline (M:1448)
02093             if ( $sAction === ACTION_UPDATE_STOCK ) {
02094                 $this->_onChangeStockResetCount( $sOXID );
02095             }
02096 
02097     }
02098 
02105     public function getCustomVAT()
02106     {
02107         if ( isset($this->oxarticles__oxvat->value) ) {
02108             return $this->oxarticles__oxvat->value;
02109         }
02110     }
02111 
02120     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02121     {
02122         $myConfig = $this->getConfig();
02123         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02124             return true;
02125         }
02126 
02127         // fetching DB info as its up-to-date
02128         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02129         $rs = oxDb::getDb(true)->Execute( $sQ );
02130 
02131         $iOnStock   = 0;
02132         $iStockFlag = 0;
02133         if ( $rs !== false && $rs->recordCount() > 0 ) {
02134             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02135             $iStockFlag = $rs->fields['oxstockflag'];
02136 
02137             // dodger : fremdlager is also always considered as on stock
02138             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02139                 return true;
02140             }
02141             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02142                 $iOnStock = floor( $iOnStock );
02143             }
02144         }
02145         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02146             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02147         }
02148         if ( $iOnStock >= $dAmount ) {
02149             return true;
02150         } else {
02151             if ( $iOnStock > 0 ) {
02152                 return $iOnStock;
02153             } else {
02154                 $oEx = oxNew( 'oxArticleInputException' );
02155                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02156                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02157                 return false;
02158             }
02159         }
02160     }
02161 
02162 
02170     public function getArticleLongDesc($sOXID = null)
02171     {
02172 
02173         if ( !$sOXID ) {
02174             $sOXID = $this->oxarticles__oxid->value;
02175         }
02176 
02177         if ($sOXID == $this->oxarticles__oxid->value) {
02178             if (isset($this->oxarticles__oxlongdesc) && ($this->oxarticles__oxlongdesc instanceof oxField) && $this->oxarticles__oxlongdesc->value) {
02179                 return $this->oxarticles__oxlongdesc;
02180             }
02181         }
02182 
02183         $myConfig = $this->getConfig();
02184 
02185         if ( $sOXID ) {
02186             $sLangField = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02187             $oDb = oxDb::getDb();
02188             $this->_setLongDesc($oDb->getOne( "select oxlongdesc{$sLangField} from oxartextends where oxid = ".$oDb->quote($sOXID) ));
02189         } else {
02190             // TODO: check if keeping fldname is needed in non-admin mode
02191             $this->oxarticles__oxlongdesc = new oxField();
02192             $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02193             $this->oxarticles__oxlongdesc->table   = 'oxarticles';
02194             $this->oxarticles__oxlongdesc->fldtype = 'text';
02195         }
02196 
02197         return $this->oxarticles__oxlongdesc;
02198     }
02199 
02207     protected function _setLongDesc($sDbValue)
02208     {
02209         // TODO: the code below is redundant, optimize it, assignments should go smooth without conversions
02210         // hack, if editor screws up text, htmledit tends to do so
02211         $sDbValue = str_replace( '&amp;nbsp;', '&nbsp;', $sDbValue );
02212         $sDbValue = str_replace( '&amp;', '&', $sDbValue );
02213         $sDbValue = str_replace( '&quot;', '"', $sDbValue );
02214         $sDbValue = str_replace( '&lang=', '&amp;lang=', $sDbValue);
02215         //
02216 
02217         $oStr = getStr();
02218         $blHasSmarty = $oStr->strstr( $sDbValue, '[{' );
02219         $blHasPhp = $oStr->strstr( $sDbValue, '<?' );
02220         $myConfig = oxConfig::getInstance();
02221         if ( ( $blHasSmarty || $blHasPhp ) && ($myConfig->getConfigParam( 'blExport' ) || !$this->isAdmin() ) && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
02222             $sDbValue = oxUtilsView::getInstance()->parseThroughSmarty( $sDbValue, $this->getId() );
02223         }
02224         $this->oxarticles__oxlongdesc = new oxField($sDbValue, oxField::T_RAW);
02225         // TODO: check if keeping fldname is needed in non-admin mode
02226         $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02227         $this->oxarticles__oxlongdesc->table   = 'oxarticles';
02228         $this->oxarticles__oxlongdesc->fldtype = 'text';
02229     }
02230 
02236     public function setArticleLongDesc()
02237     {
02238 
02239         if ( $this->_blEmployMultilanguage ) {
02240             // update or insert article long description
02241             if ($this->oxarticles__oxlongdesc instanceof oxField) {
02242                 $sLongDesc = $this->oxarticles__oxlongdesc->getRawValue();
02243             } else {
02244                 $sLongDesc = $this->oxarticles__oxlongdesc->value;
02245             }
02246             $this->_saveArtLongDesc($this->getLanguage(), $sLongDesc);
02247         } else {
02248             $oArtExt = oxNew('oxi18n');
02249             $oArtExt->init('oxartextends');
02250             $aObjFields = $oArtExt->_getAllFields(true);
02251             foreach ($aObjFields as $sKey => $sValue ) {
02252                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02253                     $sField = $this->_getFieldLongName($sKey);
02254                     if (isset($this->$sField)) {
02255                         $iLang = $oArtExt->_getFieldLang($sKey);
02256                         $sLongDesc = null;
02257                         if ($this->$sField instanceof oxField) {
02258                             $sLongDesc = $this->$sField->getRawValue();
02259                         } elseif (is_object($this->$sField)) {
02260                             $sLongDesc = $this->$sField->value;
02261                         }
02262                         if (isset($sLongDesc)) {
02263                             $this->_saveArtLongDesc($iLang, $sLongDesc);
02264                         }
02265                     }
02266                 }
02267             }
02268         }
02269     }
02270 
02276     public function getAttributes()
02277     {
02278         if ( $this->_oAttributeList === null ) {
02279             $this->_oAttributeList = oxNew( 'oxattributelist' );
02280             $this->_oAttributeList->loadAttributes( $this->getId() );
02281         }
02282 
02283         return $this->_oAttributeList;
02284     }
02285 
02294     public function appendLink( $sAddParams, $iLang = null )
02295     {
02296         if ( $sAddParams ) {
02297             if ( $iLang === null ) {
02298                 $iLang = $this->getLanguage();
02299             }
02300 
02301             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02302             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02303         }
02304     }
02305 
02314     public function getBaseSeoLink( $iLang, $blMain = false )
02315     {
02316         $oEncoder = oxSeoEncoderArticle::getInstance();
02317         if ( !$blMain ) {
02318             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02319         }
02320         return $oEncoder->getArticleMainUrl( $this, $iLang );
02321     }
02322 
02331     public function getLink( $iLang = null, $blMain = false  )
02332     {
02333         if ( !oxUtils::getInstance()->seoIsActive() ) {
02334             return $this->getStdLink( $iLang );
02335         }
02336 
02337         if ( $iLang === null ) {
02338             $iLang = $this->getLanguage();
02339         }
02340 
02341         $iLinkType = $this->getLinkType();
02342         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02343             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02344         }
02345 
02346         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02347         if ( isset($this->_aSeoAddParams[$iLang])) {
02348             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02349         }
02350 
02351         return $sUrl;
02352     }
02353 
02362     public function getMainLink( $iLang = null )
02363     {
02364         return $this->getLink( $iLang, true );
02365     }
02366 
02374     public function setLinkType( $iType )
02375     {
02376         // resetting detaisl link, to force new
02377         $this->_sDetailLink = null;
02378 
02379         // setting link type
02380         $this->_iLinkType = (int) $iType;
02381     }
02382 
02388     public function getLinkType()
02389     {
02390         return $this->_iLinkType;
02391     }
02392 
02401     public function appendStdLink( $sAddParams, $iLang = null )
02402     {
02403         if ( $sAddParams ) {
02404             if ( $iLang === null ) {
02405                 $iLang = $this->getLanguage();
02406             }
02407 
02408             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02409             $this->_aStdAddParams[$iLang] .= $sAddParams;
02410         }
02411     }
02412 
02422     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02423     {
02424         $sUrl = '';
02425         if ( $blFull ) {
02426             //always returns shop url, not admin
02427             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02428         }
02429 
02430         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02431         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02432     }
02433 
02442     public function getStdLink( $iLang = null, $aParams = array() )
02443     {
02444         if ( $iLang === null ) {
02445             $iLang = $this->getLanguage();
02446         }
02447 
02448         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02449             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02450         }
02451 
02452         return oxUtilsUrl::getInstance()->processStdUrl( $this->_aStdUrls[$iLang], $aParams, $iLang, $iLang != $this->getLanguage() );
02453     }
02454 
02462     public function getStdTagLink( $sTag )
02463     {
02464         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02465         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02466     }
02467 
02473     public function getTags()
02474     {
02475         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02476         $sQ = "select $sTagField from oxartextends where oxid = '".$this->getId()."'";
02477         $sTags = oxDb::getDb(true)->getOne($sQ);
02478         $oTagCloud = oxNew('oxtagcloud');
02479         $sTags = $oTagCloud->trimTags($sTags);
02480         return $sTags;
02481     }
02482 
02490     public function saveTags($sTags)
02491     {
02492         //do not allow derived update
02493         if ( !$this->allowDerivedUpdate() ) {
02494             return false;
02495         }
02496 
02497 
02498         $oTagCloud = oxNew('oxtagcloud');
02499         $oTagCloud->resetTagCache();
02500         $sTags = $oTagCloud->prepareTags($sTags);
02501 
02502         $sTags = mysql_real_escape_string($sTags);
02503 
02504         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02505         $sQ = "update oxartextends set $sTagField = '$sTags'  where oxid = '".$this->getId()."'";
02506         return oxDb::getDb()->execute($sQ);
02507     }
02508 
02516     public function addTag($sTag)
02517     {
02518         $oDb = oxDb::getDb();
02519 
02520         $oTagCloud = oxNew('oxtagcloud');
02521         $oTagCloud->resetTagCache();
02522         $sTag = $oTagCloud->prepareTags($sTag);
02523         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02524 
02525         $sField = "oxartextends.OXTAGS" . oxLang::getInstance()->getLanguageTag();
02526 
02527         if ( $oDb->getOne( "select $sField from oxartextends where oxartextends.OXID = '{$this->getId()}'" ) ) {
02528             $sTailTag = $sTagSeparator . $sTag;
02529         } else {
02530             $sTailTag = $sTag;
02531         }
02532 
02533         $sTag = mysql_real_escape_string($sTag);
02534         $sTailTag = mysql_real_escape_string($sTailTag);
02535 
02536         $sQ = "insert into oxartextends (oxartextends.OXID, $sField) values ('".$this->getId()."', '{$sTag}')
02537                        ON DUPLICATE KEY update $sField = CONCAT(TRIM($sField), '$sTailTag') ";
02538 
02539         return $oDb->Execute($sQ);
02540     }
02541 
02547     public function getMediaUrls()
02548     {
02549         if ( $this->_aMediaUrls === null ) {
02550             $this->_aMediaUrls = oxNew("oxlist");
02551             $this->_aMediaUrls->init("oxmediaurl");
02552             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02553 
02554             $sQ = "select * from oxmediaurls where oxobjectid = '".$this->getId()."'";
02555             $this->_aMediaUrls->selectString($sQ);
02556         }
02557         return $this->_aMediaUrls;
02558     }
02559 
02565     public function getDynImageDir()
02566     {
02567         return $this->_sDynImageDir;
02568     }
02569 
02575     public function getDispSelList()
02576     {
02577         if ($this->_aDispSelList === null) {
02578             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02579                 $this->_aDispSelList = $this->getSelectLists();
02580             }
02581         }
02582         return $this->_aDispSelList;
02583     }
02584 
02590     public function getMoreDetailLink()
02591     {
02592         if ( $this->_sMoreDetailLink == null ) {
02593 
02594             // and assign special article values
02595             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02596 
02597             // not always it is okey, as not all the time active category is the same as primary article cat.
02598             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02599                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02600             }
02601             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02602             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02603         }
02604 
02605         return $this->_sMoreDetailLink;
02606     }
02607 
02613     public function getToBasketLink()
02614     {
02615         if ( $this->_sToBasketLink == null ) {
02616             $myConfig = $this->getConfig();
02617 
02618             if ( oxUtils::getInstance()->isSearchEngine() ) {
02619                 $this->_sToBasketLink = $this->getLink();
02620             } else {
02621                 // and assign special article values
02622                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02623 
02624                 // override some classes as these should never showup
02625                 $sActClass = oxConfig::getParameter( 'cl' );
02626                 if ( $sActClass == 'thankyou') {
02627                     $sActClass = 'basket';
02628                 }
02629                 $this->_sToBasketLink .= 'cl='.$sActClass;
02630 
02631                 // this is not very correct
02632                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02633                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02634                 }
02635 
02636                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02637 
02638                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02639                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02640                 }
02641             }
02642         }
02643 
02644         return $this->_sToBasketLink;
02645     }
02646 
02652     public function getStockStatus()
02653     {
02654         return $this->_iStockStatus;
02655     }
02656 
02662     public function getDeliveryDate()
02663     {
02664         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02665             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02666         }
02667         return false;
02668     }
02669 
02675     public function getFTPrice()
02676     {
02677         if ( $oPrice = $this->getTPrice() ) {
02678             if ( $oPrice->getBruttoPrice() ) {
02679                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02680             }
02681         }
02682     }
02683 
02689     public function getFPrice()
02690     {
02691         if ( $oPrice = $this->getPrice() ) {
02692             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02693         }
02694     }
02695 
02701     public function getPricePerUnit()
02702     {
02703         return $this->_fPricePerUnit;
02704     }
02705 
02711     public function isParentNotBuyable()
02712     {
02713         return $this->_blNotBuyableParent;
02714     }
02715 
02721     public function isNotBuyable()
02722     {
02723         return $this->_blNotBuyable;
02724     }
02725 
02733     public function setBuyableState( $blBuyable = false )
02734     {
02735         $this->_blNotBuyable = !$blBuyable;
02736     }
02737 
02746     public function getVariantList()
02747     {
02748         return $this->getVariants();
02749     }
02750 
02758     public function setSelectlist( $aSelList )
02759     {
02760         $this->_aDispSelList = $aSelList;
02761     }
02762 
02770     public function getPictureUrl( $iIndex = '' )
02771     {
02772         if ( $iIndex ) {
02773 
02774             if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02775                 $this->_generateImages( $iIndex );
02776             }
02777 
02778             $sPic = $iIndex . "/" . $this->_getPictureName( $iIndex );
02779 
02780             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02781         }
02782     }
02783 
02791     protected function _getPictureName( $iIndex = '' )
02792     {
02793         if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02794             $sPicName = basename($this->{"oxarticles__oxpic".$iIndex}->value);
02795         } else {
02796             $sPicName = "nopic.jpg";
02797         }
02798 
02799         return $sPicName;
02800     }
02801 
02810     public function getIconUrl( $iIndex = '')
02811     {
02812         if ( $this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02813 
02814             $iIconIndex = ( $iIndex ) ? $iIndex : 1;
02815             //generating new images if needed
02816             if ( !$this->_hasGeneratedImage( $iIconIndex ) ) {
02817                 $this->_generateImages( $iIconIndex );
02818             }
02819         }
02820 
02821         $sIconName = $this->_getIconName( $iIndex );
02822 
02823         if ( !$iIndex ) {
02824             $sPic = "icon/" . basename( $sIconName );
02825         } else {
02826             $sPic = $iIndex . "/" . basename( $sIconName );
02827         }
02828 
02829         return $this->getConfig()->getIconUrl( $sPic, $this->isAdmin() );
02830     }
02831 
02840     protected function _getIconName( $iIndex = '' )
02841     {
02842         $oPictureHandler = oxPictureHandler::getInstance();
02843         $sIconName = "nopic_ico.jpg";
02844 
02845         if ( !$iIndex ) {
02846             if ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02847                 $sIconName = basename( $this->oxarticles__oxicon->value );
02848             } elseif ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 )  && $this->oxarticles__oxpic1->value ) {
02849                 $sIconName = $oPictureHandler->getMainIconName( $this->oxarticles__oxpic1->value );
02850             }
02851         } else {
02852             if ( $this->_hasGeneratedImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02853                 $sIconName = $oPictureHandler->getIconName( $this->{"oxarticles__oxpic".$iIndex}->value );
02854             }
02855         }
02856 
02857         return $sIconName;
02858     }
02859 
02865     public function getThumbnailUrl()
02866     {
02867         if ( $this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02868             //generating new images if needed
02869             if ( !$this->_hasGeneratedImage( 1 ) ) {
02870                 $this->_generateImages( 1 );
02871             }
02872         }
02873 
02874         $sPic = "0/" . $this->_getThumbnailName();
02875 
02876         return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02877     }
02878 
02884     protected function _getThumbnailName()
02885     {
02886         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02887             $sThumbName = basename($this->oxarticles__oxthumb->value);
02888         } else {
02889             if ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 ) && $this->oxarticles__oxpic1->value ) {
02890                 $oPictureHandler = oxPictureHandler::getInstance();
02891                 $sThumbName = $oPictureHandler->getThumbName( $this->oxarticles__oxpic1->value );
02892             } else {
02893                 $sThumbName = "nopic.jpg";
02894             }
02895         }
02896 
02897         return $sThumbName;
02898     }
02899 
02907     public function getZoomPictureUrl( $iIndex = '' )
02908     {
02909         $iIndex = (int) $iIndex;
02910         if ( $iIndex > 0) {
02911             //generating new images if needed
02912             if ( $this->_isFieldEmpty( "oxarticles__oxzoom" . $iIndex ) ) {
02913                 //generating new images if needed
02914                 if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02915                     $this->_generateImages( $iIndex );
02916                 }
02917             }
02918 
02919             $sPic = "z{$iIndex}/" . $this->_getZoomPictureName( $iIndex );
02920 
02921             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02922         }
02923     }
02924 
02932     protected function _getZoomPictureName( $iIndex = '' )
02933     {
02934         $sZoomField = "oxarticles__oxzoom" . $iIndex;
02935 
02936         if ( !$this->_isFieldEmpty( $sZoomField ) ) {
02937             $sZoomName = basename( $this->$sZoomField->value );
02938         } else {
02939             if ( $this->_hasGeneratedImage( $iIndex ) && $this->_hasMasterImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02940                 $oPictureHandler = oxPictureHandler::getInstance();
02941                 $sZoomName = $oPictureHandler->getZoomName( $this->{"oxarticles__oxpic".$iIndex}->value, $iIndex );
02942             } else {
02943                 $sZoomName = "nopic.jpg";
02944             }
02945         }
02946 
02947         return $sZoomName;
02948     }
02949 
02955     public function getFileUrl()
02956     {
02957         return $this->getConfig()->getPictureUrl( '0/' );
02958     }
02959 
02965     public function getPriceFromPrefix()
02966     {
02967         $sPricePrefics = '';
02968         if ( $this->_blIsRangePrice) {
02969             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02970         }
02971 
02972         return $sPricePrefics;
02973     }
02974 
02983     protected function _saveArtLongDesc($iLang, $sValue)
02984     {
02985         $oDB = oxDb::getDb();
02986         $iLang = (int) $iLang;
02987         $sLangField = ($iLang > '0') ? '_'.$iLang : '';
02988         $sLongDesc = $oDB->quote($sValue);
02989         $sLongDescSQL = "insert into oxartextends (oxartextends.OXID, oxartextends.OXLONGDESC{$sLangField})
02990                        VALUES ('".$this->getId()."', {$sLongDesc})
02991                        ON DUPLICATE KEY update oxartextends.OXLONGDESC{$sLangField} = {$sLongDesc} ";
02992 
02993         $oDB->execute($sLongDescSQL);
02994     }
02995 
03001     protected function _skipSaveFields()
03002     {
03003         $myConfig = $this->getConfig();
03004 
03005         $this->_aSkipSaveFields = array();
03006 
03007         $this->_aSkipSaveFields[] = 'oxtimestamp';
03008         $this->_aSkipSaveFields[] = 'oxlongdesc';
03009         $this->_aSkipSaveFields[] = 'oxinsert';
03010 
03011         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
03012             $this->_aSkipSaveFields[] = 'oxparentid';
03013         }
03014 
03015     }
03016 
03026     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03027     {
03028         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03029             // add prices of the same discounts
03030             if ( array_key_exists ($sKey, $aDiscounts) ) {
03031                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03032             } else {
03033                 $aDiscounts[$sKey] = $oDiscount;
03034             }
03035         }
03036         return $aDiscounts;
03037     }
03038 
03044     protected function _getGroupPrice()
03045     {
03046         $dPrice = $this->oxarticles__oxprice->value;
03047 
03048         $oUser = $this->getArticleUser();
03049         if ( $oUser ) {
03050             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03051                 $dPrice = $this->oxarticles__oxpricea->value;
03052             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03053                 $dPrice = $this->oxarticles__oxpriceb->value;
03054             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03055                 $dPrice = $this->oxarticles__oxpricec->value;
03056             }
03057         }
03058 
03059         // #1437/1436C - added config option, and check for zero A,B,C price values
03060         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03061             $dPrice = $this->oxarticles__oxprice->value;
03062         }
03063 
03064         return $dPrice;
03065     }
03066 
03075     protected function _getAmountPrice($dAmount = 1)
03076     {
03077         $myConfig = $this->getConfig();
03078 
03079         startProfile( "_getAmountPrice" );
03080 
03081         $dPrice = $this->_getGroupPrice();
03082         $oAmtPrices = $this->_getAmountPriceList();
03083         foreach ($oAmtPrices as $oAmPrice) {
03084             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03085                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03086                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03087                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03088             }
03089         }
03090 
03091         stopProfile( "_getAmountPrice" );
03092         return $dPrice;
03093     }
03094 
03103     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03104     {
03105         $myConfig = $this->getConfig();
03106         // #690
03107         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03108 
03109             $aSelLists = $this->getSelectLists();
03110             foreach ( $aSelLists as $key => $aSel) {
03111                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03112                     $oSel = $aSel[$aChosenList[$key]];
03113                     if ( $oSel->priceUnit =='abs' ) {
03114                         $dPrice += $oSel->price;
03115                     } elseif ( $oSel->priceUnit =='%' ) {
03116                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03117                     }
03118                 }
03119             }
03120         }
03121         return $dPrice;
03122     }
03123 
03124 
03132     protected function _fillAmountPriceList($oAmPriceList)
03133     {
03134         $myConfig = $this->getConfig();
03135         $myUtils  = oxUtils::getInstance();
03136 
03137         //modifying price
03138         $oCur = $myConfig->getActShopCurrencyObject();
03139 
03140         $oUser = $this->getArticleUser();
03141 
03142         $oDiscountList = oxDiscountList::getInstance();
03143         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03144 
03145         $oLowestPrice = null;
03146 
03147         $dBasePrice = $this->_getGroupPrice();
03148         $oLang = oxLang::getInstance();
03149 
03150         $dArticleVat = null;
03151         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03152             $dArticleVat = $this->getArticleVat();
03153         }
03154 
03155         // trying to find lowest price value
03156         foreach ($oAmPriceList as $sId => $oItem) {
03157             $oItemPrice = oxNew( 'oxprice' );
03158             if ( $oItem->oxprice2article__oxaddabs->value) {
03159                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03160                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03161                 $this->_applyCurrency( $oItemPrice, $oCur );
03162             } else {
03163                 $oItemPrice->setPrice( $dBasePrice );
03164                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03165             }
03166 
03167             if (isset($dArticleVat)) {
03168                 $this->_applyVAT($oItemPrice, $dArticleVat);
03169             }
03170 
03171             if (!$oLowestPrice) {
03172                 $oLowestPrice = $oItemPrice;
03173             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03174                 $oLowestPrice = $oItemPrice;
03175             }
03176 
03177             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03178             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03179             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03180         }
03181 
03182         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03183         return $oAmPriceList;
03184     }
03185 
03191     protected function _getVariantsIds()
03192     {
03193         $aSelect = array();
03194         $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->getId()."' " );
03195         if ( $oRs != false && $oRs->recordCount() > 0 ) {
03196             while (!$oRs->EOF) {
03197                 $aSelect[] = $oRs->fields['oxid'];
03198                 $oRs->moveNext();
03199             }
03200         }
03201         return $aSelect;
03202     }
03203 
03209     public function getArticleVat()
03210     {
03211         if (!isset($this->_dArticleVat)) {
03212             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03213         }
03214         return $this->_dArticleVat;
03215     }
03216 
03225     protected function _applyVAT( oxPrice $oPrice, $dVat )
03226     {
03227         startProfile(__FUNCTION__);
03228         $oPrice->setVAT( $dVat );
03229         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03230             $oPrice->setUserVat( $dVat );
03231         }
03232         stopProfile(__FUNCTION__);
03233     }
03234 
03242     public function applyVats( oxPrice $oPrice )
03243     {
03244         $this->_applyVAT($oPrice, $this->getArticleVat() );
03245     }
03246 
03257     protected function _applyDiscounts( $oPrice, $aDiscounts )
03258     {
03259         $oDiscountList = oxDiscountList::getInstance();
03260         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03261     }
03262 
03270     public function applyDiscountsForVariant( $oPrice )
03271     {
03272         // apply discounts
03273         if ( !$this->skipDiscounts() ) {
03274             $oDiscountList = oxDiscountList::getInstance();
03275             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03276         }
03277     }
03278 
03287     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03288     {
03289         if ( !$oCur ) {
03290             $oCur = $this->getConfig()->getActShopCurrencyObject();
03291         }
03292 
03293         $oPrice->multiply($oCur->rate);
03294     }
03295 
03296 
03305     protected function _getAttribsString(&$sAttribs, &$iCnt)
03306     {
03307         // we do not use lists here as we dont need this overhead right now
03308         $oDB = oxDb::getDb(true);
03309         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03310         $sAttribs = '';
03311         $blSep = false;
03312         $rs = $oDB->execute( $sSelect);
03313         $iCnt = 0;
03314         if ($rs != false && $rs->recordCount() > 0) {
03315             while (!$rs->EOF) {
03316                 if ( $blSep) {
03317                     $sAttribs .= ' or ';
03318                 }
03319                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03320                 $blSep = true;
03321                 $iCnt++;
03322                 $rs->moveNext();
03323             }
03324         }
03325     }
03326 
03335     protected function _getSimList($sAttribs, $iCnt)
03336     {
03337         $myConfig = $this->getConfig();
03338         $oDB      = oxDb::getDb(true);
03339 
03340         // #523A
03341         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03342         // 70% same attributes
03343         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03344             $iAttrPercent = 0.70;
03345         }
03346         // #1137V iAttributesPercent = 100 doesnt work
03347         $iHitMin = ceil( $iCnt * $iAttrPercent );
03348 
03349         // we do not use lists here as we dont need this overhead right now
03350         $aList= array();
03351         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03352                     ( $sAttribs )
03353                     and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03354                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03355 
03356         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03357         if ($rs != false && $rs->recordCount() > 0) {
03358             while (!$rs->EOF) {
03359                 $oTemp = new stdClass();    // #663
03360                 $oTemp->cnt = $rs->fields['cnt'];
03361                 $oTemp->id  = $rs->fields['oxobjectid'];
03362                 $aList[] = $oTemp;
03363                 $rs->moveNext();
03364             }
03365         }
03366         return $aList;
03367     }
03368 
03377     protected function _generateSimListSearchStr($sArticleTable, $aList)
03378     {
03379         $myConfig = $this->getConfig();
03380         $sFieldList = $this->getSelectFields();
03381         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03382         $blSep = false;
03383         $iCnt = 0;
03384         $oDb = oxDb::getDb();
03385         foreach ( $aList as $oTemp) {
03386             if ( $blSep) {
03387                 $sSearch .= ',';
03388             }
03389             $sSearch .= $oDb->quote($oTemp->id);
03390             $blSep = true;
03391             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03392                 break;
03393             }
03394             $iCnt++;
03395         }
03396 
03397         //#1741T
03398         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03399         $sSearch .= ') ';
03400 
03401         // #524A -- randomizing articles in attribute list
03402         $sSearch .= ' order by rand() ';
03403 
03404         return $sSearch;
03405     }
03406 
03415     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03416     {
03417         $sCatView = getViewName( 'oxcategories' );
03418         $sO2CView = getViewName( 'oxobject2category' );
03419 
03420         // we do not use lists here as we dont need this overhead right now
03421         if ( !$blSearchPriceCat ) {
03422             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03423                          {$sCatView}.oxid = oxobject2category.oxcatnid
03424                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03425         } else {
03426             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03427                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03428                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03429         }
03430         return $sSelect;
03431     }
03432 
03438     protected function _generateSearchStrForCustomerBought()
03439     {
03440         $sArtTable = $this->_getObjectViewName( 'oxarticles' );
03441         $sOrderArtTable = getViewName( 'oxorderarticles' );
03442 
03443         // fetching filter params
03444         $sIn = " '{$this->oxarticles__oxid->value}' ";
03445         if ( $this->oxarticles__oxparentid->value ) {
03446 
03447             // adding article parent
03448             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03449             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03450 
03451         } else {
03452             $sParentIdForVariants = $this->getId();
03453         }
03454 
03455         // adding variants
03456         $oDb = oxDb::getDb(true);
03457         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03458         if ( $oRs != false && $oRs->recordCount() > 0) {
03459             while ( !$oRs->EOF ) {
03460                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03461                 $oRs->moveNext();
03462             }
03463         }
03464 
03465         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03466         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03467 
03468         // building sql (optimized)
03469         $sQ = "select distinct {$sArtTable}.* from (
03470                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03471                ) as suborder
03472                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03473                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03474                where {$sArtTable}.oxid not in ( {$sIn} )
03475                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03476 
03477         /* non optimized, but could be used if index forcing is not supported
03478         // building sql
03479         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03480                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03481                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03482                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03483                and ".$this->getSqlActiveSnippet();
03484         */
03485 
03486         return $sQ;
03487     }
03488 
03498     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03499     {
03500         $sCategoryView = getViewName('oxcategories');
03501         $sO2CView = getViewName('oxobject2category');
03502         $sLangPrefix = (($this->getLanguage())?'_'.$this->getLanguage():'');
03503 
03504         $oDb    = oxDb::getDb();
03505         $sOXID  = $oDb->quote($sOXID);
03506         $sCatId = $oDb->quote($sCatId);
03507 
03508         if (!$dPriceFromTo) {
03509             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03510             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03511             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03512             $sSelect .= "and oxcategories.oxactive$sLangPrefix = 1 order by oxobject2category.oxtime ";
03513         } else {
03514             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03515             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03516             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03517             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03518         }
03519         return $sSelect;
03520     }
03521 
03527     protected function _getAmountPriceList()
03528     {
03529         if ($this->_oAmountPriceList) {
03530             return $this->_oAmountPriceList;
03531         }
03532 
03533         $myConfig = $this->getConfig();
03534 
03535         $sArtID  = $this->getId();
03536 
03537         // #1690C - Scale prices and variants
03538         if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03539             $sArtID = $this->oxarticles__oxparentid->value;
03540         }
03541 
03542         $sArtID = mysql_real_escape_string($sArtID);
03543 
03544         //collecting assigned to article amount-price list
03545         $oAmPriceList = oxNew( 'oxlist');
03546         $oAmPriceList->init('oxbase', 'oxprice2article');
03547 
03548         $sShopID = $myConfig->getShopID();
03549         if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03550             $sShopSelect = '1';
03551         } else {
03552             $sShopSelect = " oxshopid =  '$sShopID' ";
03553         }
03554 
03555         $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03556 
03557         // prepare abs prices if currently having percentages
03558         $oBasePrice = $this->_getGroupPrice();
03559         foreach ($oAmPriceList as $oAmPrice) {
03560             if ($oAmPrice->oxprice2article__oxaddperc->value) {
03561                 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03562             }
03563         }
03564 
03565         $this->_oAmountPriceList = $oAmPriceList;
03566         return $oAmPriceList;
03567     }
03568 
03576     protected function _isFieldEmpty($sFieldName)
03577     {
03578         $mValue = $this->$sFieldName->value;
03579 
03580         if (is_null($mValue)) {
03581             return true;
03582         }
03583 
03584         if ($mValue === '') {
03585             return true;
03586         }
03587 
03588         $aDoubleCopyFields = array('oxarticles__oxprice',
03589                                        'oxarticles__oxvat');
03590 
03591         if (!$mValue && in_array($sFieldName, $aDoubleCopyFields)) {
03592             return true;
03593         }
03594 
03595 
03596         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03597             return true;
03598         }
03599 
03600         $sFieldName = strtolower($sFieldName);
03601 
03602         if ( $sFieldName == 'oxarticles__oxicon' && strpos($mValue, "nopic_ico.jpg") !== false ) {
03603             return true;
03604         }
03605 
03606         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03607             return true;
03608         }
03609 
03610         return false;
03611     }
03612 
03620     protected function _assignParentFieldValue($sFieldName)
03621     {
03622         if (!($oParentArticle = $this->getParentArticle())) {
03623             return;
03624         }
03625 
03626         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03627 
03628         // assigning only theese which parent article has
03629         if ( $oParentArticle->$sCopyFieldName != null ) {
03630 
03631             // only overwrite database values
03632             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03633                 continue;
03634             }
03635 
03636             //do not copy certain fields
03637             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03638                 return;
03639             }
03640 
03641             //COPY THE VALUE
03642             // assigning images from parent only if variant has no master image (#1807)
03643             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03644                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03645                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03646                 }
03647             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03648                 // for zoom images checking master image with specified index
03649                 // assign from parent only if no pictures to variant are added
03650                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03651                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03652                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03653                 }
03654             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03655                 // if no pics generated for variants, load all from
03656                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03657             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03658                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03659             }
03660         }
03661     }
03662 
03668     public function getParentArticle()
03669     {
03670         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03671             if ( !isset( self::$_aLoadedParents[$sParentId] ) ) {
03672                 self::$_aLoadedParents[$sParentId] = oxNew( 'oxarticle' );
03673                 self::$_aLoadedParents[$sParentId]->_blSkipAbPrice  = true;
03674                 self::$_aLoadedParents[$sParentId]->_blLoadPrice    = false;
03675                 self::$_aLoadedParents[$sParentId]->_blLoadVariants = false;
03676                 self::$_aLoadedParents[$sParentId]->load( $sParentId );
03677             }
03678             return self::$_aLoadedParents[$sParentId];
03679         }
03680     }
03681 
03689     protected function _getParentAricle()
03690     {
03691         return $this->getParentArticle();
03692     }
03693 
03699     protected function _assignParentFieldValues()
03700     {   startProfile('articleAssignParentInternal');
03701         if ( $this->oxarticles__oxparentid->value) {
03702             // yes, we are in fact a variant
03703             if ( !$this->isAdmin() || ($this->_blLoadParentData && $this->isAdmin() ) ) {
03704                 foreach ($this->_aFieldNames as $sFieldName => $sVal) {
03705                     $this->_assignParentFieldValue($sFieldName);
03706                 }
03707 
03708                 //assing long description
03709                 $oParentArticle = $this->getParentArticle();
03710                 if ( !$this->oxarticles__oxlongdesc->value ) {
03711                     $this->oxarticles__oxlongdesc = $oParentArticle->oxarticles__oxlongdesc;
03712                 }
03713 
03714             }
03715         }
03716         stopProfile('articleAssignParentInternal');
03717 
03718     }
03719 
03725     protected function _assignNotBuyableParent()
03726     {
03727         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03728              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03729             $this->_blNotBuyableParent = true;
03730 
03731         }
03732     }
03733 
03739     protected function _assignAllPictureValues()
03740     {
03741         $myConfig = $this->getConfig();
03742 
03743         $this->_assignPictureValues( "oxarticles__oxicon" );
03744         $this->_assignPictureValues( "oxarticles__oxthumb" );
03745 
03746         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03747 
03748         for ( $i=1; $i<= $iPicCount; $i++ ) {
03749             $this->_assignPictureValues( "oxarticles__oxpic".$i );
03750         }
03751 
03752         if ( $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' ) ) {
03753             for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03754                 $this->_assignZoomPictureValues( "oxarticles__oxzoom".$i );
03755             }
03756         }
03757     }
03758 
03766     protected function _assignZoomPictureValues( $sName='' )
03767     {
03768         if ( $this->isAdmin() ) {
03769             return;
03770         }
03771 
03772         $sFieldName = substr_replace( $sName, "", 0, 12);
03773 
03774         $aAllFields = $this->_getAllFields( true );
03775 
03776         if ( isset( $aAllFields[$sFieldName] ) ) {
03777             $this->$sName = parent::__get( $sName );
03778             $this->$sName->value;
03779         }
03780 
03781         $this->_assignParentFieldValue( $sName );
03782 
03783         $iIndex = (int) str_ireplace( "oxzoom", "", $sFieldName );
03784 
03785         if ( isset($this->_aFieldNames[$sFieldName]) || isset($this->_aFieldNames["oxpic".$iIndex]) ) {
03786             if ( $iIndex > 0 ) {
03787                 $this->$sName = new oxField( 'z' . $iIndex.'/'.$this->_getZoomPictureName($iIndex) );
03788             }
03789         }
03790     }
03791 
03799     protected function _assignPictureValues( $sName='' )
03800     {
03801         if ( $this->isAdmin() || !$sName ) {
03802             return;
03803         }
03804 
03805         $sFieldName = substr_replace( $sName, "", 0, 12);
03806         $myConfig = $this->getConfig();
03807 
03808         // add directories
03809         if ( $sFieldName == 'oxicon' && isset($this->_aFieldNames["oxicon"]) ) {
03810             $this->oxarticles__oxicon = new oxField('icon/'.$this->_getIconName());
03811             return;
03812         }
03813 
03814         if ( $sFieldName == 'oxthumb' && isset($this->_aFieldNames["oxthumb"]) ) {
03815             $this->oxarticles__oxthumb = new oxField('0/'.$this->_getThumbnailName());
03816             return;
03817         }
03818 
03819         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03820         if ( strpos($sFieldName, "oxpic") === 0 && isset($this->_aFieldNames[$sFieldName] ) ) {
03821 
03822             $iIndex = (int) str_ireplace( "oxpic", "", $sFieldName );
03823 
03824             if ( $iIndex > 0 && $iIndex < $iPicCount ) {
03825                 $this->$sName = new oxField( $iIndex . '/'.$this->_getPictureName($iIndex) );
03826                 $this->{$sName.'_ico'} = new oxField( $iIndex . '/'.$this->_getIconName($iIndex) );
03827                 return;
03828             }
03829         }
03830     }
03831 
03837     protected function _assignStock()
03838     {
03839         $myConfig = $this->getConfig();
03840         // -----------------------------------
03841         // stock
03842         // -----------------------------------
03843 
03844         // #1125 A. must round (using floor()) value taken from database and cast to int
03845         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03846             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03847         }
03848         //GREEN light
03849         $this->_iStockStatus = 0;
03850 
03851         // if we have flag /*1 or*/ 4 - we show always green light
03852         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03853             //ORANGE light
03854             $iStock = $this->oxarticles__oxstock->value;
03855 
03856             if ($this->_blNotBuyableParent) {
03857                 $iStock = $this->oxarticles__oxvarstock->value;
03858             }
03859 
03860 
03861             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03862                 $this->_iStockStatus = 1;
03863             }
03864 
03865             //RED light
03866             if ($iStock <= 0) {
03867                 $this->_iStockStatus = -1;
03868             }
03869         }
03870 
03871 
03872         // stock
03873         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03874             $iOnStock = $this->oxarticles__oxstock->value;
03875             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03876                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03877             }
03878             if ($iOnStock <= 0) {
03879                 $this->_blNotBuyable = true;
03880             }
03881         }
03882 
03883         //exceptional handling for variant parent stock:
03884         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03885             $this->_blNotBuyable = false;
03886             //but then at least setting notBuaybleParent to true
03887             $this->_blNotBuyableParent = true;
03888         }
03889 
03890         //special treatment for lists when blVariantParentBuyable config option is set to false
03891         //then we just hide "to basket" button.
03892         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03893         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03894             $this->_blNotBuyable = true;
03895         }
03896 
03897         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03898         if ($this->_blNotBuyableParent && count($this->getVariants()) == 0) {
03899             $this->_blNotBuyable = true;
03900         }
03901     }
03902 
03908     protected function _assignPrices()
03909     {
03910         $myConfig = $this->getConfig();
03911 
03912         // Performance
03913         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03914             return;
03915         }
03916 
03917         // compute price
03918         $dPrice = $this->getPrice()->getBruttoPrice();
03919 
03920         $oCur = $myConfig->getActShopCurrencyObject();
03921         //price per unit handling
03922         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03923             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03924         }
03925 
03926 
03927         //getting min and max prices of variants
03928         $this->_applyRangePrice();
03929     }
03930 
03936     protected function _assignPersistentParam()
03937     {
03938         // Persistent Parameter Handling
03939         $aPersParam     = oxSession::getVar( 'persparam');
03940         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03941             $this->_aPersistParam = $aPersParam[$this->getId()];
03942         }
03943     }
03944 
03950     protected function _assignDynImageDir()
03951     {
03952         $myConfig = $this->getConfig();
03953 
03954         $sThisShop = $this->oxarticles__oxshopid->value;
03955 
03956         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03957         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03958         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03959         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03960     }
03961 
03967     protected function _assignComparisonListFlag()
03968     {
03969         // #657 add a flag if article is on comparisonlist
03970 
03971         $aItems = oxConfig::getParameter('aFiltcompproducts');
03972         if ( isset( $aItems[$this->getId()])) {
03973             $this->_blIsOnComparisonList = true;
03974         }
03975     }
03976 
03982     protected function _assignAttributes()
03983     {
03984         //#1029T load attributes
03985         //#1078S removed check for module "Produktvergleich"
03986         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03987             $this->getAttributes();
03988         }
03989     }
03990 
03991 
03999     protected function _insert()
04000     {
04001         // set oxinsert
04002         $iInsertTime = time();
04003         $now = date('Y-m-d H:i:s', $iInsertTime);
04004         $this->oxarticles__oxinsert    = new oxField( $now );
04005         $this->oxarticles__oxtimestamp = new oxField( $now );
04006         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
04007             $this->oxarticles__oxsubclass = new oxField('oxarticle');
04008         }
04009 
04010         return parent::_insert();
04011     }
04012 
04018     protected function _update()
04019     {
04020 
04021         $this->_skipSaveFields();
04022 
04023         $myConfig = $this->getConfig();
04024 
04025 
04026         return parent::_update();
04027     }
04028 
04036     protected function _deleteRecords($sOXID)
04037     {
04038         $oDB = oxDb::getDb();
04039 
04040         $sOXID = $oDB->quote($sOXID);
04041 
04042         //delete the record
04043         $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
04044         $oDB->execute( $sDelete);
04045 
04046         //remove other records
04047         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
04048         $oDB->execute( $sDelete);
04049 
04050         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
04051         $oDB->execute( $sDelete);
04052 
04053         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
04054         $oDB->execute( $sDelete);
04055 
04056         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
04057         $oDB->execute( $sDelete);
04058 
04059         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
04060         $oDB->execute( $sDelete);
04061 
04062         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
04063         $oDB->execute( $sDelete);
04064 
04065         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
04066         $oDB->execute( $sDelete);
04067 
04068         //#1508C - deleting oxobject2delivery entries added
04069         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04070         $oDB->execute( $sDelete);
04071 
04072         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04073         $oDB->execute( $sDelete);
04074 
04075         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04076         $rs = $oDB->execute( $sDelete );
04077 
04078         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04079         $rs = $oDB->execute( $sDelete );
04080 
04081 
04082         return $rs;
04083     }
04084 
04092     protected function _deleteVariantRecords($sOXID)
04093     {
04094         $oDB = oxDb::getDb();
04095         //collect variants to remove recursively
04096         $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDB->quote($sOXID);
04097         $rs = $oDB->execute( $sVariants);
04098         if ($rs != false && $rs->recordCount() > 0) {
04099             while (!$rs->EOF) {
04100                 $this->delete( $rs->fields[0]);
04101                 $rs->moveNext();
04102             }
04103         }
04104     }
04105 
04115     protected function _resetCacheAndArticleCount( $sOxid )
04116     {
04117         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04118     }
04119 
04125     protected function _deletePics()
04126     {
04127         $myUtilsPic = oxUtilsPic::getInstance();
04128         $myConfig   = $this->getConfig();
04129         $oPictureHandler = oxPictureHandler::getInstance();
04130 
04131         //deleting custom main icon
04132         $oPictureHandler->deleteMainIcon( $this );
04133 
04134         //deleting custom thumbnail
04135         $oPictureHandler->deleteThumbnail( $this );
04136 
04137         $sAbsDynImageDir = $myConfig->getAbsDynImageDir();
04138 
04139         // deleting master image and all generated images
04140         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04141         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04142             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04143         }
04144     }
04145 
04155     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04156     {
04157 
04158         $myUtilsCount = oxUtilsCount::getInstance();
04159 
04160         if ( $sVendorId ) {
04161             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04162         }
04163 
04164         if ( $sManufacturerId ) {
04165             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04166         }
04167 
04168         //also reseting category counts
04169         $oDb = oxDb::getDb();
04170         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04171         $oRs = $oDb->execute( $sQ );
04172         if ( $oRs !== false && $oRs->recordCount() > 0) {
04173             while ( !$oRs->EOF ) {
04174                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04175                 $oRs->moveNext();
04176             }
04177         }
04178     }
04179 
04187     protected function _onChangeUpdateStock( $sParentID )
04188     {
04189         $oDb = oxDb::getDb();
04190         $sParentIdQuoted = $oDb->quote($sParentID);
04191         $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04192         $rs = $oDb->execute($sQ);
04193         $iOldStock = $rs->fields[0];
04194         $iVendorID = $rs->fields[1];
04195         $iManufacturerID = $rs->fields[2];
04196 
04197         $sQ = 'select sum(oxstock) from oxarticles where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04198         $iStock = (float) $oDb->getOne( $sQ );
04199 
04200         $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04201         $oDb->execute( $sQ );
04202 
04203             //now lets update category counts
04204             //first detect stock status change for this article (to or from 0)
04205             if ( $iStock < 0 ) {
04206                 $iStock = 0;
04207             }
04208             if ( $iOldStock < 0 ) {
04209                 $iOldStock = 0;
04210             }
04211             if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04212                 //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04213                 // so far we leave it like this but later we could move all count resets to one or two functions
04214                 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04215             }
04216     }
04217 
04225     protected function _onChangeStockResetCount( $sOxid )
04226     {
04227         $myConfig = $this->getConfig();
04228 
04229         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04230            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04231 
04232                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04233         }
04234     }
04235 
04243     protected function _onChangeUpdateVarCount( $sParentID )
04244     {
04245         $oDb = oxDb::getDb();
04246         $sParentIdQuoted = $oDb->quote($sParentID);
04247         $sQ = 'select count(*) as varcount from oxarticles where oxparentid = '.$sParentIdQuoted;
04248         $iVarCount = (int) $oDb->getOne($sQ);
04249 
04250         $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = '.$sParentIdQuoted;
04251         $oDb->execute($sQ);
04252     }
04253 
04261     protected function _onChangeUpdateMinVarPrice( $sParentID )
04262     {
04263         $oDb = oxDb::getDb();
04264         $sParentIdQuoted = $oDb->quote($sParentID);
04265         //#M0000883 (Sarunas)
04266         $sQ = 'select min(oxprice) as varminprice from oxarticles where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04267         $dVarMinPrice = $oDb->getOne($sQ);
04268 
04269         $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04270 
04271         $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04272 
04273         if ($dVarMinPrice) {
04274             if ($blParentBuyable) {
04275                 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04276             }
04277 
04278         } else {
04279             $dVarMinPrice = $dParentPrice;
04280         }
04281 
04282         if ( $dVarMinPrice ) {
04283             $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04284             $oDb->execute($sQ);
04285         }
04286     }
04287 
04288 
04294     protected function _applyRangePrice()
04295     {
04296         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04297         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04298             return;
04299         }
04300 
04301         $this->_blIsRangePrice = false;
04302 
04303         // if parent is buyable - do not apply range price calcculations
04304         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04305             return;
04306         }
04307 
04308         $aPrices = array();
04309 
04310         if (!$this->_blNotBuyableParent) {
04311             $aPrices[] = $this->getPrice()->getBruttoPrice();
04312         }
04313 
04314         $aVariants = $this->getVariants(false);
04315 
04316         if (count($aVariants)) {
04317             foreach ($aVariants as $sKey => $oVariant) {
04318                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04319             }
04320         }
04321 
04322         /*  $oAmPrices = $this->loadAmountPriceInfo();
04323         foreach ($oAmPrices as $oAmPrice) {
04324             $aPrices[] = $oAmPrice->oxprice2article__oxaddabs->value;
04325         }*/
04326 
04327         if (count($aPrices)) {
04328             $dMinPrice = $aPrices[0];
04329             $dMaxPrice = $aPrices[0];
04330             foreach ($aPrices as $dPrice) {
04331                 if ($dMinPrice > $dPrice) {
04332                     $dMinPrice = $dPrice;
04333                 }
04334 
04335                 if ($dMaxPrice < $dPrice) {
04336                     $dMaxPrice = $dPrice;
04337                 }
04338             }
04339         }
04340 
04341         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04342             $this->getPrice()->setBruttoPriceMode();
04343             $this->getPrice()->setPrice($dMinPrice);
04344         }
04345 
04346         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04347             $this->getPrice()->setBruttoPriceMode();
04348             $this->getPrice()->setPrice($dMinPrice);
04349             $this->_blIsRangePrice = true;
04350         }
04351 
04352         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04353             $this->getPrice()->setBruttoPriceMode();
04354             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04355             $this->_blIsRangePrice = true;
04356             $this->_calculatePrice( $this->getPrice() );
04357         }
04358     }
04359 
04366     public function getProductId()
04367     {
04368         return $this->getId();
04369     }
04370 
04376     public function getProductParentId()
04377     {
04378         return $this->oxarticles__oxparentid->value;
04379     }
04380 
04386     public function isOrderArticle()
04387     {
04388         return false;
04389     }
04390 
04396     public function isVariant()
04397     {
04398         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04399     }
04400 
04406     public function isMdVariant()
04407     {
04408         $oMdVariant = oxNew( "oxVariantHandler" );
04409 
04410         return $oMdVariant->isMdVariant($this);
04411     }
04412 
04420     public function getSqlForPriceCategories($sFields = '')
04421     {
04422         if (!$sFields) {
04423             $sFields = 'oxid';
04424         }
04425         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04426         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04427         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04428                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04429                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04430     }
04431 
04439     public function inPriceCategory( $sCatNid )
04440     {
04441         $oDb = oxDb::getDb();
04442 
04443         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04444         $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04445         return (bool) $oDb->getOne(
04446             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04447            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04448            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04449            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04450            .")"
04451         );
04452     }
04453 
04459     public function getMdVariants()
04460     {
04461         if ( $this->_oMdVariants ) {
04462             return $this->_oMdVariants;
04463         }
04464 
04465         $oParentArticle = $this->getParentArticle();
04466         if ( $oParentArticle ) {
04467             $oVariants = $oParentArticle->getVariants();
04468         } else {
04469             $oVariants = $this->getVariants();
04470         }
04471 
04472         $oVariantHandler = oxNew( "oxVariantHandler" );
04473         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04474 
04475         return $this->_oMdVariants;
04476     }
04477 
04483     public function getMdSubvariants()
04484     {
04485         return $this->getMdVariants()->getMdSubvariants();
04486     }
04487 
04488 
04497     protected function _generateImages( $iIndex )
04498     {
04499         if ( isset($this->_aFieldNames["oxpic".$iIndex]) && !$this->_hasGeneratedImage( $iIndex ) ) {
04500             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) && $this->_hasMasterImage( $iIndex ) ) {
04501                 $oPictureHandler = oxPictureHandler::getInstance();
04502                 $oPictureHandler->generateArticlePictures( $this, $iIndex );
04503             }
04504         }
04505     }
04506 
04515     public function updateAmountOfGeneratedPictures( $iTotalGenerated )
04516     {
04517         $this->oxarticles__oxpicsgenerated = new oxField( $iTotalGenerated );
04518         $oDb = oxDb::getDb();
04519         $sIdQuoted = $oDb->quote($this->getId());
04520 
04521         $sQ = 'update oxarticles set oxpicsgenerated = '.$iTotalGenerated.' where oxid = '.$sIdQuoted;
04522         $oDb->execute( $sQ );
04523     }
04524 
04533     protected function _hasGeneratedImage( $iIndex )
04534     {
04535         if ( $iIndex > (int) $this->oxarticles__oxpicsgenerated->value ) {
04536             return false;
04537         }
04538 
04539         return true;
04540     }
04541 
04549     protected function _hasMasterImage( $iIndex )
04550     {
04551         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04552 
04553         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04554             return false;
04555         }
04556         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04557             return false;
04558         }
04559 
04560         $sMasterPic = $iIndex . "/" . $sPicName;
04561 
04562         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04563             return true;
04564         }
04565 
04566         return false;
04567     }
04568 
04577     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04578     {
04579         if ( $sFieldName ) {
04580             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04581             return $this->$sFieldName->value;
04582         }
04583     }
04584 }