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 
00014 class oxArticle extends oxI18n
00015 {
00021     protected $_sCoreTbl = 'oxarticles';
00022 
00028     protected $_sClassName = 'oxarticle';
00029 
00035     protected $_blUseLazyLoading = true;
00036 
00042     protected $_sItemKey;
00043 
00049     protected $_blCalcPrice    = true;
00050 
00055     protected $_oPrice      = null;
00056 
00061     protected $_aPersistParam  = null;
00062 
00067     protected $_blNotBuyable   = false;
00068 
00074     protected $_blLoadVariants = true;
00075 
00081     protected $_aVariants = null;
00082 
00091     protected $_blNotBuyableParent  = false;
00092 
00097     protected $_blHasVariants = false;
00098 
00102     protected $_iVarStock = 0;
00103 
00108     protected $_oVariantList   = array();
00109 
00114     protected $_blIsOnComparisonList = false;
00115 
00120     protected $_oUser = null;
00121 
00127     protected $_blLoadPrice = true;
00128 
00132     protected $_blSkipAbPrice = false;
00133 
00140     protected $_fPricePerUnit = null;
00141 
00145     protected $_blLoadParentData = false;
00146 
00150     protected $_blSkipAssign = false;
00151 
00157     protected $_blSkipDiscounts = null;
00158 
00163     protected $_oAttributeList = null;
00164 
00165 
00171     protected $_blIsRangePrice = false;
00172 
00178     protected $_aMediaUrls = null;
00179 
00185     static protected $_aLoadedParents;
00186 
00192     static protected $_aSelList;
00193 
00199     protected $_aDispSelList;
00200 
00206     protected $_blIsSeoObject = true;
00207 
00213     protected $_oAmountPriceList = null;
00214 
00223     protected $_iLinkType = 0;
00224 
00230     protected $_sStdLink = null;
00231 
00237     protected $_sDynImageDir = null;
00238 
00244     protected $_sMoreDetailLink = null;
00245 
00251     protected $_sToBasketLink = null;
00252 
00258     protected $_iStockStatus = null;
00259 
00265     protected $_oTPrice = null;
00266 
00272     protected $_oAmountPriceInfo = null;
00273 
00279     protected $_dAmountPrice = null;
00280 
00286     protected $_sDetailLink = null;
00287 
00293     protected static $_aArticleManufacturers = array();
00294 
00300     protected static $_aArticleVendors = array();
00301 
00307     protected static $_aArticleCats = array();
00308 
00317     public function __construct($aParams = null)
00318     {
00319         if ( $aParams && is_array($aParams)) {
00320             foreach ( $aParams as $sParam => $mValue) {
00321                 $this->$sParam = $mValue;
00322             }
00323         }
00324         parent::__construct();
00325         $this->init( 'oxarticles' );
00326 
00327         $this->_blIsRangePrice = false;
00328     }
00329 
00337     public function __isset( $sName )
00338     {
00339         if ( $sName == 'oxarticles__oxlongdesc' ) {
00340             //get empty oxlongdesc field
00341             $this->getArticleLongDesc();
00342             return true;
00343         }
00344         return isset( $this->$sName );
00345     }
00346 
00355     public function __set( $sName, $sValue)
00356     {
00357         if ($sName == 'oxarticles__oxlongdesc') {
00358             $this->$sName = $sValue;
00359             return;
00360         }
00361         return parent::__set($sName, $sValue);
00362     }
00363 
00372     public function __get($sName)
00373     {
00374         $myUtils = oxUtils::getInstance();
00375         switch ($sName) {
00376             // NOT using caching here, because of these params should be used in templates ONLY
00377             // and in template files they are used not very much [once most of the time]
00378 
00379             // price related
00380             case 'netprice':
00381             case 'netPrice':
00382                 $mVal = $myUtils->fRound($this->getPrice()->getNettoPrice());
00383                 break;
00384             case 'brutPrice':
00385                 return $myUtils->fRound($this->getPrice()->getBruttoPrice());
00386                 break;
00387             case 'vatPercent':
00388                 return $this->getPrice()->getVAT();
00389                 break;
00390             case 'vat':
00391                 return $this->getPrice()->getVATValue();
00392                 break;
00393             case 'fnetprice':
00394                 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($this->getPrice()->getNettoPrice()));
00395                 break;
00396             case 'fprice':
00397                 return $this->getFPrice();
00398                 break;
00399 
00400             // t price related
00401             case 'dtprice':
00402                 if ( $oPrice = $this->getTPrice() ) {
00403                     return $myUtils->fRound($oPrice->getBruttoPrice());
00404                     break;
00405                 } else {
00406                     return null;
00407                     break;
00408                 }
00409             case 'tvat':
00410                 if ( $oPrice = $this->getTPrice() ) {
00411                     return $oPrice->getVATValue();
00412                     break;
00413                 } else {
00414                     return null;
00415                     break;
00416                 }
00417             case 'ftprice':
00418                 if ( $oPrice = $this->getTPrice() ) {
00419                     return oxLang::getInstance()->formatCurrency( $myUtils->fRound($oPrice->getBruttoPrice()) );
00420                     break;
00421                 } else {
00422                     return null;
00423                     break;
00424                 }
00425             case 'oxarticles__oxlongdesc':
00426                 return $this->getArticleLongDesc($this->getId());
00427                 break;
00428             case 'foxdelivery':
00429                 return $this->getDeliveryDate();
00430                 break;
00431             case 'sItemKey':
00432                 return $this->getItemKey();
00433                 break;
00434             case 'selectlist':
00435                 return $this->_aDispSelList = $this->getDispSelList();
00436                 break;
00437             case 'blNotBuyable':
00438                 return $this->isNotBuyable();
00439                 break;
00440             case 'blNotBuyableParent':
00441                 return $this->isParentNotBuyable();
00442                 break;
00443             case 'blIsOnComparisonList':
00444                 return $this->isOnComparisonList();
00445                 break;
00446             case 'oVariantlist' :
00447                 return $this->_oVariantList;
00448                 break;
00449             case 'fPricePerUnit' :
00450                 return $this->getPricePerUnit();
00451                 break;
00452             case 'dimagedir' :
00453                 return $this->_sDynImageDir = $this->getDynImageDir();
00454                 break;
00455             case 'oxmoredetaillink' :
00456                 return $this->_sMoreDetailLink = $this->getMoreDetailLink();
00457                 break;
00458             case 'amountpricelist' :
00459                 return $this->loadAmountPriceInfo();
00460                 break;
00461             case 'stockstatus' :
00462                 return $this->getStockStatus();
00463                 break;
00464             case 'tobasketlink' :
00465                 return $this->getToBasketLink();
00466                 break;
00467             case 'oxdetaillink' :
00468                 return $this->getLink();
00469                 break;
00470             /*case 'oxarticles__oxnid':
00471                 return $this->getId();*/
00472         }
00473 
00474         $sRet = parent::__get($sName);
00475         if ( $this->$sName ) {
00476             $this->_assignParentFieldValue($sName);
00477         }
00478         //checking for picture information
00479         if ($sName == "oxarticles__oxthumb" || $sName == "oxarticles__oxicon" || strpos($sName, "oxarticles__oxpic") === 0 || strpos($sName, "oxarticles__oxzoom") === 0) {
00480             $this->_assignPictureValues();
00481             return $this->$sName;
00482         }
00483 
00484         return $sRet;
00485     }
00486 
00494     public function setId( $sId = null )
00495     {
00496         $sId = parent::setId( $sId );
00497 
00498         // TODO: in oxbase::setId make it to check if exists and update, not recreate, then delete this overload
00499         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00500 
00501         return $sId;
00502     }
00503 
00511     public function getSqlActiveSnippet( $blForceCoreTable = false )
00512     {
00513         $myConfig = $this->getConfig();
00514             $sTable = $this->getCoreTableName();
00515 
00516         // check if article is still active
00517         $sQ = " $sTable.oxactive = 1 ";
00518 
00519         // enabled time range check ?
00520         if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00521             $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00522             $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00523         }
00524 
00525         //do not check for variants
00526         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00527             $sQ = " $sQ and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0  ) ";
00528             //V #M513: When Parent article is not purchaseble, it's visibility should be displayed in shop only if any of Variants is available.
00529             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00530                 $sQ = " $sQ and ( $sTable.oxvarcount=0 or ( select count(art.oxid) from $sTable as art where art.oxstockflag=2 and art.oxparentid=$sTable.oxid and art.oxstock=0 ) < $sTable.oxvarcount ) ";
00531             }
00532         }
00533 
00534 
00535         return "( $sQ ) ";
00536     }
00537 
00545     public function setSkipAssign($blSkipAssign)
00546     {
00547         $this->_blSkipAssign = $blSkipAssign;
00548     }
00549 
00557     public function disablePriceLoad( $oArticle )
00558     {
00559         $oArticle->_blLoadPrice = false;
00560     }
00561 
00567     public function getItemKey()
00568     {
00569         return $this->_sItemKey;
00570     }
00571 
00579     public function setItemKey($sItemKey)
00580     {
00581         $this->_sItemKey = $sItemKey;
00582     }
00583 
00591     public function setNoVariantLoading( $blLoadVariants )
00592     {
00593         $this->_blLoadVariants = !$blLoadVariants;
00594     }
00595 
00601     public function isBuyable()
00602     {
00603         if ($this->_blNotBuyableParent) {
00604             return false;
00605         }
00606 
00607         return !$this->_blNotBuyable;
00608     }
00609 
00615     public function getPersParams()
00616     {
00617         return $this->_aPersistParam;
00618     }
00619 
00625     public function isOnComparisonList()
00626     {
00627         return $this->_blIsOnComparisonList;
00628     }
00629 
00637     public function setOnComparisonList( $blOnList )
00638     {
00639         $this->_blIsOnComparisonList = $blOnList;
00640     }
00641 
00649     public function setLoadParentData($blLoadParentData)
00650     {
00651         $this->_blLoadParentData = $blLoadParentData;
00652     }
00653 
00661     public function setSkipAbPrice( $blSkipAbPrice = null )
00662     {
00663         $this->_blSkipAbPrice = $blSkipAbPrice;
00664     }
00665 
00671     public function getSearchableFields()
00672     {
00673         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00674         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00675 
00676         return $aFields;
00677     }
00678 
00679 
00687     public function isMultilingualField($sFieldName)
00688     {
00689         if ($sFieldName == "oxlongdesc") {
00690             return true;
00691         }
00692 
00693         return parent::isMultilingualField($sFieldName);
00694     }
00695 
00701     public function isVisible()
00702     {
00703 
00704         // admin preview mode
00705         $myConfig = $this->getConfig();
00706         if ( oxConfig::getParameter( 'preview' ) == 1 &&  $this->isAdmin()) {
00707             return true;
00708         }
00709 
00710         // active ?
00711         $sNow = date('Y-m-d H:i:s');
00712         if ( !$this->oxarticles__oxactive->value &&
00713              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00714                 $this->oxarticles__oxactiveto->value < $sNow
00715              )) {
00716             return false;
00717         }
00718 
00719         // stock flags
00720         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
00721            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
00722             return false;
00723         }
00724 
00725         return true;
00726     }
00727 
00736     public function assign( $aRecord)
00737     {
00738         startProfile('articleAssign');
00739 
00740 
00741         // load object from database
00742         parent::assign( $aRecord);
00743 
00744         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00745 
00746         // check for simple article.
00747         if ($this->_blSkipAssign) {
00748             return;
00749         }
00750 
00751         $this->_assignLinks();
00752         $this->_assignParentFieldValues();
00753         $this->_assignNotBuyableParent();
00754         $this->_assignPictureValues();
00755         $this->_assignStock();
00756         startProfile('articleAssignPrices');
00757         $this->_assignPrices();
00758         stopProfile('articleAssignPrices');
00759         $this->_assignPersistentParam();
00760         $this->_assignDynImageDir();
00761         $this->_assignComparisonListFlag();
00762         $this->_assignAttributes();
00763 
00764 
00765         //$this->_seoAssign();
00766 
00767         stopProfile('articleAssign');
00768     }
00769 
00779     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00780     {
00781         parent::_setFieldData( $sFieldName, $sValue, $iDataType);
00782     }
00783 
00794     public function load( $oxID)
00795     {
00796         // A. #1325 resetting to avoid problems when reloading (details etc)
00797         $this->_blNotBuyableParent = false;
00798 
00799         $blRet = parent::load( $oxID);
00800 
00801         // convert date's to international format
00802         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00803         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00804 
00805         return $blRet;
00806     }
00807 
00815     public function addToRatingAverage( $iRating)
00816     {
00817         $dOldRating = $this->oxarticles__oxrating->value;
00818         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00819         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00820         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00821         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00822         $dRatingCnt = $dOldCnt + 1;
00823         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00824         oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00825     }
00826 
00832     public function getArticleRatingAverage()
00833     {
00834         return round( $this->oxarticles__oxrating->value, 1);
00835     }
00836 
00842     public function getReviews()
00843     {
00844         $myConfig  = $this->getConfig();
00845 
00846         $aIds = array($this->getId());
00847 
00848         if ( $this->oxarticles__oxparentid->value ) {
00849                 $aIds[] = $this->oxarticles__oxparentid->value;
00850         }
00851 
00852         // showing variant reviews ..
00853         if ( $myConfig->getConfigParam( 'blShowVariantReviews' ) ) {
00854             $aAdd = $this->_getVariantsIds();
00855             if (is_array($aAdd)) {
00856                 $aIds = array_merge($aIds, $aAdd);
00857             }
00858         }
00859 
00860         $oReview = oxNew('oxreview');
00861         $oRevs = $oReview->loadList('oxarticle', $aIds);
00862 
00863         //if no review found, return null
00864         if ( $oRevs->count() < 1 ) {
00865             return null;
00866         }
00867 
00868         return $oRevs;
00869     }
00870 
00876     public function getCrossSelling()
00877     {
00878         $oCrosslist = oxNew( "oxarticlelist");
00879         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00880         if ( $oCrosslist->count() ) {
00881             return $oCrosslist;
00882         }
00883     }
00884 
00890     public function getAccessoires()
00891     {
00892         $myConfig = $this->getConfig();
00893 
00894         // Performance
00895         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00896             return;
00897         }
00898 
00899         $oAcclist = oxNew( "oxarticlelist");
00900         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00901         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00902 
00903         if ( $oAcclist->count()) {
00904             return $oAcclist;
00905         }
00906     }
00907 
00913     public function getSimilarProducts()
00914     {
00915         // Performance
00916         $myConfig = $this->getConfig();
00917         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
00918             return;
00919         }
00920 
00921         $sArticleTable = $this->_getObjectViewName('oxarticles');
00922 
00923         $sAttribs = '';
00924         $iCnt = 0;
00925         $this->_getAttribsString($sAttribs, $iCnt);
00926 
00927         if ( !$sAttribs) {
00928             return null;
00929         }
00930 
00931         // DODGER : Actually to optimize this function we only take the similar products from the first 100 hits
00932         // I think that this is possible as this function anyway never worked like it should
00933         // Calculation of iHitMin was ALWAYS == 1
00934         // Still it's not so fast like I would like to have it, but I don't have any idea how to improve it more
00935 
00936         $aList = $this->_getSimList($sAttribs, $iCnt);
00937 
00938         if ( count( $aList ) ) {
00939             uasort( $aList, 'cmpart');
00940 
00941             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
00942 
00943             $oSimilarlist = oxNew( 'oxarticlelist' );
00944             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
00945             $oSimilarlist->selectString( $sSearch);
00946 
00947             return $oSimilarlist;
00948         }
00949     }
00950 
00956     public function getCustomerAlsoBoughtThisProducts()
00957     {
00958         // Performance
00959         $myConfig = $this->getConfig();
00960         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
00961             return;
00962         }
00963 
00964         // selecting products that fits
00965         $sQ = $this->_generateSearchStrForCustomerBought();
00966 
00967         $oArticles = oxNew( 'oxarticlelist' );
00968         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
00969         $oArticles->selectString( $sQ );
00970         if ( $oArticles->count() ) {
00971             return $oArticles;
00972         }
00973     }
00974 
00981     public function loadAmountPriceInfo()
00982     {
00983         $myConfig = $this->getConfig();
00984         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
00985             return array();
00986         }
00987 
00988         if ( $this->_oAmountPriceInfo !== null ) {
00989             return $this->_oAmountPriceInfo;
00990         }
00991 
00992         $oAmPriceList = $this->_getAmountPriceList();
00993 
00994         if ( count( $oAmPriceList ) ) {
00995             $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
00996             return $this->_oAmountPriceInfo;
00997         }
00998 
00999         return array();
01000     }
01001 
01009     public function getSelectLists($sKeyPrefix = null)
01010     {
01011         //#1468C - more then one article in basket with different selectlist...
01012         //optionall function parameter $sKeyPrefix added, used only in basket.php
01013         $sKey = $this->getId();
01014         if ( isset( $sKeyPrefix ) ) {
01015             $sKey = $sKeyPrefix.'__'.$this->getId();
01016         }
01017 
01018         if ( self::$_aSelList[$sKey]) {
01019             return self::$_aSelList[$sKey];
01020         }
01021 
01022         // all selectlists this article has
01023         $oLists = oxNew( 'oxlist' );
01024         $oLists->init('oxselectlist');
01025         $sSLViewName = getViewName('oxselectlist');
01026         $sSelect  = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01027         $sSelect .= 'where oxobject2selectlist.oxobjectid=\''.$this->getId().'\' ';
01028         //sorting
01029         $sSelect .= ' order by oxobject2selectlist.oxsort';
01030 
01031         $oLists->selectString( $sSelect );
01032 
01033         //#1104S if this is variant ant it has no selectlists, trying with parent
01034         if ( $this->oxarticles__oxparentid->value && $oLists->count() == 0 ) {
01035             //#1496C - select fixed ( * => $sSLViewName.*)
01036             $sSelect  = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01037             $sSelect .= "where oxobject2selectlist.oxobjectid='{$this->oxarticles__oxparentid->value}' ";
01038             //sorting
01039             $sSelect .= ' order by oxobject2selectlist.oxsort';
01040             $oLists->selectString( $sSelect);
01041         }
01042 
01043         $dVat = 0;
01044         if ( $this->getPrice() != null ) {
01045             $dVat = $this->getPrice()->getVat();
01046         }
01047 
01048         $iCnt = 0;
01049         self::$_aSelList[$sKey] = array();
01050         foreach ( $oLists as $oSelectlist ) {
01051             self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01052             self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01053             $iCnt++;
01054         }
01055         return self::$_aSelList[$sKey];
01056     }
01057 
01065     public function getVariants( $blRemoveNotOrderables = true )
01066     {
01067         if ($this->_aVariants) {
01068             return $this->_aVariants;
01069         }
01070 
01071         //return ;
01072         if (!$this->_blLoadVariants) {
01073             return array();
01074         }
01075 
01076         $myConfig = $this->getConfig();
01077 
01078         // Performance
01079         if ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants')) {
01080             return array();
01081         }
01082 
01083         //do not load variants where variant oxvarcount is 0
01084         //hint: if variantas are not loaded you should check your data integrity oxvarcount should always be equal to variant count
01085         if (!$this->isAdmin() && !$this->oxarticles__oxvarcount->value) {
01086             return array();
01087         }
01088 
01089         //do not load me as a parent later
01090         self::$_aLoadedParents[$this->getId()] = $this;
01091 
01092         //improve this
01093         if ($this->_isInList()) {
01094             $oVariants = oxNew( 'oxlist' );
01095             $oVariants->init('oxsimplevariant');
01096         } else {
01097             //loading variants
01098             $oVariants = oxNew( 'oxarticlelist' );
01099         }
01100 
01101         startProfile("selectVariants");
01102         $sSelectFields = $oVariants->getBaseObject()->getSelectFields();
01103         $sArticleTable = $this->getViewName();
01104         $sSelect =  "select $sSelectFields from $sArticleTable where ";
01105         $sSelect .= " $sArticleTable.oxparentid ='".$this->getId()."' ";
01106         $sSelect .= " order by $sArticleTable.oxsort";
01107         $oVariants->selectString( $sSelect);
01108         stopProfile("selectVariants");
01109 
01110         //print_r($oVariants);
01111 
01112         if (!$oVariants->count()) {
01113             return array();
01114         }
01115         $oVariants = $this->_removeInactiveVariants( $oVariants, $blRemoveNotOrderables );
01116         //$this->calculateMinVarPrice($oVariants);
01117         //#1104S Load selectlists
01118         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
01119             foreach ($oVariants as $key => $oVariant) {
01120                 $oVariants[$key]->aSelectlist = $oVariant->getSelectLists();
01121             }
01122         }
01123         $this->_aVariants = $oVariants;
01124         return $oVariants;
01125     }
01126 
01132     public function getSimpleVariants()
01133     {
01134         if ( $this->oxarticles__oxvarcount->value) {
01135             return $this->getVariants();
01136         }
01137     }
01138 
01147     public function getAdminVariants( $sLanguage = null )
01148     {
01149         $myConfig = $this->getConfig();
01150 
01151         $oVariants = oxNew( 'oxarticlelist');
01152 
01153         if ( is_null($sLanguage) ) {
01154             $oVariants->getBaseObject()->setLanguage(oxLang::getInstance()->getBaseLanguage());
01155         } else {
01156             $oVariants->getBaseObject()->setLanguage($sLanguage);
01157         }
01158 
01159         $sSql = 'select * from oxarticles where oxparentid = "'.$this->getId().'" order by oxsort ';
01160 
01161         $oVariants->selectString( $sSql);
01162 
01163         //if we have variants then depending on config option the parent may be non buyable
01164         if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01165             //$this->blNotBuyable = true;
01166             $this->_blNotBuyableParent = true;
01167         }
01168 
01169         return $oVariants;
01170     }
01171 
01179     public function getCategory()
01180     {
01181         startPRofile( 'getCategory' );
01182 
01183         $oCategory = oxNew( 'oxcategory' );
01184         $oCategory->setLanguage( $this->getLanguage() );
01185 
01186         // variant handling
01187         $sOXID = $this->getId();
01188         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01189             $sOXID = $this->oxarticles__oxparentid->value;
01190         }
01191 
01192         $sWhere   = $oCategory->getSqlActiveSnippet();
01193         $sSelect  = $this->_generateSearchStr( $sOXID );
01194         $sSelect .= ( strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime ";
01195 
01196         // category not found ?
01197         if ( !$oCategory->assignRecord( $sSelect ) ) {
01198 
01199             $sSelect  = $this->_generateSearchStr( $sOXID, true );
01200             $sSelect .= ( strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere ;
01201 
01202             // looking for price category
01203             if ( !$oCategory->assignRecord( $sSelect ) ) {
01204                 $oCategory = null;
01205             }
01206         }
01207 
01208         stopPRofile( 'getCategory' );
01209         return $oCategory;
01210     }
01211 
01219     public function getCategoryIds( $blSkipCache = false )
01220     {
01221         $myConfig = $this->getConfig();
01222         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01223             return self::$_aArticleCats[$this->getId()];
01224         }
01225 
01226         // variant handling
01227         $sOXID = $this->getId();
01228         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01229             $sOXID = $this->oxarticles__oxparentid->value;
01230         }
01231 
01232         $sO2CView = $this->_getObjectViewName('oxobject2category');
01233         $sCatView = $this->_getObjectViewName('oxcategories');
01234 
01235         // we do not use lists here as we dont need this overhead right now
01236         $oDB = oxDb::getDb(true);
01237         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01238         $sSelect .= 'where oxobject2category.oxobjectid=\''.$sOXID.'\' and oxcategories.oxid is not null and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 order by oxobject2category.oxtime ';
01239         $rs = $oDB->execute( $sSelect);
01240 
01241 
01242         $aRet = array();
01243         $iHitMax = 0;
01244         if ($rs != false && $rs->recordCount() > 0) {
01245             while (!$rs->EOF) {
01246                 $aRet[] = $rs->fields['oxcatnid'];
01247                 $rs->moveNext();
01248             }
01249         }
01250 
01251         return self::$_aArticleCats[$this->getId()] = $aRet;
01252     }
01253 
01263     public function getVendor( $blShopCheck = true )
01264     {
01265         if ( ( $sVendorId = $this->getVendorId() ) ) {
01266             $oVendor = oxNew( 'oxvendor' );
01267         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01268             $oVendor = oxNew( 'oxi18n' );
01269             $oVendor->init('oxvendor');
01270             $oVendor->setReadOnly( true );
01271             $sVendorId = $this->oxarticles__oxvendorid->value;
01272         }
01273         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01274             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01275                 $oVendor->setReadOnly( true );
01276             }
01277             return $oVendor;
01278         }
01279         return null;
01280     }
01281 
01289     public function getVendorId( $blForceReload = false )
01290     {
01291         $sVendorId = false;
01292         if ( $this->oxarticles__oxvendorid->value ) {
01293             if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01294                 return self::$_aArticleVendors[$this->getId()];
01295             }
01296             $sQ = "select oxid from ".getViewName('oxvendor')." where oxid='{$this->oxarticles__oxvendorid->value}'";
01297             self::$_aArticleVendors[$this->getId()] = $sVendorId = oxDb::getDb()->getOne( $sQ );
01298         }
01299         return $sVendorId;
01300     }
01301 
01309     public function getManufacturerId( $blForceReload = false )
01310     {
01311         $sManufacturerId = false;
01312         if ( $this->oxarticles__oxmanufacturerid->value ) {
01313             if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01314                 return self::$_aArticleManufacturers[$this->getId()];
01315             }
01316             $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid='{$this->oxarticles__oxmanufacturerid->value}'";
01317             self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = oxDb::getDb()->getOne( $sQ );
01318         }
01319         return $sManufacturerId;
01320     }
01321 
01331     public function getManufacturer( $blShopCheck = true )
01332     {
01333         $oManufacturer = null;
01334         if ( ( $sManufacturerId = $this->getManufacturerId() ) ) {
01335             $oManufacturer = oxNew( 'oxmanufacturer' );
01336         } elseif ( !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01337             $oManufacturer = oxNew( 'oxI18n' );
01338             $oManufacturer->init('oxmanufacturers');
01339             $oManufacturer->setReadOnly( true );
01340             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01341         }
01342 
01343         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01344             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01345                 $oManufacturer->setReadOnly( true );
01346             }
01347             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01348         } else {
01349             $oManufacturer = null;
01350         }
01351 
01352         return $oManufacturer;
01353     }
01354 
01363     public function inCategory( $sCatNid)
01364     {
01365         return in_array( $sCatNid, $this->getCategoryIds());
01366     }
01367 
01376     public function isAssignedToCategory( $sCatId )
01377     {
01378         // variant handling
01379         $sOXID = $this->getId();
01380         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01381             $sOXID = $this->oxarticles__oxparentid->value;
01382         }
01383 
01384         $oDB = oxDb::getDb();
01385         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01386         $sOXID = $oDB->getOne( $sSelect);
01387         // article is assigned to passed category!
01388         if ( isset( $sOXID) && $sOXID) {
01389             return true;
01390         }
01391 
01392         // maybe this category is price category ?
01393         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01394             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01395             if ( $dPriceFromTo > 0) {
01396                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01397                 $sOXID = $oDB->getOne( $sSelect);
01398                 // article is assigned to passed category!
01399                 if ( isset( $sOXID) && $sOXID) {
01400                     return true;
01401                 }
01402             }
01403         }
01404         return false;
01405     }
01406 
01412     public function getTPrice()
01413     {
01414         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01415             return;
01416         }
01417         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01418         if ( $this->_oTPrice !== null ) {
01419             return $this->_oTPrice;
01420         }
01421 
01422         $this->_oTPrice = oxNew( 'oxPrice' );
01423         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01424 
01425         $this->_applyVat( $this->_oTPrice, oxNew( 'oxVatSelector' )->getArticleVat( $this ) );
01426         $this->_applyCurrency( $this->_oTPrice );
01427 
01428         return $this->_oTPrice;
01429     }
01430 
01436     public function skipDiscounts()
01437     {
01438         // allready loaded skip discounts config
01439         if ( $this->_blSkipDiscounts !== null )
01440             return $this->_blSkipDiscounts;
01441 
01442         if ( $this->oxarticles__oxskipdiscounts->value )
01443             return true;
01444 
01445         $sO2CView = getViewName('oxobject2category');
01446         $sSelect =  "select 1 from $sO2CView as oxobject2category left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01447         $sSelect .= 'where oxobject2category.oxobjectid="'.$this->getId().'" and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 and oxcategories.oxskipdiscounts = "1" ';
01448 
01449         return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01450     }
01451 
01459     public function setPrice(oxPrice $oPrice)
01460     {
01461         $this->_oPrice = $oPrice;
01462     }
01463 
01472     public function getBasePrice( $dAmount = 1 )
01473     {
01474         // override this function if you want e.g. different prices
01475         // for diff. usergroups.
01476 
01477         // Performance
01478         $myConfig = $this->getConfig();
01479         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01480             return;
01481 
01482         // GroupPrice or DB price ajusted by AmountPrice
01483         $dPrice = $this->_getAmountPrice( $dAmount );
01484 
01485 
01486         return $dPrice;
01487     }
01488 
01494     public function getPrice()
01495     {
01496         $myConfig = $this->getConfig();
01497         // Performance
01498         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01499             return;
01500         }
01501         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01502         if ( $this->_oPrice ) {
01503             return $this->_oPrice;
01504         }
01505 
01506         $this->_oPrice = oxNew( 'oxPrice' );
01507 
01508         // get base
01509         $this->_oPrice->setPrice( $this->getBasePrice() );
01510 
01511         // price handling
01512         if ( !$this->_blCalcPrice ) {
01513             return $this->_oPrice;
01514         }
01515 
01516         // apply VAT only if configuration requires it
01517         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01518             $this->_applyVAT( $this->_oPrice, oxNew('oxVatSelector')->getArticleVat( $this ) );
01519         }
01520 
01521         // apply currency
01522         $this->_applyCurrency( $this->_oPrice );
01523 
01524         // apply discounts
01525         if ( !$this->skipDiscounts() ) {
01526             $this->_applyDiscounts($this->_oPrice, oxDiscountList::getInstance()->getArticleDiscounts($this, $this->getArticleUser()));
01527         }
01528 
01529         return $this->_oPrice;
01530     }
01531 
01539     public function setArticleUser($oUser)
01540     {
01541         $this->_oUser = $oUser;
01542     }
01543 
01549     public function getArticleUser()
01550     {
01551         if ($this->_oUser) {
01552             return $this->_oUser;
01553         }
01554         return $this->getUser();
01555     }
01556 
01566     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01567     {
01568         $oUser = $oBasket->getBasketUser();
01569         $this->setArticleUser($oUser);
01570 
01571         $oBasketPrice = oxNew( 'oxPrice' );
01572 
01573         // get base price
01574         $dBasePrice = $this->getBasePrice( $dAmount );
01575 
01576         // applying select list price
01577         $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01578 
01579         // setting price
01580         $oBasketPrice->setPrice( $dBasePrice );
01581 
01582         // apply VAT
01583         $this->_applyVat( $oBasketPrice, oxNew('oxVatSelector')->getBasketItemVat( $this, $oBasket ) );
01584 
01585         // apply currency
01586         $this->_applyCurrency( $oBasketPrice );
01587 
01588         // apply discounts
01589         if ( !$this->skipDiscounts() ) {
01590             // apply general discounts
01591             $this->_applyDiscounts( $oBasketPrice, oxDiscountList::getInstance()->getArticleDiscounts( $this, $oUser ) );
01592         }
01593 
01594         // returning final price object
01595         return $oBasketPrice;
01596     }
01597 
01608     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01609     {
01610         $aDiscLog = array();
01611         reset( $aDiscounts );
01612 
01613         // price object to correctly perform calculations
01614         $dOldPrice = $oPrice->getBruttoPrice();
01615 
01616         while (list( , $oDiscount) = each($aDiscounts)) {
01617             $oDiscount->applyDiscount( $oPrice );
01618             $dNewPrice = $oPrice->getBruttoPrice();
01619 
01620             if (!isset($aDiscLog[$oDiscount->getId()])) {
01621                 $aDiscLog[$oDiscount->getId()] = $oDiscount->getSimpleDiscount();
01622             }
01623 
01624             $aDiscLog[$oDiscount->getId()]->dDiscount += $dOldPrice - $dNewPrice;
01625             $aDiscLog[$oDiscount->getId()]->dDiscount *= $dAmount;
01626             $dOldPrice = $dNewPrice;
01627         }
01628         return $aDiscLog;
01629     }
01630 
01639     public function delete( $sOXID = null )
01640     {
01641         if ( !$sOXID ) {
01642             $sOXID = $this->getId();
01643         }
01644         if ( !$sOXID ) {
01645             return false;
01646         }
01647 
01648 
01649         $this->load( $sOXID );
01650         $this->_deletePics();
01651         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01652         $this->_deleteVariantRecords( $sOXID );
01653         $rs = $this->_deleteRecords( $sOXID );
01654 
01655         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01656 
01657         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01658 
01659         return $rs->EOF;
01660     }
01661 
01670     public function updateSoldAmount( $iAmount = 0 )
01671     {
01672         if ( !$iAmount ) {
01673             return;
01674         }
01675 
01676         $this->beforeUpdate();
01677 
01678         // article is not variant - should be updated current amount
01679         if ( !$this->oxarticles__oxparentid->value ) {
01680             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01681             $rs = oxDb::getDb()->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $iAmount, oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '".$this->oxarticles__oxid->value."'");
01682         } elseif ( $this->oxarticles__oxparentid->value) {
01683             // article is variant - should be updated this article parent amount
01684             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01685             $oUpdateArticle->updateSoldAmount( $iAmount );
01686         }
01687 
01688         $this->onChange( ACTION_UPDATE );
01689 
01690         return $rs;
01691     }
01692 
01698     public function disableReminder()
01699     {
01700         $oDB = oxDb::getDb(true);
01701         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = '".$this->oxarticles__oxid->value."'");
01702     }
01703 
01710     public function save()
01711     {
01712         $myConfig = $this->getConfig();
01713 
01714         $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01715         $this->oxarticles__oxicon  = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01716         $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01717         for ($i=1; $i <= $iPicCount; $i++) {
01718             if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01719                 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01720             }
01721         }
01722         $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
01723         for ($i=1; $i <= $iZoomPicCount; $i++) {
01724             if ( isset($this->{'oxarticles__oxzoom'.$i}) ) {
01725                 $this->{'oxarticles__oxzoom'.$i}->setValue(basename($this->{'oxarticles__oxzoom'.$i}->value));
01726             }
01727         }
01728 
01729 
01730             $blRet = parent::save();
01731 
01732         // save article long description
01733         $this->setArticleLongDesc();
01734         // load article images after save
01735         $this->_assignPictureValues();
01736 
01737         return $blRet;
01738     }
01739 
01746     public function getPictureGallery()
01747     {
01748         $myConfig = $this->getConfig();
01749 
01750         //initialize
01751         $blMorePic = false;
01752         $aArtPics  = array();
01753         $aArtIcons = array();
01754         $iActPicId = 1;
01755         $sActPic = $this->getPictureUrl( $iActPicId );
01756 
01757         if ( oxConfig::getParameter( 'actpicid' ) ) {
01758             $iActPicId = oxConfig::getParameter('actpicid');
01759         }
01760 
01761         $iCntr = 0;
01762         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01763         for ( $i = 1; $i <= $iPicCount; $i++) {
01764             $sPicVal = $this->getPictureUrl( $i );
01765             $sIcoVal = $this->getIconUrl( $i );
01766             if ( !strstr($sIcoVal, 'nopic_ico.jpg')) {
01767                 if ($iCntr) {
01768                     $blMorePic = true;
01769                 }
01770                 $aArtIcons[$i]= $sIcoVal;
01771                 $aArtPics[$i]= $sPicVal;
01772                 $iCntr++;
01773             }
01774             if ($iActPicId == $i) {
01775                 $sActPic = $sPicVal;
01776             }
01777         }
01778 
01779         $blZoomPic  = false;
01780         $aZoomPics = array();
01781         $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
01782         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
01783             $sVal = $this->getZoomPictureUrl($j);
01784             if ( !strstr($sVal, 'nopic.jpg')) {
01785                 if ($this->getConfig()->getConfigParam('blFormerTplSupport')) {
01786                     $sVal = $this->_sDynImageDir."/".$sVal;
01787                 }
01788                 $blZoomPic = true;
01789                 $aZoomPics[$c]['id'] = $c;
01790                 $aZoomPics[$c]['file'] = $sVal;
01791                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01792                 if (!$sVal) {
01793                     $aZoomPics[$c]['file'] = "nopic.jpg";
01794                 }
01795                 $c++;
01796             }
01797         }
01798 
01799         $aPicGallery = array('ActPicID' => $iActPicId,
01800                              'ActPic' => $sActPic,
01801                              'MorePics' => $blMorePic,
01802                              'Pics' => $aArtPics,
01803                              'Icons' => $aArtIcons,
01804                              'ZoomPic' => $blZoomPic,
01805                              'ZoomPics' => $aZoomPics);
01806 
01807         return $aPicGallery;
01808     }
01809 
01823     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
01824     {
01825         $myConfig = $this->getConfig();
01826 
01827         if (!isset($sOXID)) {
01828             if ( $this->getId()) {
01829                 $sOXID = $this->getId();
01830             }
01831             if (!isset ($sOXID)) {
01832                 $sOXID = $this->oxarticles__oxid->value;
01833             }
01834             if ($this->oxarticles__oxparentid->value) {
01835                 $sParentID = $this->oxarticles__oxparentid->value;
01836             }
01837         }
01838         if (!isset($sOXID)) {
01839             return;
01840         }
01841 
01842         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
01843         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
01844             //if article has variants then updating oxvarstock field
01845             //getting parent id
01846             if (!isset($sParentID)) {
01847                 $sQ = 'select oxparentid from oxarticles where oxid = \''.$sOXID.'\'';
01848                 $sParentID = oxDb::getDb()->getOne($sQ);
01849             }
01850             //if we have parent id then update stock
01851             if ($sParentID) {
01852                 $this->_onChangeUpdateStock($sParentID);
01853             }
01854         }
01855         //if we have parent id then update count
01856         //update count even if blUseStock is not active
01857         if ($sParentID) {
01858             $this->_onChangeUpdateVarCount($sParentID);
01859         }
01860 
01861         $sId = ( $sParentID ) ? $sParentID : $sOXID;
01862         $this->_onChangeUpdateMinVarPrice( $sId );
01863 
01864     }
01865 
01872     public function getCustomVAT()
01873     {
01874         if ( isset($this->oxarticles__oxvat->value) ) {
01875             return $this->oxarticles__oxvat->value;
01876         }
01877     }
01878 
01886     public function checkForStock( $dAmount )
01887     {
01888         $myConfig = $this->getConfig();
01889         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
01890             return true;
01891         }
01892 
01893         // fetching DB info as its up-to-date
01894         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
01895         $rs = oxDb::getDb(true)->Execute( $sQ );
01896 
01897         $iOnStock   = 0;
01898         $iStockFlag = 0;
01899         if ( $rs !== false && $rs->recordCount() > 0 ) {
01900             $iOnStock   = $rs->fields['oxstock'];
01901             $iStockFlag = $rs->fields['oxstockflag'];
01902 
01903             // dodger : fremdlager is also always considered as on stock
01904             if ( $iStockFlag == 1 || $iStockFlag == 4) {
01905                 return true;
01906             }
01907             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
01908                 //2007-09-04 MK this if is NEVER true, because upper return in if $iStockFlag == 1 or $iStockFlag == 4
01909                 /* if ( $iStockFlag == 1 || $iStockFlag == 4 ) {
01910                     $iOnStock = ceil( $iOnStock );
01911                  } else {*/
01912                     $iOnStock = floor( $iOnStock );
01913                 //}
01914             }
01915         }
01916 
01917         if ( $iOnStock >= $dAmount ) {
01918             return true;
01919         } else {
01920             if ( $iOnStock > 0 ) {
01921                 return $iOnStock;
01922             } else {
01923                 return false;
01924             }
01925         }
01926     }
01927 
01928 
01936     public function getArticleLongDesc($sOXID = null)
01937     {
01938 
01939         if ( !$sOXID ) {
01940             $sOXID = $this->oxarticles__oxid->value;
01941         }
01942 
01943         if ($sOXID == $this->oxarticles__oxid->value) {
01944             if (isset($this->oxarticles__oxlongdesc) && ($this->oxarticles__oxlongdesc instanceof oxField) && $this->oxarticles__oxlongdesc->value) {
01945                 return $this->oxarticles__oxlongdesc;
01946             }
01947         }
01948 
01949         $myConfig = $this->getConfig();
01950 
01951         // TODO: check if keeping fldname is needed in non-admin mode
01952         $this->oxarticles__oxlongdesc = new oxField();
01953         $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
01954         $this->oxarticles__oxlongdesc->table   = 'oxarticles';
01955         $this->oxarticles__oxlongdesc->fldtype = 'text';
01956 
01957         if ( $sOXID ) {
01958             $sLangField = oxLang::getInstance()->getLanguageTag($this->getLanguage());
01959             $this->oxarticles__oxlongdesc->setValue(oxDb::getDb()->getOne( "select oxlongdesc{$sLangField} from oxartextends where oxid = '$sOXID'" ), oxField::T_RAW);
01960 
01961             // TODO: eliminate code below
01962             // hack, if editor screws up text, htmledit tends to do so
01963             $this->oxarticles__oxlongdesc->setValue(str_replace( '&amp;nbsp;', '&nbsp;', $this->oxarticles__oxlongdesc->value ), oxField::T_RAW);
01964             $this->oxarticles__oxlongdesc->setValue(str_replace( '&amp;', '&', $this->oxarticles__oxlongdesc->value ), oxField::T_RAW);
01965             $this->oxarticles__oxlongdesc->setValue(str_replace( '&quot;', '"', $this->oxarticles__oxlongdesc->value ), oxField::T_RAW);
01966             $blHasSmarty = strstr( $this->oxarticles__oxlongdesc->value, '[{' );
01967             if ( $blHasSmarty && ($myConfig->getConfigParam( 'blExport' ) || !$this->isAdmin() ) && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
01968                 $this->oxarticles__oxlongdesc->setValue(oxUtilsView::getInstance()->parseThroughSmarty( $this->oxarticles__oxlongdesc->value, $this->getId() ), oxField::T_RAW);
01969             }
01970 
01971         }
01972 
01973         return $this->oxarticles__oxlongdesc;
01974     }
01975 
01981     public function setArticleLongDesc()
01982     {
01983 
01984         if ($this->_blEmployMultilanguage) {
01985             // update or insert article long description
01986             if ($this->oxarticles__oxlongdesc instanceof oxField) {
01987                 $sLongDesc = $this->oxarticles__oxlongdesc->getRawValue();
01988             } else {
01989                 $sLongDesc = $this->oxarticles__oxlongdesc->value;
01990             }
01991             $this->_saveArtLongDesc($this->getLanguage(), $sLongDesc);
01992         } else {
01993             $oArtExt = oxNew('oxi18n');
01994             $oArtExt->init('oxartextends');
01995             $aObjFields = $oArtExt->_getAllFields(true);
01996             foreach ($aObjFields as $sKey => $sValue ) {
01997                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
01998                     $iLang = $oArtExt->_getFieldLang($sKey);
01999                     $sField = $this->_getFieldLongName($sKey);
02000                     $sLongDesc = null;
02001                     if ($this->$sField instanceof oxField) {
02002                         $sLongDesc = $this->$sField->getRawValue();
02003                     } elseif (is_object($this->$sField)) {
02004                         $sLongDesc = $this->$sField->value;
02005                     }
02006                     if (isset($sLongDesc)) {
02007                         $this->_saveArtLongDesc($iLang, $sLongDesc);
02008                     }
02009                 }
02010             }
02011         }
02012     }
02013 
02019     public function getAttributes()
02020     {
02021 
02022         if ($this->_oAttributeList) {
02023             return $this->_oAttributeList;
02024         }
02025 
02026         $oAttributeList = oxNew( 'oxattributelist' );
02027         $oAttributeList->loadAttributes( $this->getId());
02028         //if config option is set then the value for this object is also set
02029         //2007-02-09T
02030         $this->_oAttributeList = $oAttributeList;
02031 
02032         return $oAttributeList;
02033     }
02034 
02042     public function appendLink( $sAddParams )
02043     {
02044         if ( $this->_sDetailLink === null ) {
02045             $this->_sDetailLink = $this->getLink();
02046         }
02047         $this->_sDetailLink .= (( strpos( $this->_sDetailLink, '?' ) !== false ) ? '&amp;' : '?' ) . $sAddParams;
02048     }
02049 
02057     public function getLink($iLang = null)
02058     {
02059         if (isset($iLang)) {
02060             $iLang = (int) $iLang;
02061             if ($iLang == (int) $this->getLanguage()) {
02062                 $iLang = null;
02063             }
02064         }
02065         if ( $this->_sDetailLink === null || isset($iLang) ) {
02066 
02067             if ( oxUtils::getInstance()->seoIsActive() ) {
02068                 $oxdetaillink = oxSeoEncoderArticle::getInstance()->getArticleUrl( $this, $iLang, $this->_iLinkType);
02069             } else {
02070                 $oxdetaillink = $this->getStdLink($iLang);
02071             }
02072 
02073             if (isset($iLang)) {
02074                 return $oxdetaillink;
02075             } else {
02076                 $this->_sDetailLink = $oxdetaillink;
02077             }
02078         }
02079 
02080         return $this->_sDetailLink;
02081     }
02082 
02090     public function setLinkType( $iType )
02091     {
02092         // resetting detaisl link, to force new
02093         $this->_sDetailLink = null;
02094 
02095         // setting link type
02096         $this->_iLinkType = (int) $iType;
02097     }
02098 
02106     public function getStdLink($iLang = null)
02107     {
02108         //always returns shop url, not admin
02109         $sUrl  = $this->getConfig()->getShopHomeURL( $iLang, false );
02110         $sUrl .= "cl=details&amp;anid=".$this->getId();
02111 
02112         $blSeo = oxUtils::getInstance()->seoIsActive();
02113         if ( !$blSeo || $this->_iLinkType != 0 ) {
02114 
02115             if ( !$blSeo ) {
02116                 $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
02117                 if ( $iPgNr > 0 ) {
02118                     $sUrl .= "&amp;pgNr={$iPgNr}";
02119                 }
02120             }
02121 
02122             if ( ( $sCat = oxConfig::getParameter( 'cnid' ) ) ) {
02123                 $sUrl .= "&amp;cnid={$sCat}";
02124             }
02125 
02126             if ( ( $sCat = oxConfig::getParameter( 'mnid' ) ) ) {
02127                 $sUrl .= "&amp;mnid={$sCat}";
02128             }
02129 
02130             $sListType = oxConfig::getParameter( 'listtype' );
02131             if ( !isset( $sListType ) ) {
02132                 // view defined list type
02133                 $sListType = $this->getConfig()->getGlobalParameter( 'listtype' );
02134             }
02135 
02136             // list type
02137             if ( $sListType ) {
02138                 $sUrl .= "&amp;listtype={$sListType}";
02139             }
02140 
02141             if (!$blSeo && isset($iLang)) {
02142                 $iLang = (int) $iLang;
02143                 if ($iLang != (int) $this->getLanguage()) {
02144                     $sUrl .= "&amp;lang={$iLang}";
02145                 }
02146             }
02147         }
02148 
02149         return $sUrl;
02150     }
02151 
02157     public function getTags()
02158     {
02159         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02160         $sQ = "select $sTagField from oxartextends where oxid = '".$this->getId()."'";
02161         $sTags = oxDb::getDb(true)->getOne($sQ);
02162         $oTagCloud = oxNew('oxtagcloud');
02163         $sTags = $oTagCloud->trimTags($sTags);
02164         return $sTags;
02165     }
02166 
02174     public function saveTags($sTags)
02175     {
02176         $sTags = mysql_real_escape_string($sTags);
02177         $oTagCloud = oxNew('oxtagcloud');
02178         $oTagCloud->resetTagCache();
02179         $sTags = $oTagCloud->prepareTags($sTags);
02180         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02181         $sQ = "update oxartextends set $sTagField = '$sTags'  where oxid = '".$this->getId()."'";
02182         return oxDb::getDb()->execute($sQ);
02183 
02184     }
02185 
02193     public function addTag($sTag)
02194     {
02195         $sTag = mysql_real_escape_string($sTag);
02196 
02197         $oTagCloud = oxNew('oxtagcloud');
02198         $oTagCloud->resetTagCache();
02199         $sTag = $oTagCloud->prepareTags($sTag);
02200 
02201         $sField = "oxartextends.OXTAGS".oxLang::getInstance()->getLanguageTag();
02202         $sQ = "insert into oxartextends (oxartextends.OXID, $sField) values ('".$this->getId()."', '{$sTag}')
02203                        ON DUPLICATE KEY update $sField = CONCAT(TRIM($sField), ' $sTag') ";
02204 
02205         return oxDb::getDb()->Execute($sQ);
02206     }
02207 
02213     public function getMediaUrls()
02214     {
02215         if ($this->_aMediaUrls) {
02216             return $this->_aMediaUrls;
02217         }
02218 
02219         $this->_aMediaUrls = oxNew("oxlist");
02220         $this->_aMediaUrls->init("oxmediaurl");
02221         $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02222 
02223         $sQ = "select * from oxmediaurls where oxobjectid = '".$this->getId()."'";
02224         $this->_aMediaUrls->selectString($sQ);
02225 
02226         return $this->_aMediaUrls;
02227     }
02228 
02234     public function getDynImageDir()
02235     {
02236         return $this->_sDynImageDir;
02237     }
02238 
02244     public function getDispSelList()
02245     {
02246         if ($this->_aDispSelList === null) {
02247             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02248                 $this->_aDispSelList = $this->getSelectLists();
02249             }
02250         }
02251         return $this->_aDispSelList;
02252     }
02253 
02259     public function getMoreDetailLink()
02260     {
02261         return $this->_sMoreDetailLink;
02262     }
02263 
02269     public function getToBasketLink()
02270     {
02271         return $this->_sToBasketLink;
02272     }
02273 
02279     public function getStockStatus()
02280     {
02281         return $this->_iStockStatus;
02282     }
02283 
02289     public function getDeliveryDate()
02290     {
02291         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02292             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02293         } else {
02294             return false;
02295         }
02296     }
02297 
02303     public function getFTPrice()
02304     {
02305         if ( $oPrice = $this->getTPrice() ) {
02306             if ( $oPrice->getBruttoPrice() ) {
02307                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02308             }
02309         } else {
02310             return null;
02311         }
02312     }
02313 
02319     public function getFPrice()
02320     {
02321         if ( $oPrice = $this->getPrice() ) {
02322             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02323         } else {
02324             return null;
02325         }
02326     }
02327 
02333     public function getPricePerUnit()
02334     {
02335         return $this->_fPricePerUnit;
02336     }
02337 
02343     public function isParentNotBuyable()
02344     {
02345         return $this->_blNotBuyableParent;
02346     }
02347 
02353     public function isNotBuyable()
02354     {
02355         return $this->_blNotBuyable;
02356     }
02357 
02363     public function getVariantList()
02364     {
02365         return $this->_oVariantList;
02366     }
02367 
02375     public function setSelectlist( $aSelList )
02376     {
02377         $this->_aDispSelList = $aSelList;
02378     }
02379 
02387     public function getPictureUrl( $iIndex )
02388     {
02389         return $this->getConfig()->getPictureUrl( $this->{"oxarticles__oxpic".$iIndex}->value );
02390     }
02391 
02399     public function getIconUrl( $iIndex = '')
02400     {
02401         if (!$iIndex) {
02402             $sFile = $this->oxarticles__oxicon->value;
02403         } else {
02404             $sFile = $this->{'oxarticles__oxpic' . $iIndex . '_ico'}->value;
02405         }
02406 
02407         $sFile = str_replace('nopic.jpg', 'nopic_ico.jpg', $sFile);
02408 
02409         //$sFile = $this->getConfig()->getPictureUrl( 'icon/' ). basename($sFile);
02410         $sFile = $this->getConfig()->getPictureUrl( $sFile );
02411 
02412         return $sFile;
02413     }
02414 
02420     public function getThumbnailUrl()
02421     {
02422         //return $this->getConfig()->getPictureUrl( $this->oxarticles__oxthumb->value );
02423         return $this->getConfig()->getPictureUrl( '0/' ) . basename($this->oxarticles__oxthumb->value);
02424     }
02425 
02433     public function getZoomPictureUrl($iIndex)
02434     {
02435         return $this->getConfig()->getPictureUrl( $this->{'oxarticles__oxzoom'.$iIndex}->value );
02436     }
02437 
02443     public function getFileUrl()
02444     {
02445         return $this->getConfig()->getPictureUrl( '0/' );
02446     }
02447 
02453     public function getPriceFromPrefix()
02454     {
02455         $sPricePrefics = '';
02456         if ( $this->_blIsRangePrice) {
02457             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02458         }
02459 
02460         return $sPricePrefics;
02461     }
02462 
02471     protected function _saveArtLongDesc($iLang, $sValue)
02472     {
02473         $oDB = oxDb::getDb();
02474         $iLang = (int) $iLang;
02475         $sLangField = ($iLang > '0') ? '_'.$iLang : '';
02476         $sLongDesc = $oDB->quote($sValue);
02477         $sLongDescSQL = "insert into oxartextends (oxartextends.OXID, oxartextends.OXLONGDESC{$sLangField})
02478                        VALUES ('".$this->getId()."', {$sLongDesc})
02479                        ON DUPLICATE KEY update oxartextends.OXLONGDESC{$sLangField} = {$sLongDesc} ";
02480 
02481         $oDB->execute($sLongDescSQL);
02482     }
02483 
02499     protected function _removeInactiveVariants( $oVariants, $blStrict = false )
02500     {
02501         $myConfig = $this->getConfig();
02502         $this->_iVarStock = 0;
02503         $this->_blHasVariants = false;
02504         $now = time();
02505         $sSearchdate = date('Y-m-d H:i:s', $now);
02506         $this->_iVarStock = $this->oxarticles__oxvarstock->value;
02507 
02508         //checking if variant is active and stock status
02509         foreach (array_keys($oVariants->getArray()) as $key ) {
02510 
02511             $oVariant = $oVariants[$key];
02512             $this->_blHasVariants = true;
02513             //removing variants not in stock
02514             if ( $myConfig->getConfigParam( 'blUseStock' ) &&
02515                 $oVariant->oxarticles__oxstockflag->value != 1 && $oVariant->oxarticles__oxstockflag->value != 4 &&
02516                 ($oVariant->oxarticles__oxstockflag->value != 3 || $blStrict) && $oVariant->oxarticles__oxstock->value <= 0) {
02517                     unset($oVariants[$key]);
02518                     continue;
02519             }
02520 
02521             //removing non active variants
02522             if (!$oVariant->oxarticles__oxactive->value &&
02523                 !($oVariant->oxarticles__oxactivefrom->value < $sSearchdate &&
02524                 $oVariant->oxarticles__oxactiveto->value > $sSearchdate) ) {
02525                     unset($oVariants[$key]);
02526                     continue;
02527             }
02528         }
02529 
02530         //if we have variants then depending on config option the parent may be non buyable
02531         if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
02532             $this->_blNotBuyableParent = true;
02533         }
02534 
02535         //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
02536         if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $oVariants->count() == 0 && $this->_blHasVariants) {
02537             $this->_blNotBuyable = true;
02538         }
02539 
02540         return $oVariants;
02541     }
02542 
02546     protected function _skipSaveFields()
02547     {
02548         $myConfig = $this->getConfig();
02549 
02550         $this->_aSkipSaveFields = array();
02551 
02552         $this->_aSkipSaveFields[] = 'oxtimestamp';
02553         $this->_aSkipSaveFields[] = 'oxlongdesc';
02554         $this->_aSkipSaveFields[] = 'oxinsert';
02555 
02556         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02557             $this->_aSkipSaveFields[] = 'oxparentid';
02558         }
02559 
02560     }
02561 
02571     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02572     {
02573         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02574             // add prices of the same discounts
02575             if ( array_key_exists ($sKey, $aDiscounts) ) {
02576                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02577             } else {
02578                 $aDiscounts[$sKey] = $oDiscount;
02579             }
02580         }
02581         return $aDiscounts;
02582     }
02583 
02589     protected function _getGroupPrice()
02590     {
02591         $dPrice = $this->oxarticles__oxprice->value;
02592 
02593         $oUser = $this->getArticleUser();
02594         if ( $oUser ) {
02595             if ( $oUser->inGroup( 'oxidpricea' ) ) {
02596                 $dPrice = $this->oxarticles__oxpricea->value;
02597             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
02598                 $dPrice = $this->oxarticles__oxpriceb->value;
02599             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
02600                 $dPrice = $this->oxarticles__oxpricec->value;
02601             }
02602         }
02603 
02604         // #1437/1436C - added config option, and check for zero A,B,C price values
02605         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
02606             $dPrice = $this->oxarticles__oxprice->value;
02607         }
02608 
02609         return $dPrice;
02610     }
02611 
02620     protected function _getAmountPrice($dAmount = 1)
02621     {
02622         $myConfig = $this->getConfig();
02623 
02624         startProfile( "_getAmountPrice" );
02625 
02626         $dPrice = $this->_getGroupPrice();
02627         $oAmtPrices = $this->_getAmountPriceList();
02628         foreach ($oAmtPrices as $oAmPrice) {
02629             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
02630                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
02631                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
02632                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
02633             }
02634         }
02635 
02636         stopProfile( "_getAmountPrice" );
02637         return $dPrice;
02638     }
02639 
02648     protected function _modifySelectListPrice( &$dPrice, $aChosenList = null )
02649     {
02650         $myConfig = $this->getConfig();
02651         // #690
02652         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
02653 
02654             $aSelLists = $this->getSelectLists();
02655             foreach ( $aSelLists as $key => $aSel) {
02656                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
02657                     $oSel = $aSel[$aChosenList[$key]];
02658                     if ( $oSel->priceUnit =='abs' ) {
02659                         $dPrice += $oSel->price;
02660                     } elseif ( $oSel->priceUnit =='%' ) {
02661                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
02662                     }
02663                 }
02664             }
02665         }
02666         return $dPrice;
02667     }
02668 
02669 
02677     protected function _fillAmountPriceList($oAmPriceList)
02678     {
02679         $myConfig = $this->getConfig();
02680         $myUtils  = oxUtils::getInstance();
02681 
02682         //modifying price
02683         $oCur = $myConfig->getActShopCurrencyObject();
02684 
02685         $oUser = $this->getArticleUser();
02686 
02687         $aDiscountList = oxDiscountList::getInstance()->getArticleDiscounts($this, $oUser );
02688 
02689         $oLowestPrice = null;
02690 
02691         $dBasePrice = $this->_getGroupPrice();
02692         $oLang = oxLang::getInstance();
02693 
02694         $dArticleVat = null;
02695         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
02696             $dArticleVat = oxNew('oxVatSelector')->getArticleVat( $this );
02697         }
02698 
02699         // trying to find lowest price value
02700         foreach ($oAmPriceList as $sId => $oItem) {
02701             $oItemPrice = oxNew( 'oxprice' );
02702             if ( $oItem->oxprice2article__oxaddabs->value) {
02703                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
02704                 $this->_applyDiscounts( $oItemPrice, $aDiscountList );
02705                 $this->_applyCurrency( $oItemPrice, $oCur );
02706             } else {
02707                 $oItemPrice->setPrice( $dBasePrice );
02708                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
02709             }
02710 
02711             if (isset($dArticleVat)) {
02712                 $this->_applyVAT($oItemPrice, $dArticleVat);
02713             }
02714 
02715             if (!$oLowestPrice) {
02716                 $oLowestPrice = $oItemPrice;
02717             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
02718                 $oLowestPrice = $oItemPrice;
02719             }
02720 
02721             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
02722             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
02723             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
02724         }
02725 
02726         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
02727         return $oAmPriceList;
02728     }
02729 
02735     protected function _getVariantsIds()
02736     {
02737         $aSelect = array();
02738         $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->oxarticles__oxid->value."' " );
02739         if ( $oRs != false && $oRs->recordCount() > 0 ) {
02740             while (!$oRs->EOF) {
02741                 $aSelect[] = $oRs->fields['oxid'];
02742                 $oRs->moveNext();
02743             }
02744         }
02745         return $aSelect;
02746     }
02747 
02756     protected function _applyVAT( oxPrice $oPrice, $dVat )
02757     {
02758         startProfile(__FUNCTION__);
02759         $oPrice->setVAT( $dVat );
02760         if ( ( $oUser = $this->getArticleUser() ) ) {
02761             if ( ( $dVat = oxNew( 'oxVatSelector' )->getUserVat( $oUser ) ) !== false ) {
02762                 $oPrice->setUserVat( $dVat );
02763             }
02764         }
02765         stopProfile(__FUNCTION__);
02766     }
02767 
02776     protected function _applyDiscounts( $oPrice, $aDiscounts )
02777     {
02778         reset( $aDiscounts );
02779         while ( list( , $oDiscount ) = each( $aDiscounts ) ) {
02780             $oDiscount->applyDiscount( $oPrice );
02781         }
02782     }
02783 
02792     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
02793     {
02794         if ( !$oCur ) {
02795             $oCur = $this->getConfig()->getActShopCurrencyObject();
02796         }
02797 
02798         $oPrice->multiply($oCur->rate);
02799     }
02800 
02809     protected function _getIcon()
02810     {
02811         // #1479/1179M - Article icon automatic generation
02812         //if set to do not generate.
02813         $myConfig = $this->getConfig();
02814 
02815         if (!$myConfig->getConfigParam( 'blAutoIcons' ) ) {
02816             if ($this->oxarticles__oxicon->value) {
02817                 return basename($this->oxarticles__oxicon->value);
02818             } else {
02819                 $sQ = "UPDATE oxarticles SET oxicon = 'nopic_ico.jpg' WHERE oxid = '".$this->getId()."'";
02820                 oxDb::getDb()->execute($sQ);
02821                 return 'nopic_ico.jpg';
02822             }
02823         }
02824 
02825         // if set to generate and icon already exist
02826         if ( $this->oxarticles__oxicon->value && strpos( $this->oxarticles__oxicon->value, 'nopic_ico.jpg') === false ) {
02827             return basename($this->oxarticles__oxicon->value);
02828         }
02829 
02830         //we don't have an icon yet so lets make one
02831         if ($this->oxarticles__oxthumb->value && strpos( $this->oxarticles__oxthumb->value, 'nopic.jpg') === false &&  function_exists('gd_info')) {
02832 
02833             $sSourceFile = $this->oxarticles__oxthumb->value;
02834             $sTargetFile = str_replace('_th', '_ico', $sSourceFile);
02835 
02836             if ($sSourceFile == $sTargetFile) {
02837                 $sPattern = '(\.[a-z0-9]*$)';
02838                 $sTargetFile = eregi_replace($sPattern, '_ico\\1', $sTargetFile);
02839             }
02840 
02841             $sTarget = $myConfig->getAbsDynImageDir().'/icon/'. basename($sTargetFile);
02842             $sSource = $myConfig->getAbsDynImageDir().'/0/'. basename($sSourceFile);
02843 
02844             if (!$myConfig->getConfigParam( 'sIconsize' ) ) {
02845                 $myConfig->setConfigParam( 'sIconsize', '56*42' );
02846             }
02847 
02848             $aSize = explode('*', $myConfig->getConfigParam( 'sIconsize' ) );
02849             $iX = $aSize[0];
02850             $iY = $aSize[1];
02851 
02852             oxUtilspic::getInstance()->resizeImage( $sSource, $sTarget, $iX, $iY );
02853 
02854             $sResult = $sTargetFile;
02855         } else {
02856             $sResult = 'nopic_ico.jpg';
02857         }
02858 
02859         //saving new icon
02860         $sIconFile = basename($sResult);
02861 
02862         $sQ = "UPDATE oxarticles SET oxicon = '$sIconFile' WHERE oxid = '".$this->getId()."'";
02863 
02864         oxDb::getDb()->execute($sQ);
02865 
02866         return $sIconFile;
02867     }
02868 
02869 
02878     protected function _getAttribsString(&$sAttribs, &$iCnt)
02879     {
02880         // we do not use lists here as we dont need this overhead right now
02881         $oDB = oxDb::getDb(true);
02882         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->oxarticles__oxid->value.'" ';
02883         $sAttribs = '';
02884         $blSep = false;
02885         $rs = $oDB->execute( $sSelect);
02886         $iCnt = 0;
02887         if ($rs != false && $rs->recordCount() > 0) {
02888             while (!$rs->EOF) {
02889                 if ( $blSep) {
02890                     $sAttribs .= ' or ';
02891                 }
02892                 $sAttribs .= 't1.oxattrid = "'.$rs->fields['oxattrid'].'" ';
02893                 $blSep = true;
02894                 $iCnt++;
02895                 $rs->moveNext();
02896             }
02897         }
02898     }
02899 
02908     protected function _getSimList($sAttribs, $iCnt)
02909     {
02910         $myConfig = $this->getConfig();
02911         $oDB      = oxDb::getDb(true);
02912 
02913         // #523A
02914         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
02915         // 70% same attributes
02916         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
02917             $iAttrPercent = 0.70;
02918         }
02919         $iHitMin = round( $iCnt * $iAttrPercent + 0.5);
02920 
02921         // we do not use lists here as we dont need this overhead right now
02922         $aList= array();
02923         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
02924                     ( $sAttribs )
02925                     and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
02926                     group by t1.oxobjectid having count(*) >= $iHitMin ";
02927 
02928         $rs = $oDB->selectLimit( $sSelect, 20, 0);
02929         if ($rs != false && $rs->recordCount() > 0) {
02930             while (!$rs->EOF) {
02931                 $oTemp = new stdClass();    // #663
02932                 $oTemp->cnt = $rs->fields['cnt'];
02933                 $oTemp->id  = $rs->fields['oxobjectid'];
02934                 $aList[] = $oTemp;
02935                 $rs->moveNext();
02936             }
02937         }
02938         return $aList;
02939     }
02940 
02949     protected function _generateSimListSearchStr($sArticleTable, $aList)
02950     {
02951         $myConfig = $this->getConfig();
02952         $sFieldList = $this->getSelectFields();
02953         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
02954         $blSep = false;
02955         $iCnt = 0;
02956         foreach ( $aList as $oTemp) {
02957             if ( $blSep) {
02958                 $sSearch .= ',';
02959             }
02960             $sSearch .= "'".$oTemp->id."'";
02961             $blSep = true;
02962             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
02963                 break;
02964             }
02965             $iCnt++;
02966         }
02967 
02968         //#1741T
02969         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
02970         $sSearch .= ') ';
02971 
02972         // #524A -- randomizing articles in attribute list
02973         $sSearch .= ' order by rand() ';
02974 
02975         return $sSearch;
02976     }
02977 
02986     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
02987     {
02988         $sCatView = getViewName( 'oxcategories' );
02989         $sO2CView = getViewName( 'oxobject2category' );
02990 
02991         // we do not use lists here as we dont need this overhead right now
02992         if ( !$blSearchPriceCat ) {
02993             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
02994                          {$sCatView}.oxid = oxobject2category.oxcatnid
02995                          where oxobject2category.oxobjectid='{$sOXID}' and {$sCatView}.oxid is not null ";
02996         } else {
02997             $sSelect  = "select {$sCatView}.* from {$sCatView} where
02998                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
02999                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03000         }
03001         return $sSelect;
03002     }
03003 
03009     protected function _generateSearchStrForCustomerBought()
03010     {
03011         $sArtTable = $this->_getObjectViewName( 'oxarticles' );
03012         $sOrderArtTable = getViewName( 'oxorderarticles' );
03013 
03014         // fetching filter params
03015         $sIn = " '{$this->oxarticles__oxid->value}' ";
03016         if ( $this->oxarticles__oxparentid->value ) {
03017 
03018             // adding article parent
03019             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03020             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03021 
03022         } else {
03023             $sParentIdForVariants = $this->getId();
03024         }
03025 
03026         // adding variants
03027         $oRs = oxDb::getDb(true)->execute( "select oxid from {$sArtTable} where oxparentid = '{$sParentIdForVariants}' and oxid != '{$this->oxarticles__oxid->value}' " );
03028         if ( $oRs != false && $oRs->recordCount() > 0) {
03029             while ( !$oRs->EOF ) {
03030                 $sIn .= ", '".current( $oRs->fields )."' ";
03031                 $oRs->moveNext();
03032             }
03033         }
03034 
03035         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03036         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03037 
03038         // building sql (optimized)
03039         $sQ = "select distinct {$sArtTable}.* from (
03040                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03041                ) as suborder
03042                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03043                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03044                where {$sArtTable}.oxid not in ( {$sIn} )
03045                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03046 
03047         /* non optimized, but could be used if index forcing is not supported
03048         // building sql
03049         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03050                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03051                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03052                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03053                and ".$this->getSqlActiveSnippet();
03054         */
03055 
03056         return $sQ;
03057     }
03058 
03068     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03069     {
03070         $sCategoryView = getViewName('oxcategories');
03071         $sO2CView = getViewName('oxobject2category');
03072         $sLangPrefix = (($this->getLanguage())?'_'.$this->getLanguage():'');
03073         if (!$dPriceFromTo) {
03074             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03075             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03076             $sSelect .= "where oxobject2category.oxcatnid='$sCatId' and oxobject2category.oxobjectid='$sOXID' ";
03077             $sSelect .= "and oxcategories.oxactive$sLangPrefix = 1 order by oxobject2category.oxtime ";
03078         } else {
03079             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03080             $sSelect .= "oxcategories.oxid='$sCatId' and '$dPriceFromTo' >= oxcategories.oxpricefrom and ";
03081             $sSelect .= "'$dPriceFromTo' <= oxcategories.oxpriceto ";
03082         }
03083         return $sSelect;
03084     }
03085 
03091     protected function _getAmountPriceList()
03092     {
03093         if ($this->_oAmountPriceList) {
03094             return $this->_oAmountPriceList;
03095         }
03096 
03097         $myConfig = $this->getConfig();
03098 
03099         $sArtID  = $this->getId();
03100 
03101         // #1690C - Scale prices and variants
03102         if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03103             $sArtID = $this->oxarticles__oxparentid->value;
03104         }
03105 
03106         // echo( "TODO replace oxlist usage here _collectAmPriceList".PHP_EOL);
03107         $sArtID = mysql_real_escape_string($sArtID);
03108 
03109         //collecting assigned to article amount-price list
03110         $oAmPriceList = oxNew( 'oxlist');
03111         $oAmPriceList->init('oxbase', 'oxprice2article');
03112 
03113         $sShopID = $myConfig->getShopID();
03114         if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03115             $sShopSelect = '1';
03116         } else {
03117             $sShopSelect = " oxshopid =  '$sShopID' ";
03118         }
03119 
03120         $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03121 
03122         // prepare abs prices if currently having percentages
03123         $oBasePrice = $this->_getGroupPrice();
03124         foreach ($oAmPriceList as $oAmPrice) {
03125             if ($oAmPrice->oxprice2article__oxaddperc->value) {
03126                 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03127             }
03128         }
03129 
03130         $this->_oAmountPriceList = $oAmPriceList;
03131         return $oAmPriceList;
03132     }
03133 
03141     protected function _isFieldEmpty($sFieldName)
03142     {
03143         $mValue = $this->$sFieldName->value;
03144 
03145         if (is_null($mValue)) {
03146             return true;
03147         }
03148 
03149         if ($mValue === '') {
03150             return true;
03151         }
03152 
03153         if ($mValue == '0000-00-00 00:00:00' || $mValue == '0000-00-00') {
03154             return true;
03155         }
03156 
03157         $sFieldName = strtolower($sFieldName);
03158 
03159         if ($mValue == "nopic_ico.jpg" && $sFieldName == 'oxarticles__oxicon') {
03160             return true;
03161         }
03162 
03163         if ($mValue == "nopic.jpg" && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom')) {
03164             return true;
03165         }
03166 
03167         return false;
03168     }
03169 
03177     protected function _assignParentFieldValue($sFieldName)
03178     {
03179         if (!($oParentArticle = $this->_getParentAricle())) {
03180             return;
03181         }
03182 
03183         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03184 
03185         // assigning only theese which parent article has
03186         if ( $oParentArticle->$sCopyFieldName != null ) {
03187 
03188             // only overwrite database values
03189             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03190                 continue;
03191             }
03192 
03193             //do not copy certain fields
03194             $aNonCopyFields = array('oxarticles__oxinsert',
03195                                     'oxarticles__oxtimestamp',
03196                                     'oxarticles__oxnid',
03197                                     'oxarticles__oxid',
03198                                     'oxarticles__oxparentid');
03199 
03200             $aDoubleCopyFields = array('oxarticles__oxprice',
03201                                        'oxarticles__oxvat');
03202 
03203             $aCopyParentField = array('oxarticles__oxnonmaterial',
03204                                       'oxarticles__oxfreeshipping',
03205                                       'oxarticles__oxremindactive');
03206 
03207             if (in_array($sCopyFieldName, $aNonCopyFields)) {
03208                 return;
03209             }
03210 
03211 
03212 
03213             //do not copy parent data for icons in case we have (need) own variant icon (in case variant thumbnail exists)
03214             if ($sFieldName == "oxicon" && !$this->_isFieldEmpty("oxarticles__oxthumb") && $this->oxarticles__oxthumb->value != $oParentArticle->oxarticles__oxthumb->value && $this->getConfig()->getConfigParam( 'blAutoIcons' ) ) {
03215                 return ;
03216             }
03217 
03218             //COPY THE VALUE
03219             //replaced the code bellow with this two liner
03220             //T2009-01-12
03221             if ($this->_isFieldEmpty($sCopyFieldName) || in_array($sCopyFieldName, $aCopyParentField)) {
03222                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03223             }
03224 
03225 
03226             /*
03227             //#1101S empty image fields (without nopic.jpg, nopic_ico.jpg) should be copied from parent too
03228             if ( $this->$sCopyFieldName->value == 'nopic.jpg' || $this->$sCopyFieldName->value == 'nopic_ico.jpg' || ((stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') || stristr($sCopyFieldName, '_oxpic') || stristr($sCopyFieldName, '_oxzoom') ) && $this->$sCopyFieldName->value == '')) {
03229                 // pictures
03230                 if ( $this->_blLoadParentData && $this->isAdmin() ) {
03231                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03232                 } else {
03233                     $aFile = explode( '/', $oParentArticle->$sCopyFieldName->value);
03234                     $this->$sCopyFieldName->setValue(basename);
03235                 }
03236             } elseif ( $this->$sCopyFieldName->value == '' ||
03237                     $this->$sCopyFieldName->value == '0000-00-00 00:00:00' ||
03238                     $this->$sCopyFieldName->value == '0000-00-00' ||
03239                     ( in_array($sCopyFieldName, $aDoubleCopyFields) && $this->$sCopyFieldName->value == 0)
03240                    ) {
03241                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03242             }
03243 
03244             //another fields which should be copied from parent if empty and not covered by above condition
03245             $aCopyParentField = array('oxarticles__oxnonmaterial',
03246                                       'oxarticles__oxfreeshipping',
03247                                       'oxarticles__oxremindactive');
03248             if (!$this->$sCopyFieldName->value && in_array($sCopyFieldName, $aCopyParentField)) {
03249                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03250             }*/
03251         }
03252     }
03253 
03259     protected function _getParentAricle()
03260     {
03261         $sParentId = $this->oxarticles__oxparentid->value;
03262         if (!$sParentId) {
03263             return null;
03264         }
03265         if (isset(self::$_aLoadedParents[$sParentId])) {
03266             return self::$_aLoadedParents[$sParentId];
03267         } else {
03268             $oParentArticle = oxNew( 'oxarticle' );
03269             $oParentArticle->_blSkipAbPrice = true;
03270             $oParentArticle->_blLoadPrice = false;
03271             $oParentArticle->_blLoadVariants = false;
03272             $oParentArticle->load( $sParentId);
03273             self::$_aLoadedParents[$sParentId] = $oParentArticle;
03274             return $oParentArticle;
03275         }
03276     }
03277 
03283     protected function _assignParentFieldValues()
03284     {   startProfile('articleAssignParentInternal');
03285         if ( $this->oxarticles__oxparentid->value) {
03286             // yes, we are in fact a variant
03287             if ( !$this->isAdmin() || ($this->_blLoadParentData && $this->isAdmin() ) ) {
03288                 foreach ($this->_aFieldNames as $sFieldName => $sVal) {
03289                     $this->_assignParentFieldValue($sFieldName);
03290                 }
03291 
03292                 //assing long description
03293                 $oParentArticle = $this->_getParentAricle();
03294                 if ( !$this->oxarticles__oxlongdesc->value ) {
03295                     $this->oxarticles__oxlongdesc = $oParentArticle->oxarticles__oxlongdesc;
03296                 }
03297             }
03298         } elseif ( $this->oxarticles__oxid->value ) {
03299             // I am not a variant but I might have some
03300             //$this->_oVariantList = $this->getSimpleVariants();
03301             startProfile("loadVariants");
03302             $this->_oVariantList = $this->getVariants();
03303             stopProfile("loadVariants");
03304             // #1650M - article title with <br> tag
03305             // htmlspecialchars parses only 5 characters, so i have stiped out '<' and '>'
03306             /*
03307             if ( !$this->isAdmin() ) {
03308                 $this->oxarticles__oxtitle->setValue(str_replace(array('&', "'", '"'), array('&amp;', '&#039;', '&quot;'), $this->oxarticles__oxtitle->value));
03309             }*/
03310         }
03311         stopProfile('articleAssignParentInternal');
03312 
03313     }
03314 
03320     protected function _assignNotBuyableParent()
03321     {
03322         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03323              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03324             $this->_blNotBuyableParent = true;
03325 
03326         }
03327     }
03328 
03334     protected function _assignPictureValues()
03335     {
03336         $myConfig = $this->getConfig();
03337         $this->oxarticles__oxicon = new oxField($this->_getIcon());
03338 
03339         // picture isset($this->_aFieldNames["thumb"]) && re handling
03340         $sNoPic     = 'nopic.jpg';
03341         $sNoPicIcon = 'nopic_ico.jpg';
03342 
03343         if ( isset($this->_aFieldNames["oxthumb"]) && !$this->oxarticles__oxthumb->value) {
03344             $this->oxarticles__oxthumb = new oxField($sNoPic);
03345         }
03346         /*
03347         if( isset($this->_aFieldNames["oxicon"]) && !isset($this->oxarticles__oxicon->value))
03348             $this->oxarticles__oxicon  = new oxField($sNoPicIcon);
03349         */
03350 
03351         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03352         for ( $i=1; $i<= $iPicCount; $i++ ) {
03353             if ( isset($this->_aFieldNames["oxpic".$i]) &&  !$this->{'oxarticles__oxpic'.$i}->value ) {
03354                 $this->{'oxarticles__oxpic'.$i} = new oxField($sNoPic);
03355             }
03356         }
03357 
03358         $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
03359         for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03360             if ( isset($this->_aFieldNames["oxzoom".$i]) &&  !$this->{'oxarticles__oxzoom'.$i}->value) {
03361                 $this->{'oxarticles__oxzoom'.$i} = new oxField($sNoPic);
03362             }
03363         }
03364 
03365         if ( !$this->isAdmin() ) {
03366             // add directories
03367             if ( isset($this->_aFieldNames["oxthumb"])) {
03368                 $this->oxarticles__oxthumb->setValue('0/'.basename($this->oxarticles__oxthumb->value));
03369             }
03370             if ( isset($this->_aFieldNames["oxicon"])) {
03371                 $this->oxarticles__oxicon = new oxField('icon/'.basename($this->oxarticles__oxicon->value));
03372             }
03373 
03374             $myUtilsPic = oxUtilsPic::getInstance();
03375             for ( $i=1; $i<= $iPicCount; $i++ ) {
03376                 $sFieldName = 'oxarticles__oxpic'.$i;
03377                 if ( isset($this->_aFieldNames["oxpic".$i])) {
03378                     $sIconFieldName = 'oxarticles__oxpic'.$i.'_ico';
03379                     $this->$sIconFieldName = new oxField($i.'/'.basename($myUtilsPic->iconName($this->$sFieldName->value)));
03380                     $this->$sFieldName     = new oxField($i.'/'.basename($this->$sFieldName->value));
03381                 }
03382             }
03383             for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03384                 if ( isset($this->_aFieldNames["oxzoom".$i])) {
03385                     $this->{'oxarticles__oxzoom'.$i} = new oxField('z'.$i.'/'.basename($this->{'oxarticles__oxzoom'.$i}->value));
03386                 }
03387             }
03388         }
03389 
03390     }
03391 
03397     protected function _assignStock()
03398     {
03399         $myConfig = $this->getConfig();
03400         // -----------------------------------
03401         // stock
03402         // -----------------------------------
03403 
03404         // #1125 A. must round (using floor()) value taken from database and cast to int
03405         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03406             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03407         }
03408         //GREEN light
03409         $this->_iStockStatus = 0;
03410 
03411         // if we have flag /*1 or*/ 4 - we show always green light
03412         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03413             //ORANGE light
03414             $iStock = $this->oxarticles__oxstock->value;
03415 
03416             if ($this->_blNotBuyableParent) {
03417                 $iStock = $this->oxarticles__oxvarstock->value;
03418             }
03419 
03420 
03421             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03422                 $this->_iStockStatus = 1;
03423             }
03424 
03425             //RED light
03426             if ($iStock <= 0) {
03427                 $this->_iStockStatus = -1;
03428             }
03429         }
03430 
03431 
03432         // stock
03433         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstock->value <= 0 && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03434             $this->_blNotBuyable = true;
03435         }
03436 
03437         //exceptional handling for variant parent stock:
03438         if ($this->_blNotBuyable && $this->_iVarStock) {
03439             $this->_blNotBuyable = false;
03440             //but then at least setting notBuaybleParent to true
03441             $this->_blNotBuyableParent = true;
03442         }
03443 
03444         //special treatment for lists when blVariantParentBuyable config option is set to false
03445         //then we just hide "to basket" button.
03446         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03447         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03448             $this->_blNotBuyable = true;
03449         }
03450 
03451         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03452         if ($this->_blNotBuyableParent && count($this->_oVariantList) == 0) {
03453             $this->_blNotBuyable = true;
03454         }
03455     }
03456 
03462     protected function _assignPrices()
03463     {
03464         $myConfig = $this->getConfig();
03465 
03466         // Performance
03467         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03468             return;
03469         }
03470 
03471 
03472         // compute price
03473         $dPrice = $this->getPrice()->getBruttoPrice();
03474 
03475         $oCur = $myConfig->getActShopCurrencyObject();
03476         //price per unit handling
03477         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03478             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03479         }
03480 
03481 
03482         //getting min and max prices of variants
03483         $this->_applyRangePrice();
03484     }
03485 
03491     protected function _assignPersistentParam()
03492     {
03493         // Persistent Parameter Handling
03494         $aPersParam     = oxSession::getVar( 'persparam');
03495         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03496             $this->_aPersistParam = $aPersParam[$this->getId()];
03497         }
03498     }
03499 
03505     protected function _assignDynImageDir()
03506     {
03507         $myConfig = $this->getConfig();
03508 
03509         $sThisShop = $this->oxarticles__oxshopid->value;
03510 
03511         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03512         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03513         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03514         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03515     }
03516 
03522     protected function _assignComparisonListFlag()
03523     {
03524         // #657 add a flag if article is on comparisonlist
03525 
03526         $aItems = oxConfig::getParameter('aFiltcompproducts');
03527         if ( isset( $aItems[$this->getId()])) {
03528             $this->_blIsOnComparisonList = true;
03529         }
03530     }
03531 
03537     protected function _assignAttributes()
03538     {
03539         //#1029T load attributes
03540         //#1078S removed check for module "Produktvergleich"
03541         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03542             $this->getAttributes();
03543         }
03544     }
03545 
03546 
03552     protected function _assignLinks()
03553     {
03554         $myConfig = $this->getConfig();
03555 
03556         // and assign special article values
03557         $sURL       = $myConfig->getShopHomeURL();
03558         $sActCat    = oxConfig::getParameter( 'cnid' );
03559         $sActClass  = oxConfig::getParameter( 'cl' );
03560         $sTPL       = basename( oxConfig::getParameter( 'tpl' ) );
03561 
03562         // override some classes as these should never showup
03563         if ( $sActClass == 'thankyou') {
03564             $sActClass = 'basket';
03565         }
03566 
03567         $sCnid = '';
03568 
03569         // this is not very correct
03570         if ($sActCat) {
03571             $sCnid = '&amp;cnid='.$sActCat;
03572         }
03573 
03574         $this->_sDetailLink     = $this->getLink();
03575 
03576         // mallchange to make sure
03577         // MALL OFF
03578         /*if( $myConfig->isMall() && !$this->InShop())
03579             $this->oxdetaillink .= "&amp;cshp=".$this->oxarticles__oxshopid->value;*/
03580 
03581         $this->_sMoreDetailLink = $sURL. 'cl=moredetails&amp;cnid='.$sActCat.'&amp;anid='.$this->getId();
03582 
03583         if ( oxUtils::getInstance()->isSearchEngine() ) {
03584             $this->_sToBasketLink = $this->_sDetailLink;
03585         } else {
03586             $this->_sToBasketLink = $sURL. 'cl='.$sActClass.'&amp;fnc=tobasket'.$sCnid.'&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
03587         }
03588 
03589 
03590         if ( isset( $sTPL) && $sTPL) {
03591             $this->_sToBasketLink .=  '&amp;tpl='.$sTPL;
03592         }
03593     }
03594 
03602     protected function _insert()
03603     {
03604         // set oxinsert
03605         $iInsertTime = time();
03606         $now = date('Y-m-d H:i:s', $iInsertTime);
03607         $this->oxarticles__oxinsert    = new oxField( $now );
03608         $this->oxarticles__oxtimestamp = new oxField( $now );
03609         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03610             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03611         }
03612 
03613         return parent::_insert();
03614     }
03615 
03621     protected function _update()
03622     {
03623 
03624         $myConfig = $this->getConfig();
03625 
03626 
03627         $this->_skipSaveFields();
03628 
03629         return parent::_update();
03630     }
03631 
03639     protected function _deleteRecords($sOXID)
03640     {
03641 
03642         //delete the record
03643         $oDB = oxDb::getDb();
03644         $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = \''.$sOXID.'\' ';
03645         $oDB->execute( $sDelete);
03646 
03647         //remove other records
03648         $sDelete = 'delete from oxobject2article where oxarticlenid = \''.$sOXID.'\' or oxobjectid = \''.$sOXID.'\' ';
03649         $oDB->execute( $sDelete);
03650 
03651         $sDelete = 'delete from oxobject2attribute where oxobjectid = \''.$sOXID.'\' ';
03652         $oDB->execute( $sDelete);
03653 
03654         $sDelete = 'delete from oxobject2category where oxobjectid = \''.$sOXID.'\' ';
03655         $oDB->execute( $sDelete);
03656 
03657         $sDelete = 'delete from oxobject2selectlist where oxobjectid = \''.$sOXID.'\' ';
03658         $oDB->execute( $sDelete);
03659 
03660         $sDelete = 'delete from oxprice2article where oxartid = \''.$sOXID.'\' ';
03661         $oDB->execute( $sDelete);
03662 
03663         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = \''.$sOXID.'\' ';
03664         $oDB->execute( $sDelete);
03665 
03666         $sDelete = 'delete from oxaccessoire2article where oxobjectid = "'.$sOXID.'" or oxarticlenid = "'.$sOXID.'" ';
03667         $oDB->execute( $sDelete);
03668 
03669         //#1508C - deleting oxobject2delivery entries added
03670         $sDelete = 'delete from oxobject2delivery where oxobjectid = \''.$sOXID.'\' and oxtype=\'oxarticles\' ';
03671         $oDB->execute( $sDelete);
03672 
03673         $sDelete = 'delete from oxartextends where oxid = \''.$sOXID.'\' ';
03674         $oDB->execute( $sDelete);
03675 
03676         $sDelete = 'delete from oxactions2article where oxartid = \''.$sOXID.'\' ';
03677         $rs = $oDB->execute( $sDelete );
03678 
03679 
03680         return $rs;
03681     }
03682 
03690     protected function _deleteVariantRecords($sOXID)
03691     {
03692         $oDB = oxDb::getDb();
03693         //collect variants to remove recursively
03694         $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = \''.$sOXID.'\'';
03695         $rs = $oDB->execute( $sVariants);
03696         if ($rs != false && $rs->recordCount() > 0) {
03697             while (!$rs->EOF) {
03698                 $this->delete( $rs->fields[0]);
03699                 $rs->moveNext();
03700             }
03701         }
03702     }
03703 
03713     protected function _resetCacheAndArticleCount( $sOxid )
03714     {
03715         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03716     }
03717 
03723     protected function _deletePics()
03724     {
03725         $myUtilsPic = oxUtilsPic::getInstance();
03726         $myConfig   = $this->getConfig();
03727 
03728         // #1173M - not all pic are deleted, after article is removed
03729         $blThumbDeleted = $myUtilsPic->safePictureDelete( $this->oxarticles__oxthumb->value, $myConfig->getAbsDynImageDir().'/0', 'oxarticles', 'oxthumb' );
03730 
03731         if ( $blThumbDeleted ) {
03732             $myUtilsPic->safePictureDelete('icon/'.$this->oxarticles__oxicon->value, $myConfig->getAbsDynImageDir(), 'oxarticles', 'oxicon' );
03733         }
03734         //removed and replaced with savePcitureDelete MAFI
03735         //if( $blThumbDeleted && $myUtilsPic->isPicDeletable( $this->oxarticles__oxthumb->value, 'oxarticles', 'oxicon' )) {
03736             //TODO: is it correct that oxarticles__oxthumb is checked and oxarticles__oxicon deleted? if not replace this with safePictureDelete MAFI
03737          //   $myUtilsPic->deletePicture( 'icon/'.$this->oxarticles__oxicon->value, $myConfig->getAbsDynImageDir(), '' $myConfig->getConfigParam( 'blIsOXDemoShop' ));
03738         //}
03739 
03740         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03741         $sAbsDynImageDir = $myConfig->getAbsDynImageDir();
03742         for ( $i = 1; $i <= $iPicCount; $i++ ) {
03743             // Getting coresponding pic's filename value
03744             $sPicFName = $this->{'oxarticles__oxpic'.$i}->value;
03745             $myUtilsPic->safePictureDelete($sPicFName, $sAbsDynImageDir.'/'.$i, 'oxarticles', 'oxpic'.$i );
03746         }
03747         // deleting zoom images
03748         $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
03749         for ( $i = 1; $i <= $iZoomPicCount; $i++ ) {
03750             if ( isset($this->{'oxarticles__oxzoom'.$i}) ) {
03751                 $myUtilsPic->safePictureDelete($this->{'oxarticles__oxzoom'.$i}->value, $sAbsDynImageDir.'/z'.$i, 'oxarticles', 'oxzoom'.$i );
03752             }
03753         }
03754 
03755     }
03756 
03766     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
03767     {
03768 
03769         $myUtilsCount = oxUtilsCount::getInstance();
03770 
03771         if ( $sVendorId ) {
03772             $myUtilsCount->resetVendorArticleCount( $sVendorId );
03773         }
03774 
03775         if ( $sManufacturerId ) {
03776             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
03777         }
03778 
03779         //also reseting category counts
03780         $sQ = "select oxcatnid from oxobject2category where oxobjectid = '{$sOxid}'";
03781         $oRs = oxDb::getDb()->execute( $sQ );
03782         if ( $oRs !== false && $oRs->recordCount() > 0) {
03783             while ( !$oRs->EOF ) {
03784                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
03785                 $oRs->moveNext();
03786             }
03787         }
03788     }
03789 
03797     protected function _onChangeUpdateStock( $sParentID )
03798     {
03799         $oDb = oxDb::getDb();
03800         $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = \''.$sParentID.'\' ';
03801         $rs = $oDb->execute($sQ);
03802         $iOldStock = $rs->fields[0];
03803         $iVendorID = $rs->fields[1];
03804         $iManufacturerID = $rs->fields[2];
03805 
03806         $sQ = 'select sum(oxstock) from oxarticles where oxparentid = \''.$sParentID.'\' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
03807         $iStock = (float) $oDb->getOne( $sQ );
03808 
03809         $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = \''.$sParentID.'\'';
03810         $oDb->execute( $sQ );
03811 
03812             //now lets update category counts
03813             //first detect stock status change for this article (to or from 0)
03814             if ( $iStock < 0 ) {
03815                 $iStock = 0;
03816             }
03817             if ( $iOldStock < 0 ) {
03818                 $iOldStock = 0;
03819             }
03820             if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
03821                 //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
03822                 // so far we leave it like this but later we could move all count resets to one or two functions
03823                 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
03824             }
03825     }
03826 
03834     protected function _onChangeUpdateVarCount( $sParentID )
03835     {
03836         $oDb = oxDb::getDb();
03837         $sQ = 'select count(*) as varcount from oxarticles where oxparentid = \''.$sParentID.'\' ';
03838         $iVarCount = (int) $oDb->getOne($sQ);
03839 
03840         $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = \''.$sParentID.'\'';
03841         $oDb->execute($sQ);
03842     }
03843 
03851     protected function _onChangeUpdateMinVarPrice( $sParentID )
03852     {
03853         $sQ = 'select min(oxprice) as varminprice from oxarticles where oxparentid = "'.$sParentID.'"';
03854         //V #M378: Quicksorting after price in articlelist does not work correctly when parent article is not buyable
03855         if ( !$this->isParentNotBuyable() || $this->oxarticles__oxvarcount->value == 0) {
03856             $sQ .= ' or oxid = "'.$sParentID.'"';
03857         }
03858 
03859         $oDb = oxDb::getDb();
03860         $dVarMinPrice = $oDb->getOne($sQ);
03861         if ( $dVarMinPrice ) {
03862             $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = "'.$sParentID.'"';
03863             $oDb->execute($sQ);
03864         }
03865     }
03866 
03867 
03873     protected function _applyRangePrice()
03874     {
03875         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
03876         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03877             return;
03878         }
03879 
03880         $this->_blIsRangePrice = false;
03881 
03882         if ($this->_blSkipAbPrice && !$this->_blNotBuyableParent) {
03883             return;
03884         }
03885 
03886         $aPrices = array();
03887 
03888         if (!$this->_blNotBuyableParent) {
03889             $aPrices[] = $this->getPrice()->getBruttoPrice();
03890         }
03891 
03892         if (count($this->_oVariantList)) {
03893             foreach ($this->_oVariantList as $sKey => $oVariant) {
03894                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
03895             }
03896         }
03897 
03898         /*  $oAmPrices = $this->loadAmountPriceInfo();
03899         foreach ($oAmPrices as $oAmPrice) {
03900             $aPrices[] = $oAmPrice->oxprice2article__oxaddabs->value;
03901         }*/
03902 
03903         if (count($aPrices)) {
03904             $dMinPrice = $aPrices[0];
03905             $dMaxPrice = $aPrices[0];
03906             foreach ($aPrices as $dPrice) {
03907                 if ($dMinPrice > $dPrice) {
03908                     $dMinPrice = $dPrice;
03909                 }
03910 
03911                 if ($dMaxPrice < $dPrice) {
03912                     $dMaxPrice = $dPrice;
03913                 }
03914             }
03915         }
03916 
03917         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
03918             $this->getPrice()->setBruttoPriceMode();
03919             $this->getPrice()->setPrice($dMinPrice);
03920         }
03921 
03922         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
03923             $this->getPrice()->setBruttoPriceMode();
03924             $this->getPrice()->setPrice($dMinPrice);
03925             $this->_blIsRangePrice = true;
03926         }
03927 
03928         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
03929             $this->getPrice()->setBruttoPriceMode();
03930             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
03931             $this->_blIsRangePrice = true;
03932         }
03933     }
03934 }

Generated on Tue Apr 21 15:45:44 2009 for OXID eShop CE by  doxygen 1.5.5