00001 <?php
00002
00003
00004 define( 'OXARTICLE_LINKTYPE_CATEGORY', 0 );
00005 define( 'OXARTICLE_LINKTYPE_VENDOR', 1 );
00006 define( 'OXARTICLE_LINKTYPE_MANUFACTURER', 2 );
00007
00014 class oxArticle extends oxI18n
00015 {
00021 protected $_sCoreTbl = 'oxarticles';
00022
00028 protected $_sClassName = 'oxarticle';
00029
00035 protected $_blUseLazyLoading = true;
00036
00042 protected $_sItemKey;
00043
00049 protected $_blCalcPrice = true;
00050
00055 protected $_oPrice = null;
00056
00061 protected $_aPersistParam = null;
00062
00067 protected $_blNotBuyable = false;
00068
00074 protected $_blLoadVariants = true;
00075
00081 protected $_aVariants = null;
00082
00091 protected $_blNotBuyableParent = false;
00092
00097 protected $_blHasVariants = false;
00098
00102 protected $_iVarStock = 0;
00103
00108 protected $_oVariantList = array();
00109
00114 protected $_blIsOnComparisonList = false;
00115
00120 protected $_oUser = null;
00121
00127 protected $_blLoadPrice = true;
00128
00132 protected $_blSkipAbPrice = false;
00133
00140 protected $_fPricePerUnit = null;
00141
00145 protected $_blLoadParentData = false;
00146
00150 protected $_blSkipAssign = false;
00151
00157 protected $_blSkipDiscounts = null;
00158
00163 protected $_oAttributeList = null;
00164
00165
00171 protected $_blIsRangePrice = false;
00172
00178 protected $_aMediaUrls = null;
00179
00185 static protected $_aLoadedParents;
00186
00192 static protected $_aSelList;
00193
00199 protected $_aDispSelList;
00200
00206 protected $_blIsSeoObject = true;
00207
00213 protected $_oAmountPriceList = null;
00214
00223 protected $_iLinkType = 0;
00224
00230 protected $_sStdLink = null;
00231
00237 protected $_sDynImageDir = null;
00238
00244 protected $_sMoreDetailLink = null;
00245
00251 protected $_sToBasketLink = null;
00252
00258 protected $_iStockStatus = null;
00259
00265 protected $_oTPrice = null;
00266
00272 protected $_oAmountPriceInfo = null;
00273
00279 protected $_dAmountPrice = null;
00280
00286 protected $_sDetailLink = null;
00287
00293 protected static $_aArticleManufacturers = array();
00294
00300 protected static $_aArticleVendors = array();
00301
00307 protected static $_aArticleCats = array();
00308
00317 public function __construct($aParams = null)
00318 {
00319 if ( $aParams && is_array($aParams)) {
00320 foreach ( $aParams as $sParam => $mValue) {
00321 $this->$sParam = $mValue;
00322 }
00323 }
00324 parent::__construct();
00325 $this->init( 'oxarticles' );
00326
00327 $this->_blIsRangePrice = false;
00328 }
00329
00337 public function __isset( $sName )
00338 {
00339 if ( $sName == 'oxarticles__oxlongdesc' ) {
00340
00341 $this->getArticleLongDesc();
00342 return true;
00343 }
00344 return isset( $this->$sName );
00345 }
00346
00355 public function __set( $sName, $sValue)
00356 {
00357 if ($sName == 'oxarticles__oxlongdesc') {
00358 $this->$sName = $sValue;
00359 return;
00360 }
00361 return parent::__set($sName, $sValue);
00362 }
00363
00372 public function __get($sName)
00373 {
00374 $myUtils = oxUtils::getInstance();
00375 switch ($sName) {
00376
00377
00378
00379
00380 case 'netprice':
00381 case 'netPrice':
00382 $mVal = $myUtils->fRound($this->getPrice()->getNettoPrice());
00383 break;
00384 case 'brutPrice':
00385 return $myUtils->fRound($this->getPrice()->getBruttoPrice());
00386 break;
00387 case 'vatPercent':
00388 return $this->getPrice()->getVAT();
00389 break;
00390 case 'vat':
00391 return $this->getPrice()->getVATValue();
00392 break;
00393 case 'fnetprice':
00394 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($this->getPrice()->getNettoPrice()));
00395 break;
00396 case 'fprice':
00397 return $this->getFPrice();
00398 break;
00399
00400
00401 case 'dtprice':
00402 if ( $oPrice = $this->getTPrice() ) {
00403 return $myUtils->fRound($oPrice->getBruttoPrice());
00404 break;
00405 } else {
00406 return null;
00407 break;
00408 }
00409 case 'tvat':
00410 if ( $oPrice = $this->getTPrice() ) {
00411 return $oPrice->getVATValue();
00412 break;
00413 } else {
00414 return null;
00415 break;
00416 }
00417 case 'ftprice':
00418 if ( $oPrice = $this->getTPrice() ) {
00419 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($oPrice->getBruttoPrice()) );
00420 break;
00421 } else {
00422 return null;
00423 break;
00424 }
00425 case 'oxarticles__oxlongdesc':
00426 return $this->getArticleLongDesc($this->getId());
00427 break;
00428 case 'foxdelivery':
00429 return $this->getDeliveryDate();
00430 break;
00431 case 'sItemKey':
00432 return $this->getItemKey();
00433 break;
00434 case 'selectlist':
00435 return $this->_aDispSelList = $this->getDispSelList();
00436 break;
00437 case 'blNotBuyable':
00438 return $this->isNotBuyable();
00439 break;
00440 case 'blNotBuyableParent':
00441 return $this->isParentNotBuyable();
00442 break;
00443 case 'blIsOnComparisonList':
00444 return $this->isOnComparisonList();
00445 break;
00446 case 'oVariantlist' :
00447 return $this->_oVariantList;
00448 break;
00449 case 'fPricePerUnit' :
00450 return $this->getPricePerUnit();
00451 break;
00452 case 'dimagedir' :
00453 return $this->_sDynImageDir = $this->getDynImageDir();
00454 break;
00455 case 'oxmoredetaillink' :
00456 return $this->_sMoreDetailLink = $this->getMoreDetailLink();
00457 break;
00458 case 'amountpricelist' :
00459 return $this->loadAmountPriceInfo();
00460 break;
00461 case 'stockstatus' :
00462 return $this->getStockStatus();
00463 break;
00464 case 'tobasketlink' :
00465 return $this->getToBasketLink();
00466 break;
00467 case 'oxdetaillink' :
00468 return $this->getLink();
00469 break;
00470
00471
00472 }
00473
00474 $sRet = parent::__get($sName);
00475 if ( $this->$sName ) {
00476 $this->_assignParentFieldValue($sName);
00477 }
00478
00479 if ($sName == "oxarticles__oxthumb" || $sName == "oxarticles__oxicon" || strpos($sName, "oxarticles__oxpic") === 0 || strpos($sName, "oxarticles__oxzoom") === 0) {
00480 $this->_assignPictureValues();
00481 return $this->$sName;
00482 }
00483
00484 return $sRet;
00485 }
00486
00494 public function setId( $sId = null )
00495 {
00496 $sId = parent::setId( $sId );
00497
00498
00499 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00500
00501 return $sId;
00502 }
00503
00511 public function getSqlActiveSnippet( $blForceCoreTable = false )
00512 {
00513 $myConfig = $this->getConfig();
00514 $sTable = $this->getCoreTableName();
00515
00516
00517 $sQ = " $sTable.oxactive = 1 ";
00518
00519
00520 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00521 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00522 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00523 }
00524
00525
00526 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00527 $sQ = " $sQ and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00528
00529 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00530 $sQ = " $sQ and ( $sTable.oxvarcount=0 or ( select count(art.oxid) from $sTable as art where art.oxstockflag=2 and art.oxparentid=$sTable.oxid and art.oxstock=0 ) < $sTable.oxvarcount ) ";
00531 }
00532 }
00533
00534
00535 return "( $sQ ) ";
00536 }
00537
00545 public function setSkipAssign($blSkipAssign)
00546 {
00547 $this->_blSkipAssign = $blSkipAssign;
00548 }
00549
00557 public function disablePriceLoad( $oArticle )
00558 {
00559 $oArticle->_blLoadPrice = false;
00560 }
00561
00567 public function getItemKey()
00568 {
00569 return $this->_sItemKey;
00570 }
00571
00579 public function setItemKey($sItemKey)
00580 {
00581 $this->_sItemKey = $sItemKey;
00582 }
00583
00591 public function setNoVariantLoading( $blLoadVariants )
00592 {
00593 $this->_blLoadVariants = !$blLoadVariants;
00594 }
00595
00601 public function isBuyable()
00602 {
00603 if ($this->_blNotBuyableParent) {
00604 return false;
00605 }
00606
00607 return !$this->_blNotBuyable;
00608 }
00609
00615 public function getPersParams()
00616 {
00617 return $this->_aPersistParam;
00618 }
00619
00625 public function isOnComparisonList()
00626 {
00627 return $this->_blIsOnComparisonList;
00628 }
00629
00637 public function setOnComparisonList( $blOnList )
00638 {
00639 $this->_blIsOnComparisonList = $blOnList;
00640 }
00641
00649 public function setLoadParentData($blLoadParentData)
00650 {
00651 $this->_blLoadParentData = $blLoadParentData;
00652 }
00653
00661 public function setSkipAbPrice( $blSkipAbPrice = null )
00662 {
00663 $this->_blSkipAbPrice = $blSkipAbPrice;
00664 }
00665
00671 public function getSearchableFields()
00672 {
00673 $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00674 $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00675
00676 return $aFields;
00677 }
00678
00679
00687 public function isMultilingualField($sFieldName)
00688 {
00689 if ($sFieldName == "oxlongdesc") {
00690 return true;
00691 }
00692
00693 return parent::isMultilingualField($sFieldName);
00694 }
00695
00701 public function isVisible()
00702 {
00703
00704
00705 $myConfig = $this->getConfig();
00706 if ( oxConfig::getParameter( 'preview' ) == 1 && $this->isAdmin()) {
00707 return true;
00708 }
00709
00710
00711 $sNow = date('Y-m-d H:i:s');
00712 if ( !$this->oxarticles__oxactive->value &&
00713 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00714 $this->oxarticles__oxactiveto->value < $sNow
00715 )) {
00716 return false;
00717 }
00718
00719
00720 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
00721 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
00722 return false;
00723 }
00724
00725 return true;
00726 }
00727
00736 public function assign( $aRecord)
00737 {
00738 startProfile('articleAssign');
00739
00740
00741
00742 parent::assign( $aRecord);
00743
00744 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00745
00746
00747 if ($this->_blSkipAssign) {
00748 return;
00749 }
00750
00751 $this->_assignLinks();
00752 $this->_assignParentFieldValues();
00753 $this->_assignNotBuyableParent();
00754 $this->_assignPictureValues();
00755 $this->_assignStock();
00756 startProfile('articleAssignPrices');
00757 $this->_assignPrices();
00758 stopProfile('articleAssignPrices');
00759 $this->_assignPersistentParam();
00760 $this->_assignDynImageDir();
00761 $this->_assignComparisonListFlag();
00762 $this->_assignAttributes();
00763
00764
00765
00766
00767 stopProfile('articleAssign');
00768 }
00769
00779 protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00780 {
00781 parent::_setFieldData( $sFieldName, $sValue, $iDataType);
00782 }
00783
00794 public function load( $oxID)
00795 {
00796
00797 $this->_blNotBuyableParent = false;
00798
00799 $blRet = parent::load( $oxID);
00800
00801
00802 $this->oxarticles__oxinsert = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00803 $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00804
00805 return $blRet;
00806 }
00807
00815 public function addToRatingAverage( $iRating)
00816 {
00817 $dOldRating = $this->oxarticles__oxrating->value;
00818 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00819 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00820 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00821 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00822 $dRatingCnt = $dOldCnt + 1;
00823
00824 oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00825 }
00826
00832 public function getArticleRatingAverage()
00833 {
00834 return round( $this->oxarticles__oxrating->value, 1);
00835 }
00836
00842 public function getReviews()
00843 {
00844 $myConfig = $this->getConfig();
00845
00846 $aIds = array($this->getId());
00847
00848 if ( $this->oxarticles__oxparentid->value ) {
00849 $aIds[] = $this->oxarticles__oxparentid->value;
00850 }
00851
00852
00853 if ( $myConfig->getConfigParam( 'blShowVariantReviews' ) ) {
00854 $aAdd = $this->_getVariantsIds();
00855 if (is_array($aAdd)) {
00856 $aIds = array_merge($aIds, $aAdd);
00857 }
00858 }
00859
00860 $oReview = oxNew('oxreview');
00861 $oRevs = $oReview->loadList('oxarticle', $aIds);
00862
00863
00864 if ( $oRevs->count() < 1 ) {
00865 return null;
00866 }
00867
00868 return $oRevs;
00869 }
00870
00876 public function getCrossSelling()
00877 {
00878 $oCrosslist = oxNew( "oxarticlelist");
00879 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00880 if ( $oCrosslist->count() ) {
00881 return $oCrosslist;
00882 }
00883 }
00884
00890 public function getAccessoires()
00891 {
00892 $myConfig = $this->getConfig();
00893
00894
00895 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00896 return;
00897 }
00898
00899 $oAcclist = oxNew( "oxarticlelist");
00900 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00901 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00902
00903 if ( $oAcclist->count()) {
00904 return $oAcclist;
00905 }
00906 }
00907
00913 public function getSimilarProducts()
00914 {
00915
00916 $myConfig = $this->getConfig();
00917 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
00918 return;
00919 }
00920
00921 $sArticleTable = $this->_getObjectViewName('oxarticles');
00922
00923 $sAttribs = '';
00924 $iCnt = 0;
00925 $this->_getAttribsString($sAttribs, $iCnt);
00926
00927 if ( !$sAttribs) {
00928 return null;
00929 }
00930
00931
00932
00933
00934
00935
00936 $aList = $this->_getSimList($sAttribs, $iCnt);
00937
00938 if ( count( $aList ) ) {
00939 uasort( $aList, 'cmpart');
00940
00941 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
00942
00943 $oSimilarlist = oxNew( 'oxarticlelist' );
00944 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
00945 $oSimilarlist->selectString( $sSearch);
00946
00947 return $oSimilarlist;
00948 }
00949 }
00950
00956 public function getCustomerAlsoBoughtThisProducts()
00957 {
00958
00959 $myConfig = $this->getConfig();
00960 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
00961 return;
00962 }
00963
00964
00965 $sQ = $this->_generateSearchStrForCustomerBought();
00966
00967 $oArticles = oxNew( 'oxarticlelist' );
00968 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
00969 $oArticles->selectString( $sQ );
00970 if ( $oArticles->count() ) {
00971 return $oArticles;
00972 }
00973 }
00974
00981 public function loadAmountPriceInfo()
00982 {
00983 $myConfig = $this->getConfig();
00984 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
00985 return array();
00986 }
00987
00988 if ( $this->_oAmountPriceInfo !== null ) {
00989 return $this->_oAmountPriceInfo;
00990 }
00991
00992 $oAmPriceList = $this->_getAmountPriceList();
00993
00994 if ( count( $oAmPriceList ) ) {
00995 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
00996 return $this->_oAmountPriceInfo;
00997 }
00998
00999 return array();
01000 }
01001
01009 public function getSelectLists($sKeyPrefix = null)
01010 {
01011
01012
01013 $sKey = $this->getId();
01014 if ( isset( $sKeyPrefix ) ) {
01015 $sKey = $sKeyPrefix.'__'.$this->getId();
01016 }
01017
01018 if ( self::$_aSelList[$sKey]) {
01019 return self::$_aSelList[$sKey];
01020 }
01021
01022
01023 $oLists = oxNew( 'oxlist' );
01024 $oLists->init('oxselectlist');
01025 $sSLViewName = getViewName('oxselectlist');
01026 $sSelect = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01027 $sSelect .= 'where oxobject2selectlist.oxobjectid=\''.$this->getId().'\' ';
01028 //sorting
01029 $sSelect .= ' order by oxobject2selectlist.oxsort';
01030
01031 $oLists->selectString( $sSelect );
01032
01033 //#1104S if this is variant ant it has no selectlists, trying with parent
01034 if ( $this->oxarticles__oxparentid->value && $oLists->count() == 0 ) {
01035 //#1496C - select fixed ( * => $sSLViewName.*)
01036 $sSelect = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01037 $sSelect .= "where oxobject2selectlist.oxobjectid='{$this->oxarticles__oxparentid->value}' ";
01038 //sorting
01039 $sSelect .= ' order by oxobject2selectlist.oxsort';
01040 $oLists->selectString( $sSelect);
01041 }
01042
01043 $dVat = 0;
01044 if ( $this->getPrice() != null ) {
01045 $dVat = $this->getPrice()->getVat();
01046 }
01047
01048 $iCnt = 0;
01049 self::$_aSelList[$sKey] = array();
01050 foreach ( $oLists as $oSelectlist ) {
01051 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01052 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01053 $iCnt++;
01054 }
01055 return self::$_aSelList[$sKey];
01056 }
01057
01065 public function getVariants( $blRemoveNotOrderables = true )
01066 {
01067 if ($this->_aVariants) {
01068 return $this->_aVariants;
01069 }
01070
01071 //return ;
01072 if (!$this->_blLoadVariants) {
01073 return array();
01074 }
01075
01076 $myConfig = $this->getConfig();
01077
01078 // Performance
01079 if ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants')) {
01080 return array();
01081 }
01082
01083 //do not load variants where variant oxvarcount is 0
01084 //hint: if variantas are not loaded you should check your data integrity oxvarcount should always be equal to variant count
01085 if (!$this->isAdmin() && !$this->oxarticles__oxvarcount->value) {
01086 return array();
01087 }
01088
01089 //do not load me as a parent later
01090 self::$_aLoadedParents[$this->getId()] = $this;
01091
01092 //load simple variants for lists
01093 if ($this->_isInList()) {
01094 $oVariants = oxNew( 'oxsimplevariantlist' );
01095 $oVariants->setParent($this);
01096 } else {
01097 //loading variants
01098 $oVariants = oxNew( 'oxarticlelist' );
01099 }
01100
01101 startProfile("selectVariants");
01102 $sSelectFields = $oVariants->getBaseObject()->getSelectFields();
01103 $sArticleTable = $this->getViewName();
01104 $sSelect = "select $sSelectFields from $sArticleTable where ";
01105 $sSelect .= " $sArticleTable.oxparentid ='".$this->getId()."' ";
01106 $sSelect .= " order by $sArticleTable.oxsort";
01107 $oVariants->selectString( $sSelect);
01108 stopProfile("selectVariants");
01109
01110 //print_r($oVariants);
01111
01112 if (!$oVariants->count()) {
01113 return array();
01114 }
01115 $oVariants = $this->_removeInactiveVariants( $oVariants, $blRemoveNotOrderables );
01116 //$this->calculateMinVarPrice($oVariants);
01117 //#1104S Load selectlists
01118 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
01119 foreach ($oVariants as $key => $oVariant) {
01120 $oVariants[$key]->aSelectlist = $oVariant->getSelectLists();
01121 }
01122 }
01123 $this->_aVariants = $oVariants;
01124 return $oVariants;
01125 }
01126
01132 public function getSimpleVariants()
01133 {
01134 if ( $this->oxarticles__oxvarcount->value) {
01135 return $this->getVariants();
01136 }
01137 }
01138
01147 public function getAdminVariants( $sLanguage = null )
01148 {
01149 $myConfig = $this->getConfig();
01150
01151 $oVariants = oxNew( 'oxarticlelist');
01152
01153 if ( is_null($sLanguage) ) {
01154 $oVariants->getBaseObject()->setLanguage(oxLang::getInstance()->getBaseLanguage());
01155 } else {
01156 $oVariants->getBaseObject()->setLanguage($sLanguage);
01157 }
01158
01159 $sSql = 'select * from oxarticles where oxparentid = "'.$this->getId().'" order by oxsort ';
01160
01161 $oVariants->selectString( $sSql);
01162
01163 //if we have variants then depending on config option the parent may be non buyable
01164 if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01165 //$this->blNotBuyable = true;
01166 $this->_blNotBuyableParent = true;
01167 }
01168
01169 return $oVariants;
01170 }
01171
01179 public function getCategory()
01180 {
01181 startPRofile( 'getCategory' );
01182
01183 $oCategory = oxNew( 'oxcategory' );
01184 $oCategory->setLanguage( $this->getLanguage() );
01185
01186 // variant handling
01187 $sOXID = $this->getId();
01188 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01189 $sOXID = $this->oxarticles__oxparentid->value;
01190 }
01191
01192 $sWhere = $oCategory->getSqlActiveSnippet();
01193 $sSelect = $this->_generateSearchStr( $sOXID );
01194 $sSelect .= ( strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime ";
01195
01196 // category not found ?
01197 if ( !$oCategory->assignRecord( $sSelect ) ) {
01198
01199 $sSelect = $this->_generateSearchStr( $sOXID, true );
01200 $sSelect .= ( strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere ;
01201
01202 // looking for price category
01203 if ( !$oCategory->assignRecord( $sSelect ) ) {
01204 $oCategory = null;
01205 }
01206 }
01207
01208 stopPRofile( 'getCategory' );
01209 return $oCategory;
01210 }
01211
01219 public function getCategoryIds( $blSkipCache = false )
01220 {
01221 $myConfig = $this->getConfig();
01222 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01223 return self::$_aArticleCats[$this->getId()];
01224 }
01225
01226 // variant handling
01227 $sOXID = $this->getId();
01228 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01229 $sOXID = $this->oxarticles__oxparentid->value;
01230 }
01231
01232 $sO2CView = $this->_getObjectViewName('oxobject2category');
01233 $sCatView = $this->_getObjectViewName('oxcategories');
01234
01235 // we do not use lists here as we dont need this overhead right now
01236 $oDB = oxDb::getDb(true);
01237 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01238 $sSelect .= 'where oxobject2category.oxobjectid=\''.$sOXID.'\' and oxcategories.oxid is not null and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 order by oxobject2category.oxtime ';
01239 $rs = $oDB->execute( $sSelect);
01240
01241
01242 $aRet = array();
01243 $iHitMax = 0;
01244 if ($rs != false && $rs->recordCount() > 0) {
01245 while (!$rs->EOF) {
01246 $aRet[] = $rs->fields['oxcatnid'];
01247 $rs->moveNext();
01248 }
01249 }
01250
01251 return self::$_aArticleCats[$this->getId()] = $aRet;
01252 }
01253
01263 public function getVendor( $blShopCheck = true )
01264 {
01265 if ( ( $sVendorId = $this->getVendorId() ) ) {
01266 $oVendor = oxNew( 'oxvendor' );
01267 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01268 $oVendor = oxNew( 'oxi18n' );
01269 $oVendor->init('oxvendor');
01270 $oVendor->setReadOnly( true );
01271 $sVendorId = $this->oxarticles__oxvendorid->value;
01272 }
01273 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01274 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01275 $oVendor->setReadOnly( true );
01276 }
01277 return $oVendor;
01278 }
01279 return null;
01280 }
01281
01289 public function getVendorId( $blForceReload = false )
01290 {
01291 $sVendorId = false;
01292 if ( $this->oxarticles__oxvendorid->value ) {
01293 if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01294 return self::$_aArticleVendors[$this->getId()];
01295 }
01296 $sQ = "select oxid from ".getViewName('oxvendor')." where oxid='{$this->oxarticles__oxvendorid->value}'";
01297 self::$_aArticleVendors[$this->getId()] = $sVendorId = oxDb::getDb()->getOne( $sQ );
01298 }
01299 return $sVendorId;
01300 }
01301
01309 public function getManufacturerId( $blForceReload = false )
01310 {
01311 $sManufacturerId = false;
01312 if ( $this->oxarticles__oxmanufacturerid->value ) {
01313 if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01314 return self::$_aArticleManufacturers[$this->getId()];
01315 }
01316 $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid='{$this->oxarticles__oxmanufacturerid->value}'";
01317 self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = oxDb::getDb()->getOne( $sQ );
01318 }
01319 return $sManufacturerId;
01320 }
01321
01331 public function getManufacturer( $blShopCheck = true )
01332 {
01333 $oManufacturer = null;
01334 if ( ( $sManufacturerId = $this->getManufacturerId() ) ) {
01335 $oManufacturer = oxNew( 'oxmanufacturer' );
01336 } elseif ( !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01337 $oManufacturer = oxNew( 'oxI18n' );
01338 $oManufacturer->init('oxmanufacturers');
01339 $oManufacturer->setReadOnly( true );
01340 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01341 }
01342
01343 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01344 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01345 $oManufacturer->setReadOnly( true );
01346 }
01347 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01348 } else {
01349 $oManufacturer = null;
01350 }
01351
01352 return $oManufacturer;
01353 }
01354
01363 public function inCategory( $sCatNid)
01364 {
01365 return in_array( $sCatNid, $this->getCategoryIds());
01366 }
01367
01376 public function isAssignedToCategory( $sCatId )
01377 {
01378 // variant handling
01379 $sOXID = $this->getId();
01380 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01381 $sOXID = $this->oxarticles__oxparentid->value;
01382 }
01383
01384 $oDB = oxDb::getDb();
01385 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01386 $sOXID = $oDB->getOne( $sSelect);
01387 // article is assigned to passed category!
01388 if ( isset( $sOXID) && $sOXID) {
01389 return true;
01390 }
01391
01392 // maybe this category is price category ?
01393 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01394 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01395 if ( $dPriceFromTo > 0) {
01396 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01397 $sOXID = $oDB->getOne( $sSelect);
01398 // article is assigned to passed category!
01399 if ( isset( $sOXID) && $sOXID) {
01400 return true;
01401 }
01402 }
01403 }
01404 return false;
01405 }
01406
01412 public function getTPrice()
01413 {
01414 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01415 return;
01416 }
01417 // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01418 if ( $this->_oTPrice !== null ) {
01419 return $this->_oTPrice;
01420 }
01421
01422 $this->_oTPrice = oxNew( 'oxPrice' );
01423 $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01424
01425 $this->_applyVat( $this->_oTPrice, oxNew( 'oxVatSelector' )->getArticleVat( $this ) );
01426 $this->_applyCurrency( $this->_oTPrice );
01427
01428 return $this->_oTPrice;
01429 }
01430
01436 public function skipDiscounts()
01437 {
01438 // allready loaded skip discounts config
01439 if ( $this->_blSkipDiscounts !== null )
01440 return $this->_blSkipDiscounts;
01441
01442 if ( $this->oxarticles__oxskipdiscounts->value )
01443 return true;
01444
01445 $sO2CView = getViewName('oxobject2category');
01446 $sSelect = "select 1 from $sO2CView as oxobject2category left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01447 $sSelect .= 'where oxobject2category.oxobjectid="'.$this->getId().'" and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 and oxcategories.oxskipdiscounts = "1" ';
01448
01449 return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01450 }
01451
01459 public function setPrice(oxPrice $oPrice)
01460 {
01461 $this->_oPrice = $oPrice;
01462 }
01463
01472 public function getBasePrice( $dAmount = 1 )
01473 {
01474 // override this function if you want e.g. different prices
01475 // for diff. usergroups.
01476
01477 // Performance
01478 $myConfig = $this->getConfig();
01479 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01480 return;
01481
01482 // GroupPrice or DB price ajusted by AmountPrice
01483 $dPrice = $this->_getAmountPrice( $dAmount );
01484
01485
01486 return $dPrice;
01487 }
01488
01494 public function getPrice()
01495 {
01496 $myConfig = $this->getConfig();
01497 // Performance
01498 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01499 return;
01500 }
01501 // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01502 if ( $this->_oPrice ) {
01503 return $this->_oPrice;
01504 }
01505
01506 $this->_oPrice = oxNew( 'oxPrice' );
01507
01508 // get base
01509 $this->_oPrice->setPrice( $this->getBasePrice() );
01510
01511 // price handling
01512 if ( !$this->_blCalcPrice ) {
01513 return $this->_oPrice;
01514 }
01515
01516 // apply VAT only if configuration requires it
01517 if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01518 $this->_applyVAT( $this->_oPrice, oxNew('oxVatSelector')->getArticleVat( $this ) );
01519 }
01520
01521 // apply currency
01522 $this->_applyCurrency( $this->_oPrice );
01523
01524 // apply discounts
01525 if ( !$this->skipDiscounts() ) {
01526 $this->_applyDiscounts($this->_oPrice, oxDiscountList::getInstance()->getArticleDiscounts($this, $this->getArticleUser()));
01527 }
01528
01529 return $this->_oPrice;
01530 }
01531
01539 public function setArticleUser($oUser)
01540 {
01541 $this->_oUser = $oUser;
01542 }
01543
01549 public function getArticleUser()
01550 {
01551 if ($this->_oUser) {
01552 return $this->_oUser;
01553 }
01554 return $this->getUser();
01555 }
01556
01566 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01567 {
01568 $oUser = $oBasket->getBasketUser();
01569 $this->setArticleUser($oUser);
01570
01571 $oBasketPrice = oxNew( 'oxPrice' );
01572
01573 // get base price
01574 $dBasePrice = $this->getBasePrice( $dAmount );
01575
01576 // applying select list price
01577 $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01578
01579 // setting price
01580 $oBasketPrice->setPrice( $dBasePrice );
01581
01582 // apply VAT
01583 $this->_applyVat( $oBasketPrice, oxNew('oxVatSelector')->getBasketItemVat( $this, $oBasket ) );
01584
01585 // apply currency
01586 $this->_applyCurrency( $oBasketPrice );
01587
01588 // apply discounts
01589 if ( !$this->skipDiscounts() ) {
01590 // apply general discounts
01591 $this->_applyDiscounts( $oBasketPrice, oxDiscountList::getInstance()->getArticleDiscounts( $this, $oUser ) );
01592 }
01593
01594 // returning final price object
01595 return $oBasketPrice;
01596 }
01597
01608 public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01609 {
01610 $aDiscLog = array();
01611 reset( $aDiscounts );
01612
01613 // price object to correctly perform calculations
01614 $dOldPrice = $oPrice->getBruttoPrice();
01615
01616 while (list( , $oDiscount) = each($aDiscounts)) {
01617 $oDiscount->applyDiscount( $oPrice );
01618 $dNewPrice = $oPrice->getBruttoPrice();
01619
01620 if (!isset($aDiscLog[$oDiscount->getId()])) {
01621 $aDiscLog[$oDiscount->getId()] = $oDiscount->getSimpleDiscount();
01622 }
01623
01624 $aDiscLog[$oDiscount->getId()]->dDiscount += $dOldPrice - $dNewPrice;
01625 $aDiscLog[$oDiscount->getId()]->dDiscount *= $dAmount;
01626 $dOldPrice = $dNewPrice;
01627 }
01628 return $aDiscLog;
01629 }
01630
01639 public function delete( $sOXID = null )
01640 {
01641 if ( !$sOXID ) {
01642 $sOXID = $this->getId();
01643 }
01644 if ( !$sOXID ) {
01645 return false;
01646 }
01647
01648
01649 $this->load( $sOXID );
01650 $this->_deletePics();
01651 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01652 $this->_deleteVariantRecords( $sOXID );
01653 $rs = $this->_deleteRecords( $sOXID );
01654
01655 oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01656
01657 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01658
01659 return $rs->EOF;
01660 }
01661
01670 public function updateSoldAmount( $iAmount = 0 )
01671 {
01672 if ( !$iAmount ) {
01673 return;
01674 }
01675
01676 $this->beforeUpdate();
01677
01678 // article is not variant - should be updated current amount
01679 if ( !$this->oxarticles__oxparentid->value ) {
01680 //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01681 $rs = oxDb::getDb()->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $iAmount, oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '".$this->oxarticles__oxid->value."'");
01682 } elseif ( $this->oxarticles__oxparentid->value) {
01683 // article is variant - should be updated this article parent amount
01684 $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01685 $oUpdateArticle->updateSoldAmount( $iAmount );
01686 }
01687
01688 $this->onChange( ACTION_UPDATE );
01689
01690 return $rs;
01691 }
01692
01698 public function disableReminder()
01699 {
01700 $oDB = oxDb::getDb(true);
01701 return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = '".$this->oxarticles__oxid->value."'");
01702 }
01703
01710 public function save()
01711 {
01712 $myConfig = $this->getConfig();
01713
01714 $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01715 $this->oxarticles__oxicon = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01716 $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01717 for ($i=1; $i <= $iPicCount; $i++) {
01718 if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01719 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01720 }
01721 }
01722 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
01723 for ($i=1; $i <= $iZoomPicCount; $i++) {
01724 if ( isset($this->{'oxarticles__oxzoom'.$i}) ) {
01725 $this->{'oxarticles__oxzoom'.$i}->setValue(basename($this->{'oxarticles__oxzoom'.$i}->value));
01726 }
01727 }
01728
01729
01730 $blRet = parent::save();
01731
01732 // save article long description
01733 $this->setArticleLongDesc();
01734 // load article images after save
01735 $this->_assignPictureValues();
01736
01737 return $blRet;
01738 }
01739
01746 public function getPictureGallery()
01747 {
01748 $myConfig = $this->getConfig();
01749
01750 //initialize
01751 $blMorePic = false;
01752 $aArtPics = array();
01753 $aArtIcons = array();
01754 $iActPicId = 1;
01755 $sActPic = $this->getPictureUrl( $iActPicId );
01756
01757 if ( oxConfig::getParameter( 'actpicid' ) ) {
01758 $iActPicId = oxConfig::getParameter('actpicid');
01759 }
01760
01761 $iCntr = 0;
01762 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01763 for ( $i = 1; $i <= $iPicCount; $i++) {
01764 $sPicVal = $this->getPictureUrl( $i );
01765 $sIcoVal = $this->getIconUrl( $i );
01766 if ( !strstr($sIcoVal, 'nopic_ico.jpg')) {
01767 if ($iCntr) {
01768 $blMorePic = true;
01769 }
01770 $aArtIcons[$i]= $sIcoVal;
01771 $aArtPics[$i]= $sPicVal;
01772 $iCntr++;
01773 }
01774 if ($iActPicId == $i) {
01775 $sActPic = $sPicVal;
01776 }
01777 }
01778
01779 $blZoomPic = false;
01780 $aZoomPics = array();
01781 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
01782 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
01783 $sVal = $this->getZoomPictureUrl($j);
01784 if ( !strstr($sVal, 'nopic.jpg')) {
01785 if ($this->getConfig()->getConfigParam('blFormerTplSupport')) {
01786 $sVal = $this->_sDynImageDir."/".$sVal;
01787 }
01788 $blZoomPic = true;
01789 $aZoomPics[$c]['id'] = $c;
01790 $aZoomPics[$c]['file'] = $sVal;
01791 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01792 if (!$sVal) {
01793 $aZoomPics[$c]['file'] = "nopic.jpg";
01794 }
01795 $c++;
01796 }
01797 }
01798
01799 $aPicGallery = array('ActPicID' => $iActPicId,
01800 'ActPic' => $sActPic,
01801 'MorePics' => $blMorePic,
01802 'Pics' => $aArtPics,
01803 'Icons' => $aArtIcons,
01804 'ZoomPic' => $blZoomPic,
01805 'ZoomPics' => $aZoomPics);
01806
01807 return $aPicGallery;
01808 }
01809
01823 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
01824 {
01825 $myConfig = $this->getConfig();
01826
01827 if (!isset($sOXID)) {
01828 if ( $this->getId()) {
01829 $sOXID = $this->getId();
01830 }
01831 if (!isset ($sOXID)) {
01832 $sOXID = $this->oxarticles__oxid->value;
01833 }
01834 if ($this->oxarticles__oxparentid->value) {
01835 $sParentID = $this->oxarticles__oxparentid->value;
01836 }
01837 }
01838 if (!isset($sOXID)) {
01839 return;
01840 }
01841
01842 //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
01843 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
01844 //if article has variants then updating oxvarstock field
01845 //getting parent id
01846 if (!isset($sParentID)) {
01847 $sQ = 'select oxparentid from oxarticles where oxid = \''.$sOXID.'\'';
01848 $sParentID = oxDb::getDb()->getOne($sQ);
01849 }
01850
01851 if ($sParentID) {
01852 $this->_onChangeUpdateStock($sParentID);
01853 }
01854 }
01855
01856
01857 if ($sParentID) {
01858 $this->_onChangeUpdateVarCount($sParentID);
01859 }
01860
01861 $sId = ( $sParentID ) ? $sParentID : $sOXID;
01862 $this->_onChangeUpdateMinVarPrice( $sId );
01863
01864 }
01865
01872 public function getCustomVAT()
01873 {
01874 if ( isset($this->oxarticles__oxvat->value) ) {
01875 return $this->oxarticles__oxvat->value;
01876 }
01877 }
01878
01886 public function checkForStock( $dAmount )
01887 {
01888 $myConfig = $this->getConfig();
01889 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
01890 return true;
01891 }
01892
01893
01894 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
01895 $rs = oxDb::getDb(true)->Execute( $sQ );
01896
01897 $iOnStock = 0;
01898 $iStockFlag = 0;
01899 if ( $rs !== false && $rs->recordCount() > 0 ) {
01900 $iOnStock = $rs->fields['oxstock'];
01901 $iStockFlag = $rs->fields['oxstockflag'];
01902
01903
01904 if ( $iStockFlag == 1 || $iStockFlag == 4) {
01905 return true;
01906 }
01907 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
01908
01909
01910
01911
01912 $iOnStock = floor( $iOnStock );
01913
01914 }
01915 }
01916
01917 if ( $iOnStock >= $dAmount ) {
01918 return true;
01919 } else {
01920 if ( $iOnStock > 0 ) {
01921 return $iOnStock;
01922 } else {
01923 return false;
01924 }
01925 }
01926 }
01927
01928
01936 public function getArticleLongDesc($sOXID = null)
01937 {
01938
01939 if ( !$sOXID ) {
01940 $sOXID = $this->oxarticles__oxid->value;
01941 }
01942
01943 if ($sOXID == $this->oxarticles__oxid->value) {
01944 if (isset($this->oxarticles__oxlongdesc) && ($this->oxarticles__oxlongdesc instanceof oxField) && $this->oxarticles__oxlongdesc->value) {
01945 return $this->oxarticles__oxlongdesc;
01946 }
01947 }
01948
01949 $myConfig = $this->getConfig();
01950
01951
01952 $this->oxarticles__oxlongdesc = new oxField();
01953 $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
01954 $this->oxarticles__oxlongdesc->table = 'oxarticles';
01955 $this->oxarticles__oxlongdesc->fldtype = 'text';
01956
01957 if ( $sOXID ) {
01958 $sLangField = oxLang::getInstance()->getLanguageTag($this->getLanguage());
01959 $this->oxarticles__oxlongdesc->setValue(oxDb::getDb()->getOne( "select oxlongdesc{$sLangField} from oxartextends where oxid = '$sOXID'" ), oxField::T_RAW);
01960
01961
01962
01963 $this->oxarticles__oxlongdesc->setValue(str_replace( '&nbsp;', ' ', $this->oxarticles__oxlongdesc->value ), oxField::T_RAW);
01964 $this->oxarticles__oxlongdesc->setValue(str_replace( '&', '&', $this->oxarticles__oxlongdesc->value ), oxField::T_RAW);
01965 $this->oxarticles__oxlongdesc->setValue(str_replace( '"', '"', $this->oxarticles__oxlongdesc->value ), oxField::T_RAW);
01966 $blHasSmarty = strstr( $this->oxarticles__oxlongdesc->value, '[{' );
01967 if ( $blHasSmarty && ($myConfig->getConfigParam( 'blExport' ) || !$this->isAdmin() ) && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
01968 $this->oxarticles__oxlongdesc->setValue(oxUtilsView::getInstance()->parseThroughSmarty( $this->oxarticles__oxlongdesc->value, $this->getId() ), oxField::T_RAW);
01969 }
01970
01971 }
01972
01973 return $this->oxarticles__oxlongdesc;
01974 }
01975
01981 public function setArticleLongDesc()
01982 {
01983
01984 if ($this->_blEmployMultilanguage) {
01985
01986 if ($this->oxarticles__oxlongdesc instanceof oxField) {
01987 $sLongDesc = $this->oxarticles__oxlongdesc->getRawValue();
01988 } else {
01989 $sLongDesc = $this->oxarticles__oxlongdesc->value;
01990 }
01991 $this->_saveArtLongDesc($this->getLanguage(), $sLongDesc);
01992 } else {
01993 $oArtExt = oxNew('oxi18n');
01994 $oArtExt->init('oxartextends');
01995 $aObjFields = $oArtExt->_getAllFields(true);
01996 foreach ($aObjFields as $sKey => $sValue ) {
01997 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
01998 $iLang = $oArtExt->_getFieldLang($sKey);
01999 $sField = $this->_getFieldLongName($sKey);
02000 $sLongDesc = null;
02001 if ($this->$sField instanceof oxField) {
02002 $sLongDesc = $this->$sField->getRawValue();
02003 } elseif (is_object($this->$sField)) {
02004 $sLongDesc = $this->$sField->value;
02005 }
02006 if (isset($sLongDesc)) {
02007 $this->_saveArtLongDesc($iLang, $sLongDesc);
02008 }
02009 }
02010 }
02011 }
02012 }
02013
02019 public function getAttributes()
02020 {
02021
02022 if ($this->_oAttributeList) {
02023 return $this->_oAttributeList;
02024 }
02025
02026 $oAttributeList = oxNew( 'oxattributelist' );
02027 $oAttributeList->loadAttributes( $this->getId());
02028
02029
02030 $this->_oAttributeList = $oAttributeList;
02031
02032 return $oAttributeList;
02033 }
02034
02042 public function appendLink( $sAddParams )
02043 {
02044 if ( $this->_sDetailLink === null ) {
02045 $this->_sDetailLink = $this->getLink();
02046 }
02047 $this->_sDetailLink .= (( strpos( $this->_sDetailLink, '?' ) !== false ) ? '&' : '?' ) . $sAddParams;
02048 }
02049
02057 public function getLink($iLang = null)
02058 {
02059 if (isset($iLang)) {
02060 $iLang = (int) $iLang;
02061 if ($iLang == (int) $this->getLanguage()) {
02062 $iLang = null;
02063 }
02064 }
02065 if ( $this->_sDetailLink === null || isset($iLang) ) {
02066
02067 if ( oxUtils::getInstance()->seoIsActive() ) {
02068 $oxdetaillink = oxSeoEncoderArticle::getInstance()->getArticleUrl( $this, $iLang, $this->_iLinkType);
02069 } else {
02070 $oxdetaillink = $this->getStdLink($iLang);
02071 }
02072
02073 if (isset($iLang)) {
02074 return $oxdetaillink;
02075 } else {
02076 $this->_sDetailLink = $oxdetaillink;
02077 }
02078 }
02079
02080 return $this->_sDetailLink;
02081 }
02082
02090 public function setLinkType( $iType )
02091 {
02092
02093 $this->_sDetailLink = null;
02094
02095
02096 $this->_iLinkType = (int) $iType;
02097 }
02098
02106 public function getStdLink($iLang = null)
02107 {
02108
02109 $sUrl = $this->getConfig()->getShopHomeURL( $iLang, false );
02110 $sUrl .= "cl=details&anid=".$this->getId();
02111
02112 $blSeo = oxUtils::getInstance()->seoIsActive();
02113 if ( !$blSeo || $this->_iLinkType != 0 ) {
02114
02115 if ( !$blSeo ) {
02116 $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
02117 if ( $iPgNr > 0 ) {
02118 $sUrl .= "&pgNr={$iPgNr}";
02119 }
02120 }
02121
02122 if ( ( $sCat = oxConfig::getParameter( 'cnid' ) ) ) {
02123 $sUrl .= "&cnid={$sCat}";
02124 }
02125
02126 if ( ( $sCat = oxConfig::getParameter( 'mnid' ) ) ) {
02127 $sUrl .= "&mnid={$sCat}";
02128 }
02129
02130 $sListType = oxConfig::getParameter( 'listtype' );
02131 if ( !isset( $sListType ) ) {
02132
02133 $sListType = $this->getConfig()->getGlobalParameter( 'listtype' );
02134 }
02135
02136
02137 if ( $sListType ) {
02138 $sUrl .= "&listtype={$sListType}";
02139 }
02140
02141 if (!$blSeo && isset($iLang)) {
02142 $iLang = (int) $iLang;
02143 if ($iLang != (int) $this->getLanguage()) {
02144 $sUrl .= "&lang={$iLang}";
02145 }
02146 }
02147 }
02148
02149 return $sUrl;
02150 }
02151
02157 public function getTags()
02158 {
02159 $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02160 $sQ = "select $sTagField from oxartextends where oxid = '".$this->getId()."'";
02161 $sTags = oxDb::getDb(true)->getOne($sQ);
02162 $oTagCloud = oxNew('oxtagcloud');
02163 $sTags = $oTagCloud->trimTags($sTags);
02164 return $sTags;
02165 }
02166
02174 public function saveTags($sTags)
02175 {
02176 $sTags = mysql_real_escape_string($sTags);
02177 $oTagCloud = oxNew('oxtagcloud');
02178 $oTagCloud->resetTagCache();
02179 $sTags = $oTagCloud->prepareTags($sTags);
02180 $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02181 $sQ = "update oxartextends set $sTagField = '$sTags' where oxid = '".$this->getId()."'";
02182 return oxDb::getDb()->execute($sQ);
02183
02184 }
02185
02193 public function addTag($sTag)
02194 {
02195 $sTag = mysql_real_escape_string($sTag);
02196
02197 $oTagCloud = oxNew('oxtagcloud');
02198 $oTagCloud->resetTagCache();
02199 $sTag = $oTagCloud->prepareTags($sTag);
02200
02201 $sField = "oxartextends.OXTAGS".oxLang::getInstance()->getLanguageTag();
02202 $sQ = "insert into oxartextends (oxartextends.OXID, $sField) values ('".$this->getId()."', '{$sTag}')
02203 ON DUPLICATE KEY update $sField = CONCAT(TRIM($sField), ' $sTag') ";
02204
02205 return oxDb::getDb()->Execute($sQ);
02206 }
02207
02213 public function getMediaUrls()
02214 {
02215 if ($this->_aMediaUrls) {
02216 return $this->_aMediaUrls;
02217 }
02218
02219 $this->_aMediaUrls = oxNew("oxlist");
02220 $this->_aMediaUrls->init("oxmediaurl");
02221 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02222
02223 $sQ = "select * from oxmediaurls where oxobjectid = '".$this->getId()."'";
02224 $this->_aMediaUrls->selectString($sQ);
02225
02226 return $this->_aMediaUrls;
02227 }
02228
02234 public function getDynImageDir()
02235 {
02236 return $this->_sDynImageDir;
02237 }
02238
02244 public function getDispSelList()
02245 {
02246 if ($this->_aDispSelList === null) {
02247 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02248 $this->_aDispSelList = $this->getSelectLists();
02249 }
02250 }
02251 return $this->_aDispSelList;
02252 }
02253
02259 public function getMoreDetailLink()
02260 {
02261 return $this->_sMoreDetailLink;
02262 }
02263
02269 public function getToBasketLink()
02270 {
02271 return $this->_sToBasketLink;
02272 }
02273
02279 public function getStockStatus()
02280 {
02281 return $this->_iStockStatus;
02282 }
02283
02289 public function getDeliveryDate()
02290 {
02291 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02292 return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02293 } else {
02294 return false;
02295 }
02296 }
02297
02303 public function getFTPrice()
02304 {
02305 if ( $oPrice = $this->getTPrice() ) {
02306 if ( $oPrice->getBruttoPrice() ) {
02307 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02308 }
02309 } else {
02310 return null;
02311 }
02312 }
02313
02319 public function getFPrice()
02320 {
02321 if ( $oPrice = $this->getPrice() ) {
02322 return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02323 } else {
02324 return null;
02325 }
02326 }
02327
02333 public function getPricePerUnit()
02334 {
02335 return $this->_fPricePerUnit;
02336 }
02337
02343 public function isParentNotBuyable()
02344 {
02345 return $this->_blNotBuyableParent;
02346 }
02347
02353 public function isNotBuyable()
02354 {
02355 return $this->_blNotBuyable;
02356 }
02357
02363 public function getVariantList()
02364 {
02365 return $this->_oVariantList;
02366 }
02367
02375 public function setSelectlist( $aSelList )
02376 {
02377 $this->_aDispSelList = $aSelList;
02378 }
02379
02387 public function getPictureUrl( $iIndex )
02388 {
02389 return $this->getConfig()->getPictureUrl( $this->{"oxarticles__oxpic".$iIndex}->value );
02390 }
02391
02399 public function getIconUrl( $iIndex = '')
02400 {
02401 if (!$iIndex) {
02402 $sFile = $this->oxarticles__oxicon->value;
02403 } else {
02404 $sFile = $this->{'oxarticles__oxpic' . $iIndex . '_ico'}->value;
02405 }
02406
02407 $sFile = str_replace('nopic.jpg', 'nopic_ico.jpg', $sFile);
02408
02409
02410 $sFile = $this->getConfig()->getPictureUrl( $sFile );
02411
02412 return $sFile;
02413 }
02414
02420 public function getThumbnailUrl()
02421 {
02422
02423 return $this->getConfig()->getPictureUrl( '0/' ) . basename($this->oxarticles__oxthumb->value);
02424 }
02425
02433 public function getZoomPictureUrl($iIndex)
02434 {
02435 return $this->getConfig()->getPictureUrl( $this->{'oxarticles__oxzoom'.$iIndex}->value );
02436 }
02437
02443 public function getFileUrl()
02444 {
02445 return $this->getConfig()->getPictureUrl( '0/' );
02446 }
02447
02453 public function getPriceFromPrefix()
02454 {
02455 $sPricePrefics = '';
02456 if ( $this->_blIsRangePrice) {
02457 $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02458 }
02459
02460 return $sPricePrefics;
02461 }
02462
02471 protected function _saveArtLongDesc($iLang, $sValue)
02472 {
02473 $oDB = oxDb::getDb();
02474 $iLang = (int) $iLang;
02475 $sLangField = ($iLang > '0') ? '_'.$iLang : '';
02476 $sLongDesc = $oDB->quote($sValue);
02477 $sLongDescSQL = "insert into oxartextends (oxartextends.OXID, oxartextends.OXLONGDESC{$sLangField})
02478 VALUES ('".$this->getId()."', {$sLongDesc})
02479 ON DUPLICATE KEY update oxartextends.OXLONGDESC{$sLangField} = {$sLongDesc} ";
02480
02481 $oDB->execute($sLongDescSQL);
02482 }
02483
02499 protected function _removeInactiveVariants( $oVariants, $blStrict = false )
02500 {
02501 $myConfig = $this->getConfig();
02502 $this->_iVarStock = 0;
02503 $this->_blHasVariants = false;
02504 $now = time();
02505 $sSearchdate = date('Y-m-d H:i:s', $now);
02506 $this->_iVarStock = $this->oxarticles__oxvarstock->value;
02507
02508
02509 foreach (array_keys($oVariants->getArray()) as $key ) {
02510
02511 $oVariant = $oVariants[$key];
02512 $this->_blHasVariants = true;
02513
02514 if ( $myConfig->getConfigParam( 'blUseStock' ) &&
02515 $oVariant->oxarticles__oxstockflag->value != 1 && $oVariant->oxarticles__oxstockflag->value != 4 &&
02516 ($oVariant->oxarticles__oxstockflag->value != 3 || $blStrict) && $oVariant->oxarticles__oxstock->value <= 0) {
02517 unset($oVariants[$key]);
02518 continue;
02519 }
02520
02521
02522 if (!$oVariant->oxarticles__oxactive->value &&
02523 !($oVariant->oxarticles__oxactivefrom->value < $sSearchdate &&
02524 $oVariant->oxarticles__oxactiveto->value > $sSearchdate) ) {
02525 unset($oVariants[$key]);
02526 continue;
02527 }
02528 }
02529
02530
02531 if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
02532 $this->_blNotBuyableParent = true;
02533 }
02534
02535
02536 if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $oVariants->count() == 0 && $this->_blHasVariants) {
02537 $this->_blNotBuyable = true;
02538 }
02539
02540 return $oVariants;
02541 }
02542
02546 protected function _skipSaveFields()
02547 {
02548 $myConfig = $this->getConfig();
02549
02550 $this->_aSkipSaveFields = array();
02551
02552 $this->_aSkipSaveFields[] = 'oxtimestamp';
02553 $this->_aSkipSaveFields[] = 'oxlongdesc';
02554 $this->_aSkipSaveFields[] = 'oxinsert';
02555
02556 if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02557 $this->_aSkipSaveFields[] = 'oxparentid';
02558 }
02559
02560 }
02561
02571 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02572 {
02573 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02574
02575 if ( array_key_exists ($sKey, $aDiscounts) ) {
02576 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02577 } else {
02578 $aDiscounts[$sKey] = $oDiscount;
02579 }
02580 }
02581 return $aDiscounts;
02582 }
02583
02589 protected function _getGroupPrice()
02590 {
02591 $dPrice = $this->oxarticles__oxprice->value;
02592
02593 $oUser = $this->getArticleUser();
02594 if ( $oUser ) {
02595 if ( $oUser->inGroup( 'oxidpricea' ) ) {
02596 $dPrice = $this->oxarticles__oxpricea->value;
02597 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
02598 $dPrice = $this->oxarticles__oxpriceb->value;
02599 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
02600 $dPrice = $this->oxarticles__oxpricec->value;
02601 }
02602 }
02603
02604
02605 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
02606 $dPrice = $this->oxarticles__oxprice->value;
02607 }
02608
02609 return $dPrice;
02610 }
02611
02620 protected function _getAmountPrice($dAmount = 1)
02621 {
02622 $myConfig = $this->getConfig();
02623
02624 startProfile( "_getAmountPrice" );
02625
02626 $dPrice = $this->_getGroupPrice();
02627 $oAmtPrices = $this->_getAmountPriceList();
02628 foreach ($oAmtPrices as $oAmPrice) {
02629 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
02630 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
02631 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
02632 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
02633 }
02634 }
02635
02636 stopProfile( "_getAmountPrice" );
02637 return $dPrice;
02638 }
02639
02648 protected function _modifySelectListPrice( &$dPrice, $aChosenList = null )
02649 {
02650 $myConfig = $this->getConfig();
02651
02652 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
02653
02654 $aSelLists = $this->getSelectLists();
02655 foreach ( $aSelLists as $key => $aSel) {
02656 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
02657 $oSel = $aSel[$aChosenList[$key]];
02658 if ( $oSel->priceUnit =='abs' ) {
02659 $dPrice += $oSel->price;
02660 } elseif ( $oSel->priceUnit =='%' ) {
02661 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
02662 }
02663 }
02664 }
02665 }
02666 return $dPrice;
02667 }
02668
02669
02677 protected function _fillAmountPriceList($oAmPriceList)
02678 {
02679 $myConfig = $this->getConfig();
02680 $myUtils = oxUtils::getInstance();
02681
02682
02683 $oCur = $myConfig->getActShopCurrencyObject();
02684
02685 $oUser = $this->getArticleUser();
02686
02687 $aDiscountList = oxDiscountList::getInstance()->getArticleDiscounts($this, $oUser );
02688
02689 $oLowestPrice = null;
02690
02691 $dBasePrice = $this->_getGroupPrice();
02692 $oLang = oxLang::getInstance();
02693
02694 $dArticleVat = null;
02695 if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
02696 $dArticleVat = oxNew('oxVatSelector')->getArticleVat( $this );
02697 }
02698
02699
02700 foreach ($oAmPriceList as $sId => $oItem) {
02701 $oItemPrice = oxNew( 'oxprice' );
02702 if ( $oItem->oxprice2article__oxaddabs->value) {
02703 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
02704 $this->_applyDiscounts( $oItemPrice, $aDiscountList );
02705 $this->_applyCurrency( $oItemPrice, $oCur );
02706 } else {
02707 $oItemPrice->setPrice( $dBasePrice );
02708 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
02709 }
02710
02711 if (isset($dArticleVat)) {
02712 $this->_applyVAT($oItemPrice, $dArticleVat);
02713 }
02714
02715 if (!$oLowestPrice) {
02716 $oLowestPrice = $oItemPrice;
02717 } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
02718 $oLowestPrice = $oItemPrice;
02719 }
02720
02721 $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
02722 $oAmPriceList[$sId]->fnetprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
02723 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
02724 }
02725
02726 $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
02727 return $oAmPriceList;
02728 }
02729
02735 protected function _getVariantsIds()
02736 {
02737 $aSelect = array();
02738 $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->oxarticles__oxid->value."' " );
02739 if ( $oRs != false && $oRs->recordCount() > 0 ) {
02740 while (!$oRs->EOF) {
02741 $aSelect[] = $oRs->fields['oxid'];
02742 $oRs->moveNext();
02743 }
02744 }
02745 return $aSelect;
02746 }
02747
02756 protected function _applyVAT( oxPrice $oPrice, $dVat )
02757 {
02758 startProfile(__FUNCTION__);
02759 $oPrice->setVAT( $dVat );
02760 if ( ( $oUser = $this->getArticleUser() ) ) {
02761 if ( ( $dVat = oxNew( 'oxVatSelector' )->getUserVat( $oUser ) ) !== false ) {
02762 $oPrice->setUserVat( $dVat );
02763 }
02764 }
02765 stopProfile(__FUNCTION__);
02766 }
02767
02776 protected function _applyDiscounts( $oPrice, $aDiscounts )
02777 {
02778 reset( $aDiscounts );
02779 while ( list( , $oDiscount ) = each( $aDiscounts ) ) {
02780 $oDiscount->applyDiscount( $oPrice );
02781 }
02782 }
02783
02792 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
02793 {
02794 if ( !$oCur ) {
02795 $oCur = $this->getConfig()->getActShopCurrencyObject();
02796 }
02797
02798 $oPrice->multiply($oCur->rate);
02799 }
02800
02809 protected function _getIcon()
02810 {
02811
02812
02813 $myConfig = $this->getConfig();
02814
02815 if (!$myConfig->getConfigParam( 'blAutoIcons' ) ) {
02816 if ($this->oxarticles__oxicon->value) {
02817 return basename($this->oxarticles__oxicon->value);
02818 } else {
02819 $sQ = "UPDATE oxarticles SET oxicon = 'nopic_ico.jpg' WHERE oxid = '".$this->getId()."'";
02820 oxDb::getDb()->execute($sQ);
02821 return 'nopic_ico.jpg';
02822 }
02823 }
02824
02825
02826 if ( $this->oxarticles__oxicon->value && strpos( $this->oxarticles__oxicon->value, 'nopic_ico.jpg') === false ) {
02827 return basename($this->oxarticles__oxicon->value);
02828 }
02829
02830
02831 if ($this->oxarticles__oxthumb->value && strpos( $this->oxarticles__oxthumb->value, 'nopic.jpg') === false && function_exists('gd_info')) {
02832
02833 $sSourceFile = $this->oxarticles__oxthumb->value;
02834 $sTargetFile = str_replace('_th', '_ico', $sSourceFile);
02835
02836 if ($sSourceFile == $sTargetFile) {
02837 $sPattern = '(\.[a-z0-9]*$)';
02838 $sTargetFile = eregi_replace($sPattern, '_ico\\1', $sTargetFile);
02839 }
02840
02841 $sTarget = $myConfig->getAbsDynImageDir().'/icon/'. basename($sTargetFile);
02842 $sSource = $myConfig->getAbsDynImageDir().'/0/'. basename($sSourceFile);
02843
02844 if (!$myConfig->getConfigParam( 'sIconsize' ) ) {
02845 $myConfig->setConfigParam( 'sIconsize', '56*42' );
02846 }
02847
02848 $aSize = explode('*', $myConfig->getConfigParam( 'sIconsize' ) );
02849 $iX = $aSize[0];
02850 $iY = $aSize[1];
02851
02852 oxUtilspic::getInstance()->resizeImage( $sSource, $sTarget, $iX, $iY );
02853
02854 $sResult = $sTargetFile;
02855 } else {
02856 $sResult = 'nopic_ico.jpg';
02857 }
02858
02859
02860 $sIconFile = basename($sResult);
02861
02862 $sQ = "UPDATE oxarticles SET oxicon = '$sIconFile' WHERE oxid = '".$this->getId()."'";
02863
02864 oxDb::getDb()->execute($sQ);
02865
02866 return $sIconFile;
02867 }
02868
02869
02878 protected function _getAttribsString(&$sAttribs, &$iCnt)
02879 {
02880
02881 $oDB = oxDb::getDb(true);
02882 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->oxarticles__oxid->value.'" ';
02883 $sAttribs = '';
02884 $blSep = false;
02885 $rs = $oDB->execute( $sSelect);
02886 $iCnt = 0;
02887 if ($rs != false && $rs->recordCount() > 0) {
02888 while (!$rs->EOF) {
02889 if ( $blSep) {
02890 $sAttribs .= ' or ';
02891 }
02892 $sAttribs .= 't1.oxattrid = "'.$rs->fields['oxattrid'].'" ';
02893 $blSep = true;
02894 $iCnt++;
02895 $rs->moveNext();
02896 }
02897 }
02898 }
02899
02908 protected function _getSimList($sAttribs, $iCnt)
02909 {
02910 $myConfig = $this->getConfig();
02911 $oDB = oxDb::getDb(true);
02912
02913
02914 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
02915
02916 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
02917 $iAttrPercent = 0.70;
02918 }
02919 $iHitMin = round( $iCnt * $iAttrPercent + 0.5);
02920
02921
02922 $aList= array();
02923 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
02924 ( $sAttribs )
02925 and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
02926 group by t1.oxobjectid having count(*) >= $iHitMin ";
02927
02928 $rs = $oDB->selectLimit( $sSelect, 20, 0);
02929 if ($rs != false && $rs->recordCount() > 0) {
02930 while (!$rs->EOF) {
02931 $oTemp = new stdClass();
02932 $oTemp->cnt = $rs->fields['cnt'];
02933 $oTemp->id = $rs->fields['oxobjectid'];
02934 $aList[] = $oTemp;
02935 $rs->moveNext();
02936 }
02937 }
02938 return $aList;
02939 }
02940
02949 protected function _generateSimListSearchStr($sArticleTable, $aList)
02950 {
02951 $myConfig = $this->getConfig();
02952 $sFieldList = $this->getSelectFields();
02953 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
02954 $blSep = false;
02955 $iCnt = 0;
02956 foreach ( $aList as $oTemp) {
02957 if ( $blSep) {
02958 $sSearch .= ',';
02959 }
02960 $sSearch .= "'".$oTemp->id."'";
02961 $blSep = true;
02962 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
02963 break;
02964 }
02965 $iCnt++;
02966 }
02967
02968
02969
02970 $sSearch .= ') ';
02971
02972
02973 $sSearch .= ' order by rand() ';
02974
02975 return $sSearch;
02976 }
02977
02986 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
02987 {
02988 $sCatView = getViewName( 'oxcategories' );
02989 $sO2CView = getViewName( 'oxobject2category' );
02990
02991
02992 if ( !$blSearchPriceCat ) {
02993 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
02994 {$sCatView}.oxid = oxobject2category.oxcatnid
02995 where oxobject2category.oxobjectid='{$sOXID}' and {$sCatView}.oxid is not null ";
02996 } else {
02997 $sSelect = "select {$sCatView}.* from {$sCatView} where
02998 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
02999 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03000 }
03001 return $sSelect;
03002 }
03003
03009 protected function _generateSearchStrForCustomerBought()
03010 {
03011 $sArtTable = $this->_getObjectViewName( 'oxarticles' );
03012 $sOrderArtTable = getViewName( 'oxorderarticles' );
03013
03014
03015 $sIn = " '{$this->oxarticles__oxid->value}' ";
03016 if ( $this->oxarticles__oxparentid->value ) {
03017
03018
03019 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03020 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03021
03022 } else {
03023 $sParentIdForVariants = $this->getId();
03024 }
03025
03026
03027 $oRs = oxDb::getDb(true)->execute( "select oxid from {$sArtTable} where oxparentid = '{$sParentIdForVariants}' and oxid != '{$this->oxarticles__oxid->value}' " );
03028 if ( $oRs != false && $oRs->recordCount() > 0) {
03029 while ( !$oRs->EOF ) {
03030 $sIn .= ", '".current( $oRs->fields )."' ";
03031 $oRs->moveNext();
03032 }
03033 }
03034
03035 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03036 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03037
03038
03039 $sQ = "select distinct {$sArtTable}.* from (
03040 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03041 ) as suborder
03042 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03043 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03044 where {$sArtTable}.oxid not in ( {$sIn} )
03045 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03046
03047
03048
03049
03050
03051
03052
03053
03054
03055
03056 return $sQ;
03057 }
03058
03068 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03069 {
03070 $sCategoryView = getViewName('oxcategories');
03071 $sO2CView = getViewName('oxobject2category');
03072 $sLangPrefix = (($this->getLanguage())?'_'.$this->getLanguage():'');
03073 if (!$dPriceFromTo) {
03074 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03075 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03076 $sSelect .= "where oxobject2category.oxcatnid='$sCatId' and oxobject2category.oxobjectid='$sOXID' ";
03077 $sSelect .= "and oxcategories.oxactive$sLangPrefix = 1 order by oxobject2category.oxtime ";
03078 } else {
03079 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03080 $sSelect .= "oxcategories.oxid='$sCatId' and '$dPriceFromTo' >= oxcategories.oxpricefrom and ";
03081 $sSelect .= "'$dPriceFromTo' <= oxcategories.oxpriceto ";
03082 }
03083 return $sSelect;
03084 }
03085
03091 protected function _getAmountPriceList()
03092 {
03093 if ($this->_oAmountPriceList) {
03094 return $this->_oAmountPriceList;
03095 }
03096
03097 $myConfig = $this->getConfig();
03098
03099 $sArtID = $this->getId();
03100
03101
03102 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03103 $sArtID = $this->oxarticles__oxparentid->value;
03104 }
03105
03106
03107 $sArtID = mysql_real_escape_string($sArtID);
03108
03109
03110 $oAmPriceList = oxNew( 'oxlist');
03111 $oAmPriceList->init('oxbase', 'oxprice2article');
03112
03113 $sShopID = $myConfig->getShopID();
03114 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03115 $sShopSelect = '1';
03116 } else {
03117 $sShopSelect = " oxshopid = '$sShopID' ";
03118 }
03119
03120 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03121
03122
03123 $oBasePrice = $this->_getGroupPrice();
03124 foreach ($oAmPriceList as $oAmPrice) {
03125 if ($oAmPrice->oxprice2article__oxaddperc->value) {
03126 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03127 }
03128 }
03129
03130 $this->_oAmountPriceList = $oAmPriceList;
03131 return $oAmPriceList;
03132 }
03133
03141 protected function _isFieldEmpty($sFieldName)
03142 {
03143 $mValue = $this->$sFieldName->value;
03144
03145 if (is_null($mValue)) {
03146 return true;
03147 }
03148
03149 if ($mValue === '') {
03150 return true;
03151 }
03152
03153 $aDoubleCopyFields = array('oxarticles__oxprice',
03154 'oxarticles__oxvat');
03155
03156 if (!$mValue && in_array($sFieldName, $aDoubleCopyFields))
03157 return true;
03158
03159
03160 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03161 return true;
03162 }
03163
03164 $sFieldName = strtolower($sFieldName);
03165
03166 if ($mValue == "nopic_ico.jpg" && $sFieldName == 'oxarticles__oxicon') {
03167 return true;
03168 }
03169
03170 if ($mValue == "nopic.jpg" && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom')) {
03171 return true;
03172 }
03173
03174 return false;
03175 }
03176
03184 protected function _assignParentFieldValue($sFieldName)
03185 {
03186 if (!($oParentArticle = $this->_getParentAricle())) {
03187 return;
03188 }
03189
03190 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03191
03192
03193 if ( $oParentArticle->$sCopyFieldName != null ) {
03194
03195
03196 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03197 continue;
03198 }
03199
03200
03201 $aNonCopyFields = array('oxarticles__oxinsert',
03202 'oxarticles__oxtimestamp',
03203 'oxarticles__oxnid',
03204 'oxarticles__oxid',
03205 'oxarticles__oxparentid');
03206
03207 $aCopyParentField = array('oxarticles__oxnonmaterial',
03208 'oxarticles__oxfreeshipping',
03209 'oxarticles__oxremindactive');
03210
03211 if (in_array($sCopyFieldName, $aNonCopyFields)) {
03212 return;
03213 }
03214
03215
03216
03217
03218 if ($sFieldName == "oxicon" && !$this->_isFieldEmpty("oxarticles__oxthumb") && $this->oxarticles__oxthumb->value != $oParentArticle->oxarticles__oxthumb->value && $this->getConfig()->getConfigParam( 'blAutoIcons' ) ) {
03219 return ;
03220 }
03221
03222
03223
03224
03225 if ($this->_isFieldEmpty($sCopyFieldName) || in_array($sCopyFieldName, $aCopyParentField)) {
03226 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03227 }
03228
03229
03230
03231
03232
03233
03234
03235
03236
03237
03238
03239
03240
03241
03242
03243
03244
03245
03246
03247
03248
03249
03250
03251
03252
03253
03254
03255 }
03256 }
03257
03263 protected function _getParentAricle()
03264 {
03265 $sParentId = $this->oxarticles__oxparentid->value;
03266 if (!$sParentId) {
03267 return null;
03268 }
03269 if (isset(self::$_aLoadedParents[$sParentId])) {
03270 return self::$_aLoadedParents[$sParentId];
03271 } else {
03272 $oParentArticle = oxNew( 'oxarticle' );
03273 $oParentArticle->_blSkipAbPrice = true;
03274 $oParentArticle->_blLoadPrice = false;
03275 $oParentArticle->_blLoadVariants = false;
03276 $oParentArticle->load( $sParentId);
03277 self::$_aLoadedParents[$sParentId] = $oParentArticle;
03278 return $oParentArticle;
03279 }
03280 }
03281
03287 protected function _assignParentFieldValues()
03288 { startProfile('articleAssignParentInternal');
03289 if ( $this->oxarticles__oxparentid->value) {
03290
03291 if ( !$this->isAdmin() || ($this->_blLoadParentData && $this->isAdmin() ) ) {
03292 foreach ($this->_aFieldNames as $sFieldName => $sVal) {
03293 $this->_assignParentFieldValue($sFieldName);
03294 }
03295
03296
03297 $oParentArticle = $this->_getParentAricle();
03298 if ( !$this->oxarticles__oxlongdesc->value ) {
03299 $this->oxarticles__oxlongdesc = $oParentArticle->oxarticles__oxlongdesc;
03300 }
03301 }
03302 } elseif ( $this->oxarticles__oxid->value ) {
03303
03304
03305 startProfile("loadVariants");
03306 $this->_oVariantList = $this->getVariants();
03307 stopProfile("loadVariants");
03308
03309
03310
03311
03312
03313
03314 }
03315 stopProfile('articleAssignParentInternal');
03316
03317 }
03318
03324 protected function _assignNotBuyableParent()
03325 {
03326 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03327 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03328 $this->_blNotBuyableParent = true;
03329
03330 }
03331 }
03332
03338 protected function _assignPictureValues()
03339 {
03340 $myConfig = $this->getConfig();
03341 $this->oxarticles__oxicon = new oxField($this->_getIcon());
03342
03343
03344 $sNoPic = 'nopic.jpg';
03345 $sNoPicIcon = 'nopic_ico.jpg';
03346
03347 if ( isset($this->_aFieldNames["oxthumb"]) && !$this->oxarticles__oxthumb->value) {
03348 $this->oxarticles__oxthumb = new oxField($sNoPic);
03349 }
03350
03351
03352
03353
03354
03355 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03356 for ( $i=1; $i<= $iPicCount; $i++ ) {
03357 if ( isset($this->_aFieldNames["oxpic".$i]) && !$this->{'oxarticles__oxpic'.$i}->value ) {
03358 $this->{'oxarticles__oxpic'.$i} = new oxField($sNoPic);
03359 }
03360 }
03361
03362 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
03363 for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03364 if ( isset($this->_aFieldNames["oxzoom".$i]) && !$this->{'oxarticles__oxzoom'.$i}->value) {
03365 $this->{'oxarticles__oxzoom'.$i} = new oxField($sNoPic);
03366 }
03367 }
03368
03369 if ( !$this->isAdmin() ) {
03370
03371 if ( isset($this->_aFieldNames["oxthumb"])) {
03372 $this->oxarticles__oxthumb->setValue('0/'.basename($this->oxarticles__oxthumb->value));
03373 }
03374 if ( isset($this->_aFieldNames["oxicon"])) {
03375 $this->oxarticles__oxicon = new oxField('icon/'.basename($this->oxarticles__oxicon->value));
03376 }
03377
03378 $myUtilsPic = oxUtilsPic::getInstance();
03379 for ( $i=1; $i<= $iPicCount; $i++ ) {
03380 $sFieldName = 'oxarticles__oxpic'.$i;
03381 if ( isset($this->_aFieldNames["oxpic".$i])) {
03382 $sIconFieldName = 'oxarticles__oxpic'.$i.'_ico';
03383 $this->$sIconFieldName = new oxField($i.'/'.basename($myUtilsPic->iconName($this->$sFieldName->value)));
03384 $this->$sFieldName = new oxField($i.'/'.basename($this->$sFieldName->value));
03385 }
03386 }
03387 for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03388 if ( isset($this->_aFieldNames["oxzoom".$i])) {
03389 $this->{'oxarticles__oxzoom'.$i} = new oxField('z'.$i.'/'.basename($this->{'oxarticles__oxzoom'.$i}->value));
03390 }
03391 }
03392 }
03393
03394 }
03395
03401 protected function _assignStock()
03402 {
03403 $myConfig = $this->getConfig();
03404
03405
03406
03407
03408
03409 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03410 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03411 }
03412
03413 $this->_iStockStatus = 0;
03414
03415
03416 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03417
03418 $iStock = $this->oxarticles__oxstock->value;
03419
03420 if ($this->_blNotBuyableParent) {
03421 $iStock = $this->oxarticles__oxvarstock->value;
03422 }
03423
03424
03425 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03426 $this->_iStockStatus = 1;
03427 }
03428
03429
03430 if ($iStock <= 0) {
03431 $this->_iStockStatus = -1;
03432 }
03433 }
03434
03435
03436
03437 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstock->value <= 0 && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03438 $this->_blNotBuyable = true;
03439 }
03440
03441
03442 if ($this->_blNotBuyable && $this->_iVarStock) {
03443 $this->_blNotBuyable = false;
03444
03445 $this->_blNotBuyableParent = true;
03446 }
03447
03448
03449
03450
03451 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03452 $this->_blNotBuyable = true;
03453 }
03454
03455
03456 if ($this->_blNotBuyableParent && count($this->_oVariantList) == 0) {
03457 $this->_blNotBuyable = true;
03458 }
03459 }
03460
03466 protected function _assignPrices()
03467 {
03468 $myConfig = $this->getConfig();
03469
03470
03471 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03472 return;
03473 }
03474
03475
03476
03477 $dPrice = $this->getPrice()->getBruttoPrice();
03478
03479 $oCur = $myConfig->getActShopCurrencyObject();
03480
03481 if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03482 $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03483 }
03484
03485
03486
03487 $this->_applyRangePrice();
03488 }
03489
03495 protected function _assignPersistentParam()
03496 {
03497
03498 $aPersParam = oxSession::getVar( 'persparam');
03499 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03500 $this->_aPersistParam = $aPersParam[$this->getId()];
03501 }
03502 }
03503
03509 protected function _assignDynImageDir()
03510 {
03511 $myConfig = $this->getConfig();
03512
03513 $sThisShop = $this->oxarticles__oxshopid->value;
03514
03515 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03516 $this->dabsimagedir = $myConfig->getPictureDir( false );
03517 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03518 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03519 }
03520
03526 protected function _assignComparisonListFlag()
03527 {
03528
03529
03530 $aItems = oxConfig::getParameter('aFiltcompproducts');
03531 if ( isset( $aItems[$this->getId()])) {
03532 $this->_blIsOnComparisonList = true;
03533 }
03534 }
03535
03541 protected function _assignAttributes()
03542 {
03543
03544
03545 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03546 $this->getAttributes();
03547 }
03548 }
03549
03550
03556 protected function _assignLinks()
03557 {
03558 $myConfig = $this->getConfig();
03559
03560
03561 $sURL = $myConfig->getShopHomeURL();
03562 $sActCat = oxConfig::getParameter( 'cnid' );
03563 $sActClass = oxConfig::getParameter( 'cl' );
03564 $sTPL = basename( oxConfig::getParameter( 'tpl' ) );
03565
03566
03567 if ( $sActClass == 'thankyou') {
03568 $sActClass = 'basket';
03569 }
03570
03571 $sCnid = '';
03572
03573
03574 if ($sActCat) {
03575 $sCnid = '&cnid='.$sActCat;
03576 }
03577
03578 $this->_sDetailLink = $this->getLink();
03579
03580
03581
03582
03583
03584
03585 $this->_sMoreDetailLink = $sURL. 'cl=moredetails&cnid='.$sActCat.'&anid='.$this->getId();
03586
03587 if ( oxUtils::getInstance()->isSearchEngine() ) {
03588 $this->_sToBasketLink = $this->_sDetailLink;
03589 } else {
03590 $this->_sToBasketLink = $sURL. 'cl='.$sActClass.'&fnc=tobasket'.$sCnid.'&aid='.$this->getId().'&anid='.$this->getId();
03591 }
03592
03593
03594 if ( isset( $sTPL) && $sTPL) {
03595 $this->_sToBasketLink .= '&tpl='.$sTPL;
03596 }
03597 }
03598
03606 protected function _insert()
03607 {
03608
03609 $iInsertTime = time();
03610 $now = date('Y-m-d H:i:s', $iInsertTime);
03611 $this->oxarticles__oxinsert = new oxField( $now );
03612 $this->oxarticles__oxtimestamp = new oxField( $now );
03613 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03614 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03615 }
03616
03617 return parent::_insert();
03618 }
03619
03625 protected function _update()
03626 {
03627
03628 $myConfig = $this->getConfig();
03629
03630
03631 $this->_skipSaveFields();
03632
03633 return parent::_update();
03634 }
03635
03643 protected function _deleteRecords($sOXID)
03644 {
03645
03646
03647 $oDB = oxDb::getDb();
03648 $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = \''.$sOXID.'\' ';
03649 $oDB->execute( $sDelete);
03650
03651 //remove other records
03652 $sDelete = 'delete from oxobject2article where oxarticlenid = \''.$sOXID.'\' or oxobjectid = \''.$sOXID.'\' ';
03653 $oDB->execute( $sDelete);
03654
03655 $sDelete = 'delete from oxobject2attribute where oxobjectid = \''.$sOXID.'\' ';
03656 $oDB->execute( $sDelete);
03657
03658 $sDelete = 'delete from oxobject2category where oxobjectid = \''.$sOXID.'\' ';
03659 $oDB->execute( $sDelete);
03660
03661 $sDelete = 'delete from oxobject2selectlist where oxobjectid = \''.$sOXID.'\' ';
03662 $oDB->execute( $sDelete);
03663
03664 $sDelete = 'delete from oxprice2article where oxartid = \''.$sOXID.'\' ';
03665 $oDB->execute( $sDelete);
03666
03667 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = \''.$sOXID.'\' ';
03668 $oDB->execute( $sDelete);
03669
03670 $sDelete = 'delete from oxaccessoire2article where oxobjectid = "'.$sOXID.'" or oxarticlenid = "'.$sOXID.'" ';
03671 $oDB->execute( $sDelete);
03672
03673 //#1508C - deleting oxobject2delivery entries added
03674 $sDelete = 'delete from oxobject2delivery where oxobjectid = \''.$sOXID.'\' and oxtype=\'oxarticles\' ';
03675 $oDB->execute( $sDelete);
03676
03677 $sDelete = 'delete from oxartextends where oxid = \''.$sOXID.'\' ';
03678 $oDB->execute( $sDelete);
03679
03680 $sDelete = 'delete from oxactions2article where oxartid = \''.$sOXID.'\' ';
03681 $rs = $oDB->execute( $sDelete );
03682
03683
03684 return $rs;
03685 }
03686
03694 protected function _deleteVariantRecords($sOXID)
03695 {
03696 $oDB = oxDb::getDb();
03697 //collect variants to remove recursively
03698 $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = \''.$sOXID.'\'';
03699 $rs = $oDB->execute( $sVariants);
03700 if ($rs != false && $rs->recordCount() > 0) {
03701 while (!$rs->EOF) {
03702 $this->delete( $rs->fields[0]);
03703 $rs->moveNext();
03704 }
03705 }
03706 }
03707
03717 protected function _resetCacheAndArticleCount( $sOxid )
03718 {
03719 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03720 }
03721
03727 protected function _deletePics()
03728 {
03729 $myUtilsPic = oxUtilsPic::getInstance();
03730 $myConfig = $this->getConfig();
03731
03732
03733 $blThumbDeleted = $myUtilsPic->safePictureDelete( $this->oxarticles__oxthumb->value, $myConfig->getAbsDynImageDir().'/0', 'oxarticles', 'oxthumb' );
03734
03735 if ( $blThumbDeleted ) {
03736 $myUtilsPic->safePictureDelete('icon/'.$this->oxarticles__oxicon->value, $myConfig->getAbsDynImageDir(), 'oxarticles', 'oxicon' );
03737 }
03738
03739
03740
03741
03742
03743
03744 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03745 $sAbsDynImageDir = $myConfig->getAbsDynImageDir();
03746 for ( $i = 1; $i <= $iPicCount; $i++ ) {
03747
03748 $sPicFName = $this->{'oxarticles__oxpic'.$i}->value;
03749 $myUtilsPic->safePictureDelete($sPicFName, $sAbsDynImageDir.'/'.$i, 'oxarticles', 'oxpic'.$i );
03750 }
03751
03752 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
03753 for ( $i = 1; $i <= $iZoomPicCount; $i++ ) {
03754 if ( isset($this->{'oxarticles__oxzoom'.$i}) ) {
03755 $myUtilsPic->safePictureDelete($this->{'oxarticles__oxzoom'.$i}->value, $sAbsDynImageDir.'/z'.$i, 'oxarticles', 'oxzoom'.$i );
03756 }
03757 }
03758
03759 }
03760
03770 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
03771 {
03772
03773 $myUtilsCount = oxUtilsCount::getInstance();
03774
03775 if ( $sVendorId ) {
03776 $myUtilsCount->resetVendorArticleCount( $sVendorId );
03777 }
03778
03779 if ( $sManufacturerId ) {
03780 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
03781 }
03782
03783
03784 $sQ = "select oxcatnid from oxobject2category where oxobjectid = '{$sOxid}'";
03785 $oRs = oxDb::getDb()->execute( $sQ );
03786 if ( $oRs !== false && $oRs->recordCount() > 0) {
03787 while ( !$oRs->EOF ) {
03788 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
03789 $oRs->moveNext();
03790 }
03791 }
03792 }
03793
03801 protected function _onChangeUpdateStock( $sParentID )
03802 {
03803 $oDb = oxDb::getDb();
03804 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = \''.$sParentID.'\' ';
03805 $rs = $oDb->execute($sQ);
03806 $iOldStock = $rs->fields[0];
03807 $iVendorID = $rs->fields[1];
03808 $iManufacturerID = $rs->fields[2];
03809
03810 $sQ = 'select sum(oxstock) from oxarticles where oxparentid = \''.$sParentID.'\' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
03811 $iStock = (float) $oDb->getOne( $sQ );
03812
03813 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = \''.$sParentID.'\'';
03814 $oDb->execute( $sQ );
03815
03816
03817
03818 if ( $iStock < 0 ) {
03819 $iStock = 0;
03820 }
03821 if ( $iOldStock < 0 ) {
03822 $iOldStock = 0;
03823 }
03824 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
03825
03826
03827 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
03828 }
03829 }
03830
03838 protected function _onChangeUpdateVarCount( $sParentID )
03839 {
03840 $oDb = oxDb::getDb();
03841 $sQ = 'select count(*) as varcount from oxarticles where oxparentid = \''.$sParentID.'\' ';
03842 $iVarCount = (int) $oDb->getOne($sQ);
03843
03844 $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = \''.$sParentID.'\'';
03845 $oDb->execute($sQ);
03846 }
03847
03855 protected function _onChangeUpdateMinVarPrice( $sParentID )
03856 {
03857 $sQ = 'select min(oxprice) as varminprice from oxarticles where oxparentid = "'.$sParentID.'"';
03858
03859 if ( !$this->isParentNotBuyable() || $this->oxarticles__oxvarcount->value == 0) {
03860 $sQ .= ' or oxid = "'.$sParentID.'"';
03861 }
03862
03863 $oDb = oxDb::getDb();
03864 $dVarMinPrice = $oDb->getOne($sQ);
03865 if ( $dVarMinPrice ) {
03866 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = "'.$sParentID.'"';
03867 $oDb->execute($sQ);
03868 }
03869 }
03870
03871
03877 protected function _applyRangePrice()
03878 {
03879
03880 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03881 return;
03882 }
03883
03884 $this->_blIsRangePrice = false;
03885
03886 if ($this->_blSkipAbPrice && !$this->_blNotBuyableParent) {
03887 return;
03888 }
03889
03890 $aPrices = array();
03891
03892 if (!$this->_blNotBuyableParent) {
03893 $aPrices[] = $this->getPrice()->getBruttoPrice();
03894 }
03895
03896 if (count($this->_oVariantList)) {
03897 foreach ($this->_oVariantList as $sKey => $oVariant) {
03898 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
03899 }
03900 }
03901
03902
03903
03904
03905
03906
03907 if (count($aPrices)) {
03908 $dMinPrice = $aPrices[0];
03909 $dMaxPrice = $aPrices[0];
03910 foreach ($aPrices as $dPrice) {
03911 if ($dMinPrice > $dPrice) {
03912 $dMinPrice = $dPrice;
03913 }
03914
03915 if ($dMaxPrice < $dPrice) {
03916 $dMaxPrice = $dPrice;
03917 }
03918 }
03919 }
03920
03921 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
03922 $this->getPrice()->setBruttoPriceMode();
03923 $this->getPrice()->setPrice($dMinPrice);
03924 }
03925
03926 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
03927 $this->getPrice()->setBruttoPriceMode();
03928 $this->getPrice()->setPrice($dMinPrice);
03929 $this->_blIsRangePrice = true;
03930 }
03931
03932 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
03933 $this->getPrice()->setBruttoPriceMode();
03934 $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
03935 $this->_blIsRangePrice = true;
03936 }
03937 }
03938 }