oxarticle.php

Go to the documentation of this file.
00001 <?php
00002 
00003 // defining supported link types
00004 define( 'OXARTICLE_LINKTYPE_CATEGORY', 0 );
00005 define( 'OXARTICLE_LINKTYPE_VENDOR', 1 );
00006 define( 'OXARTICLE_LINKTYPE_MANUFACTURER', 2 );
00007 define( 'OXARTICLE_LINKTYPE_PRICECATEGORY', 3 );
00008 define( 'OXARTICLE_LINKTYPE_TAG', 4 );
00009 define( 'OXARTICLE_LINKTYPE_RECOMM', 5 );
00010 
00017 class oxArticle extends oxI18n implements oxIArticle, oxIUrl
00018 {
00024     protected $_sCoreTbl = 'oxarticles';
00025 
00031     protected $_sClassName = 'oxarticle';
00032 
00038     protected $_blUseLazyLoading = true;
00039 
00045     protected $_sItemKey;
00046 
00052     protected $_blCalcPrice    = true;
00053 
00058     protected $_oPrice      = null;
00059 
00065     protected $_dArticleVat = null;
00066 
00072     protected $_aPersistParam  = null;
00073 
00079     protected $_blNotBuyable   = false;
00080 
00087     protected $_blLoadVariants = true;
00088 
00094     protected $_aVariants = null;
00095 
00101     protected $_aVariantsWithNotOrderables = null;
00102 
00111     protected $_blNotBuyableParent  = false;
00112 
00117     protected $_blHasVariants = false;
00118 
00122     protected $_blHasMdVariants = false;
00123 
00127     protected $_iVarStock = 0;
00128 
00133     protected $_oVariantList   = array();
00134 
00139     protected $_blIsOnComparisonList = false;
00140 
00145     protected $_oUser = null;
00146 
00152     protected $_blLoadPrice = true;
00153 
00157     protected $_blSkipAbPrice = false;
00158 
00165     protected $_fPricePerUnit = null;
00166 
00170     protected $_blLoadParentData = false;
00171 
00175     protected $_blSkipAssign = false;
00176 
00182     protected $_blSkipDiscounts = null;
00183 
00188     protected $_oAttributeList = null;
00189 
00190 
00196     protected $_blIsRangePrice = false;
00197 
00203     protected $_aMediaUrls = null;
00204 
00210     static protected $_aLoadedParents;
00211 
00217     static protected $_aSelList;
00218 
00224     protected $_aDispSelList;
00225 
00231     protected $_blIsSeoObject = true;
00232 
00238     protected $_oAmountPriceList = null;
00239 
00248     protected $_iLinkType = 0;
00249 
00255     protected $_aStdUrls = array();
00256 
00262     protected $_aSeoUrls = array();
00263 
00269     protected $_aSeoAddParams = array();
00270 
00276     protected $_aStdAddParams = array();
00277 
00283     protected $_sDynImageDir = null;
00284 
00290     protected $_sMoreDetailLink = null;
00291 
00297     protected $_sToBasketLink = null;
00298 
00304     protected $_iStockStatus = null;
00305 
00311     protected $_oTPrice = null;
00312 
00318     protected $_oAmountPriceInfo = null;
00319 
00325     protected $_dAmountPrice = null;
00326 
00332     protected static $_aArticleManufacturers = array();
00333 
00339     protected static $_aArticleVendors = array();
00340 
00346     protected static $_aArticleCats = array();
00347 
00353     protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00354                                              'oxarticles__oxtimestamp',
00355                                              'oxarticles__oxnid',
00356                                              'oxarticles__oxid',
00357                                              'oxarticles__oxparentid');
00358 
00364     protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00365                                          'oxarticles__oxfreeshipping',
00366                                          'oxarticles__oxremindactive');
00367 
00373     protected $_oMdVariants = null;
00374 
00383     public function __construct($aParams = null)
00384     {
00385         if ( $aParams && is_array($aParams)) {
00386             foreach ( $aParams as $sParam => $mValue) {
00387                 $this->$sParam = $mValue;
00388             }
00389         }
00390         parent::__construct();
00391         $this->init( 'oxarticles' );
00392 
00393         $this->_blIsRangePrice = false;
00394     }
00395 
00403     public function __isset( $sName )
00404     {
00405         if ( $sName == 'oxarticles__oxlongdesc' ) {
00406             //get empty oxlongdesc field
00407             $this->getArticleLongDesc();
00408             return true;
00409         }
00410         return isset( $this->$sName );
00411     }
00412 
00421     public function __get($sName)
00422     {
00423         $myUtils = oxUtils::getInstance();
00424         switch ($sName) {
00425             // NOT using caching here, because of these params should be used in templates ONLY
00426             // and in template files they are used not very much [once most of the time]
00427 
00428             // price related
00429             case 'netprice':
00430             case 'netPrice':
00431                 $mVal = $myUtils->fRound($this->getPrice()->getNettoPrice());
00432                 break;
00433             case 'brutPrice':
00434                 return $myUtils->fRound($this->getPrice()->getBruttoPrice());
00435                 break;
00436             case 'vatPercent':
00437                 return $this->getPrice()->getVAT();
00438                 break;
00439             case 'vat':
00440                 return $this->getPrice()->getVATValue();
00441                 break;
00442             case 'fnetprice':
00443                 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($this->getPrice()->getNettoPrice()));
00444                 break;
00445             case 'fprice':
00446                 return $this->getFPrice();
00447                 break;
00448 
00449             // t price related
00450             case 'dtprice':
00451                 if ( $oPrice = $this->getTPrice() ) {
00452                     return $myUtils->fRound($oPrice->getBruttoPrice());
00453                     break;
00454                 } else {
00455                     return null;
00456                     break;
00457                 }
00458             case 'tvat':
00459                 if ( $oPrice = $this->getTPrice() ) {
00460                     return $oPrice->getVATValue();
00461                     break;
00462                 } else {
00463                     return null;
00464                     break;
00465                 }
00466             case 'ftprice':
00467                 if ( $oPrice = $this->getTPrice() ) {
00468                     return oxLang::getInstance()->formatCurrency( $myUtils->fRound($oPrice->getBruttoPrice()) );
00469                     break;
00470                 } else {
00471                     return null;
00472                     break;
00473                 }
00474             case 'oxarticles__oxlongdesc':
00475                 return $this->getArticleLongDesc($this->getId());
00476                 break;
00477             case 'foxdelivery':
00478                 return $this->getDeliveryDate();
00479                 break;
00480             case 'sItemKey':
00481                 return $this->getItemKey();
00482                 break;
00483             case 'selectlist':
00484                 return $this->_aDispSelList = $this->getDispSelList();
00485                 break;
00486             case 'blNotBuyable':
00487                 return $this->isNotBuyable();
00488                 break;
00489             case 'blNotBuyableParent':
00490                 return $this->isParentNotBuyable();
00491                 break;
00492             case 'blIsOnComparisonList':
00493                 return $this->isOnComparisonList();
00494                 break;
00495             case 'oVariantlist' :
00496                 return $this->_oVariantList;
00497                 break;
00498             case 'fPricePerUnit' :
00499                 return $this->getPricePerUnit();
00500                 break;
00501             case 'dimagedir' :
00502                 return $this->_sDynImageDir = $this->getDynImageDir();
00503                 break;
00504             case 'oxmoredetaillink' :
00505                 return $this->_sMoreDetailLink = $this->getMoreDetailLink();
00506                 break;
00507             case 'amountpricelist' :
00508                 return $this->loadAmountPriceInfo();
00509                 break;
00510             case 'stockstatus' :
00511                 return $this->getStockStatus();
00512                 break;
00513             case 'tobasketlink' :
00514                 return $this->getToBasketLink();
00515                 break;
00516             case 'oxdetaillink' :
00517                 return $this->getLink();
00518                 break;
00519             case 'aSelectlist' :
00520                 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00521                     return $this->aSelectlist = $this->getSelectLists();
00522                 }
00523                 return;
00524                 break;
00525             /*case 'oxarticles__oxnid':
00526                 return $this->getId();*/
00527         }
00528 
00529         $this->$sName = parent::__get($sName);
00530         if ( $this->$sName ) {
00531             $this->_assignParentFieldValue($sName);
00532         }
00533 
00534         //checking for picture information
00535         if ($sName == "oxarticles__oxthumb" || $sName == "oxarticles__oxicon" || (strpos($sName, "oxarticles__oxpic") === 0 && $sName != "oxarticles__oxpicsgenerated") || strpos($sName, "oxarticles__oxzoom") === 0) {
00536             $this->_assignPictureValues( $sName );
00537             return $this->$sName;
00538         }
00539 
00540         return $this->$sName;
00541     }
00542 
00550     public function setId( $sId = null )
00551     {
00552         $sId = parent::setId( $sId );
00553 
00554         // TODO: in oxbase::setId make it to check if exists and update, not recreate, then delete this overload
00555         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00556 
00557         return $sId;
00558     }
00559 
00567     public function getTableNameForActiveSnippet( $blForceCoreTable = false )
00568     {
00569             $sTable = $this->getCoreTableName();
00570 
00571         return $sTable;
00572     }
00573 
00583     public function getActiveCheckQuery( $blForceCoreTable = false )
00584     {
00585         $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00586 
00587         // check if article is still active
00588         $sQ = " $sTable.oxactive = 1 ";
00589 
00590         // enabled time range check ?
00591         if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00592             $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00593             $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00594         }
00595 
00596         return $sQ;
00597     }
00598 
00612     public function getStockCheckQuery( $blForceCoreTable = false )
00613     {
00614         $myConfig = $this->getConfig();
00615         $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00616 
00617         $sQ = "";
00618 
00619         //do not check for variants
00620         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00621             $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0  ) ";
00622             //V #M513: When Parent article is not purchaseble, it's visibility should be displayed in shop only if any of Variants is available.
00623             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00624                 $sTimeCheckQ = '';
00625                 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00626                      $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00627                      $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00628                 }
00629                 $sQ = " $sQ and IF( $sTable.oxvarcount = 0, 1, ( select 1 from $sTable as art where art.oxparentid=$sTable.oxid and ( art.oxactive = 1 $sTimeCheckQ ) and ( art.oxstockflag != 2 or art.oxstock > 0 ) limit 1 ) ) ";
00630             }
00631         }
00632 
00633         return $sQ;
00634     }
00635 
00647     public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = false  )
00648     {
00649         $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00650         $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00651 
00652         //checking if variant is active and stock status
00653         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00654             $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00655             if ( $blRemoveNotOrderables ) {
00656                 $sQ .= " and $sTable.oxstockflag != 3 ";
00657             }
00658             $sQ .= " ) ) ";
00659         }
00660 
00661         return $sQ;
00662     }
00663 
00671     public function getSqlActiveSnippet( $blForceCoreTable = false )
00672     {
00673         $myConfig = $this->getConfig();
00674 
00675         // check if article is still active
00676         $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00677 
00678         // stock and variants check
00679         $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00680 
00681 
00682         return "( $sQ ) ";
00683     }
00684 
00692     public function setSkipAssign($blSkipAssign)
00693     {
00694         $this->_blSkipAssign = $blSkipAssign;
00695     }
00696 
00704     public function disablePriceLoad( $oArticle )
00705     {
00706         $oArticle->_blLoadPrice = false;
00707     }
00708 
00714     public function getItemKey()
00715     {
00716         return $this->_sItemKey;
00717     }
00718 
00726     public function setItemKey($sItemKey)
00727     {
00728         $this->_sItemKey = $sItemKey;
00729     }
00730 
00738     public function setNoVariantLoading( $blLoadVariants )
00739     {
00740         $this->_blLoadVariants = !$blLoadVariants;
00741     }
00742 
00748     public function isBuyable()
00749     {
00750         if ($this->_blNotBuyableParent) {
00751             return false;
00752         }
00753 
00754         return !$this->_blNotBuyable;
00755     }
00756 
00762     public function getPersParams()
00763     {
00764         return $this->_aPersistParam;
00765     }
00766 
00772     public function isOnComparisonList()
00773     {
00774         return $this->_blIsOnComparisonList;
00775     }
00776 
00784     public function setOnComparisonList( $blOnList )
00785     {
00786         $this->_blIsOnComparisonList = $blOnList;
00787     }
00788 
00796     public function setLoadParentData($blLoadParentData)
00797     {
00798         $this->_blLoadParentData = $blLoadParentData;
00799     }
00800 
00808     public function setSkipAbPrice( $blSkipAbPrice = null )
00809     {
00810         $this->_blSkipAbPrice = $blSkipAbPrice;
00811     }
00812 
00818     public function getSearchableFields()
00819     {
00820         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00821         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00822 
00823         return $aFields;
00824     }
00825 
00826 
00834     public function isMultilingualField($sFieldName)
00835     {
00836         switch ($sFieldName) {
00837             case "oxlongdesc":
00838             case "oxtags":
00839                 return true;
00840         }
00841 
00842         return parent::isMultilingualField($sFieldName);
00843     }
00844 
00850     public function isVisible()
00851     {
00852 
00853         // admin preview mode
00854         $myConfig  = $this->getConfig();
00855         if ( ( $sPrevId = oxConfig::getParameter( 'preview' ) ) &&
00856              ( $sAdminSid = oxUtilsServer::getInstance()->getOxCookie( 'admin_sid' ) ) ) {
00857 
00858             $oDb = oxDb::getDb();
00859             $sPrevId   = $oDb->quote( $sPrevId );
00860             $sAdminSid = $oDb->quote( $sAdminSid );
00861             $sTable    = getViewName( 'oxuser' );
00862 
00863             return (bool) $oDb->getOne( "select 1 from $sTable where MD5( CONCAT( {$sAdminSid}, {$sTable}.oxid, {$sTable}.oxpassword, {$sTable}.oxrights ) ) = $sPrevId" );
00864         }
00865 
00866         // active ?
00867         $sNow = date('Y-m-d H:i:s');
00868         if ( !$this->oxarticles__oxactive->value &&
00869              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00870                 $this->oxarticles__oxactiveto->value < $sNow
00871              )) {
00872             return false;
00873         }
00874 
00875         // stock flags
00876         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
00877            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
00878             return false;
00879         }
00880 
00881         return true;
00882     }
00883 
00892     public function assign( $aRecord)
00893     {
00894         startProfile('articleAssign');
00895 
00896 
00897         // load object from database
00898         parent::assign( $aRecord);
00899 
00900         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00901 
00902         // check for simple article.
00903         if ($this->_blSkipAssign) {
00904             return;
00905         }
00906 
00907         $this->_assignParentFieldValues();
00908         $this->_assignNotBuyableParent();
00909 
00910         $this->_assignAllPictureValues();
00911 
00912         $this->_assignStock();
00913         startProfile('articleAssignPrices');
00914         $this->_assignPrices();
00915         stopProfile('articleAssignPrices');
00916         $this->_assignPersistentParam();
00917         $this->_assignDynImageDir();
00918         $this->_assignComparisonListFlag();
00919         $this->_assignAttributes();
00920 
00921 
00922         //$this->_seoAssign();
00923 
00924         stopProfile('articleAssign');
00925     }
00926 
00937     public function load( $oxID)
00938     {
00939         // A. #1325 resetting to avoid problems when reloading (details etc)
00940         $this->_blNotBuyableParent = false;
00941 
00942         $blRet = parent::load( $oxID);
00943 
00944         // convert date's to international format
00945         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00946         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00947 
00948         return $blRet;
00949     }
00950 
00958     public function addToRatingAverage( $iRating)
00959     {
00960         $dOldRating = $this->oxarticles__oxrating->value;
00961         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00962         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00963         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00964         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00965         $dRatingCnt = (int) ($dOldCnt + 1);
00966         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00967         oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00968     }
00969 
00975     public function getArticleRatingAverage()
00976     {
00977         return round( $this->oxarticles__oxrating->value, 1);
00978     }
00979 
00985     public function getReviews()
00986     {
00987         $myConfig  = $this->getConfig();
00988 
00989         $aIds = array($this->getId());
00990 
00991         if ( $this->oxarticles__oxparentid->value ) {
00992                 $aIds[] = $this->oxarticles__oxparentid->value;
00993         }
00994 
00995         // showing variant reviews ..
00996         if ( $myConfig->getConfigParam( 'blShowVariantReviews' ) ) {
00997             $aAdd = $this->_getVariantsIds();
00998             if (is_array($aAdd)) {
00999                 $aIds = array_merge($aIds, $aAdd);
01000             }
01001         }
01002 
01003         $oReview = oxNew('oxreview');
01004         $oRevs = $oReview->loadList('oxarticle', $aIds);
01005 
01006         //if no review found, return null
01007         if ( $oRevs->count() < 1 ) {
01008             return null;
01009         }
01010 
01011         return $oRevs;
01012     }
01013 
01019     public function getCrossSelling()
01020     {
01021         $oCrosslist = oxNew( "oxarticlelist");
01022         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
01023         if ( $oCrosslist->count() ) {
01024             return $oCrosslist;
01025         }
01026     }
01027 
01033     public function getAccessoires()
01034     {
01035         $myConfig = $this->getConfig();
01036 
01037         // Performance
01038         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01039             return;
01040         }
01041 
01042         $oAcclist = oxNew( "oxarticlelist");
01043         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01044         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01045 
01046         if ( $oAcclist->count()) {
01047             return $oAcclist;
01048         }
01049     }
01050 
01056     public function getSimilarProducts()
01057     {
01058         // Performance
01059         $myConfig = $this->getConfig();
01060         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01061             return;
01062         }
01063 
01064         $sArticleTable = $this->_getObjectViewName('oxarticles');
01065 
01066         $sAttribs = '';
01067         $iCnt = 0;
01068         $this->_getAttribsString($sAttribs, $iCnt);
01069 
01070         if ( !$sAttribs) {
01071             return null;
01072         }
01073 
01074         $aList = $this->_getSimList($sAttribs, $iCnt);
01075 
01076         if ( count( $aList ) ) {
01077             uasort( $aList, 'cmpart');
01078 
01079             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01080 
01081             $oSimilarlist = oxNew( 'oxarticlelist' );
01082             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01083             $oSimilarlist->selectString( $sSearch);
01084 
01085             return $oSimilarlist;
01086         }
01087     }
01088 
01094     public function getCustomerAlsoBoughtThisProducts()
01095     {
01096         // Performance
01097         $myConfig = $this->getConfig();
01098         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01099             return;
01100         }
01101 
01102         // selecting products that fits
01103         $sQ = $this->_generateSearchStrForCustomerBought();
01104 
01105         $oArticles = oxNew( 'oxarticlelist' );
01106         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01107         $oArticles->selectString( $sQ );
01108         if ( $oArticles->count() ) {
01109             return $oArticles;
01110         }
01111     }
01112 
01119     public function loadAmountPriceInfo()
01120     {
01121         $myConfig = $this->getConfig();
01122         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01123             return array();
01124         }
01125 
01126         if ( $this->_oAmountPriceInfo === null ) {
01127             $this->_oAmountPriceInfo = array();
01128             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01129                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01130 
01131             }
01132         }
01133         return $this->_oAmountPriceInfo;
01134     }
01135 
01143     public function getSelectLists($sKeyPrefix = null)
01144     {
01145         //#1468C - more then one article in basket with different selectlist...
01146         //optionall function parameter $sKeyPrefix added, used only in basket.php
01147         $sKey = $this->getId();
01148         if ( isset( $sKeyPrefix ) ) {
01149             $sKey = $sKeyPrefix.'__'.$this->getId();
01150         }
01151 
01152         if ( !isset( self::$_aSelList[$sKey] ) ) {
01153             // all selectlists this article has
01154             $oLists = oxNew( 'oxlist' );
01155             $oLists->init('oxselectlist');
01156             $sSLViewName = getViewName('oxselectlist');
01157             $sSelect  = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01158             $sSelect .= 'where oxobject2selectlist.oxobjectid=\''.$this->getId().'\' ';
01159             //sorting
01160             $sSelect .= ' order by oxobject2selectlist.oxsort';
01161 
01162             $oLists->selectString( $sSelect );
01163 
01164             //#1104S if this is variant ant it has no selectlists, trying with parent
01165             if ( $this->oxarticles__oxparentid->value && $oLists->count() == 0 ) {
01166                 $sParentQuoted = oxDb::getDb()->quote($this->oxarticles__oxparentid->value);
01167                 //#1496C - select fixed ( * => $sSLViewName.*)
01168                 $sSelect  = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01169                 $sSelect .= "where oxobject2selectlist.oxobjectid=$sParentQuoted ";
01170                 //sorting
01171                 $sSelect .= ' order by oxobject2selectlist.oxsort';
01172                 $oLists->selectString( $sSelect);
01173             }
01174 
01175             $dVat = 0;
01176             if ( $this->getPrice() != null ) {
01177                 $dVat = $this->getPrice()->getVat();
01178             }
01179 
01180             $iCnt = 0;
01181             self::$_aSelList[$sKey] = array();
01182             foreach ( $oLists as $oSelectlist ) {
01183                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01184                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01185                 $iCnt++;
01186             }
01187         }
01188         return self::$_aSelList[$sKey];
01189     }
01190 
01198     protected function _hasAnyVariant( $blForceCoreTable = false )
01199     {
01200         $sArticleTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
01201         return (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='".$this->getId()."'" );
01202     }
01203 
01209     public function hasMdVariants()
01210     {
01211         return $this->_blHasMdVariants;
01212     }
01213 
01222     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = false  )
01223     {
01224         if ( $blRemoveNotOrderables && $this->_aVariants ) {
01225             return $this->_aVariants;
01226         } elseif ( !$blRemoveNotOrderables && $this->_aVariantsWithNotOrderables ) {
01227             return $this->_aVariantsWithNotOrderables;
01228         }
01229 
01230         $myConfig = $this->getConfig();
01231         if ( !$this->_blLoadVariants ||
01232             ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01233             ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01234             return array();
01235         }
01236 
01237         //do not load me as a parent later
01238         self::$_aLoadedParents[$this->getId()] = $this;
01239 
01240         //load simple variants for lists
01241         if ( $this->_isInList() ) {
01242             $oVariants = oxNew( 'oxsimplevariantlist' );
01243             $oVariants->setParent( $this );
01244         } else {
01245             //loading variants
01246             $oVariants = oxNew( 'oxarticlelist' );
01247             $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01248         }
01249 
01250         $this->_iVarStock = $this->oxarticles__oxvarstock->value;
01251         if ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) {
01252 
01253             startProfile("selectVariants");
01254             $blUseCoreTable = $blForceCoreTable;
01255             $oBaseObject = $oVariants->getBaseObject();
01256             $sArticleTable = $this->getTableNameForActiveSnippet( $blUseCoreTable );
01257 
01258             $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01259                        $this->getActiveCheckQuery( $blUseCoreTable ) .
01260                        $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01261                        " order by $sArticleTable.oxsort";
01262 
01263             $oVariants->selectString( $sSelect );
01264 
01265             //if this is multidimensional variants, make additional processing
01266             if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01267                 $oMdVariants = oxNew( "oxVariantHandler" );
01268                 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01269             }
01270             stopProfile("selectVariants");
01271         }
01272 
01273         //if we have variants then depending on config option the parent may be non buyable
01274         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01275             $this->_blNotBuyableParent = true;
01276         }
01277 
01278         //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01279         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $oVariants->count() == 0 && $this->_blHasVariants ) {
01280             $this->_blNotBuyable = true;
01281         }
01282 
01283         // cache
01284         if ( $blRemoveNotOrderables ) {
01285             $this->_aVariants = $oVariants;
01286         } else {
01287             $this->_aVariantsWithNotOrderables = $oVariants;
01288         }
01289 
01290         return $oVariants;
01291     }
01292 
01298     public function getSimpleVariants()
01299     {
01300         if ( $this->oxarticles__oxvarcount->value) {
01301             return $this->getVariants();
01302         }
01303     }
01304 
01313     public function getAdminVariants( $sLanguage = null )
01314     {
01315         $myConfig = $this->getConfig();
01316 
01317         $oVariants = oxNew( 'oxarticlelist');
01318 
01319         if ( is_null($sLanguage) ) {
01320             $oVariants->getBaseObject()->setLanguage(oxLang::getInstance()->getBaseLanguage());
01321         } else {
01322             $oVariants->getBaseObject()->setLanguage($sLanguage);
01323         }
01324 
01325         $sSql = 'select * from oxarticles where oxparentid = "'.$this->getId().'" order by oxsort ';
01326 
01327         $oVariants->selectString( $sSql);
01328 
01329         //if we have variants then depending on config option the parent may be non buyable
01330         if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01331             //$this->blNotBuyable = true;
01332             $this->_blNotBuyableParent = true;
01333         }
01334 
01335         return $oVariants;
01336     }
01337 
01345     public function getCategory()
01346     {
01347         startPRofile( 'getCategory' );
01348 
01349         $oCategory = oxNew( 'oxcategory' );
01350         $oCategory->setLanguage( $this->getLanguage() );
01351 
01352         // variant handling
01353         $sOXID = $this->getId();
01354         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01355             $sOXID = $this->oxarticles__oxparentid->value;
01356         }
01357 
01358         $oStr = getStr();
01359         $sWhere   = $oCategory->getSqlActiveSnippet();
01360         $sSelect  = $this->_generateSearchStr( $sOXID );
01361         $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01362 
01363         // category not found ?
01364         if ( !$oCategory->assignRecord( $sSelect ) ) {
01365 
01366             $sSelect  = $this->_generateSearchStr( $sOXID, true );
01367             $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01368 
01369             // looking for price category
01370             if ( !$oCategory->assignRecord( $sSelect ) ) {
01371                 $oCategory = null;
01372             }
01373         }
01374 
01375         stopPRofile( 'getCategory' );
01376         return $oCategory;
01377     }
01378 
01387     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01388     {
01389         $myConfig = $this->getConfig();
01390         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01391             return self::$_aArticleCats[$this->getId()];
01392         }
01393 
01394         // variant handling
01395         $sOXID = $this->getId();
01396         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01397             $sOXID = $this->oxarticles__oxparentid->value;
01398         }
01399 
01400         // we do not use lists here as we dont need this overhead right now
01401         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01402         $oDB = oxDb::getDb(true);
01403         $rs = $oDB->execute( $sSql );
01404 
01405 
01406         $aRet = array();
01407         $iHitMax = 0;
01408         if ($rs != false && $rs->recordCount() > 0) {
01409             while (!$rs->EOF) {
01410                 $aRet[] = $rs->fields['oxcatnid'];
01411                 $rs->moveNext();
01412             }
01413         }
01414 
01415         return self::$_aArticleCats[$this->getId()] = $aRet;
01416     }
01417 
01426     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01427     {
01428         $sO2CView = $this->_getObjectViewName('oxobject2category');
01429         $sCatView = $this->_getObjectViewName('oxcategories');
01430         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01431         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 ';
01432         if ( $blActCats ) {
01433             $sSelect .= "and oxcategories.oxhidden = 0 and (select count(cats.oxid) from $sCatView as cats where cats.oxrootid = oxcategories.oxrootid and cats.oxleft < oxcategories.oxleft and cats.oxright > oxcategories.oxright and ( cats.oxhidden = 1 or cats.oxactive".(($this->getLanguage())?"_".$this->getLanguage():"")." = 0 ) ) = 0 ";
01434         }
01435         $sSelect .= 'order by oxobject2category.oxtime ';
01436         return $sSelect;
01437     }
01438 
01448     public function getVendor( $blShopCheck = true )
01449     {
01450         if ( ( $sVendorId = $this->getVendorId() ) ) {
01451             $oVendor = oxNew( 'oxvendor' );
01452         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01453             $oVendor = oxNew( 'oxi18n' );
01454             $oVendor->init('oxvendor');
01455             $oVendor->setReadOnly( true );
01456             $sVendorId = $this->oxarticles__oxvendorid->value;
01457         }
01458         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01459             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01460                 $oVendor->setReadOnly( true );
01461             }
01462             return $oVendor;
01463         }
01464         return null;
01465     }
01466 
01474     public function getVendorId( $blForceReload = false )
01475     {
01476         $sVendorId = false;
01477         if ( $this->oxarticles__oxvendorid->value ) {
01478             if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01479                 return self::$_aArticleVendors[$this->getId()];
01480             }
01481             $oDb = oxDb::getDb();
01482             $sVendorIdQuoted = $oDb->quote($this->oxarticles__oxvendorid->value);
01483             $sQ = "select oxid from ".getViewName('oxvendor')." where oxid=$sVendorIdQuoted";
01484             self::$_aArticleVendors[$this->getId()] = $sVendorId = $oDb->getOne( $sQ );
01485         }
01486         return $sVendorId;
01487     }
01488 
01496     public function getManufacturerId( $blForceReload = false )
01497     {
01498         $sManufacturerId = false;
01499         if ( $this->oxarticles__oxmanufacturerid->value ) {
01500             if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01501                 return self::$_aArticleManufacturers[$this->getId()];
01502             }
01503             $oDb = oxDb::getDb();
01504             $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid=".$oDb->quote($this->oxarticles__oxmanufacturerid->value);
01505             self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = $oDb->getOne( $sQ );
01506         }
01507         return $sManufacturerId;
01508     }
01509 
01519     public function getManufacturer( $blShopCheck = true )
01520     {
01521         $oManufacturer = oxNew( 'oxmanufacturer' );;
01522         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01523              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01524             $oManufacturer->setReadOnly( true );
01525             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01526         }
01527 
01528         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01529             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01530                 $oManufacturer->setReadOnly( true );
01531             }
01532             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01533         } else {
01534             $oManufacturer = null;
01535         }
01536 
01537         return $oManufacturer;
01538     }
01539 
01547     public function inCategory( $sCatNid)
01548     {
01549         return in_array( $sCatNid, $this->getCategoryIds());
01550     }
01551 
01560     public function isAssignedToCategory( $sCatId )
01561     {
01562         // variant handling
01563         $sOXID = $this->getId();
01564         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01565             $sOXID = $this->oxarticles__oxparentid->value;
01566         }
01567 
01568         $oDB = oxDb::getDb();
01569         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01570         $sOXID = $oDB->getOne( $sSelect);
01571         // article is assigned to passed category!
01572         if ( isset( $sOXID) && $sOXID) {
01573             return true;
01574         }
01575 
01576         // maybe this category is price category ?
01577         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01578             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01579             if ( $dPriceFromTo > 0) {
01580                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01581                 $sOXID = $oDB->getOne( $sSelect);
01582                 // article is assigned to passed category!
01583                 if ( isset( $sOXID) && $sOXID) {
01584                     return true;
01585                 }
01586             }
01587         }
01588         return false;
01589     }
01590 
01596     public function getTPrice()
01597     {
01598         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01599             return;
01600         }
01601         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01602         if ( $this->_oTPrice !== null ) {
01603             return $this->_oTPrice;
01604         }
01605 
01606         $this->_oTPrice = oxNew( 'oxPrice' );
01607         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01608 
01609         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01610         $this->_applyCurrency( $this->_oTPrice );
01611 
01612         return $this->_oTPrice;
01613     }
01614 
01620     public function skipDiscounts()
01621     {
01622         // allready loaded skip discounts config
01623         if ( $this->_blSkipDiscounts !== null )
01624             return $this->_blSkipDiscounts;
01625 
01626         if ( $this->oxarticles__oxskipdiscounts->value )
01627             return true;
01628 
01629         $sO2CView = getViewName('oxobject2category');
01630         $sSelect =  "select 1 from $sO2CView as oxobject2category left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01631         $sSelect .= 'where oxobject2category.oxobjectid="'.$this->getId().'" and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 and oxcategories.oxskipdiscounts = "1" ';
01632 
01633         return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01634     }
01635 
01643     public function setPrice(oxPrice $oPrice)
01644     {
01645         $this->_oPrice = $oPrice;
01646     }
01647 
01656     public function getBasePrice( $dAmount = 1 )
01657     {
01658         // override this function if you want e.g. different prices
01659         // for diff. usergroups.
01660 
01661         // Performance
01662         $myConfig = $this->getConfig();
01663         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01664             return;
01665 
01666         // GroupPrice or DB price ajusted by AmountPrice
01667         $dPrice = $this->_getAmountPrice( $dAmount );
01668 
01669 
01670         return $dPrice;
01671     }
01672 
01680     public function getPrice( $dAmount = 1 )
01681     {
01682         $myConfig = $this->getConfig();
01683         // Performance
01684         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01685             return;
01686         }
01687 
01688         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01689         if ( $dAmount != 1 || $this->_oPrice === null ) {
01690             $oPrice = oxNew( 'oxPrice' );
01691 
01692             // get base
01693             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01694 
01695             // price handling
01696             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01697                 return $this->_oPrice = $oPrice;
01698             }
01699 
01700             $this->_calculatePrice( $oPrice );
01701             if ( $dAmount != 1 ) {
01702                 return $oPrice;
01703             }
01704 
01705             $this->_oPrice = $oPrice;
01706         }
01707         return $this->_oPrice;
01708     }
01709 
01717     protected function _calculatePrice( $oPrice )
01718     {
01719         // apply VAT only if configuration requires it
01720         if ( !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01721             $this->_applyVAT( $oPrice, $this->getArticleVat() );
01722         }
01723 
01724         // apply currency
01725         $this->_applyCurrency( $oPrice );
01726         // apply discounts
01727         if ( !$this->skipDiscounts() ) {
01728             $oDiscountList = oxDiscountList::getInstance();
01729             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts($this, $this->getArticleUser() ) );
01730         }
01731 
01732         return $oPrice;
01733     }
01734 
01742     public function setArticleUser($oUser)
01743     {
01744         $this->_oUser = $oUser;
01745     }
01746 
01752     public function getArticleUser()
01753     {
01754         if ($this->_oUser) {
01755             return $this->_oUser;
01756         }
01757         return $this->getUser();
01758     }
01759 
01769     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01770     {
01771         $oUser = $oBasket->getBasketUser();
01772         $this->setArticleUser($oUser);
01773 
01774         $oBasketPrice = oxNew( 'oxPrice' );
01775 
01776         // get base price
01777         $dBasePrice = $this->getBasePrice( $dAmount );
01778 
01779         // applying select list price
01780         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01781 
01782         // setting price
01783         $oBasketPrice->setPrice( $dBasePrice );
01784 
01785         // apply VAT
01786         $this->_applyVat( $oBasketPrice, oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket ) );
01787 
01788         // apply currency
01789         $this->_applyCurrency( $oBasketPrice );
01790 
01791         // apply discounts
01792         if ( !$this->skipDiscounts() ) {
01793             // apply general discounts
01794             $oDiscountList = oxDiscountList::getInstance();
01795             $oDiscountList->applyDiscounts( $oBasketPrice, $oDiscountList->getArticleDiscounts( $this, $oUser ) );
01796         }
01797 
01798         // returning final price object
01799         return $oBasketPrice;
01800     }
01801 
01814     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01815     {
01816         $oDiscountList = oxDiscountList::getInstance();
01817         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01818     }
01819 
01828     public function delete( $sOXID = null )
01829     {
01830         if ( !$sOXID ) {
01831             $sOXID = $this->getId();
01832         }
01833         if ( !$sOXID ) {
01834             return false;
01835         }
01836 
01837 
01838         $this->load( $sOXID );
01839         $this->_deletePics();
01840         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01841         $this->_deleteVariantRecords( $sOXID );
01842         $rs = $this->_deleteRecords( $sOXID );
01843 
01844         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01845 
01846         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01847 
01848         return $rs->EOF;
01849     }
01850 
01859     public function updateSoldAmount( $dAmount = 0 )
01860     {
01861         if ( !$dAmount ) {
01862             return;
01863         }
01864 
01865         $this->beforeUpdate();
01866 
01867         // article is not variant - should be updated current amount
01868         if ( !$this->oxarticles__oxparentid->value ) {
01869             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01870             $dAmount = (double) $dAmount;
01871             $oDb = oxDb::getDb();
01872             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01873         } elseif ( $this->oxarticles__oxparentid->value) {
01874             // article is variant - should be updated this article parent amount
01875             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01876             $oUpdateArticle->updateSoldAmount( $dAmount );
01877         }
01878 
01879         $this->onChange( ACTION_UPDATE );
01880 
01881         return $rs;
01882     }
01883 
01889     public function disableReminder()
01890     {
01891         $oDB = oxDb::getDb(true);
01892         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01893     }
01894 
01901     public function save()
01902     {
01903         $myConfig = $this->getConfig();
01904 
01905         $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01906         $this->oxarticles__oxicon  = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01907         $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01908         for ($i=1; $i <= $iPicCount; $i++) {
01909             if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01910                 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01911             }
01912         }
01913 
01914         $blRet = parent::save();
01915 
01916         // save article long description
01917         $this->setArticleLongDesc();
01918 
01919         // load article images after save
01920         $this->_assignAllPictureValues();
01921 
01922         return $blRet;
01923     }
01924 
01925 
01932     public function getPictureGallery()
01933     {
01934         $myConfig = $this->getConfig();
01935 
01936         //initialize
01937         $blMorePic = false;
01938         $aArtPics  = array();
01939         $aArtIcons = array();
01940         $iActPicId = 1;
01941         $sActPic = $this->getPictureUrl( $iActPicId );
01942 
01943         if ( oxConfig::getParameter( 'actpicid' ) ) {
01944             $iActPicId = oxConfig::getParameter('actpicid');
01945         }
01946 
01947         $oStr = getStr();
01948         $iCntr = 0;
01949         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01950         $blCheckActivePicId = true;
01951 
01952         for ( $i = 1; $i <= $iPicCount; $i++) {
01953             $sPicVal = $this->getPictureUrl( $i );
01954             $sIcoVal = $this->getIconUrl( $i );
01955             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') ) {
01956                 if ($iCntr) {
01957                     $blMorePic = true;
01958                 }
01959                 $aArtIcons[$i]= $sIcoVal;
01960                 $aArtPics[$i]= $sPicVal;
01961                 $iCntr++;
01962 
01963                 if ($iActPicId == $i) {
01964                     $sActPic = $sPicVal;
01965                     $blCheckActivePicId = false;
01966                 }
01967 
01968             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
01969                 // if picture is empty, setting active pic id to next
01970                 // picture
01971                 $iActPicId++;
01972             }
01973         }
01974 
01975         $blZoomPic  = false;
01976         $aZoomPics = array();
01977         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
01978 
01979         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
01980             $sVal = $this->getZoomPictureUrl($j);
01981 
01982             if ( !$oStr->strstr($sVal, 'nopic.jpg')) {
01983                 if ($this->getConfig()->getConfigParam('blFormerTplSupport')) {
01984                     $sVal = $this->_sDynImageDir."/".$sVal;
01985                 }
01986                 $blZoomPic = true;
01987                 $aZoomPics[$c]['id'] = $c;
01988                 $aZoomPics[$c]['file'] = $sVal;
01989                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01990                 if (!$sVal) {
01991                     $aZoomPics[$c]['file'] = "nopic.jpg";
01992                 }
01993                 $c++;
01994             }
01995         }
01996 
01997         $aPicGallery = array('ActPicID' => $iActPicId,
01998                              'ActPic' => $sActPic,
01999                              'MorePics' => $blMorePic,
02000                              'Pics' => $aArtPics,
02001                              'Icons' => $aArtIcons,
02002                              'ZoomPic' => $blZoomPic,
02003                              'ZoomPics' => $aZoomPics);
02004 
02005         return $aPicGallery;
02006     }
02007 
02021     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02022     {
02023         $myConfig = $this->getConfig();
02024 
02025         if (!isset($sOXID)) {
02026             if ( $this->getId()) {
02027                 $sOXID = $this->getId();
02028             }
02029             if (!isset ($sOXID)) {
02030                 $sOXID = $this->oxarticles__oxid->value;
02031             }
02032             if ($this->oxarticles__oxparentid->value) {
02033                 $sParentID = $this->oxarticles__oxparentid->value;
02034             }
02035         }
02036         if (!isset($sOXID)) {
02037             return;
02038         }
02039 
02040         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02041         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02042             //if article has variants then updating oxvarstock field
02043             //getting parent id
02044             if (!isset($sParentID)) {
02045                 $oDb = oxDb::getDb();
02046                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02047                 $sParentID = $oDb->getOne($sQ);
02048             }
02049             //if we have parent id then update stock
02050             if ($sParentID) {
02051                 $this->_onChangeUpdateStock($sParentID);
02052             }
02053         }
02054         //if we have parent id then update count
02055         //update count even if blUseStock is not active
02056         if ($sParentID) {
02057             $this->_onChangeUpdateVarCount($sParentID);
02058         }
02059 
02060         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02061         $this->_onChangeUpdateMinVarPrice( $sId );
02062 
02063             // reseting articles count cache if stock has changed and some
02064             // articles goes offline (M:1448)
02065             if ( $sAction === ACTION_UPDATE_STOCK ) {
02066                 $this->_onChangeStockResetCount( $sOXID );
02067             }
02068 
02069     }
02070 
02077     public function getCustomVAT()
02078     {
02079         if ( isset($this->oxarticles__oxvat->value) ) {
02080             return $this->oxarticles__oxvat->value;
02081         }
02082     }
02083 
02092     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02093     {
02094         $myConfig = $this->getConfig();
02095         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02096             return true;
02097         }
02098 
02099         // fetching DB info as its up-to-date
02100         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02101         $rs = oxDb::getDb(true)->Execute( $sQ );
02102 
02103         $iOnStock   = 0;
02104         $iStockFlag = 0;
02105         if ( $rs !== false && $rs->recordCount() > 0 ) {
02106             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02107             $iStockFlag = $rs->fields['oxstockflag'];
02108 
02109             // dodger : fremdlager is also always considered as on stock
02110             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02111                 return true;
02112             }
02113             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02114                 //2007-09-04 MK this if is NEVER true, because upper return in if $iStockFlag == 1 or $iStockFlag == 4
02115                 /* if ( $iStockFlag == 1 || $iStockFlag == 4 ) {
02116                     $iOnStock = ceil( $iOnStock );
02117                  } else {*/
02118                     $iOnStock = floor( $iOnStock );
02119                 //}
02120             }
02121         }
02122 
02123         if ( $iOnStock >= $dAmount ) {
02124             return true;
02125         } else {
02126             if ( $iOnStock > 0 ) {
02127                 return $iOnStock;
02128             } else {
02129                 $oEx = oxNew( 'oxArticleInputException' );
02130                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02131                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02132                 return false;
02133             }
02134         }
02135     }
02136 
02137 
02145     public function getArticleLongDesc($sOXID = null)
02146     {
02147 
02148         if ( !$sOXID ) {
02149             $sOXID = $this->oxarticles__oxid->value;
02150         }
02151 
02152         if ($sOXID == $this->oxarticles__oxid->value) {
02153             if (isset($this->oxarticles__oxlongdesc) && ($this->oxarticles__oxlongdesc instanceof oxField) && $this->oxarticles__oxlongdesc->value) {
02154                 return $this->oxarticles__oxlongdesc;
02155             }
02156         }
02157 
02158         $myConfig = $this->getConfig();
02159 
02160         if ( $sOXID ) {
02161             $sLangField = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02162             $oDb = oxDb::getDb();
02163             $this->_setLongDesc($oDb->getOne( "select oxlongdesc{$sLangField} from oxartextends where oxid = ".$oDb->quote($sOXID) ));
02164         } else {
02165             // TODO: check if keeping fldname is needed in non-admin mode
02166             $this->oxarticles__oxlongdesc = new oxField();
02167             $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02168             $this->oxarticles__oxlongdesc->table   = 'oxarticles';
02169             $this->oxarticles__oxlongdesc->fldtype = 'text';
02170         }
02171 
02172         return $this->oxarticles__oxlongdesc;
02173     }
02174 
02182     protected function _setLongDesc($sDbValue)
02183     {
02184         // TODO: eliminate code below
02185         // hack, if editor screws up text, htmledit tends to do so
02186         $sDbValue = str_replace( '&amp;nbsp;', '&nbsp;', $sDbValue );
02187         $sDbValue = str_replace( '&amp;', '&', $sDbValue );
02188         $sDbValue = str_replace( '&quot;', '"', $sDbValue );
02189         $sDbValue = str_replace( '&lang=', '&amp;lang=', $sDbValue);
02190         //
02191 
02192         $oStr = getStr();
02193         $blHasSmarty = $oStr->strstr( $sDbValue, '[{' );
02194         $blHasPhp = $oStr->strstr( $sDbValue, '<?' );
02195         $myConfig = oxConfig::getInstance();
02196         if ( ( $blHasSmarty || $blHasPhp ) && ($myConfig->getConfigParam( 'blExport' ) || !$this->isAdmin() ) && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
02197             $sDbValue = oxUtilsView::getInstance()->parseThroughSmarty( $sDbValue, $this->getId() );
02198         }
02199         $this->oxarticles__oxlongdesc = new oxField($sDbValue, oxField::T_RAW);
02200         // TODO: check if keeping fldname is needed in non-admin mode
02201         $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02202         $this->oxarticles__oxlongdesc->table   = 'oxarticles';
02203         $this->oxarticles__oxlongdesc->fldtype = 'text';
02204     }
02205 
02211     public function setArticleLongDesc()
02212     {
02213 
02214         if ( $this->_blEmployMultilanguage ) {
02215             // update or insert article long description
02216             if ($this->oxarticles__oxlongdesc instanceof oxField) {
02217                 $sLongDesc = $this->oxarticles__oxlongdesc->getRawValue();
02218             } else {
02219                 $sLongDesc = $this->oxarticles__oxlongdesc->value;
02220             }
02221             $this->_saveArtLongDesc($this->getLanguage(), $sLongDesc);
02222         } else {
02223             $oArtExt = oxNew('oxi18n');
02224             $oArtExt->init('oxartextends');
02225             $aObjFields = $oArtExt->_getAllFields(true);
02226             foreach ($aObjFields as $sKey => $sValue ) {
02227                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02228                     $sField = $this->_getFieldLongName($sKey);
02229                     if (isset($this->$sField)) {
02230                         $iLang = $oArtExt->_getFieldLang($sKey);
02231                         $sLongDesc = null;
02232                         if ($this->$sField instanceof oxField) {
02233                             $sLongDesc = $this->$sField->getRawValue();
02234                         } elseif (is_object($this->$sField)) {
02235                             $sLongDesc = $this->$sField->value;
02236                         }
02237                         if (isset($sLongDesc)) {
02238                             $this->_saveArtLongDesc($iLang, $sLongDesc);
02239                         }
02240                     }
02241                 }
02242             }
02243         }
02244     }
02245 
02251     public function getAttributes()
02252     {
02253         if ( $this->_oAttributeList === null ) {
02254             $this->_oAttributeList = oxNew( 'oxattributelist' );
02255             $this->_oAttributeList->loadAttributes( $this->getId() );
02256         }
02257 
02258         return $this->_oAttributeList;
02259     }
02260 
02269     public function appendLink( $sAddParams, $iLang = null )
02270     {
02271         if ( $sAddParams ) {
02272             if ( $iLang === null ) {
02273                 $iLang = $this->getLanguage();
02274             }
02275 
02276             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02277             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02278         }
02279     }
02280 
02289     public function getBaseSeoLink( $iLang, $blMain = false )
02290     {
02291         $oEncoder = oxSeoEncoderArticle::getInstance();
02292         if ( !$blMain ) {
02293             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02294         }
02295         return $oEncoder->getArticleMainUrl( $this, $iLang );
02296     }
02297 
02306     public function getLink( $iLang = null, $blMain = false  )
02307     {
02308         if ( !oxUtils::getInstance()->seoIsActive() ) {
02309             return $this->getStdLink( $iLang );
02310         }
02311 
02312         if ( $iLang === null ) {
02313             $iLang = $this->getLanguage();
02314         }
02315 
02316         $iLinkType = $this->getLinkType();
02317         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02318             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02319         }
02320 
02321         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02322         if ( isset($this->_aSeoAddParams[$iLang])) {
02323             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02324         }
02325 
02326         return $sUrl;
02327     }
02328 
02337     public function getMainLink( $iLang = null )
02338     {
02339         return $this->getLink( $iLang, true );
02340     }
02341 
02349     public function setLinkType( $iType )
02350     {
02351         // resetting detaisl link, to force new
02352         $this->_sDetailLink = null;
02353 
02354         // setting link type
02355         $this->_iLinkType = (int) $iType;
02356     }
02357 
02363     public function getLinkType()
02364     {
02365         return $this->_iLinkType;
02366     }
02367 
02376     public function appendStdLink( $sAddParams, $iLang = null )
02377     {
02378         if ( $sAddParams ) {
02379             if ( $iLang === null ) {
02380                 $iLang = $this->getLanguage();
02381             }
02382 
02383             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02384             $this->_aStdAddParams[$iLang] .= $sAddParams;
02385         }
02386     }
02387 
02397     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02398     {
02399         $sUrl = '';
02400         if ( $blFull ) {
02401             //always returns shop url, not admin
02402             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02403         }
02404 
02405         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02406         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02407     }
02408 
02417     public function getStdLink( $iLang = null, $aParams = array() )
02418     {
02419         if ( $iLang === null ) {
02420             $iLang = $this->getLanguage();
02421         }
02422 
02423         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02424             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02425         }
02426 
02427         return oxUtilsUrl::getInstance()->processStdUrl( $this->_aStdUrls[$iLang], $aParams, $iLang, $iLang != $this->getLanguage() );
02428     }
02429 
02437     public function getStdTagLink( $sTag )
02438     {
02439         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02440         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02441     }
02442 
02448     public function getTags()
02449     {
02450         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02451         $sQ = "select $sTagField from oxartextends where oxid = '".$this->getId()."'";
02452         $sTags = oxDb::getDb(true)->getOne($sQ);
02453         $oTagCloud = oxNew('oxtagcloud');
02454         $sTags = $oTagCloud->trimTags($sTags);
02455         return $sTags;
02456     }
02457 
02465     public function saveTags($sTags)
02466     {
02467         $sTags = mysql_real_escape_string($sTags);
02468         $oTagCloud = oxNew('oxtagcloud');
02469         $oTagCloud->resetTagCache();
02470         $sTags = $oTagCloud->prepareTags($sTags);
02471         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02472         $sQ = "update oxartextends set $sTagField = '$sTags'  where oxid = '".$this->getId()."'";
02473         return oxDb::getDb()->execute($sQ);
02474 
02475     }
02476 
02484     public function addTag($sTag)
02485     {
02486         $sTag = mysql_real_escape_string($sTag);
02487 
02488         $oTagCloud = oxNew('oxtagcloud');
02489         $oTagCloud->resetTagCache();
02490         $sTag = $oTagCloud->prepareTags($sTag);
02491         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02492         $sTailTag = $sTagSeparator.$sTag;
02493 
02494         $sField = "oxartextends.OXTAGS".oxLang::getInstance()->getLanguageTag();
02495         $sQ = "insert into oxartextends (oxartextends.OXID, $sField) values ('".$this->getId()."', '{$sTag}')
02496                        ON DUPLICATE KEY update $sField = CONCAT(TRIM($sField), '$sTailTag') ";
02497 
02498         return oxDb::getDb()->Execute($sQ);
02499     }
02500 
02506     public function getMediaUrls()
02507     {
02508         if ( $this->_aMediaUrls === null ) {
02509             $this->_aMediaUrls = oxNew("oxlist");
02510             $this->_aMediaUrls->init("oxmediaurl");
02511             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02512 
02513             $sQ = "select * from oxmediaurls where oxobjectid = '".$this->getId()."'";
02514             $this->_aMediaUrls->selectString($sQ);
02515         }
02516         return $this->_aMediaUrls;
02517     }
02518 
02524     public function getDynImageDir()
02525     {
02526         return $this->_sDynImageDir;
02527     }
02528 
02534     public function getDispSelList()
02535     {
02536         if ($this->_aDispSelList === null) {
02537             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02538                 $this->_aDispSelList = $this->getSelectLists();
02539             }
02540         }
02541         return $this->_aDispSelList;
02542     }
02543 
02549     public function getMoreDetailLink()
02550     {
02551         if ( $this->_sMoreDetailLink == null ) {
02552 
02553             // and assign special article values
02554             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02555 
02556             // not always it is okey, as not all the time active category is the same as primary article cat.
02557             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02558                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02559             }
02560             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02561             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02562         }
02563 
02564         return $this->_sMoreDetailLink;
02565     }
02566 
02572     public function getToBasketLink()
02573     {
02574         if ( $this->_sToBasketLink == null ) {
02575             $myConfig = $this->getConfig();
02576 
02577             if ( oxUtils::getInstance()->isSearchEngine() ) {
02578                 $this->_sToBasketLink = $this->getLink();
02579             } else {
02580                 // and assign special article values
02581                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02582 
02583                 // override some classes as these should never showup
02584                 $sActClass = oxConfig::getParameter( 'cl' );
02585                 if ( $sActClass == 'thankyou') {
02586                     $sActClass = 'basket';
02587                 }
02588                 $this->_sToBasketLink .= 'cl='.$sActClass;
02589 
02590                 // this is not very correct
02591                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02592                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02593                 }
02594 
02595                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02596 
02597                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02598                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02599                 }
02600             }
02601         }
02602 
02603         return $this->_sToBasketLink;
02604     }
02605 
02611     public function getStockStatus()
02612     {
02613         return $this->_iStockStatus;
02614     }
02615 
02621     public function getDeliveryDate()
02622     {
02623         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02624             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02625         }
02626         return false;
02627     }
02628 
02634     public function getFTPrice()
02635     {
02636         if ( $oPrice = $this->getTPrice() ) {
02637             if ( $oPrice->getBruttoPrice() ) {
02638                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02639             }
02640         }
02641     }
02642 
02648     public function getFPrice()
02649     {
02650         if ( $oPrice = $this->getPrice() ) {
02651             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02652         }
02653     }
02654 
02660     public function getPricePerUnit()
02661     {
02662         return $this->_fPricePerUnit;
02663     }
02664 
02670     public function isParentNotBuyable()
02671     {
02672         return $this->_blNotBuyableParent;
02673     }
02674 
02680     public function isNotBuyable()
02681     {
02682         return $this->_blNotBuyable;
02683     }
02684 
02692     public function setBuyableState( $blBuyable = false )
02693     {
02694         $this->_blNotBuyable = !$blBuyable;
02695     }
02696 
02702     public function getVariantList()
02703     {
02704         return $this->_oVariantList;
02705     }
02706 
02714     public function setSelectlist( $aSelList )
02715     {
02716         $this->_aDispSelList = $aSelList;
02717     }
02718 
02726     public function getPictureUrl( $iIndex = '' )
02727     {
02728         if ( $iIndex ) {
02729 
02730             if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02731                 $this->_generateImages( $iIndex );
02732             }
02733 
02734             $sPic = $iIndex . "/" . $this->_getPictureName( $iIndex );
02735 
02736             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02737         }
02738     }
02739 
02747     protected function _getPictureName( $iIndex = '' )
02748     {
02749         if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02750             $sPicName = basename($this->{"oxarticles__oxpic".$iIndex}->value);
02751         } else {
02752             $sPicName = "nopic.jpg";
02753         }
02754 
02755         return $sPicName;
02756     }
02757 
02766     public function getIconUrl( $iIndex = '')
02767     {
02768         if ( $this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02769 
02770             $iIconIndex = ( $iIndex ) ? $iIndex : 1;
02771             //generating new images if needed
02772             if ( !$this->_hasGeneratedImage( $iIconIndex ) ) {
02773                 $this->_generateImages( $iIconIndex );
02774             }
02775         }
02776 
02777         $sIconName = $this->_getIconName( $iIndex );
02778 
02779         if ( !$iIndex ) {
02780             $sPic = "icon/" . basename( $sIconName );
02781         } else {
02782             $sPic = $iIndex . "/" . basename( $sIconName );
02783         }
02784 
02785         return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02786     }
02787 
02796     protected function _getIconName( $iIndex = '' )
02797     {
02798         $oPictureHandler = oxPictureHandler::getInstance();
02799         $sIconName = "nopic_ico.jpg";
02800 
02801         if ( !$iIndex ) {
02802             if ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02803                 $sIconName = basename( $this->oxarticles__oxicon->value );
02804             } elseif ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 )  && $this->oxarticles__oxpic1->value ) {
02805                 $sIconName = $oPictureHandler->getMainIconName( $this->oxarticles__oxpic1->value );
02806             }
02807         } else {
02808             if ( $this->_hasGeneratedImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02809                 $sIconName = $oPictureHandler->getIconName( $this->{"oxarticles__oxpic".$iIndex}->value );
02810             }
02811         }
02812 
02813         return $sIconName;
02814     }
02815 
02821     public function getThumbnailUrl()
02822     {
02823         if ( $this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02824             //generating new images if needed
02825             if ( !$this->_hasGeneratedImage( 1 ) ) {
02826                 $this->_generateImages( 1 );
02827             }
02828         }
02829 
02830         $sPic = "0/" . $this->_getThumbnailName();
02831 
02832         return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02833     }
02834 
02840     protected function _getThumbnailName()
02841     {
02842         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02843             $sThumbName = basename($this->oxarticles__oxthumb->value);
02844         } else {
02845             if ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 ) && $this->oxarticles__oxpic1->value ) {
02846                 $oPictureHandler = oxPictureHandler::getInstance();
02847                 $sThumbName = $oPictureHandler->getThumbName( $this->oxarticles__oxpic1->value );
02848             } else {
02849                 $sThumbName = "nopic.jpg";
02850             }
02851         }
02852 
02853         return $sThumbName;
02854     }
02855 
02863     public function getZoomPictureUrl( $iIndex = '' )
02864     {
02865         $iIndex = (int) $iIndex;
02866         if ( $iIndex > 0) {
02867             //generating new images if needed
02868             if ( $this->_isFieldEmpty( "oxarticles__oxzoom" . $iIndex ) ) {
02869                 //generating new images if needed
02870                 if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02871                     $this->_generateImages( $iIndex );
02872                 }
02873             }
02874 
02875             $sPic = "z{$iIndex}/" . $this->_getZoomPictureName( $iIndex );
02876 
02877             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02878         }
02879     }
02880 
02888     protected function _getZoomPictureName( $iIndex = '' )
02889     {
02890         $sZoomField = "oxarticles__oxzoom" . $iIndex;
02891 
02892         if ( !$this->_isFieldEmpty( $sZoomField ) ) {
02893             $sZoomName = basename( $this->$sZoomField->value );
02894         } else {
02895             if ( $this->_hasGeneratedImage( $iIndex ) && $this->_hasMasterImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02896                 $oPictureHandler = oxPictureHandler::getInstance();
02897                 $sZoomName = $oPictureHandler->getZoomName( $this->{"oxarticles__oxpic".$iIndex}->value, $iIndex );
02898             } else {
02899                 $sZoomName = "nopic.jpg";
02900             }
02901         }
02902 
02903         return $sZoomName;
02904     }
02905 
02911     public function getFileUrl()
02912     {
02913         return $this->getConfig()->getPictureUrl( '0/' );
02914     }
02915 
02921     public function getPriceFromPrefix()
02922     {
02923         $sPricePrefics = '';
02924         if ( $this->_blIsRangePrice) {
02925             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02926         }
02927 
02928         return $sPricePrefics;
02929     }
02930 
02939     protected function _saveArtLongDesc($iLang, $sValue)
02940     {
02941         $oDB = oxDb::getDb();
02942         $iLang = (int) $iLang;
02943         $sLangField = ($iLang > '0') ? '_'.$iLang : '';
02944         $sLongDesc = $oDB->quote($sValue);
02945         $sLongDescSQL = "insert into oxartextends (oxartextends.OXID, oxartextends.OXLONGDESC{$sLangField})
02946                        VALUES ('".$this->getId()."', {$sLongDesc})
02947                        ON DUPLICATE KEY update oxartextends.OXLONGDESC{$sLangField} = {$sLongDesc} ";
02948 
02949         $oDB->execute($sLongDescSQL);
02950     }
02951 
02957     protected function _skipSaveFields()
02958     {
02959         $myConfig = $this->getConfig();
02960 
02961         $this->_aSkipSaveFields = array();
02962 
02963         $this->_aSkipSaveFields[] = 'oxtimestamp';
02964         $this->_aSkipSaveFields[] = 'oxlongdesc';
02965         $this->_aSkipSaveFields[] = 'oxinsert';
02966 
02967         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02968             $this->_aSkipSaveFields[] = 'oxparentid';
02969         }
02970 
02971     }
02972 
02982     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02983     {
02984         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02985             // add prices of the same discounts
02986             if ( array_key_exists ($sKey, $aDiscounts) ) {
02987                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02988             } else {
02989                 $aDiscounts[$sKey] = $oDiscount;
02990             }
02991         }
02992         return $aDiscounts;
02993     }
02994 
03000     protected function _getGroupPrice()
03001     {
03002         $dPrice = $this->oxarticles__oxprice->value;
03003 
03004         $oUser = $this->getArticleUser();
03005         if ( $oUser ) {
03006             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03007                 $dPrice = $this->oxarticles__oxpricea->value;
03008             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03009                 $dPrice = $this->oxarticles__oxpriceb->value;
03010             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03011                 $dPrice = $this->oxarticles__oxpricec->value;
03012             }
03013         }
03014 
03015         // #1437/1436C - added config option, and check for zero A,B,C price values
03016         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03017             $dPrice = $this->oxarticles__oxprice->value;
03018         }
03019 
03020         return $dPrice;
03021     }
03022 
03031     protected function _getAmountPrice($dAmount = 1)
03032     {
03033         $myConfig = $this->getConfig();
03034 
03035         startProfile( "_getAmountPrice" );
03036 
03037         $dPrice = $this->_getGroupPrice();
03038         $oAmtPrices = $this->_getAmountPriceList();
03039         foreach ($oAmtPrices as $oAmPrice) {
03040             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03041                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03042                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03043                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03044             }
03045         }
03046 
03047         stopProfile( "_getAmountPrice" );
03048         return $dPrice;
03049     }
03050 
03059     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03060     {
03061         $myConfig = $this->getConfig();
03062         // #690
03063         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03064 
03065             $aSelLists = $this->getSelectLists();
03066             foreach ( $aSelLists as $key => $aSel) {
03067                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03068                     $oSel = $aSel[$aChosenList[$key]];
03069                     if ( $oSel->priceUnit =='abs' ) {
03070                         $dPrice += $oSel->price;
03071                     } elseif ( $oSel->priceUnit =='%' ) {
03072                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03073                     }
03074                 }
03075             }
03076         }
03077         return $dPrice;
03078     }
03079 
03080 
03088     protected function _fillAmountPriceList($oAmPriceList)
03089     {
03090         $myConfig = $this->getConfig();
03091         $myUtils  = oxUtils::getInstance();
03092 
03093         //modifying price
03094         $oCur = $myConfig->getActShopCurrencyObject();
03095 
03096         $oUser = $this->getArticleUser();
03097 
03098         $oDiscountList = oxDiscountList::getInstance();
03099         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03100 
03101         $oLowestPrice = null;
03102 
03103         $dBasePrice = $this->_getGroupPrice();
03104         $oLang = oxLang::getInstance();
03105 
03106         $dArticleVat = null;
03107         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03108             $dArticleVat = $this->getArticleVat();
03109         }
03110 
03111         // trying to find lowest price value
03112         foreach ($oAmPriceList as $sId => $oItem) {
03113             $oItemPrice = oxNew( 'oxprice' );
03114             if ( $oItem->oxprice2article__oxaddabs->value) {
03115                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03116                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03117                 $this->_applyCurrency( $oItemPrice, $oCur );
03118             } else {
03119                 $oItemPrice->setPrice( $dBasePrice );
03120                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03121             }
03122 
03123             if (isset($dArticleVat)) {
03124                 $this->_applyVAT($oItemPrice, $dArticleVat);
03125             }
03126 
03127             if (!$oLowestPrice) {
03128                 $oLowestPrice = $oItemPrice;
03129             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03130                 $oLowestPrice = $oItemPrice;
03131             }
03132 
03133             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03134             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03135             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03136         }
03137 
03138         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03139         return $oAmPriceList;
03140     }
03141 
03147     protected function _getVariantsIds()
03148     {
03149         $aSelect = array();
03150         $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->getId()."' " );
03151         if ( $oRs != false && $oRs->recordCount() > 0 ) {
03152             while (!$oRs->EOF) {
03153                 $aSelect[] = $oRs->fields['oxid'];
03154                 $oRs->moveNext();
03155             }
03156         }
03157         return $aSelect;
03158     }
03159 
03165     public function getArticleVat()
03166     {
03167         if (!isset($this->_dArticleVat)) {
03168             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03169         }
03170         return $this->_dArticleVat;
03171     }
03172 
03181     protected function _applyVAT( oxPrice $oPrice, $dVat )
03182     {
03183         startProfile(__FUNCTION__);
03184         $oPrice->setVAT( $dVat );
03185         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03186             $oPrice->setUserVat( $dVat );
03187         }
03188         stopProfile(__FUNCTION__);
03189     }
03190 
03198     public function applyVats( oxPrice $oPrice )
03199     {
03200         $this->_applyVAT($oPrice,
03201                          $this->getArticleVat()
03202                         );
03203     }
03204 
03215     protected function _applyDiscounts( $oPrice, $aDiscounts )
03216     {
03217         $oDiscountList = oxDiscountList::getInstance();
03218         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03219     }
03220 
03228     public function applyDiscountsForVariant( $oPrice )
03229     {
03230         // apply discounts
03231         if ( !$this->skipDiscounts() ) {
03232             $oDiscountList = oxDiscountList::getInstance();
03233             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03234         }
03235     }
03236 
03245     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03246     {
03247         if ( !$oCur ) {
03248             $oCur = $this->getConfig()->getActShopCurrencyObject();
03249         }
03250 
03251         $oPrice->multiply($oCur->rate);
03252     }
03253 
03254 
03263     protected function _getAttribsString(&$sAttribs, &$iCnt)
03264     {
03265         // we do not use lists here as we dont need this overhead right now
03266         $oDB = oxDb::getDb(true);
03267         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03268         $sAttribs = '';
03269         $blSep = false;
03270         $rs = $oDB->execute( $sSelect);
03271         $iCnt = 0;
03272         if ($rs != false && $rs->recordCount() > 0) {
03273             while (!$rs->EOF) {
03274                 if ( $blSep) {
03275                     $sAttribs .= ' or ';
03276                 }
03277                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03278                 $blSep = true;
03279                 $iCnt++;
03280                 $rs->moveNext();
03281             }
03282         }
03283     }
03284 
03293     protected function _getSimList($sAttribs, $iCnt)
03294     {
03295         $myConfig = $this->getConfig();
03296         $oDB      = oxDb::getDb(true);
03297 
03298         // #523A
03299         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03300         // 70% same attributes
03301         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03302             $iAttrPercent = 0.70;
03303         }
03304         // #1137V iAttributesPercent = 100 doesnt work
03305         $iHitMin = ceil( $iCnt * $iAttrPercent );
03306 
03307         // we do not use lists here as we dont need this overhead right now
03308         $aList= array();
03309         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03310                     ( $sAttribs )
03311                     and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03312                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03313 
03314         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03315         if ($rs != false && $rs->recordCount() > 0) {
03316             while (!$rs->EOF) {
03317                 $oTemp = new stdClass();    // #663
03318                 $oTemp->cnt = $rs->fields['cnt'];
03319                 $oTemp->id  = $rs->fields['oxobjectid'];
03320                 $aList[] = $oTemp;
03321                 $rs->moveNext();
03322             }
03323         }
03324         return $aList;
03325     }
03326 
03335     protected function _generateSimListSearchStr($sArticleTable, $aList)
03336     {
03337         $myConfig = $this->getConfig();
03338         $sFieldList = $this->getSelectFields();
03339         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03340         $blSep = false;
03341         $iCnt = 0;
03342         $oDb = oxDb::getDb();
03343         foreach ( $aList as $oTemp) {
03344             if ( $blSep) {
03345                 $sSearch .= ',';
03346             }
03347             $sSearch .= $oDb->quote($oTemp->id);
03348             $blSep = true;
03349             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03350                 break;
03351             }
03352             $iCnt++;
03353         }
03354 
03355         //#1741T
03356         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03357         $sSearch .= ') ';
03358 
03359         // #524A -- randomizing articles in attribute list
03360         $sSearch .= ' order by rand() ';
03361 
03362         return $sSearch;
03363     }
03364 
03373     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03374     {
03375         $sCatView = getViewName( 'oxcategories' );
03376         $sO2CView = getViewName( 'oxobject2category' );
03377 
03378         // we do not use lists here as we dont need this overhead right now
03379         if ( !$blSearchPriceCat ) {
03380             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03381                          {$sCatView}.oxid = oxobject2category.oxcatnid
03382                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03383         } else {
03384             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03385                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03386                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03387         }
03388         return $sSelect;
03389     }
03390 
03396     protected function _generateSearchStrForCustomerBought()
03397     {
03398         $sArtTable = $this->_getObjectViewName( 'oxarticles' );
03399         $sOrderArtTable = getViewName( 'oxorderarticles' );
03400 
03401         // fetching filter params
03402         $sIn = " '{$this->oxarticles__oxid->value}' ";
03403         if ( $this->oxarticles__oxparentid->value ) {
03404 
03405             // adding article parent
03406             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03407             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03408 
03409         } else {
03410             $sParentIdForVariants = $this->getId();
03411         }
03412 
03413         // adding variants
03414         $oDb = oxDb::getDb(true);
03415         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03416         if ( $oRs != false && $oRs->recordCount() > 0) {
03417             while ( !$oRs->EOF ) {
03418                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03419                 $oRs->moveNext();
03420             }
03421         }
03422 
03423         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03424         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03425 
03426         // building sql (optimized)
03427         $sQ = "select distinct {$sArtTable}.* from (
03428                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03429                ) as suborder
03430                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03431                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03432                where {$sArtTable}.oxid not in ( {$sIn} )
03433                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03434 
03435         /* non optimized, but could be used if index forcing is not supported
03436         // building sql
03437         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03438                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03439                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03440                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03441                and ".$this->getSqlActiveSnippet();
03442         */
03443 
03444         return $sQ;
03445     }
03446 
03456     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03457     {
03458         $sCategoryView = getViewName('oxcategories');
03459         $sO2CView = getViewName('oxobject2category');
03460         $sLangPrefix = (($this->getLanguage())?'_'.$this->getLanguage():'');
03461 
03462         $oDb    = oxDb::getDb();
03463         $sOXID  = $oDb->quote($sOXID);
03464         $sCatId = $oDb->quote($sCatId);
03465 
03466         if (!$dPriceFromTo) {
03467             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03468             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03469             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03470             $sSelect .= "and oxcategories.oxactive$sLangPrefix = 1 order by oxobject2category.oxtime ";
03471         } else {
03472             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03473             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03474             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03475             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03476         }
03477         return $sSelect;
03478     }
03479 
03485     protected function _getAmountPriceList()
03486     {
03487         if ($this->_oAmountPriceList) {
03488             return $this->_oAmountPriceList;
03489         }
03490 
03491         $myConfig = $this->getConfig();
03492 
03493         $sArtID  = $this->getId();
03494 
03495         // #1690C - Scale prices and variants
03496         if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03497             $sArtID = $this->oxarticles__oxparentid->value;
03498         }
03499 
03500         // echo( "TODO replace oxlist usage here _collectAmPriceList".PHP_EOL);
03501         $sArtID = mysql_real_escape_string($sArtID);
03502 
03503         //collecting assigned to article amount-price list
03504         $oAmPriceList = oxNew( 'oxlist');
03505         $oAmPriceList->init('oxbase', 'oxprice2article');
03506 
03507         $sShopID = $myConfig->getShopID();
03508         if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03509             $sShopSelect = '1';
03510         } else {
03511             $sShopSelect = " oxshopid =  '$sShopID' ";
03512         }
03513 
03514         $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03515 
03516         // prepare abs prices if currently having percentages
03517         $oBasePrice = $this->_getGroupPrice();
03518         foreach ($oAmPriceList as $oAmPrice) {
03519             if ($oAmPrice->oxprice2article__oxaddperc->value) {
03520                 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03521             }
03522         }
03523 
03524         $this->_oAmountPriceList = $oAmPriceList;
03525         return $oAmPriceList;
03526     }
03527 
03535     protected function _isFieldEmpty($sFieldName)
03536     {
03537         $mValue = $this->$sFieldName->value;
03538 
03539         if (is_null($mValue)) {
03540             return true;
03541         }
03542 
03543         if ($mValue === '') {
03544             return true;
03545         }
03546 
03547         $aDoubleCopyFields = array('oxarticles__oxprice',
03548                                        'oxarticles__oxvat');
03549 
03550         if (!$mValue && in_array($sFieldName, $aDoubleCopyFields)) {
03551             return true;
03552         }
03553 
03554 
03555         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03556             return true;
03557         }
03558 
03559         $sFieldName = strtolower($sFieldName);
03560 
03561         if ( $sFieldName == 'oxarticles__oxicon' && strpos($mValue, "nopic_ico.jpg") !== false ) {
03562             return true;
03563         }
03564 
03565         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03566             return true;
03567         }
03568 
03569         return false;
03570     }
03571 
03579     protected function _assignParentFieldValue($sFieldName)
03580     {
03581         if (!($oParentArticle = $this->getParentArticle())) {
03582             return;
03583         }
03584 
03585         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03586 
03587         // assigning only theese which parent article has
03588         if ( $oParentArticle->$sCopyFieldName != null ) {
03589 
03590             // only overwrite database values
03591             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03592                 continue;
03593             }
03594 
03595             //do not copy certain fields
03596             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03597                 return;
03598             }
03599 
03600             //do not copy parent data for icons in case we have (need) own variant icon (in case variant thumbnail exists)
03601             if ($sFieldName == "oxicon" && !$this->_isFieldEmpty("oxarticles__oxthumb") && $this->oxarticles__oxthumb->value != $oParentArticle->oxarticles__oxthumb->value && $this->getConfig()->getConfigParam( 'blAutoIcons' ) ) {
03602                 return ;
03603             }
03604 
03605             //COPY THE VALUE
03606             //replaced the code bellow with this two liner
03607             //T2009-01-12
03608             if ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03609                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03610             }
03611 
03612 
03613             /*
03614             //#1101S empty image fields (without nopic.jpg, nopic_ico.jpg) should be copied from parent too
03615             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 == '')) {
03616                 // pictures
03617                 if ( $this->_blLoadParentData && $this->isAdmin() ) {
03618                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03619                 } else {
03620                     $aFile = explode( '/', $oParentArticle->$sCopyFieldName->value);
03621                     $this->$sCopyFieldName->setValue(basename);
03622                 }
03623             } elseif ( $this->$sCopyFieldName->value == '' ||
03624                     $this->$sCopyFieldName->value == '0000-00-00 00:00:00' ||
03625                     $this->$sCopyFieldName->value == '0000-00-00' ||
03626                     ( in_array($sCopyFieldName, $aDoubleCopyFields) && $this->$sCopyFieldName->value == 0)
03627                    ) {
03628                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03629             }
03630 
03631             //another fields which should be copied from parent if empty and not covered by above condition
03632             $aCopyParentField = array('oxarticles__oxnonmaterial',
03633                                       'oxarticles__oxfreeshipping',
03634                                       'oxarticles__oxremindactive');
03635             if (!$this->$sCopyFieldName->value && in_array($sCopyFieldName, $aCopyParentField)) {
03636                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03637             }*/
03638         }
03639     }
03640 
03646     public function getParentArticle()
03647     {
03648         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03649             if ( !isset( self::$_aLoadedParents[$sParentId] ) ) {
03650                 self::$_aLoadedParents[$sParentId] = oxNew( 'oxarticle' );
03651                 self::$_aLoadedParents[$sParentId]->_blSkipAbPrice  = true;
03652                 self::$_aLoadedParents[$sParentId]->_blLoadPrice    = false;
03653                 self::$_aLoadedParents[$sParentId]->_blLoadVariants = false;
03654                 self::$_aLoadedParents[$sParentId]->load( $sParentId );
03655             }
03656             return self::$_aLoadedParents[$sParentId];
03657         }
03658     }
03659 
03667     protected function _getParentAricle()
03668     {
03669         return $this->getParentArticle();
03670     }
03671 
03677     protected function _assignParentFieldValues()
03678     {   startProfile('articleAssignParentInternal');
03679         if ( $this->oxarticles__oxparentid->value) {
03680             // yes, we are in fact a variant
03681             if ( !$this->isAdmin() || ($this->_blLoadParentData && $this->isAdmin() ) ) {
03682                 foreach ($this->_aFieldNames as $sFieldName => $sVal) {
03683                     $this->_assignParentFieldValue($sFieldName);
03684                 }
03685 
03686                 //assing long description
03687                 $oParentArticle = $this->getParentArticle();
03688                 if ( !$this->oxarticles__oxlongdesc->value ) {
03689                     $this->oxarticles__oxlongdesc = $oParentArticle->oxarticles__oxlongdesc;
03690                 }
03691 
03692             }
03693         } elseif ( $this->oxarticles__oxid->value ) {
03694             // I am not a variant but I might have some
03695             //$this->_oVariantList = $this->getSimpleVariants();
03696             startProfile("loadVariants");
03697             $this->_oVariantList = $this->getVariants();
03698             stopProfile("loadVariants");
03699             // #1650M - article title with <br> tag
03700             // htmlspecialchars parses only 5 characters, so i have stiped out '<' and '>'
03701             /*
03702             if ( !$this->isAdmin() ) {
03703                 $this->oxarticles__oxtitle->setValue(str_replace(array('&', "'", '"'), array('&amp;', '&#039;', '&quot;'), $this->oxarticles__oxtitle->value));
03704             }*/
03705         }
03706         stopProfile('articleAssignParentInternal');
03707 
03708     }
03709 
03715     protected function _assignNotBuyableParent()
03716     {
03717         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03718              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03719             $this->_blNotBuyableParent = true;
03720 
03721         }
03722     }
03723 
03729     protected function _assignAllPictureValues()
03730     {
03731         $myConfig = $this->getConfig();
03732 
03733         $this->_assignPictureValues( "oxarticles__oxicon" );
03734         $this->_assignPictureValues( "oxarticles__oxthumb" );
03735 
03736         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03737         for ( $i=1; $i<= $iPicCount; $i++ ) {
03738             $this->_assignPictureValues( "oxarticles__oxpic".$i );
03739         }
03740 
03741         if ( $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' ) ) {
03742             for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03743                 $this->_assignPictureValues( "oxarticles__oxzoom".$i );
03744             }
03745         }
03746     }
03747 
03755     protected function _assignPictureValues( $sName='' )
03756     {
03757         if ( $this->isAdmin() || !$sName ) {
03758             return;
03759         }
03760 
03761         $sFieldName = substr_replace( $sName, "", 0, 12);
03762         $myConfig = $this->getConfig();
03763 
03764         // add directories
03765         if ( $sFieldName == 'oxicon' && isset($this->_aFieldNames["oxicon"]) ) {
03766             $this->oxarticles__oxicon = new oxField('icon/'.$this->_getIconName());
03767             return;
03768         }
03769 
03770         if ( $sFieldName == 'oxthumb' && isset($this->_aFieldNames["oxthumb"]) ) {
03771             $this->oxarticles__oxthumb = new oxField('0/'.$this->_getThumbnailName());
03772             return;
03773         }
03774 
03775         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03776 
03777         if ( strpos($sFieldName, "oxpic") === 0 && isset($this->_aFieldNames[$sFieldName] ) ) {
03778 
03779             $iIndex = (int) str_ireplace( "oxpic", "", $sFieldName );
03780 
03781             if ( $iIndex > 0 && $iIndex < $iPicCount ) {
03782                 $this->$sName = new oxField( $iIndex . '/'.$this->_getPictureName($iIndex) );
03783                 $this->{$sName.'_ico'} = new oxField( $iIndex . '/'.$this->_getIconName($iIndex) );
03784                 return;
03785             }
03786         }
03787 
03788         if ( strpos($sFieldName, "oxzoom") === 0 ) {
03789 
03790             $iIndex = (int) str_ireplace( "oxzoom", "", $sFieldName );
03791 
03792             // if oxzoom or oxpic field with same index is setted, loading field values
03793             if ( isset($this->_aFieldNames[$sFieldName]) || isset($this->_aFieldNames["oxpic".$iIndex]) ) {
03794                 if ( $iIndex > 0 && $iIndex < $iPicCount ) {
03795                     $this->$sName = new oxField( 'z' . $iIndex.'/'.$this->_getZoomPictureName($iIndex) );
03796                     return;
03797                 }
03798             }
03799         }
03800     }
03801 
03807     protected function _assignStock()
03808     {
03809         $myConfig = $this->getConfig();
03810         // -----------------------------------
03811         // stock
03812         // -----------------------------------
03813 
03814         // #1125 A. must round (using floor()) value taken from database and cast to int
03815         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03816             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03817         }
03818         //GREEN light
03819         $this->_iStockStatus = 0;
03820 
03821         // if we have flag /*1 or*/ 4 - we show always green light
03822         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03823             //ORANGE light
03824             $iStock = $this->oxarticles__oxstock->value;
03825 
03826             if ($this->_blNotBuyableParent) {
03827                 $iStock = $this->oxarticles__oxvarstock->value;
03828             }
03829 
03830 
03831             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03832                 $this->_iStockStatus = 1;
03833             }
03834 
03835             //RED light
03836             if ($iStock <= 0) {
03837                 $this->_iStockStatus = -1;
03838             }
03839         }
03840 
03841 
03842         // stock
03843         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstock->value <= 0 && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03844             $this->_blNotBuyable = true;
03845         }
03846 
03847         //exceptional handling for variant parent stock:
03848         if ($this->_blNotBuyable && $this->_iVarStock) {
03849             $this->_blNotBuyable = false;
03850             //but then at least setting notBuaybleParent to true
03851             $this->_blNotBuyableParent = true;
03852         }
03853 
03854         //special treatment for lists when blVariantParentBuyable config option is set to false
03855         //then we just hide "to basket" button.
03856         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03857         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03858             $this->_blNotBuyable = true;
03859         }
03860 
03861         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03862         if ($this->_blNotBuyableParent && count($this->_oVariantList) == 0) {
03863             $this->_blNotBuyable = true;
03864         }
03865     }
03866 
03872     protected function _assignPrices()
03873     {
03874         $myConfig = $this->getConfig();
03875 
03876         // Performance
03877         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03878             return;
03879         }
03880 
03881         // compute price
03882         $dPrice = $this->getPrice()->getBruttoPrice();
03883 
03884         $oCur = $myConfig->getActShopCurrencyObject();
03885         //price per unit handling
03886         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03887             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03888         }
03889 
03890 
03891         //getting min and max prices of variants
03892         $this->_applyRangePrice();
03893     }
03894 
03900     protected function _assignPersistentParam()
03901     {
03902         // Persistent Parameter Handling
03903         $aPersParam     = oxSession::getVar( 'persparam');
03904         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03905             $this->_aPersistParam = $aPersParam[$this->getId()];
03906         }
03907     }
03908 
03914     protected function _assignDynImageDir()
03915     {
03916         $myConfig = $this->getConfig();
03917 
03918         $sThisShop = $this->oxarticles__oxshopid->value;
03919 
03920         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03921         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03922         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03923         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03924     }
03925 
03931     protected function _assignComparisonListFlag()
03932     {
03933         // #657 add a flag if article is on comparisonlist
03934 
03935         $aItems = oxConfig::getParameter('aFiltcompproducts');
03936         if ( isset( $aItems[$this->getId()])) {
03937             $this->_blIsOnComparisonList = true;
03938         }
03939     }
03940 
03946     protected function _assignAttributes()
03947     {
03948         //#1029T load attributes
03949         //#1078S removed check for module "Produktvergleich"
03950         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03951             $this->getAttributes();
03952         }
03953     }
03954 
03955 
03963     protected function _insert()
03964     {
03965         // set oxinsert
03966         $iInsertTime = time();
03967         $now = date('Y-m-d H:i:s', $iInsertTime);
03968         $this->oxarticles__oxinsert    = new oxField( $now );
03969         $this->oxarticles__oxtimestamp = new oxField( $now );
03970         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03971             $this->oxarticles__oxsubclass = new oxField('oxarticle');
03972         }
03973 
03974         return parent::_insert();
03975     }
03976 
03982     protected function _update()
03983     {
03984 
03985         $this->_skipSaveFields();
03986 
03987         $myConfig = $this->getConfig();
03988 
03989 
03990         return parent::_update();
03991     }
03992 
04000     protected function _deleteRecords($sOXID)
04001     {
04002         $oDB = oxDb::getDb();
04003 
04004         $sOXID = $oDB->quote($sOXID);
04005 
04006         //delete the record
04007         $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
04008         $oDB->execute( $sDelete);
04009 
04010         //remove other records
04011         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
04012         $oDB->execute( $sDelete);
04013 
04014         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
04015         $oDB->execute( $sDelete);
04016 
04017         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
04018         $oDB->execute( $sDelete);
04019 
04020         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
04021         $oDB->execute( $sDelete);
04022 
04023         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
04024         $oDB->execute( $sDelete);
04025 
04026         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
04027         $oDB->execute( $sDelete);
04028 
04029         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
04030         $oDB->execute( $sDelete);
04031 
04032         //#1508C - deleting oxobject2delivery entries added
04033         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04034         $oDB->execute( $sDelete);
04035 
04036         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04037         $oDB->execute( $sDelete);
04038 
04039         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04040         $rs = $oDB->execute( $sDelete );
04041 
04042         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04043         $rs = $oDB->execute( $sDelete );
04044 
04045 
04046         return $rs;
04047     }
04048 
04056     protected function _deleteVariantRecords($sOXID)
04057     {
04058         $oDB = oxDb::getDb();
04059         //collect variants to remove recursively
04060         $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDB->quote($sOXID);
04061         $rs = $oDB->execute( $sVariants);
04062         if ($rs != false && $rs->recordCount() > 0) {
04063             while (!$rs->EOF) {
04064                 $this->delete( $rs->fields[0]);
04065                 $rs->moveNext();
04066             }
04067         }
04068     }
04069 
04079     protected function _resetCacheAndArticleCount( $sOxid )
04080     {
04081         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04082     }
04083 
04089     protected function _deletePics()
04090     {
04091         $myUtilsPic = oxUtilsPic::getInstance();
04092         $myConfig   = $this->getConfig();
04093         $oPictureHandler = oxPictureHandler::getInstance();
04094 
04095         //deleting custom main icon
04096         $oPictureHandler->deleteMainIcon( $this );
04097 
04098         //deleting custom thumbnail
04099         $oPictureHandler->deleteThumbnail( $this );
04100 
04101         $sAbsDynImageDir = $myConfig->getAbsDynImageDir();
04102 
04103         // deleting master image and all generated images
04104         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04105         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04106             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04107         }
04108     }
04109 
04119     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04120     {
04121 
04122         $myUtilsCount = oxUtilsCount::getInstance();
04123 
04124         if ( $sVendorId ) {
04125             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04126         }
04127 
04128         if ( $sManufacturerId ) {
04129             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04130         }
04131 
04132         //also reseting category counts
04133         $oDb = oxDb::getDb();
04134         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04135         $oRs = $oDb->execute( $sQ );
04136         if ( $oRs !== false && $oRs->recordCount() > 0) {
04137             while ( !$oRs->EOF ) {
04138                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04139                 $oRs->moveNext();
04140             }
04141         }
04142     }
04143 
04151     protected function _onChangeUpdateStock( $sParentID )
04152     {
04153         $oDb = oxDb::getDb();
04154         $sParentIdQuoted = $oDb->quote($sParentID);
04155         $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04156         $rs = $oDb->execute($sQ);
04157         $iOldStock = $rs->fields[0];
04158         $iVendorID = $rs->fields[1];
04159         $iManufacturerID = $rs->fields[2];
04160 
04161         $sQ = 'select sum(oxstock) from oxarticles where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04162         $iStock = (float) $oDb->getOne( $sQ );
04163 
04164         $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04165         $oDb->execute( $sQ );
04166 
04167             //now lets update category counts
04168             //first detect stock status change for this article (to or from 0)
04169             if ( $iStock < 0 ) {
04170                 $iStock = 0;
04171             }
04172             if ( $iOldStock < 0 ) {
04173                 $iOldStock = 0;
04174             }
04175             if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04176                 //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04177                 // so far we leave it like this but later we could move all count resets to one or two functions
04178                 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04179             }
04180     }
04181 
04189     protected function _onChangeStockResetCount( $sOxid )
04190     {
04191         $myConfig = $this->getConfig();
04192 
04193         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04194            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04195 
04196                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04197         }
04198     }
04199 
04207     protected function _onChangeUpdateVarCount( $sParentID )
04208     {
04209         $oDb = oxDb::getDb();
04210         $sParentIdQuoted = $oDb->quote($sParentID);
04211         $sQ = 'select count(*) as varcount from oxarticles where oxparentid = '.$sParentIdQuoted;
04212         $iVarCount = (int) $oDb->getOne($sQ);
04213 
04214         $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = '.$sParentIdQuoted;
04215         $oDb->execute($sQ);
04216     }
04217 
04225     protected function _onChangeUpdateMinVarPrice( $sParentID )
04226     {
04227         $oDb = oxDb::getDb();
04228         $sParentIdQuoted = $oDb->quote($sParentID);
04229         //#M0000883 (Sarunas)
04230         $sQ = 'select min(oxprice) as varminprice from oxarticles where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted;
04231         //#M0000886 (Sarunas)
04232         if ( $this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) ) {
04233             $sQ .= ' or oxid = '.$sParentIdQuoted;
04234         } else {
04235             $sQ .= ' or (oxid = '.$sParentIdQuoted.' and oxvarcount=0)';
04236         }
04237         $sQ .= ')';
04238         $dVarMinPrice = $oDb->getOne($sQ);
04239         if ( $dVarMinPrice ) {
04240             $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04241             $oDb->execute($sQ);
04242         }
04243     }
04244 
04245 
04251     protected function _applyRangePrice()
04252     {
04253         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04254         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04255             return;
04256         }
04257 
04258         $this->_blIsRangePrice = false;
04259 
04260         // if parent is buyable - do not apply range price calcculations
04261         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04262             return;
04263         }
04264 
04265         $aPrices = array();
04266 
04267         if (!$this->_blNotBuyableParent) {
04268             $aPrices[] = $this->getPrice()->getBruttoPrice();
04269         }
04270 
04271         if (count($this->_oVariantList)) {
04272             foreach ($this->_oVariantList as $sKey => $oVariant) {
04273                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04274             }
04275         }
04276 
04277         /*  $oAmPrices = $this->loadAmountPriceInfo();
04278         foreach ($oAmPrices as $oAmPrice) {
04279             $aPrices[] = $oAmPrice->oxprice2article__oxaddabs->value;
04280         }*/
04281 
04282         if (count($aPrices)) {
04283             $dMinPrice = $aPrices[0];
04284             $dMaxPrice = $aPrices[0];
04285             foreach ($aPrices as $dPrice) {
04286                 if ($dMinPrice > $dPrice) {
04287                     $dMinPrice = $dPrice;
04288                 }
04289 
04290                 if ($dMaxPrice < $dPrice) {
04291                     $dMaxPrice = $dPrice;
04292                 }
04293             }
04294         }
04295 
04296         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04297             $this->getPrice()->setBruttoPriceMode();
04298             $this->getPrice()->setPrice($dMinPrice);
04299         }
04300 
04301         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04302             $this->getPrice()->setBruttoPriceMode();
04303             $this->getPrice()->setPrice($dMinPrice);
04304             $this->_blIsRangePrice = true;
04305         }
04306 
04307         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04308             $this->getPrice()->setBruttoPriceMode();
04309             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04310             $this->_blIsRangePrice = true;
04311             $this->_calculatePrice( $this->getPrice() );
04312         }
04313     }
04314 
04321     public function getProductId()
04322     {
04323         return $this->getId();
04324     }
04325 
04331     public function getProductParentId()
04332     {
04333         return $this->oxarticles__oxparentid->value;
04334     }
04335 
04341     public function isOrderArticle()
04342     {
04343         return false;
04344     }
04345 
04351     public function isVariant()
04352     {
04353         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04354     }
04355 
04361     public function isMdVariant()
04362     {
04363         $oMdVariant = oxNew( "oxVariantHandler" );
04364 
04365         return $oMdVariant->isMdVariant($this);
04366     }
04367 
04375     public function getSqlForPriceCategories($sFields = '')
04376     {
04377         if (!$sFields) {
04378             $sFields = 'oxid';
04379         }
04380         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04381         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04382         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04383                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04384                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04385     }
04386 
04394     public function inPriceCategory( $sCatNid )
04395     {
04396         $oDb = oxDb::getDb();
04397 
04398         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04399         $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04400         return (bool) $oDb->getOne(
04401             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04402            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04403            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04404            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04405            .")"
04406         );
04407     }
04408 
04414     public function getMdVariants()
04415     {
04416         if ( $this->_oMdVariants ) {
04417             return $this->_oMdVariants;
04418         }
04419 
04420         $oParentArticle = $this->getParentArticle();
04421         if ( $oParentArticle ) {
04422             $oVariants = $oParentArticle->getVariants();
04423         } else {
04424             $oVariants = $this->getVariants();
04425         }
04426 
04427         $oVariantHandler = oxNew( "oxVariantHandler" );
04428         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04429 
04430         return $this->_oMdVariants;
04431     }
04432 
04438     public function getMdSubvariants()
04439     {
04440         return $this->getMdVariants()->getMdSubvariants();
04441     }
04442 
04443 
04452     protected function _generateImages( $iIndex )
04453     {
04454         if ( isset($this->_aFieldNames["oxpic".$iIndex]) && !$this->_hasGeneratedImage( $iIndex ) ) {
04455             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) && $this->_hasMasterImage( $iIndex ) ) {
04456                 $oPictureHandler = oxPictureHandler::getInstance();
04457                 $oPictureHandler->generateArticlePictures( $this, $iIndex );
04458             }
04459         }
04460     }
04461 
04470     public function updateAmountOfGeneratedPictures( $iTotalGenerated )
04471     {
04472         $sQ = "UPDATE oxarticles SET oxpicsgenerated = '$iTotalGenerated' WHERE oxid = '".$this->getId()."'";
04473         oxDb::getDb()->execute($sQ);
04474 
04475         $this->oxarticles__oxpicsgenerated = new oxField( $iTotalGenerated );
04476     }
04477 
04486     protected function _hasGeneratedImage( $iIndex )
04487     {
04488         if ( $iIndex > (int) $this->oxarticles__oxpicsgenerated->value ) {
04489             return false;
04490         }
04491 
04492         return true;
04493     }
04494 
04502     protected function _hasMasterImage( $iIndex )
04503     {
04504         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04505 
04506         if ( $sPicName == "nopic.jpg" ) {
04507             return false;
04508         }
04509 
04510         $sMasterPic = $iIndex . "/" . $sPicName;
04511 
04512         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04513             return true;
04514         }
04515 
04516         return false;
04517     }
04518 }

Generated by  doxygen 1.6.2