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;
00394 protected static $_blHasAmountPrice = null;
00395
00396
00405 public function __construct($aParams = null)
00406 {
00407 if ( $aParams && is_array($aParams)) {
00408 foreach ( $aParams as $sParam => $mValue) {
00409 $this->$sParam = $mValue;
00410 }
00411 }
00412 parent::__construct();
00413 $this->init( 'oxarticles' );
00414
00415 $this->_blIsRangePrice = false;
00416 }
00417
00426 public function __get($sName)
00427 {
00428 $myUtils = oxUtils::getInstance();
00429
00430 if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00431 return $this->getArticleLongDesc();
00432 }
00433
00434 $this->$sName = parent::__get($sName);
00435 if ( $this->$sName ) {
00436
00437 $this->_assignParentFieldValue($sName);
00438 }
00439
00440 return $this->$sName;
00441 }
00442
00451 public function __set( $sName, $sValue )
00452 {
00453
00454 if ( strpos( $sName, 'oxarticles__oxlongdesc' ) === 0 ) {
00455 if ($this->_blEmployMultilanguage) {
00456 $sValue = ( $sValue instanceof oxField ) ? $sValue->getRawValue() : $sValue;
00457 $this->setArticleLongDesc( $sValue );
00458 } else {
00459 $this->$sName = $sValue;
00460 }
00461 } else {
00462 parent::__set( $sName, $sValue );
00463 }
00464 }
00465
00473 public function setId( $sId = null )
00474 {
00475 $sId = parent::setId( $sId );
00476
00477
00478 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00479
00480 return $sId;
00481 }
00482
00492 public function getActiveCheckQuery( $blForceCoreTable = null )
00493 {
00494 $sTable = $this->getViewName( $blForceCoreTable );
00495
00496
00497 $sQ = " $sTable.oxactive = 1 ";
00498
00499
00500 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00501 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00502 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00503 }
00504
00505 return $sQ;
00506 }
00507
00521 public function getStockCheckQuery( $blForceCoreTable = null )
00522 {
00523 $myConfig = $this->getConfig();
00524 $sTable = $this->getViewName( $blForceCoreTable );
00525
00526 $sQ = "";
00527
00528
00529 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00530 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00531
00532 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00533 $sTimeCheckQ = '';
00534 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00535 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00536 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00537 }
00538 $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 ) ) ";
00539 }
00540 }
00541
00542 return $sQ;
00543 }
00544
00556 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null )
00557 {
00558 $sTable = $this->getViewName( $blForceCoreTable );
00559 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00560
00561
00562 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00563 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00564 if ( $blRemoveNotOrderables ) {
00565 $sQ .= " and $sTable.oxstockflag != 3 ";
00566 }
00567 $sQ .= " ) ) ";
00568 }
00569
00570 return $sQ;
00571 }
00572
00580 public function getSqlActiveSnippet( $blForceCoreTable = null )
00581 {
00582 $myConfig = $this->getConfig();
00583
00584
00585 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00586
00587
00588 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00589
00590
00591 return "( $sQ ) ";
00592 }
00593
00601 public function setSkipAssign($blSkipAssign)
00602 {
00603 $this->_blSkipAssign = $blSkipAssign;
00604 }
00605
00611 public function disablePriceLoad()
00612 {
00613 $this->_blLoadPrice = false;
00614 }
00615
00621 public function getItemKey()
00622 {
00623 return $this->_sItemKey;
00624 }
00625
00633 public function setItemKey($sItemKey)
00634 {
00635 $this->_sItemKey = $sItemKey;
00636 }
00637
00645 public function setNoVariantLoading( $blLoadVariants )
00646 {
00647 $this->_blLoadVariants = !$blLoadVariants;
00648 }
00649
00655 public function isBuyable()
00656 {
00657 if ($this->_blNotBuyableParent) {
00658 return false;
00659 }
00660
00661 return !$this->_blNotBuyable;
00662 }
00663
00669 public function getPersParams()
00670 {
00671 return $this->_aPersistParam;
00672 }
00673
00679 public function isOnComparisonList()
00680 {
00681 return $this->_blIsOnComparisonList;
00682 }
00683
00691 public function setOnComparisonList( $blOnList )
00692 {
00693 $this->_blIsOnComparisonList = $blOnList;
00694 }
00695
00703 public function setLoadParentData($blLoadParentData)
00704 {
00705 $this->_blLoadParentData = $blLoadParentData;
00706 }
00707
00715 public function setSkipAbPrice( $blSkipAbPrice = null )
00716 {
00717 $this->_blSkipAbPrice = $blSkipAbPrice;
00718 }
00719
00727 public function getSearchableFields()
00728 {
00729 $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00730 $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00731
00732 return $aFields;
00733 }
00734
00735
00743 public function isMultilingualField($sFieldName)
00744 {
00745 switch ($sFieldName) {
00746 case "oxlongdesc":
00747 case "oxtags":
00748 return true;
00749 }
00750
00751 return parent::isMultilingualField($sFieldName);
00752 }
00753
00759 public function isVisible()
00760 {
00761
00762
00763 if ( ( $blCanPreview = oxUtils::getInstance()->canPreview() ) !== null ) {
00764 return $blCanPreview;
00765 }
00766
00767
00768 $sNow = date('Y-m-d H:i:s');
00769 if ( !$this->oxarticles__oxactive->value &&
00770 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00771 $this->oxarticles__oxactiveto->value < $sNow
00772 )) {
00773 return false;
00774 }
00775
00776
00777 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00778 $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00779 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00780 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00781 }
00782 if ( $iOnStock <= 0 ) {
00783 return false;
00784 }
00785 }
00786
00787 return true;
00788 }
00789
00798 public function assign( $aRecord)
00799 {
00800 startProfile('articleAssign');
00801
00802
00803
00804 parent::assign( $aRecord);
00805
00806 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00807
00808
00809 if ($this->_blSkipAssign) {
00810 return;
00811 }
00812
00813 $this->_assignParentFieldValues();
00814 $this->_assignNotBuyableParent();
00815
00816 $this->_assignStock();
00817 startProfile('articleAssignPrices');
00818 $this->_assignPrices();
00819 stopProfile('articleAssignPrices');
00820 $this->_assignPersistentParam();
00821 $this->_assignDynImageDir();
00822 $this->_assignComparisonListFlag();
00823 $this->_assignAttributes();
00824
00825
00826
00827
00828 stopProfile('articleAssign');
00829 }
00830
00841 public function load( $oxID)
00842 {
00843
00844 $this->_blNotBuyableParent = false;
00845
00846 $blRet = parent::load( $oxID);
00847
00848
00849 $this->oxarticles__oxinsert = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00850 $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00851
00852 return $blRet;
00853 }
00854
00862 public function addToRatingAverage( $iRating)
00863 {
00864 $dOldRating = $this->oxarticles__oxrating->value;
00865 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00866 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00867 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00868 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00869 $dRatingCnt = (int) ($dOldCnt + 1);
00870
00871 $oDb = oxDb::getDb();
00872 $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00873 }
00874
00880 public function getArticleRatingAverage()
00881 {
00882 return round( $this->oxarticles__oxrating->value, 1);
00883 }
00884
00890 public function getReviews()
00891 {
00892 $aIds = array($this->getId());
00893
00894 if ( $this->oxarticles__oxparentid->value ) {
00895 $aIds[] = $this->oxarticles__oxparentid->value;
00896 }
00897
00898
00899 if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00900 $aAdd = $this->_getVariantsIds();
00901 if (is_array($aAdd)) {
00902 $aIds = array_merge($aIds, $aAdd);
00903 }
00904 }
00905
00906 $oReview = oxNew('oxreview');
00907 $oRevs = $oReview->loadList('oxarticle', $aIds);
00908
00909
00910 if ( $oRevs->count() < 1 ) {
00911 return null;
00912 }
00913
00914 return $oRevs;
00915 }
00916
00922 public function getCrossSelling()
00923 {
00924 $oCrosslist = oxNew( "oxarticlelist");
00925 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00926 if ( $oCrosslist->count() ) {
00927 return $oCrosslist;
00928 }
00929 }
00930
00936 public function getAccessoires()
00937 {
00938 $myConfig = $this->getConfig();
00939
00940
00941 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00942 return;
00943 }
00944
00945 $oAcclist = oxNew( "oxarticlelist");
00946 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00947 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00948
00949 if ( $oAcclist->count()) {
00950 return $oAcclist;
00951 }
00952 }
00953
00959 public function getSimilarProducts()
00960 {
00961
00962 $myConfig = $this->getConfig();
00963 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
00964 return;
00965 }
00966
00967 $sArticleTable = $this->getViewName();
00968
00969 $sAttribs = '';
00970 $iCnt = 0;
00971 $this->_getAttribsString($sAttribs, $iCnt);
00972
00973 if ( !$sAttribs) {
00974 return null;
00975 }
00976
00977 $aList = $this->_getSimList($sAttribs, $iCnt);
00978
00979 if ( count( $aList ) ) {
00980 uasort( $aList, 'cmpart');
00981
00982 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
00983
00984 $oSimilarlist = oxNew( 'oxarticlelist' );
00985 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
00986 $oSimilarlist->selectString( $sSearch);
00987
00988 return $oSimilarlist;
00989 }
00990 }
00991
00997 public function getCustomerAlsoBoughtThisProducts()
00998 {
00999
01000 $myConfig = $this->getConfig();
01001 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01002 return;
01003 }
01004
01005
01006 $sQ = $this->_generateSearchStrForCustomerBought();
01007
01008 $oArticles = oxNew( 'oxarticlelist' );
01009 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01010 $oArticles->selectString( $sQ );
01011 if ( $oArticles->count() ) {
01012 return $oArticles;
01013 }
01014 }
01015
01022 public function loadAmountPriceInfo()
01023 {
01024 $myConfig = $this->getConfig();
01025 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice || !$this->hasAmountPrice() ) {
01026 return array();
01027 }
01028
01029 if ( $this->_oAmountPriceInfo === null ) {
01030 $this->_oAmountPriceInfo = array();
01031 if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01032 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01033 }
01034 }
01035 return $this->_oAmountPriceInfo;
01036 }
01037
01045 public function getSelectLists($sKeyPrefix = null)
01046 {
01047
01048
01049 $sKey = $this->getId();
01050 if ( isset( $sKeyPrefix ) ) {
01051 $sKey = $sKeyPrefix.'__'.$this->getId();
01052 }
01053
01054 if ( !isset( self::$_aSelList[$sKey] ) ) {
01055 $oDb = oxDb::getDb();
01056 $sSLViewName = getViewName( 'oxselectlist' );
01057
01058 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01059 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01060
01061
01062 $oLists = oxNew( 'oxlist' );
01063 $oLists->init( 'oxselectlist' );
01064 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01065
01066
01067 if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01068 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01069 }
01070
01071 $dVat = 0;
01072 if ( $this->getPrice() != null ) {
01073 $dVat = $this->getPrice()->getVat();
01074 }
01075
01076 $iCnt = 0;
01077 self::$_aSelList[$sKey] = array();
01078 foreach ( $oLists as $oSelectlist ) {
01079 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01080 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01081 $iCnt++;
01082 }
01083 }
01084 return self::$_aSelList[$sKey];
01085 }
01086
01094 protected function _hasAnyVariant( $blForceCoreTable = null )
01095 {
01096 $blHas = false;
01097 if ( ( $sId = $this->getId() ) ) {
01098 if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01099 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01100 } else {
01101 $sArticleTable = $this->getViewName( $blForceCoreTable );
01102 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01103 }
01104
01105 }
01106 return $blHas;
01107 }
01108
01114 public function hasMdVariants()
01115 {
01116 return $this->_blHasMdVariants;
01117 }
01118
01128 public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01129 {
01130
01131 $iLimit = (int) $iLimit;
01132 if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01133 $this->_aVariantSelections[$iLimit] = false;
01134 if ( $this->oxarticles__oxvarcount->value ) {
01135 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $this->getVariants(), $aFilterIds, $sActVariantId, $iLimit );
01136 }
01137 }
01138 return $this->_aVariantSelections[$iLimit];
01139 }
01140
01149 public function getSelections( $iLimit = null, $aFilter = null )
01150 {
01151 $sId = $this->getId() . ( (int) $iLimit );
01152 if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01153
01154 $oDb = oxDb::getDb();
01155 $sSLViewName = getViewName( 'oxselectlist' );
01156
01157 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01158 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01159
01160 if ( ( $iLimit = (int) $iLimit ) ) {
01161 $sQ .= " limit $iLimit ";
01162 }
01163
01164
01165 $dVat = 0;
01166 if ( ( $oPrice = $this->getPrice() ) != null ) {
01167 $dVat = $oPrice->getVat();
01168 }
01169
01170
01171 $oList = oxNew( 'oxlist' );
01172 $oList->init( 'oxselectlist' );
01173 $oList->getBaseObject()->setVat( $dVat );
01174 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01175
01176
01177 if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01178 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01179 }
01180
01181 self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01182 }
01183
01184 if ( self::$_aSelections[$sId] ) {
01185
01186 $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01187 if ( $aFilter ) {
01188 $iSelIdx = 0;
01189 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01190 if ( isset( $aFilter[$iSelIdx] ) ) {
01191 $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01192 }
01193 $iSelIdx++;
01194 }
01195 }
01196 }
01197
01198 return self::$_aSelections[$sId];
01199 }
01200
01210 protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01211 {
01212 $oVariants = array();
01213 if ( ( $sId = $this->getId() ) ) {
01214
01215 self::$_aLoadedParents[$sId] = $this;
01216
01217 $myConfig = $this->getConfig();
01218
01219 if ( !$this->_blLoadVariants ||
01220 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01221 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01222 return $oVariants;
01223 }
01224
01225
01226 $sCacheKey = $blSimple ? "simple" : "full";
01227 if ( $blRemoveNotOrderables ) {
01228 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01229 return $this->_aVariants[$sCacheKey];
01230 } else {
01231 $this->_aVariants[$sCacheKey] = & $oVariants;
01232 }
01233 } elseif ( !$blRemoveNotOrderables ) {
01234 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01235 return $this->_aVariantsWithNotOrderables[$sCacheKey];
01236 } else {
01237 $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01238 }
01239 }
01240
01241 if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01242
01243
01244 if ( $blSimple ) {
01245 $oVariants = oxNew( 'oxsimplevariantlist' );
01246 $oVariants->setParent( $this );
01247 } else {
01248
01249 $oVariants = oxNew( 'oxarticlelist' );
01250 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01251 }
01252
01253 startProfile("selectVariants");
01254 $blUseCoreTable = (bool) $blForceCoreTable;
01255 $oBaseObject = $oVariants->getBaseObject();
01256 $oBaseObject->setLanguage( $this->getLanguage() );
01257
01258
01259 $sArticleTable = $this->getViewName( $blUseCoreTable );
01260
01261 $sSelect = "select ".$oBaseObject->getSelectFields( $blUseCoreTable )." from $sArticleTable where " .
01262 $this->getActiveCheckQuery( $blUseCoreTable ) .
01263 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01264 " order by $sArticleTable.oxsort";
01265
01266
01267 $oVariants->selectString( $sSelect );
01268
01269
01270 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01271 $oMdVariants = oxNew( "oxVariantHandler" );
01272 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01273 }
01274 stopProfile("selectVariants");
01275 }
01276
01277
01278 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01279 $this->_blNotBuyableParent = true;
01280 }
01281
01282
01283 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01284 $this->_blNotBuyable = true;
01285 }
01286 }
01287 return $oVariants;
01288 }
01289
01298 public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01299 {
01300 return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01301 }
01302
01311 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01312 {
01313 return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01314 }
01315
01321 public function getSimpleVariants()
01322 {
01323 if ( $this->oxarticles__oxvarcount->value) {
01324 return $this->getVariants();
01325 }
01326 }
01327
01336 public function getAdminVariants( $sLanguage = null )
01337 {
01338 $oVariants = oxNew( 'oxarticlelist');
01339 if ( ( $sId = $this->getId() ) ) {
01340
01341 $oBaseObj = $oVariants->getBaseObject();
01342
01343 if ( is_null( $sLanguage ) ) {
01344 $oBaseObj->setLanguage( oxLang::getInstance()->getBaseLanguage() );
01345 } else {
01346 $oBaseObj->setLanguage( $sLanguage );
01347 }
01348
01349 $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01350 $oVariants->selectString( $sSql );
01351
01352
01353 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01354
01355 $this->_blNotBuyableParent = true;
01356 }
01357 }
01358
01359 return $oVariants;
01360 }
01361
01369 public function getCategory()
01370 {
01371 $oCategory = oxNew( 'oxcategory' );
01372 $oCategory->setLanguage( $this->getLanguage() );
01373
01374
01375 $sOXID = $this->getId();
01376 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01377 $sOXID = $this->oxarticles__oxparentid->value;
01378 }
01379
01380 if ( $sOXID ) {
01381
01382 if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01383 startPRofile( 'getCategory' );
01384 $oStr = getStr();
01385 $sWhere = $oCategory->getSqlActiveSnippet();
01386 $sSelect = $this->_generateSearchStr( $sOXID );
01387 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01388
01389
01390 if ( !$oCategory->assignRecord( $sSelect ) ) {
01391
01392 $sSelect = $this->_generateSearchStr( $sOXID, true );
01393 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01394
01395
01396 if ( !$oCategory->assignRecord( $sSelect ) ) {
01397 $oCategory = null;
01398 }
01399 }
01400
01401 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01402 stopPRofile( 'getCategory' );
01403 } else {
01404
01405 $oCategory = $this->_aCategoryCache[ $sOXID ];
01406 }
01407 }
01408
01409 return $oCategory;
01410 }
01411
01420 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01421 {
01422 $myConfig = $this->getConfig();
01423 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01424 return self::$_aArticleCats[$this->getId()];
01425 }
01426
01427
01428 $sOXID = $this->getId();
01429 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01430 $sOXID = $this->oxarticles__oxparentid->value;
01431 }
01432
01433
01434 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01435 $oDB = oxDb::getDb(true);
01436 $rs = $oDB->execute( $sSql );
01437
01438
01439 $aRet = array();
01440
01441 if ($rs != false && $rs->recordCount() > 0) {
01442 while (!$rs->EOF) {
01443 $aRet[] = $rs->fields['oxcatnid'];
01444 $rs->moveNext();
01445 }
01446 }
01447
01448
01449 $sSql = $this->getSqlForPriceCategories();
01450
01451 $oDB = oxDb::getDb( true );
01452 $rs = $oDB->execute( $sSql );
01453
01454 if ($rs != false && $rs->recordCount() > 0) {
01455 while (!$rs->EOF) {
01456
01457 if ( is_array( $rs->fields ) ) {
01458 $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01459 }
01460
01461
01462 if ( !$aRet[$rs->fields['oxid']] ) {
01463 $aRet[] = $rs->fields['oxid'];
01464 }
01465 $rs->moveNext();
01466 }
01467 }
01468
01469 return self::$_aArticleCats[$this->getId()] = $aRet;
01470 }
01471
01480 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01481 {
01482 $sO2CView = $this->_getObjectViewName('oxobject2category');
01483 $sCatView = $this->_getObjectViewName('oxcategories');
01484 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01485 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01486 if ( $blActCats ) {
01487 $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 ";
01488 }
01489 $sSelect .= 'order by oxobject2category.oxtime ';
01490 return $sSelect;
01491 }
01492
01502 public function getVendor( $blShopCheck = true )
01503 {
01504 if ( ( $sVendorId = $this->getVendorId() ) ) {
01505 $oVendor = oxNew( 'oxvendor' );
01506 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01507 $oVendor = oxNew( 'oxi18n' );
01508 $oVendor->init('oxvendor');
01509 $oVendor->setReadOnly( true );
01510 $sVendorId = $this->oxarticles__oxvendorid->value;
01511 }
01512 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01513 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01514 $oVendor->setReadOnly( true );
01515 }
01516 return $oVendor;
01517 }
01518 return null;
01519 }
01520
01528 public function getVendorId( $blForceReload = false )
01529 {
01530 $sVendorId = false;
01531 if ( $this->oxarticles__oxvendorid->value ) {
01532 $sVendorId = $this->oxarticles__oxvendorid->value;
01533
01534 }
01535 return $sVendorId;
01536 }
01537
01545 public function getManufacturerId( $blForceReload = false )
01546 {
01547 $sManufacturerId = false;
01548 if ( $this->oxarticles__oxmanufacturerid->value ) {
01549
01550 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01551
01552 }
01553 return $sManufacturerId;
01554 }
01555
01565 public function getManufacturer( $blShopCheck = true )
01566 {
01567 $oManufacturer = oxNew( 'oxmanufacturer' );;
01568 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01569 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01570 $oManufacturer->setReadOnly( true );
01571 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01572 }
01573
01574 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01575 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01576 $oManufacturer->setReadOnly( true );
01577 }
01578 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01579 } else {
01580 $oManufacturer = null;
01581 }
01582
01583 return $oManufacturer;
01584 }
01585
01593 public function inCategory( $sCatNid)
01594 {
01595 return in_array( $sCatNid, $this->getCategoryIds());
01596 }
01597
01606 public function isAssignedToCategory( $sCatId )
01607 {
01608
01609 $sOXID = $this->getId();
01610 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01611 $sOXID = $this->oxarticles__oxparentid->value;
01612 }
01613
01614 $oDB = oxDb::getDb();
01615 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01616 $sOXID = $oDB->getOne( $sSelect);
01617
01618 if ( isset( $sOXID) && $sOXID) {
01619 return true;
01620 }
01621
01622
01623 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01624 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01625 if ( $dPriceFromTo > 0) {
01626 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01627 $sOXID = $oDB->getOne( $sSelect);
01628
01629 if ( isset( $sOXID) && $sOXID) {
01630 return true;
01631 }
01632 }
01633 }
01634 return false;
01635 }
01636
01642 public function getTPrice()
01643 {
01644 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01645 return;
01646 }
01647
01648 if ( $this->_oTPrice !== null ) {
01649 return $this->_oTPrice;
01650 }
01651
01652 $this->_oTPrice = oxNew( 'oxPrice' );
01653 $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01654
01655 $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01656 $this->_applyCurrency( $this->_oTPrice );
01657
01658 return $this->_oTPrice;
01659 }
01660
01666 public function skipDiscounts()
01667 {
01668
01669 if ( $this->_blSkipDiscounts !== null ) {
01670 return $this->_blSkipDiscounts;
01671 }
01672
01673 if ( $this->oxarticles__oxskipdiscounts->value ) {
01674 return true;
01675 }
01676
01677
01678 $this->_blSkipDiscounts = false;
01679 if ( oxDiscountList::getInstance()->hasSkipDiscountCategories() ) {
01680
01681 $oDb = oxDb::getDb();
01682 $sO2CView = getViewName( 'oxobject2category', $this->getLanguage() );
01683 $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01684 $sSelect = "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01685 where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01686 $this->_blSkipDiscounts = ( $oDb->getOne($sSelect) == 1 );
01687 }
01688 return $this->_blSkipDiscounts;
01689 }
01690
01698 public function setPrice(oxPrice $oPrice)
01699 {
01700 $this->_oPrice = $oPrice;
01701 }
01702
01711 public function getBasePrice( $dAmount = 1 )
01712 {
01713
01714
01715
01716
01717 $myConfig = $this->getConfig();
01718 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01719 return;
01720
01721
01722 $dPrice = $this->_getAmountPrice( $dAmount );
01723
01724
01725 return $dPrice;
01726 }
01727
01735 public function getPrice( $dAmount = 1 )
01736 {
01737 $myConfig = $this->getConfig();
01738
01739 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01740 return;
01741 }
01742
01743
01744 if ( $dAmount != 1 || $this->_oPrice === null ) {
01745 $oPrice = oxNew( 'oxPrice' );
01746
01747
01748 $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01749
01750
01751 if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01752 return $this->_oPrice = $oPrice;
01753 }
01754
01755 $this->_calculatePrice( $oPrice );
01756 if ( $dAmount != 1 ) {
01757 return $oPrice;
01758 }
01759
01760 $this->_oPrice = $oPrice;
01761 }
01762 return $this->_oPrice;
01763 }
01764
01773 protected function _calculatePrice( $oPrice, $dVat = null )
01774 {
01775
01776 if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01777 $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01778 }
01779
01780
01781 $this->_applyCurrency( $oPrice );
01782
01783 if ( !$this->skipDiscounts() ) {
01784 $oDiscountList = oxDiscountList::getInstance();
01785 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
01786 }
01787
01788 return $oPrice;
01789 }
01790
01798 public function setArticleUser($oUser)
01799 {
01800 $this->_oUser = $oUser;
01801 }
01802
01808 public function getArticleUser()
01809 {
01810 if ($this->_oUser) {
01811 return $this->_oUser;
01812 }
01813 return $this->getUser();
01814 }
01815
01825 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01826 {
01827 $oUser = $oBasket->getBasketUser();
01828 $this->setArticleUser( $oUser );
01829
01830 $oBasketPrice = oxNew( 'oxPrice' );
01831
01832
01833 $dBasePrice = $this->getBasePrice( $dAmount );
01834
01835
01836 $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01837
01838
01839 $oBasketPrice->setPrice( $dBasePrice );
01840
01841 $dVat = oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket );
01842 $this->_calculatePrice( $oBasketPrice, $dVat );
01843
01844
01845 return $oBasketPrice;
01846 }
01847
01860 public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01861 {
01862 $oDiscountList = oxDiscountList::getInstance();
01863 return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01864 }
01865
01874 public function delete( $sOXID = null )
01875 {
01876 if ( !$sOXID ) {
01877 $sOXID = $this->getId();
01878 }
01879 if ( !$sOXID ) {
01880 return false;
01881 }
01882
01883
01884
01885 $this->_deleteVariantRecords( $sOXID );
01886 $this->load( $sOXID );
01887 $this->_deletePics();
01888 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01889
01890
01891 parent::delete( $sOXID );
01892
01893 $rs = $this->_deleteRecords( $sOXID );
01894
01895 oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01896
01897 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01898
01899 return $rs->EOF;
01900 }
01901
01910 public function reduceStock($dAmount, $blAllowNegativeStock = false)
01911 {
01912 $this->beforeUpdate();
01913
01914 $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01915 if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01916 $dAmount += $iStockCount;
01917 $iStockCount = 0;
01918 }
01919 $this->oxarticles__oxstock = new oxField($iStockCount);
01920
01921 $oDb = oxDb::getDb();
01922 $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01923 $this->onChange( ACTION_UPDATE_STOCK );
01924 return $dAmount;
01925 }
01926
01935 public function updateSoldAmount( $dAmount = 0 )
01936 {
01937 if ( !$dAmount ) {
01938 return;
01939 }
01940
01941 $this->beforeUpdate();
01942
01943
01944 if ( !$this->oxarticles__oxparentid->value ) {
01945
01946 $dAmount = (double) $dAmount;
01947 $oDb = oxDb::getDb();
01948 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01949 } elseif ( $this->oxarticles__oxparentid->value) {
01950
01951 $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01952 $oUpdateArticle->updateSoldAmount( $dAmount );
01953 }
01954
01955 $this->onChange( ACTION_UPDATE );
01956
01957 return $rs;
01958 }
01959
01965 public function disableReminder()
01966 {
01967 $oDB = oxDb::getDb(true);
01968 return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01969 }
01970
01978 public function save()
01979 {
01980
01981 $this->oxarticles__oxthumb = new oxField( basename( $this->oxarticles__oxthumb->value ), oxField::T_RAW );
01982 $this->oxarticles__oxicon = new oxField( basename( $this->oxarticles__oxicon->value ), oxField::T_RAW );
01983 $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
01984 for ( $i = 1; $i <= $iPicCount; $i++ ) {
01985 $sFieldName = 'oxarticles__oxpic' . $i;
01986 if ( isset( $this->$sFieldName ) ) {
01987 $this->_setFieldData( $sFieldName, basename( $this->$sFieldName->value ), oxField::T_RAW );
01988 }
01989 }
01990
01991
01992 if ( ( $blRet = parent::save() ) ) {
01993
01994 $this->_saveArtLongDesc();
01995 }
01996
01997 return $blRet;
01998 }
01999
02000
02007 public function getPictureGallery()
02008 {
02009 $myConfig = $this->getConfig();
02010
02011
02012 $blMorePic = false;
02013 $aArtPics = array();
02014 $aArtIcons = array();
02015 $iActPicId = 1;
02016 $sActPic = $this->getPictureUrl( $iActPicId );
02017
02018 if ( oxConfig::getParameter( 'actpicid' ) ) {
02019 $iActPicId = oxConfig::getParameter('actpicid');
02020 }
02021
02022 $oStr = getStr();
02023 $iCntr = 0;
02024 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02025 $blCheckActivePicId = true;
02026
02027 for ( $i = 1; $i <= $iPicCount; $i++) {
02028 $sPicVal = $this->getPictureUrl( $i );
02029 $sIcoVal = $this->getIconUrl( $i );
02030 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02031 !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02032 if ($iCntr) {
02033 $blMorePic = true;
02034 }
02035 $aArtIcons[$i]= $sIcoVal;
02036 $aArtPics[$i]= $sPicVal;
02037 $iCntr++;
02038
02039 if ($iActPicId == $i) {
02040 $sActPic = $sPicVal;
02041 $blCheckActivePicId = false;
02042 }
02043
02044 } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02045
02046
02047 $iActPicId++;
02048 }
02049 }
02050
02051 $blZoomPic = false;
02052 $aZoomPics = array();
02053 $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02054
02055 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02056 $sVal = $this->getZoomPictureUrl($j);
02057
02058 if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02059 $blZoomPic = true;
02060 $aZoomPics[$c]['id'] = $c;
02061 $aZoomPics[$c]['file'] = $sVal;
02062
02063 if (!$sVal) {
02064 $aZoomPics[$c]['file'] = "nopic.jpg";
02065 }
02066 $c++;
02067 }
02068 }
02069
02070 $aPicGallery = array('ActPicID' => $iActPicId,
02071 'ActPic' => $sActPic,
02072 'MorePics' => $blMorePic,
02073 'Pics' => $aArtPics,
02074 'Icons' => $aArtIcons,
02075 'ZoomPic' => $blZoomPic,
02076 'ZoomPics' => $aZoomPics);
02077
02078 return $aPicGallery;
02079 }
02080
02094 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02095 {
02096 $myConfig = $this->getConfig();
02097
02098 if (!isset($sOXID)) {
02099 if ( $this->getId()) {
02100 $sOXID = $this->getId();
02101 }
02102 if (!isset ($sOXID)) {
02103 $sOXID = $this->oxarticles__oxid->value;
02104 }
02105 if ($this->oxarticles__oxparentid->value) {
02106 $sParentID = $this->oxarticles__oxparentid->value;
02107 }
02108 }
02109 if (!isset($sOXID)) {
02110 return;
02111 }
02112
02113
02114 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02115
02116
02117 if (!isset($sParentID)) {
02118 $oDb = oxDb::getDb();
02119 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02120 $sParentID = $oDb->getOne($sQ);
02121 }
02122
02123 if ($sParentID) {
02124 $this->_onChangeUpdateStock($sParentID);
02125 }
02126 }
02127
02128
02129 if ($sParentID) {
02130 $this->_onChangeUpdateVarCount($sParentID);
02131 }
02132
02133 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02134 $this->_onChangeUpdateMinVarPrice( $sId );
02135
02136
02137
02138 if ( $sAction === ACTION_UPDATE_STOCK ) {
02139 $this->_onChangeStockResetCount( $sOXID );
02140 }
02141
02142 }
02143
02150 public function getCustomVAT()
02151 {
02152 if ( isset($this->oxarticles__oxvat->value) ) {
02153 return $this->oxarticles__oxvat->value;
02154 }
02155 }
02156
02165 public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02166 {
02167 $myConfig = $this->getConfig();
02168 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02169 return true;
02170 }
02171
02172 $oDb = oxDb::getDb(true);
02173
02174 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.oxDb::getDb(true)->quote( $this->getId() );
02175 $rs = oxDb::getDb(true)->execute( $sQ );
02176
02177 $iOnStock = 0;
02178 $iStockFlag = 0;
02179 if ( $rs !== false && $rs->recordCount() > 0 ) {
02180 $iOnStock = $rs->fields['oxstock'] - $dArtStockAmount;
02181 $iStockFlag = $rs->fields['oxstockflag'];
02182
02183
02184 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02185 return true;
02186 }
02187 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02188 $iOnStock = floor( $iOnStock );
02189 }
02190 }
02191 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02192 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02193 }
02194 if ( $iOnStock >= $dAmount ) {
02195 return true;
02196 } else {
02197 if ( $iOnStock > 0 ) {
02198 return $iOnStock;
02199 } else {
02200 $oEx = oxNew( 'oxArticleInputException' );
02201 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02202 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02203 return false;
02204 }
02205 }
02206 }
02207
02208
02216 public function getArticleLongDesc( $sOxid = null )
02217 {
02218 if ( $this->_oLongDesc === null ) {
02219
02220 $this->_oLongDesc = new oxField();
02221
02222
02223
02224 $sOxid = $sOxid === null ? $this->getId() : $sOxid;
02225 $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02226
02227 $sDbValue = oxDb::getDb()->getOne( "select oxlongdesc from {$sViewName} where oxid = ?", array( $sOxid ) );
02228 if ( $sDbValue !== false ) {
02229 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02230 } elseif ( $this->oxarticles__oxparentid->value ) {
02231 $this->_oLongDesc->setValue( $this->getParentArticle()->getArticleLongDesc()->getRawValue(), oxField::T_RAW );
02232 }
02233 }
02234 return $this->_oLongDesc;
02235 }
02236
02246 protected function _setLongDesc( $sDbValue )
02247 {
02248 $this->setArticleLongDesc( $sDbValue );
02249 }
02250
02257 public function getLongDesc()
02258 {
02259 return oxUtilsView::getInstance()->parseThroughSmarty( $this->getArticleLongDesc()->getRawValue(), $this->getId().$this->getLanguage() );
02260 }
02261
02270 public function setArticleLongDesc( $sDesc, $sOrigValue = null )
02271 {
02272
02273
02274 $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02275
02276
02277 if ( $sOrigValue ) {
02278 $this->_oLongDesc->orignalValue = $sOrigValue;
02279 }
02280 }
02281
02287 public function getAttributes()
02288 {
02289 if ( $this->_oAttributeList === null ) {
02290 $this->_oAttributeList = oxNew( 'oxattributelist' );
02291 $this->_oAttributeList->loadAttributes( $this->getId() );
02292 }
02293
02294 return $this->_oAttributeList;
02295 }
02296
02305 public function appendLink( $sAddParams, $iLang = null )
02306 {
02307 if ( $sAddParams ) {
02308 if ( $iLang === null ) {
02309 $iLang = $this->getLanguage();
02310 }
02311
02312 $this->_aSeoAddParams[$iLang] = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&" : "";
02313 $this->_aSeoAddParams[$iLang] .= $sAddParams;
02314 }
02315 }
02316
02325 public function getBaseSeoLink( $iLang, $blMain = false )
02326 {
02327 $oEncoder = oxSeoEncoderArticle::getInstance();
02328 if ( !$blMain ) {
02329 return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02330 }
02331 return $oEncoder->getArticleMainUrl( $this, $iLang );
02332 }
02333
02342 public function getLink( $iLang = null, $blMain = false )
02343 {
02344 if ( !oxUtils::getInstance()->seoIsActive() ) {
02345 return $this->getStdLink( $iLang );
02346 }
02347
02348 if ( $iLang === null ) {
02349 $iLang = $this->getLanguage();
02350 }
02351
02352 $iLinkType = $this->getLinkType();
02353 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02354 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02355 }
02356
02357 $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02358 if ( isset($this->_aSeoAddParams[$iLang])) {
02359 $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&' ).$this->_aSeoAddParams[$iLang];
02360 }
02361
02362 return $sUrl;
02363 }
02364
02373 public function getMainLink( $iLang = null )
02374 {
02375 return $this->getLink( $iLang, true );
02376 }
02377
02385 public function setLinkType( $iType )
02386 {
02387
02388 $this->_sDetailLink = null;
02389
02390
02391 $this->_iLinkType = (int) $iType;
02392 }
02393
02399 public function getLinkType()
02400 {
02401 return $this->_iLinkType;
02402 }
02403
02412 public function appendStdLink( $sAddParams, $iLang = null )
02413 {
02414 if ( $sAddParams ) {
02415 if ( $iLang === null ) {
02416 $iLang = $this->getLanguage();
02417 }
02418
02419 $this->_aStdAddParams[$iLang] = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&" : "";
02420 $this->_aStdAddParams[$iLang] .= $sAddParams;
02421 }
02422 }
02423
02433 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02434 {
02435 $sUrl = '';
02436 if ( $blFull ) {
02437
02438 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02439 }
02440
02441 $sUrl .= "index.php?cl=details" . ( $blAddId ? "&anid=".$this->getId() : "" );
02442 return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&". $this->_aStdAddParams[$iLang] : "" );
02443 }
02444
02453 public function getStdLink( $iLang = null, $aParams = array() )
02454 {
02455 if ( $iLang === null ) {
02456 $iLang = $this->getLanguage();
02457 }
02458
02459 if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02460 $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02461 }
02462
02463 return oxUtilsUrl::getInstance()->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02464 }
02465
02473 public function getStdTagLink( $sTag )
02474 {
02475 $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02476 return $sStdTagLink . "cl=details&anid=".$this->getId()."&listtype=tag&searchtag=".rawurlencode( $sTag );
02477 }
02478
02484 public function getTags()
02485 {
02486 $oDb = oxDb::getDb();
02487 $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02488 $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02489 $oTagCloud = oxNew('oxtagcloud');
02490 return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02491 }
02492
02500 public function saveTags($sTags)
02501 {
02502
02503 if ( !$this->allowDerivedUpdate() ) {
02504 return false;
02505 }
02506
02507
02508 $oTagCloud = oxNew( 'oxtagcloud' );
02509 $oTagCloud->resetTagCache();
02510 $sTags = mysql_real_escape_string( $oTagCloud->prepareTags( $sTags ) );
02511 $oDb = oxDb::getDb();
02512
02513 $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02514 $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02515 $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02516 on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02517 return $oDb->execute( $sQ );
02518 }
02519
02527 public function addTag($sTag)
02528 {
02529 $oDb = oxDb::getDb();
02530
02531 $oTagCloud = oxNew('oxtagcloud');
02532 $oTagCloud->resetTagCache();
02533 $sTag = $oTagCloud->prepareTags($sTag);
02534 $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02535
02536 $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02537 $sLangSuffix = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02538 if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02539 $sTailTag = $sTagSeparator . $sTag;
02540 } else {
02541 $sTailTag = $sTag;
02542 }
02543
02544 $sTag = mysql_real_escape_string($sTag);
02545 $sTailTag = mysql_real_escape_string($sTailTag);
02546
02547 $sTag = mysql_real_escape_string($sTag);
02548 $sTailTag = mysql_real_escape_string($sTailTag);
02549
02550 $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02551 ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02552
02553 return $oDb->execute( $sQ );
02554 }
02555
02561 public function getMediaUrls()
02562 {
02563 if ( $this->_aMediaUrls === null ) {
02564 $this->_aMediaUrls = oxNew("oxlist");
02565 $this->_aMediaUrls->init("oxmediaurl");
02566 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02567
02568 $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02569 $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02570 $this->_aMediaUrls->selectString($sQ);
02571 }
02572 return $this->_aMediaUrls;
02573 }
02574
02580 public function getDynImageDir()
02581 {
02582 return $this->_sDynImageDir;
02583 }
02584
02590 public function getDispSelList()
02591 {
02592 if ($this->_aDispSelList === null) {
02593 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02594 $this->_aDispSelList = $this->getSelectLists();
02595 }
02596 }
02597 return $this->_aDispSelList;
02598 }
02599
02605 public function getMoreDetailLink()
02606 {
02607 if ( $this->_sMoreDetailLink == null ) {
02608
02609
02610 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02611
02612
02613 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02614 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02615 }
02616 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02617 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02618 }
02619
02620 return $this->_sMoreDetailLink;
02621 }
02622
02628 public function getToBasketLink()
02629 {
02630 if ( $this->_sToBasketLink == null ) {
02631 $myConfig = $this->getConfig();
02632
02633 if ( oxUtils::getInstance()->isSearchEngine() ) {
02634 $this->_sToBasketLink = $this->getLink();
02635 } else {
02636
02637 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02638
02639
02640 $sActClass = oxConfig::getParameter( 'cl' );
02641 if ( $sActClass == 'thankyou') {
02642 $sActClass = 'basket';
02643 }
02644 $this->_sToBasketLink .= 'cl='.$sActClass;
02645
02646
02647 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02648 $this->_sToBasketLink .= '&cnid='.$sActCat;
02649 }
02650
02651 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02652
02653 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02654 $this->_sToBasketLink .= '&tpl='.$sTpl;
02655 }
02656 }
02657 }
02658
02659 return $this->_sToBasketLink;
02660 }
02661
02667 public function getStockStatus()
02668 {
02669 return $this->_iStockStatus;
02670 }
02671
02677 public function getDeliveryDate()
02678 {
02679 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02680 return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02681 }
02682 return false;
02683 }
02684
02690 public function getFTPrice()
02691 {
02692 if ( $oPrice = $this->getTPrice() ) {
02693 if ( $oPrice->getBruttoPrice() ) {
02694 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02695 }
02696 }
02697 }
02698
02704 public function getFPrice()
02705 {
02706 if ( $oPrice = $this->getPrice() ) {
02707 return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02708 }
02709 }
02710
02716 public function getFNetPrice()
02717 {
02718 if ( $oPrice = $this->getPrice() ) {
02719 return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
02720 }
02721 }
02722
02728 public function getPricePerUnit()
02729 {
02730 return $this->_fPricePerUnit;
02731 }
02732
02738 public function isParentNotBuyable()
02739 {
02740 return $this->_blNotBuyableParent;
02741 }
02742
02748 public function isNotBuyable()
02749 {
02750 return $this->_blNotBuyable;
02751 }
02752
02760 public function setBuyableState( $blBuyable = false )
02761 {
02762 $this->_blNotBuyable = !$blBuyable;
02763 }
02764
02773 public function getVariantList()
02774 {
02775 return $this->getVariants();
02776 }
02777
02785 public function setSelectlist( $aSelList )
02786 {
02787 $this->_aDispSelList = $aSelList;
02788 }
02789
02797 public function getPictureUrl( $iIndex = 1 )
02798 {
02799 if ( $iIndex ) {
02800 $sImgName = false;
02801 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02802 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02803 }
02804
02805 $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02806 return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02807 }
02808 }
02809
02818 public function getIconUrl( $iIndex = 0 )
02819 {
02820 $sImgName = false;
02821 $sDirname = "product/1/";
02822 if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02823 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02824 $sDirname = "product/{$iIndex}/";
02825 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02826 $sImgName = basename( $this->oxarticles__oxicon->value );
02827 $sDirname = "product/icon/";
02828 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02829 $sImgName = basename( $this->oxarticles__oxpic1->value );
02830 }
02831
02832 $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02833 return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02834 }
02835
02841 public function getThumbnailUrl()
02842 {
02843 $sImgName = false;
02844 $sDirname = "product/1/";
02845 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02846 $sImgName = basename( $this->oxarticles__oxthumb->value );
02847 $sDirname = "product/thumb/";
02848 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02849 $sImgName = basename( $this->oxarticles__oxpic1->value );
02850 }
02851
02852 $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02853 return oxPictureHandler::getInstance()->getProductPicUrl( $sDirname, $sImgName, $sSize, 0 );
02854 }
02855
02863 public function getZoomPictureUrl( $iIndex = '' )
02864 {
02865 $iIndex = (int) $iIndex;
02866 if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02867 $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02868 $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02869 return oxPictureHandler::getInstance()->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02870 }
02871 }
02872
02878 public function getFileUrl()
02879 {
02880 return $this->getConfig()->getPictureUrl( 'media/' );
02881 }
02882
02888 public function getPriceFromPrefix()
02889 {
02890 $sPricePrefix = '';
02891 if ( $this->_blIsRangePrice) {
02892 $sPricePrefix = oxLang::getInstance()->translateString('priceFrom').' ';
02893 }
02894
02895 return $sPricePrefix;
02896 }
02897
02903 protected function _saveArtLongDesc()
02904 {
02905 $myConfig = $this->getConfig();
02906 $sShopId = $myConfig->getShopID();
02907 if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02908 return;
02909 }
02910
02911 if ($this->_blEmployMultilanguage) {
02912 $sValue = $this->getArticleLongDesc()->getRawValue();
02913 if ( $sValue !== null ) {
02914 $oArtExt = oxNew('oxI18n');
02915 $oArtExt->init('oxartextends');
02916 $oArtExt->setLanguage((int) $this->getLanguage());
02917 if (!$oArtExt->load($this->getId())) {
02918 $oArtExt->setId($this->getId());
02919 }
02920 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02921 $oArtExt->save();
02922 }
02923 } else {
02924 $oArtExt = oxNew('oxI18n');
02925 $oArtExt->setEnableMultilang(false);
02926 $oArtExt->init('oxartextends');
02927 $aObjFields = $oArtExt->_getAllFields(true);
02928 if (!$oArtExt->load($this->getId())) {
02929 $oArtExt->setId($this->getId());
02930 }
02931
02932 foreach ($aObjFields as $sKey => $sValue ) {
02933 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02934 $sField = $this->_getFieldLongName($sKey);
02935
02936 if (isset($this->$sField)) {
02937 $sLongDesc = null;
02938 if ($this->$sField instanceof oxField) {
02939 $sLongDesc = $this->$sField->getRawValue();
02940 } elseif (is_object($this->$sField)) {
02941 $sLongDesc = $this->$sField->value;
02942 }
02943 if (isset($sLongDesc)) {
02944 $sAEField = $oArtExt->_getFieldLongName($sKey);
02945 $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
02946 }
02947 }
02948 }
02949 }
02950 $oArtExt->save();
02951 }
02952 }
02953
02959 protected function _skipSaveFields()
02960 {
02961 $myConfig = $this->getConfig();
02962
02963 $this->_aSkipSaveFields = array();
02964
02965 $this->_aSkipSaveFields[] = 'oxtimestamp';
02966
02967 $this->_aSkipSaveFields[] = 'oxinsert';
02968
02969 if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02970 $this->_aSkipSaveFields[] = 'oxparentid';
02971 }
02972
02973 }
02974
02984 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02985 {
02986 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02987
02988 if ( array_key_exists ($sKey, $aDiscounts) ) {
02989 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02990 } else {
02991 $aDiscounts[$sKey] = $oDiscount;
02992 }
02993 }
02994 return $aDiscounts;
02995 }
02996
03002 protected function _getGroupPrice()
03003 {
03004 $dPrice = $this->oxarticles__oxprice->value;
03005
03006 $oUser = $this->getArticleUser();
03007 if ( $oUser ) {
03008 if ( $oUser->inGroup( 'oxidpricea' ) ) {
03009 $dPrice = $this->oxarticles__oxpricea->value;
03010 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03011 $dPrice = $this->oxarticles__oxpriceb->value;
03012 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03013 $dPrice = $this->oxarticles__oxpricec->value;
03014 }
03015 }
03016
03017
03018 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03019 $dPrice = $this->oxarticles__oxprice->value;
03020 }
03021
03022 return $dPrice;
03023 }
03024
03033 protected function _getAmountPrice($dAmount = 1)
03034 {
03035 $myConfig = $this->getConfig();
03036
03037 startProfile( "_getAmountPrice" );
03038
03039 $dPrice = $this->_getGroupPrice();
03040 $oAmtPrices = $this->_getAmountPriceList();
03041 foreach ($oAmtPrices as $oAmPrice) {
03042 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03043 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03044 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03045 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03046 }
03047 }
03048
03049 stopProfile( "_getAmountPrice" );
03050 return $dPrice;
03051 }
03052
03061 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03062 {
03063 $myConfig = $this->getConfig();
03064
03065 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03066
03067 $aSelLists = $this->getSelectLists();
03068
03069 foreach ( $aSelLists as $key => $aSel) {
03070 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03071 $oSel = $aSel[$aChosenList[$key]];
03072 if ( $oSel->priceUnit =='abs' ) {
03073 $dPrice += $oSel->price;
03074 } elseif ( $oSel->priceUnit =='%' ) {
03075 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03076 }
03077 }
03078 }
03079 }
03080 return $dPrice;
03081 }
03082
03083
03091 protected function _fillAmountPriceList($oAmPriceList)
03092 {
03093 $myConfig = $this->getConfig();
03094 $myUtils = oxUtils::getInstance();
03095
03096
03097 $oCur = $myConfig->getActShopCurrencyObject();
03098
03099 $oUser = $this->getArticleUser();
03100
03101 $oDiscountList = oxDiscountList::getInstance();
03102 $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03103
03104 $oLowestPrice = null;
03105
03106 $dBasePrice = $this->_getGroupPrice();
03107 $oLang = oxLang::getInstance();
03108
03109 $dArticleVat = null;
03110 if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03111 $dArticleVat = $this->getArticleVat();
03112 }
03113
03114
03115 foreach ($oAmPriceList as $sId => $oItem) {
03116 $oItemPrice = oxNew( 'oxprice' );
03117 if ( $oItem->oxprice2article__oxaddabs->value) {
03118 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03119 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03120 $this->_applyCurrency( $oItemPrice, $oCur );
03121 } else {
03122 $oItemPrice->setPrice( $dBasePrice );
03123 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03124 }
03125
03126 if (isset($dArticleVat)) {
03127 $this->_applyVAT($oItemPrice, $dArticleVat);
03128 }
03129
03130 if (!$oLowestPrice) {
03131 $oLowestPrice = $oItemPrice;
03132 } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03133 $oLowestPrice = $oItemPrice;
03134 }
03135
03136 $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03137 $oAmPriceList[$sId]->fnetprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03138 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03139 }
03140
03141 $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03142 return $oAmPriceList;
03143 }
03144
03150 protected function _getVariantsIds()
03151 {
03152 $aSelect = array();
03153 if ( ( $sId = $this->getId() ) ) {
03154 $oDb = oxDb::getDb(true);
03155 $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03156 $this->getSqlActiveSnippet( true );
03157
03158 $oRs = $oDb->execute( $sQ );
03159 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03160 while (!$oRs->EOF) {
03161 $aSelect[] = reset( $oRs->fields );
03162 $oRs->moveNext();
03163 }
03164 }
03165 }
03166 return $aSelect;
03167 }
03168
03174 public function getArticleVat()
03175 {
03176 if (!isset($this->_dArticleVat)) {
03177 $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03178 }
03179 return $this->_dArticleVat;
03180 }
03181
03190 protected function _applyVAT( oxPrice $oPrice, $dVat )
03191 {
03192 startProfile(__FUNCTION__);
03193 $oPrice->setVAT( $dVat );
03194 if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03195 $oPrice->setUserVat( $dVat );
03196 }
03197 stopProfile(__FUNCTION__);
03198 }
03199
03207 public function applyVats( oxPrice $oPrice )
03208 {
03209 $this->_applyVAT($oPrice, $this->getArticleVat() );
03210 }
03211
03222 protected function _applyDiscounts( $oPrice, $aDiscounts )
03223 {
03224 $oDiscountList = oxDiscountList::getInstance();
03225 $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03226 }
03227
03235 public function applyDiscountsForVariant( $oPrice )
03236 {
03237
03238 if ( !$this->skipDiscounts() ) {
03239 $oDiscountList = oxDiscountList::getInstance();
03240 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03241 }
03242 }
03243
03252 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03253 {
03254 if ( !$oCur ) {
03255 $oCur = $this->getConfig()->getActShopCurrencyObject();
03256 }
03257
03258 $oPrice->multiply($oCur->rate);
03259 }
03260
03261
03270 protected function _getAttribsString(&$sAttribs, &$iCnt)
03271 {
03272
03273 $oDB = oxDb::getDb(true);
03274 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDB->quote( $this->getId() );
03275 $sAttribs = '';
03276 $blSep = false;
03277 $rs = $oDB->execute( $sSelect);
03278 $iCnt = 0;
03279 if ($rs != false && $rs->recordCount() > 0) {
03280 while (!$rs->EOF) {
03281 if ( $blSep) {
03282 $sAttribs .= ' or ';
03283 }
03284 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03285 $blSep = true;
03286 $iCnt++;
03287 $rs->moveNext();
03288 }
03289 }
03290 }
03291
03300 protected function _getSimList($sAttribs, $iCnt)
03301 {
03302 $myConfig = $this->getConfig();
03303 $oDB = oxDb::getDb(true);
03304
03305
03306 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03307
03308 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03309 $iAttrPercent = 0.70;
03310 }
03311
03312 $iHitMin = ceil( $iCnt * $iAttrPercent );
03313
03314
03315 $aList= array();
03316 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03317 ( $sAttribs )
03318 and t1.oxobjectid != ".$oDB->quote( $this->oxarticles__oxid->value )."
03319 group by t1.oxobjectid having count(*) >= $iHitMin ";
03320
03321 $rs = $oDB->selectLimit( $sSelect, 20, 0);
03322 if ($rs != false && $rs->recordCount() > 0) {
03323 while (!$rs->EOF) {
03324 $oTemp = new stdClass();
03325 $oTemp->cnt = $rs->fields['cnt'];
03326 $oTemp->id = $rs->fields['oxobjectid'];
03327 $aList[] = $oTemp;
03328 $rs->moveNext();
03329 }
03330 }
03331 return $aList;
03332 }
03333
03342 protected function _generateSimListSearchStr($sArticleTable, $aList)
03343 {
03344 $myConfig = $this->getConfig();
03345 $sFieldList = $this->getSelectFields();
03346 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03347 $blSep = false;
03348 $iCnt = 0;
03349 $oDb = oxDb::getDb();
03350 foreach ( $aList as $oTemp) {
03351 if ( $blSep) {
03352 $sSearch .= ',';
03353 }
03354 $sSearch .= $oDb->quote($oTemp->id);
03355 $blSep = true;
03356 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03357 break;
03358 }
03359 $iCnt++;
03360 }
03361
03362
03363
03364 $sSearch .= ') ';
03365
03366
03367 $sSearch .= ' order by rand() ';
03368
03369 return $sSearch;
03370 }
03371
03380 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03381 {
03382
03383 $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03384 $sO2CView = getViewName( 'oxobject2category' );
03385
03386
03387 if ( !$blSearchPriceCat ) {
03388 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03389 {$sCatView}.oxid = oxobject2category.oxcatnid
03390 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03391 } else {
03392 $sSelect = "select {$sCatView}.* from {$sCatView} where
03393 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03394 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03395 }
03396 return $sSelect;
03397 }
03398
03404 protected function _generateSearchStrForCustomerBought()
03405 {
03406 $sArtTable = $this->getViewName();
03407 $sOrderArtTable = getViewName( 'oxorderarticles' );
03408
03409
03410 $sIn = " '{$this->oxarticles__oxid->value}' ";
03411 if ( $this->oxarticles__oxparentid->value ) {
03412
03413
03414 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03415 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03416
03417 } else {
03418 $sParentIdForVariants = $this->getId();
03419 }
03420
03421
03422 $oDb = oxDb::getDb(true);
03423 $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03424 if ( $oRs != false && $oRs->recordCount() > 0) {
03425 while ( !$oRs->EOF ) {
03426 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03427 $oRs->moveNext();
03428 }
03429 }
03430
03431 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03432 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03433
03434
03435 $sQ = "select distinct {$sArtTable}.* from (
03436 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03437 ) as suborder
03438 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03439 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03440 where {$sArtTable}.oxid not in ( {$sIn} )
03441 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03442
03443
03444
03445
03446
03447
03448
03449
03450
03451
03452 return $sQ;
03453 }
03454
03464 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03465 {
03466 $sCategoryView = getViewName('oxcategories');
03467 $sO2CView = getViewName('oxobject2category');
03468
03469 $oDb = oxDb::getDb();
03470 $sOXID = $oDb->quote($sOXID);
03471 $sCatId = $oDb->quote($sCatId);
03472
03473 if (!$dPriceFromTo) {
03474 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03475 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03476 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03477 $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03478 } else {
03479 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03480 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03481 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03482 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03483 }
03484 return $sSelect;
03485 }
03486
03492 protected function _getAmountPriceList()
03493 {
03494 if ( $this->_oAmountPriceList === null ) {
03495 $this->_oAmountPriceList = array();
03496 if ( !$this->skipDiscounts() ) {
03497 $myConfig = $this->getConfig();
03498 $sArtId = $this->getId();
03499
03500
03501 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03502 $sArtId = $this->oxarticles__oxparentid->value;
03503 }
03504
03505
03506 $oAmPriceList = oxNew( 'oxlist' );
03507 $oAmPriceList->init( 'oxbase', 'oxprice2article' );
03508
03509 $sShopID = $myConfig->getShopID();
03510 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03511 $sShopSelect = '1';
03512 } else {
03513 $sShopSelect = " oxshopid = '$sShopID' ";
03514 }
03515
03516 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = " . oxDb::getDb()->quote( $sArtId ) . " and $sShopSelect order by oxamount ");
03517
03518
03519 $oBasePrice = $this->_getGroupPrice();
03520 foreach ( $oAmPriceList as $oAmPrice ) {
03521 if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03522 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03523 }
03524 }
03525
03526 $this->_oAmountPriceList = $oAmPriceList;
03527 }
03528 }
03529
03530 return $this->_oAmountPriceList;
03531 }
03532
03540 protected function _isFieldEmpty( $sFieldName )
03541 {
03542 $mValue = $this->$sFieldName->value;
03543
03544 if ( is_null( $mValue ) ) {
03545 return true;
03546 }
03547
03548 if ( $mValue === '' ) {
03549 return true;
03550 }
03551
03552 $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03553
03554 if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03555 return true;
03556 }
03557
03558
03559 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03560 return true;
03561 }
03562
03563 $sFieldName = strtolower($sFieldName);
03564
03565 if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03566 return true;
03567 }
03568
03569 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03570 return true;
03571 }
03572
03573 return false;
03574 }
03575
03583 protected function _assignParentFieldValue($sFieldName)
03584 {
03585 if (!($oParentArticle = $this->getParentArticle())) {
03586 return;
03587 }
03588
03589 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03590
03591
03592 if ( $oParentArticle->$sCopyFieldName != null ) {
03593
03594
03595 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03596 return;
03597 }
03598
03599
03600 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03601 return;
03602 }
03603
03604
03605
03606 if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03607 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03608 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03609 }
03610 } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03611
03612
03613 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03614 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03615 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03616 }
03617 } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03618
03619 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03620 } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03621 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03622 }
03623 }
03624 }
03625
03631 public function getParentArticle()
03632 {
03633 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03634 $sIndex = $sParentId . "_" . $this->getLanguage();
03635 if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03636 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03637 self::$_aLoadedParents[$sIndex]->_blSkipAbPrice = true;
03638 self::$_aLoadedParents[$sIndex]->_blLoadPrice = false;
03639 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03640 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03641 }
03642 return self::$_aLoadedParents[$sIndex];
03643 }
03644 }
03645
03653 protected function _getParentAricle()
03654 {
03655 return $this->getParentArticle();
03656 }
03657
03663 protected function _assignParentFieldValues()
03664 {
03665 startProfile('articleAssignParentInternal');
03666 if ( $this->oxarticles__oxparentid->value ) {
03667
03668 if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03669 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03670 $this->_assignParentFieldValue( $sFieldName );
03671 }
03672 }
03673 }
03674 stopProfile('articleAssignParentInternal');
03675 }
03676
03682 protected function _assignNotBuyableParent()
03683 {
03684 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03685 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03686 $this->_blNotBuyableParent = true;
03687
03688 }
03689 }
03690
03696 protected function _assignStock()
03697 {
03698 $myConfig = $this->getConfig();
03699
03700
03701
03702
03703
03704 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03705 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03706 }
03707
03708 $this->_iStockStatus = 0;
03709
03710
03711 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03712
03713 $iStock = $this->oxarticles__oxstock->value;
03714
03715 if ($this->_blNotBuyableParent) {
03716 $iStock = $this->oxarticles__oxvarstock->value;
03717 }
03718
03719
03720 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03721 $this->_iStockStatus = 1;
03722 }
03723
03724
03725 if ($iStock <= 0) {
03726 $this->_iStockStatus = -1;
03727 }
03728 }
03729
03730
03731
03732 if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03733 $iOnStock = $this->oxarticles__oxstock->value;
03734 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03735 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03736 }
03737 if ($iOnStock <= 0) {
03738 $this->_blNotBuyable = true;
03739 }
03740 }
03741
03742
03743 if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03744 $this->_blNotBuyable = false;
03745
03746 $this->_blNotBuyableParent = true;
03747 }
03748
03749
03750
03751
03752 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03753 $this->_blNotBuyable = true;
03754 }
03755
03756
03757 if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03758 $this->_blNotBuyable = true;
03759 }
03760 }
03761
03767 protected function _assignPrices()
03768 {
03769 $myConfig = $this->getConfig();
03770
03771
03772 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03773 return;
03774 }
03775
03776
03777 $dPrice = $this->getPrice()->getBruttoPrice();
03778
03779 $oCur = $myConfig->getActShopCurrencyObject();
03780
03781 if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03782 $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03783 }
03784
03785
03786 if ( $this->_hasAnyVariant() ) {
03787 $this->_applyRangePrice();
03788 }
03789 }
03790
03796 protected function _assignPersistentParam()
03797 {
03798
03799 $aPersParam = oxSession::getVar( 'persparam');
03800 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03801 $this->_aPersistParam = $aPersParam[$this->getId()];
03802 }
03803 }
03804
03810 protected function _assignDynImageDir()
03811 {
03812 $myConfig = $this->getConfig();
03813
03814 $sThisShop = $this->oxarticles__oxshopid->value;
03815
03816 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03817 $this->dabsimagedir = $myConfig->getPictureDir( false );
03818 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03819 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03820 }
03821
03827 protected function _assignComparisonListFlag()
03828 {
03829
03830
03831 $aItems = oxSession::getVar('aFiltcompproducts');
03832 if ( isset( $aItems[$this->getId()])) {
03833 $this->_blIsOnComparisonList = true;
03834 }
03835 }
03836
03842 protected function _assignAttributes()
03843 {
03844
03845
03846 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03847 $this->getAttributes();
03848 }
03849 }
03850
03851
03859 protected function _insert()
03860 {
03861
03862 $iInsertTime = time();
03863 $now = date('Y-m-d H:i:s', $iInsertTime);
03864 $this->oxarticles__oxinsert = new oxField( $now );
03865 $this->oxarticles__oxtimestamp = new oxField( $now );
03866 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03867 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03868 }
03869
03870 return parent::_insert();
03871 }
03872
03878 protected function _update()
03879 {
03880
03881 $this->_skipSaveFields();
03882
03883 $myConfig = $this->getConfig();
03884
03885
03886 return parent::_update();
03887 }
03888
03896 protected function _deleteRecords($sOXID)
03897 {
03898 $oDB = oxDb::getDb();
03899
03900 $sOXID = $oDB->quote($sOXID);
03901
03902
03903 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03904 $oDB->execute( $sDelete);
03905
03906 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03907 $oDB->execute( $sDelete);
03908
03909 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03910 $oDB->execute( $sDelete);
03911
03912 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03913 $oDB->execute( $sDelete);
03914
03915 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03916 $oDB->execute( $sDelete);
03917
03918 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03919 $oDB->execute( $sDelete);
03920
03921 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03922 $oDB->execute( $sDelete);
03923
03924
03925 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03926 $oDB->execute( $sDelete);
03927
03928 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03929 $oDB->execute( $sDelete);
03930
03931
03932 foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03933 $oDB->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03934 }
03935
03936 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03937 $rs = $oDB->execute( $sDelete );
03938
03939 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03940 $rs = $oDB->execute( $sDelete );
03941
03942
03943 return $rs;
03944 }
03945
03953 protected function _deleteVariantRecords( $sOXID )
03954 {
03955 if ( $sOXID ) {
03956 $oDb = oxDb::getDb();
03957
03958 $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03959 $rs = $oDb->execute( $sQ );
03960 if ($rs != false && $rs->recordCount() > 0) {
03961 while (!$rs->EOF) {
03962 $this->delete( $rs->fields[0] );
03963 $rs->moveNext();
03964 }
03965 }
03966 }
03967 }
03968
03978 protected function _resetCacheAndArticleCount( $sOxid )
03979 {
03980 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03981 }
03982
03988 protected function _deletePics()
03989 {
03990 $myUtilsPic = oxUtilsPic::getInstance();
03991 $myConfig = $this->getConfig();
03992 $oPictureHandler = oxPictureHandler::getInstance();
03993
03994
03995 $oPictureHandler->deleteMainIcon( $this );
03996
03997
03998 $oPictureHandler->deleteThumbnail( $this );
03999
04000 $sAbsDynImageDir = $myConfig->getPictureDir(false);
04001
04002
04003 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04004 for ( $i = 1; $i <= $iPicCount; $i++ ) {
04005 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04006 }
04007 }
04008
04018 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04019 {
04020
04021 $myUtilsCount = oxUtilsCount::getInstance();
04022
04023 if ( $sVendorId ) {
04024 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04025 }
04026
04027 if ( $sManufacturerId ) {
04028 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04029 }
04030
04031
04032 $oDb = oxDb::getDb();
04033 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04034 $oRs = $oDb->execute( $sQ );
04035 if ( $oRs !== false && $oRs->recordCount() > 0) {
04036 while ( !$oRs->EOF ) {
04037 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04038 $oRs->moveNext();
04039 }
04040 }
04041 }
04042
04050 protected function _onChangeUpdateStock( $sParentID )
04051 {
04052 if ( $sParentID ) {
04053 $oDb = oxDb::getDb();
04054 $sParentIdQuoted = $oDb->quote($sParentID);
04055 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04056 $rs = $oDb->execute($sQ);
04057 $iOldStock = $rs->fields[0];
04058 $iVendorID = $rs->fields[1];
04059 $iManufacturerID = $rs->fields[2];
04060
04061 $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04062 $iStock = (float) $oDb->getOne( $sQ );
04063
04064 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04065 $oDb->execute( $sQ );
04066
04067
04068
04069 if ( $iStock < 0 ) {
04070 $iStock = 0;
04071 }
04072 if ( $iOldStock < 0 ) {
04073 $iOldStock = 0;
04074 }
04075 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04076
04077
04078 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04079 }
04080 }
04081 }
04082
04090 protected function _onChangeStockResetCount( $sOxid )
04091 {
04092 $myConfig = $this->getConfig();
04093
04094 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04095 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04096
04097 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04098 }
04099 }
04100
04108 protected function _onChangeUpdateVarCount( $sParentID )
04109 {
04110 if ( $sParentID ) {
04111 $oDb = oxDb::getDb();
04112 $sParentIdQuoted = $oDb->quote( $sParentID );
04113 $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04114 $iVarCount = (int) $oDb->getOne( $sQ );
04115
04116 $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04117 $oDb->execute( $sQ );
04118 }
04119 }
04120
04128 protected function _onChangeUpdateMinVarPrice( $sParentID )
04129 {
04130 if ( $sParentID ) {
04131 $oDb = oxDb::getDb();
04132 $sParentIdQuoted = $oDb->quote($sParentID);
04133
04134 $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04135 $dVarMinPrice = $oDb->getOne($sQ);
04136
04137 $dParentPrice = $oDb->getOne("select oxprice from oxarticles where oxid = $sParentIdQuoted ");
04138
04139 $blParentBuyable = $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04140
04141 if ($dVarMinPrice) {
04142 if ($blParentBuyable) {
04143 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04144 }
04145
04146 } else {
04147 $dVarMinPrice = $dParentPrice;
04148 }
04149
04150 if ( $dVarMinPrice ) {
04151 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04152 $oDb->execute($sQ);
04153 }
04154 }
04155 }
04156
04157
04163 protected function _applyRangePrice()
04164 {
04165
04166 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04167 return;
04168 }
04169
04170 $this->_blIsRangePrice = false;
04171
04172
04173 if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04174 return;
04175 }
04176
04177 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04178
04179
04180 $dPrice = $this->oxarticles__oxvarminprice->value;
04181 $this->getPrice()->setPrice($dPrice);
04182 $this->_blIsRangePrice = true;
04183 $this->_calculatePrice( $this->getPrice() );
04184 return;
04185 }
04186
04187 $aPrices = array();
04188
04189 if (!$this->_blNotBuyableParent) {
04190 $aPrices[] = $this->getPrice()->getBruttoPrice();
04191 }
04192
04193 $aVariants = $this->getVariants(false);
04194
04195 if (count($aVariants)) {
04196 foreach ($aVariants as $sKey => $oVariant) {
04197 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04198 }
04199 }
04200
04201 if ( count( $aPrices ) ) {
04202 $dMinPrice = min( $aPrices );
04203 $dMaxPrice = max( $aPrices );
04204 }
04205
04206 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04207 $this->getPrice()->setBruttoPriceMode();
04208 $this->getPrice()->setPrice($dMinPrice);
04209 }
04210
04211 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04212 $this->getPrice()->setBruttoPriceMode();
04213 $this->getPrice()->setPrice($dMinPrice);
04214 $this->_blIsRangePrice = true;
04215 }
04216 }
04217
04224 public function getProductId()
04225 {
04226 return $this->getId();
04227 }
04228
04234 public function getProductParentId()
04235 {
04236 return $this->oxarticles__oxparentid->value;
04237 }
04238
04244 public function isOrderArticle()
04245 {
04246 return false;
04247 }
04248
04254 public function isVariant()
04255 {
04256 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04257 }
04258
04264 public function isMdVariant()
04265 {
04266 $oMdVariant = oxNew( "oxVariantHandler" );
04267
04268 return $oMdVariant->isMdVariant($this);
04269 }
04270
04278 public function getSqlForPriceCategories($sFields = '')
04279 {
04280 if (!$sFields) {
04281 $sFields = 'oxid';
04282 }
04283 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04284 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04285 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04286 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04287 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04288 }
04289
04297 public function inPriceCategory( $sCatNid )
04298 {
04299 $oDb = oxDb::getDb();
04300
04301 $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04302 $sQuotedCnid = $oDb->quote( $sCatNid );
04303 return (bool) $oDb->getOne(
04304 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04305 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04306 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04307 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04308 .")"
04309 );
04310 }
04311
04317 public function getMdVariants()
04318 {
04319 if ( $this->_oMdVariants ) {
04320 return $this->_oMdVariants;
04321 }
04322
04323 $oParentArticle = $this->getParentArticle();
04324 if ( $oParentArticle ) {
04325 $oVariants = $oParentArticle->getVariants();
04326 } else {
04327 $oVariants = $this->getVariants();
04328 }
04329
04330 $oVariantHandler = oxNew( "oxVariantHandler" );
04331 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04332
04333 return $this->_oMdVariants;
04334 }
04335
04341 public function getMdSubvariants()
04342 {
04343 return $this->getMdVariants()->getMdSubvariants();
04344 }
04345
04353 protected function _hasMasterImage( $iIndex )
04354 {
04355 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04356
04357 if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04358 return false;
04359 }
04360 if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04361 return false;
04362 }
04363
04364 $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04365
04366 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04367 return true;
04368 }
04369
04370 return false;
04371 }
04372
04381 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04382 {
04383 if ( $sFieldName ) {
04384 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04385 return $this->$sFieldName->value;
04386 }
04387 }
04388
04396 public function getMasterZoomPictureUrl( $iIndex )
04397 {
04398 $sPicUrl = false;
04399 $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04400
04401 if ( $sPicName && $sPicName != "nopic.jpg" ) {
04402 $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04403 if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04404 $sPicUrl = false;
04405 }
04406 }
04407
04408 return $sPicUrl;
04409 }
04410
04416 public function hasAmountPrice()
04417 {
04418 if ( self::$_blHasAmountPrice === null ) {
04419
04420 self::$_blHasAmountPrice = false;
04421
04422 $oDb = oxDb::getDb();
04423 $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04424
04425 if ( $oDb->getOne( $sQ ) ) {
04426 self::$_blHasAmountPrice = true;
04427 }
04428 }
04429
04430 return self::$_blHasAmountPrice;
04431 }
04432 }