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 {
00019
00025 protected $_sClassName = 'oxarticle';
00026
00032 protected $_blUseLazyLoading = true;
00033
00039 protected $_sItemKey;
00040
00046 protected $_blCalcPrice = true;
00047
00052 protected $_oPrice = null;
00053
00054
00060 protected $_dVarMinPrice = null;
00061
00067 protected $_dVarMaxPrice = null;
00068
00074 protected $_dArticleVat = null;
00075
00081 protected $_aPersistParam = null;
00082
00088 protected $_blNotBuyable = false;
00089
00096 protected $_blLoadVariants = true;
00097
00103 protected $_aVariants = null;
00104
00110 protected $_aVariantsWithNotOrderables = null;
00111
00120 protected $_blNotBuyableParent = false;
00121
00122
00126 protected $_blHasVariants = false;
00127
00131 protected $_blHasMdVariants = false;
00132
00137 protected $_blIsOnComparisonList = false;
00138
00143 protected $_oUser = null;
00144
00150 protected $_blLoadPrice = true;
00151
00158 protected $_blSkipAbPrice = false;
00159
00166 protected $_fPricePerUnit = null;
00167
00171 protected $_blLoadParentData = false;
00172
00176 protected $_blAllowEmptyParentId = false;
00177
00181 protected $_blSkipAssign = false;
00182
00188 protected $_blSkipDiscounts = null;
00189
00194 protected $_oAttributeList = null;
00195
00196
00202 protected $_blIsRangePrice = null;
00203
00209 protected $_aMediaUrls = null;
00210
00216 static protected $_aLoadedParents;
00217
00223 static protected $_aSelList;
00224
00230 protected $_aDispSelList;
00231
00237 protected $_blIsSeoObject = true;
00238
00244 protected $_oAmountPriceList = null;
00245
00254 protected $_iLinkType = 0;
00255
00261 protected $_aStdUrls = array();
00262
00268 protected $_aSeoUrls = array();
00269
00275 protected $_aSeoAddParams = array();
00276
00282 protected $_aStdAddParams = array();
00283
00289 protected $_sDynImageDir = null;
00290
00296 protected $_sMoreDetailLink = null;
00297
00303 protected $_sToBasketLink = null;
00304
00310 protected $_iStockStatusOnLoad = null;
00311
00317 protected $_iStockStatus = null;
00318
00324 protected $_oTPrice = null;
00325
00331 protected $_oAmountPriceInfo = null;
00332
00338 protected $_dAmountPrice = null;
00339
00345 protected static $_aArticleManufacturers = array();
00346
00352 protected static $_aArticleVendors = array();
00353
00359 protected static $_aArticleCats = array();
00360
00366 protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00367 'oxarticles__oxtimestamp',
00368 'oxarticles__oxnid',
00369 'oxarticles__oxid',
00370 'oxarticles__oxparentid');
00371
00377 protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00378 'oxarticles__oxfreeshipping',
00379 'oxarticles__oxisdownloadable',
00380 'oxarticles__oxshowcustomagreement');
00381
00387 protected $_oMdVariants = null;
00388
00394 protected $_oLongDesc = null;
00395
00403 protected $_aVariantSelections = array();
00404
00409 protected static $_aSelections = array();
00410
00415 protected static $_aCategoryCache = null;
00416
00421 protected static $_blHasAmountPrice = null;
00422
00427 protected $_aArticleFiles = null;
00428
00433 protected $_blCanUpdateAnyField = null;
00434
00443 public function __construct($aParams = null)
00444 {
00445 if ( $aParams && is_array($aParams)) {
00446 foreach ( $aParams as $sParam => $mValue) {
00447 $this->$sParam = $mValue;
00448 }
00449 }
00450 parent::__construct();
00451 $this->init( 'oxarticles' );
00452 }
00453
00462 public function __get($sName)
00463 {
00464 $this->$sName = parent::__get($sName);
00465 if ( $this->$sName ) {
00466
00467 $this->_assignParentFieldValue($sName);
00468 }
00469
00470 return $this->$sName;
00471 }
00472
00481 public function __set( $sName, $sValue )
00482 {
00483 parent::__set( $sName, $sValue );
00484 }
00485
00492 public function isInList()
00493 {
00494 return $this->_isInList();
00495 }
00496
00504 public function setId( $sId = null )
00505 {
00506 $sId = parent::setId( $sId );
00507
00508
00509 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00510
00511 return $sId;
00512 }
00513
00523 public function getActiveCheckQuery( $blForceCoreTable = null )
00524 {
00525 $sTable = $this->getViewName( $blForceCoreTable );
00526
00527
00528 $sQ = " $sTable.oxactive = 1 ";
00529
00530
00531 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00532 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00533 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00534 }
00535
00536 return $sQ;
00537 }
00538
00552 public function getStockCheckQuery( $blForceCoreTable = null )
00553 {
00554 $myConfig = $this->getConfig();
00555 $sTable = $this->getViewName( $blForceCoreTable );
00556
00557 $sQ = "";
00558
00559
00560 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00561 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00562
00563 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00564 $sTimeCheckQ = '';
00565 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00566 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00567 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00568 }
00569 $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 ) ) ";
00570 }
00571 }
00572
00573 return $sQ;
00574 }
00575
00587 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null )
00588 {
00589 $sTable = $this->getViewName( $blForceCoreTable );
00590 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00591
00592
00593 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00594 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00595 if ( $blRemoveNotOrderables ) {
00596 $sQ .= " and $sTable.oxstockflag != 3 ";
00597 }
00598 $sQ .= " ) ) ";
00599 }
00600
00601 return $sQ;
00602 }
00603
00611 public function getSqlActiveSnippet( $blForceCoreTable = null )
00612 {
00613 $myConfig = $this->getConfig();
00614
00615
00616 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00617
00618
00619 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00620
00621
00622 return "( $sQ ) ";
00623 }
00624
00632 public function setSkipAssign($blSkipAssign)
00633 {
00634 $this->_blSkipAssign = $blSkipAssign;
00635 }
00636
00642 public function disablePriceLoad()
00643 {
00644 $this->_blLoadPrice = false;
00645 }
00646
00652 public function enablePriceLoad()
00653 {
00654 $this->_blLoadPrice = true;
00655 }
00656
00662 public function getItemKey()
00663 {
00664 return $this->_sItemKey;
00665 }
00666
00674 public function setItemKey($sItemKey)
00675 {
00676 $this->_sItemKey = $sItemKey;
00677 }
00678
00686 public function setNoVariantLoading( $blLoadVariants )
00687 {
00688 $this->_blLoadVariants = !$blLoadVariants;
00689 }
00690
00696 public function isBuyable()
00697 {
00698 if ($this->_blNotBuyableParent) {
00699 return false;
00700 }
00701
00702 return !$this->_blNotBuyable;
00703 }
00704
00710 public function getPersParams()
00711 {
00712 return $this->_aPersistParam;
00713 }
00714
00720 public function isOnComparisonList()
00721 {
00722 return $this->_blIsOnComparisonList;
00723 }
00724
00732 public function setOnComparisonList( $blOnList )
00733 {
00734 $this->_blIsOnComparisonList = $blOnList;
00735 }
00736
00744 public function setLoadParentData($blLoadParentData)
00745 {
00746 $this->_blLoadParentData = $blLoadParentData;
00747 }
00748
00758 public function setSkipAbPrice( $blSkipAbPrice = null )
00759 {
00760 $this->_blSkipAbPrice = $blSkipAbPrice;
00761 }
00762
00763
00771 public function isMultilingualField($sFieldName)
00772 {
00773 switch ($sFieldName) {
00774 case "oxlongdesc":
00775 case "oxtags":
00776 return true;
00777 }
00778
00779 return parent::isMultilingualField($sFieldName);
00780 }
00781
00787 public function isVisible()
00788 {
00789
00790
00791 if ( ( $blCanPreview = oxRegistry::getUtils()->canPreview() ) !== null ) {
00792 return $blCanPreview;
00793 }
00794
00795
00796 $sNow = date('Y-m-d H:i:s');
00797 if ( !$this->oxarticles__oxactive->value &&
00798 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00799 $this->oxarticles__oxactiveto->value < $sNow
00800 )) {
00801 return false;
00802 }
00803
00804
00805 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00806 $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00807 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00808 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00809 }
00810 if ( $iOnStock <= 0 ) {
00811 return false;
00812 }
00813 }
00814
00815 return true;
00816 }
00817
00826 public function assign( $aRecord )
00827 {
00828
00829 startProfile('articleAssign');
00830
00831
00832 parent::assign( $aRecord );
00833
00834 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00835
00836
00837 if ($this->_blSkipAssign) {
00838 return null;
00839 }
00840
00841 $this->_assignParentFieldValues();
00842 $this->_assignNotBuyableParent();
00843
00844
00845 $this->_assignStock();
00846 $this->_assignPersistentParam();
00847 $this->_assignDynImageDir();
00848 $this->_assignComparisonListFlag();
00849
00850
00851 stopProfile('articleAssign');
00852
00853 return null;
00854 }
00855
00856
00864 protected function _loadFromDb( $sOXID )
00865 {
00866
00867 $sSelect = $this->buildSelectString( array( $this->getViewName().".oxid" => $sOXID ));
00868
00869
00870 $aData = oxDb::getDb( oxDb::FETCH_MODE_ASSOC )->getRow( $sSelect );
00871
00872 return $aData;
00873 }
00874
00875
00886 public function load( $sOXID )
00887 {
00888
00889 $this->_blNotBuyableParent = false;
00890
00891
00892 $aData = $this->_loadFromDb( $sOXID );
00893
00894 if ( $aData ) {
00895 $this->assign( $aData );
00896
00897
00898 $this->_iStockStatusOnLoad = $this->_iStockStatus;
00899
00900 $this->_isLoaded = true;
00901 return true;
00902 }
00903
00904 return false;
00905 }
00906
00907
00915 public function addToRatingAverage( $iRating )
00916 {
00917 $dOldRating = $this->oxarticles__oxrating->value;
00918 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00919 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00920 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00921 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00922 $dRatingCnt = (int) ($dOldCnt + 1);
00923
00924 $oDb = oxDb::getDb();
00925 $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00926
00927 }
00928
00936 public function setRatingAverage( $iRating )
00937 {
00938 $this->oxarticles__oxrating = new oxField( $iRating );
00939 }
00940
00948 public function setRatingCount( $iRatingCnt )
00949 {
00950 $this->oxarticles__oxratingcnt = new oxField( $iRatingCnt );
00951 }
00952
00960 public function getArticleRatingAverage( $blIncludeVariants = false )
00961 {
00962 if ( !$blIncludeVariants ) {
00963 return round( $this->oxarticles__oxrating->value, 1);
00964 } else {
00965 $oRating = oxNew( 'oxRating' );
00966 return $oRating->getRatingAverage( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00967 }
00968 }
00969
00977 public function getArticleRatingCount( $blIncludeVariants = false )
00978 {
00979 if ( !$blIncludeVariants ) {
00980 return $this->oxarticles__oxratingcnt->value;
00981 } else {
00982 $oRating = oxNew( 'oxRating' );
00983 return $oRating->getRatingCount( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00984 }
00985 }
00986
00987
00993 public function getReviews()
00994 {
00995 $aIds = array($this->getId());
00996
00997 if ( $this->oxarticles__oxparentid->value ) {
00998 $aIds[] = $this->oxarticles__oxparentid->value;
00999 }
01000
01001
01002 if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
01003 $aAdd = $this->_getVariantsIds();
01004 if (is_array($aAdd)) {
01005 $aIds = array_merge($aIds, $aAdd);
01006 }
01007 }
01008
01009 $oReview = oxNew('oxreview');
01010 $oRevs = $oReview->loadList('oxarticle', $aIds);
01011
01012
01013 if ( $oRevs->count() < 1 ) {
01014 return null;
01015 }
01016
01017 return $oRevs;
01018 }
01019
01025 public function getCrossSelling()
01026 {
01027 $oCrosslist = oxNew( "oxarticlelist");
01028 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
01029 if ( $oCrosslist->count() ) {
01030 return $oCrosslist;
01031 }
01032
01033 return null;
01034 }
01035
01041 public function getAccessoires()
01042 {
01043 $myConfig = $this->getConfig();
01044
01045
01046 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01047 return null;
01048 }
01049
01050 $oAcclist = oxNew( "oxarticlelist");
01051 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01052 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01053
01054 if ( $oAcclist->count()) {
01055 return $oAcclist;
01056 }
01057
01058 return null;
01059 }
01060
01066 public function getSimilarProducts()
01067 {
01068
01069 $myConfig = $this->getConfig();
01070 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01071 return null;
01072 }
01073
01074 $sArticleTable = $this->getViewName();
01075
01076 $sAttribs = '';
01077 $iCnt = 0;
01078 $this->_getAttribsString($sAttribs, $iCnt);
01079
01080 if ( !$sAttribs) {
01081 return null;
01082 }
01083
01084 $aList = $this->_getSimList($sAttribs, $iCnt);
01085
01086 if ( count( $aList ) ) {
01087 uasort( $aList, 'cmpart');
01088
01089 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01090
01091 $oSimilarlist = oxNew( 'oxarticlelist' );
01092 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01093 $oSimilarlist->selectString( $sSearch);
01094
01095 return $oSimilarlist;
01096 }
01097
01098 return null;
01099 }
01100
01106 public function getCustomerAlsoBoughtThisProducts()
01107 {
01108
01109 $myConfig = $this->getConfig();
01110 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01111 return null;
01112 }
01113
01114
01115 $sQ = $this->_generateSearchStrForCustomerBought();
01116
01117 $oArticles = oxNew( 'oxarticlelist' );
01118 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01119 $oArticles->selectString( $sQ );
01120 if ( $oArticles->count() ) {
01121 return $oArticles;
01122 }
01123
01124 return null;
01125 }
01126
01133 public function loadAmountPriceInfo()
01134 {
01135 $myConfig = $this->getConfig();
01136 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice || !$this->hasAmountPrice() ) {
01137 return array();
01138 }
01139
01140 if ( $this->_oAmountPriceInfo === null ) {
01141 $this->_oAmountPriceInfo = array();
01142 if ( count( ( $aAmPriceList = $this->_getAmountPriceList()->getArray() ) ) ) {
01143 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $aAmPriceList );
01144 }
01145 }
01146 return $this->_oAmountPriceInfo;
01147 }
01148
01156 public function getSelectLists($sKeyPrefix = null)
01157 {
01158
01159
01160 $sKey = $this->getId();
01161 if ( isset( $sKeyPrefix ) ) {
01162 $sKey = $sKeyPrefix.'__'.$sKey;
01163 }
01164
01165 if ( !isset( self::$_aSelList[$sKey] ) ) {
01166 $oDb = oxDb::getDb();
01167 $sSLViewName = getViewName( 'oxselectlist' );
01168
01169 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01170 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01171
01172
01173 $oLists = oxNew( 'oxlist' );
01174 $oLists->init( 'oxselectlist' );
01175 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01176
01177
01178 if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01179 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01180 }
01181
01182
01183
01184
01185
01186 $dVat = $this->getArticleVat();
01187
01188 $iCnt = 0;
01189 self::$_aSelList[$sKey] = array();
01190 foreach ( $oLists as $oSelectlist ) {
01191 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01192 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01193 $iCnt++;
01194 }
01195 }
01196 return self::$_aSelList[$sKey];
01197 }
01198
01206 protected function _hasAnyVariant( $blForceCoreTable = null )
01207 {
01208 $blHas = false;
01209 if ( ( $sId = $this->getId() ) ) {
01210 if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01211 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01212 } else {
01213 $sArticleTable = $this->getViewName( $blForceCoreTable );
01214 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01215 }
01216 }
01217 return $blHas;
01218 }
01219
01225 public function getVariantsCount()
01226 {
01227 return $this->oxarticles__oxvarcount->value;
01228 }
01229
01235 public function hasMdVariants()
01236 {
01237 return $this->_blHasMdVariants;
01238 }
01239
01245 public function hasIntangibleAgreement()
01246 {
01247 return $this->oxarticles__oxshowcustomagreement->value && $this->oxarticles__oxnonmaterial->value && !$this->hasDownloadableAgreement();
01248 }
01249
01255 public function hasDownloadableAgreement()
01256 {
01257 return $this->oxarticles__oxshowcustomagreement->value && $this->oxarticles__oxisdownloadable->value;
01258 }
01259
01269 public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01270 {
01271 $iLimit = (int) $iLimit;
01272 if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01273 $aVariantSelections = false;
01274 if ( $this->oxarticles__oxvarcount->value ) {
01275 $oVariants = $this->getVariants( false );
01276 $aVariantSelections = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $oVariants, $aFilterIds, $sActVariantId, $iLimit );
01277
01278 if ( !empty($oVariants) && empty( $aVariantSelections['rawselections'] ) ) {
01279 $aVariantSelections = false;
01280 }
01281 }
01282 $this->_aVariantSelections[$iLimit] = $aVariantSelections;
01283 }
01284
01285 return $this->_aVariantSelections[$iLimit];
01286 }
01287
01296 public function getSelections( $iLimit = null, $aFilter = null )
01297 {
01298 $sId = $this->getId() . ( (int) $iLimit );
01299 if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01300
01301 $oDb = oxDb::getDb();
01302 $sSLViewName = getViewName( 'oxselectlist' );
01303
01304 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01305 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01306
01307 if ( ( $iLimit = (int) $iLimit ) ) {
01308 $sQ .= " limit $iLimit ";
01309 }
01310
01311
01312 $dVat = 0;
01313 if ( ( $oPrice = $this->getPrice() ) != null ) {
01314 $dVat = $oPrice->getVat();
01315 }
01316
01317
01318 $oList = oxNew( 'oxlist' );
01319 $oList->init( 'oxselectlist' );
01320 $oList->getBaseObject()->setVat( $dVat );
01321 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01322
01323
01324 if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01325 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01326 }
01327
01328 self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01329 }
01330
01331 if ( self::$_aSelections[$sId] ) {
01332
01333 $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01334 if ( $aFilter ) {
01335 $iSelIdx = 0;
01336 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01337 if ( isset( $aFilter[$iSelIdx] ) ) {
01338 $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01339 }
01340 $iSelIdx++;
01341 }
01342 }
01343 }
01344
01345 return self::$_aSelections[$sId];
01346 }
01347
01357 protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01358 {
01359 $oVariants = array();
01360 $sId = $this->getId();
01361
01362 if (!$sId) {
01363 return $oVariants;
01364 }
01365
01366
01367 self::$_aLoadedParents[$sId . "_" . $this->getLanguage()] = $this;
01368
01369 $myConfig = $this->getConfig();
01370
01371 if ( !$this->_blLoadVariants ||
01372 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01373 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01374 return $oVariants;
01375 }
01376
01377
01378 $sCacheKey = $blSimple ? "simple" : "full";
01379 if ( $blRemoveNotOrderables ) {
01380 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01381 return $this->_aVariants[$sCacheKey];
01382 } else {
01383 $this->_aVariants[$sCacheKey] = & $oVariants;
01384 }
01385 } elseif ( !$blRemoveNotOrderables ) {
01386 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01387 return $this->_aVariantsWithNotOrderables[$sCacheKey];
01388 } else {
01389 $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01390 }
01391 }
01392
01393 if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01394
01395 $oVariants = $this->loadSimpleVariantsForLists( $blSimple );
01396
01397 $oVariants = $this->_selectVariants( $blRemoveNotOrderables, $blForceCoreTable, $oVariants );
01398 }
01399
01400
01401 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01402 $this->_blNotBuyableParent = true;
01403 }
01404
01405
01406 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01407 $this->_blNotBuyable = true;
01408 }
01409
01410 return $oVariants;
01411 }
01412
01421 public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01422 {
01423 return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01424 }
01425
01434 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01435 {
01436 return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01437 }
01438
01444 public function getSimpleVariants()
01445 {
01446 if ( $this->oxarticles__oxvarcount->value) {
01447 return $this->getVariants();
01448 }
01449
01450 return null;
01451 }
01452
01461 public function getAdminVariants( $sLanguage = null )
01462 {
01463 $oVariants = oxNew( 'oxarticlelist');
01464 if ( ( $sId = $this->getId() ) ) {
01465
01466 $oBaseObj = $oVariants->getBaseObject();
01467
01468 if ( is_null( $sLanguage ) ) {
01469 $oBaseObj->setLanguage( oxRegistry::getLang()->getBaseLanguage() );
01470 } else {
01471 $oBaseObj->setLanguage( $sLanguage );
01472 }
01473
01474 $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01475 $oVariants->selectString( $sSql );
01476
01477
01478 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01479
01480 $this->_blNotBuyableParent = true;
01481 }
01482 }
01483
01484 return $oVariants;
01485 }
01486
01494 public function getCategory()
01495 {
01496 $oCategory = oxNew( 'oxcategory' );
01497 $oCategory->setLanguage( $this->getLanguage() );
01498
01499
01500 $sOXID = $this->getId();
01501 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01502 $sOXID = $this->oxarticles__oxparentid->value;
01503 }
01504
01505 if ( $sOXID ) {
01506
01507 if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01508 startPRofile( 'getCategory' );
01509 $oStr = getStr();
01510 $sWhere = $oCategory->getSqlActiveSnippet();
01511 $sSelect = $this->_generateSearchStr( $sOXID );
01512 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01513
01514
01515 if ( !$oCategory->assignRecord( $sSelect ) ) {
01516
01517 $sSelect = $this->_generateSearchStr( $sOXID, true );
01518 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01519
01520
01521 if ( !$oCategory->assignRecord( $sSelect ) ) {
01522 $oCategory = null;
01523 }
01524 }
01525
01526 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01527 stopPRofile( 'getCategory' );
01528 } else {
01529
01530 $oCategory = $this->_aCategoryCache[ $sOXID ];
01531 }
01532 }
01533
01534 return $oCategory;
01535 }
01536
01545 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01546 {
01547 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01548 return self::$_aArticleCats[$this->getId()];
01549 }
01550
01551
01552 $sOXID = $this->getId();
01553
01554 $aRet = $this->_getArticleCategories( $sOXID, $blActCats );
01555
01556 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01557 $aRet = array_merge( $aRet, $this->_getArticleCategories( $this->oxarticles__oxparentid->value, $blActCats ) );
01558 }
01559
01560
01561 $sSql = $this->getSqlForPriceCategories();
01562
01563 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01564 $rs = $oDb->select( $sSql );
01565
01566
01567 if ($rs != false && $rs->recordCount() > 0) {
01568 while (!$rs->EOF) {
01569
01570 if ( is_array( $rs->fields ) ) {
01571 $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01572 }
01573
01574
01575 if ( !$aRet[$rs->fields['oxid']] ) {
01576 $aRet[] = $rs->fields['oxid'];
01577 }
01578 $rs->moveNext();
01579 }
01580 }
01581
01582 return self::$_aArticleCats[$this->getId()] = $aRet;
01583 }
01584
01593 protected function _getArticleCategories( $sOXID, $blActCats = false )
01594 {
01595
01596 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01597 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01598 $rs = $oDb->select( $sSql );
01599
01600
01601 $aRet = array();
01602
01603 if ($rs != false && $rs->recordCount() > 0) {
01604 while (!$rs->EOF) {
01605 $aRet[] = $rs->fields['oxcatnid'];
01606 $rs->moveNext();
01607 }
01608 }
01609
01610 return $aRet;
01611 }
01612
01621 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01622 {
01623 $sO2CView = $this->_getObjectViewName('oxobject2category');
01624 $sCatView = $this->_getObjectViewName('oxcategories');
01625 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01626 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01627 if ( $blActCats ) {
01628 $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 ";
01629 }
01630 $sSelect .= 'order by oxobject2category.oxtime ';
01631 return $sSelect;
01632 }
01633
01643 public function getVendor( $blShopCheck = true )
01644 {
01645 if ( ( $sVendorId = $this->getVendorId() ) ) {
01646 $oVendor = oxNew( 'oxvendor' );
01647 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01648 $oVendor = oxNew( 'oxi18n' );
01649 $oVendor->init('oxvendor');
01650 $oVendor->setReadOnly( true );
01651 $sVendorId = $this->oxarticles__oxvendorid->value;
01652 }
01653 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01654
01655 return $oVendor;
01656 }
01657 return null;
01658 }
01659
01667 public function getVendorId( $blForceReload = false )
01668 {
01669 $sVendorId = false;
01670 if ( $this->oxarticles__oxvendorid->value ) {
01671 $sVendorId = $this->oxarticles__oxvendorid->value;
01672
01673 }
01674 return $sVendorId;
01675 }
01676
01684 public function getManufacturerId( $blForceReload = false )
01685 {
01686 $sManufacturerId = false;
01687 if ( $this->oxarticles__oxmanufacturerid->value ) {
01688
01689 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01690
01691 }
01692 return $sManufacturerId;
01693 }
01694
01704 public function getManufacturer( $blShopCheck = true )
01705 {
01706 $oManufacturer = oxNew( 'oxmanufacturer' );;
01707 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01708 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01709 $oManufacturer->setReadOnly( true );
01710 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01711 }
01712
01713 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01714 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01715 $oManufacturer->setReadOnly( true );
01716 }
01717 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01718 } else {
01719 $oManufacturer = null;
01720 }
01721
01722 return $oManufacturer;
01723 }
01724
01732 public function inCategory( $sCatNid)
01733 {
01734 return in_array( $sCatNid, $this->getCategoryIds());
01735 }
01736
01745 public function isAssignedToCategory( $sCatId )
01746 {
01747
01748 $sOXID = $this->getId();
01749 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01750 $sOXID = $this->oxarticles__oxparentid->value;
01751 }
01752
01753 $oDb = oxDb::getDb();
01754 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01755 $sOXID = $oDb->getOne( $sSelect );
01756
01757 if ( isset( $sOXID) && $sOXID) {
01758 return true;
01759 }
01760
01761
01762 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01763 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01764 if ( $dPriceFromTo > 0) {
01765 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01766 $sOXID = $oDb->getOne( $sSelect );
01767
01768 if ( isset( $sOXID) && $sOXID) {
01769 return true;
01770 }
01771 }
01772 }
01773 return false;
01774 }
01775
01781 public function getTPrice()
01782 {
01783 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01784 return null;
01785 }
01786
01787
01788 if ( $this->_oTPrice !== null ) {
01789 return $this->_oTPrice;
01790 }
01791
01792 $oPrice = $this->_getPriceObject();
01793
01794 $dBasePrice = $this->oxarticles__oxtprice->value;
01795 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01796
01797 $oPrice->setPrice( $dBasePrice );
01798
01799 $this->_applyVat( $oPrice, $this->getArticleVat() );
01800 $this->_applyCurrency( $oPrice );
01801
01802 if ( $this->isParentNotBuyable() ) {
01803
01804 $oPrice2 = $this->getVarMinPrice();
01805 } else {
01806
01807 $oPrice2 = $this->getPrice();
01808 }
01809
01810 if ( $oPrice->getPrice() <= $oPrice2->getPrice() ) {
01811
01812 return null;
01813 }
01814
01815 $this->_oTPrice = $oPrice;
01816
01817 return $this->_oTPrice;
01818 }
01819
01825 public function skipDiscounts()
01826 {
01827
01828 if ( $this->_blSkipDiscounts !== null ) {
01829 return $this->_blSkipDiscounts;
01830 }
01831
01832 if ( $this->oxarticles__oxskipdiscounts->value ) {
01833 return true;
01834 }
01835
01836
01837 $this->_blSkipDiscounts = false;
01838 if ( oxRegistry::get("oxDiscountList")->hasSkipDiscountCategories() ) {
01839
01840 $oDb = oxDb::getDb();
01841 $sO2CView = getViewName( 'oxobject2category', $this->getLanguage() );
01842 $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01843 $sSelect = "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01844 where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01845 $this->_blSkipDiscounts = ( $oDb->getOne( $sSelect ) == 1 );
01846 }
01847
01848 return $this->_blSkipDiscounts;
01849 }
01850
01858 public function setPrice(oxPrice $oPrice)
01859 {
01860 $this->_oPrice = $oPrice;
01861 }
01862
01871 public function getBasePrice( $dAmount = 1 )
01872 {
01873
01874
01875
01876
01877 $myConfig = $this->getConfig();
01878 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01879 return null;
01880
01881
01882 $dPrice = $this->_getAmountPrice( $dAmount );
01883
01884
01885 return $dPrice;
01886 }
01887
01895 public function getPrice( $dAmount = 1 )
01896 {
01897 $myConfig = $this->getConfig();
01898
01899 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01900 return null;
01901 }
01902
01903
01904 if ( $dAmount != 1 || $this->_oPrice === null ) {
01905
01906
01907 $dBasePrice = $this->getBasePrice( $dAmount );
01908 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01909
01910 $oPrice = $this->_getPriceObject();
01911
01912 $oPrice->setPrice( $dBasePrice );
01913
01914
01915 if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01916 return $this->_oPrice = $oPrice;
01917 }
01918
01919 $this->_calculatePrice( $oPrice );
01920 if ( $dAmount != 1 ) {
01921 return $oPrice;
01922 }
01923
01924 $this->_oPrice = $oPrice;
01925 }
01926 return $this->_oPrice;
01927 }
01928
01937 protected function _calculatePrice( $oPrice, $dVat = null )
01938 {
01939
01940 if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01941 $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01942 }
01943
01944
01945 $this->_applyCurrency( $oPrice );
01946
01947 if ( !$this->skipDiscounts() ) {
01948 $oDiscountList = oxRegistry::get("oxDiscountList");
01949 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
01950
01951 reset( $aDiscounts );
01952 foreach ( $aDiscounts as $oDiscount ) {
01953 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
01954 }
01955 $oPrice->calculateDiscount();
01956 }
01957
01958 return $oPrice;
01959 }
01960
01968 public function setArticleUser($oUser)
01969 {
01970 $this->_oUser = $oUser;
01971 }
01972
01978 public function getArticleUser()
01979 {
01980 if ($this->_oUser) {
01981 return $this->_oUser;
01982 }
01983 return $this->getUser();
01984 }
01985
01995 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01996 {
01997 $oUser = $oBasket->getBasketUser();
01998 $this->setArticleUser( $oUser );
01999
02000 $oBasketPrice = $this->_getPriceObject( $oBasket->isCalculationModeNetto() );
02001
02002
02003 $dBasePrice = $this->getBasePrice( $dAmount );
02004
02005 $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
02006 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat(), $oBasket->isCalculationModeNetto() );
02007
02008
02009
02010
02011 $oBasketPrice->setPrice( $dBasePrice );
02012
02013 $dVat = oxRegistry::get("oxVatSelector")->getBasketItemVat( $this, $oBasket );
02014 $this->_calculatePrice( $oBasketPrice, $dVat );
02015
02016
02017 return $oBasketPrice;
02018 }
02019
02028 public function delete( $sOXID = null )
02029 {
02030 if ( !$sOXID ) {
02031 $sOXID = $this->getId();
02032 }
02033 if ( !$sOXID ) {
02034 return false;
02035 }
02036
02037
02038
02039
02040 $this->_deleteVariantRecords( $sOXID );
02041 $this->load( $sOXID );
02042 $this->_deletePics();
02043 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
02044
02045
02046 parent::delete( $sOXID );
02047
02048 $rs = $this->_deleteRecords( $sOXID );
02049
02050 oxRegistry::get("oxSeoEncoderArticle")->onDeleteArticle($this);
02051
02052 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
02053
02054 return $rs->EOF;
02055 }
02056
02065 public function reduceStock($dAmount, $blAllowNegativeStock = false)
02066 {
02067 $this->beforeUpdate();
02068
02069 $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
02070 if (!$blAllowNegativeStock && ($iStockCount < 0)) {
02071 $dAmount += $iStockCount;
02072 $iStockCount = 0;
02073 }
02074 $this->oxarticles__oxstock = new oxField($iStockCount);
02075
02076 $oDb = oxDb::getDb();
02077 $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
02078 $this->onChange( ACTION_UPDATE_STOCK );
02079 return $dAmount;
02080 }
02081
02090 public function updateSoldAmount( $dAmount = 0 )
02091 {
02092 if ( !$dAmount ) {
02093 return null;
02094 }
02095
02096
02097 if ( !$this->oxarticles__oxparentid->value ) {
02098
02099 $dAmount = (double) $dAmount;
02100 $oDb = oxDb::getDb();
02101 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02102 } elseif ( $this->oxarticles__oxparentid->value) {
02103
02104 $oUpdateArticle = $this->getParentArticle();
02105 $oUpdateArticle->updateSoldAmount( $dAmount );
02106 }
02107
02108 return $rs;
02109 }
02110
02116 public function disableReminder()
02117 {
02118 $oDb = oxDb::getDb();
02119 return $oDb->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02120 }
02121
02127 public function save()
02128 {
02129 $this->_assignParentDependFields();
02130
02131 if ( ( $blRet = parent::save() ) ) {
02132
02133 $this->_saveArtLongDesc();
02134 }
02135
02136 return $blRet;
02137 }
02138
02144 public function resetParent()
02145 {
02146 $sParentId = $this->oxarticles__oxparentid->value;
02147 $this->oxarticles__oxparentid = new oxField( '', oxField::T_RAW );
02148 $this->_blAllowEmptyParentId = true;
02149 $this->save();
02150 $this->_blAllowEmptyParentId = false;
02151
02152 if ( $sParentId !== '' ) {
02153 $this->onChange( ACTION_UPDATE, null, $sParentId );
02154 }
02155 }
02156
02157
02164 public function getPictureGallery()
02165 {
02166 $myConfig = $this->getConfig();
02167
02168
02169 $blMorePic = false;
02170 $aArtPics = array();
02171 $aArtIcons = array();
02172 $iActPicId = 1;
02173 $sActPic = $this->getPictureUrl( $iActPicId );
02174
02175 if ( oxConfig::getParameter( 'actpicid' ) ) {
02176 $iActPicId = oxConfig::getParameter('actpicid');
02177 }
02178
02179 $oStr = getStr();
02180 $iCntr = 0;
02181 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02182 $blCheckActivePicId = true;
02183
02184 for ( $i = 1; $i <= $iPicCount; $i++) {
02185 $sPicVal = $this->getPictureUrl( $i );
02186 $sIcoVal = $this->getIconUrl( $i );
02187 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02188 !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02189 if ($iCntr) {
02190 $blMorePic = true;
02191 }
02192 $aArtIcons[$i]= $sIcoVal;
02193 $aArtPics[$i]= $sPicVal;
02194 $iCntr++;
02195
02196 if ($iActPicId == $i) {
02197 $sActPic = $sPicVal;
02198 $blCheckActivePicId = false;
02199 }
02200
02201 } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02202
02203
02204 $iActPicId++;
02205 }
02206 }
02207
02208 $blZoomPic = false;
02209 $aZoomPics = array();
02210 $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02211
02212 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02213 $sVal = $this->getZoomPictureUrl($j);
02214
02215 if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02216 $blZoomPic = true;
02217 $aZoomPics[$c]['id'] = $c;
02218 $aZoomPics[$c]['file'] = $sVal;
02219
02220 if (!$sVal) {
02221 $aZoomPics[$c]['file'] = "nopic.jpg";
02222 }
02223 $c++;
02224 }
02225 }
02226
02227 $aPicGallery = array('ActPicID' => $iActPicId,
02228 'ActPic' => $sActPic,
02229 'MorePics' => $blMorePic,
02230 'Pics' => $aArtPics,
02231 'Icons' => $aArtIcons,
02232 'ZoomPic' => $blZoomPic,
02233 'ZoomPics' => $aZoomPics);
02234
02235 return $aPicGallery;
02236 }
02237
02251 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02252 {
02253 $myConfig = $this->getConfig();
02254
02255 if (!isset($sOXID)) {
02256 if ( $this->getId()) {
02257 $sOXID = $this->getId();
02258 }
02259 if (!isset ($sOXID)) {
02260 $sOXID = $this->oxarticles__oxid->value;
02261 }
02262 if ($this->oxarticles__oxparentid->value) {
02263 $sParentID = $this->oxarticles__oxparentid->value;
02264 }
02265 }
02266 if (!isset($sOXID)) {
02267 return;
02268 }
02269
02270
02271 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02272
02273
02274 if (!isset($sParentID)) {
02275 $oDb = oxDb::getDb();
02276 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02277 $sParentID = $oDb->getOne( $sQ );
02278 }
02279
02280 if ($sParentID) {
02281 $this->_onChangeUpdateStock($sParentID);
02282 }
02283 }
02284
02285
02286 if ($sParentID) {
02287 $this->_onChangeUpdateVarCount($sParentID);
02288 }
02289
02290 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02291 $this->_setVarMinMaxPrice( $sId );
02292
02293 $this->_updateParentDependFields();
02294
02295
02296
02297 if ( $sAction === ACTION_UPDATE_STOCK ) {
02298 $this->_assignStock();
02299 $this->_onChangeStockResetCount( $sOXID );
02300 }
02301
02302 }
02303
02310 public function getCustomVAT()
02311 {
02312 if ( isset($this->oxarticles__oxvat->value) ) {
02313 return $this->oxarticles__oxvat->value;
02314 }
02315
02316 return null;
02317 }
02318
02327 public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02328 {
02329 $myConfig = $this->getConfig();
02330 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02331 return true;
02332 }
02333
02334 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
02335
02336 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.$oDb->quote( $this->getId() );
02337 $rs = $oDb->select( $sQ );
02338
02339 $iOnStock = 0;
02340 $iStockFlag = 0;
02341 if ( $rs !== false && $rs->recordCount() > 0 ) {
02342 $iOnStock = $rs->fields['oxstock'] - $dArtStockAmount;
02343 $iStockFlag = $rs->fields['oxstockflag'];
02344
02345
02346 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02347 return true;
02348 }
02349 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02350 $iOnStock = floor( $iOnStock );
02351 }
02352 }
02353 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02354 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02355 }
02356 if ( $iOnStock >= $dAmount ) {
02357 return true;
02358 } else {
02359 if ( $iOnStock > 0 ) {
02360 return $iOnStock;
02361 } else {
02362 $oEx = oxNew( 'oxArticleInputException' );
02363 $oEx->setMessage( 'ERROR_MESSAGE_ARTICLE_ARTICLE_NOT_BUYABLE' );
02364 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
02365 return false;
02366 }
02367 }
02368 }
02369
02370
02376 public function getLongDescription()
02377 {
02378 if ( $this->_oLongDesc === null ) {
02379
02380 $this->_oLongDesc = new oxField();
02381
02382
02383
02384 $sOxid = $this->getId();
02385 $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02386
02387 $oDb = oxDb::getDb();
02388 $sDbValue = $oDb->getOne( "select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote( $sOxid ) );
02389
02390 if ( $sDbValue != false ) {
02391 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02392 } elseif ( $this->oxarticles__oxparentid->value ) {
02393 if ( !$this->isAdmin() || $this->_blLoadParentData ) {
02394 $this->_oLongDesc->setValue( $this->getParentArticle()->getLongDescription()->getRawValue(), oxField::T_RAW );
02395 }
02396 }
02397 }
02398 return $this->_oLongDesc;
02399 }
02400
02407 public function getLongDesc()
02408 {
02409 return oxRegistry::get("oxUtilsView")->parseThroughSmarty( $this->getLongDescription()->getRawValue(), $this->getId().$this->getLanguage(), null, true );
02410 }
02411
02419 public function setArticleLongDesc( $sDesc )
02420 {
02421
02422
02423 $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02424 $this->oxarticles__oxlongdesc = new oxField( $sDesc, oxField::T_RAW );
02425
02426 return null;
02427 }
02428
02434 public function getAttributes()
02435 {
02436 if ( $this->_oAttributeList === null ) {
02437 $this->_oAttributeList = oxNew( 'oxattributelist' );
02438 $this->_oAttributeList->loadAttributes( $this->getId(), $this->getParentId() );
02439 }
02440
02441 return $this->_oAttributeList;
02442 }
02443
02449 public function getAttributesDisplayableInBasket()
02450 {
02451 if ( $this->_oAttributeList === null ) {
02452 $this->_oAttributeList = oxNew( 'oxattributelist' );
02453 $this->_oAttributeList->loadAttributesDisplayableInBasket( $this->getId(), $this->getParentId() );
02454 }
02455
02456 return $this->_oAttributeList;
02457 }
02458
02459
02468 public function appendLink( $sAddParams, $iLang = null )
02469 {
02470 if ( $sAddParams ) {
02471 if ( $iLang === null ) {
02472 $iLang = $this->getLanguage();
02473 }
02474
02475 $this->_aSeoAddParams[$iLang] = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&" : "";
02476 $this->_aSeoAddParams[$iLang] .= $sAddParams;
02477 }
02478 }
02479
02488 public function getBaseSeoLink( $iLang, $blMain = false )
02489 {
02490 $oEncoder = oxRegistry::get("oxSeoEncoderArticle");
02491 if ( !$blMain ) {
02492 return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02493 }
02494 return $oEncoder->getArticleMainUrl( $this, $iLang );
02495 }
02496
02505 public function getLink( $iLang = null, $blMain = false )
02506 {
02507 if ( !oxRegistry::getUtils()->seoIsActive() ) {
02508 return $this->getStdLink( $iLang );
02509 }
02510
02511 if ( $iLang === null ) {
02512 $iLang = $this->getLanguage();
02513 }
02514
02515 $iLinkType = $this->getLinkType();
02516 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02517 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02518 }
02519
02520 $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02521 if ( isset($this->_aSeoAddParams[$iLang])) {
02522 $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&' ).$this->_aSeoAddParams[$iLang];
02523 }
02524
02525 return $sUrl;
02526 }
02527
02536 public function getMainLink( $iLang = null )
02537 {
02538 return $this->getLink( $iLang, true );
02539 }
02540
02548 public function setLinkType( $iType )
02549 {
02550
02551 $this->_sDetailLink = null;
02552
02553
02554 $this->_iLinkType = (int) $iType;
02555 }
02556
02562 public function getLinkType()
02563 {
02564 return $this->_iLinkType;
02565 }
02566
02575 public function appendStdLink( $sAddParams, $iLang = null )
02576 {
02577 if ( $sAddParams ) {
02578 if ( $iLang === null ) {
02579 $iLang = $this->getLanguage();
02580 }
02581
02582 $this->_aStdAddParams[$iLang] = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&" : "";
02583 $this->_aStdAddParams[$iLang] .= $sAddParams;
02584 }
02585 }
02586
02596 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02597 {
02598 $sUrl = '';
02599 if ( $blFull ) {
02600
02601 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02602 }
02603
02604 $sUrl .= 'index.php?cl=details' . ( $blAddId ? '&anid=' . urlencode($this->getId()) : '' );
02605 return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? '&' . $this->_aStdAddParams[$iLang] : '' );
02606 }
02607
02616 public function getStdLink( $iLang = null, $aParams = array() )
02617 {
02618 if ( $iLang === null ) {
02619 $iLang = $this->getLanguage();
02620 }
02621
02622 if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02623 $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02624 }
02625
02626 return oxRegistry::get("oxUtilsUrl")->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02627 }
02628
02638 public function getStdTagLink( $sTag )
02639 {
02640 $oArticleTags = oxNew('oxarticletaglist');
02641 $oArticleTags->setArticleId( $this->getId() );
02642 return $oArticleTags->getStdTagLink($sTag);
02643 }
02644
02652 public function getTags()
02653 {
02654 $oArticleTags = oxNew('oxarticletaglist');
02655 $oArticleTags->load( $this->getId() );
02656 return $oArticleTags->get()->__toString();
02657 }
02658
02668 public function saveTags($sTags)
02669 {
02670
02671 if ( !$this->allowDerivedUpdate() ) {
02672 return false;
02673 }
02674 $oArticleTags = oxNew('oxarticletaglist');
02675 $oArticleTags->setArticleId( $this->getId() );
02676 $oArticleTags->set( $sTags );
02677 $oArticleTags->save();
02678 }
02679
02689 public function addTag($sTag)
02690 {
02691 $oArticleTags = oxNew('oxarticletaglist');
02692 $oArticleTags->load( $this->getId() );
02693 $oArticleTags->addTag( $sTag );
02694 if ( $oArticleTags->save() ) {
02695 return true;
02696 }
02697 return false;
02698 }
02699
02705 public function getMediaUrls()
02706 {
02707 if ( $this->_aMediaUrls === null ) {
02708 $this->_aMediaUrls = oxNew("oxlist");
02709 $this->_aMediaUrls->init("oxmediaurl");
02710 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02711
02712 $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02713 $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02714 $this->_aMediaUrls->selectString($sQ);
02715 }
02716 return $this->_aMediaUrls;
02717 }
02718
02724 public function getDynImageDir()
02725 {
02726 return $this->_sDynImageDir;
02727 }
02728
02734 public function getDispSelList()
02735 {
02736 if ($this->_aDispSelList === null) {
02737 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02738 $this->_aDispSelList = $this->getSelectLists();
02739 }
02740 }
02741 return $this->_aDispSelList;
02742 }
02743
02749 public function getMoreDetailLink()
02750 {
02751 if ( $this->_sMoreDetailLink == null ) {
02752
02753
02754 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02755
02756
02757 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02758 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02759 }
02760 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02761 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02762 }
02763
02764 return $this->_sMoreDetailLink;
02765 }
02766
02772 public function getToBasketLink()
02773 {
02774 if ( $this->_sToBasketLink == null ) {
02775 $myConfig = $this->getConfig();
02776
02777 if ( oxRegistry::getUtils()->isSearchEngine() ) {
02778 $this->_sToBasketLink = $this->getLink();
02779 } else {
02780
02781 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02782
02783
02784 $sActClass = oxConfig::getParameter( 'cl' );
02785 if ( $sActClass == 'thankyou') {
02786 $sActClass = 'basket';
02787 }
02788 $this->_sToBasketLink .= 'cl='.$sActClass;
02789
02790
02791 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02792 $this->_sToBasketLink .= '&cnid='.$sActCat;
02793 }
02794
02795 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02796
02797 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02798 $this->_sToBasketLink .= '&tpl='.$sTpl;
02799 }
02800 }
02801 }
02802
02803 return $this->_sToBasketLink;
02804 }
02805
02811 public function getStockStatus()
02812 {
02813 return $this->_iStockStatus;
02814 }
02815
02821 protected function _isStockStatusChanged()
02822 {
02823 return $this->_iStockStatus != $this->_iStockStatusOnLoad;
02824 }
02825
02831 protected function _isVisibilityChanged()
02832 {
02833 return $this->_isStockStatusChanged() && ($this->_iStockStatus == -1 || $this->_iStockStatusOnLoad == -1);
02834 }
02835
02841 public function getDeliveryDate()
02842 {
02843 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02844 return oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxarticles__oxdelivery->value);
02845 }
02846 return false;
02847 }
02848
02856 public function getFTPrice()
02857 {
02858
02859 if ( $oPrice = $this->getTPrice() ) {
02860 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
02861 return oxRegistry::getLang()->formatCurrency( $dPrice );
02862 }
02863 }
02864 }
02865
02873 public function getFPrice()
02874 {
02875 if ( $oPrice = $this->getPrice() ) {
02876 $dPrice = $this->_getPriceForView( $oPrice );
02877 return oxRegistry::getLang()->formatCurrency( $dPrice );
02878 }
02879 }
02880
02887 public function resetRemindStatus()
02888 {
02889 if ( $this->oxarticles__oxremindactive->value == 2 &&
02890 $this->oxarticles__oxremindamount->value <= $this->oxarticles__oxstock->value ) {
02891 $this->oxarticles__oxremindactive->value = 1;
02892 }
02893
02894 return null;
02895 }
02896
02904 public function getFNetPrice()
02905 {
02906 if ( $oPrice = $this->getPrice() ) {
02907 return oxRegistry::getLang()->formatCurrency( $oPrice->getNettoPrice() );
02908 }
02909 }
02910
02918 public function getPricePerUnit()
02919 {
02920 return $this->getFUnitPrice();
02921 }
02922
02928 public function isParentNotBuyable()
02929 {
02930 return $this->_blNotBuyableParent;
02931 }
02932
02938 public function isNotBuyable()
02939 {
02940 return $this->_blNotBuyable;
02941 }
02942
02950 public function setBuyableState( $blBuyable = false )
02951 {
02952 $this->_blNotBuyable = !$blBuyable;
02953 }
02954
02962 public function setSelectlist( $aSelList )
02963 {
02964 $this->_aDispSelList = $aSelList;
02965 }
02966
02974 public function getPictureUrl( $iIndex = 1 )
02975 {
02976 if ( $iIndex ) {
02977 $sImgName = false;
02978 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02979 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02980 }
02981
02982 $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02983 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02984 }
02985 }
02986
02995 public function getIconUrl( $iIndex = 0 )
02996 {
02997 $sImgName = false;
02998 $sDirname = "product/1/";
02999 if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
03000 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
03001 $sDirname = "product/{$iIndex}/";
03002 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
03003 $sImgName = basename( $this->oxarticles__oxicon->value );
03004 $sDirname = "product/icon/";
03005 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
03006 $sImgName = basename( $this->oxarticles__oxpic1->value );
03007 }
03008
03009 $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
03010 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
03011 }
03012
03020 public function getThumbnailUrl( $bSsl = null )
03021 {
03022 $sImgName = false;
03023 $sDirname = "product/1/";
03024 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
03025 $sImgName = basename( $this->oxarticles__oxthumb->value );
03026 $sDirname = "product/thumb/";
03027 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
03028 $sImgName = basename( $this->oxarticles__oxpic1->value );
03029 }
03030
03031 $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
03032 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
03033 }
03034
03042 public function getZoomPictureUrl( $iIndex = '' )
03043 {
03044 $iIndex = (int) $iIndex;
03045 if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
03046 $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
03047 $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
03048 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
03049 }
03050 }
03051
03059 public function getFileUrl()
03060 {
03061 return $this->getConfig()->getPictureUrl( 'media/' );
03062 }
03063
03071 public function getPriceFromPrefix()
03072 {
03073 $sPricePrefix = '';
03074 if ( $this->_blIsRangePrice) {
03075 $sPricePrefix = oxLang::getInstance()->translateString('PRICE_FROM').' ';
03076 }
03077
03078 return $sPricePrefix;
03079 }
03080
03086 protected function _saveArtLongDesc()
03087 {
03088 $myConfig = $this->getConfig();
03089 $sShopId = $myConfig->getShopID();
03090 if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
03091 return;
03092 }
03093
03094 if ($this->_blEmployMultilanguage) {
03095 $sValue = $this->getLongDescription()->getRawValue();
03096 if ( $sValue !== null ) {
03097 $oArtExt = oxNew('oxI18n');
03098 $oArtExt->init('oxartextends');
03099 $oArtExt->setLanguage((int) $this->getLanguage());
03100 if (!$oArtExt->load($this->getId())) {
03101 $oArtExt->setId($this->getId());
03102 }
03103 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
03104 $oArtExt->save();
03105 }
03106 } else {
03107 $oArtExt = oxNew('oxI18n');
03108 $oArtExt->setEnableMultilang(false);
03109 $oArtExt->init('oxartextends');
03110 $aObjFields = $oArtExt->_getAllFields(true);
03111 if (!$oArtExt->load($this->getId())) {
03112 $oArtExt->setId($this->getId());
03113 }
03114
03115 foreach ($aObjFields as $sKey => $sValue ) {
03116 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
03117 $sField = $this->_getFieldLongName($sKey);
03118
03119 if (isset($this->$sField)) {
03120 $sLongDesc = null;
03121 if ($this->$sField instanceof oxField) {
03122 $sLongDesc = $this->$sField->getRawValue();
03123 } elseif (is_object($this->$sField)) {
03124 $sLongDesc = $this->$sField->value;
03125 }
03126 if (isset($sLongDesc)) {
03127 $sAEField = $oArtExt->_getFieldLongName($sKey);
03128 $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
03129 }
03130 }
03131 }
03132 }
03133 $oArtExt->save();
03134 }
03135 }
03136
03142 protected function _skipSaveFields()
03143 {
03144 $myConfig = $this->getConfig();
03145
03146 $this->_aSkipSaveFields = array();
03147
03148 $this->_aSkipSaveFields[] = 'oxtimestamp';
03149
03150 $this->_aSkipSaveFields[] = 'oxinsert';
03151
03152 if ( !$this->_blAllowEmptyParentId && (!isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') ) {
03153 $this->_aSkipSaveFields[] = 'oxparentid';
03154 }
03155
03156 }
03157
03167 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03168 {
03169 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03170
03171 if ( array_key_exists ($sKey, $aDiscounts) ) {
03172 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03173 } else {
03174 $aDiscounts[$sKey] = $oDiscount;
03175 }
03176 }
03177 return $aDiscounts;
03178 }
03179
03185 protected function _getGroupPrice()
03186 {
03187 $sPriceSufix = $this->_getUserPriceSufix();
03188 $sVarName = "oxarticles__oxprice{$sPriceSufix}";
03189 $dPrice = $this->$sVarName->value;
03190
03191
03192 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03193 $dPrice = $this->oxarticles__oxprice->value;
03194 }
03195
03196 return $dPrice;
03197 }
03198
03207 protected function _getAmountPrice($dAmount = 1)
03208 {
03209 startProfile( "_getAmountPrice" );
03210
03211 $dPrice = $this->_getGroupPrice();
03212 $oAmtPrices = $this->_getAmountPriceList();
03213 foreach ($oAmtPrices as $oAmPrice) {
03214 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03215 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03216 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03217 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03218 }
03219 }
03220
03221 stopProfile( "_getAmountPrice" );
03222 return $dPrice;
03223 }
03224
03233 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03234 {
03235 $myConfig = $this->getConfig();
03236
03237 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03238
03239 $aSelLists = $this->getSelectLists();
03240
03241 foreach ( $aSelLists as $key => $aSel) {
03242 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03243 $oSel = $aSel[$aChosenList[$key]];
03244 if ( $oSel->priceUnit =='abs' ) {
03245 $dPrice += $oSel->price;
03246 } elseif ( $oSel->priceUnit =='%' ) {
03247 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03248 }
03249 }
03250 }
03251 }
03252 return $dPrice;
03253 }
03254
03255
03263 protected function _fillAmountPriceList($aAmPriceList)
03264 {
03265 $oLang = oxRegistry::getLang();
03266
03267
03268 foreach ($aAmPriceList as $sId => $oItem) {
03269
03270 $oItemPrice = $this->_getPriceObject();
03271 if ( $oItem->oxprice2article__oxaddabs->value ) {
03272
03273 $dBasePrice = $oItem->oxprice2article__oxaddabs->value;
03274 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03275
03276 $oItemPrice->setPrice( $dBasePrice );
03277 $this->_calculatePrice( $oItemPrice );
03278
03279 } else {
03280 $dBasePrice = $this->_getGroupPrice();
03281 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03282 $oItemPrice->setPrice( $dBasePrice );
03283 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03284 }
03285
03286
03287 $aAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $this->_getPriceForView( $oItemPrice ) );
03288 }
03289
03290 return $aAmPriceList;
03291 }
03292
03293
03299 protected function _getVariantsIds()
03300 {
03301 $aSelect = array();
03302 if ( ( $sId = $this->getId() ) ) {
03303 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03304 $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03305 $this->getSqlActiveSnippet( true ) . " order by oxsort";
03306 $oRs = $oDb->select( $sQ );
03307 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03308 while (!$oRs->EOF) {
03309 $aSelect[] = reset( $oRs->fields );
03310 $oRs->moveNext();
03311 }
03312 }
03313 }
03314 return $aSelect;
03315 }
03316
03322 public function getArticleVat()
03323 {
03324 if (!isset($this->_dArticleVat)) {
03325 $this->_dArticleVat = oxRegistry::get("oxVatSelector")->getArticleVat( $this );
03326 }
03327 return $this->_dArticleVat;
03328 }
03329
03338 protected function _applyVAT( oxPrice $oPrice, $dVat )
03339 {
03340 startProfile(__FUNCTION__);
03341 $oPrice->setVAT( $dVat );
03342 if ( ($dVat = oxRegistry::get("oxVatSelector")->getArticleUserVat($this)) !== false ) {
03343 $oPrice->setUserVat( $dVat );
03344 }
03345 stopProfile(__FUNCTION__);
03346 }
03347
03355 public function applyVats( oxPrice $oPrice )
03356 {
03357 $this->_applyVAT($oPrice, $this->getArticleVat() );
03358 }
03359
03367 public function applyDiscountsForVariant( $oPrice )
03368 {
03369
03370 if ( !$this->skipDiscounts() ) {
03371 $oDiscountList = oxRegistry::get("oxDiscountList");
03372 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
03373
03374 reset( $aDiscounts );
03375 foreach ( $aDiscounts as $oDiscount ) {
03376 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
03377 }
03378 $oPrice->calculateDiscount();
03379 }
03380 }
03381
03390 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03391 {
03392 if ( !$oCur ) {
03393 $oCur = $this->getConfig()->getActShopCurrencyObject();
03394 }
03395
03396 $oPrice->multiply($oCur->rate);
03397 }
03398
03399
03408 protected function _getAttribsString(&$sAttribs, &$iCnt)
03409 {
03410
03411 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03412 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03413 $sAttribs = '';
03414 $blSep = false;
03415 $rs = $oDb->select( $sSelect);
03416 $iCnt = 0;
03417 if ($rs != false && $rs->recordCount() > 0) {
03418 while (!$rs->EOF) {
03419 if ( $blSep) {
03420 $sAttribs .= ' or ';
03421 }
03422 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03423 $blSep = true;
03424 $iCnt++;
03425 $rs->moveNext();
03426 }
03427 }
03428 }
03429
03438 protected function _getSimList($sAttribs, $iCnt)
03439 {
03440 $myConfig = $this->getConfig();
03441 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03442
03443
03444 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03445
03446 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03447 $iAttrPercent = 0.70;
03448 }
03449
03450 $iHitMin = ceil( $iCnt * $iAttrPercent );
03451
03452
03453 $aList= array();
03454 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03455 ( $sAttribs )
03456 and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03457 group by t1.oxobjectid having count(*) >= $iHitMin ";
03458
03459 $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03460 if ($rs != false && $rs->recordCount() > 0) {
03461 while (!$rs->EOF) {
03462 $oTemp = new stdClass();
03463 $oTemp->cnt = $rs->fields['cnt'];
03464 $oTemp->id = $rs->fields['oxobjectid'];
03465 $aList[] = $oTemp;
03466 $rs->moveNext();
03467 }
03468 }
03469 return $aList;
03470 }
03471
03480 protected function _generateSimListSearchStr($sArticleTable, $aList)
03481 {
03482 $myConfig = $this->getConfig();
03483 $sFieldList = $this->getSelectFields();
03484 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03485 $blSep = false;
03486 $iCnt = 0;
03487 $oDb = oxDb::getDb();
03488 foreach ( $aList as $oTemp) {
03489 if ( $blSep) {
03490 $sSearch .= ',';
03491 }
03492 $sSearch .= $oDb->quote($oTemp->id);
03493 $blSep = true;
03494 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03495 break;
03496 }
03497 $iCnt++;
03498 }
03499
03500
03501
03502 $sSearch .= ') ';
03503
03504
03505 $sSearch .= ' order by rand() ';
03506
03507 return $sSearch;
03508 }
03509
03518 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03519 {
03520
03521 $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03522 $sO2CView = getViewName( 'oxobject2category' );
03523
03524
03525 if ( !$blSearchPriceCat ) {
03526 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03527 {$sCatView}.oxid = oxobject2category.oxcatnid
03528 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03529 } else {
03530 $sSelect = "select {$sCatView}.* from {$sCatView} where
03531 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03532 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03533 }
03534 return $sSelect;
03535 }
03536
03542 protected function _generateSearchStrForCustomerBought()
03543 {
03544 $sArtTable = $this->getViewName();
03545 $sOrderArtTable = getViewName( 'oxorderarticles' );
03546
03547
03548 $sIn = " '{$this->oxarticles__oxid->value}' ";
03549 if ( $this->oxarticles__oxparentid->value ) {
03550
03551
03552 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03553 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03554
03555 } else {
03556 $sParentIdForVariants = $this->getId();
03557 }
03558
03559
03560 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03561 $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03562 if ( $oRs != false && $oRs->recordCount() > 0) {
03563 while ( !$oRs->EOF ) {
03564 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03565 $oRs->moveNext();
03566 }
03567 }
03568
03569 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03570 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03571
03572
03573 $sQ = "select distinct {$sArtTable}.* from (
03574 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03575 ) as suborder
03576 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03577 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03578 where {$sArtTable}.oxid not in ( {$sIn} )
03579 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03580
03581
03582
03583
03584
03585
03586
03587
03588
03589
03590 return $sQ;
03591 }
03592
03602 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03603 {
03604 $sCategoryView = getViewName('oxcategories');
03605 $sO2CView = getViewName('oxobject2category');
03606
03607 $oDb = oxDb::getDb();
03608 $sOXID = $oDb->quote($sOXID);
03609 $sCatId = $oDb->quote($sCatId);
03610
03611 if (!$dPriceFromTo) {
03612 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03613 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03614 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03615 $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03616 } else {
03617 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03618 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03619 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03620 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03621 }
03622 return $sSelect;
03623 }
03624
03630 protected function _getAmountPriceList()
03631 {
03632 if ( $this->_oAmountPriceList === null ) {
03633 $oAmPriceList = oxNew( 'oxAmountPricelist' );
03634
03635 if ( !$this->skipDiscounts() ) {
03636
03637 $oAmPriceList->load( $this );
03638
03639
03640 $oBasePrice = $this->_getGroupPrice();
03641 foreach ( $oAmPriceList as $oAmPrice ) {
03642 if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03643 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03644 }
03645 }
03646
03647 }
03648
03649 $this->_oAmountPriceList = $oAmPriceList;
03650 }
03651
03652 return $this->_oAmountPriceList;
03653 }
03654
03662 protected function _isFieldEmpty( $sFieldName )
03663 {
03664 $mValue = $this->$sFieldName->value;
03665
03666 if ( is_null( $mValue ) ) {
03667 return true;
03668 }
03669
03670 if ( $mValue === '' ) {
03671 return true;
03672 }
03673
03674
03675 $aZeroValueFields = array('oxarticles__oxprice', 'oxarticles__oxvat', 'oxarticles__oxunitquantity');
03676
03677 if (!$mValue && in_array( $sFieldName, $aZeroValueFields ) ) {
03678 return true;
03679 }
03680
03681
03682 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03683 return true;
03684 }
03685
03686 $sFieldName = strtolower($sFieldName);
03687
03688 if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03689 return true;
03690 }
03691
03692 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03693 return true;
03694 }
03695
03696 return false;
03697 }
03698
03706 protected function _isImageField($sFieldName)
03707 {
03708 $blIsImageField = ( stristr($sFieldName, '_oxthumb') || stristr($sFieldName, '_oxicon') || stristr($sFieldName, '_oxzoom') || stristr($sFieldName, '_oxpic') );
03709 return $blIsImageField;
03710 }
03711
03719 protected function _assignParentFieldValue($sFieldName)
03720 {
03721 if (!($oParentArticle = $this->getParentArticle())) {
03722 return;
03723 }
03724
03725 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03726
03727
03728 if ( $oParentArticle->$sCopyFieldName != null ) {
03729
03730
03731 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03732 return;
03733 }
03734
03735
03736 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03737 return;
03738 }
03739
03740
03741 if ($this->_isFieldEmpty($sCopyFieldName) && $this->_isImageField($sCopyFieldName) && $this->_hasMasterImage( 1 )) {
03742 return;
03743 }
03744
03745
03746 if ( $this->_isFieldEmpty($sCopyFieldName) ) {
03747 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03748 }
03749 }
03750 }
03751
03757 public function getParentArticle()
03758 {
03759 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03760 $sIndex = $sParentId . "_" . $this->getLanguage();
03761 if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03762 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03763 self::$_aLoadedParents[$sIndex]->_blLoadPrice = false;
03764 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03765 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03766 }
03767 return self::$_aLoadedParents[$sIndex];
03768 }
03769 }
03770
03776 protected function _assignParentFieldValues()
03777 {
03778 startProfile('articleAssignParentInternal');
03779 if ( $this->oxarticles__oxparentid->value ) {
03780
03781 if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03782 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03783 $this->_assignParentFieldValue( $sFieldName );
03784 }
03785 }
03786 }
03787 stopProfile('articleAssignParentInternal');
03788 }
03789
03795 protected function _assignNotBuyableParent()
03796 {
03797 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03798 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03799 $this->_blNotBuyableParent = true;
03800
03801 }
03802 }
03803
03809 protected function _assignStock()
03810 {
03811 $myConfig = $this->getConfig();
03812
03813
03814
03815
03816
03817 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03818 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03819 }
03820
03821 $this->_iStockStatus = 0;
03822
03823
03824 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03825
03826 $iStock = $this->oxarticles__oxstock->value;
03827
03828 if ($this->_blNotBuyableParent) {
03829 $iStock = $this->oxarticles__oxvarstock->value;
03830 }
03831
03832
03833 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03834 $this->_iStockStatus = 1;
03835 }
03836
03837
03838 if ($iStock <= 0) {
03839 $this->_iStockStatus = -1;
03840 }
03841 }
03842
03843
03844
03845 if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03846 $iOnStock = $this->oxarticles__oxstock->value;
03847 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03848 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03849 }
03850 if ($iOnStock <= 0) {
03851 $this->setBuyableState( false );
03852 }
03853 }
03854
03855
03856 if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03857 $this->setBuyableState( true );
03858
03859 $this->_blNotBuyableParent = true;
03860 }
03861
03862
03863
03864
03865 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03866 $this->setBuyableState( false );
03867 }
03868
03869
03870 if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03871 $this->setBuyableState( false );
03872 }
03873 }
03874
03882 protected function _assignPrices()
03883 {
03884 $myConfig = $this->getConfig();
03885
03886
03887 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03888 return;
03889 }
03890
03891
03892 if ( $this->_hasAnyVariant() ) {
03893 $this->_applyRangePrice();
03894 }
03895 }
03896
03902 protected function _assignPersistentParam()
03903 {
03904
03905 $aPersParam = oxSession::getVar( 'persparam');
03906 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03907 $this->_aPersistParam = $aPersParam[$this->getId()];
03908 }
03909 }
03910
03916 protected function _assignDynImageDir()
03917 {
03918 $myConfig = $this->getConfig();
03919
03920 $sThisShop = $this->oxarticles__oxshopid->value;
03921
03922 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03923 $this->dabsimagedir = $myConfig->getPictureDir( false );
03924 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03925 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03926 }
03927
03933 protected function _assignComparisonListFlag()
03934 {
03935
03936
03937 $aItems = oxSession::getVar('aFiltcompproducts');
03938 if ( isset( $aItems[$this->getId()])) {
03939 $this->_blIsOnComparisonList = true;
03940 }
03941 }
03942
03943
03951 protected function _insert()
03952 {
03953
03954 $sNow = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
03955 $this->oxarticles__oxinsert = new oxField( $sNow );
03956 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03957 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03958 }
03959
03960 return parent::_insert();
03961 }
03962
03968 protected function _update()
03969 {
03970
03971 $this->_skipSaveFields();
03972
03973 $myConfig = $this->getConfig();
03974
03975
03976 $blRes = parent::_update();
03977
03978
03979 return $blRes;
03980 }
03981
03987 public function updateVariantsRemind()
03988 {
03989
03990 if ( !$this->isVariant() && $this->_hasAnyVariant()) {
03991 $oDb = oxDb::getDb();
03992 $sOxId = $oDb->quote($this->getId());
03993 $sOxShopId = $oDb->quote($this->getShopId());
03994 $iRemindActive = $oDb->quote($this->oxarticles__oxremindactive->value);
03995 $sUpdate = "
03996 update oxarticles
03997 set oxremindactive = $iRemindActive
03998 where oxparentid = $sOxId and
03999 oxshopid = $sOxShopId
04000 ";
04001 $oDb->execute( $sUpdate );
04002 }
04003 }
04004
04012 protected function _deleteRecords($sOXID)
04013 {
04014 $oDb = oxDb::getDb();
04015
04016 $sOXID = $oDb->quote($sOXID);
04017
04018
04019 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
04020 $oDb->execute( $sDelete);
04021
04022 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
04023 $oDb->execute( $sDelete);
04024
04025 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
04026 $oDb->execute( $sDelete);
04027
04028 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
04029 $oDb->execute( $sDelete);
04030
04031 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
04032 $oDb->execute( $sDelete);
04033
04034 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
04035 $oDb->execute( $sDelete);
04036
04037 $sDelete = 'delete from oxratings where oxobjectid = '.$sOXID.' ';
04038 $rs = $oDb->execute( $sDelete );
04039
04040 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
04041 $oDb->execute( $sDelete);
04042
04043
04044 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04045 $oDb->execute( $sDelete);
04046
04047 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04048 $oDb->execute( $sDelete);
04049
04050
04051 foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
04052 $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
04053 }
04054
04055 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04056 $rs = $oDb->execute( $sDelete );
04057
04058 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04059 $rs = $oDb->execute( $sDelete );
04060
04061
04062 return $rs;
04063 }
04064
04072 protected function _deleteVariantRecords( $sOXID )
04073 {
04074 if ( $sOXID ) {
04075 $oDb = oxDb::getDb();
04076
04077 $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
04078 $rs = $oDb->select( $sQ, false, false );
04079 $oArticle = oxNew("oxArticle");
04080 if ($rs != false && $rs->recordCount() > 0) {
04081 while (!$rs->EOF) {
04082 $oArticle->setId($rs->fields[0]);
04083 $oArticle->delete();
04084 $rs->moveNext();
04085 }
04086 }
04087 }
04088 }
04089
04095 protected function _deletePics()
04096 {
04097 $myUtilsPic = oxRegistry::get("oxUtilsPic");
04098 $myConfig = $this->getConfig();
04099 $oPictureHandler = oxRegistry::get("oxPictureHandler");
04100
04101
04102 $oPictureHandler->deleteMainIcon( $this );
04103
04104
04105 $oPictureHandler->deleteThumbnail( $this );
04106
04107 $sAbsDynImageDir = $myConfig->getPictureDir(false);
04108
04109
04110 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04111 for ( $i = 1; $i <= $iPicCount; $i++ ) {
04112 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04113 }
04114 }
04115
04125 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04126 {
04127
04128 $myUtilsCount = oxRegistry::get("oxUtilsCount");
04129
04130 if ( $sVendorId ) {
04131 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04132 }
04133
04134 if ( $sManufacturerId ) {
04135 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04136 }
04137
04138
04139 $oDb = oxDb::getDb();
04140 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04141 $oRs = $oDb->select( $sQ, false, false );
04142 if ( $oRs !== false && $oRs->recordCount() > 0) {
04143 while ( !$oRs->EOF ) {
04144 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04145 $oRs->moveNext();
04146 }
04147 }
04148 }
04149
04157 protected function _onChangeUpdateStock( $sParentID )
04158 {
04159 if ( $sParentID ) {
04160 $oDb = oxDb::getDb();
04161 $sParentIdQuoted = $oDb->quote($sParentID);
04162 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04163 $rs = $oDb->select( $sQ, false, false );
04164 $iOldStock = $rs->fields[0];
04165 $iVendorID = $rs->fields[1];
04166 $iManufacturerID = $rs->fields[2];
04167
04168 $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04169 $iStock = (float) $oDb->getOne( $sQ, false, false );
04170
04171 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04172 $oDb->execute( $sQ );
04173
04174
04175
04176 if ( $iStock < 0 ) {
04177 $iStock = 0;
04178 }
04179 if ( $iOldStock < 0 ) {
04180 $iOldStock = 0;
04181 }
04182 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04183
04184
04185 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04186 }
04187 }
04188 }
04189
04197 protected function _onChangeStockResetCount( $sOxid )
04198 {
04199 $myConfig = $this->getConfig();
04200
04201 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04202 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04203
04204 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04205 }
04206 }
04207
04215 protected function _onChangeUpdateVarCount( $sParentID )
04216 {
04217 if ( $sParentID ) {
04218 $oDb = oxDb::getDb();
04219 $sParentIdQuoted = $oDb->quote( $sParentID );
04220 $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04221 $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04222
04223 $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04224 $oDb->execute( $sQ );
04225 }
04226 }
04227
04235 protected function _setVarMinMaxPrice( $sParentId )
04236 {
04237 if ( $sParentId ) {
04238 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
04239 $sQ = '
04240 SELECT
04241 MIN( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varminprice`,
04242 MAX( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varmaxprice`
04243 FROM '. $this->getViewName(true) . ' AS `oxarticles`
04244 LEFT JOIN '. $this->getViewName(true) . ' AS `p` ON ( `p`.`oxid` = `oxarticles`.`oxparentid` AND `p`.`oxprice` > 0 )
04245 WHERE '. $this->getSqlActiveSnippet(true) .'
04246 AND ( `oxarticles`.`oxparentid` = '. $oDb->quote( $sParentId ) .' )';
04247 $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
04248 $aPrices = $oDb->getRow( $sQ, false, false );
04249 if ( !is_null( $aPrices['varminprice'] ) || !is_null( $aPrices['varmaxprice'] ) ) {
04250 $sQ = '
04251 UPDATE `oxarticles`
04252 SET
04253 `oxvarminprice` = '. $oDb->quote( $aPrices['varminprice'] ) .',
04254 `oxvarmaxprice` = '. $oDb->quote( $aPrices['varmaxprice'] ) .'
04255 WHERE
04256 `oxid` = ' . $oDb->quote( $sParentId );
04257 } else {
04258 $sQ = '
04259 UPDATE `oxarticles`
04260 SET
04261 `oxvarminprice` = `oxprice`,
04262 `oxvarmaxprice` = `oxprice`
04263 WHERE
04264 `oxid` = ' . $oDb->quote( $sParentId );
04265 }
04266 $oDb->execute( $sQ );
04267 }
04268 }
04269
04270
04280 protected function _onChangeUpdateMinVarPrice( $sParentID )
04281 {
04282 if ( $sParentID ) {
04283 $oDb = oxDb::getDb();
04284 $sParentIdQuoted = $oDb->quote($sParentID);
04285
04286 $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04287 $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04288
04289 $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04290
04291 $blParentBuyable = $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04292
04293 if ($dVarMinPrice) {
04294 if ($blParentBuyable) {
04295 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04296 }
04297 } else {
04298 $dVarMinPrice = $dParentPrice;
04299 }
04300
04301 if ( $dVarMinPrice ) {
04302 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04303 $oDb->execute($sQ);
04304 }
04305 }
04306 }
04307
04308
04316 protected function _applyRangePrice()
04317 {
04318
04319 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04320 return;
04321 }
04322
04323 $this->_blIsRangePrice = false;
04324
04325
04326 if ($this->_blSkipFromPrice || !$this->_blNotBuyableParent) {
04327 return;
04328 }
04329
04330 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04331
04332 $dPrice = $this->_preparePrice( $this->oxarticles__oxvarminprice->value, $this->getArticleVat() );
04333 $this->getPrice()->setPrice($dPrice);
04334 $this->_blIsRangePrice = true;
04335 $this->_calculatePrice( $this->getPrice() );
04336 return;
04337
04338 }
04339
04340 $aPrices = array();
04341
04342 if (!$this->_blNotBuyableParent) {
04343 $aPrices[] = $this->getPrice()->getPrice();
04344 }
04345
04346 $aVariants = $this->getVariants(false);
04347
04348 if (count($aVariants)) {
04349 foreach ($aVariants as $sKey => $oVariant) {
04350 $aPrices[] = $oVariant->getPrice()->getPrice();
04351 }
04352 }
04353
04354 if ( count( $aPrices ) ) {
04355 $dMinPrice = min( $aPrices );
04356 $dMaxPrice = max( $aPrices );
04357 }
04358
04359 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04360 $this->getPrice()->setPrice($dMinPrice);
04361 }
04362
04363 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04364 $this->getPrice()->setPrice($dMinPrice);
04365 $this->_blIsRangePrice = true;
04366 }
04367 }
04368
04375 public function getProductId()
04376 {
04377 return $this->getId();
04378 }
04379
04387 public function getProductParentId()
04388 {
04389 return $this->getParentId();
04390 }
04391
04397 public function getParentId()
04398 {
04399 return $this->oxarticles__oxparentid->value;
04400 }
04401
04407 public function isOrderArticle()
04408 {
04409 return false;
04410 }
04411
04417 public function isVariant()
04418 {
04419 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04420 }
04421
04427 public function isMdVariant()
04428 {
04429 $oMdVariant = oxNew( "oxVariantHandler" );
04430
04431 return $oMdVariant->isMdVariant($this);
04432 }
04433
04441 public function getSqlForPriceCategories($sFields = '')
04442 {
04443 if (!$sFields) {
04444 $sFields = 'oxid';
04445 }
04446 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04447 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04448 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04449 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04450 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04451 }
04452
04460 public function inPriceCategory( $sCatNid )
04461 {
04462 $oDb = oxDb::getDb();
04463
04464 $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04465 $sQuotedCnid = $oDb->quote( $sCatNid );
04466 return (bool) $oDb->getOne(
04467 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04468 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04469 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04470 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04471 .")"
04472 );
04473 }
04474
04480 public function getMdVariants()
04481 {
04482 if ( $this->_oMdVariants ) {
04483 return $this->_oMdVariants;
04484 }
04485
04486 $oParentArticle = $this->getParentArticle();
04487 if ( $oParentArticle ) {
04488 $oVariants = $oParentArticle->getVariants();
04489 } else {
04490 $oVariants = $this->getVariants();
04491 }
04492
04493 $oVariantHandler = oxNew( "oxVariantHandler" );
04494 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04495
04496 return $this->_oMdVariants;
04497 }
04498
04504 public function getMdSubvariants()
04505 {
04506 return $this->getMdVariants()->getMdSubvariants();
04507 }
04508
04516 protected function _hasMasterImage( $iIndex )
04517 {
04518 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04519
04520 if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04521 return false;
04522 }
04523 if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04524 return false;
04525 }
04526
04527 $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04528
04529 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04530 return true;
04531 }
04532
04533 return false;
04534 }
04535
04544 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04545 {
04546 if ( $sFieldName ) {
04547 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04548 return $this->$sFieldName->value;
04549 }
04550 }
04551
04559 public function getMasterZoomPictureUrl( $iIndex )
04560 {
04561 $sPicUrl = false;
04562 $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04563
04564 if ( $sPicName && $sPicName != "nopic.jpg" ) {
04565 $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04566 if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04567 $sPicUrl = false;
04568 }
04569 }
04570
04571 return $sPicUrl;
04572 }
04573
04579 public function getUnitName()
04580 {
04581 if ( $this->oxarticles__oxunitname->value ) {
04582 return oxRegistry::getLang()->translateString( $this->oxarticles__oxunitname->value );
04583 }
04584 }
04585
04593 public function getArticleFiles( $blAddFromParent=false )
04594 {
04595 if ( $this->_aArticleFiles === null) {
04596
04597 $this->_aArticleFiles = false;
04598
04599 $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04600
04601 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04602 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04603 }
04604
04605 $oArticleFiles = oxNew("oxlist");
04606 $oArticleFiles->init("oxfile");
04607 $oArticleFiles->selectString( $sQ );
04608 $this->_aArticleFiles = $oArticleFiles;
04609
04610 }
04611
04612 return $this->_aArticleFiles;
04613 }
04614
04620 public function isDownloadable()
04621 {
04622 return $this->oxarticles__oxisdownloadable->value;
04623 }
04624
04630 public function hasAmountPrice()
04631 {
04632 if ( self::$_blHasAmountPrice === null ) {
04633
04634 self::$_blHasAmountPrice = false;
04635
04636 $oDb = oxDb::getDb();
04637 $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04638
04639 if ( $oDb->getOne( $sQ ) ) {
04640 self::$_blHasAmountPrice = true;
04641 }
04642 }
04643
04644 return self::$_blHasAmountPrice;
04645 }
04646
04647
04653 protected function _isPriceViewModeNetto()
04654 {
04655 $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
04656 $oUser = $this->getArticleUser();
04657 if ( $oUser ) {
04658 $blResult = $oUser->isPriceViewModeNetto();
04659 }
04660
04661 return $blResult;
04662 }
04663
04664
04672 protected function _getPriceObject( $blCalculationModeNetto = null )
04673 {
04674 $oPrice = oxNew( 'oxPrice' );
04675
04676 if ( $blCalculationModeNetto === null ) {
04677 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04678 }
04679
04680 if ( $blCalculationModeNetto ) {
04681 $oPrice->setNettoPriceMode();
04682 } else {
04683 $oPrice->setBruttoPriceMode();
04684 }
04685
04686 return $oPrice;
04687 }
04688
04689
04697 protected function _getPriceForView( $oPrice )
04698 {
04699 if ( $this->_isPriceViewModeNetto() ) {
04700 $dPrice = $oPrice->getNettoPrice();
04701 } else {
04702 $dPrice = $oPrice->getBruttoPrice();
04703 }
04704
04705 return $dPrice;
04706 }
04707
04708
04718 protected function _preparePrice( $dPrice, $dVat, $blCalculationModeNetto = null )
04719 {
04720 if ( $blCalculationModeNetto === null ) {
04721 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04722 }
04723
04724 $oCurrency = $this->getConfig()->getActShopCurrencyObject();
04725
04726 $blEnterNetPrice = $this->getConfig()->getConfigParam('blEnterNetPrice');
04727 if ( $blCalculationModeNetto && !$blEnterNetPrice ) {
04728 $dPrice = round( oxPrice::brutto2Netto( $dPrice, $dVat ), $oCurrency->decimal );
04729 } elseif ( !$blCalculationModeNetto && $blEnterNetPrice ) {
04730 $dPrice = round( oxPrice::netto2Brutto( $dPrice, $dVat ), $oCurrency->decimal );
04731 }
04732
04733 return $dPrice;
04734 }
04735
04736
04743 public function getFUnitPrice()
04744 {
04745 if ($this->_fPricePerUnit == null) {
04746 if ( $oPrice = $this->getUnitPrice() ) {
04747 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
04748 $this->_fPricePerUnit = oxRegistry::getLang()->formatCurrency( $dPrice );
04749 }
04750 }
04751 }
04752
04753 return $this->_fPricePerUnit;
04754 }
04755
04756
04762 public function getUnitPrice()
04763 {
04764
04765 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04766 return;
04767 }
04768
04769 $oPrice = null;
04770 if ( (double) $this->getUnitQuantity() && $this->oxarticles__oxunitname->value ) {
04771 $oPrice = clone $this->getPrice();
04772 $oPrice->divide( (double) $this->getUnitQuantity() );
04773 }
04774
04775 return $oPrice;
04776 }
04777
04778
04786 public function getFMinPrice()
04787 {
04788 $sPrice = '';
04789 if ( $oPrice = $this->getMinPrice() ) {
04790 $dPrice = $this->_getPriceForView( $oPrice );
04791 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04792 }
04793
04794 return $sPrice;
04795 }
04796
04804 public function getFVarMinPrice()
04805 {
04806 $sPrice = '';
04807 if ( $oPrice = $this->getVarMinPrice() ) {
04808 $dPrice = $this->_getPriceForView( $oPrice );
04809 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04810 }
04811
04812 return $sPrice;
04813 }
04814
04820 public function getVarMinPrice()
04821 {
04822 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04823 return;
04824 }
04825
04826 $oPrice = null;
04827 $dPrice = $this->_getVarMinPrice();
04828
04829 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04830
04831
04832 $oPrice = $this->_getPriceObject();
04833 $oPrice->setPrice( $dPrice );
04834 $this->_calculatePrice( $oPrice );
04835
04836
04837 return $oPrice;
04838 }
04839
04840
04846 public function getMinPrice()
04847 {
04848 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04849 return;
04850 }
04851
04852 $oPrice = null;
04853 $dPrice = $this->_getPrice();
04854 if ( $this->_getVarMinPrice() !== null && $dPrice > $this->_getVarMinPrice() ) {
04855 $dPrice = $this->_getVarMinPrice();
04856 }
04857
04858 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04859
04860
04861 $oPrice = $this->_getPriceObject();
04862 $oPrice->setPrice( $dPrice );
04863 $this->_calculatePrice( $oPrice );
04864
04865 return $oPrice;
04866 }
04867
04868
04874 public function isRangePrice()
04875 {
04876 if ( $this->_blIsRangePrice === null ) {
04877
04878 $this->setRangePrice( false );
04879
04880 if ( $this->_hasAnyVariant() ) {
04881 $dPrice = $this->_getPrice();
04882 $dMinPrice = $this->_getVarMinPrice();
04883 $dMaxPrice = $this->_getVarMaxPrice();
04884
04885 if ( $dMinPrice != $dMaxPrice ) {
04886 $this->setRangePrice();
04887 } elseif ( !$this->isParentNotBuyable() && $dMinPrice != $dPrice ) {
04888 $this->setRangePrice();
04889 }
04890 }
04891 }
04892
04893 return $this->_blIsRangePrice;
04894 }
04895
04896
04904 public function setRangePrice( $blIsRangePrice = true )
04905 {
04906 return $this->_blIsRangePrice = $blIsRangePrice;
04907 }
04908
04914 protected function _getUserPriceSufix()
04915 {
04916 $sPriceSufix = '';
04917 $oUser = $this->getArticleUser();
04918
04919 if ( $oUser ) {
04920 if ( $oUser->inGroup( 'oxidpricea' ) ) {
04921 $sPriceSufix = 'a';
04922 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
04923 $sPriceSufix = 'b';
04924 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
04925 $sPriceSufix = 'c';
04926 }
04927 }
04928
04929 return $sPriceSufix;
04930 }
04931
04932
04938 protected function _getPrice()
04939 {
04940 $sPriceSufix = $this->_getUserPriceSufix();
04941 if ( $sPriceSufix === '') {
04942 $dPrice = $this->oxarticles__oxprice->value;
04943 } else {
04944 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04945 $dPrice = ($this->{oxarticles__oxprice.$sPriceSufix}->value !=0 )? $this->{oxarticles__oxprice.$sPriceSufix}->value : $this->oxarticles__oxprice->value;
04946 } else {
04947 $dPrice = $this->{oxarticles__oxprice.$sPriceSufix}->value;
04948 }
04949 }
04950 return $dPrice;
04951 }
04952
04953
04959 protected function _getVarMinPrice()
04960 {
04961 if ( $this->_dVarMinPrice === null) {
04962
04963 $sPriceSufix = $this->_getUserPriceSufix();
04964 if ( $dPrice === null ) {
04965 if ( $sPriceSufix === '' ) {
04966 $dPrice = $this->oxarticles__oxvarminprice->value;
04967 } else {
04968 $sSql = 'SELECT ';
04969 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04970 $sSql .= 'MIN( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varminprice` ';
04971 } else {
04972 $sSql .= 'MIN(`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04973 }
04974
04975 $sSql .= ' FROM ' . $this->getViewName(true) . '
04976 WHERE ' .$this->getSqlActiveSnippet(true) . '
04977 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04978
04979 $dPrice = oxDb::getDb()->getOne( $sSql );
04980 }
04981 }
04982 $this->_dVarMinPrice = $dPrice;
04983 }
04984
04985 return $this->_dVarMinPrice;
04986 }
04987
04993 protected function _getSubShopVarMinPrice()
04994 {
04995 $myConfig = $this->getConfig();
04996 $sShopId = $myConfig->getShopId();
04997 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04998 $sPriceSufix = $this->_getUserPriceSufix();
04999 $sSql = 'SELECT ';
05000 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
05001 $sSql .= 'MIN(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varminprice` ';
05002 } else {
05003 $sSql .= 'MIN(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
05004 }
05005 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
05006 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
05007 WHERE ' .$this->getSqlActiveSnippet(true) . '
05008 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
05009 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
05010 $dPrice = oxDb::getDb()->getOne( $sSql );
05011 }
05012 return $dPrice;
05013 }
05014
05020 protected function _getVarMaxPrice()
05021 {
05022 if ( $this->_dVarMaxPrice === null ) {
05023
05024 $sPriceSufix = $this->_getUserPriceSufix();
05025 if ( $dPrice === null ) {
05026 if ( $sPriceSufix === '') {
05027 $dPrice = $this->oxarticles__oxvarmaxprice->value;
05028 } else {
05029 $sSql = 'SELECT ';
05030 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
05031 $sSql .= 'MAX( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varmaxprice` ';
05032 } else {
05033 $sSql .= 'MAX(`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
05034 }
05035
05036 $sSql .= ' FROM ' . $this->getViewName(true) . '
05037 WHERE ' .$this->getSqlActiveSnippet(true) . '
05038 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
05039
05040 $dPrice = oxDb::getDb()->getOne( $sSql );
05041 }
05042 }
05043 $this->_dVarMaxPrice = $dPrice;
05044 }
05045
05046 return $this->_dVarMaxPrice;
05047 }
05048
05054 protected function _getSubShopVarMaxPrice()
05055 {
05056 $myConfig = $this->getConfig();
05057 $sShopId = $myConfig->getShopId();
05058 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
05059 $sPriceSufix = $this->_getUserPriceSufix();
05060 $sSql = 'SELECT ';
05061 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
05062 $sSql .= 'MAX(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varmaxprice` ';
05063 } else {
05064 $sSql .= 'MAX(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
05065 }
05066 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
05067 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
05068 WHERE ' .$this->getSqlActiveSnippet(true) . '
05069 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
05070 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
05071 $dPrice = oxDb::getDb()->getOne( $sSql );
05072 }
05073 return $dPrice;
05074 }
05075
05081 public function getUnitQuantity()
05082 {
05083 return $this->oxarticles__oxunitquantity->value;
05084 }
05085
05091 public function getSize()
05092 {
05093 $dSize = $this->oxarticles__oxlength->value *
05094 $this->oxarticles__oxwidth->value *
05095 $this->oxarticles__oxheight->value;
05096
05097 return $dSize;
05098 }
05099
05105 public function getWeight()
05106 {
05107 return $this->oxarticles__oxweight->value;
05108 }
05109
05115 protected function _updateParentDependFields()
05116 {
05117 $oDb = oxDb::getDb();
05118
05119 foreach ( $this->_getCopyParentFields() as $sField ) {
05120 $sValue = isset( $this->$sField->value ) ? $this->$sField->value : 0;
05121 $sSqlSets[] = '`' . str_replace( 'oxarticles__', '', $sField ) . '` = ' . $oDb->quote( $sValue );
05122 }
05123
05124 $sSql = "UPDATE `oxarticles` SET ";
05125 $sSql .= implode(', ', $sSqlSets) . '';
05126 $sSql .= " WHERE `oxparentid` = " . $oDb->quote( $this->getId() );
05127
05128 return $oDb->execute( $sSql );
05129 }
05130
05131
05137 protected function _getCopyParentFields()
05138 {
05139 return $this->_aCopyParentField;
05140 }
05141
05147 protected function _assignParentDependFields()
05148 {
05149 $sParent = $this->getParentArticle();
05150 if ( $sParent ) {
05151 foreach ( $this->_getCopyParentFields() as $sField ) {
05152 $this->$sField = new oxField ( $sParent->$sField->value );
05153 }
05154 }
05155 }
05156
05164 protected function loadSimpleVariantsForLists( $blSimple )
05165 {
05166 if ( $blSimple ) {
05167 $oVariants = oxNew( 'oxsimplevariantlist' );
05168 $oVariants->setParent( $this );
05169 } else {
05170 $oVariants = oxNew( 'oxarticlelist' );
05171 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
05172 }
05173
05174 return $oVariants;
05175 }
05176
05186 protected function _selectVariants( $blRemoveNotOrderables, $blForceCoreTable, $oVariants )
05187 {
05188 $myConfig = $this->getConfig();
05189
05190 startProfile( "selectVariants" );
05191
05192 $blUseCoreTable = (bool) $blForceCoreTable;
05193 $oBaseObject = $oVariants->getBaseObject();
05194 $oBaseObject->setLanguage( $this->getLanguage() );
05195
05196
05197 $sArticleTable = $this->getViewName( $blUseCoreTable );
05198
05199 $sSelect = "select " . $oBaseObject->getSelectFields( $blUseCoreTable ) . " from $sArticleTable where " .
05200 $this->getActiveCheckQuery( $blUseCoreTable ) .
05201 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
05202 " order by $sArticleTable.oxsort";
05203
05204
05205 $oVariants->selectString( $sSelect );
05206
05207
05208 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
05209 $oMdVariants = oxNew( "oxVariantHandler" );
05210 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
05211 }
05212
05213 stopProfile( "selectVariants" );
05214
05215 return $oVariants;
05216 }
05217
05218 }