00001 <?php
00002
00003
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
00368 protected $_oLongDesc = null;
00369
00377 protected $_aVariantSelections = array();
00378
00383 protected static $_aSelections = array();
00384
00389 protected static $_aCategoryCache = null;
00398 public function __construct($aParams = null)
00399 {
00400 if ( $aParams && is_array($aParams)) {
00401 foreach ( $aParams as $sParam => $mValue) {
00402 $this->$sParam = $mValue;
00403 }
00404 }
00405 parent::__construct();
00406 $this->init( 'oxarticles' );
00407
00408 $this->_blIsRangePrice = false;
00409 }
00410
00419 public function __get($sName)
00420 {
00421 $myUtils = oxUtils::getInstance();
00422
00423 if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00424 return $this->getArticleLongDesc();
00425 }
00426
00427 $this->$sName = parent::__get($sName);
00428 if ( $this->$sName ) {
00429
00430 $this->_assignParentFieldValue($sName);
00431 }
00432
00433 return $this->$sName;
00434 }
00435
00444 public function __set( $sName, $sValue )
00445 {
00446
00447 if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00448 if ($this->_blEmployMultilanguage) {
00449 $sValue = ( $sValue instanceof oxField ) ? $sValue->getRawValue() : $sValue;
00450 $this->setArticleLongDesc( $sValue );
00451 } else {
00452 $this->$sName = $sValue;
00453 }
00454 } else {
00455 parent::__set( $sName, $sValue );
00456 }
00457 }
00458
00466 public function setId( $sId = null )
00467 {
00468 $sId = parent::setId( $sId );
00469
00470
00471 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00472
00473 return $sId;
00474 }
00475
00485 public function getActiveCheckQuery( $blForceCoreTable = null )
00486 {
00487 $sTable = $this->getViewName( $blForceCoreTable );
00488
00489
00490 $sQ = " $sTable.oxactive = 1 ";
00491
00492
00493 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00494 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00495 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00496 }
00497
00498 return $sQ;
00499 }
00500
00514 public function getStockCheckQuery( $blForceCoreTable = null )
00515 {
00516 $myConfig = $this->getConfig();
00517 $sTable = $this->getViewName( $blForceCoreTable );
00518
00519 $sQ = "";
00520
00521
00522 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00523 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00524
00525 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00526 $sTimeCheckQ = '';
00527 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00528 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00529 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00530 }
00531 $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 ) ) ";
00532 }
00533 }
00534
00535 return $sQ;
00536 }
00537
00549 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null )
00550 {
00551 $sTable = $this->getViewName( $blForceCoreTable );
00552 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00553
00554
00555 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00556 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00557 if ( $blRemoveNotOrderables ) {
00558 $sQ .= " and $sTable.oxstockflag != 3 ";
00559 }
00560 $sQ .= " ) ) ";
00561 }
00562
00563 return $sQ;
00564 }
00565
00573 public function getSqlActiveSnippet( $blForceCoreTable = null )
00574 {
00575 $myConfig = $this->getConfig();
00576
00577
00578 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00579
00580
00581 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00582
00583
00584 return "( $sQ ) ";
00585 }
00586
00594 public function setSkipAssign($blSkipAssign)
00595 {
00596 $this->_blSkipAssign = $blSkipAssign;
00597 }
00598
00604 public function disablePriceLoad()
00605 {
00606 $this->_blLoadPrice = false;
00607 }
00608
00614 public function getItemKey()
00615 {
00616 return $this->_sItemKey;
00617 }
00618
00626 public function setItemKey($sItemKey)
00627 {
00628 $this->_sItemKey = $sItemKey;
00629 }
00630
00638 public function setNoVariantLoading( $blLoadVariants )
00639 {
00640 $this->_blLoadVariants = !$blLoadVariants;
00641 }
00642
00648 public function isBuyable()
00649 {
00650 if ($this->_blNotBuyableParent) {
00651 return false;
00652 }
00653
00654 return !$this->_blNotBuyable;
00655 }
00656
00662 public function getPersParams()
00663 {
00664 return $this->_aPersistParam;
00665 }
00666
00672 public function isOnComparisonList()
00673 {
00674 return $this->_blIsOnComparisonList;
00675 }
00676
00684 public function setOnComparisonList( $blOnList )
00685 {
00686 $this->_blIsOnComparisonList = $blOnList;
00687 }
00688
00696 public function setLoadParentData($blLoadParentData)
00697 {
00698 $this->_blLoadParentData = $blLoadParentData;
00699 }
00700
00708 public function setSkipAbPrice( $blSkipAbPrice = null )
00709 {
00710 $this->_blSkipAbPrice = $blSkipAbPrice;
00711 }
00712
00720 public function getSearchableFields()
00721 {
00722 $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00723 $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00724
00725 return $aFields;
00726 }
00727
00728
00736 public function isMultilingualField($sFieldName)
00737 {
00738 switch ($sFieldName) {
00739 case "oxlongdesc":
00740 case "oxtags":
00741 return true;
00742 }
00743
00744 return parent::isMultilingualField($sFieldName);
00745 }
00746
00752 public function isVisible()
00753 {
00754
00755
00756 if ( ( $blCanPreview = oxUtils::getInstance()->canPreview() ) !== null ) {
00757 return $blCanPreview;
00758 }
00759
00760
00761 $sNow = date('Y-m-d H:i:s');
00762 if ( !$this->oxarticles__oxactive->value &&
00763 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00764 $this->oxarticles__oxactiveto->value < $sNow
00765 )) {
00766 return false;
00767 }
00768
00769
00770 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00771 $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00772 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00773 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00774 }
00775 if ( $iOnStock <= 0 ) {
00776 return false;
00777 }
00778 }
00779
00780 return true;
00781 }
00782
00791 public function assign( $aRecord)
00792 {
00793 startProfile('articleAssign');
00794
00795
00796
00797 parent::assign( $aRecord);
00798
00799 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00800
00801
00802 if ($this->_blSkipAssign) {
00803 return;
00804 }
00805
00806 $this->_assignParentFieldValues();
00807 $this->_assignNotBuyableParent();
00808
00809 $this->_assignStock();
00810 startProfile('articleAssignPrices');
00811 $this->_assignPrices();
00812 stopProfile('articleAssignPrices');
00813 $this->_assignPersistentParam();
00814 $this->_assignDynImageDir();
00815 $this->_assignComparisonListFlag();
00816 $this->_assignAttributes();
00817
00818
00819
00820
00821 stopProfile('articleAssign');
00822 }
00823
00834 public function load( $oxID)
00835 {
00836
00837 $this->_blNotBuyableParent = false;
00838
00839 $blRet = parent::load( $oxID);
00840
00841
00842 $this->oxarticles__oxinsert = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00843 $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00844
00845 return $blRet;
00846 }
00847
00855 public function addToRatingAverage( $iRating)
00856 {
00857 $dOldRating = $this->oxarticles__oxrating->value;
00858 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00859 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00860 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00861 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00862 $dRatingCnt = (int) ($dOldCnt + 1);
00863
00864 $oDb = oxDb::getDb();
00865 $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00866 }
00867
00873 public function getArticleRatingAverage()
00874 {
00875 return round( $this->oxarticles__oxrating->value, 1);
00876 }
00877
00883 public function getReviews()
00884 {
00885 $aIds = array($this->getId());
00886
00887 if ( $this->oxarticles__oxparentid->value ) {
00888 $aIds[] = $this->oxarticles__oxparentid->value;
00889 }
00890
00891
00892 if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00893 $aAdd = $this->_getVariantsIds();
00894 if (is_array($aAdd)) {
00895 $aIds = array_merge($aIds, $aAdd);
00896 }
00897 }
00898
00899 $oReview = oxNew('oxreview');
00900 $oRevs = $oReview->loadList('oxarticle', $aIds);
00901
00902
00903 if ( $oRevs->count() < 1 ) {
00904 return null;
00905 }
00906
00907 return $oRevs;
00908 }
00909
00915 public function getCrossSelling()
00916 {
00917 $oCrosslist = oxNew( "oxarticlelist");
00918 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00919 if ( $oCrosslist->count() ) {
00920 return $oCrosslist;
00921 }
00922 }
00923
00929 public function getAccessoires()
00930 {
00931 $myConfig = $this->getConfig();
00932
00933
00934 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00935 return;
00936 }
00937
00938 $oAcclist = oxNew( "oxarticlelist");
00939 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00940 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00941
00942 if ( $oAcclist->count()) {
00943 return $oAcclist;
00944 }
00945 }
00946
00952 public function getSimilarProducts()
00953 {
00954
00955 $myConfig = $this->getConfig();
00956 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
00957 return;
00958 }
00959
00960 $sArticleTable = $this->getViewName();
00961
00962 $sAttribs = '';
00963 $iCnt = 0;
00964 $this->_getAttribsString($sAttribs, $iCnt);
00965
00966 if ( !$sAttribs) {
00967 return null;
00968 }
00969
00970 $aList = $this->_getSimList($sAttribs, $iCnt);
00971
00972 if ( count( $aList ) ) {
00973 uasort( $aList, 'cmpart');
00974
00975 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
00976
00977 $oSimilarlist = oxNew( 'oxarticlelist' );
00978 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
00979 $oSimilarlist->selectString( $sSearch);
00980
00981 return $oSimilarlist;
00982 }
00983 }
00984
00990 public function getCustomerAlsoBoughtThisProducts()
00991 {
00992
00993 $myConfig = $this->getConfig();
00994 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
00995 return;
00996 }
00997
00998
00999 $sQ = $this->_generateSearchStrForCustomerBought();
01000
01001 $oArticles = oxNew( 'oxarticlelist' );
01002 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01003 $oArticles->selectString( $sQ );
01004 if ( $oArticles->count() ) {
01005 return $oArticles;
01006 }
01007 }
01008
01015 public function loadAmountPriceInfo()
01016 {
01017 $myConfig = $this->getConfig();
01018 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01019 return array();
01020 }
01021
01022 if ( $this->_oAmountPriceInfo === null ) {
01023 $this->_oAmountPriceInfo = array();
01024 if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01025 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01026
01027 }
01028 }
01029 return $this->_oAmountPriceInfo;
01030 }
01031
01039 public function getSelectLists($sKeyPrefix = null)
01040 {
01041
01042
01043 $sKey = $this->getId();
01044 if ( isset( $sKeyPrefix ) ) {
01045 $sKey = $sKeyPrefix.'__'.$this->getId();
01046 }
01047
01048 if ( !isset( self::$_aSelList[$sKey] ) ) {
01049 $oDb = oxDb::getDb();
01050 $sSLViewName = getViewName( 'oxselectlist' );
01051
01052 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01053 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01054
01055
01056 $oLists = oxNew( 'oxlist' );
01057 $oLists->init( 'oxselectlist' );
01058 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01059
01060
01061 if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01062 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01063 }
01064
01065 $dVat = 0;
01066 if ( $this->getPrice() != null ) {
01067 $dVat = $this->getPrice()->getVat();
01068 }
01069
01070 $iCnt = 0;
01071 self::$_aSelList[$sKey] = array();
01072 foreach ( $oLists as $oSelectlist ) {
01073 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01074 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01075 $iCnt++;
01076 }
01077 }
01078 return self::$_aSelList[$sKey];
01079 }
01080
01088 protected function _hasAnyVariant( $blForceCoreTable = null )
01089 {
01090 $blHas = false;
01091 if ( ( $sId = $this->getId() ) ) {
01092 if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01093 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01094 } else {
01095 $sArticleTable = $this->getViewName( $blForceCoreTable );
01096 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01097 }
01098
01099 }
01100 return $blHas;
01101 }
01102
01108 public function hasMdVariants()
01109 {
01110 return $this->_blHasMdVariants;
01111 }
01112
01122 public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01123 {
01124 $iLimit = (int) $iLimit;
01125 if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01126 $this->_aVariantSelections[$iLimit] = false;
01127 if ( $this->oxarticles__oxvarcount->value ) {
01128 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $this->getVariants(), $aFilterIds, $sActVariantId, $iLimit );
01129 }
01130 }
01131 return $this->_aVariantSelections[$iLimit];
01132 }
01133
01142 public function getSelections( $iLimit = null, $aFilter = null )
01143 {
01144 $sId = $this->getId() . ( (int) $iLimit );
01145 if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01146
01147 $oDb = oxDb::getDb();
01148 $sSLViewName = getViewName( 'oxselectlist' );
01149
01150 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01151 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01152
01153 if ( ( $iLimit = (int) $iLimit ) ) {
01154 $sQ .= " limit $iLimit ";
01155 }
01156
01157
01158 $dVat = 0;
01159 if ( ( $oPrice = $this->getPrice() ) != null ) {
01160 $dVat = $oPrice->getVat();
01161 }
01162
01163
01164 $oList = oxNew( 'oxlist' );
01165 $oList->init( 'oxselectlist' );
01166 $oList->getBaseObject()->setVat( $dVat );
01167 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01168
01169
01170 if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01171 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01172 }
01173
01174 self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01175 }
01176
01177 if ( self::$_aSelections[$sId] ) {
01178
01179 $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01180 if ( $aFilter ) {
01181 $iSelIdx = 0;
01182 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01183 if ( isset( $aFilter[$iSelIdx] ) ) {
01184 $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01185 }
01186 $iSelIdx++;
01187 }
01188 }
01189 }
01190
01191 return self::$_aSelections[$sId];
01192 }
01193
01203 protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01204 {
01205 $oVariants = array();
01206 if ( ( $sId = $this->getId() ) ) {
01207
01208 self::$_aLoadedParents[$sId] = $this;
01209
01210 $myConfig = $this->getConfig();
01211
01212 if ( !$this->_blLoadVariants ||
01213 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01214 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01215 return $oVariants;
01216 }
01217
01218
01219 $sCacheKey = $blSimple ? "simple" : "full";
01220 if ( $blRemoveNotOrderables ) {
01221 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01222 return $this->_aVariants[$sCacheKey];
01223 } else {
01224 $this->_aVariants[$sCacheKey] = & $oVariants;
01225 }
01226 } elseif ( !$blRemoveNotOrderables ) {
01227 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01228 return $this->_aVariantsWithNotOrderables[$sCacheKey];
01229 } else {
01230 $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01231 }
01232 }
01233
01234 if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01235
01236
01237 if ( $blSimple ) {
01238 $oVariants = oxNew( 'oxsimplevariantlist' );
01239 $oVariants->setParent( $this );
01240 } else {
01241
01242 $oVariants = oxNew( 'oxarticlelist' );
01243 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01244 }
01245
01246 startProfile("selectVariants");
01247 $blUseCoreTable = (bool) $blForceCoreTable;
01248 $oBaseObject = $oVariants->getBaseObject();
01249 $oBaseObject->setLanguage( $this->getLanguage() );
01250
01251
01252 $sArticleTable = $this->getViewName( $blUseCoreTable );
01253
01254 $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01255 $this->getActiveCheckQuery( $blUseCoreTable ) .
01256 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01257 " order by $sArticleTable.oxsort";
01258
01259 $oVariants->selectString( $sSelect );
01260
01261
01262 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01263 $oMdVariants = oxNew( "oxVariantHandler" );
01264 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01265 }
01266 stopProfile("selectVariants");
01267 }
01268
01269
01270 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01271 $this->_blNotBuyableParent = true;
01272 }
01273
01274
01275 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01276 $this->_blNotBuyable = true;
01277 }
01278 }
01279 return $oVariants;
01280 }
01281
01290 public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01291 {
01292 return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01293 }
01294
01303 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01304 {
01305 return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01306 }
01307
01313 public function getSimpleVariants()
01314 {
01315 if ( $this->oxarticles__oxvarcount->value) {
01316 return $this->getVariants();
01317 }
01318 }
01319
01328 public function getAdminVariants( $sLanguage = null )
01329 {
01330 $oVariants = oxNew( 'oxarticlelist');
01331 if ( ( $sId = $this->getId() ) ) {
01332
01333 $oBaseObj = $oVariants->getBaseObject();
01334
01335 if ( is_null( $sLanguage ) ) {
01336 $oBaseObj->setLanguage( oxLang::getInstance()->getBaseLanguage() );
01337 } else {
01338 $oBaseObj->setLanguage( $sLanguage );
01339 }
01340
01341 $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01342 $oVariants->selectString( $sSql );
01343
01344
01345 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01346
01347 $this->_blNotBuyableParent = true;
01348 }
01349 }
01350
01351 return $oVariants;
01352 }
01353
01361 public function getCategory()
01362 {
01363 $oCategory = oxNew( 'oxcategory' );
01364 $oCategory->setLanguage( $this->getLanguage() );
01365
01366
01367 $sOXID = $this->getId();
01368 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01369 $sOXID = $this->oxarticles__oxparentid->value;
01370 }
01371
01372 if ( $sOXID ) {
01373
01374 if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01375 startPRofile( 'getCategory' );
01376 $oStr = getStr();
01377 $sWhere = $oCategory->getSqlActiveSnippet();
01378 $sSelect = $this->_generateSearchStr( $sOXID );
01379 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01380
01381
01382 if ( !$oCategory->assignRecord( $sSelect ) ) {
01383
01384 $sSelect = $this->_generateSearchStr( $sOXID, true );
01385 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01386
01387
01388 if ( !$oCategory->assignRecord( $sSelect ) ) {
01389 $oCategory = null;
01390 }
01391 }
01392
01393 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01394 stopPRofile( 'getCategory' );
01395 } else {
01396
01397 $oCategory = $this->_aCategoryCache[ $sOXID ];
01398 }
01399 }
01400
01401 return $oCategory;
01402 }
01403
01412 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01413 {
01414 $myConfig = $this->getConfig();
01415 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01416 return self::$_aArticleCats[$this->getId()];
01417 }
01418
01419
01420 $sOXID = $this->getId();
01421 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01422 $sOXID = $this->oxarticles__oxparentid->value;
01423 }
01424
01425
01426 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01427 $oDB = oxDb::getDb(true);
01428 $rs = $oDB->execute( $sSql );
01429
01430
01431 $aRet = array();
01432
01433 if ($rs != false && $rs->recordCount() > 0) {
01434 while (!$rs->EOF) {
01435 $aRet[] = $rs->fields['oxcatnid'];
01436 $rs->moveNext();
01437 }
01438 }
01439
01440
01441 $sSql = $this->getSqlForPriceCategories();
01442
01443 $oDB = oxDb::getDb( true );
01444 $rs = $oDB->execute( $sSql );
01445
01446 if ($rs != false && $rs->recordCount() > 0) {
01447 while (!$rs->EOF) {
01448
01449 if ( is_array( $rs->fields ) ) {
01450 $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01451 }
01452
01453
01454 if ( !$aRet[$rs->fields['oxid']] ) {
01455 $aRet[] = $rs->fields['oxid'];
01456 }
01457 $rs->moveNext();
01458 }
01459 }
01460
01461 return self::$_aArticleCats[$this->getId()] = $aRet;
01462 }
01463
01472 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01473 {
01474 $sO2CView = $this->_getObjectViewName('oxobject2category');
01475 $sCatView = $this->_getObjectViewName('oxcategories');
01476 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01477 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01478 if ( $blActCats ) {
01479 $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 = 0 ) ) = 0 ";
01480 }
01481 $sSelect .= 'order by oxobject2category.oxtime ';
01482 return $sSelect;
01483 }
01484
01494 public function getVendor( $blShopCheck = true )
01495 {
01496 if ( ( $sVendorId = $this->getVendorId() ) ) {
01497 $oVendor = oxNew( 'oxvendor' );
01498 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01499 $oVendor = oxNew( 'oxi18n' );
01500 $oVendor->init('oxvendor');
01501 $oVendor->setReadOnly( true );
01502 $sVendorId = $this->oxarticles__oxvendorid->value;
01503 }
01504 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01505 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01506 $oVendor->setReadOnly( true );
01507 }
01508 return $oVendor;
01509 }
01510 return null;
01511 }
01512
01520 public function getVendorId( $blForceReload = false )
01521 {
01522 $sVendorId = false;
01523 if ( $this->oxarticles__oxvendorid->value ) {
01524 $sVendorId = $this->oxarticles__oxvendorid->value;
01525
01526 }
01527 return $sVendorId;
01528 }
01529
01537 public function getManufacturerId( $blForceReload = false )
01538 {
01539 $sManufacturerId = false;
01540 if ( $this->oxarticles__oxmanufacturerid->value ) {
01541
01542 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01543
01544 }
01545 return $sManufacturerId;
01546 }
01547
01557 public function getManufacturer( $blShopCheck = true )
01558 {
01559 $oManufacturer = oxNew( 'oxmanufacturer' );;
01560 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01561 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01562 $oManufacturer->setReadOnly( true );
01563 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01564 }
01565
01566 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01567 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01568 $oManufacturer->setReadOnly( true );
01569 }
01570 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01571 } else {
01572 $oManufacturer = null;
01573 }
01574
01575 return $oManufacturer;
01576 }
01577
01585 public function inCategory( $sCatNid)
01586 {
01587 return in_array( $sCatNid, $this->getCategoryIds());
01588 }
01589
01598 public function isAssignedToCategory( $sCatId )
01599 {
01600
01601 $sOXID = $this->getId();
01602 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01603 $sOXID = $this->oxarticles__oxparentid->value;
01604 }
01605
01606 $oDB = oxDb::getDb();
01607 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01608 $sOXID = $oDB->getOne( $sSelect);
01609
01610 if ( isset( $sOXID) && $sOXID) {
01611 return true;
01612 }
01613
01614
01615 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01616 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01617 if ( $dPriceFromTo > 0) {
01618 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01619 $sOXID = $oDB->getOne( $sSelect);
01620
01621 if ( isset( $sOXID) && $sOXID) {
01622 return true;
01623 }
01624 }
01625 }
01626 return false;
01627 }
01628
01634 public function getTPrice()
01635 {
01636 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01637 return;
01638 }
01639
01640 if ( $this->_oTPrice !== null ) {
01641 return $this->_oTPrice;
01642 }
01643
01644 $this->_oTPrice = oxNew( 'oxPrice' );
01645 $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01646
01647 $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01648 $this->_applyCurrency( $this->_oTPrice );
01649
01650 return $this->_oTPrice;
01651 }
01652
01658 public function skipDiscounts()
01659 {
01660
01661 if ( $this->_blSkipDiscounts !== null ) {
01662 return $this->_blSkipDiscounts;
01663 }
01664
01665 if ( $this->oxarticles__oxskipdiscounts->value ) {
01666 return true;
01667 }
01668
01669
01670 $this->_blSkipDiscounts = false;
01671 if ( oxDiscountList::getInstance()->hasSkipDiscountCategories() ) {
01672
01673 $oDb = oxDb::getDb();
01674 $sO2CView = getViewName( 'oxobject2category', $this->getLanguage() );
01675 $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01676 $sSelect = "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01677 where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01678 $this->_blSkipDiscounts = ( $oDb->getOne($sSelect) == 1 );
01679 }
01680 return $this->_blSkipDiscounts;
01681 }
01682
01690 public function setPrice(oxPrice $oPrice)
01691 {
01692 $this->_oPrice = $oPrice;
01693 }
01694
01703 public function getBasePrice( $dAmount = 1 )
01704 {
01705
01706
01707
01708
01709 $myConfig = $this->getConfig();
01710 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01711 return;
01712
01713
01714 $dPrice = $this->_getAmountPrice( $dAmount );
01715
01716
01717 return $dPrice;
01718 }
01719
01727 public function getPrice( $dAmount = 1 )
01728 {
01729 $myConfig = $this->getConfig();
01730
01731 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01732 return;
01733 }
01734
01735
01736 if ( $dAmount != 1 || $this->_oPrice === null ) {
01737 $oPrice = oxNew( 'oxPrice' );
01738
01739
01740 $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01741
01742
01743 if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01744 return $this->_oPrice = $oPrice;
01745 }
01746
01747 $this->_calculatePrice( $oPrice );
01748 if ( $dAmount != 1 ) {
01749 return $oPrice;
01750 }
01751
01752 $this->_oPrice = $oPrice;
01753 }
01754 return $this->_oPrice;
01755 }
01756
01765 protected function _calculatePrice( $oPrice, $dVat = null )
01766 {
01767
01768 if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01769 $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01770 }
01771
01772
01773 $this->_applyCurrency( $oPrice );
01774
01775 if ( !$this->skipDiscounts() ) {
01776 $oDiscountList = oxDiscountList::getInstance();
01777 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
01778 }
01779
01780 return $oPrice;
01781 }
01782
01790 public function setArticleUser($oUser)
01791 {
01792 $this->_oUser = $oUser;
01793 }
01794
01800 public function getArticleUser()
01801 {
01802 if ($this->_oUser) {
01803 return $this->_oUser;
01804 }
01805 return $this->getUser();
01806 }
01807
01817 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01818 {
01819 $oUser = $oBasket->getBasketUser();
01820 $this->setArticleUser( $oUser );
01821
01822 $oBasketPrice = oxNew( 'oxPrice' );
01823
01824
01825 $dBasePrice = $this->getBasePrice( $dAmount );
01826
01827
01828 $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01829
01830
01831 $oBasketPrice->setPrice( $dBasePrice );
01832
01833 $dVat = oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket );
01834 $this->_calculatePrice( $oBasketPrice, $dVat );
01835
01836
01837 return $oBasketPrice;
01838 }
01839
01852 public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01853 {
01854 $oDiscountList = oxDiscountList::getInstance();
01855 return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01856 }
01857
01866 public function delete( $sOXID = null )
01867 {
01868 if ( !$sOXID ) {
01869 $sOXID = $this->getId();
01870 }
01871 if ( !$sOXID ) {
01872 return false;
01873 }
01874
01875
01876
01877 $this->_deleteVariantRecords( $sOXID );
01878 $this->load( $sOXID );
01879 $this->_deletePics();
01880 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01881
01882
01883 parent::delete( $sOXID );
01884
01885 $rs = $this->_deleteRecords( $sOXID );
01886
01887 oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01888
01889 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01890
01891 return $rs->EOF;
01892 }
01893
01902 public function reduceStock($dAmount, $blAllowNegativeStock = false)
01903 {
01904 $this->beforeUpdate();
01905
01906 $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01907 if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01908 $dAmount += $iStockCount;
01909 $iStockCount = 0;
01910 }
01911 $this->oxarticles__oxstock = new oxField($iStockCount);
01912
01913 $oDb = oxDb::getDb();
01914 $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01915 $this->onChange( ACTION_UPDATE_STOCK );
01916 return $dAmount;
01917 }
01918
01927 public function updateSoldAmount( $dAmount = 0 )
01928 {
01929 if ( !$dAmount ) {
01930 return;
01931 }
01932
01933 $this->beforeUpdate();
01934
01935
01936 if ( !$this->oxarticles__oxparentid->value ) {
01937
01938 $dAmount = (double) $dAmount;
01939 $oDb = oxDb::getDb();
01940 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01941 } elseif ( $this->oxarticles__oxparentid->value) {
01942
01943 $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01944 $oUpdateArticle->updateSoldAmount( $dAmount );
01945 }
01946
01947 $this->onChange( ACTION_UPDATE );
01948
01949 return $rs;
01950 }
01951
01957 public function disableReminder()
01958 {
01959 $oDB = oxDb::getDb(true);
01960 return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01961 }
01962
01970 public function save()
01971 {
01972
01973 $this->oxarticles__oxthumb = new oxField( basename( $this->oxarticles__oxthumb->value ), oxField::T_RAW );
01974 $this->oxarticles__oxicon = new oxField( basename( $this->oxarticles__oxicon->value ), oxField::T_RAW );
01975 $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
01976 for ( $i = 1; $i <= $iPicCount; $i++ ) {
01977 $sFieldName = 'oxarticles__oxpic' . $i;
01978 if ( isset( $this->$sFieldName ) ) {
01979 $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );
01980 }
01981 }
01982
01983
01984 if ( ( $blRet = parent::save() ) ) {
01985
01986 $this->_saveArtLongDesc();
01987 }
01988
01989 return $blRet;
01990 }
01991
01992
01999 public function getPictureGallery()
02000 {
02001 $myConfig = $this->getConfig();
02002
02003
02004 $blMorePic = false;
02005 $aArtPics = array();
02006 $aArtIcons = array();
02007 $iActPicId = 1;
02008 $sActPic = $this->getPictureUrl( $iActPicId );
02009
02010 if ( oxConfig::getParameter( 'actpicid' ) ) {
02011 $iActPicId = oxConfig::getParameter('actpicid');
02012 }
02013
02014 $oStr = getStr();
02015 $iCntr = 0;
02016 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02017 $blCheckActivePicId = true;
02018
02019 for ( $i = 1; $i <= $iPicCount; $i++) {
02020 $sPicVal = $this->getPictureUrl( $i );
02021 $sIcoVal = $this->getIconUrl( $i );
02022 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02023 !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02024 if ($iCntr) {
02025 $blMorePic = true;
02026 }
02027 $aArtIcons[$i]= $sIcoVal;
02028 $aArtPics[$i]= $sPicVal;
02029 $iCntr++;
02030
02031 if ($iActPicId == $i) {
02032 $sActPic = $sPicVal;
02033 $blCheckActivePicId = false;
02034 }
02035
02036 } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02037
02038
02039 $iActPicId++;
02040 }
02041 }
02042
02043 $blZoomPic = false;
02044 $aZoomPics = array();
02045 $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02046
02047 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02048 $sVal = $this->getZoomPictureUrl($j);
02049
02050 if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02051 $blZoomPic = true;
02052 $aZoomPics[$c]['id'] = $c;
02053 $aZoomPics[$c]['file'] = $sVal;
02054
02055 if (!$sVal) {
02056 $aZoomPics[$c]['file'] = "nopic.jpg";
02057 }
02058 $c++;
02059 }
02060 }
02061
02062 $aPicGallery = array('ActPicID' => $iActPicId,
02063 'ActPic' => $sActPic,
02064 'MorePics' => $blMorePic,
02065 'Pics' => $aArtPics,
02066 'Icons' => $aArtIcons,
02067 'ZoomPic' => $blZoomPic,
02068 'ZoomPics' => $aZoomPics);
02069
02070 return $aPicGallery;
02071 }
02072
02086 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02087 {
02088 $myConfig = $this->getConfig();
02089
02090 if (!isset($sOXID)) {
02091 if ( $this->getId()) {
02092 $sOXID = $this->getId();
02093 }
02094 if (!isset ($sOXID)) {
02095 $sOXID = $this->oxarticles__oxid->value;
02096 }
02097 if ($this->oxarticles__oxparentid->value) {
02098 $sParentID = $this->oxarticles__oxparentid->value;
02099 }
02100 }
02101 if (!isset($sOXID)) {
02102 return;
02103 }
02104
02105
02106 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02107
02108
02109 if (!isset($sParentID)) {
02110 $oDb = oxDb::getDb();
02111 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02112 $sParentID = $oDb->getOne($sQ);
02113 }
02114
02115 if ($sParentID) {
02116 $this->_onChangeUpdateStock($sParentID);
02117 }
02118 }
02119
02120
02121 if ($sParentID) {
02122 $this->_onChangeUpdateVarCount($sParentID);
02123 }
02124
02125 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02126 $this->_onChangeUpdateMinVarPrice( $sId );
02127
02128
02129
02130 if ( $sAction === ACTION_UPDATE_STOCK ) {
02131 $this->_onChangeStockResetCount( $sOXID );
02132 }
02133
02134 }
02135
02142 public function getCustomVAT()
02143 {
02144 if ( isset($this->oxarticles__oxvat->value) ) {
02145 return $this->oxarticles__oxvat->value;
02146 }
02147 }
02148
02157 public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02158 {
02159 $myConfig = $this->getConfig();
02160 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02161 return true;
02162 }
02163
02164 $oDb = oxDb::getDb(true);
02165
02166 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.oxDb::getDb(true)->quote( $this->getId() );
02167 $rs = oxDb::getDb(true)->execute( $sQ );
02168
02169 $iOnStock = 0;
02170 $iStockFlag = 0;
02171 if ( $rs !== false && $rs->recordCount() > 0 ) {
02172 $iOnStock = $rs->fields['oxstock'] - $dArtStockAmount;
02173 $iStockFlag = $rs->fields['oxstockflag'];
02174
02175
02176 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02177 return true;
02178 }
02179 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02180 $iOnStock = floor( $iOnStock );
02181 }
02182 }
02183 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02184 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02185 }
02186 if ( $iOnStock >= $dAmount ) {
02187 return true;
02188 } else {
02189 if ( $iOnStock > 0 ) {
02190 return $iOnStock;
02191 } else {
02192 $oEx = oxNew( 'oxArticleInputException' );
02193 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02194 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02195 return false;
02196 }
02197 }
02198 }
02199
02200
02208 public function getArticleLongDesc( $sOxid = null )
02209 {
02210 if ( $this->_oLongDesc === null ) {
02211
02212 $this->_oLongDesc = new oxField();
02213
02214
02215
02216 $sOxid = $sOxid === null ? $this->getId() : $sOxid;
02217 $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02218
02219 $sDbValue = oxDb::getDb()->getOne( "select oxlongdesc from {$sViewName} where oxid = ?", array( $sOxid ) );
02220 if ( $sDbValue !== false ) {
02221 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02222 } elseif ( $this->oxarticles__oxparentid->value ) {
02223 $this->_oLongDesc->setValue( $this->getParentArticle()->getArticleLongDesc()->getRawValue(), oxField::T_RAW );
02224 }
02225 }
02226 return $this->_oLongDesc;
02227 }
02228
02238 protected function _setLongDesc( $sDbValue )
02239 {
02240 $this->setArticleLongDesc( $sDbValue );
02241 }
02242
02249 public function getLongDesc()
02250 {
02251 return oxUtilsView::getInstance()->parseThroughSmarty( $this->getArticleLongDesc()->getRawValue(), $this->getId().$this->getLanguage() );
02252 }
02253
02262 public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02263 {
02264
02265
02266 $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02267
02268
02269 if ( $sOrigValue ) {
02270 $this->_oLongDesc->orignalValue = $sOrigValue;
02271 }
02272 }
02273
02279 public function getAttributes()
02280 {
02281 if ( $this->_oAttributeList === null ) {
02282 $this->_oAttributeList = oxNew( 'oxattributelist' );
02283 $this->_oAttributeList->loadAttributes( $this->getId() );
02284 }
02285
02286 return $this->_oAttributeList;
02287 }
02288
02297 public function appendLink( $sAddParams, $iLang = null )
02298 {
02299 if ( $sAddParams ) {
02300 if ( $iLang === null ) {
02301 $iLang = $this->getLanguage();
02302 }
02303
02304 $this->_aSeoAddParams[$iLang] = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&" : "";
02305 $this->_aSeoAddParams[$iLang] .= $sAddParams;
02306 }
02307 }
02308
02317 public function getBaseSeoLink( $iLang, $blMain = false )
02318 {
02319 $oEncoder = oxSeoEncoderArticle::getInstance();
02320 if ( !$blMain ) {
02321 return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02322 }
02323 return $oEncoder->getArticleMainUrl( $this, $iLang );
02324 }
02325
02334 public function getLink( $iLang = null, $blMain = false )
02335 {
02336 if ( !oxUtils::getInstance()->seoIsActive() ) {
02337 return $this->getStdLink( $iLang );
02338 }
02339
02340 if ( $iLang === null ) {
02341 $iLang = $this->getLanguage();
02342 }
02343
02344 $iLinkType = $this->getLinkType();
02345 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02346 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02347 }
02348
02349 $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02350 if ( isset($this->_aSeoAddParams[$iLang])) {
02351 $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&' ).$this->_aSeoAddParams[$iLang];
02352 }
02353
02354 return $sUrl;
02355 }
02356
02365 public function getMainLink( $iLang = null )
02366 {
02367 return $this->getLink( $iLang, true );
02368 }
02369
02377 public function setLinkType( $iType )
02378 {
02379
02380 $this->_sDetailLink = null;
02381
02382
02383 $this->_iLinkType = (int) $iType;
02384 }
02385
02391 public function getLinkType()
02392 {
02393 return $this->_iLinkType;
02394 }
02395
02404 public function appendStdLink( $sAddParams, $iLang = null )
02405 {
02406 if ( $sAddParams ) {
02407 if ( $iLang === null ) {
02408 $iLang = $this->getLanguage();
02409 }
02410
02411 $this->_aStdAddParams[$iLang] = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&" : "";
02412 $this->_aStdAddParams[$iLang] .= $sAddParams;
02413 }
02414 }
02415
02425 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02426 {
02427 $sUrl = '';
02428 if ( $blFull ) {
02429
02430 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02431 }
02432
02433 $sUrl .= "index.php?cl=details" . ( $blAddId ? "&anid=".$this->getId() : "" );
02434 return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&". $this->_aStdAddParams[$iLang] : "" );
02435 }
02436
02445 public function getStdLink( $iLang = null, $aParams = array() )
02446 {
02447 if ( $iLang === null ) {
02448 $iLang = $this->getLanguage();
02449 }
02450
02451 if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02452 $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02453 }
02454
02455 return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02456 }
02457
02465 public function getStdTagLink( $sTag )
02466 {
02467 $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02468 return $sStdTagLink . "cl=details&anid=".$this->getId()."&listtype=tag&searchtag=".rawurlencode( $sTag );
02469 }
02470
02476 public function getTags()
02477 {
02478 $oDb = oxDb::getDb();
02479 $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02480 $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02481 $oTagCloud = oxNew('oxtagcloud');
02482 return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02483 }
02484
02492 public function saveTags($sTags)
02493 {
02494
02495 if ( !$this->allowDerivedUpdate() ) {
02496 return false;
02497 }
02498
02499
02500 $oTagCloud = oxNew( 'oxtagcloud' );
02501 $oTagCloud->resetTagCache();
02502 $sTags = mysql_real_escape_string( $oTagCloud->prepareTags( $sTags ) );
02503 $oDb = oxDb::getDb();
02504
02505 $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02506 $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02507 $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02508 on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02509 return $oDb->execute( $sQ );
02510 }
02511
02519 public function addTag($sTag)
02520 {
02521 $oDb = oxDb::getDb();
02522
02523 $oTagCloud = oxNew('oxtagcloud');
02524 $oTagCloud->resetTagCache();
02525 $sTag = $oTagCloud->prepareTags($sTag);
02526 $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02527
02528 $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02529 $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02530 if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02531 $sTailTag = $sTagSeparator . $sTag;
02532 } else {
02533 $sTailTag = $sTag;
02534 }
02535
02536 $sTag = mysql_real_escape_string($sTag);
02537 $sTailTag = mysql_real_escape_string($sTailTag);
02538
02539 $sTag = mysql_real_escape_string($sTag);
02540 $sTailTag = mysql_real_escape_string($sTailTag);
02541
02542 $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02543 ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02544
02545 return $oDb->execute( $sQ );
02546 }
02547
02553 public function getMediaUrls()
02554 {
02555 if ( $this->_aMediaUrls === null ) {
02556 $this->_aMediaUrls = oxNew("oxlist");
02557 $this->_aMediaUrls->init("oxmediaurl");
02558 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02559
02560 $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02561 $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02562 $this->_aMediaUrls->selectString($sQ);
02563 }
02564 return $this->_aMediaUrls;
02565 }
02566
02572 public function getDynImageDir()
02573 {
02574 return $this->_sDynImageDir;
02575 }
02576
02582 public function getDispSelList()
02583 {
02584 if ($this->_aDispSelList === null) {
02585 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02586 $this->_aDispSelList = $this->getSelectLists();
02587 }
02588 }
02589 return $this->_aDispSelList;
02590 }
02591
02597 public function getMoreDetailLink()
02598 {
02599 if ( $this->_sMoreDetailLink == null ) {
02600
02601
02602 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02603
02604
02605 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02606 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02607 }
02608 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02609 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02610 }
02611
02612 return $this->_sMoreDetailLink;
02613 }
02614
02620 public function getToBasketLink()
02621 {
02622 if ( $this->_sToBasketLink == null ) {
02623 $myConfig = $this->getConfig();
02624
02625 if ( oxUtils::getInstance()->isSearchEngine() ) {
02626 $this->_sToBasketLink = $this->getLink();
02627 } else {
02628
02629 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02630
02631
02632 $sActClass = oxConfig::getParameter( 'cl' );
02633 if ( $sActClass == 'thankyou') {
02634 $sActClass = 'basket';
02635 }
02636 $this->_sToBasketLink .= 'cl='.$sActClass;
02637
02638
02639 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02640 $this->_sToBasketLink .= '&cnid='.$sActCat;
02641 }
02642
02643 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02644
02645 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02646 $this->_sToBasketLink .= '&tpl='.$sTpl;
02647 }
02648 }
02649 }
02650
02651 return $this->_sToBasketLink;
02652 }
02653
02659 public function getStockStatus()
02660 {
02661 return $this->_iStockStatus;
02662 }
02663
02669 public function getDeliveryDate()
02670 {
02671 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02672 return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02673 }
02674 return false;
02675 }
02676
02682 public function getFTPrice()
02683 {
02684 if ( $oPrice = $this->getTPrice() ) {
02685 if ( $oPrice->getBruttoPrice() ) {
02686 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02687 }
02688 }
02689 }
02690
02696 public function getFPrice()
02697 {
02698 if ( $oPrice = $this->getPrice() ) {
02699 return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02700 }
02701 }
02702
02708 public function getFNetPrice()
02709 {
02710 if ( $oPrice = $this->getPrice() ) {
02711 return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02712 }
02713 }
02714
02720 public function getPricePerUnit()
02721 {
02722 return $this->_fPricePerUnit;
02723 }
02724
02730 public function isParentNotBuyable()
02731 {
02732 return $this->_blNotBuyableParent;
02733 }
02734
02740 public function isNotBuyable()
02741 {
02742 return $this->_blNotBuyable;
02743 }
02744
02752 public function setBuyableState( $blBuyable = false )
02753 {
02754 $this->_blNotBuyable = !$blBuyable;
02755 }
02756
02765 public function getVariantList()
02766 {
02767 return $this->getVariants();
02768 }
02769
02777 public function setSelectlist( $aSelList )
02778 {
02779 $this->_aDispSelList = $aSelList;
02780 }
02781
02789 public function getPictureUrl( $iIndex = 1 )
02790 {
02791 if ( $iIndex ) {
02792 $sImgName = false;
02793 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02794 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02795 }
02796
02797 $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02798 return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02799 }
02800 }
02801
02810 public function getIconUrl( $iIndex = 0 )
02811 {
02812 $sImgName = false;
02813 $sDirname = "product/1/";
02814 if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02815 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02816 $sDirname = "product/{$iIndex}/";
02817 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02818 $sImgName = basename( $this->oxarticles__oxicon->value );
02819 $sDirname = "product/icon/";
02820 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02821 $sImgName = basename( $this->oxarticles__oxpic1->value );
02822 }
02823
02824 $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02825 return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02826 }
02827
02833 public function getThumbnailUrl()
02834 {
02835 $sImgName = false;
02836 $sDirname = "product/1/";
02837 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02838 $sImgName = basename( $this->oxarticles__oxthumb->value );
02839 $sDirname = "product/thumb/";
02840 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02841 $sImgName = basename( $this->oxarticles__oxpic1->value );
02842 }
02843
02844 $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02845 return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0 );
02846 }
02847
02855 public function getZoomPictureUrl( $iIndex = '' )
02856 {
02857 $iIndex = (int) $iIndex;
02858 if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02859 $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02860 $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02861 return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02862 }
02863 }
02864
02870 public function getFileUrl()
02871 {
02872 return $this->getConfig()->getPictureUrl( 'media/' );
02873 }
02874
02880 public function getPriceFromPrefix()
02881 {
02882 $sPricePrefix = '';
02883 if ( $this->_blIsRangePrice) {
02884 $sPricePrefix = oxLang::getInstance()->translateString('priceFrom').' ';
02885 }
02886
02887 return $sPricePrefix;
02888 }
02889
02895 protected function _saveArtLongDesc()
02896 {
02897 $myConfig = $this->getConfig();
02898 $sShopId = $myConfig->getShopID();
02899 if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02900 return;
02901 }
02902
02903 if ($this->_blEmployMultilanguage) {
02904 $sValue = $this->getArticleLongDesc()->getRawValue();
02905 if ( $sValue !== null ) {
02906 $oArtExt = oxNew('oxI18n');
02907 $oArtExt->init('oxartextends');
02908 $oArtExt->setLanguage((int) $this->getLanguage());
02909 if (!$oArtExt->load($this->getId())) {
02910 $oArtExt->setId($this->getId());
02911 }
02912 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02913 $oArtExt->save();
02914 }
02915 } else {
02916 $oArtExt = oxNew('oxI18n');
02917 $oArtExt->setEnableMultilang(false);
02918 $oArtExt->init('oxartextends');
02919 $aObjFields = $oArtExt->_getAllFields(true);
02920 if (!$oArtExt->load($this->getId())) {
02921 $oArtExt->setId($this->getId());
02922 }
02923
02924 foreach ($aObjFields as $sKey => $sValue ) {
02925 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02926 $sField = $this->_getFieldLongName($sKey);
02927
02928 if (isset($this->$sField)) {
02929 $sLongDesc = null;
02930 if ($this->$sField instanceof oxField) {
02931 $sLongDesc = $this->$sField->getRawValue();
02932 } elseif (is_object($this->$sField)) {
02933 $sLongDesc = $this->$sField->value;
02934 }
02935 if (isset($sLongDesc)) {
02936 $sAEField = $oArtExt->_getFieldLongName($sKey);
02937 $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
02938 }
02939 }
02940 }
02941 }
02942 $oArtExt->save();
02943 }
02944 }
02945
02951 protected function _skipSaveFields()
02952 {
02953 $myConfig = $this->getConfig();
02954
02955 $this->_aSkipSaveFields = array();
02956
02957 $this->_aSkipSaveFields[] = 'oxtimestamp';
02958
02959 $this->_aSkipSaveFields[] = 'oxinsert';
02960
02961 if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02962 $this->_aSkipSaveFields[] = 'oxparentid';
02963 }
02964
02965 }
02966
02976 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02977 {
02978 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02979
02980 if ( array_key_exists ($sKey, $aDiscounts) ) {
02981 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02982 } else {
02983 $aDiscounts[$sKey] = $oDiscount;
02984 }
02985 }
02986 return $aDiscounts;
02987 }
02988
02994 protected function _getGroupPrice()
02995 {
02996 $dPrice = $this->oxarticles__oxprice->value;
02997
02998 $oUser = $this->getArticleUser();
02999 if ( $oUser ) {
03000 if ( $oUser->inGroup( 'oxidpricea' ) ) {
03001 $dPrice = $this->oxarticles__oxpricea->value;
03002 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03003 $dPrice = $this->oxarticles__oxpriceb->value;
03004 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03005 $dPrice = $this->oxarticles__oxpricec->value;
03006 }
03007 }
03008
03009
03010 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03011 $dPrice = $this->oxarticles__oxprice->value;
03012 }
03013
03014 return $dPrice;
03015 }
03016
03025 protected function _getAmountPrice($dAmount = 1)
03026 {
03027 $myConfig = $this->getConfig();
03028
03029 startProfile( "_getAmountPrice" );
03030
03031 $dPrice = $this->_getGroupPrice();
03032 $oAmtPrices = $this->_getAmountPriceList();
03033 foreach ($oAmtPrices as $oAmPrice) {
03034 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03035 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03036 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03037 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03038 }
03039 }
03040
03041 stopProfile( "_getAmountPrice" );
03042 return $dPrice;
03043 }
03044
03053 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03054 {
03055 $myConfig = $this->getConfig();
03056
03057 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03058
03059 $aSelLists = $this->getSelectLists();
03060
03061 foreach ( $aSelLists as $key => $aSel) {
03062 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03063 $oSel = $aSel[$aChosenList[$key]];
03064 if ( $oSel->priceUnit =='abs' ) {
03065 $dPrice += $oSel->price;
03066 } elseif ( $oSel->priceUnit =='%' ) {
03067 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03068 }
03069 }
03070 }
03071 }
03072 return $dPrice;
03073 }
03074
03075
03083 protected function _fillAmountPriceList($oAmPriceList)
03084 {
03085 $myConfig = $this->getConfig();
03086 $myUtils = oxUtils::getInstance();
03087
03088
03089 $oCur = $myConfig->getActShopCurrencyObject();
03090
03091 $oUser = $this->getArticleUser();
03092
03093 $oDiscountList = oxDiscountList::getInstance();
03094 $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03095
03096 $oLowestPrice = null;
03097
03098 $dBasePrice = $this->_getGroupPrice();
03099 $oLang = oxLang::getInstance();
03100
03101 $dArticleVat = null;
03102 if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03103 $dArticleVat = $this->getArticleVat();
03104 }
03105
03106
03107 foreach ($oAmPriceList as $sId => $oItem) {
03108 $oItemPrice = oxNew( 'oxprice' );
03109 if ( $oItem->oxprice2article__oxaddabs->value) {
03110 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03111 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03112 $this->_applyCurrency( $oItemPrice, $oCur );
03113 } else {
03114 $oItemPrice->setPrice( $dBasePrice );
03115 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03116 }
03117
03118 if (isset($dArticleVat)) {
03119 $this->_applyVAT($oItemPrice, $dArticleVat);
03120 }
03121
03122 if (!$oLowestPrice) {
03123 $oLowestPrice = $oItemPrice;
03124 } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03125 $oLowestPrice = $oItemPrice;
03126 }
03127
03128 $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03129 $oAmPriceList[$sId]->fnetprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03130 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03131 }
03132
03133 $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03134 return $oAmPriceList;
03135 }
03136
03142 protected function _getVariantsIds()
03143 {
03144 $aSelect = array();
03145 if ( ( $sId = $this->getId() ) ) {
03146 $oDb = oxDb::getDb(true);
03147 $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03148 $this->getSqlActiveSnippet( true );
03149
03150 $oRs = $oDb->execute( $sQ );
03151 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03152 while (!$oRs->EOF) {
03153 $aSelect[] = reset( $oRs->fields );
03154 $oRs->moveNext();
03155 }
03156 }
03157 }
03158 return $aSelect;
03159 }
03160
03166 public function getArticleVat()
03167 {
03168 if (!isset($this->_dArticleVat)) {
03169 $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03170 }
03171 return $this->_dArticleVat;
03172 }
03173
03182 protected function _applyVAT( oxPrice $oPrice, $dVat )
03183 {
03184 startProfile(__FUNCTION__);
03185 $oPrice->setVAT( $dVat );
03186 if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03187 $oPrice->setUserVat( $dVat );
03188 }
03189 stopProfile(__FUNCTION__);
03190 }
03191
03199 public function applyVats( oxPrice $oPrice )
03200 {
03201 $this->_applyVAT($oPrice, $this->getArticleVat() );
03202 }
03203
03214 protected function _applyDiscounts( $oPrice, $aDiscounts )
03215 {
03216 $oDiscountList = oxDiscountList::getInstance();
03217 $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03218 }
03219
03227 public function applyDiscountsForVariant( $oPrice )
03228 {
03229
03230 if ( !$this->skipDiscounts() ) {
03231 $oDiscountList = oxDiscountList::getInstance();
03232 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03233 }
03234 }
03235
03244 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03245 {
03246 if ( !$oCur ) {
03247 $oCur = $this->getConfig()->getActShopCurrencyObject();
03248 }
03249
03250 $oPrice->multiply($oCur->rate);
03251 }
03252
03253
03262 protected function _getAttribsString(&$sAttribs, &$iCnt)
03263 {
03264
03265 $oDB = oxDb::getDb(true);
03266 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDB->quote( $this->getId() );
03267 $sAttribs = '';
03268 $blSep = false;
03269 $rs = $oDB->execute( $sSelect);
03270 $iCnt = 0;
03271 if ($rs != false && $rs->recordCount() > 0) {
03272 while (!$rs->EOF) {
03273 if ( $blSep) {
03274 $sAttribs .= ' or ';
03275 }
03276 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03277 $blSep = true;
03278 $iCnt++;
03279 $rs->moveNext();
03280 }
03281 }
03282 }
03283
03292 protected function _getSimList($sAttribs, $iCnt)
03293 {
03294 $myConfig = $this->getConfig();
03295 $oDB = oxDb::getDb(true);
03296
03297
03298 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03299
03300 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03301 $iAttrPercent = 0.70;
03302 }
03303
03304 $iHitMin = ceil( $iCnt * $iAttrPercent );
03305
03306
03307 $aList= array();
03308 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03309 ( $sAttribs )
03310 and t1.oxobjectid != ".$oDB->quote( $this->oxarticles__oxid->value )."
03311 group by t1.oxobjectid having count(*) >= $iHitMin ";
03312
03313 $rs = $oDB->selectLimit( $sSelect, 20, 0);
03314 if ($rs != false && $rs->recordCount() > 0) {
03315 while (!$rs->EOF) {
03316 $oTemp = new stdClass();
03317 $oTemp->cnt = $rs->fields['cnt'];
03318 $oTemp->id = $rs->fields['oxobjectid'];
03319 $aList[] = $oTemp;
03320 $rs->moveNext();
03321 }
03322 }
03323 return $aList;
03324 }
03325
03334 protected function _generateSimListSearchStr($sArticleTable, $aList)
03335 {
03336 $myConfig = $this->getConfig();
03337 $sFieldList = $this->getSelectFields();
03338 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03339 $blSep = false;
03340 $iCnt = 0;
03341 $oDb = oxDb::getDb();
03342 foreach ( $aList as $oTemp) {
03343 if ( $blSep) {
03344 $sSearch .= ',';
03345 }
03346 $sSearch .= $oDb->quote($oTemp->id);
03347 $blSep = true;
03348 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03349 break;
03350 }
03351 $iCnt++;
03352 }
03353
03354
03355
03356 $sSearch .= ') ';
03357
03358
03359 $sSearch .= ' order by rand() ';
03360
03361 return $sSearch;
03362 }
03363
03372 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03373 {
03374
03375 $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03376 $sO2CView = getViewName( 'oxobject2category' );
03377
03378
03379 if ( !$blSearchPriceCat ) {
03380 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03381 {$sCatView}.oxid = oxobject2category.oxcatnid
03382 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03383 } else {
03384 $sSelect = "select {$sCatView}.* from {$sCatView} where
03385 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03386 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03387 }
03388 return $sSelect;
03389 }
03390
03396 protected function _generateSearchStrForCustomerBought()
03397 {
03398 $sArtTable = $this->getViewName();
03399 $sOrderArtTable = getViewName( 'oxorderarticles' );
03400
03401
03402 $sIn = " '{$this->oxarticles__oxid->value}' ";
03403 if ( $this->oxarticles__oxparentid->value ) {
03404
03405
03406 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03407 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03408
03409 } else {
03410 $sParentIdForVariants = $this->getId();
03411 }
03412
03413
03414 $oDb = oxDb::getDb(true);
03415 $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03416 if ( $oRs != false && $oRs->recordCount() > 0) {
03417 while ( !$oRs->EOF ) {
03418 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03419 $oRs->moveNext();
03420 }
03421 }
03422
03423 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03424 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03425
03426
03427 $sQ = "select distinct {$sArtTable}.* from (
03428 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03429 ) as suborder
03430 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03431 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03432 where {$sArtTable}.oxid not in ( {$sIn} )
03433 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03434
03435
03436
03437
03438
03439
03440
03441
03442
03443
03444 return $sQ;
03445 }
03446
03456 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03457 {
03458 $sCategoryView = getViewName('oxcategories');
03459 $sO2CView = getViewName('oxobject2category');
03460
03461 $oDb = oxDb::getDb();
03462 $sOXID = $oDb->quote($sOXID);
03463 $sCatId = $oDb->quote($sCatId);
03464
03465 if (!$dPriceFromTo) {
03466 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03467 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03468 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03469 $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03470 } else {
03471 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03472 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03473 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03474 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03475 }
03476 return $sSelect;
03477 }
03478
03484 protected function _getAmountPriceList()
03485 {
03486 if ( $this->_oAmountPriceList === null ) {
03487 $this->_oAmountPriceList = array();
03488 if ( !$this->skipDiscounts() ) {
03489 $myConfig = $this->getConfig();
03490 $sArtId = $this->getId();
03491
03492
03493 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03494 $sArtId = $this->oxarticles__oxparentid->value;
03495 }
03496
03497
03498 $oAmPriceList = oxNew( 'oxlist' );
03499 $oAmPriceList->init( 'oxbase', 'oxprice2article' );
03500
03501 $sShopID = $myConfig->getShopID();
03502 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03503 $sShopSelect = '1';
03504 } else {
03505 $sShopSelect = " oxshopid = '$sShopID' ";
03506 }
03507
03508 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = " . oxDb::getDb()->quote( $sArtId ) . " and $sShopSelect order by oxamount ");
03509
03510
03511 $oBasePrice = $this->_getGroupPrice();
03512 foreach ( $oAmPriceList as $oAmPrice ) {
03513 if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03514 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03515 }
03516 }
03517
03518 $this->_oAmountPriceList = $oAmPriceList;
03519 }
03520 }
03521
03522 return $this->_oAmountPriceList;
03523 }
03524
03532 protected function _isFieldEmpty( $sFieldName )
03533 {
03534 $mValue = $this->$sFieldName->value;
03535
03536 if ( is_null( $mValue ) ) {
03537 return true;
03538 }
03539
03540 if ( $mValue === '' ) {
03541 return true;
03542 }
03543
03544 $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03545
03546 if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03547 return true;
03548 }
03549
03550
03551 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03552 return true;
03553 }
03554
03555 $sFieldName = strtolower($sFieldName);
03556
03557 if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03558 return true;
03559 }
03560
03561 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03562 return true;
03563 }
03564
03565 return false;
03566 }
03567
03575 protected function _assignParentFieldValue($sFieldName)
03576 {
03577 if (!($oParentArticle = $this->getParentArticle())) {
03578 return;
03579 }
03580
03581 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03582
03583
03584 if ( $oParentArticle->$sCopyFieldName != null ) {
03585
03586
03587 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03588 return;
03589 }
03590
03591
03592 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03593 return;
03594 }
03595
03596
03597
03598 if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03599 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03600 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03601 }
03602 } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03603
03604
03605 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03606 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03607 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03608 }
03609 } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03610
03611 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03612 } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03613 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03614 }
03615 }
03616 }
03617
03623 public function getParentArticle()
03624 {
03625 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03626 $sIndex = $sParentId . "_" . $this->getLanguage();
03627 if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03628 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03629 self::$_aLoadedParents[$sIndex]->_blSkipAbPrice = true;
03630 self::$_aLoadedParents[$sIndex]->_blLoadPrice = false;
03631 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03632 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03633 }
03634 return self::$_aLoadedParents[$sIndex];
03635 }
03636 }
03637
03645 protected function _getParentAricle()
03646 {
03647 return $this->getParentArticle();
03648 }
03649
03655 protected function _assignParentFieldValues()
03656 {
03657 startProfile('articleAssignParentInternal');
03658 if ( $this->oxarticles__oxparentid->value ) {
03659
03660 if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03661 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03662 $this->_assignParentFieldValue( $sFieldName );
03663 }
03664 }
03665 }
03666 stopProfile('articleAssignParentInternal');
03667 }
03668
03674 protected function _assignNotBuyableParent()
03675 {
03676 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03677 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03678 $this->_blNotBuyableParent = true;
03679
03680 }
03681 }
03682
03688 protected function _assignStock()
03689 {
03690 $myConfig = $this->getConfig();
03691
03692
03693
03694
03695
03696 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03697 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03698 }
03699
03700 $this->_iStockStatus = 0;
03701
03702
03703 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03704
03705 $iStock = $this->oxarticles__oxstock->value;
03706
03707 if ($this->_blNotBuyableParent) {
03708 $iStock = $this->oxarticles__oxvarstock->value;
03709 }
03710
03711
03712 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03713 $this->_iStockStatus = 1;
03714 }
03715
03716
03717 if ($iStock <= 0) {
03718 $this->_iStockStatus = -1;
03719 }
03720 }
03721
03722
03723
03724 if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03725 $iOnStock = $this->oxarticles__oxstock->value;
03726 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03727 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03728 }
03729 if ($iOnStock <= 0) {
03730 $this->_blNotBuyable = true;
03731 }
03732 }
03733
03734
03735 if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03736 $this->_blNotBuyable = false;
03737
03738 $this->_blNotBuyableParent = true;
03739 }
03740
03741
03742
03743
03744 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03745 $this->_blNotBuyable = true;
03746 }
03747
03748
03749 if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03750 $this->_blNotBuyable = true;
03751 }
03752 }
03753
03759 protected function _assignPrices()
03760 {
03761 $myConfig = $this->getConfig();
03762
03763
03764 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03765 return;
03766 }
03767
03768
03769 $dPrice = $this->getPrice()->getBruttoPrice();
03770
03771 $oCur = $myConfig->getActShopCurrencyObject();
03772
03773 if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03774 $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03775 }
03776
03777
03778 if ( $this->_hasAnyVariant() ) {
03779 $this->_applyRangePrice();
03780 }
03781 }
03782
03788 protected function _assignPersistentParam()
03789 {
03790
03791 $aPersParam = oxSession::getVar( 'persparam');
03792 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03793 $this->_aPersistParam = $aPersParam[$this->getId()];
03794 }
03795 }
03796
03802 protected function _assignDynImageDir()
03803 {
03804 $myConfig = $this->getConfig();
03805
03806 $sThisShop = $this->oxarticles__oxshopid->value;
03807
03808 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03809 $this->dabsimagedir = $myConfig->getPictureDir( false );
03810 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03811 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03812 }
03813
03819 protected function _assignComparisonListFlag()
03820 {
03821
03822
03823 $aItems = oxSession::getVar('aFiltcompproducts');
03824 if ( isset( $aItems[$this->getId()])) {
03825 $this->_blIsOnComparisonList = true;
03826 }
03827 }
03828
03834 protected function _assignAttributes()
03835 {
03836
03837
03838 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03839 $this->getAttributes();
03840 }
03841 }
03842
03843
03851 protected function _insert()
03852 {
03853
03854 $iInsertTime = time();
03855 $now = date('Y-m-d H:i:s', $iInsertTime);
03856 $this->oxarticles__oxinsert = new oxField( $now );
03857 $this->oxarticles__oxtimestamp = new oxField( $now );
03858 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03859 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03860 }
03861
03862 return parent::_insert();
03863 }
03864
03870 protected function _update()
03871 {
03872
03873 $this->_skipSaveFields();
03874
03875 $myConfig = $this->getConfig();
03876
03877
03878 return parent::_update();
03879 }
03880
03888 protected function _deleteRecords($sOXID)
03889 {
03890 $oDB = oxDb::getDb();
03891
03892 $sOXID = $oDB->quote($sOXID);
03893
03894
03895 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03896 $oDB->execute( $sDelete);
03897
03898 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03899 $oDB->execute( $sDelete);
03900
03901 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03902 $oDB->execute( $sDelete);
03903
03904 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03905 $oDB->execute( $sDelete);
03906
03907 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03908 $oDB->execute( $sDelete);
03909
03910 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03911 $oDB->execute( $sDelete);
03912
03913 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03914 $oDB->execute( $sDelete);
03915
03916
03917 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03918 $oDB->execute( $sDelete);
03919
03920 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03921 $oDB->execute( $sDelete);
03922
03923
03924 foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03925 $oDB->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03926 }
03927
03928 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03929 $rs = $oDB->execute( $sDelete );
03930
03931 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03932 $rs = $oDB->execute( $sDelete );
03933
03934
03935 return $rs;
03936 }
03937
03945 protected function _deleteVariantRecords( $sOXID )
03946 {
03947 if ( $sOXID ) {
03948 $oDb = oxDb::getDb();
03949
03950 $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03951 $rs = $oDb->execute( $sQ );
03952 if ($rs != false && $rs->recordCount() > 0) {
03953 while (!$rs->EOF) {
03954 $this->delete( $rs->fields[0] );
03955 $rs->moveNext();
03956 }
03957 }
03958 }
03959 }
03960
03970 protected function _resetCacheAndArticleCount( $sOxid )
03971 {
03972 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03973 }
03974
03980 protected function _deletePics()
03981 {
03982 $myUtilsPic = oxUtilsPic::getInstance();
03983 $myConfig = $this->getConfig();
03984 $oPictureHandler = oxPictureHandler::getInstance();
03985
03986
03987 $oPictureHandler->deleteMainIcon( $this );
03988
03989
03990 $oPictureHandler->deleteThumbnail( $this );
03991
03992 $sAbsDynImageDir = $myConfig->getPictureDir(false);
03993
03994
03995 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03996 for ( $i = 1; $i <= $iPicCount; $i++ ) {
03997 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
03998 }
03999 }
04000
04010 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04011 {
04012
04013 $myUtilsCount = oxUtilsCount::getInstance();
04014
04015 if ( $sVendorId ) {
04016 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04017 }
04018
04019 if ( $sManufacturerId ) {
04020 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04021 }
04022
04023
04024 $oDb = oxDb::getDb();
04025 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04026 $oRs = $oDb->execute( $sQ );
04027 if ( $oRs !== false && $oRs->recordCount() > 0) {
04028 while ( !$oRs->EOF ) {
04029 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04030 $oRs->moveNext();
04031 }
04032 }
04033 }
04034
04042 protected function _onChangeUpdateStock( $sParentID )
04043 {
04044 if ( $sParentID ) {
04045 $oDb = oxDb::getDb();
04046 $sParentIdQuoted = $oDb->quote($sParentID);
04047 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04048 $rs = $oDb->execute($sQ);
04049 $iOldStock = $rs->fields[0];
04050 $iVendorID = $rs->fields[1];
04051 $iManufacturerID = $rs->fields[2];
04052
04053 $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04054 $iStock = (float) $oDb->getOne( $sQ );
04055
04056 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04057 $oDb->execute( $sQ );
04058
04059
04060
04061 if ( $iStock < 0 ) {
04062 $iStock = 0;
04063 }
04064 if ( $iOldStock < 0 ) {
04065 $iOldStock = 0;
04066 }
04067 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04068
04069
04070 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04071 }
04072 }
04073 }
04074
04082 protected function _onChangeStockResetCount( $sOxid )
04083 {
04084 $myConfig = $this->getConfig();
04085
04086 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04087 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04088
04089 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04090 }
04091 }
04092
04100 protected function _onChangeUpdateVarCount( $sParentID )
04101 {
04102 if ( $sParentID ) {
04103 $oDb = oxDb::getDb();
04104 $sParentIdQuoted = $oDb->quote( $sParentID );
04105 $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04106 $iVarCount = (int) $oDb->getOne( $sQ );
04107
04108 $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04109 $oDb->execute( $sQ );
04110 }
04111 }
04112
04120 protected function _onChangeUpdateMinVarPrice( $sParentID )
04121 {
04122 if ( $sParentID ) {
04123 $oDb = oxDb::getDb();
04124 $sParentIdQuoted = $oDb->quote($sParentID);
04125
04126 $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04127 $dVarMinPrice = $oDb->getOne($sQ);
04128
04129 $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04130
04131 $blParentBuyable = $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04132
04133 if ($dVarMinPrice) {
04134 if ($blParentBuyable) {
04135 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04136 }
04137
04138 } else {
04139 $dVarMinPrice = $dParentPrice;
04140 }
04141
04142 if ( $dVarMinPrice ) {
04143 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04144 $oDb->execute($sQ);
04145 }
04146 }
04147 }
04148
04149
04155 protected function _applyRangePrice()
04156 {
04157
04158 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04159 return;
04160 }
04161
04162 $this->_blIsRangePrice = false;
04163
04164
04165 if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04166 return;
04167 }
04168
04169 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04170
04171
04172 $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04173 $this->_blIsRangePrice = true;
04174 $this->_calculatePrice( $this->getPrice() );
04175 return;
04176 }
04177
04178 $aPrices = array();
04179
04180 if (!$this->_blNotBuyableParent) {
04181 $aPrices[] = $this->getPrice()->getBruttoPrice();
04182 }
04183
04184 $aVariants = $this->getVariants(false);
04185
04186 if (count($aVariants)) {
04187 foreach ($aVariants as $sKey => $oVariant) {
04188 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04189 }
04190 }
04191
04192 if ( count( $aPrices ) ) {
04193 $dMinPrice = min( $aPrices );
04194 $dMaxPrice = max( $aPrices );
04195 }
04196
04197 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04198 $this->getPrice()->setBruttoPriceMode();
04199 $this->getPrice()->setPrice($dMinPrice);
04200 }
04201
04202 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04203 $this->getPrice()->setBruttoPriceMode();
04204 $this->getPrice()->setPrice($dMinPrice);
04205 $this->_blIsRangePrice = true;
04206 }
04207 }
04208
04215 public function getProductId()
04216 {
04217 return $this->getId();
04218 }
04219
04225 public function getProductParentId()
04226 {
04227 return $this->oxarticles__oxparentid->value;
04228 }
04229
04235 public function isOrderArticle()
04236 {
04237 return false;
04238 }
04239
04245 public function isVariant()
04246 {
04247 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04248 }
04249
04255 public function isMdVariant()
04256 {
04257 $oMdVariant = oxNew( "oxVariantHandler" );
04258
04259 return $oMdVariant->isMdVariant($this);
04260 }
04261
04269 public function getSqlForPriceCategories($sFields = '')
04270 {
04271 if (!$sFields) {
04272 $sFields = 'oxid';
04273 }
04274 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04275 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04276 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04277 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04278 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04279 }
04280
04288 public function inPriceCategory( $sCatNid )
04289 {
04290 $oDb = oxDb::getDb();
04291
04292 $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04293 $sQuotedCnid = $oDb->quote( $sCatNid );
04294 return (bool) $oDb->getOne(
04295 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04296 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04297 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04298 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04299 .")"
04300 );
04301 }
04302
04308 public function getMdVariants()
04309 {
04310 if ( $this->_oMdVariants ) {
04311 return $this->_oMdVariants;
04312 }
04313
04314 $oParentArticle = $this->getParentArticle();
04315 if ( $oParentArticle ) {
04316 $oVariants = $oParentArticle->getVariants();
04317 } else {
04318 $oVariants = $this->getVariants();
04319 }
04320
04321 $oVariantHandler = oxNew( "oxVariantHandler" );
04322 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04323
04324 return $this->_oMdVariants;
04325 }
04326
04332 public function getMdSubvariants()
04333 {
04334 return $this->getMdVariants()->getMdSubvariants();
04335 }
04336
04344 protected function _hasMasterImage( $iIndex )
04345 {
04346 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04347
04348 if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04349 return false;
04350 }
04351 if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04352 return false;
04353 }
04354
04355 $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04356
04357 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04358 return true;
04359 }
04360
04361 return false;
04362 }
04363
04372 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04373 {
04374 if ( $sFieldName ) {
04375 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04376 return $this->$sFieldName->value;
04377 }
04378 }
04379
04387 public function getMasterZoomPictureUrl( $iIndex )
04388 {
04389 $sPicUrl = false;
04390 $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04391
04392 if ( $sPicName && $sPicName != "nopic.jpg" ) {
04393 $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04394 if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04395 $sPicUrl = false;
04396 }
04397 }
04398
04399 return $sPicUrl;
04400 }
04401 }