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         // #2339 delete first variants before deleting parent product
01842         $this->_deleteVariantRecords( $sOXID );
01843         $this->load( $sOXID );
01844         $this->_deletePics();
01845         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01846 
01847         $rs = $this->_deleteRecords( $sOXID );
01848 
01849         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01850 
01851         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01852 
01853         return $rs->EOF;
01854     }
01855 
01864     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01865     {
01866         $this->beforeUpdate();
01867 
01868         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01869         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01870             $dAmount += $iStockCount;
01871             $iStockCount = 0;
01872         }
01873         $this->oxarticles__oxstock = new oxField($iStockCount);
01874 
01875         $oDb = oxDb::getDb();
01876         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01877         $this->onChange( ACTION_UPDATE_STOCK );
01878         return $dAmount;
01879     }
01880 
01889     public function updateSoldAmount( $dAmount = 0 )
01890     {
01891         if ( !$dAmount ) {
01892             return;
01893         }
01894 
01895         $this->beforeUpdate();
01896 
01897         // article is not variant - should be updated current amount
01898         if ( !$this->oxarticles__oxparentid->value ) {
01899             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01900             $dAmount = (double) $dAmount;
01901             $oDb = oxDb::getDb();
01902             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01903         } elseif ( $this->oxarticles__oxparentid->value) {
01904             // article is variant - should be updated this article parent amount
01905             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01906             $oUpdateArticle->updateSoldAmount( $dAmount );
01907         }
01908 
01909         $this->onChange( ACTION_UPDATE );
01910 
01911         return $rs;
01912     }
01913 
01919     public function disableReminder()
01920     {
01921         $oDB = oxDb::getDb(true);
01922         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01923     }
01924 
01931     public function save()
01932     {
01933         $myConfig = $this->getConfig();
01934 
01935         $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01936         $this->oxarticles__oxicon  = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01937         $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01938         for ($i=1; $i <= $iPicCount; $i++) {
01939             if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01940                 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01941             }
01942         }
01943 
01944         $blRet = parent::save();
01945 
01946         // save article long description
01947         $this->setArticleLongDesc();
01948 
01949         // load article images after save
01950         $this->_assignAllPictureValues();
01951 
01952         return $blRet;
01953     }
01954 
01955 
01962     public function getPictureGallery()
01963     {
01964         $myConfig = $this->getConfig();
01965 
01966         //initialize
01967         $blMorePic = false;
01968         $aArtPics  = array();
01969         $aArtIcons = array();
01970         $iActPicId = 1;
01971         $sActPic = $this->getPictureUrl( $iActPicId );
01972 
01973         if ( oxConfig::getParameter( 'actpicid' ) ) {
01974             $iActPicId = oxConfig::getParameter('actpicid');
01975         }
01976 
01977         $oStr = getStr();
01978         $iCntr = 0;
01979         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01980         $blCheckActivePicId = true;
01981 
01982         for ( $i = 1; $i <= $iPicCount; $i++) {
01983             $sPicVal = $this->getPictureUrl( $i );
01984             $sIcoVal = $this->getIconUrl( $i );
01985             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') ) {
01986                 if ($iCntr) {
01987                     $blMorePic = true;
01988                 }
01989                 $aArtIcons[$i]= $sIcoVal;
01990                 $aArtPics[$i]= $sPicVal;
01991                 $iCntr++;
01992 
01993                 if ($iActPicId == $i) {
01994                     $sActPic = $sPicVal;
01995                     $blCheckActivePicId = false;
01996                 }
01997 
01998             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
01999                 // if picture is empty, setting active pic id to next
02000                 // picture
02001                 $iActPicId++;
02002             }
02003         }
02004 
02005         $blZoomPic  = false;
02006         $aZoomPics = array();
02007         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02008 
02009         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02010             $sVal = $this->getZoomPictureUrl($j);
02011 
02012             if ( !$oStr->strstr($sVal, 'nopic.jpg')) {
02013                 if ($this->getConfig()->getConfigParam('blFormerTplSupport')) {
02014                     $sVal = $this->_sDynImageDir."/".$sVal;
02015                 }
02016                 $blZoomPic = true;
02017                 $aZoomPics[$c]['id'] = $c;
02018                 $aZoomPics[$c]['file'] = $sVal;
02019                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02020                 if (!$sVal) {
02021                     $aZoomPics[$c]['file'] = "nopic.jpg";
02022                 }
02023                 $c++;
02024             }
02025         }
02026 
02027         $aPicGallery = array('ActPicID' => $iActPicId,
02028                              'ActPic' => $sActPic,
02029                              'MorePics' => $blMorePic,
02030                              'Pics' => $aArtPics,
02031                              'Icons' => $aArtIcons,
02032                              'ZoomPic' => $blZoomPic,
02033                              'ZoomPics' => $aZoomPics);
02034 
02035         return $aPicGallery;
02036     }
02037 
02051     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02052     {
02053         $myConfig = $this->getConfig();
02054 
02055         if (!isset($sOXID)) {
02056             if ( $this->getId()) {
02057                 $sOXID = $this->getId();
02058             }
02059             if (!isset ($sOXID)) {
02060                 $sOXID = $this->oxarticles__oxid->value;
02061             }
02062             if ($this->oxarticles__oxparentid->value) {
02063                 $sParentID = $this->oxarticles__oxparentid->value;
02064             }
02065         }
02066         if (!isset($sOXID)) {
02067             return;
02068         }
02069 
02070         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02071         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02072             //if article has variants then updating oxvarstock field
02073             //getting parent id
02074             if (!isset($sParentID)) {
02075                 $oDb = oxDb::getDb();
02076                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02077                 $sParentID = $oDb->getOne($sQ);
02078             }
02079             //if we have parent id then update stock
02080             if ($sParentID) {
02081                 $this->_onChangeUpdateStock($sParentID);
02082             }
02083         }
02084         //if we have parent id then update count
02085         //update count even if blUseStock is not active
02086         if ($sParentID) {
02087             $this->_onChangeUpdateVarCount($sParentID);
02088         }
02089 
02090         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02091         $this->_onChangeUpdateMinVarPrice( $sId );
02092 
02093             // reseting articles count cache if stock has changed and some
02094             // articles goes offline (M:1448)
02095             if ( $sAction === ACTION_UPDATE_STOCK ) {
02096                 $this->_onChangeStockResetCount( $sOXID );
02097             }
02098 
02099     }
02100 
02107     public function getCustomVAT()
02108     {
02109         if ( isset($this->oxarticles__oxvat->value) ) {
02110             return $this->oxarticles__oxvat->value;
02111         }
02112     }
02113 
02122     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02123     {
02124         $myConfig = $this->getConfig();
02125         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02126             return true;
02127         }
02128 
02129         // fetching DB info as its up-to-date
02130         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02131         $rs = oxDb::getDb(true)->Execute( $sQ );
02132 
02133         $iOnStock   = 0;
02134         $iStockFlag = 0;
02135         if ( $rs !== false && $rs->recordCount() > 0 ) {
02136             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02137             $iStockFlag = $rs->fields['oxstockflag'];
02138 
02139             // dodger : fremdlager is also always considered as on stock
02140             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02141                 return true;
02142             }
02143             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02144                 $iOnStock = floor( $iOnStock );
02145             }
02146         }
02147         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02148             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02149         }
02150         if ( $iOnStock >= $dAmount ) {
02151             return true;
02152         } else {
02153             if ( $iOnStock > 0 ) {
02154                 return $iOnStock;
02155             } else {
02156                 $oEx = oxNew( 'oxArticleInputException' );
02157                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02158                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02159                 return false;
02160             }
02161         }
02162     }
02163 
02164 
02172     public function getArticleLongDesc($sOXID = null)
02173     {
02174 
02175         if ( !$sOXID ) {
02176             $sOXID = $this->oxarticles__oxid->value;
02177         }
02178 
02179         if ($sOXID == $this->oxarticles__oxid->value) {
02180             if (isset($this->oxarticles__oxlongdesc) && ($this->oxarticles__oxlongdesc instanceof oxField) && $this->oxarticles__oxlongdesc->value) {
02181                 return $this->oxarticles__oxlongdesc;
02182             }
02183         }
02184 
02185         $myConfig = $this->getConfig();
02186 
02187         if ( $sOXID ) {
02188             $sLangField = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02189             $oDb = oxDb::getDb();
02190             $this->_setLongDesc($oDb->getOne( "select oxlongdesc{$sLangField} from oxartextends where oxid = ".$oDb->quote($sOXID) ));
02191         } else {
02192             // TODO: check if keeping fldname is needed in non-admin mode
02193             $this->oxarticles__oxlongdesc = new oxField();
02194             $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02195             $this->oxarticles__oxlongdesc->table   = 'oxarticles';
02196             $this->oxarticles__oxlongdesc->fldtype = 'text';
02197         }
02198 
02199         return $this->oxarticles__oxlongdesc;
02200     }
02201 
02209     protected function _setLongDesc($sDbValue)
02210     {
02211         // TODO: the code below is redundant, optimize it, assignments should go smooth without conversions
02212         // hack, if editor screws up text, htmledit tends to do so
02213         $sDbValue = str_replace( '&amp;nbsp;', '&nbsp;', $sDbValue );
02214         $sDbValue = str_replace( '&amp;', '&', $sDbValue );
02215         $sDbValue = str_replace( '&quot;', '"', $sDbValue );
02216         $sDbValue = str_replace( '&lang=', '&amp;lang=', $sDbValue);
02217         //
02218 
02219         $oStr = getStr();
02220         $blHasSmarty = $oStr->strstr( $sDbValue, '[{' );
02221         $blHasPhp = $oStr->strstr( $sDbValue, '<?' );
02222         $myConfig = oxConfig::getInstance();
02223         if ( ( $blHasSmarty || $blHasPhp ) && ($myConfig->getConfigParam( 'blExport' ) || !$this->isAdmin() ) && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
02224             $sDbValue = oxUtilsView::getInstance()->parseThroughSmarty( $sDbValue, $this->getId() );
02225         }
02226         $this->oxarticles__oxlongdesc = new oxField($sDbValue, oxField::T_RAW);
02227         // TODO: check if keeping fldname is needed in non-admin mode
02228         $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02229         $this->oxarticles__oxlongdesc->table   = 'oxarticles';
02230         $this->oxarticles__oxlongdesc->fldtype = 'text';
02231     }
02232 
02238     public function setArticleLongDesc()
02239     {
02240 
02241         if ( $this->_blEmployMultilanguage ) {
02242             // update or insert article long description
02243             if ($this->oxarticles__oxlongdesc instanceof oxField) {
02244                 $sLongDesc = $this->oxarticles__oxlongdesc->getRawValue();
02245             } else {
02246                 $sLongDesc = $this->oxarticles__oxlongdesc->value;
02247             }
02248             $this->_saveArtLongDesc($this->getLanguage(), $sLongDesc);
02249         } else {
02250             $oArtExt = oxNew('oxi18n');
02251             $oArtExt->init('oxartextends');
02252             $aObjFields = $oArtExt->_getAllFields(true);
02253             foreach ($aObjFields as $sKey => $sValue ) {
02254                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02255                     $sField = $this->_getFieldLongName($sKey);
02256                     if (isset($this->$sField)) {
02257                         $iLang = $oArtExt->_getFieldLang($sKey);
02258                         $sLongDesc = null;
02259                         if ($this->$sField instanceof oxField) {
02260                             $sLongDesc = $this->$sField->getRawValue();
02261                         } elseif (is_object($this->$sField)) {
02262                             $sLongDesc = $this->$sField->value;
02263                         }
02264                         if (isset($sLongDesc)) {
02265                             $this->_saveArtLongDesc($iLang, $sLongDesc);
02266                         }
02267                     }
02268                 }
02269             }
02270         }
02271     }
02272 
02278     public function getAttributes()
02279     {
02280         if ( $this->_oAttributeList === null ) {
02281             $this->_oAttributeList = oxNew( 'oxattributelist' );
02282             $this->_oAttributeList->loadAttributes( $this->getId() );
02283         }
02284 
02285         return $this->_oAttributeList;
02286     }
02287 
02296     public function appendLink( $sAddParams, $iLang = null )
02297     {
02298         if ( $sAddParams ) {
02299             if ( $iLang === null ) {
02300                 $iLang = $this->getLanguage();
02301             }
02302 
02303             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02304             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02305         }
02306     }
02307 
02316     public function getBaseSeoLink( $iLang, $blMain = false )
02317     {
02318         $oEncoder = oxSeoEncoderArticle::getInstance();
02319         if ( !$blMain ) {
02320             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02321         }
02322         return $oEncoder->getArticleMainUrl( $this, $iLang );
02323     }
02324 
02333     public function getLink( $iLang = null, $blMain = false  )
02334     {
02335         if ( !oxUtils::getInstance()->seoIsActive() ) {
02336             return $this->getStdLink( $iLang );
02337         }
02338 
02339         if ( $iLang === null ) {
02340             $iLang = $this->getLanguage();
02341         }
02342 
02343         $iLinkType = $this->getLinkType();
02344         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02345             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02346         }
02347 
02348         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02349         if ( isset($this->_aSeoAddParams[$iLang])) {
02350             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02351         }
02352 
02353         return $sUrl;
02354     }
02355 
02364     public function getMainLink( $iLang = null )
02365     {
02366         return $this->getLink( $iLang, true );
02367     }
02368 
02376     public function setLinkType( $iType )
02377     {
02378         // resetting detaisl link, to force new
02379         $this->_sDetailLink = null;
02380 
02381         // setting link type
02382         $this->_iLinkType = (int) $iType;
02383     }
02384 
02390     public function getLinkType()
02391     {
02392         return $this->_iLinkType;
02393     }
02394 
02403     public function appendStdLink( $sAddParams, $iLang = null )
02404     {
02405         if ( $sAddParams ) {
02406             if ( $iLang === null ) {
02407                 $iLang = $this->getLanguage();
02408             }
02409 
02410             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02411             $this->_aStdAddParams[$iLang] .= $sAddParams;
02412         }
02413     }
02414 
02424     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02425     {
02426         $sUrl = '';
02427         if ( $blFull ) {
02428             //always returns shop url, not admin
02429             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02430         }
02431 
02432         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02433         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02434     }
02435 
02444     public function getStdLink( $iLang = null, $aParams = array() )
02445     {
02446         if ( $iLang === null ) {
02447             $iLang = $this->getLanguage();
02448         }
02449 
02450         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02451             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02452         }
02453 
02454         return oxUtilsUrl::getInstance()->processStdUrl( $this->_aStdUrls[$iLang], $aParams, $iLang, $iLang != $this->getLanguage() );
02455     }
02456 
02464     public function getStdTagLink( $sTag )
02465     {
02466         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02467         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02468     }
02469 
02475     public function getTags()
02476     {
02477         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02478         $sQ = "select $sTagField from oxartextends where oxid = '".$this->getId()."'";
02479         $sTags = oxDb::getDb(true)->getOne($sQ);
02480         $oTagCloud = oxNew('oxtagcloud');
02481         $sTags = $oTagCloud->trimTags($sTags);
02482         return $sTags;
02483     }
02484 
02492     public function saveTags($sTags)
02493     {
02494         //do not allow derived update
02495         if ( !$this->allowDerivedUpdate() ) {
02496             return false;
02497         }
02498 
02499 
02500         $oTagCloud = oxNew('oxtagcloud');
02501         $oTagCloud->resetTagCache();
02502         $sTags = $oTagCloud->prepareTags($sTags);
02503 
02504         $sTags = mysql_real_escape_string($sTags);
02505 
02506         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02507         $sQ = "update oxartextends set $sTagField = '$sTags'  where oxid = '".$this->getId()."'";
02508         return oxDb::getDb()->execute($sQ);
02509     }
02510 
02518     public function addTag($sTag)
02519     {
02520         $oDb = oxDb::getDb();
02521 
02522         $oTagCloud = oxNew('oxtagcloud');
02523         $oTagCloud->resetTagCache();
02524         $sTag = $oTagCloud->prepareTags($sTag);
02525         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02526 
02527         $sField = "oxartextends.OXTAGS" . oxLang::getInstance()->getLanguageTag();
02528 
02529         if ( $oDb->getOne( "select $sField from oxartextends where oxartextends.OXID = '{$this->getId()}'" ) ) {
02530             $sTailTag = $sTagSeparator . $sTag;
02531         } else {
02532             $sTailTag = $sTag;
02533         }
02534 
02535         $sTag = mysql_real_escape_string($sTag);
02536         $sTailTag = mysql_real_escape_string($sTailTag);
02537 
02538         $sQ = "insert into oxartextends (oxartextends.OXID, $sField) values ('".$this->getId()."', '{$sTag}')
02539                        ON DUPLICATE KEY update $sField = CONCAT(TRIM($sField), '$sTailTag') ";
02540 
02541         return $oDb->Execute($sQ);
02542     }
02543 
02549     public function getMediaUrls()
02550     {
02551         if ( $this->_aMediaUrls === null ) {
02552             $this->_aMediaUrls = oxNew("oxlist");
02553             $this->_aMediaUrls->init("oxmediaurl");
02554             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02555 
02556             $sQ = "select * from oxmediaurls where oxobjectid = '".$this->getId()."'";
02557             $this->_aMediaUrls->selectString($sQ);
02558         }
02559         return $this->_aMediaUrls;
02560     }
02561 
02567     public function getDynImageDir()
02568     {
02569         return $this->_sDynImageDir;
02570     }
02571 
02577     public function getDispSelList()
02578     {
02579         if ($this->_aDispSelList === null) {
02580             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02581                 $this->_aDispSelList = $this->getSelectLists();
02582             }
02583         }
02584         return $this->_aDispSelList;
02585     }
02586 
02592     public function getMoreDetailLink()
02593     {
02594         if ( $this->_sMoreDetailLink == null ) {
02595 
02596             // and assign special article values
02597             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02598 
02599             // not always it is okey, as not all the time active category is the same as primary article cat.
02600             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02601                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02602             }
02603             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02604             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02605         }
02606 
02607         return $this->_sMoreDetailLink;
02608     }
02609 
02615     public function getToBasketLink()
02616     {
02617         if ( $this->_sToBasketLink == null ) {
02618             $myConfig = $this->getConfig();
02619 
02620             if ( oxUtils::getInstance()->isSearchEngine() ) {
02621                 $this->_sToBasketLink = $this->getLink();
02622             } else {
02623                 // and assign special article values
02624                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02625 
02626                 // override some classes as these should never showup
02627                 $sActClass = oxConfig::getParameter( 'cl' );
02628                 if ( $sActClass == 'thankyou') {
02629                     $sActClass = 'basket';
02630                 }
02631                 $this->_sToBasketLink .= 'cl='.$sActClass;
02632 
02633                 // this is not very correct
02634                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02635                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02636                 }
02637 
02638                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02639 
02640                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02641                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02642                 }
02643             }
02644         }
02645 
02646         return $this->_sToBasketLink;
02647     }
02648 
02654     public function getStockStatus()
02655     {
02656         return $this->_iStockStatus;
02657     }
02658 
02664     public function getDeliveryDate()
02665     {
02666         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02667             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02668         }
02669         return false;
02670     }
02671 
02677     public function getFTPrice()
02678     {
02679         if ( $oPrice = $this->getTPrice() ) {
02680             if ( $oPrice->getBruttoPrice() ) {
02681                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02682             }
02683         }
02684     }
02685 
02691     public function getFPrice()
02692     {
02693         if ( $oPrice = $this->getPrice() ) {
02694             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02695         }
02696     }
02697 
02703     public function getPricePerUnit()
02704     {
02705         return $this->_fPricePerUnit;
02706     }
02707 
02713     public function isParentNotBuyable()
02714     {
02715         return $this->_blNotBuyableParent;
02716     }
02717 
02723     public function isNotBuyable()
02724     {
02725         return $this->_blNotBuyable;
02726     }
02727 
02735     public function setBuyableState( $blBuyable = false )
02736     {
02737         $this->_blNotBuyable = !$blBuyable;
02738     }
02739 
02748     public function getVariantList()
02749     {
02750         return $this->getVariants();
02751     }
02752 
02760     public function setSelectlist( $aSelList )
02761     {
02762         $this->_aDispSelList = $aSelList;
02763     }
02764 
02772     public function getPictureUrl( $iIndex = '' )
02773     {
02774         if ( $iIndex ) {
02775 
02776             if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02777                 $this->_generateImages( $iIndex );
02778             }
02779 
02780             $sPic = $iIndex . "/" . $this->_getPictureName( $iIndex );
02781 
02782             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02783         }
02784     }
02785 
02793     protected function _getPictureName( $iIndex = '' )
02794     {
02795         if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02796             $sPicName = basename($this->{"oxarticles__oxpic".$iIndex}->value);
02797         } else {
02798             $sPicName = "nopic.jpg";
02799         }
02800 
02801         return $sPicName;
02802     }
02803 
02812     public function getIconUrl( $iIndex = '')
02813     {
02814         if ( $this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02815 
02816             $iIconIndex = ( $iIndex ) ? $iIndex : 1;
02817             //generating new images if needed
02818             if ( !$this->_hasGeneratedImage( $iIconIndex ) ) {
02819                 $this->_generateImages( $iIconIndex );
02820             }
02821         }
02822 
02823         $sIconName = $this->_getIconName( $iIndex );
02824 
02825         if ( !$iIndex ) {
02826             $sPic = "icon/" . basename( $sIconName );
02827         } else {
02828             $sPic = $iIndex . "/" . basename( $sIconName );
02829         }
02830 
02831         return $this->getConfig()->getIconUrl( $sPic, $this->isAdmin() );
02832     }
02833 
02842     protected function _getIconName( $iIndex = '' )
02843     {
02844         $oPictureHandler = oxPictureHandler::getInstance();
02845         $sIconName = "nopic_ico.jpg";
02846 
02847         if ( !$iIndex ) {
02848             if ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02849                 $sIconName = basename( $this->oxarticles__oxicon->value );
02850             } elseif ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 )  && $this->oxarticles__oxpic1->value ) {
02851                 $sIconName = $oPictureHandler->getMainIconName( $this->oxarticles__oxpic1->value );
02852             }
02853         } else {
02854             if ( $this->_hasGeneratedImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02855                 $sIconName = $oPictureHandler->getIconName( $this->{"oxarticles__oxpic".$iIndex}->value );
02856             }
02857         }
02858 
02859         return $sIconName;
02860     }
02861 
02867     public function getThumbnailUrl()
02868     {
02869         if ( $this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02870             //generating new images if needed
02871             if ( !$this->_hasGeneratedImage( 1 ) ) {
02872                 $this->_generateImages( 1 );
02873             }
02874         }
02875 
02876         $sPic = "0/" . $this->_getThumbnailName();
02877 
02878         return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02879     }
02880 
02886     protected function _getThumbnailName()
02887     {
02888         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02889             $sThumbName = basename($this->oxarticles__oxthumb->value);
02890         } else {
02891             if ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 ) && $this->oxarticles__oxpic1->value ) {
02892                 $oPictureHandler = oxPictureHandler::getInstance();
02893                 $sThumbName = $oPictureHandler->getThumbName( $this->oxarticles__oxpic1->value );
02894             } else {
02895                 $sThumbName = "nopic.jpg";
02896             }
02897         }
02898 
02899         return $sThumbName;
02900     }
02901 
02909     public function getZoomPictureUrl( $iIndex = '' )
02910     {
02911         $iIndex = (int) $iIndex;
02912         if ( $iIndex > 0) {
02913             //generating new images if needed
02914             if ( $this->_isFieldEmpty( "oxarticles__oxzoom" . $iIndex ) ) {
02915                 //generating new images if needed
02916                 if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02917                     $this->_generateImages( $iIndex );
02918                 }
02919             }
02920 
02921             $sPic = "z{$iIndex}/" . $this->_getZoomPictureName( $iIndex );
02922 
02923             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02924         }
02925     }
02926 
02934     protected function _getZoomPictureName( $iIndex = '' )
02935     {
02936         $sZoomField = "oxarticles__oxzoom" . $iIndex;
02937 
02938         if ( !$this->_isFieldEmpty( $sZoomField ) ) {
02939             $sZoomName = basename( $this->$sZoomField->value );
02940         } else {
02941             if ( $this->_hasGeneratedImage( $iIndex ) && $this->_hasMasterImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02942                 $oPictureHandler = oxPictureHandler::getInstance();
02943                 $sZoomName = $oPictureHandler->getZoomName( $this->{"oxarticles__oxpic".$iIndex}->value, $iIndex );
02944             } else {
02945                 $sZoomName = "nopic.jpg";
02946             }
02947         }
02948 
02949         return $sZoomName;
02950     }
02951 
02957     public function getFileUrl()
02958     {
02959         return $this->getConfig()->getPictureUrl( '0/' );
02960     }
02961 
02967     public function getPriceFromPrefix()
02968     {
02969         $sPricePrefics = '';
02970         if ( $this->_blIsRangePrice) {
02971             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02972         }
02973 
02974         return $sPricePrefics;
02975     }
02976 
02985     protected function _saveArtLongDesc($iLang, $sValue)
02986     {
02987         $oDB = oxDb::getDb();
02988         $iLang = (int) $iLang;
02989         $sLangField = ($iLang > '0') ? '_'.$iLang : '';
02990         $sLongDesc = $oDB->quote($sValue);
02991         $sLongDescSQL = "insert into oxartextends (oxartextends.OXID, oxartextends.OXLONGDESC{$sLangField})
02992                        VALUES ('".$this->getId()."', {$sLongDesc})
02993                        ON DUPLICATE KEY update oxartextends.OXLONGDESC{$sLangField} = {$sLongDesc} ";
02994 
02995         $oDB->execute($sLongDescSQL);
02996     }
02997 
03003     protected function _skipSaveFields()
03004     {
03005         $myConfig = $this->getConfig();
03006 
03007         $this->_aSkipSaveFields = array();
03008 
03009         $this->_aSkipSaveFields[] = 'oxtimestamp';
03010         $this->_aSkipSaveFields[] = 'oxlongdesc';
03011         $this->_aSkipSaveFields[] = 'oxinsert';
03012 
03013         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
03014             $this->_aSkipSaveFields[] = 'oxparentid';
03015         }
03016 
03017     }
03018 
03028     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03029     {
03030         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03031             // add prices of the same discounts
03032             if ( array_key_exists ($sKey, $aDiscounts) ) {
03033                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03034             } else {
03035                 $aDiscounts[$sKey] = $oDiscount;
03036             }
03037         }
03038         return $aDiscounts;
03039     }
03040 
03046     protected function _getGroupPrice()
03047     {
03048         $dPrice = $this->oxarticles__oxprice->value;
03049 
03050         $oUser = $this->getArticleUser();
03051         if ( $oUser ) {
03052             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03053                 $dPrice = $this->oxarticles__oxpricea->value;
03054             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03055                 $dPrice = $this->oxarticles__oxpriceb->value;
03056             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03057                 $dPrice = $this->oxarticles__oxpricec->value;
03058             }
03059         }
03060 
03061         // #1437/1436C - added config option, and check for zero A,B,C price values
03062         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03063             $dPrice = $this->oxarticles__oxprice->value;
03064         }
03065 
03066         return $dPrice;
03067     }
03068 
03077     protected function _getAmountPrice($dAmount = 1)
03078     {
03079         $myConfig = $this->getConfig();
03080 
03081         startProfile( "_getAmountPrice" );
03082 
03083         $dPrice = $this->_getGroupPrice();
03084         $oAmtPrices = $this->_getAmountPriceList();
03085         foreach ($oAmtPrices as $oAmPrice) {
03086             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03087                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03088                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03089                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03090             }
03091         }
03092 
03093         stopProfile( "_getAmountPrice" );
03094         return $dPrice;
03095     }
03096 
03105     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03106     {
03107         $myConfig = $this->getConfig();
03108         // #690
03109         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03110 
03111             $aSelLists = $this->getSelectLists();
03112             foreach ( $aSelLists as $key => $aSel) {
03113                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03114                     $oSel = $aSel[$aChosenList[$key]];
03115                     if ( $oSel->priceUnit =='abs' ) {
03116                         $dPrice += $oSel->price;
03117                     } elseif ( $oSel->priceUnit =='%' ) {
03118                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03119                     }
03120                 }
03121             }
03122         }
03123         return $dPrice;
03124     }
03125 
03126 
03134     protected function _fillAmountPriceList($oAmPriceList)
03135     {
03136         $myConfig = $this->getConfig();
03137         $myUtils  = oxUtils::getInstance();
03138 
03139         //modifying price
03140         $oCur = $myConfig->getActShopCurrencyObject();
03141 
03142         $oUser = $this->getArticleUser();
03143 
03144         $oDiscountList = oxDiscountList::getInstance();
03145         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03146 
03147         $oLowestPrice = null;
03148 
03149         $dBasePrice = $this->_getGroupPrice();
03150         $oLang = oxLang::getInstance();
03151 
03152         $dArticleVat = null;
03153         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03154             $dArticleVat = $this->getArticleVat();
03155         }
03156 
03157         // trying to find lowest price value
03158         foreach ($oAmPriceList as $sId => $oItem) {
03159             $oItemPrice = oxNew( 'oxprice' );
03160             if ( $oItem->oxprice2article__oxaddabs->value) {
03161                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03162                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03163                 $this->_applyCurrency( $oItemPrice, $oCur );
03164             } else {
03165                 $oItemPrice->setPrice( $dBasePrice );
03166                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03167             }
03168 
03169             if (isset($dArticleVat)) {
03170                 $this->_applyVAT($oItemPrice, $dArticleVat);
03171             }
03172 
03173             if (!$oLowestPrice) {
03174                 $oLowestPrice = $oItemPrice;
03175             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03176                 $oLowestPrice = $oItemPrice;
03177             }
03178 
03179             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03180             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03181             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03182         }
03183 
03184         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03185         return $oAmPriceList;
03186     }
03187 
03193     protected function _getVariantsIds()
03194     {
03195         $aSelect = array();
03196         $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->getId()."' " );
03197         if ( $oRs != false && $oRs->recordCount() > 0 ) {
03198             while (!$oRs->EOF) {
03199                 $aSelect[] = $oRs->fields['oxid'];
03200                 $oRs->moveNext();
03201             }
03202         }
03203         return $aSelect;
03204     }
03205 
03211     public function getArticleVat()
03212     {
03213         if (!isset($this->_dArticleVat)) {
03214             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03215         }
03216         return $this->_dArticleVat;
03217     }
03218 
03227     protected function _applyVAT( oxPrice $oPrice, $dVat )
03228     {
03229         startProfile(__FUNCTION__);
03230         $oPrice->setVAT( $dVat );
03231         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03232             $oPrice->setUserVat( $dVat );
03233         }
03234         stopProfile(__FUNCTION__);
03235     }
03236 
03244     public function applyVats( oxPrice $oPrice )
03245     {
03246         $this->_applyVAT($oPrice, $this->getArticleVat() );
03247     }
03248 
03259     protected function _applyDiscounts( $oPrice, $aDiscounts )
03260     {
03261         $oDiscountList = oxDiscountList::getInstance();
03262         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03263     }
03264 
03272     public function applyDiscountsForVariant( $oPrice )
03273     {
03274         // apply discounts
03275         if ( !$this->skipDiscounts() ) {
03276             $oDiscountList = oxDiscountList::getInstance();
03277             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03278         }
03279     }
03280 
03289     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03290     {
03291         if ( !$oCur ) {
03292             $oCur = $this->getConfig()->getActShopCurrencyObject();
03293         }
03294 
03295         $oPrice->multiply($oCur->rate);
03296     }
03297 
03298 
03307     protected function _getAttribsString(&$sAttribs, &$iCnt)
03308     {
03309         // we do not use lists here as we dont need this overhead right now
03310         $oDB = oxDb::getDb(true);
03311         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03312         $sAttribs = '';
03313         $blSep = false;
03314         $rs = $oDB->execute( $sSelect);
03315         $iCnt = 0;
03316         if ($rs != false && $rs->recordCount() > 0) {
03317             while (!$rs->EOF) {
03318                 if ( $blSep) {
03319                     $sAttribs .= ' or ';
03320                 }
03321                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03322                 $blSep = true;
03323                 $iCnt++;
03324                 $rs->moveNext();
03325             }
03326         }
03327     }
03328 
03337     protected function _getSimList($sAttribs, $iCnt)
03338     {
03339         $myConfig = $this->getConfig();
03340         $oDB      = oxDb::getDb(true);
03341 
03342         // #523A
03343         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03344         // 70% same attributes
03345         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03346             $iAttrPercent = 0.70;
03347         }
03348         // #1137V iAttributesPercent = 100 doesnt work
03349         $iHitMin = ceil( $iCnt * $iAttrPercent );
03350 
03351         // we do not use lists here as we dont need this overhead right now
03352         $aList= array();
03353         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03354                     ( $sAttribs )
03355                     and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03356                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03357 
03358         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03359         if ($rs != false && $rs->recordCount() > 0) {
03360             while (!$rs->EOF) {
03361                 $oTemp = new stdClass();    // #663
03362                 $oTemp->cnt = $rs->fields['cnt'];
03363                 $oTemp->id  = $rs->fields['oxobjectid'];
03364                 $aList[] = $oTemp;
03365                 $rs->moveNext();
03366             }
03367         }
03368         return $aList;
03369     }
03370 
03379     protected function _generateSimListSearchStr($sArticleTable, $aList)
03380     {
03381         $myConfig = $this->getConfig();
03382         $sFieldList = $this->getSelectFields();
03383         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03384         $blSep = false;
03385         $iCnt = 0;
03386         $oDb = oxDb::getDb();
03387         foreach ( $aList as $oTemp) {
03388             if ( $blSep) {
03389                 $sSearch .= ',';
03390             }
03391             $sSearch .= $oDb->quote($oTemp->id);
03392             $blSep = true;
03393             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03394                 break;
03395             }
03396             $iCnt++;
03397         }
03398 
03399         //#1741T
03400         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03401         $sSearch .= ') ';
03402 
03403         // #524A -- randomizing articles in attribute list
03404         $sSearch .= ' order by rand() ';
03405 
03406         return $sSearch;
03407     }
03408 
03417     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03418     {
03419         $sCatView = getViewName( 'oxcategories' );
03420         $sO2CView = getViewName( 'oxobject2category' );
03421 
03422         // we do not use lists here as we dont need this overhead right now
03423         if ( !$blSearchPriceCat ) {
03424             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03425                          {$sCatView}.oxid = oxobject2category.oxcatnid
03426                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03427         } else {
03428             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03429                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03430                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03431         }
03432         return $sSelect;
03433     }
03434 
03440     protected function _generateSearchStrForCustomerBought()
03441     {
03442         $sArtTable = $this->_getObjectViewName( 'oxarticles' );
03443         $sOrderArtTable = getViewName( 'oxorderarticles' );
03444 
03445         // fetching filter params
03446         $sIn = " '{$this->oxarticles__oxid->value}' ";
03447         if ( $this->oxarticles__oxparentid->value ) {
03448 
03449             // adding article parent
03450             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03451             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03452 
03453         } else {
03454             $sParentIdForVariants = $this->getId();
03455         }
03456 
03457         // adding variants
03458         $oDb = oxDb::getDb(true);
03459         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03460         if ( $oRs != false && $oRs->recordCount() > 0) {
03461             while ( !$oRs->EOF ) {
03462                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03463                 $oRs->moveNext();
03464             }
03465         }
03466 
03467         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03468         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03469 
03470         // building sql (optimized)
03471         $sQ = "select distinct {$sArtTable}.* from (
03472                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03473                ) as suborder
03474                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03475                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03476                where {$sArtTable}.oxid not in ( {$sIn} )
03477                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03478 
03479         /* non optimized, but could be used if index forcing is not supported
03480         // building sql
03481         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03482                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03483                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03484                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03485                and ".$this->getSqlActiveSnippet();
03486         */
03487 
03488         return $sQ;
03489     }
03490 
03500     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03501     {
03502         $sCategoryView = getViewName('oxcategories');
03503         $sO2CView = getViewName('oxobject2category');
03504         $sLangPrefix = (($this->getLanguage())?'_'.$this->getLanguage():'');
03505 
03506         $oDb    = oxDb::getDb();
03507         $sOXID  = $oDb->quote($sOXID);
03508         $sCatId = $oDb->quote($sCatId);
03509 
03510         if (!$dPriceFromTo) {
03511             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03512             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03513             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03514             $sSelect .= "and oxcategories.oxactive$sLangPrefix = 1 order by oxobject2category.oxtime ";
03515         } else {
03516             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03517             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03518             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03519             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03520         }
03521         return $sSelect;
03522     }
03523 
03529     protected function _getAmountPriceList()
03530     {
03531         if ($this->_oAmountPriceList) {
03532             return $this->_oAmountPriceList;
03533         }
03534 
03535         $myConfig = $this->getConfig();
03536 
03537         $sArtID  = $this->getId();
03538 
03539         // #1690C - Scale prices and variants
03540         if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03541             $sArtID = $this->oxarticles__oxparentid->value;
03542         }
03543 
03544         $sArtID = mysql_real_escape_string($sArtID);
03545 
03546         //collecting assigned to article amount-price list
03547         $oAmPriceList = oxNew( 'oxlist');
03548         $oAmPriceList->init('oxbase', 'oxprice2article');
03549 
03550         $sShopID = $myConfig->getShopID();
03551         if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03552             $sShopSelect = '1';
03553         } else {
03554             $sShopSelect = " oxshopid =  '$sShopID' ";
03555         }
03556 
03557         $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03558 
03559         // prepare abs prices if currently having percentages
03560         $oBasePrice = $this->_getGroupPrice();
03561         foreach ($oAmPriceList as $oAmPrice) {
03562             if ($oAmPrice->oxprice2article__oxaddperc->value) {
03563                 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03564             }
03565         }
03566 
03567         $this->_oAmountPriceList = $oAmPriceList;
03568         return $oAmPriceList;
03569     }
03570 
03578     protected function _isFieldEmpty($sFieldName)
03579     {
03580         $mValue = $this->$sFieldName->value;
03581 
03582         if (is_null($mValue)) {
03583             return true;
03584         }
03585 
03586         if ($mValue === '') {
03587             return true;
03588         }
03589 
03590         $aDoubleCopyFields = array('oxarticles__oxprice',
03591                                        'oxarticles__oxvat');
03592 
03593         if (!$mValue && in_array($sFieldName, $aDoubleCopyFields)) {
03594             return true;
03595         }
03596 
03597 
03598         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03599             return true;
03600         }
03601 
03602         $sFieldName = strtolower($sFieldName);
03603 
03604         if ( $sFieldName == 'oxarticles__oxicon' && strpos($mValue, "nopic_ico.jpg") !== false ) {
03605             return true;
03606         }
03607 
03608         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03609             return true;
03610         }
03611 
03612         return false;
03613     }
03614 
03622     protected function _assignParentFieldValue($sFieldName)
03623     {
03624         if (!($oParentArticle = $this->getParentArticle())) {
03625             return;
03626         }
03627 
03628         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03629 
03630         // assigning only theese which parent article has
03631         if ( $oParentArticle->$sCopyFieldName != null ) {
03632 
03633             // only overwrite database values
03634             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03635                 continue;
03636             }
03637 
03638             //do not copy certain fields
03639             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03640                 return;
03641             }
03642 
03643             //COPY THE VALUE
03644             // assigning images from parent only if variant has no master image (#1807)
03645             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03646                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03647                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03648                 }
03649             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03650                 // for zoom images checking master image with specified index
03651                 // assign from parent only if no pictures to variant are added
03652                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03653                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03654                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03655                 }
03656             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03657                 // if no pics generated for variants, load all from
03658                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03659             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03660                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03661             }
03662         }
03663     }
03664 
03670     public function getParentArticle()
03671     {
03672         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03673             if ( !isset( self::$_aLoadedParents[$sParentId] ) ) {
03674                 self::$_aLoadedParents[$sParentId] = oxNew( 'oxarticle' );
03675                 self::$_aLoadedParents[$sParentId]->_blSkipAbPrice  = true;
03676                 self::$_aLoadedParents[$sParentId]->_blLoadPrice    = false;
03677                 self::$_aLoadedParents[$sParentId]->_blLoadVariants = false;
03678                 self::$_aLoadedParents[$sParentId]->load( $sParentId );
03679             }
03680             return self::$_aLoadedParents[$sParentId];
03681         }
03682     }
03683 
03691     protected function _getParentAricle()
03692     {
03693         return $this->getParentArticle();
03694     }
03695 
03701     protected function _assignParentFieldValues()
03702     {   startProfile('articleAssignParentInternal');
03703         if ( $this->oxarticles__oxparentid->value) {
03704             // yes, we are in fact a variant
03705             if ( !$this->isAdmin() || ($this->_blLoadParentData && $this->isAdmin() ) ) {
03706                 foreach ($this->_aFieldNames as $sFieldName => $sVal) {
03707                     $this->_assignParentFieldValue($sFieldName);
03708                 }
03709 
03710                 //assing long description
03711                 $oParentArticle = $this->getParentArticle();
03712                 if ( !$this->oxarticles__oxlongdesc->value ) {
03713                     $this->oxarticles__oxlongdesc = $oParentArticle->oxarticles__oxlongdesc;
03714                 }
03715 
03716             }
03717         }
03718         stopProfile('articleAssignParentInternal');
03719 
03720     }
03721 
03727     protected function _assignNotBuyableParent()
03728     {
03729         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03730              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03731             $this->_blNotBuyableParent = true;
03732 
03733         }
03734     }
03735 
03741     protected function _assignAllPictureValues()
03742     {
03743         $myConfig = $this->getConfig();
03744 
03745         $this->_assignPictureValues( "oxarticles__oxicon" );
03746         $this->_assignPictureValues( "oxarticles__oxthumb" );
03747 
03748         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03749 
03750         for ( $i=1; $i<= $iPicCount; $i++ ) {
03751             $this->_assignPictureValues( "oxarticles__oxpic".$i );
03752         }
03753 
03754         if ( $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' ) ) {
03755             for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03756                 $this->_assignZoomPictureValues( "oxarticles__oxzoom".$i );
03757             }
03758         }
03759     }
03760 
03768     protected function _assignZoomPictureValues( $sName='' )
03769     {
03770         if ( $this->isAdmin() ) {
03771             return;
03772         }
03773 
03774         $sFieldName = substr_replace( $sName, "", 0, 12);
03775 
03776         $aAllFields = $this->_getAllFields( true );
03777 
03778         if ( isset( $aAllFields[$sFieldName] ) ) {
03779             $this->$sName = parent::__get( $sName );
03780             $this->$sName->value;
03781         }
03782 
03783         $this->_assignParentFieldValue( $sName );
03784 
03785         $iIndex = (int) str_ireplace( "oxzoom", "", $sFieldName );
03786 
03787         if ( isset($this->_aFieldNames[$sFieldName]) || isset($this->_aFieldNames["oxpic".$iIndex]) ) {
03788             if ( $iIndex > 0 ) {
03789                 $this->$sName = new oxField( 'z' . $iIndex.'/'.$this->_getZoomPictureName($iIndex) );
03790             }
03791         }
03792     }
03793 
03801     protected function _assignPictureValues( $sName='' )
03802     {
03803         if ( $this->isAdmin() || !$sName ) {
03804             return;
03805         }
03806 
03807         $sFieldName = substr_replace( $sName, "", 0, 12);
03808         $myConfig = $this->getConfig();
03809 
03810         // add directories
03811         if ( $sFieldName == 'oxicon' && isset($this->_aFieldNames["oxicon"]) ) {
03812             $this->oxarticles__oxicon = new oxField('icon/'.$this->_getIconName());
03813             return;
03814         }
03815 
03816         if ( $sFieldName == 'oxthumb' && isset($this->_aFieldNames["oxthumb"]) ) {
03817             $this->oxarticles__oxthumb = new oxField('0/'.$this->_getThumbnailName());
03818             return;
03819         }
03820 
03821         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03822         if ( strpos($sFieldName, "oxpic") === 0 && isset($this->_aFieldNames[$sFieldName] ) ) {
03823 
03824             $iIndex = (int) str_ireplace( "oxpic", "", $sFieldName );
03825 
03826             if ( $iIndex > 0 && $iIndex < $iPicCount ) {
03827                 $this->$sName = new oxField( $iIndex . '/'.$this->_getPictureName($iIndex) );
03828                 $this->{$sName.'_ico'} = new oxField( $iIndex . '/'.$this->_getIconName($iIndex) );
03829                 return;
03830             }
03831         }
03832     }
03833 
03839     protected function _assignStock()
03840     {
03841         $myConfig = $this->getConfig();
03842         // -----------------------------------
03843         // stock
03844         // -----------------------------------
03845 
03846         // #1125 A. must round (using floor()) value taken from database and cast to int
03847         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03848             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03849         }
03850         //GREEN light
03851         $this->_iStockStatus = 0;
03852 
03853         // if we have flag /*1 or*/ 4 - we show always green light
03854         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03855             //ORANGE light
03856             $iStock = $this->oxarticles__oxstock->value;
03857 
03858             if ($this->_blNotBuyableParent) {
03859                 $iStock = $this->oxarticles__oxvarstock->value;
03860             }
03861 
03862 
03863             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03864                 $this->_iStockStatus = 1;
03865             }
03866 
03867             //RED light
03868             if ($iStock <= 0) {
03869                 $this->_iStockStatus = -1;
03870             }
03871         }
03872 
03873 
03874         // stock
03875         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03876             $iOnStock = $this->oxarticles__oxstock->value;
03877             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03878                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03879             }
03880             if ($iOnStock <= 0) {
03881                 $this->_blNotBuyable = true;
03882             }
03883         }
03884 
03885         //exceptional handling for variant parent stock:
03886         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03887             $this->_blNotBuyable = false;
03888             //but then at least setting notBuaybleParent to true
03889             $this->_blNotBuyableParent = true;
03890         }
03891 
03892         //special treatment for lists when blVariantParentBuyable config option is set to false
03893         //then we just hide "to basket" button.
03894         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03895         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03896             $this->_blNotBuyable = true;
03897         }
03898 
03899         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03900         if ($this->_blNotBuyableParent && count($this->getVariants()) == 0) {
03901             $this->_blNotBuyable = true;
03902         }
03903     }
03904 
03910     protected function _assignPrices()
03911     {
03912         $myConfig = $this->getConfig();
03913 
03914         // Performance
03915         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03916             return;
03917         }
03918 
03919         // compute price
03920         $dPrice = $this->getPrice()->getBruttoPrice();
03921 
03922         $oCur = $myConfig->getActShopCurrencyObject();
03923         //price per unit handling
03924         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03925             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03926         }
03927 
03928 
03929         //getting min and max prices of variants
03930         $this->_applyRangePrice();
03931     }
03932 
03938     protected function _assignPersistentParam()
03939     {
03940         // Persistent Parameter Handling
03941         $aPersParam     = oxSession::getVar( 'persparam');
03942         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03943             $this->_aPersistParam = $aPersParam[$this->getId()];
03944         }
03945     }
03946 
03952     protected function _assignDynImageDir()
03953     {
03954         $myConfig = $this->getConfig();
03955 
03956         $sThisShop = $this->oxarticles__oxshopid->value;
03957 
03958         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03959         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03960         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03961         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03962     }
03963 
03969     protected function _assignComparisonListFlag()
03970     {
03971         // #657 add a flag if article is on comparisonlist
03972 
03973         $aItems = oxConfig::getParameter('aFiltcompproducts');
03974         if ( isset( $aItems[$this->getId()])) {
03975             $this->_blIsOnComparisonList = true;
03976         }
03977     }
03978 
03984     protected function _assignAttributes()
03985     {
03986         //#1029T load attributes
03987         //#1078S removed check for module "Produktvergleich"
03988         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03989             $this->getAttributes();
03990         }
03991     }
03992 
03993 
04001     protected function _insert()
04002     {
04003         // set oxinsert
04004         $iInsertTime = time();
04005         $now = date('Y-m-d H:i:s', $iInsertTime);
04006         $this->oxarticles__oxinsert    = new oxField( $now );
04007         $this->oxarticles__oxtimestamp = new oxField( $now );
04008         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
04009             $this->oxarticles__oxsubclass = new oxField('oxarticle');
04010         }
04011 
04012         return parent::_insert();
04013     }
04014 
04020     protected function _update()
04021     {
04022 
04023         $this->_skipSaveFields();
04024 
04025         $myConfig = $this->getConfig();
04026 
04027 
04028         return parent::_update();
04029     }
04030 
04038     protected function _deleteRecords($sOXID)
04039     {
04040         $oDB = oxDb::getDb();
04041 
04042         $sOXID = $oDB->quote($sOXID);
04043 
04044         //delete the record
04045         $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
04046         $oDB->execute( $sDelete);
04047 
04048         //remove other records
04049         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
04050         $oDB->execute( $sDelete);
04051 
04052         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
04053         $oDB->execute( $sDelete);
04054 
04055         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
04056         $oDB->execute( $sDelete);
04057 
04058         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
04059         $oDB->execute( $sDelete);
04060 
04061         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
04062         $oDB->execute( $sDelete);
04063 
04064         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
04065         $oDB->execute( $sDelete);
04066 
04067         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
04068         $oDB->execute( $sDelete);
04069 
04070         //#1508C - deleting oxobject2delivery entries added
04071         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04072         $oDB->execute( $sDelete);
04073 
04074         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04075         $oDB->execute( $sDelete);
04076 
04077         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04078         $rs = $oDB->execute( $sDelete );
04079 
04080         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04081         $rs = $oDB->execute( $sDelete );
04082 
04083 
04084         return $rs;
04085     }
04086 
04094     protected function _deleteVariantRecords($sOXID)
04095     {
04096         $oDB = oxDb::getDb();
04097         //collect variants to remove recursively
04098         $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDB->quote($sOXID);
04099         $rs = $oDB->execute( $sVariants);
04100         if ($rs != false && $rs->recordCount() > 0) {
04101             while (!$rs->EOF) {
04102                 $this->delete( $rs->fields[0]);
04103                 $rs->moveNext();
04104             }
04105         }
04106     }
04107 
04117     protected function _resetCacheAndArticleCount( $sOxid )
04118     {
04119         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04120     }
04121 
04127     protected function _deletePics()
04128     {
04129         $myUtilsPic = oxUtilsPic::getInstance();
04130         $myConfig   = $this->getConfig();
04131         $oPictureHandler = oxPictureHandler::getInstance();
04132 
04133         //deleting custom main icon
04134         $oPictureHandler->deleteMainIcon( $this );
04135 
04136         //deleting custom thumbnail
04137         $oPictureHandler->deleteThumbnail( $this );
04138 
04139         $sAbsDynImageDir = $myConfig->getAbsDynImageDir();
04140 
04141         // deleting master image and all generated images
04142         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04143         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04144             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04145         }
04146     }
04147 
04157     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04158     {
04159 
04160         $myUtilsCount = oxUtilsCount::getInstance();
04161 
04162         if ( $sVendorId ) {
04163             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04164         }
04165 
04166         if ( $sManufacturerId ) {
04167             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04168         }
04169 
04170         //also reseting category counts
04171         $oDb = oxDb::getDb();
04172         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04173         $oRs = $oDb->execute( $sQ );
04174         if ( $oRs !== false && $oRs->recordCount() > 0) {
04175             while ( !$oRs->EOF ) {
04176                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04177                 $oRs->moveNext();
04178             }
04179         }
04180     }
04181 
04189     protected function _onChangeUpdateStock( $sParentID )
04190     {
04191         $oDb = oxDb::getDb();
04192         $sParentIdQuoted = $oDb->quote($sParentID);
04193         $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04194         $rs = $oDb->execute($sQ);
04195         $iOldStock = $rs->fields[0];
04196         $iVendorID = $rs->fields[1];
04197         $iManufacturerID = $rs->fields[2];
04198 
04199         $sQ = 'select sum(oxstock) from oxarticles where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04200         $iStock = (float) $oDb->getOne( $sQ );
04201 
04202         $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04203         $oDb->execute( $sQ );
04204 
04205             //now lets update category counts
04206             //first detect stock status change for this article (to or from 0)
04207             if ( $iStock < 0 ) {
04208                 $iStock = 0;
04209             }
04210             if ( $iOldStock < 0 ) {
04211                 $iOldStock = 0;
04212             }
04213             if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04214                 //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04215                 // so far we leave it like this but later we could move all count resets to one or two functions
04216                 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04217             }
04218     }
04219 
04227     protected function _onChangeStockResetCount( $sOxid )
04228     {
04229         $myConfig = $this->getConfig();
04230 
04231         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04232            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04233 
04234                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04235         }
04236     }
04237 
04245     protected function _onChangeUpdateVarCount( $sParentID )
04246     {
04247         $oDb = oxDb::getDb();
04248         $sParentIdQuoted = $oDb->quote($sParentID);
04249         $sQ = 'select count(*) as varcount from oxarticles where oxparentid = '.$sParentIdQuoted;
04250         $iVarCount = (int) $oDb->getOne($sQ);
04251 
04252         $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = '.$sParentIdQuoted;
04253         $oDb->execute($sQ);
04254     }
04255 
04263     protected function _onChangeUpdateMinVarPrice( $sParentID )
04264     {
04265         $oDb = oxDb::getDb();
04266         $sParentIdQuoted = $oDb->quote($sParentID);
04267         //#M0000883 (Sarunas)
04268         $sQ = 'select min(oxprice) as varminprice from oxarticles where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04269         $dVarMinPrice = $oDb->getOne($sQ);
04270 
04271         $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04272 
04273         $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04274 
04275         if ($dVarMinPrice) {
04276             if ($blParentBuyable) {
04277                 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04278             }
04279 
04280         } else {
04281             $dVarMinPrice = $dParentPrice;
04282         }
04283 
04284         if ( $dVarMinPrice ) {
04285             $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04286             $oDb->execute($sQ);
04287         }
04288     }
04289 
04290 
04296     protected function _applyRangePrice()
04297     {
04298         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04299         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04300             return;
04301         }
04302 
04303         $this->_blIsRangePrice = false;
04304 
04305         // if parent is buyable - do not apply range price calcculations
04306         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04307             return;
04308         }
04309 
04310         $aPrices = array();
04311 
04312         if (!$this->_blNotBuyableParent) {
04313             $aPrices[] = $this->getPrice()->getBruttoPrice();
04314         }
04315 
04316         $aVariants = $this->getVariants(false);
04317 
04318         if (count($aVariants)) {
04319             foreach ($aVariants as $sKey => $oVariant) {
04320                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04321             }
04322         }
04323 
04324         /*  $oAmPrices = $this->loadAmountPriceInfo();
04325         foreach ($oAmPrices as $oAmPrice) {
04326             $aPrices[] = $oAmPrice->oxprice2article__oxaddabs->value;
04327         }*/
04328 
04329         if (count($aPrices)) {
04330             $dMinPrice = $aPrices[0];
04331             $dMaxPrice = $aPrices[0];
04332             foreach ($aPrices as $dPrice) {
04333                 if ($dMinPrice > $dPrice) {
04334                     $dMinPrice = $dPrice;
04335                 }
04336 
04337                 if ($dMaxPrice < $dPrice) {
04338                     $dMaxPrice = $dPrice;
04339                 }
04340             }
04341         }
04342 
04343         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04344             $this->getPrice()->setBruttoPriceMode();
04345             $this->getPrice()->setPrice($dMinPrice);
04346         }
04347 
04348         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04349             $this->getPrice()->setBruttoPriceMode();
04350             $this->getPrice()->setPrice($dMinPrice);
04351             $this->_blIsRangePrice = true;
04352         }
04353 
04354         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04355             //#2509 we cannot force brutto price here, as netto price can be added to DB
04356             // $this->getPrice()->setBruttoPriceMode();
04357             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04358             $this->_blIsRangePrice = true;
04359             $this->_calculatePrice( $this->getPrice() );
04360         }
04361     }
04362 
04369     public function getProductId()
04370     {
04371         return $this->getId();
04372     }
04373 
04379     public function getProductParentId()
04380     {
04381         return $this->oxarticles__oxparentid->value;
04382     }
04383 
04389     public function isOrderArticle()
04390     {
04391         return false;
04392     }
04393 
04399     public function isVariant()
04400     {
04401         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04402     }
04403 
04409     public function isMdVariant()
04410     {
04411         $oMdVariant = oxNew( "oxVariantHandler" );
04412 
04413         return $oMdVariant->isMdVariant($this);
04414     }
04415 
04423     public function getSqlForPriceCategories($sFields = '')
04424     {
04425         if (!$sFields) {
04426             $sFields = 'oxid';
04427         }
04428         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04429         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04430         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04431                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04432                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04433     }
04434 
04442     public function inPriceCategory( $sCatNid )
04443     {
04444         $oDb = oxDb::getDb();
04445 
04446         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04447         $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04448         return (bool) $oDb->getOne(
04449             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04450            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04451            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04452            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04453            .")"
04454         );
04455     }
04456 
04462     public function getMdVariants()
04463     {
04464         if ( $this->_oMdVariants ) {
04465             return $this->_oMdVariants;
04466         }
04467 
04468         $oParentArticle = $this->getParentArticle();
04469         if ( $oParentArticle ) {
04470             $oVariants = $oParentArticle->getVariants();
04471         } else {
04472             $oVariants = $this->getVariants();
04473         }
04474 
04475         $oVariantHandler = oxNew( "oxVariantHandler" );
04476         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04477 
04478         return $this->_oMdVariants;
04479     }
04480 
04486     public function getMdSubvariants()
04487     {
04488         return $this->getMdVariants()->getMdSubvariants();
04489     }
04490 
04491 
04500     protected function _generateImages( $iIndex )
04501     {
04502         if ( isset($this->_aFieldNames["oxpic".$iIndex]) && !$this->_hasGeneratedImage( $iIndex ) ) {
04503             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) && $this->_hasMasterImage( $iIndex ) ) {
04504                 $oPictureHandler = oxPictureHandler::getInstance();
04505                 $oPictureHandler->generateArticlePictures( $this, $iIndex );
04506             }
04507         }
04508     }
04509 
04518     public function updateAmountOfGeneratedPictures( $iTotalGenerated )
04519     {
04520         $this->oxarticles__oxpicsgenerated = new oxField( $iTotalGenerated );
04521         $oDb = oxDb::getDb();
04522         $sIdQuoted = $oDb->quote($this->getId());
04523 
04524         $sQ = 'update oxarticles set oxpicsgenerated = '.$iTotalGenerated.' where oxid = '.$sIdQuoted;
04525         $oDb->execute( $sQ );
04526     }
04527 
04536     protected function _hasGeneratedImage( $iIndex )
04537     {
04538         if ( $iIndex > (int) $this->oxarticles__oxpicsgenerated->value ) {
04539             return false;
04540         }
04541 
04542         return true;
04543     }
04544 
04552     protected function _hasMasterImage( $iIndex )
04553     {
04554         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04555 
04556         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04557             return false;
04558         }
04559         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04560             return false;
04561         }
04562 
04563         $sMasterPic = $iIndex . "/" . $sPicName;
04564 
04565         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04566             return true;
04567         }
04568 
04569         return false;
04570     }
04571 
04580     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04581     {
04582         if ( $sFieldName ) {
04583             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04584             return $this->$sFieldName->value;
04585         }
04586     }
04587 }