oxarticle.php

Go to the documentation of this file.
00001 <?php
00002 
00003 // defining supported link types
00004 define( 'OXARTICLE_LINKTYPE_CATEGORY', 0 );
00005 define( 'OXARTICLE_LINKTYPE_VENDOR', 1 );
00006 define( 'OXARTICLE_LINKTYPE_MANUFACTURER', 2 );
00007 define( 'OXARTICLE_LINKTYPE_PRICECATEGORY', 3 );
00008 define( 'OXARTICLE_LINKTYPE_TAG', 4 );
00009 define( 'OXARTICLE_LINKTYPE_RECOMM', 5 );
00010 
00017 class oxArticle extends oxI18n implements oxIArticle, oxIUrl
00018 {
00024     protected $_sCoreTbl = 'oxarticles';
00025 
00031     protected $_sClassName = 'oxarticle';
00032 
00038     protected $_blUseLazyLoading = true;
00039 
00045     protected $_sItemKey;
00046 
00052     protected $_blCalcPrice    = true;
00053 
00058     protected $_oPrice      = null;
00059 
00065     protected $_dArticleVat = null;
00066 
00072     protected $_aPersistParam  = null;
00073 
00079     protected $_blNotBuyable   = false;
00080 
00087     protected $_blLoadVariants = true;
00088 
00094     protected $_aVariants = null;
00095 
00101     protected $_aVariantsWithNotOrderables = null;
00102 
00111     protected $_blNotBuyableParent  = false;
00112 
00116     protected $_blHasVariants = false;
00117 
00121     protected $_blHasMdVariants = false;
00122 
00127     protected $_blIsOnComparisonList = false;
00128 
00133     protected $_oUser = null;
00134 
00140     protected $_blLoadPrice = true;
00141 
00145     protected $_blSkipAbPrice = false;
00146 
00153     protected $_fPricePerUnit = null;
00154 
00158     protected $_blLoadParentData = false;
00159 
00163     protected $_blSkipAssign = false;
00164 
00170     protected $_blSkipDiscounts = null;
00171 
00176     protected $_oAttributeList = null;
00177 
00178 
00184     protected $_blIsRangePrice = false;
00185 
00191     protected $_aMediaUrls = null;
00192 
00198     static protected $_aLoadedParents;
00199 
00205     static protected $_aSelList;
00206 
00212     protected $_aDispSelList;
00213 
00219     protected $_blIsSeoObject = true;
00220 
00226     protected $_oAmountPriceList = null;
00227 
00236     protected $_iLinkType = 0;
00237 
00243     protected $_aStdUrls = array();
00244 
00250     protected $_aSeoUrls = array();
00251 
00257     protected $_aSeoAddParams = array();
00258 
00264     protected $_aStdAddParams = array();
00265 
00271     protected $_sDynImageDir = null;
00272 
00278     protected $_sMoreDetailLink = null;
00279 
00285     protected $_sToBasketLink = null;
00286 
00292     protected $_iStockStatus = null;
00293 
00299     protected $_oTPrice = null;
00300 
00306     protected $_oAmountPriceInfo = null;
00307 
00313     protected $_dAmountPrice = null;
00314 
00320     protected static $_aArticleManufacturers = array();
00321 
00327     protected static $_aArticleVendors = array();
00328 
00334     protected static $_aArticleCats = array();
00335 
00341     protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00342                                              'oxarticles__oxtimestamp',
00343                                              'oxarticles__oxnid',
00344                                              'oxarticles__oxid',
00345                                              'oxarticles__oxparentid');
00346 
00352     protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00353                                          'oxarticles__oxfreeshipping',
00354                                          'oxarticles__oxremindactive');
00355 
00361     protected $_oMdVariants = null;
00362 
00371     public function __construct($aParams = null)
00372     {
00373         if ( $aParams && is_array($aParams)) {
00374             foreach ( $aParams as $sParam => $mValue) {
00375                 $this->$sParam = $mValue;
00376             }
00377         }
00378         parent::__construct();
00379         $this->init( 'oxarticles' );
00380 
00381         $this->_blIsRangePrice = false;
00382     }
00383 
00391     public function __isset( $sName )
00392     {
00393         if ( $sName == 'oxarticles__oxlongdesc' ) {
00394             //get empty oxlongdesc field
00395             $this->getArticleLongDesc();
00396             return true;
00397         }
00398         return isset( $this->$sName );
00399     }
00400 
00409     public function __get($sName)
00410     {
00411         $myUtils = oxUtils::getInstance();
00412         switch ($sName) {
00413             // NOT using caching here, because of these params should be used in templates ONLY
00414             // and in template files they are used not very much [once most of the time]
00415 
00416             // price related
00417             case 'netprice':
00418             case 'netPrice':
00419                 $mVal = $myUtils->fRound($this->getPrice()->getNettoPrice());
00420                 break;
00421             case 'brutPrice':
00422                 return $myUtils->fRound($this->getPrice()->getBruttoPrice());
00423                 break;
00424             case 'vatPercent':
00425                 return $this->getPrice()->getVAT();
00426                 break;
00427             case 'vat':
00428                 return $this->getPrice()->getVATValue();
00429                 break;
00430             case 'fnetprice':
00431                 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($this->getPrice()->getNettoPrice()));
00432                 break;
00433             case 'fprice':
00434                 return $this->getFPrice();
00435                 break;
00436 
00437             // t price related
00438             case 'dtprice':
00439                 if ( $oPrice = $this->getTPrice() ) {
00440                     return $myUtils->fRound($oPrice->getBruttoPrice());
00441                     break;
00442                 } else {
00443                     return null;
00444                     break;
00445                 }
00446             case 'tvat':
00447                 if ( $oPrice = $this->getTPrice() ) {
00448                     return $oPrice->getVATValue();
00449                     break;
00450                 } else {
00451                     return null;
00452                     break;
00453                 }
00454             case 'ftprice':
00455                 if ( $oPrice = $this->getTPrice() ) {
00456                     return oxLang::getInstance()->formatCurrency( $myUtils->fRound($oPrice->getBruttoPrice()) );
00457                     break;
00458                 } else {
00459                     return null;
00460                     break;
00461                 }
00462             case 'oxarticles__oxlongdesc':
00463                 return $this->getArticleLongDesc($this->getId());
00464                 break;
00465             case 'foxdelivery':
00466                 return $this->getDeliveryDate();
00467                 break;
00468             case 'sItemKey':
00469                 return $this->getItemKey();
00470                 break;
00471             case 'selectlist':
00472                 return $this->_aDispSelList = $this->getDispSelList();
00473                 break;
00474             case 'blNotBuyable':
00475                 return $this->isNotBuyable();
00476                 break;
00477             case 'blNotBuyableParent':
00478                 return $this->isParentNotBuyable();
00479                 break;
00480             case 'blIsOnComparisonList':
00481                 return $this->isOnComparisonList();
00482                 break;
00483             case 'oVariantlist' :
00484                 return $this->getVariants();
00485                 break;
00486             case 'fPricePerUnit' :
00487                 return $this->getPricePerUnit();
00488                 break;
00489             case 'dimagedir' :
00490                 return $this->_sDynImageDir = $this->getDynImageDir();
00491                 break;
00492             case 'oxmoredetaillink' :
00493                 return $this->_sMoreDetailLink = $this->getMoreDetailLink();
00494                 break;
00495             case 'amountpricelist' :
00496                 return $this->loadAmountPriceInfo();
00497                 break;
00498             case 'stockstatus' :
00499                 return $this->getStockStatus();
00500                 break;
00501             case 'tobasketlink' :
00502                 return $this->getToBasketLink();
00503                 break;
00504             case 'oxdetaillink' :
00505                 return $this->getLink();
00506                 break;
00507             case 'aSelectlist' :
00508                 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00509                     return $this->aSelectlist = $this->getSelectLists();
00510                 }
00511                 return;
00512                 break;
00513         }
00514 
00515         //checking for zoom picture
00516         if ( strpos($sName, "oxarticles__oxzoom") === 0 ) {
00517             $this->_assignZoomPictureValues( $sName );
00518             return $this->$sName;
00519         }
00520 
00521         $this->$sName = parent::__get($sName);
00522         if ( $this->$sName ) {
00523             $this->_assignParentFieldValue($sName);
00524         }
00525 
00526         //checking for picture information
00527         if ( $sName == "oxarticles__oxthumb" || $sName == "oxarticles__oxicon" || (strpos($sName, "oxarticles__oxpic") === 0 && $sName != "oxarticles__oxpicsgenerated") ) {
00528             $this->_assignPictureValues( $sName );
00529             return $this->$sName;
00530         }
00531 
00532         return $this->$sName;
00533     }
00534 
00542     public function setId( $sId = null )
00543     {
00544         $sId = parent::setId( $sId );
00545 
00546         // TODO: in oxbase::setId make it to check if exists and update, not recreate, then delete this overload
00547         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00548 
00549         return $sId;
00550     }
00551 
00559     public function getTableNameForActiveSnippet( $blForceCoreTable = false )
00560     {
00561             $sTable = $this->getCoreTableName();
00562 
00563         return $sTable;
00564     }
00565 
00575     public function getActiveCheckQuery( $blForceCoreTable = false )
00576     {
00577         $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00578 
00579         // check if article is still active
00580         $sQ = " $sTable.oxactive = 1 ";
00581 
00582         // enabled time range check ?
00583         if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00584             $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00585             $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00586         }
00587 
00588         return $sQ;
00589     }
00590 
00604     public function getStockCheckQuery( $blForceCoreTable = false )
00605     {
00606         $myConfig = $this->getConfig();
00607         $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00608 
00609         $sQ = "";
00610 
00611         //do not check for variants
00612         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00613             $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0  ) ";
00614             //V #M513: When Parent article is not purchaseble, it's visibility should be displayed in shop only if any of Variants is available.
00615             if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00616                 $sTimeCheckQ = '';
00617                 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00618                      $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00619                      $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00620                 }
00621                 $sQ = " $sQ and IF( $sTable.oxvarcount = 0, 1, ( select 1 from $sTable as art where art.oxparentid=$sTable.oxid and ( art.oxactive = 1 $sTimeCheckQ ) and ( art.oxstockflag != 2 or art.oxstock > 0 ) limit 1 ) ) ";
00622             }
00623         }
00624 
00625         return $sQ;
00626     }
00627 
00639     public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = false  )
00640     {
00641         $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00642         $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00643 
00644         //checking if variant is active and stock status
00645         if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00646             $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00647             if ( $blRemoveNotOrderables ) {
00648                 $sQ .= " and $sTable.oxstockflag != 3 ";
00649             }
00650             $sQ .= " ) ) ";
00651         }
00652 
00653         return $sQ;
00654     }
00655 
00663     public function getSqlActiveSnippet( $blForceCoreTable = false )
00664     {
00665         $myConfig = $this->getConfig();
00666 
00667         // check if article is still active
00668         $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00669 
00670         // stock and variants check
00671         $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00672 
00673 
00674         return "( $sQ ) ";
00675     }
00676 
00684     public function setSkipAssign($blSkipAssign)
00685     {
00686         $this->_blSkipAssign = $blSkipAssign;
00687     }
00688 
00696     public function disablePriceLoad( $oArticle )
00697     {
00698         $oArticle->_blLoadPrice = false;
00699     }
00700 
00706     public function getItemKey()
00707     {
00708         return $this->_sItemKey;
00709     }
00710 
00718     public function setItemKey($sItemKey)
00719     {
00720         $this->_sItemKey = $sItemKey;
00721     }
00722 
00730     public function setNoVariantLoading( $blLoadVariants )
00731     {
00732         $this->_blLoadVariants = !$blLoadVariants;
00733     }
00734 
00740     public function isBuyable()
00741     {
00742         if ($this->_blNotBuyableParent) {
00743             return false;
00744         }
00745 
00746         return !$this->_blNotBuyable;
00747     }
00748 
00754     public function getPersParams()
00755     {
00756         return $this->_aPersistParam;
00757     }
00758 
00764     public function isOnComparisonList()
00765     {
00766         return $this->_blIsOnComparisonList;
00767     }
00768 
00776     public function setOnComparisonList( $blOnList )
00777     {
00778         $this->_blIsOnComparisonList = $blOnList;
00779     }
00780 
00788     public function setLoadParentData($blLoadParentData)
00789     {
00790         $this->_blLoadParentData = $blLoadParentData;
00791     }
00792 
00800     public function setSkipAbPrice( $blSkipAbPrice = null )
00801     {
00802         $this->_blSkipAbPrice = $blSkipAbPrice;
00803     }
00804 
00810     public function getSearchableFields()
00811     {
00812         $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00813         $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00814 
00815         return $aFields;
00816     }
00817 
00818 
00826     public function isMultilingualField($sFieldName)
00827     {
00828         switch ($sFieldName) {
00829             case "oxlongdesc":
00830             case "oxtags":
00831                 return true;
00832         }
00833 
00834         return parent::isMultilingualField($sFieldName);
00835     }
00836 
00842     public function isVisible()
00843     {
00844 
00845         // admin preview mode
00846         $myConfig  = $this->getConfig();
00847         if ( ( $sPrevId = oxConfig::getParameter( 'preview' ) ) &&
00848              ( $sAdminSid = oxUtilsServer::getInstance()->getOxCookie( 'admin_sid' ) ) ) {
00849 
00850             $oDb = oxDb::getDb();
00851             $sPrevId   = $oDb->quote( $sPrevId );
00852             $sAdminSid = $oDb->quote( $sAdminSid );
00853             $sTable    = getViewName( 'oxuser' );
00854 
00855             return (bool) $oDb->getOne( "select 1 from $sTable where MD5( CONCAT( {$sAdminSid}, {$sTable}.oxid, {$sTable}.oxpassword, {$sTable}.oxrights ) ) = $sPrevId" );
00856         }
00857 
00858         // active ?
00859         $sNow = date('Y-m-d H:i:s');
00860         if ( !$this->oxarticles__oxactive->value &&
00861              (  $this->oxarticles__oxactivefrom->value > $sNow ||
00862                 $this->oxarticles__oxactiveto->value < $sNow
00863              )) {
00864             return false;
00865         }
00866 
00867         // stock flags
00868         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00869             $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00870             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00871                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00872             }
00873             if ( $iOnStock <= 0 ) {
00874                 return false;
00875             }
00876         }
00877 
00878         return true;
00879     }
00880 
00889     public function assign( $aRecord)
00890     {
00891         startProfile('articleAssign');
00892 
00893 
00894         // load object from database
00895         parent::assign( $aRecord);
00896 
00897         $this->oxarticles__oxnid = $this->oxarticles__oxid;
00898 
00899         // check for simple article.
00900         if ($this->_blSkipAssign) {
00901             return;
00902         }
00903 
00904         $this->_assignParentFieldValues();
00905         $this->_assignNotBuyableParent();
00906 
00907         $this->_assignAllPictureValues();
00908 
00909         $this->_assignStock();
00910         startProfile('articleAssignPrices');
00911         $this->_assignPrices();
00912         stopProfile('articleAssignPrices');
00913         $this->_assignPersistentParam();
00914         $this->_assignDynImageDir();
00915         $this->_assignComparisonListFlag();
00916         $this->_assignAttributes();
00917 
00918 
00919         //$this->_seoAssign();
00920 
00921         stopProfile('articleAssign');
00922     }
00923 
00934     public function load( $oxID)
00935     {
00936         // A. #1325 resetting to avoid problems when reloading (details etc)
00937         $this->_blNotBuyableParent = false;
00938 
00939         $blRet = parent::load( $oxID);
00940 
00941         // convert date's to international format
00942         $this->oxarticles__oxinsert    = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00943         $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00944 
00945         return $blRet;
00946     }
00947 
00955     public function addToRatingAverage( $iRating)
00956     {
00957         $dOldRating = $this->oxarticles__oxrating->value;
00958         $dOldCnt    = $this->oxarticles__oxratingcnt->value;
00959         $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00960         $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00961         $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00962         $dRatingCnt = (int) ($dOldCnt + 1);
00963         // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00964         oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00965     }
00966 
00972     public function getArticleRatingAverage()
00973     {
00974         return round( $this->oxarticles__oxrating->value, 1);
00975     }
00976 
00982     public function getReviews()
00983     {
00984         $myConfig  = $this->getConfig();
00985 
00986         $aIds = array($this->getId());
00987 
00988         if ( $this->oxarticles__oxparentid->value ) {
00989                 $aIds[] = $this->oxarticles__oxparentid->value;
00990         }
00991 
00992         // showing variant reviews ..
00993         if ( $myConfig->getConfigParam( 'blShowVariantReviews' ) ) {
00994             $aAdd = $this->_getVariantsIds();
00995             if (is_array($aAdd)) {
00996                 $aIds = array_merge($aIds, $aAdd);
00997             }
00998         }
00999 
01000         $oReview = oxNew('oxreview');
01001         $oRevs = $oReview->loadList('oxarticle', $aIds);
01002 
01003         //if no review found, return null
01004         if ( $oRevs->count() < 1 ) {
01005             return null;
01006         }
01007 
01008         return $oRevs;
01009     }
01010 
01016     public function getCrossSelling()
01017     {
01018         $oCrosslist = oxNew( "oxarticlelist");
01019         $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
01020         if ( $oCrosslist->count() ) {
01021             return $oCrosslist;
01022         }
01023     }
01024 
01030     public function getAccessoires()
01031     {
01032         $myConfig = $this->getConfig();
01033 
01034         // Performance
01035         if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01036             return;
01037         }
01038 
01039         $oAcclist = oxNew( "oxarticlelist");
01040         $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01041         $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01042 
01043         if ( $oAcclist->count()) {
01044             return $oAcclist;
01045         }
01046     }
01047 
01053     public function getSimilarProducts()
01054     {
01055         // Performance
01056         $myConfig = $this->getConfig();
01057         if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01058             return;
01059         }
01060 
01061         $sArticleTable = $this->_getObjectViewName('oxarticles');
01062 
01063         $sAttribs = '';
01064         $iCnt = 0;
01065         $this->_getAttribsString($sAttribs, $iCnt);
01066 
01067         if ( !$sAttribs) {
01068             return null;
01069         }
01070 
01071         $aList = $this->_getSimList($sAttribs, $iCnt);
01072 
01073         if ( count( $aList ) ) {
01074             uasort( $aList, 'cmpart');
01075 
01076             $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01077 
01078             $oSimilarlist = oxNew( 'oxarticlelist' );
01079             $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01080             $oSimilarlist->selectString( $sSearch);
01081 
01082             return $oSimilarlist;
01083         }
01084     }
01085 
01091     public function getCustomerAlsoBoughtThisProducts()
01092     {
01093         // Performance
01094         $myConfig = $this->getConfig();
01095         if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01096             return;
01097         }
01098 
01099         // selecting products that fits
01100         $sQ = $this->_generateSearchStrForCustomerBought();
01101 
01102         $oArticles = oxNew( 'oxarticlelist' );
01103         $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01104         $oArticles->selectString( $sQ );
01105         if ( $oArticles->count() ) {
01106             return $oArticles;
01107         }
01108     }
01109 
01116     public function loadAmountPriceInfo()
01117     {
01118         $myConfig = $this->getConfig();
01119         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01120             return array();
01121         }
01122 
01123         if ( $this->_oAmountPriceInfo === null ) {
01124             $this->_oAmountPriceInfo = array();
01125             if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01126                 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01127 
01128             }
01129         }
01130         return $this->_oAmountPriceInfo;
01131     }
01132 
01140     public function getSelectLists($sKeyPrefix = null)
01141     {
01142         //#1468C - more then one article in basket with different selectlist...
01143         //optionall function parameter $sKeyPrefix added, used only in basket.php
01144         $sKey = $this->getId();
01145         if ( isset( $sKeyPrefix ) ) {
01146             $sKey = $sKeyPrefix.'__'.$this->getId();
01147         }
01148 
01149         if ( !isset( self::$_aSelList[$sKey] ) ) {
01150             $oDb = oxDb::getDb();
01151             $sSLViewName = getViewName( 'oxselectlist' );
01152 
01153             $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01154                    where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01155 
01156             // all selectlists this article has
01157             $oLists = oxNew( 'oxlist' );
01158             $oLists->init( 'oxselectlist' );
01159             $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01160 
01161             //#1104S if this is variant ant it has no selectlists, trying with parent
01162             if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01163                 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01164             }
01165 
01166             $dVat = 0;
01167             if ( $this->getPrice() != null ) {
01168                 $dVat = $this->getPrice()->getVat();
01169             }
01170 
01171             $iCnt = 0;
01172             self::$_aSelList[$sKey] = array();
01173             foreach ( $oLists as $oSelectlist ) {
01174                 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01175                 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01176                 $iCnt++;
01177             }
01178         }
01179         return self::$_aSelList[$sKey];
01180     }
01181 
01189     protected function _hasAnyVariant( $blForceCoreTable = false )
01190     {
01191         $sArticleTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
01192         return (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='".$this->getId()."'" );
01193     }
01194 
01200     public function hasMdVariants()
01201     {
01202         return $this->_blHasMdVariants;
01203     }
01204 
01213     public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = false  )
01214     {
01215         if ( $blRemoveNotOrderables && $this->_aVariants ) {
01216             return $this->_aVariants;
01217         } elseif ( !$blRemoveNotOrderables && $this->_aVariantsWithNotOrderables ) {
01218             return $this->_aVariantsWithNotOrderables;
01219         }
01220 
01221         $myConfig = $this->getConfig();
01222         if ( !$this->_blLoadVariants ||
01223             ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01224             ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01225             return array();
01226         }
01227 
01228         //do not load me as a parent later
01229         self::$_aLoadedParents[$this->getId()] = $this;
01230 
01231         //load simple variants for lists
01232         if ( $this->_isInList() ) {
01233             $oVariants = oxNew( 'oxsimplevariantlist' );
01234             $oVariants->setParent( $this );
01235         } else {
01236             //loading variants
01237             $oVariants = oxNew( 'oxarticlelist' );
01238             $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01239         }
01240 
01241         if ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) {
01242 
01243             startProfile("selectVariants");
01244             $blUseCoreTable = $blForceCoreTable;
01245             $oBaseObject = $oVariants->getBaseObject();
01246             $sArticleTable = $this->getTableNameForActiveSnippet( $blUseCoreTable );
01247 
01248             $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01249                        $this->getActiveCheckQuery( $blUseCoreTable ) .
01250                        $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01251                        " order by $sArticleTable.oxsort";
01252 
01253             $oVariants->selectString( $sSelect );
01254 
01255             //if this is multidimensional variants, make additional processing
01256             if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01257                 $oMdVariants = oxNew( "oxVariantHandler" );
01258                 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01259             }
01260             stopProfile("selectVariants");
01261         }
01262 
01263         //if we have variants then depending on config option the parent may be non buyable
01264         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01265             $this->_blNotBuyableParent = true;
01266         }
01267 
01268         //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01269         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $oVariants->count() == 0 && $this->_blHasVariants ) {
01270             $this->_blNotBuyable = true;
01271         }
01272 
01273         // cache
01274         if ( $blRemoveNotOrderables ) {
01275             $this->_aVariants = $oVariants;
01276         } else {
01277             $this->_aVariantsWithNotOrderables = $oVariants;
01278         }
01279 
01280         return $oVariants;
01281     }
01282 
01288     public function getSimpleVariants()
01289     {
01290         if ( $this->oxarticles__oxvarcount->value) {
01291             return $this->getVariants();
01292         }
01293     }
01294 
01303     public function getAdminVariants( $sLanguage = null )
01304     {
01305         $myConfig = $this->getConfig();
01306 
01307         $oVariants = oxNew( 'oxarticlelist');
01308 
01309         if ( is_null($sLanguage) ) {
01310             $oVariants->getBaseObject()->setLanguage(oxLang::getInstance()->getBaseLanguage());
01311         } else {
01312             $oVariants->getBaseObject()->setLanguage($sLanguage);
01313         }
01314 
01315         $sSql = 'select * from oxarticles where oxparentid = "'.$this->getId().'" order by oxsort ';
01316 
01317         $oVariants->selectString( $sSql);
01318 
01319         //if we have variants then depending on config option the parent may be non buyable
01320         if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01321             //$this->blNotBuyable = true;
01322             $this->_blNotBuyableParent = true;
01323         }
01324 
01325         return $oVariants;
01326     }
01327 
01335     public function getCategory()
01336     {
01337         startPRofile( 'getCategory' );
01338 
01339         $oCategory = oxNew( 'oxcategory' );
01340         $oCategory->setLanguage( $this->getLanguage() );
01341 
01342         // variant handling
01343         $sOXID = $this->getId();
01344         if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01345             $sOXID = $this->oxarticles__oxparentid->value;
01346         }
01347 
01348         $oStr = getStr();
01349         $sWhere   = $oCategory->getSqlActiveSnippet();
01350         $sSelect  = $this->_generateSearchStr( $sOXID );
01351         $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01352 
01353         // category not found ?
01354         if ( !$oCategory->assignRecord( $sSelect ) ) {
01355 
01356             $sSelect  = $this->_generateSearchStr( $sOXID, true );
01357             $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01358 
01359             // looking for price category
01360             if ( !$oCategory->assignRecord( $sSelect ) ) {
01361                 $oCategory = null;
01362             }
01363         }
01364 
01365         stopPRofile( 'getCategory' );
01366         return $oCategory;
01367     }
01368 
01377     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01378     {
01379         $myConfig = $this->getConfig();
01380         if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01381             return self::$_aArticleCats[$this->getId()];
01382         }
01383 
01384         // variant handling
01385         $sOXID = $this->getId();
01386         if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01387             $sOXID = $this->oxarticles__oxparentid->value;
01388         }
01389 
01390         // we do not use lists here as we dont need this overhead right now
01391         $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01392         $oDB = oxDb::getDb(true);
01393         $rs = $oDB->execute( $sSql );
01394 
01395 
01396         $aRet = array();
01397 
01398         if ($rs != false && $rs->recordCount() > 0) {
01399             while (!$rs->EOF) {
01400                 $aRet[] = $rs->fields['oxcatnid'];
01401                 $rs->moveNext();
01402             }
01403         }
01404 
01405         // adding price categories if such exists
01406         $sSql = $this->getSqlForPriceCategories();
01407 
01408         $oDB = oxDb::getDb( true );
01409         $rs = $oDB->execute( $sSql );
01410 
01411         if ($rs != false && $rs->recordCount() > 0) {
01412             while (!$rs->EOF) {
01413 
01414                 if ( is_array( $rs->fields ) ) {
01415                    $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01416                 }
01417 
01418 
01419                 if ( !$aRet[$rs->fields['oxid']] ) {
01420                     $aRet[] = $rs->fields['oxid'];
01421                 }
01422                 $rs->moveNext();
01423             }
01424         }
01425 
01426         return self::$_aArticleCats[$this->getId()] = $aRet;
01427     }
01428 
01437     protected function _getSelectCatIds( $sOXID, $blActCats = false )
01438     {
01439         $sO2CView = $this->_getObjectViewName('oxobject2category');
01440         $sCatView = $this->_getObjectViewName('oxcategories');
01441         $sSelect =  "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01442         $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 ';
01443         if ( $blActCats ) {
01444             $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 ";
01445         }
01446         $sSelect .= 'order by oxobject2category.oxtime ';
01447         return $sSelect;
01448     }
01449 
01459     public function getVendor( $blShopCheck = true )
01460     {
01461         if ( ( $sVendorId = $this->getVendorId() ) ) {
01462             $oVendor = oxNew( 'oxvendor' );
01463         } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01464             $oVendor = oxNew( 'oxi18n' );
01465             $oVendor->init('oxvendor');
01466             $oVendor->setReadOnly( true );
01467             $sVendorId = $this->oxarticles__oxvendorid->value;
01468         }
01469         if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01470             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01471                 $oVendor->setReadOnly( true );
01472             }
01473             return $oVendor;
01474         }
01475         return null;
01476     }
01477 
01485     public function getVendorId( $blForceReload = false )
01486     {
01487         $sVendorId = false;
01488         if ( $this->oxarticles__oxvendorid->value ) {
01489             if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01490                 return self::$_aArticleVendors[$this->getId()];
01491             }
01492             $oDb = oxDb::getDb();
01493             $sVendorIdQuoted = $oDb->quote($this->oxarticles__oxvendorid->value);
01494             $sQ = "select oxid from ".getViewName('oxvendor')." where oxid=$sVendorIdQuoted";
01495             self::$_aArticleVendors[$this->getId()] = $sVendorId = $oDb->getOne( $sQ );
01496         }
01497         return $sVendorId;
01498     }
01499 
01507     public function getManufacturerId( $blForceReload = false )
01508     {
01509         $sManufacturerId = false;
01510         if ( $this->oxarticles__oxmanufacturerid->value ) {
01511             if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01512                 return self::$_aArticleManufacturers[$this->getId()];
01513             }
01514             $oDb = oxDb::getDb();
01515             $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid=".$oDb->quote($this->oxarticles__oxmanufacturerid->value);
01516             self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = $oDb->getOne( $sQ );
01517         }
01518         return $sManufacturerId;
01519     }
01520 
01530     public function getManufacturer( $blShopCheck = true )
01531     {
01532         $oManufacturer = oxNew( 'oxmanufacturer' );;
01533         if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01534              !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01535             $oManufacturer->setReadOnly( true );
01536             $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01537         }
01538 
01539         if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01540             if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01541                 $oManufacturer->setReadOnly( true );
01542             }
01543             $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01544         } else {
01545             $oManufacturer = null;
01546         }
01547 
01548         return $oManufacturer;
01549     }
01550 
01558     public function inCategory( $sCatNid)
01559     {
01560         return in_array( $sCatNid, $this->getCategoryIds());
01561     }
01562 
01571     public function isAssignedToCategory( $sCatId )
01572     {
01573         // variant handling
01574         $sOXID = $this->getId();
01575         if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01576             $sOXID = $this->oxarticles__oxparentid->value;
01577         }
01578 
01579         $oDB = oxDb::getDb();
01580         $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01581         $sOXID = $oDB->getOne( $sSelect);
01582         // article is assigned to passed category!
01583         if ( isset( $sOXID) && $sOXID) {
01584             return true;
01585         }
01586 
01587         // maybe this category is price category ?
01588         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01589             $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01590             if ( $dPriceFromTo > 0) {
01591                 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01592                 $sOXID = $oDB->getOne( $sSelect);
01593                 // article is assigned to passed category!
01594                 if ( isset( $sOXID) && $sOXID) {
01595                     return true;
01596                 }
01597             }
01598         }
01599         return false;
01600     }
01601 
01607     public function getTPrice()
01608     {
01609         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01610             return;
01611         }
01612         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01613         if ( $this->_oTPrice !== null ) {
01614             return $this->_oTPrice;
01615         }
01616 
01617         $this->_oTPrice = oxNew( 'oxPrice' );
01618         $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01619 
01620         $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01621         $this->_applyCurrency( $this->_oTPrice );
01622 
01623         return $this->_oTPrice;
01624     }
01625 
01631     public function skipDiscounts()
01632     {
01633         // allready loaded skip discounts config
01634         if ( $this->_blSkipDiscounts !== null )
01635             return $this->_blSkipDiscounts;
01636 
01637         if ( $this->oxarticles__oxskipdiscounts->value )
01638             return true;
01639 
01640         $sO2CView = getViewName('oxobject2category');
01641         $sSelect =  "select 1 from $sO2CView as oxobject2category left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01642         $sSelect .= 'where oxobject2category.oxobjectid="'.$this->getId().'" and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 and oxcategories.oxskipdiscounts = "1" ';
01643 
01644         return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01645     }
01646 
01654     public function setPrice(oxPrice $oPrice)
01655     {
01656         $this->_oPrice = $oPrice;
01657     }
01658 
01667     public function getBasePrice( $dAmount = 1 )
01668     {
01669         // override this function if you want e.g. different prices
01670         // for diff. usergroups.
01671 
01672         // Performance
01673         $myConfig = $this->getConfig();
01674         if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01675             return;
01676 
01677         // GroupPrice or DB price ajusted by AmountPrice
01678         $dPrice = $this->_getAmountPrice( $dAmount );
01679 
01680 
01681         return $dPrice;
01682     }
01683 
01691     public function getPrice( $dAmount = 1 )
01692     {
01693         $myConfig = $this->getConfig();
01694         // Performance
01695         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01696             return;
01697         }
01698 
01699         // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01700         if ( $dAmount != 1 || $this->_oPrice === null ) {
01701             $oPrice = oxNew( 'oxPrice' );
01702 
01703             // get base
01704             $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01705 
01706             // price handling
01707             if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01708                 return $this->_oPrice = $oPrice;
01709             }
01710 
01711             $this->_calculatePrice( $oPrice );
01712             if ( $dAmount != 1 ) {
01713                 return $oPrice;
01714             }
01715 
01716             $this->_oPrice = $oPrice;
01717         }
01718         return $this->_oPrice;
01719     }
01720 
01728     protected function _calculatePrice( $oPrice )
01729     {
01730         // apply VAT only if configuration requires it
01731         if ( !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01732             $this->_applyVAT( $oPrice, $this->getArticleVat() );
01733         }
01734 
01735         // apply currency
01736         $this->_applyCurrency( $oPrice );
01737         // apply discounts
01738         if ( !$this->skipDiscounts() ) {
01739             $oDiscountList = oxDiscountList::getInstance();
01740             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts($this, $this->getArticleUser() ) );
01741         }
01742 
01743         return $oPrice;
01744     }
01745 
01753     public function setArticleUser($oUser)
01754     {
01755         $this->_oUser = $oUser;
01756     }
01757 
01763     public function getArticleUser()
01764     {
01765         if ($this->_oUser) {
01766             return $this->_oUser;
01767         }
01768         return $this->getUser();
01769     }
01770 
01780     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01781     {
01782         $oUser = $oBasket->getBasketUser();
01783         $this->setArticleUser($oUser);
01784 
01785         $oBasketPrice = oxNew( 'oxPrice' );
01786 
01787         // get base price
01788         $dBasePrice = $this->getBasePrice( $dAmount );
01789 
01790         // applying select list price
01791         $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01792 
01793         // setting price
01794         $oBasketPrice->setPrice( $dBasePrice );
01795 
01796         // apply VAT
01797         $this->_applyVat( $oBasketPrice, oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket ) );
01798 
01799         // apply currency
01800         $this->_applyCurrency( $oBasketPrice );
01801 
01802         // apply discounts
01803         if ( !$this->skipDiscounts() ) {
01804             // apply general discounts
01805             $oDiscountList = oxDiscountList::getInstance();
01806             $oDiscountList->applyDiscounts( $oBasketPrice, $oDiscountList->getArticleDiscounts( $this, $oUser ) );
01807         }
01808 
01809         // returning final price object
01810         return $oBasketPrice;
01811     }
01812 
01825     public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01826     {
01827         $oDiscountList = oxDiscountList::getInstance();
01828         return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01829     }
01830 
01839     public function delete( $sOXID = null )
01840     {
01841         if ( !$sOXID ) {
01842             $sOXID = $this->getId();
01843         }
01844         if ( !$sOXID ) {
01845             return false;
01846         }
01847 
01848 
01849         $this->load( $sOXID );
01850         $this->_deletePics();
01851         $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01852         $this->_deleteVariantRecords( $sOXID );
01853         $rs = $this->_deleteRecords( $sOXID );
01854 
01855         oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01856 
01857         $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01858 
01859         return $rs->EOF;
01860     }
01861 
01870     public function reduceStock($dAmount, $blAllowNegativeStock = false)
01871     {
01872         $this->beforeUpdate();
01873 
01874         $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01875         if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01876             $dAmount += $iStockCount;
01877             $iStockCount = 0;
01878         }
01879         $this->oxarticles__oxstock = new oxField($iStockCount);
01880 
01881         $oDb = oxDb::getDb();
01882         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01883         $this->onChange( ACTION_UPDATE_STOCK );
01884         return $dAmount;
01885     }
01886 
01895     public function updateSoldAmount( $dAmount = 0 )
01896     {
01897         if ( !$dAmount ) {
01898             return;
01899         }
01900 
01901         $this->beforeUpdate();
01902 
01903         // article is not variant - should be updated current amount
01904         if ( !$this->oxarticles__oxparentid->value ) {
01905             //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01906             $dAmount = (double) $dAmount;
01907             $oDb = oxDb::getDb();
01908             $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01909         } elseif ( $this->oxarticles__oxparentid->value) {
01910             // article is variant - should be updated this article parent amount
01911             $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01912             $oUpdateArticle->updateSoldAmount( $dAmount );
01913         }
01914 
01915         $this->onChange( ACTION_UPDATE );
01916 
01917         return $rs;
01918     }
01919 
01925     public function disableReminder()
01926     {
01927         $oDB = oxDb::getDb(true);
01928         return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01929     }
01930 
01937     public function save()
01938     {
01939         $myConfig = $this->getConfig();
01940 
01941         $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01942         $this->oxarticles__oxicon  = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01943         $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01944         for ($i=1; $i <= $iPicCount; $i++) {
01945             if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01946                 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01947             }
01948         }
01949 
01950         $blRet = parent::save();
01951 
01952         // save article long description
01953         $this->setArticleLongDesc();
01954 
01955         // load article images after save
01956         $this->_assignAllPictureValues();
01957 
01958         return $blRet;
01959     }
01960 
01961 
01968     public function getPictureGallery()
01969     {
01970         $myConfig = $this->getConfig();
01971 
01972         //initialize
01973         $blMorePic = false;
01974         $aArtPics  = array();
01975         $aArtIcons = array();
01976         $iActPicId = 1;
01977         $sActPic = $this->getPictureUrl( $iActPicId );
01978 
01979         if ( oxConfig::getParameter( 'actpicid' ) ) {
01980             $iActPicId = oxConfig::getParameter('actpicid');
01981         }
01982 
01983         $oStr = getStr();
01984         $iCntr = 0;
01985         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01986         $blCheckActivePicId = true;
01987 
01988         for ( $i = 1; $i <= $iPicCount; $i++) {
01989             $sPicVal = $this->getPictureUrl( $i );
01990             $sIcoVal = $this->getIconUrl( $i );
01991             if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') ) {
01992                 if ($iCntr) {
01993                     $blMorePic = true;
01994                 }
01995                 $aArtIcons[$i]= $sIcoVal;
01996                 $aArtPics[$i]= $sPicVal;
01997                 $iCntr++;
01998 
01999                 if ($iActPicId == $i) {
02000                     $sActPic = $sPicVal;
02001                     $blCheckActivePicId = false;
02002                 }
02003 
02004             } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02005                 // if picture is empty, setting active pic id to next
02006                 // picture
02007                 $iActPicId++;
02008             }
02009         }
02010 
02011         $blZoomPic  = false;
02012         $aZoomPics = array();
02013         $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02014 
02015         for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02016             $sVal = $this->getZoomPictureUrl($j);
02017 
02018             if ( !$oStr->strstr($sVal, 'nopic.jpg')) {
02019                 if ($this->getConfig()->getConfigParam('blFormerTplSupport')) {
02020                     $sVal = $this->_sDynImageDir."/".$sVal;
02021                 }
02022                 $blZoomPic = true;
02023                 $aZoomPics[$c]['id'] = $c;
02024                 $aZoomPics[$c]['file'] = $sVal;
02025                 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02026                 if (!$sVal) {
02027                     $aZoomPics[$c]['file'] = "nopic.jpg";
02028                 }
02029                 $c++;
02030             }
02031         }
02032 
02033         $aPicGallery = array('ActPicID' => $iActPicId,
02034                              'ActPic' => $sActPic,
02035                              'MorePics' => $blMorePic,
02036                              'Pics' => $aArtPics,
02037                              'Icons' => $aArtIcons,
02038                              'ZoomPic' => $blZoomPic,
02039                              'ZoomPics' => $aZoomPics);
02040 
02041         return $aPicGallery;
02042     }
02043 
02057     public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02058     {
02059         $myConfig = $this->getConfig();
02060 
02061         if (!isset($sOXID)) {
02062             if ( $this->getId()) {
02063                 $sOXID = $this->getId();
02064             }
02065             if (!isset ($sOXID)) {
02066                 $sOXID = $this->oxarticles__oxid->value;
02067             }
02068             if ($this->oxarticles__oxparentid->value) {
02069                 $sParentID = $this->oxarticles__oxparentid->value;
02070             }
02071         }
02072         if (!isset($sOXID)) {
02073             return;
02074         }
02075 
02076         //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02077         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02078             //if article has variants then updating oxvarstock field
02079             //getting parent id
02080             if (!isset($sParentID)) {
02081                 $oDb = oxDb::getDb();
02082                 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02083                 $sParentID = $oDb->getOne($sQ);
02084             }
02085             //if we have parent id then update stock
02086             if ($sParentID) {
02087                 $this->_onChangeUpdateStock($sParentID);
02088             }
02089         }
02090         //if we have parent id then update count
02091         //update count even if blUseStock is not active
02092         if ($sParentID) {
02093             $this->_onChangeUpdateVarCount($sParentID);
02094         }
02095 
02096         $sId = ( $sParentID ) ? $sParentID : $sOXID;
02097         $this->_onChangeUpdateMinVarPrice( $sId );
02098 
02099             // reseting articles count cache if stock has changed and some
02100             // articles goes offline (M:1448)
02101             if ( $sAction === ACTION_UPDATE_STOCK ) {
02102                 $this->_onChangeStockResetCount( $sOXID );
02103             }
02104 
02105     }
02106 
02113     public function getCustomVAT()
02114     {
02115         if ( isset($this->oxarticles__oxvat->value) ) {
02116             return $this->oxarticles__oxvat->value;
02117         }
02118     }
02119 
02128     public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02129     {
02130         $myConfig = $this->getConfig();
02131         if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02132             return true;
02133         }
02134 
02135         // fetching DB info as its up-to-date
02136         $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02137         $rs = oxDb::getDb(true)->Execute( $sQ );
02138 
02139         $iOnStock   = 0;
02140         $iStockFlag = 0;
02141         if ( $rs !== false && $rs->recordCount() > 0 ) {
02142             $iOnStock   = $rs->fields['oxstock'] - $dArtStockAmount;
02143             $iStockFlag = $rs->fields['oxstockflag'];
02144 
02145             // dodger : fremdlager is also always considered as on stock
02146             if ( $iStockFlag == 1 || $iStockFlag == 4) {
02147                 return true;
02148             }
02149             if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02150                 $iOnStock = floor( $iOnStock );
02151             }
02152         }
02153         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02154             $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02155         }
02156         if ( $iOnStock >= $dAmount ) {
02157             return true;
02158         } else {
02159             if ( $iOnStock > 0 ) {
02160                 return $iOnStock;
02161             } else {
02162                 $oEx = oxNew( 'oxArticleInputException' );
02163                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02164                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02165                 return false;
02166             }
02167         }
02168     }
02169 
02170 
02178     public function getArticleLongDesc($sOXID = null)
02179     {
02180 
02181         if ( !$sOXID ) {
02182             $sOXID = $this->oxarticles__oxid->value;
02183         }
02184 
02185         if ($sOXID == $this->oxarticles__oxid->value) {
02186             if (isset($this->oxarticles__oxlongdesc) && ($this->oxarticles__oxlongdesc instanceof oxField) && $this->oxarticles__oxlongdesc->value) {
02187                 return $this->oxarticles__oxlongdesc;
02188             }
02189         }
02190 
02191         $myConfig = $this->getConfig();
02192 
02193         if ( $sOXID ) {
02194             $sLangField = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02195             $oDb = oxDb::getDb();
02196             $this->_setLongDesc($oDb->getOne( "select oxlongdesc{$sLangField} from oxartextends where oxid = ".$oDb->quote($sOXID) ));
02197         } else {
02198             // TODO: check if keeping fldname is needed in non-admin mode
02199             $this->oxarticles__oxlongdesc = new oxField();
02200             $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02201             $this->oxarticles__oxlongdesc->table   = 'oxarticles';
02202             $this->oxarticles__oxlongdesc->fldtype = 'text';
02203         }
02204 
02205         return $this->oxarticles__oxlongdesc;
02206     }
02207 
02215     protected function _setLongDesc($sDbValue)
02216     {
02217         // TODO: the code below is redundant, optimize it, assignments should go smooth without conversions
02218         // hack, if editor screws up text, htmledit tends to do so
02219         $sDbValue = str_replace( '&amp;nbsp;', '&nbsp;', $sDbValue );
02220         $sDbValue = str_replace( '&amp;', '&', $sDbValue );
02221         $sDbValue = str_replace( '&quot;', '"', $sDbValue );
02222         $sDbValue = str_replace( '&lang=', '&amp;lang=', $sDbValue);
02223         //
02224 
02225         $oStr = getStr();
02226         $blHasSmarty = $oStr->strstr( $sDbValue, '[{' );
02227         $blHasPhp = $oStr->strstr( $sDbValue, '<?' );
02228         $myConfig = oxConfig::getInstance();
02229         if ( ( $blHasSmarty || $blHasPhp ) && ($myConfig->getConfigParam( 'blExport' ) || !$this->isAdmin() ) && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
02230             $sDbValue = oxUtilsView::getInstance()->parseThroughSmarty( $sDbValue, $this->getId() );
02231         }
02232         $this->oxarticles__oxlongdesc = new oxField($sDbValue, oxField::T_RAW);
02233         // TODO: check if keeping fldname is needed in non-admin mode
02234         $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02235         $this->oxarticles__oxlongdesc->table   = 'oxarticles';
02236         $this->oxarticles__oxlongdesc->fldtype = 'text';
02237     }
02238 
02244     public function setArticleLongDesc()
02245     {
02246 
02247         if ( $this->_blEmployMultilanguage ) {
02248             // update or insert article long description
02249             if ($this->oxarticles__oxlongdesc instanceof oxField) {
02250                 $sLongDesc = $this->oxarticles__oxlongdesc->getRawValue();
02251             } else {
02252                 $sLongDesc = $this->oxarticles__oxlongdesc->value;
02253             }
02254             $this->_saveArtLongDesc($this->getLanguage(), $sLongDesc);
02255         } else {
02256             $oArtExt = oxNew('oxi18n');
02257             $oArtExt->init('oxartextends');
02258             $aObjFields = $oArtExt->_getAllFields(true);
02259             foreach ($aObjFields as $sKey => $sValue ) {
02260                 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02261                     $sField = $this->_getFieldLongName($sKey);
02262                     if (isset($this->$sField)) {
02263                         $iLang = $oArtExt->_getFieldLang($sKey);
02264                         $sLongDesc = null;
02265                         if ($this->$sField instanceof oxField) {
02266                             $sLongDesc = $this->$sField->getRawValue();
02267                         } elseif (is_object($this->$sField)) {
02268                             $sLongDesc = $this->$sField->value;
02269                         }
02270                         if (isset($sLongDesc)) {
02271                             $this->_saveArtLongDesc($iLang, $sLongDesc);
02272                         }
02273                     }
02274                 }
02275             }
02276         }
02277     }
02278 
02284     public function getAttributes()
02285     {
02286         if ( $this->_oAttributeList === null ) {
02287             $this->_oAttributeList = oxNew( 'oxattributelist' );
02288             $this->_oAttributeList->loadAttributes( $this->getId() );
02289         }
02290 
02291         return $this->_oAttributeList;
02292     }
02293 
02302     public function appendLink( $sAddParams, $iLang = null )
02303     {
02304         if ( $sAddParams ) {
02305             if ( $iLang === null ) {
02306                 $iLang = $this->getLanguage();
02307             }
02308 
02309             $this->_aSeoAddParams[$iLang]  = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&amp;" : "";
02310             $this->_aSeoAddParams[$iLang] .= $sAddParams;
02311         }
02312     }
02313 
02322     public function getBaseSeoLink( $iLang, $blMain = false )
02323     {
02324         $oEncoder = oxSeoEncoderArticle::getInstance();
02325         if ( !$blMain ) {
02326             return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02327         }
02328         return $oEncoder->getArticleMainUrl( $this, $iLang );
02329     }
02330 
02339     public function getLink( $iLang = null, $blMain = false  )
02340     {
02341         if ( !oxUtils::getInstance()->seoIsActive() ) {
02342             return $this->getStdLink( $iLang );
02343         }
02344 
02345         if ( $iLang === null ) {
02346             $iLang = $this->getLanguage();
02347         }
02348 
02349         $iLinkType = $this->getLinkType();
02350         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02351             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02352         }
02353 
02354         $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02355         if ( isset($this->_aSeoAddParams[$iLang])) {
02356             $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&amp;' ).$this->_aSeoAddParams[$iLang];
02357         }
02358 
02359         return $sUrl;
02360     }
02361 
02370     public function getMainLink( $iLang = null )
02371     {
02372         return $this->getLink( $iLang, true );
02373     }
02374 
02382     public function setLinkType( $iType )
02383     {
02384         // resetting detaisl link, to force new
02385         $this->_sDetailLink = null;
02386 
02387         // setting link type
02388         $this->_iLinkType = (int) $iType;
02389     }
02390 
02396     public function getLinkType()
02397     {
02398         return $this->_iLinkType;
02399     }
02400 
02409     public function appendStdLink( $sAddParams, $iLang = null )
02410     {
02411         if ( $sAddParams ) {
02412             if ( $iLang === null ) {
02413                 $iLang = $this->getLanguage();
02414             }
02415 
02416             $this->_aStdAddParams[$iLang]  = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&amp;" : "";
02417             $this->_aStdAddParams[$iLang] .= $sAddParams;
02418         }
02419     }
02420 
02430     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02431     {
02432         $sUrl = '';
02433         if ( $blFull ) {
02434             //always returns shop url, not admin
02435             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02436         }
02437 
02438         $sUrl .= "index.php?cl=details" . ( $blAddId ? "&amp;anid=".$this->getId() : "" );
02439         return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&amp;". $this->_aStdAddParams[$iLang] : "" );
02440     }
02441 
02450     public function getStdLink( $iLang = null, $aParams = array() )
02451     {
02452         if ( $iLang === null ) {
02453             $iLang = $this->getLanguage();
02454         }
02455 
02456         if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02457             $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02458         }
02459 
02460         return oxUtilsUrl::getInstance()->processStdUrl( $this->_aStdUrls[$iLang], $aParams, $iLang, $iLang != $this->getLanguage() );
02461     }
02462 
02470     public function getStdTagLink( $sTag )
02471     {
02472         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02473         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
02474     }
02475 
02481     public function getTags()
02482     {
02483         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02484         $sQ = "select $sTagField from oxartextends where oxid = '".$this->getId()."'";
02485         $sTags = oxDb::getDb(true)->getOne($sQ);
02486         $oTagCloud = oxNew('oxtagcloud');
02487         $sTags = $oTagCloud->trimTags($sTags);
02488         return $sTags;
02489     }
02490 
02498     public function saveTags($sTags)
02499     {
02500         //do not allow derived update
02501         if ( !$this->allowDerivedUpdate() ) {
02502             return false;
02503         }
02504 
02505 
02506         $oTagCloud = oxNew('oxtagcloud');
02507         $oTagCloud->resetTagCache();
02508         $sTags = $oTagCloud->prepareTags($sTags);
02509         $sTags = mysql_real_escape_string($sTags);
02510 
02511         $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02512         $sQ = "update oxartextends set $sTagField = '$sTags'  where oxid = '".$this->getId()."'";
02513         return oxDb::getDb()->execute($sQ);
02514     }
02515 
02523     public function addTag($sTag)
02524     {
02525         $oDb = oxDb::getDb();
02526         $sTag = mysql_real_escape_string($sTag);
02527 
02528         $oTagCloud = oxNew('oxtagcloud');
02529         $oTagCloud->resetTagCache();
02530         $sTag = $oTagCloud->prepareTags($sTag);
02531         $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02532 
02533         $sField = "oxartextends.OXTAGS" . oxLang::getInstance()->getLanguageTag();
02534 
02535         if ( $oDb->getOne( "select $sField from oxartextends where oxartextends.OXID = '{$this->getId()}'" ) ) {
02536             $sTailTag = $sTagSeparator . $sTag;
02537         } else {
02538             $sTailTag = $sTag;
02539         }
02540 
02541         $sQ = "insert into oxartextends (oxartextends.OXID, $sField) values ('".$this->getId()."', '{$sTag}')
02542                        ON DUPLICATE KEY update $sField = CONCAT(TRIM($sField), '$sTailTag') ";
02543 
02544         return $oDb->Execute($sQ);
02545     }
02546 
02552     public function getMediaUrls()
02553     {
02554         if ( $this->_aMediaUrls === null ) {
02555             $this->_aMediaUrls = oxNew("oxlist");
02556             $this->_aMediaUrls->init("oxmediaurl");
02557             $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02558 
02559             $sQ = "select * from oxmediaurls where oxobjectid = '".$this->getId()."'";
02560             $this->_aMediaUrls->selectString($sQ);
02561         }
02562         return $this->_aMediaUrls;
02563     }
02564 
02570     public function getDynImageDir()
02571     {
02572         return $this->_sDynImageDir;
02573     }
02574 
02580     public function getDispSelList()
02581     {
02582         if ($this->_aDispSelList === null) {
02583             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02584                 $this->_aDispSelList = $this->getSelectLists();
02585             }
02586         }
02587         return $this->_aDispSelList;
02588     }
02589 
02595     public function getMoreDetailLink()
02596     {
02597         if ( $this->_sMoreDetailLink == null ) {
02598 
02599             // and assign special article values
02600             $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02601 
02602             // not always it is okey, as not all the time active category is the same as primary article cat.
02603             if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02604                 $this->_sMoreDetailLink .= '&amp;cnid='.$sActCat;
02605             }
02606             $this->_sMoreDetailLink .= '&amp;anid='.$this->getId();
02607             $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02608         }
02609 
02610         return $this->_sMoreDetailLink;
02611     }
02612 
02618     public function getToBasketLink()
02619     {
02620         if ( $this->_sToBasketLink == null ) {
02621             $myConfig = $this->getConfig();
02622 
02623             if ( oxUtils::getInstance()->isSearchEngine() ) {
02624                 $this->_sToBasketLink = $this->getLink();
02625             } else {
02626                 // and assign special article values
02627                 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02628 
02629                 // override some classes as these should never showup
02630                 $sActClass = oxConfig::getParameter( 'cl' );
02631                 if ( $sActClass == 'thankyou') {
02632                     $sActClass = 'basket';
02633                 }
02634                 $this->_sToBasketLink .= 'cl='.$sActClass;
02635 
02636                 // this is not very correct
02637                 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02638                     $this->_sToBasketLink .= '&amp;cnid='.$sActCat;
02639                 }
02640 
02641                 $this->_sToBasketLink .= '&amp;fnc=tobasket&amp;aid='.$this->getId().'&amp;anid='.$this->getId();
02642 
02643                 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02644                     $this->_sToBasketLink .= '&amp;tpl='.$sTpl;
02645                 }
02646             }
02647         }
02648 
02649         return $this->_sToBasketLink;
02650     }
02651 
02657     public function getStockStatus()
02658     {
02659         return $this->_iStockStatus;
02660     }
02661 
02667     public function getDeliveryDate()
02668     {
02669         if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02670             return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02671         }
02672         return false;
02673     }
02674 
02680     public function getFTPrice()
02681     {
02682         if ( $oPrice = $this->getTPrice() ) {
02683             if ( $oPrice->getBruttoPrice() ) {
02684                 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02685             }
02686         }
02687     }
02688 
02694     public function getFPrice()
02695     {
02696         if ( $oPrice = $this->getPrice() ) {
02697             return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02698         }
02699     }
02700 
02706     public function getPricePerUnit()
02707     {
02708         return $this->_fPricePerUnit;
02709     }
02710 
02716     public function isParentNotBuyable()
02717     {
02718         return $this->_blNotBuyableParent;
02719     }
02720 
02726     public function isNotBuyable()
02727     {
02728         return $this->_blNotBuyable;
02729     }
02730 
02738     public function setBuyableState( $blBuyable = false )
02739     {
02740         $this->_blNotBuyable = !$blBuyable;
02741     }
02742 
02751     public function getVariantList()
02752     {
02753         return $this->getVariants();
02754     }
02755 
02763     public function setSelectlist( $aSelList )
02764     {
02765         $this->_aDispSelList = $aSelList;
02766     }
02767 
02775     public function getPictureUrl( $iIndex = '' )
02776     {
02777         if ( $iIndex ) {
02778 
02779             if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02780                 $this->_generateImages( $iIndex );
02781             }
02782 
02783             $sPic = $iIndex . "/" . $this->_getPictureName( $iIndex );
02784 
02785             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02786         }
02787     }
02788 
02796     protected function _getPictureName( $iIndex = '' )
02797     {
02798         if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02799             $sPicName = basename($this->{"oxarticles__oxpic".$iIndex}->value);
02800         } else {
02801             $sPicName = "nopic.jpg";
02802         }
02803 
02804         return $sPicName;
02805     }
02806 
02815     public function getIconUrl( $iIndex = '')
02816     {
02817         if ( $this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02818 
02819             $iIconIndex = ( $iIndex ) ? $iIndex : 1;
02820             //generating new images if needed
02821             if ( !$this->_hasGeneratedImage( $iIconIndex ) ) {
02822                 $this->_generateImages( $iIconIndex );
02823             }
02824         }
02825 
02826         $sIconName = $this->_getIconName( $iIndex );
02827 
02828         if ( !$iIndex ) {
02829             $sPic = "icon/" . basename( $sIconName );
02830         } else {
02831             $sPic = $iIndex . "/" . basename( $sIconName );
02832         }
02833 
02834         return $this->getConfig()->getIconUrl( $sPic, $this->isAdmin() );
02835     }
02836 
02845     protected function _getIconName( $iIndex = '' )
02846     {
02847         $oPictureHandler = oxPictureHandler::getInstance();
02848         $sIconName = "nopic_ico.jpg";
02849 
02850         if ( !$iIndex ) {
02851             if ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02852                 $sIconName = basename( $this->oxarticles__oxicon->value );
02853             } elseif ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 )  && $this->oxarticles__oxpic1->value ) {
02854                 $sIconName = $oPictureHandler->getMainIconName( $this->oxarticles__oxpic1->value );
02855             }
02856         } else {
02857             if ( $this->_hasGeneratedImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02858                 $sIconName = $oPictureHandler->getIconName( $this->{"oxarticles__oxpic".$iIndex}->value );
02859             }
02860         }
02861 
02862         return $sIconName;
02863     }
02864 
02870     public function getThumbnailUrl()
02871     {
02872         if ( $this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02873             //generating new images if needed
02874             if ( !$this->_hasGeneratedImage( 1 ) ) {
02875                 $this->_generateImages( 1 );
02876             }
02877         }
02878 
02879         $sPic = "0/" . $this->_getThumbnailName();
02880 
02881         return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02882     }
02883 
02889     protected function _getThumbnailName()
02890     {
02891         if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02892             $sThumbName = basename($this->oxarticles__oxthumb->value);
02893         } else {
02894             if ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 ) && $this->oxarticles__oxpic1->value ) {
02895                 $oPictureHandler = oxPictureHandler::getInstance();
02896                 $sThumbName = $oPictureHandler->getThumbName( $this->oxarticles__oxpic1->value );
02897             } else {
02898                 $sThumbName = "nopic.jpg";
02899             }
02900         }
02901 
02902         return $sThumbName;
02903     }
02904 
02912     public function getZoomPictureUrl( $iIndex = '' )
02913     {
02914         $iIndex = (int) $iIndex;
02915         if ( $iIndex > 0) {
02916             //generating new images if needed
02917             if ( $this->_isFieldEmpty( "oxarticles__oxzoom" . $iIndex ) ) {
02918                 //generating new images if needed
02919                 if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02920                     $this->_generateImages( $iIndex );
02921                 }
02922             }
02923 
02924             $sPic = "z{$iIndex}/" . $this->_getZoomPictureName( $iIndex );
02925 
02926             return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02927         }
02928     }
02929 
02937     protected function _getZoomPictureName( $iIndex = '' )
02938     {
02939         $sZoomField = "oxarticles__oxzoom" . $iIndex;
02940 
02941         if ( !$this->_isFieldEmpty( $sZoomField ) ) {
02942             $sZoomName = basename( $this->$sZoomField->value );
02943         } else {
02944             if ( $this->_hasGeneratedImage( $iIndex ) && $this->_hasMasterImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02945                 $oPictureHandler = oxPictureHandler::getInstance();
02946                 $sZoomName = $oPictureHandler->getZoomName( $this->{"oxarticles__oxpic".$iIndex}->value, $iIndex );
02947             } else {
02948                 $sZoomName = "nopic.jpg";
02949             }
02950         }
02951 
02952         return $sZoomName;
02953     }
02954 
02960     public function getFileUrl()
02961     {
02962         return $this->getConfig()->getPictureUrl( '0/' );
02963     }
02964 
02970     public function getPriceFromPrefix()
02971     {
02972         $sPricePrefics = '';
02973         if ( $this->_blIsRangePrice) {
02974             $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02975         }
02976 
02977         return $sPricePrefics;
02978     }
02979 
02988     protected function _saveArtLongDesc($iLang, $sValue)
02989     {
02990         $oDB = oxDb::getDb();
02991         $iLang = (int) $iLang;
02992         $sLangField = ($iLang > '0') ? '_'.$iLang : '';
02993         $sLongDesc = $oDB->quote($sValue);
02994         $sLongDescSQL = "insert into oxartextends (oxartextends.OXID, oxartextends.OXLONGDESC{$sLangField})
02995                        VALUES ('".$this->getId()."', {$sLongDesc})
02996                        ON DUPLICATE KEY update oxartextends.OXLONGDESC{$sLangField} = {$sLongDesc} ";
02997 
02998         $oDB->execute($sLongDescSQL);
02999     }
03000 
03006     protected function _skipSaveFields()
03007     {
03008         $myConfig = $this->getConfig();
03009 
03010         $this->_aSkipSaveFields = array();
03011 
03012         $this->_aSkipSaveFields[] = 'oxtimestamp';
03013         $this->_aSkipSaveFields[] = 'oxlongdesc';
03014         $this->_aSkipSaveFields[] = 'oxinsert';
03015 
03016         if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
03017             $this->_aSkipSaveFields[] = 'oxparentid';
03018         }
03019 
03020     }
03021 
03031     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03032     {
03033         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03034             // add prices of the same discounts
03035             if ( array_key_exists ($sKey, $aDiscounts) ) {
03036                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03037             } else {
03038                 $aDiscounts[$sKey] = $oDiscount;
03039             }
03040         }
03041         return $aDiscounts;
03042     }
03043 
03049     protected function _getGroupPrice()
03050     {
03051         $dPrice = $this->oxarticles__oxprice->value;
03052 
03053         $oUser = $this->getArticleUser();
03054         if ( $oUser ) {
03055             if ( $oUser->inGroup( 'oxidpricea' ) ) {
03056                 $dPrice = $this->oxarticles__oxpricea->value;
03057             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03058                 $dPrice = $this->oxarticles__oxpriceb->value;
03059             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03060                 $dPrice = $this->oxarticles__oxpricec->value;
03061             }
03062         }
03063 
03064         // #1437/1436C - added config option, and check for zero A,B,C price values
03065         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03066             $dPrice = $this->oxarticles__oxprice->value;
03067         }
03068 
03069         return $dPrice;
03070     }
03071 
03080     protected function _getAmountPrice($dAmount = 1)
03081     {
03082         $myConfig = $this->getConfig();
03083 
03084         startProfile( "_getAmountPrice" );
03085 
03086         $dPrice = $this->_getGroupPrice();
03087         $oAmtPrices = $this->_getAmountPriceList();
03088         foreach ($oAmtPrices as $oAmPrice) {
03089             if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03090                     && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03091                     && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03092                 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03093             }
03094         }
03095 
03096         stopProfile( "_getAmountPrice" );
03097         return $dPrice;
03098     }
03099 
03108     protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03109     {
03110         $myConfig = $this->getConfig();
03111         // #690
03112         if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03113 
03114             $aSelLists = $this->getSelectLists();
03115             foreach ( $aSelLists as $key => $aSel) {
03116                 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03117                     $oSel = $aSel[$aChosenList[$key]];
03118                     if ( $oSel->priceUnit =='abs' ) {
03119                         $dPrice += $oSel->price;
03120                     } elseif ( $oSel->priceUnit =='%' ) {
03121                         $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03122                     }
03123                 }
03124             }
03125         }
03126         return $dPrice;
03127     }
03128 
03129 
03137     protected function _fillAmountPriceList($oAmPriceList)
03138     {
03139         $myConfig = $this->getConfig();
03140         $myUtils  = oxUtils::getInstance();
03141 
03142         //modifying price
03143         $oCur = $myConfig->getActShopCurrencyObject();
03144 
03145         $oUser = $this->getArticleUser();
03146 
03147         $oDiscountList = oxDiscountList::getInstance();
03148         $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03149 
03150         $oLowestPrice = null;
03151 
03152         $dBasePrice = $this->_getGroupPrice();
03153         $oLang = oxLang::getInstance();
03154 
03155         $dArticleVat = null;
03156         if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03157             $dArticleVat = $this->getArticleVat();
03158         }
03159 
03160         // trying to find lowest price value
03161         foreach ($oAmPriceList as $sId => $oItem) {
03162             $oItemPrice = oxNew( 'oxprice' );
03163             if ( $oItem->oxprice2article__oxaddabs->value) {
03164                 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03165                 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03166                 $this->_applyCurrency( $oItemPrice, $oCur );
03167             } else {
03168                 $oItemPrice->setPrice( $dBasePrice );
03169                 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03170             }
03171 
03172             if (isset($dArticleVat)) {
03173                 $this->_applyVAT($oItemPrice, $dArticleVat);
03174             }
03175 
03176             if (!$oLowestPrice) {
03177                 $oLowestPrice = $oItemPrice;
03178             } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03179                 $oLowestPrice = $oItemPrice;
03180             }
03181 
03182             $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03183             $oAmPriceList[$sId]->fnetprice  = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03184             $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03185         }
03186 
03187         $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03188         return $oAmPriceList;
03189     }
03190 
03196     protected function _getVariantsIds()
03197     {
03198         $aSelect = array();
03199         $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->getId()."' " );
03200         if ( $oRs != false && $oRs->recordCount() > 0 ) {
03201             while (!$oRs->EOF) {
03202                 $aSelect[] = $oRs->fields['oxid'];
03203                 $oRs->moveNext();
03204             }
03205         }
03206         return $aSelect;
03207     }
03208 
03214     public function getArticleVat()
03215     {
03216         if (!isset($this->_dArticleVat)) {
03217             $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03218         }
03219         return $this->_dArticleVat;
03220     }
03221 
03230     protected function _applyVAT( oxPrice $oPrice, $dVat )
03231     {
03232         startProfile(__FUNCTION__);
03233         $oPrice->setVAT( $dVat );
03234         if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03235             $oPrice->setUserVat( $dVat );
03236         }
03237         stopProfile(__FUNCTION__);
03238     }
03239 
03247     public function applyVats( oxPrice $oPrice )
03248     {
03249         $this->_applyVAT($oPrice, $this->getArticleVat() );
03250     }
03251 
03262     protected function _applyDiscounts( $oPrice, $aDiscounts )
03263     {
03264         $oDiscountList = oxDiscountList::getInstance();
03265         $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03266     }
03267 
03275     public function applyDiscountsForVariant( $oPrice )
03276     {
03277         // apply discounts
03278         if ( !$this->skipDiscounts() ) {
03279             $oDiscountList = oxDiscountList::getInstance();
03280             $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03281         }
03282     }
03283 
03292     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03293     {
03294         if ( !$oCur ) {
03295             $oCur = $this->getConfig()->getActShopCurrencyObject();
03296         }
03297 
03298         $oPrice->multiply($oCur->rate);
03299     }
03300 
03301 
03310     protected function _getAttribsString(&$sAttribs, &$iCnt)
03311     {
03312         // we do not use lists here as we dont need this overhead right now
03313         $oDB = oxDb::getDb(true);
03314         $sSelect =  'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03315         $sAttribs = '';
03316         $blSep = false;
03317         $rs = $oDB->execute( $sSelect);
03318         $iCnt = 0;
03319         if ($rs != false && $rs->recordCount() > 0) {
03320             while (!$rs->EOF) {
03321                 if ( $blSep) {
03322                     $sAttribs .= ' or ';
03323                 }
03324                 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03325                 $blSep = true;
03326                 $iCnt++;
03327                 $rs->moveNext();
03328             }
03329         }
03330     }
03331 
03340     protected function _getSimList($sAttribs, $iCnt)
03341     {
03342         $myConfig = $this->getConfig();
03343         $oDB      = oxDb::getDb(true);
03344 
03345         // #523A
03346         $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03347         // 70% same attributes
03348         if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03349             $iAttrPercent = 0.70;
03350         }
03351         // #1137V iAttributesPercent = 100 doesnt work
03352         $iHitMin = ceil( $iCnt * $iAttrPercent );
03353 
03354         // we do not use lists here as we dont need this overhead right now
03355         $aList= array();
03356         $sSelect =  "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03357                     ( $sAttribs )
03358                     and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03359                     group by t1.oxobjectid having count(*) >= $iHitMin ";
03360 
03361         $rs = $oDB->selectLimit( $sSelect, 20, 0);
03362         if ($rs != false && $rs->recordCount() > 0) {
03363             while (!$rs->EOF) {
03364                 $oTemp = new stdClass();    // #663
03365                 $oTemp->cnt = $rs->fields['cnt'];
03366                 $oTemp->id  = $rs->fields['oxobjectid'];
03367                 $aList[] = $oTemp;
03368                 $rs->moveNext();
03369             }
03370         }
03371         return $aList;
03372     }
03373 
03382     protected function _generateSimListSearchStr($sArticleTable, $aList)
03383     {
03384         $myConfig = $this->getConfig();
03385         $sFieldList = $this->getSelectFields();
03386         $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()."  and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03387         $blSep = false;
03388         $iCnt = 0;
03389         $oDb = oxDb::getDb();
03390         foreach ( $aList as $oTemp) {
03391             if ( $blSep) {
03392                 $sSearch .= ',';
03393             }
03394             $sSearch .= $oDb->quote($oTemp->id);
03395             $blSep = true;
03396             if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03397                 break;
03398             }
03399             $iCnt++;
03400         }
03401 
03402         //#1741T
03403         //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03404         $sSearch .= ') ';
03405 
03406         // #524A -- randomizing articles in attribute list
03407         $sSearch .= ' order by rand() ';
03408 
03409         return $sSearch;
03410     }
03411 
03420     protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03421     {
03422         $sCatView = getViewName( 'oxcategories' );
03423         $sO2CView = getViewName( 'oxobject2category' );
03424 
03425         // we do not use lists here as we dont need this overhead right now
03426         if ( !$blSearchPriceCat ) {
03427             $sSelect  = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03428                          {$sCatView}.oxid = oxobject2category.oxcatnid
03429                          where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03430         } else {
03431             $sSelect  = "select {$sCatView}.* from {$sCatView} where
03432                          '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03433                          '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03434         }
03435         return $sSelect;
03436     }
03437 
03443     protected function _generateSearchStrForCustomerBought()
03444     {
03445         $sArtTable = $this->_getObjectViewName( 'oxarticles' );
03446         $sOrderArtTable = getViewName( 'oxorderarticles' );
03447 
03448         // fetching filter params
03449         $sIn = " '{$this->oxarticles__oxid->value}' ";
03450         if ( $this->oxarticles__oxparentid->value ) {
03451 
03452             // adding article parent
03453             $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03454             $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03455 
03456         } else {
03457             $sParentIdForVariants = $this->getId();
03458         }
03459 
03460         // adding variants
03461         $oDb = oxDb::getDb(true);
03462         $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03463         if ( $oRs != false && $oRs->recordCount() > 0) {
03464             while ( !$oRs->EOF ) {
03465                 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03466                 $oRs->moveNext();
03467             }
03468         }
03469 
03470         $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03471         $iLimit = $iLimit?( $iLimit * 10 ): 50;
03472 
03473         // building sql (optimized)
03474         $sQ = "select distinct {$sArtTable}.* from (
03475                    select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03476                ) as suborder
03477                left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03478                left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03479                where {$sArtTable}.oxid not in ( {$sIn} )
03480                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03481 
03482         /* non optimized, but could be used if index forcing is not supported
03483         // building sql
03484         $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03485                    select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03486                ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03487                and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03488                and ".$this->getSqlActiveSnippet();
03489         */
03490 
03491         return $sQ;
03492     }
03493 
03503     protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03504     {
03505         $sCategoryView = getViewName('oxcategories');
03506         $sO2CView = getViewName('oxobject2category');
03507         $sLangPrefix = (($this->getLanguage())?'_'.$this->getLanguage():'');
03508 
03509         $oDb    = oxDb::getDb();
03510         $sOXID  = $oDb->quote($sOXID);
03511         $sCatId = $oDb->quote($sCatId);
03512 
03513         if (!$dPriceFromTo) {
03514             $sSelect  = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03515             $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03516             $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03517             $sSelect .= "and oxcategories.oxactive$sLangPrefix = 1 order by oxobject2category.oxtime ";
03518         } else {
03519             $dPriceFromTo = $oDb->quote($dPriceFromTo);
03520             $sSelect  = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03521             $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03522             $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03523         }
03524         return $sSelect;
03525     }
03526 
03532     protected function _getAmountPriceList()
03533     {
03534         if ($this->_oAmountPriceList) {
03535             return $this->_oAmountPriceList;
03536         }
03537 
03538         $myConfig = $this->getConfig();
03539 
03540         $sArtID  = $this->getId();
03541 
03542         // #1690C - Scale prices and variants
03543         if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03544             $sArtID = $this->oxarticles__oxparentid->value;
03545         }
03546 
03547         $sArtID = mysql_real_escape_string($sArtID);
03548 
03549         //collecting assigned to article amount-price list
03550         $oAmPriceList = oxNew( 'oxlist');
03551         $oAmPriceList->init('oxbase', 'oxprice2article');
03552 
03553         $sShopID = $myConfig->getShopID();
03554         if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03555             $sShopSelect = '1';
03556         } else {
03557             $sShopSelect = " oxshopid =  '$sShopID' ";
03558         }
03559 
03560         $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03561 
03562         // prepare abs prices if currently having percentages
03563         $oBasePrice = $this->_getGroupPrice();
03564         foreach ($oAmPriceList as $oAmPrice) {
03565             if ($oAmPrice->oxprice2article__oxaddperc->value) {
03566                 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03567             }
03568         }
03569 
03570         $this->_oAmountPriceList = $oAmPriceList;
03571         return $oAmPriceList;
03572     }
03573 
03581     protected function _isFieldEmpty($sFieldName)
03582     {
03583         $mValue = $this->$sFieldName->value;
03584 
03585         if (is_null($mValue)) {
03586             return true;
03587         }
03588 
03589         if ($mValue === '') {
03590             return true;
03591         }
03592 
03593         $aDoubleCopyFields = array('oxarticles__oxprice',
03594                                        'oxarticles__oxvat');
03595 
03596         if (!$mValue && in_array($sFieldName, $aDoubleCopyFields)) {
03597             return true;
03598         }
03599 
03600 
03601         if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03602             return true;
03603         }
03604 
03605         $sFieldName = strtolower($sFieldName);
03606 
03607         if ( $sFieldName == 'oxarticles__oxicon' && strpos($mValue, "nopic_ico.jpg") !== false ) {
03608             return true;
03609         }
03610 
03611         if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03612             return true;
03613         }
03614 
03615         return false;
03616     }
03617 
03625     protected function _assignParentFieldValue($sFieldName)
03626     {
03627         if (!($oParentArticle = $this->getParentArticle())) {
03628             return;
03629         }
03630 
03631         $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03632 
03633         // assigning only theese which parent article has
03634         if ( $oParentArticle->$sCopyFieldName != null ) {
03635 
03636             // only overwrite database values
03637             if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03638                 continue;
03639             }
03640 
03641             //do not copy certain fields
03642             if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03643                 return;
03644             }
03645 
03646             //COPY THE VALUE
03647             // assigning images from parent only if variant has no master image (#1807)
03648             if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03649                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03650                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03651                 }
03652             } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03653                 // for zoom images checking master image with specified index
03654                 // assign from parent only if no pictures to variant are added
03655                 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03656                 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03657                     $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03658                 }
03659             } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03660                 // if no pics generated for variants, load all from
03661                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03662             } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03663                 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03664             }
03665         }
03666     }
03667 
03673     public function getParentArticle()
03674     {
03675         if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03676             if ( !isset( self::$_aLoadedParents[$sParentId] ) ) {
03677                 self::$_aLoadedParents[$sParentId] = oxNew( 'oxarticle' );
03678                 self::$_aLoadedParents[$sParentId]->_blSkipAbPrice  = true;
03679                 self::$_aLoadedParents[$sParentId]->_blLoadPrice    = false;
03680                 self::$_aLoadedParents[$sParentId]->_blLoadVariants = false;
03681                 self::$_aLoadedParents[$sParentId]->load( $sParentId );
03682             }
03683             return self::$_aLoadedParents[$sParentId];
03684         }
03685     }
03686 
03694     protected function _getParentAricle()
03695     {
03696         return $this->getParentArticle();
03697     }
03698 
03704     protected function _assignParentFieldValues()
03705     {   startProfile('articleAssignParentInternal');
03706         if ( $this->oxarticles__oxparentid->value) {
03707             // yes, we are in fact a variant
03708             if ( !$this->isAdmin() || ($this->_blLoadParentData && $this->isAdmin() ) ) {
03709                 foreach ($this->_aFieldNames as $sFieldName => $sVal) {
03710                     $this->_assignParentFieldValue($sFieldName);
03711                 }
03712 
03713                 //assing long description
03714                 $oParentArticle = $this->getParentArticle();
03715                 if ( !$this->oxarticles__oxlongdesc->value ) {
03716                     $this->oxarticles__oxlongdesc = $oParentArticle->oxarticles__oxlongdesc;
03717                 }
03718 
03719             }
03720         }
03721         stopProfile('articleAssignParentInternal');
03722 
03723     }
03724 
03730     protected function _assignNotBuyableParent()
03731     {
03732         if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03733              ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03734             $this->_blNotBuyableParent = true;
03735 
03736         }
03737     }
03738 
03744     protected function _assignAllPictureValues()
03745     {
03746         $myConfig = $this->getConfig();
03747 
03748         $this->_assignPictureValues( "oxarticles__oxicon" );
03749         $this->_assignPictureValues( "oxarticles__oxthumb" );
03750 
03751         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03752 
03753         for ( $i=1; $i<= $iPicCount; $i++ ) {
03754             $this->_assignPictureValues( "oxarticles__oxpic".$i );
03755         }
03756 
03757         if ( $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' ) ) {
03758             for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03759                 $this->_assignZoomPictureValues( "oxarticles__oxzoom".$i );
03760             }
03761         }
03762     }
03763 
03771     protected function _assignZoomPictureValues( $sName='' )
03772     {
03773         if ( $this->isAdmin() ) {
03774             return;
03775         }
03776 
03777         $sFieldName = substr_replace( $sName, "", 0, 12);
03778 
03779         $aAllFields = $this->_getAllFields( true );
03780 
03781         if ( isset( $aAllFields[$sFieldName] ) ) {
03782             $this->$sName = parent::__get( $sName );
03783             $this->$sName->value;
03784         }
03785 
03786         $this->_assignParentFieldValue( $sName );
03787 
03788         $iIndex = (int) str_ireplace( "oxzoom", "", $sFieldName );
03789 
03790         if ( isset($this->_aFieldNames[$sFieldName]) || isset($this->_aFieldNames["oxpic".$iIndex]) ) {
03791             if ( $iIndex > 0 ) {
03792                 $this->$sName = new oxField( 'z' . $iIndex.'/'.$this->_getZoomPictureName($iIndex) );
03793             }
03794         }
03795     }
03796 
03804     protected function _assignPictureValues( $sName='' )
03805     {
03806         if ( $this->isAdmin() || !$sName ) {
03807             return;
03808         }
03809 
03810         $sFieldName = substr_replace( $sName, "", 0, 12);
03811         $myConfig = $this->getConfig();
03812 
03813         // add directories
03814         if ( $sFieldName == 'oxicon' && isset($this->_aFieldNames["oxicon"]) ) {
03815             $this->oxarticles__oxicon = new oxField('icon/'.$this->_getIconName());
03816             return;
03817         }
03818 
03819         if ( $sFieldName == 'oxthumb' && isset($this->_aFieldNames["oxthumb"]) ) {
03820             $this->oxarticles__oxthumb = new oxField('0/'.$this->_getThumbnailName());
03821             return;
03822         }
03823 
03824         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03825         if ( strpos($sFieldName, "oxpic") === 0 && isset($this->_aFieldNames[$sFieldName] ) ) {
03826 
03827             $iIndex = (int) str_ireplace( "oxpic", "", $sFieldName );
03828 
03829             if ( $iIndex > 0 && $iIndex < $iPicCount ) {
03830                 $this->$sName = new oxField( $iIndex . '/'.$this->_getPictureName($iIndex) );
03831                 $this->{$sName.'_ico'} = new oxField( $iIndex . '/'.$this->_getIconName($iIndex) );
03832                 return;
03833             }
03834         }
03835     }
03836 
03842     protected function _assignStock()
03843     {
03844         $myConfig = $this->getConfig();
03845         // -----------------------------------
03846         // stock
03847         // -----------------------------------
03848 
03849         // #1125 A. must round (using floor()) value taken from database and cast to int
03850         if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03851             $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03852         }
03853         //GREEN light
03854         $this->_iStockStatus = 0;
03855 
03856         // if we have flag /*1 or*/ 4 - we show always green light
03857         if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03858             //ORANGE light
03859             $iStock = $this->oxarticles__oxstock->value;
03860 
03861             if ($this->_blNotBuyableParent) {
03862                 $iStock = $this->oxarticles__oxvarstock->value;
03863             }
03864 
03865 
03866             if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03867                 $this->_iStockStatus = 1;
03868             }
03869 
03870             //RED light
03871             if ($iStock <= 0) {
03872                 $this->_iStockStatus = -1;
03873             }
03874         }
03875 
03876 
03877         // stock
03878         if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03879             $iOnStock = $this->oxarticles__oxstock->value;
03880             if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03881                 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03882             }
03883             if ($iOnStock <= 0) {
03884                 $this->_blNotBuyable = true;
03885             }
03886         }
03887 
03888         //exceptional handling for variant parent stock:
03889         if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03890             $this->_blNotBuyable = false;
03891             //but then at least setting notBuaybleParent to true
03892             $this->_blNotBuyableParent = true;
03893         }
03894 
03895         //special treatment for lists when blVariantParentBuyable config option is set to false
03896         //then we just hide "to basket" button.
03897         //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03898         if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03899             $this->_blNotBuyable = true;
03900         }
03901 
03902         //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03903         if ($this->_blNotBuyableParent && count($this->getVariants()) == 0) {
03904             $this->_blNotBuyable = true;
03905         }
03906     }
03907 
03913     protected function _assignPrices()
03914     {
03915         $myConfig = $this->getConfig();
03916 
03917         // Performance
03918         if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03919             return;
03920         }
03921 
03922         // compute price
03923         $dPrice = $this->getPrice()->getBruttoPrice();
03924 
03925         $oCur = $myConfig->getActShopCurrencyObject();
03926         //price per unit handling
03927         if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03928             $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03929         }
03930 
03931 
03932         //getting min and max prices of variants
03933         $this->_applyRangePrice();
03934     }
03935 
03941     protected function _assignPersistentParam()
03942     {
03943         // Persistent Parameter Handling
03944         $aPersParam     = oxSession::getVar( 'persparam');
03945         if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03946             $this->_aPersistParam = $aPersParam[$this->getId()];
03947         }
03948     }
03949 
03955     protected function _assignDynImageDir()
03956     {
03957         $myConfig = $this->getConfig();
03958 
03959         $sThisShop = $this->oxarticles__oxshopid->value;
03960 
03961         $this->_sDynImageDir   = $myConfig->getPictureUrl( null, false );
03962         $this->dabsimagedir    = $myConfig->getPictureDir( false ); //$sThisShop
03963         $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03964         $this->ssl_dimagedir   = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03965     }
03966 
03972     protected function _assignComparisonListFlag()
03973     {
03974         // #657 add a flag if article is on comparisonlist
03975 
03976         $aItems = oxConfig::getParameter('aFiltcompproducts');
03977         if ( isset( $aItems[$this->getId()])) {
03978             $this->_blIsOnComparisonList = true;
03979         }
03980     }
03981 
03987     protected function _assignAttributes()
03988     {
03989         //#1029T load attributes
03990         //#1078S removed check for module "Produktvergleich"
03991         if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03992             $this->getAttributes();
03993         }
03994     }
03995 
03996 
04004     protected function _insert()
04005     {
04006         // set oxinsert
04007         $iInsertTime = time();
04008         $now = date('Y-m-d H:i:s', $iInsertTime);
04009         $this->oxarticles__oxinsert    = new oxField( $now );
04010         $this->oxarticles__oxtimestamp = new oxField( $now );
04011         if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
04012             $this->oxarticles__oxsubclass = new oxField('oxarticle');
04013         }
04014 
04015         return parent::_insert();
04016     }
04017 
04023     protected function _update()
04024     {
04025 
04026         $this->_skipSaveFields();
04027 
04028         $myConfig = $this->getConfig();
04029 
04030 
04031         return parent::_update();
04032     }
04033 
04041     protected function _deleteRecords($sOXID)
04042     {
04043         $oDB = oxDb::getDb();
04044 
04045         $sOXID = $oDB->quote($sOXID);
04046 
04047         //delete the record
04048         $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
04049         $oDB->execute( $sDelete);
04050 
04051         //remove other records
04052         $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
04053         $oDB->execute( $sDelete);
04054 
04055         $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
04056         $oDB->execute( $sDelete);
04057 
04058         $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
04059         $oDB->execute( $sDelete);
04060 
04061         $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
04062         $oDB->execute( $sDelete);
04063 
04064         $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
04065         $oDB->execute( $sDelete);
04066 
04067         $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
04068         $oDB->execute( $sDelete);
04069 
04070         $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
04071         $oDB->execute( $sDelete);
04072 
04073         //#1508C - deleting oxobject2delivery entries added
04074         $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04075         $oDB->execute( $sDelete);
04076 
04077         $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04078         $oDB->execute( $sDelete);
04079 
04080         $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04081         $rs = $oDB->execute( $sDelete );
04082 
04083         $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04084         $rs = $oDB->execute( $sDelete );
04085 
04086 
04087         return $rs;
04088     }
04089 
04097     protected function _deleteVariantRecords($sOXID)
04098     {
04099         $oDB = oxDb::getDb();
04100         //collect variants to remove recursively
04101         $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDB->quote($sOXID);
04102         $rs = $oDB->execute( $sVariants);
04103         if ($rs != false && $rs->recordCount() > 0) {
04104             while (!$rs->EOF) {
04105                 $this->delete( $rs->fields[0]);
04106                 $rs->moveNext();
04107             }
04108         }
04109     }
04110 
04120     protected function _resetCacheAndArticleCount( $sOxid )
04121     {
04122         $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04123     }
04124 
04130     protected function _deletePics()
04131     {
04132         $myUtilsPic = oxUtilsPic::getInstance();
04133         $myConfig   = $this->getConfig();
04134         $oPictureHandler = oxPictureHandler::getInstance();
04135 
04136         //deleting custom main icon
04137         $oPictureHandler->deleteMainIcon( $this );
04138 
04139         //deleting custom thumbnail
04140         $oPictureHandler->deleteThumbnail( $this );
04141 
04142         $sAbsDynImageDir = $myConfig->getAbsDynImageDir();
04143 
04144         // deleting master image and all generated images
04145         $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04146         for ( $i = 1; $i <= $iPicCount; $i++ ) {
04147             $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04148         }
04149     }
04150 
04160     protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04161     {
04162 
04163         $myUtilsCount = oxUtilsCount::getInstance();
04164 
04165         if ( $sVendorId ) {
04166             $myUtilsCount->resetVendorArticleCount( $sVendorId );
04167         }
04168 
04169         if ( $sManufacturerId ) {
04170             $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04171         }
04172 
04173         //also reseting category counts
04174         $oDb = oxDb::getDb();
04175         $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04176         $oRs = $oDb->execute( $sQ );
04177         if ( $oRs !== false && $oRs->recordCount() > 0) {
04178             while ( !$oRs->EOF ) {
04179                 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04180                 $oRs->moveNext();
04181             }
04182         }
04183     }
04184 
04192     protected function _onChangeUpdateStock( $sParentID )
04193     {
04194         $oDb = oxDb::getDb();
04195         $sParentIdQuoted = $oDb->quote($sParentID);
04196         $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04197         $rs = $oDb->execute($sQ);
04198         $iOldStock = $rs->fields[0];
04199         $iVendorID = $rs->fields[1];
04200         $iManufacturerID = $rs->fields[2];
04201 
04202         $sQ = 'select sum(oxstock) from oxarticles where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04203         $iStock = (float) $oDb->getOne( $sQ );
04204 
04205         $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04206         $oDb->execute( $sQ );
04207 
04208             //now lets update category counts
04209             //first detect stock status change for this article (to or from 0)
04210             if ( $iStock < 0 ) {
04211                 $iStock = 0;
04212             }
04213             if ( $iOldStock < 0 ) {
04214                 $iOldStock = 0;
04215             }
04216             if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04217                 //means the stock status could be changed (oxstock turns from 0 to 1 or from 1 to 0)
04218                 // so far we leave it like this but later we could move all count resets to one or two functions
04219                 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04220             }
04221     }
04222 
04230     protected function _onChangeStockResetCount( $sOxid )
04231     {
04232         $myConfig = $this->getConfig();
04233 
04234         if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04235            ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04236 
04237                $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04238         }
04239     }
04240 
04248     protected function _onChangeUpdateVarCount( $sParentID )
04249     {
04250         $oDb = oxDb::getDb();
04251         $sParentIdQuoted = $oDb->quote($sParentID);
04252         $sQ = 'select count(*) as varcount from oxarticles where oxparentid = '.$sParentIdQuoted;
04253         $iVarCount = (int) $oDb->getOne($sQ);
04254 
04255         $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = '.$sParentIdQuoted;
04256         $oDb->execute($sQ);
04257     }
04258 
04266     protected function _onChangeUpdateMinVarPrice( $sParentID )
04267     {
04268         $oDb = oxDb::getDb();
04269         $sParentIdQuoted = $oDb->quote($sParentID);
04270         //#M0000883 (Sarunas)
04271         $sQ = 'select min(oxprice) as varminprice from oxarticles where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04272         $dVarMinPrice = $oDb->getOne($sQ);
04273 
04274         $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04275 
04276         $blParentBuyable =  $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04277 
04278         if ($dVarMinPrice) {
04279             if ($blParentBuyable) {
04280                 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04281             }
04282 
04283         } else {
04284             $dVarMinPrice = $dParentPrice;
04285         }
04286 
04287         if ( $dVarMinPrice ) {
04288             $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04289             $oDb->execute($sQ);
04290         }
04291     }
04292 
04293 
04299     protected function _applyRangePrice()
04300     {
04301         //#buglist_413 if bl_perfLoadPriceForAddList variant price shouldn't be loaded too
04302         if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04303             return;
04304         }
04305 
04306         $this->_blIsRangePrice = false;
04307 
04308         // if parent is buyable - do not apply range price calcculations
04309         if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04310             return;
04311         }
04312 
04313         $aPrices = array();
04314 
04315         if (!$this->_blNotBuyableParent) {
04316             $aPrices[] = $this->getPrice()->getBruttoPrice();
04317         }
04318 
04319         $aVariants = $this->getVariants(false);
04320 
04321         if (count($aVariants)) {
04322             foreach ($aVariants as $sKey => $oVariant) {
04323                 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04324             }
04325         }
04326 
04327         /*  $oAmPrices = $this->loadAmountPriceInfo();
04328         foreach ($oAmPrices as $oAmPrice) {
04329             $aPrices[] = $oAmPrice->oxprice2article__oxaddabs->value;
04330         }*/
04331 
04332         if (count($aPrices)) {
04333             $dMinPrice = $aPrices[0];
04334             $dMaxPrice = $aPrices[0];
04335             foreach ($aPrices as $dPrice) {
04336                 if ($dMinPrice > $dPrice) {
04337                     $dMinPrice = $dPrice;
04338                 }
04339 
04340                 if ($dMaxPrice < $dPrice) {
04341                     $dMaxPrice = $dPrice;
04342                 }
04343             }
04344         }
04345 
04346         if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04347             $this->getPrice()->setBruttoPriceMode();
04348             $this->getPrice()->setPrice($dMinPrice);
04349         }
04350 
04351         if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04352             $this->getPrice()->setBruttoPriceMode();
04353             $this->getPrice()->setPrice($dMinPrice);
04354             $this->_blIsRangePrice = true;
04355         }
04356 
04357         if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04358             $this->getPrice()->setBruttoPriceMode();
04359             $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04360             $this->_blIsRangePrice = true;
04361             $this->_calculatePrice( $this->getPrice() );
04362         }
04363     }
04364 
04371     public function getProductId()
04372     {
04373         return $this->getId();
04374     }
04375 
04381     public function getProductParentId()
04382     {
04383         return $this->oxarticles__oxparentid->value;
04384     }
04385 
04391     public function isOrderArticle()
04392     {
04393         return false;
04394     }
04395 
04401     public function isVariant()
04402     {
04403         return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04404     }
04405 
04411     public function isMdVariant()
04412     {
04413         $oMdVariant = oxNew( "oxVariantHandler" );
04414 
04415         return $oMdVariant->isMdVariant($this);
04416     }
04417 
04425     public function getSqlForPriceCategories($sFields = '')
04426     {
04427         if (!$sFields) {
04428             $sFields = 'oxid';
04429         }
04430         $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04431         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04432         return  "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04433                ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04434                ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04435     }
04436 
04444     public function inPriceCategory( $sCatNid )
04445     {
04446         $oDb = oxDb::getDb();
04447 
04448         $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04449         $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04450         return (bool) $oDb->getOne(
04451             "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04452            ."(   (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04453            ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04454            ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04455            .")"
04456         );
04457     }
04458 
04464     public function getMdVariants()
04465     {
04466         if ( $this->_oMdVariants ) {
04467             return $this->_oMdVariants;
04468         }
04469 
04470         $oParentArticle = $this->getParentArticle();
04471         if ( $oParentArticle ) {
04472             $oVariants = $oParentArticle->getVariants();
04473         } else {
04474             $oVariants = $this->getVariants();
04475         }
04476 
04477         $oVariantHandler = oxNew( "oxVariantHandler" );
04478         $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04479 
04480         return $this->_oMdVariants;
04481     }
04482 
04488     public function getMdSubvariants()
04489     {
04490         return $this->getMdVariants()->getMdSubvariants();
04491     }
04492 
04493 
04502     protected function _generateImages( $iIndex )
04503     {
04504         if ( isset($this->_aFieldNames["oxpic".$iIndex]) && !$this->_hasGeneratedImage( $iIndex ) ) {
04505             if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) && $this->_hasMasterImage( $iIndex ) ) {
04506                 $oPictureHandler = oxPictureHandler::getInstance();
04507                 $oPictureHandler->generateArticlePictures( $this, $iIndex );
04508             }
04509         }
04510     }
04511 
04520     public function updateAmountOfGeneratedPictures( $iTotalGenerated )
04521     {
04522         $this->oxarticles__oxpicsgenerated = new oxField( $iTotalGenerated );
04523         $oDb = oxDb::getDb();
04524         $sIdQuoted = $oDb->quote($this->getId());
04525 
04526         $sQ = 'update oxarticles set oxpicsgenerated = '.$iTotalGenerated.' where oxid = '.$sIdQuoted;
04527         $oDb->execute( $sQ );
04528     }
04529 
04538     protected function _hasGeneratedImage( $iIndex )
04539     {
04540         if ( $iIndex > (int) $this->oxarticles__oxpicsgenerated->value ) {
04541             return false;
04542         }
04543 
04544         return true;
04545     }
04546 
04554     protected function _hasMasterImage( $iIndex )
04555     {
04556         $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04557 
04558         if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04559             return false;
04560         }
04561         if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04562             return false;
04563         }
04564 
04565         $sMasterPic = $iIndex . "/" . $sPicName;
04566 
04567         if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04568             return true;
04569         }
04570 
04571         return false;
04572     }
04573 
04582     public function getPictureFieldValue( $sFieldName, $iIndex = null )
04583     {
04584         if ( $sFieldName ) {
04585             $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04586             return $this->$sFieldName->value;
04587         }
04588     }
04589 }