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
00016 class oxArticle extends oxI18n implements oxIArticle
00017 {
00023 protected $_sCoreTbl = 'oxarticles';
00024
00030 protected $_sClassName = 'oxarticle';
00031
00037 protected $_blUseLazyLoading = true;
00038
00044 protected $_sItemKey;
00045
00051 protected $_blCalcPrice = true;
00052
00057 protected $_oPrice = null;
00058
00064 protected $_dArticleVat = null;
00065
00071 protected $_aPersistParam = null;
00072
00078 protected $_blNotBuyable = false;
00079
00086 protected $_blLoadVariants = true;
00087
00093 protected $_aVariants = null;
00094
00100 protected $_aVariantsWithNotOrderables = null;
00101
00110 protected $_blNotBuyableParent = false;
00111
00116 protected $_blHasVariants = false;
00117
00121 protected $_iVarStock = 0;
00122
00127 protected $_oVariantList = array();
00128
00133 protected $_blIsOnComparisonList = false;
00134
00139 protected $_oUser = null;
00140
00146 protected $_blLoadPrice = true;
00147
00151 protected $_blSkipAbPrice = false;
00152
00159 protected $_fPricePerUnit = null;
00160
00164 protected $_blLoadParentData = false;
00165
00169 protected $_blSkipAssign = false;
00170
00176 protected $_blSkipDiscounts = null;
00177
00182 protected $_oAttributeList = null;
00183
00184
00190 protected $_blIsRangePrice = false;
00191
00197 protected $_aMediaUrls = null;
00198
00204 static protected $_aLoadedParents;
00205
00211 static protected $_aSelList;
00212
00218 protected $_aDispSelList;
00219
00225 protected $_blIsSeoObject = true;
00226
00232 protected $_oAmountPriceList = null;
00233
00242 protected $_iLinkType = 0;
00243
00249 protected $_sStdLink = null;
00250
00256 protected $_sDynImageDir = null;
00257
00263 protected $_sMoreDetailLink = null;
00264
00270 protected $_sToBasketLink = null;
00271
00277 protected $_iStockStatus = null;
00278
00284 protected $_oTPrice = null;
00285
00291 protected $_oAmountPriceInfo = null;
00292
00298 protected $_dAmountPrice = null;
00299
00305 protected $_sDetailLink = null;
00306
00312 protected static $_aArticleManufacturers = array();
00313
00319 protected static $_aArticleVendors = array();
00320
00326 protected static $_aArticleCats = array();
00327
00336 public function __construct($aParams = null)
00337 {
00338 if ( $aParams && is_array($aParams)) {
00339 foreach ( $aParams as $sParam => $mValue) {
00340 $this->$sParam = $mValue;
00341 }
00342 }
00343 parent::__construct();
00344 $this->init( 'oxarticles' );
00345
00346 $this->_blIsRangePrice = false;
00347 }
00348
00356 public function __isset( $sName )
00357 {
00358 if ( $sName == 'oxarticles__oxlongdesc' ) {
00359
00360 $this->getArticleLongDesc();
00361 return true;
00362 }
00363 return isset( $this->$sName );
00364 }
00365
00374 public function __get($sName)
00375 {
00376 $myUtils = oxUtils::getInstance();
00377 switch ($sName) {
00378
00379
00380
00381
00382 case 'netprice':
00383 case 'netPrice':
00384 $mVal = $myUtils->fRound($this->getPrice()->getNettoPrice());
00385 break;
00386 case 'brutPrice':
00387 return $myUtils->fRound($this->getPrice()->getBruttoPrice());
00388 break;
00389 case 'vatPercent':
00390 return $this->getPrice()->getVAT();
00391 break;
00392 case 'vat':
00393 return $this->getPrice()->getVATValue();
00394 break;
00395 case 'fnetprice':
00396 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($this->getPrice()->getNettoPrice()));
00397 break;
00398 case 'fprice':
00399 return $this->getFPrice();
00400 break;
00401
00402
00403 case 'dtprice':
00404 if ( $oPrice = $this->getTPrice() ) {
00405 return $myUtils->fRound($oPrice->getBruttoPrice());
00406 break;
00407 } else {
00408 return null;
00409 break;
00410 }
00411 case 'tvat':
00412 if ( $oPrice = $this->getTPrice() ) {
00413 return $oPrice->getVATValue();
00414 break;
00415 } else {
00416 return null;
00417 break;
00418 }
00419 case 'ftprice':
00420 if ( $oPrice = $this->getTPrice() ) {
00421 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($oPrice->getBruttoPrice()) );
00422 break;
00423 } else {
00424 return null;
00425 break;
00426 }
00427 case 'oxarticles__oxlongdesc':
00428 return $this->getArticleLongDesc($this->getId());
00429 break;
00430 case 'foxdelivery':
00431 return $this->getDeliveryDate();
00432 break;
00433 case 'sItemKey':
00434 return $this->getItemKey();
00435 break;
00436 case 'selectlist':
00437 return $this->_aDispSelList = $this->getDispSelList();
00438 break;
00439 case 'blNotBuyable':
00440 return $this->isNotBuyable();
00441 break;
00442 case 'blNotBuyableParent':
00443 return $this->isParentNotBuyable();
00444 break;
00445 case 'blIsOnComparisonList':
00446 return $this->isOnComparisonList();
00447 break;
00448 case 'oVariantlist' :
00449 return $this->_oVariantList;
00450 break;
00451 case 'fPricePerUnit' :
00452 return $this->getPricePerUnit();
00453 break;
00454 case 'dimagedir' :
00455 return $this->_sDynImageDir = $this->getDynImageDir();
00456 break;
00457 case 'oxmoredetaillink' :
00458 return $this->_sMoreDetailLink = $this->getMoreDetailLink();
00459 break;
00460 case 'amountpricelist' :
00461 return $this->loadAmountPriceInfo();
00462 break;
00463 case 'stockstatus' :
00464 return $this->getStockStatus();
00465 break;
00466 case 'tobasketlink' :
00467 return $this->getToBasketLink();
00468 break;
00469 case 'oxdetaillink' :
00470 return $this->getLink();
00471 break;
00472 case 'aSelectlist' :
00473 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00474 return $this->aSelectlist = $this->getSelectLists();
00475 }
00476 return;
00477 break;
00478
00479
00480 }
00481
00482 $this->$sName = parent::__get($sName);
00483 if ( $this->$sName ) {
00484 $this->_assignParentFieldValue($sName);
00485 }
00486
00487 if ($sName == "oxarticles__oxthumb" || $sName == "oxarticles__oxicon" || strpos($sName, "oxarticles__oxpic") === 0 || strpos($sName, "oxarticles__oxzoom") === 0) {
00488 $this->_assignPictureValues();
00489 return $this->$sName;
00490 }
00491
00492 return $this->$sName;
00493 }
00494
00502 public function setId( $sId = null )
00503 {
00504 $sId = parent::setId( $sId );
00505
00506
00507 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00508
00509 return $sId;
00510 }
00511
00519 public function getTableNameForActiveSnippet( $blForceCoreTable = false )
00520 {
00521 $sTable = $this->getCoreTableName();
00522
00523 return $sTable;
00524 }
00525
00535 public function getActiveCheckQuery( $blForceCoreTable = false )
00536 {
00537 $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00538
00539
00540 $sQ = " $sTable.oxactive = 1 ";
00541
00542
00543 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00544 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00545 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00546 }
00547
00548 return $sQ;
00549 }
00550
00564 public function getStockCheckQuery( $blForceCoreTable = false )
00565 {
00566 $myConfig = $this->getConfig();
00567 $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00568
00569 $sQ = "";
00570
00571
00572 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00573 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00574
00575 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00576 $sTimeCheckQ = '';
00577 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00578 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00579 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00580 }
00581 $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 ) ) ";
00582 }
00583 }
00584
00585 return $sQ;
00586 }
00587
00599 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = false )
00600 {
00601 $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00602 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00603
00604
00605 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $blRemoveNotOrderables ) {
00606 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and ( $sTable.oxstockflag = 1 or $sTable.oxstockflag = 4 ) ) ) ";
00607 }
00608
00609 return $sQ;
00610 }
00611
00619 public function getSqlActiveSnippet( $blForceCoreTable = false )
00620 {
00621 $myConfig = $this->getConfig();
00622
00623
00624 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00625
00626
00627 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00628
00629
00630 return "( $sQ ) ";
00631 }
00632
00640 public function setSkipAssign($blSkipAssign)
00641 {
00642 $this->_blSkipAssign = $blSkipAssign;
00643 }
00644
00652 public function disablePriceLoad( $oArticle )
00653 {
00654 $oArticle->_blLoadPrice = false;
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
00756 public function setSkipAbPrice( $blSkipAbPrice = null )
00757 {
00758 $this->_blSkipAbPrice = $blSkipAbPrice;
00759 }
00760
00766 public function getSearchableFields()
00767 {
00768 $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00769 $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00770
00771 return $aFields;
00772 }
00773
00774
00782 public function isMultilingualField($sFieldName)
00783 {
00784 switch ($sFieldName) {
00785 case "oxlongdesc":
00786 case "oxtags":
00787 return true;
00788 }
00789
00790 return parent::isMultilingualField($sFieldName);
00791 }
00792
00798 public function isVisible()
00799 {
00800
00801
00802 $myConfig = $this->getConfig();
00803 if ( ( $sPrevId = oxConfig::getParameter( 'preview' ) ) &&
00804 ( $sAdminSid = oxUtilsServer::getInstance()->getOxCookie( 'admin_sid' ) ) ) {
00805
00806 $oDb = oxDb::getDb();
00807 $sPrevId = $oDb->quote( $sPrevId );
00808 $sAdminSid = $oDb->quote( $sAdminSid );
00809 $sTable = getViewName( 'oxuser' );
00810
00811 return (bool) $oDb->getOne( "select 1 from $sTable where MD5( CONCAT( {$sAdminSid}, {$sTable}.oxid, {$sTable}.oxpassword, {$sTable}.oxrights ) ) = $sPrevId" );
00812 }
00813
00814
00815 $sNow = date('Y-m-d H:i:s');
00816 if ( !$this->oxarticles__oxactive->value &&
00817 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00818 $this->oxarticles__oxactiveto->value < $sNow
00819 )) {
00820 return false;
00821 }
00822
00823
00824 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
00825 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
00826 return false;
00827 }
00828
00829 return true;
00830 }
00831
00840 public function assign( $aRecord)
00841 {
00842 startProfile('articleAssign');
00843
00844
00845
00846 parent::assign( $aRecord);
00847
00848 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00849
00850
00851 if ($this->_blSkipAssign) {
00852 return;
00853 }
00854
00855 $this->_assignParentFieldValues();
00856 $this->_assignNotBuyableParent();
00857 $this->_assignPictureValues();
00858 $this->_assignStock();
00859 startProfile('articleAssignPrices');
00860 $this->_assignPrices();
00861 stopProfile('articleAssignPrices');
00862 $this->_assignPersistentParam();
00863 $this->_assignDynImageDir();
00864 $this->_assignComparisonListFlag();
00865 $this->_assignAttributes();
00866
00867
00868
00869
00870 stopProfile('articleAssign');
00871 }
00872
00883 public function load( $oxID)
00884 {
00885
00886 $this->_blNotBuyableParent = false;
00887
00888 $blRet = parent::load( $oxID);
00889
00890
00891 $this->oxarticles__oxinsert = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00892 $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00893
00894 return $blRet;
00895 }
00896
00904 public function addToRatingAverage( $iRating)
00905 {
00906 $dOldRating = $this->oxarticles__oxrating->value;
00907 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00908 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00909 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00910 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00911 $dRatingCnt = (int)($dOldCnt + 1);
00912
00913 oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00914 }
00915
00921 public function getArticleRatingAverage()
00922 {
00923 return round( $this->oxarticles__oxrating->value, 1);
00924 }
00925
00931 public function getReviews()
00932 {
00933 $myConfig = $this->getConfig();
00934
00935 $aIds = array($this->getId());
00936
00937 if ( $this->oxarticles__oxparentid->value ) {
00938 $aIds[] = $this->oxarticles__oxparentid->value;
00939 }
00940
00941
00942 if ( $myConfig->getConfigParam( 'blShowVariantReviews' ) ) {
00943 $aAdd = $this->_getVariantsIds();
00944 if (is_array($aAdd)) {
00945 $aIds = array_merge($aIds, $aAdd);
00946 }
00947 }
00948
00949 $oReview = oxNew('oxreview');
00950 $oRevs = $oReview->loadList('oxarticle', $aIds);
00951
00952
00953 if ( $oRevs->count() < 1 ) {
00954 return null;
00955 }
00956
00957 return $oRevs;
00958 }
00959
00965 public function getCrossSelling()
00966 {
00967 $oCrosslist = oxNew( "oxarticlelist");
00968 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00969 if ( $oCrosslist->count() ) {
00970 return $oCrosslist;
00971 }
00972 }
00973
00979 public function getAccessoires()
00980 {
00981 $myConfig = $this->getConfig();
00982
00983
00984 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00985 return;
00986 }
00987
00988 $oAcclist = oxNew( "oxarticlelist");
00989 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00990 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
00991
00992 if ( $oAcclist->count()) {
00993 return $oAcclist;
00994 }
00995 }
00996
01002 public function getSimilarProducts()
01003 {
01004
01005 $myConfig = $this->getConfig();
01006 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01007 return;
01008 }
01009
01010 $sArticleTable = $this->_getObjectViewName('oxarticles');
01011
01012 $sAttribs = '';
01013 $iCnt = 0;
01014 $this->_getAttribsString($sAttribs, $iCnt);
01015
01016 if ( !$sAttribs) {
01017 return null;
01018 }
01019
01020
01021
01022
01023
01024
01025 $aList = $this->_getSimList($sAttribs, $iCnt);
01026
01027 if ( count( $aList ) ) {
01028 uasort( $aList, 'cmpart');
01029
01030 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01031
01032 $oSimilarlist = oxNew( 'oxarticlelist' );
01033 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01034 $oSimilarlist->selectString( $sSearch);
01035
01036 return $oSimilarlist;
01037 }
01038 }
01039
01045 public function getCustomerAlsoBoughtThisProducts()
01046 {
01047
01048 $myConfig = $this->getConfig();
01049 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01050 return;
01051 }
01052
01053
01054 $sQ = $this->_generateSearchStrForCustomerBought();
01055
01056 $oArticles = oxNew( 'oxarticlelist' );
01057 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01058 $oArticles->selectString( $sQ );
01059 if ( $oArticles->count() ) {
01060 return $oArticles;
01061 }
01062 }
01063
01070 public function loadAmountPriceInfo()
01071 {
01072 $myConfig = $this->getConfig();
01073 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01074 return array();
01075 }
01076
01077 if ( $this->_oAmountPriceInfo !== null ) {
01078 return $this->_oAmountPriceInfo;
01079 }
01080
01081 $oAmPriceList = $this->_getAmountPriceList();
01082
01083 if ( count( $oAmPriceList ) ) {
01084 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01085 return $this->_oAmountPriceInfo;
01086 }
01087
01088 return array();
01089 }
01090
01098 public function getSelectLists($sKeyPrefix = null)
01099 {
01100
01101
01102 $sKey = $this->getId();
01103 if ( isset( $sKeyPrefix ) ) {
01104 $sKey = $sKeyPrefix.'__'.$this->getId();
01105 }
01106
01107 if ( self::$_aSelList[$sKey]) {
01108 return self::$_aSelList[$sKey];
01109 }
01110
01111
01112 $oLists = oxNew( 'oxlist' );
01113 $oLists->init('oxselectlist');
01114 $sSLViewName = getViewName('oxselectlist');
01115 $sSelect = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01116 $sSelect .= 'where oxobject2selectlist.oxobjectid=\''.$this->getId().'\' ';
01117 //sorting
01118 $sSelect .= ' order by oxobject2selectlist.oxsort';
01119
01120 $oLists->selectString( $sSelect );
01121
01122 //#1104S if this is variant ant it has no selectlists, trying with parent
01123 if ( $this->oxarticles__oxparentid->value && $oLists->count() == 0 ) {
01124 $sParentQuoted = oxDb::getDb()->quote($this->oxarticles__oxparentid->value);
01125 //#1496C - select fixed ( * => $sSLViewName.*)
01126 $sSelect = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01127 $sSelect .= "where oxobject2selectlist.oxobjectid=$sParentQuoted ";
01128 //sorting
01129 $sSelect .= ' order by oxobject2selectlist.oxsort';
01130 $oLists->selectString( $sSelect);
01131 }
01132
01133 $dVat = 0;
01134 if ( $this->getPrice() != null ) {
01135 $dVat = $this->getPrice()->getVat();
01136 }
01137
01138 $iCnt = 0;
01139 self::$_aSelList[$sKey] = array();
01140 foreach ( $oLists as $oSelectlist ) {
01141 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01142 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01143 $iCnt++;
01144 }
01145 return self::$_aSelList[$sKey];
01146 }
01147
01155 protected function _hasAnyVariant( $blForceCoreTable = false )
01156 {
01157 $sArticleTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
01158 return (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='".$this->getId()."'" );
01159 }
01160
01168 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = false )
01169 {
01170 if ( $blRemoveNotOrderables && $this->_aVariants ) {
01171 return $this->_aVariants;
01172 } elseif ( !$blRemoveNotOrderables && $this->_aVariantsWithNotOrderables ) {
01173 return $this->_aVariantsWithNotOrderables;
01174 }
01175
01176 $myConfig = $this->getConfig();
01177 if ( !$this->_blLoadVariants ||
01178 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01179 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01180 return array();
01181 }
01182
01183 //do not load me as a parent later
01184 self::$_aLoadedParents[$this->getId()] = $this;
01185
01186 //load simple variants for lists
01187 if ( $this->_isInList() ) {
01188 $oVariants = oxNew( 'oxsimplevariantlist' );
01189 $oVariants->setParent( $this );
01190 } else {
01191 //loading variants
01192 $oVariants = oxNew( 'oxarticlelist' );
01193 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01194 }
01195
01196 $this->_iVarStock = $this->oxarticles__oxvarstock->value;
01197 if ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) {
01198
01199 startProfile("selectVariants");
01200 $blUseCoreTable = $blForceCoreTable;
01201 $oBaseObject = $oVariants->getBaseObject();
01202 $sArticleTable = $this->getTableNameForActiveSnippet( $blUseCoreTable );
01203
01204 $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01205 $this->getActiveCheckQuery( $blUseCoreTable ) .
01206 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01207 " order by $sArticleTable.oxsort";
01208
01209 $oVariants->selectString( $sSelect );
01210 stopProfile("selectVariants");
01211 }
01212
01213 //if we have variants then depending on config option the parent may be non buyable
01214 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01215 $this->_blNotBuyableParent = true;
01216 }
01217
01218 //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01219 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $oVariants->count() == 0 && $this->_blHasVariants ) {
01220 $this->_blNotBuyable = true;
01221 }
01222
01223 // cache
01224 if ( $blRemoveNotOrderables ) {
01225 $this->_aVariants = $oVariants;
01226 } else {
01227 $this->_aVariantsWithNotOrderables = $oVariants;
01228 }
01229
01230 return $oVariants;
01231 }
01232
01238 public function getSimpleVariants()
01239 {
01240 if ( $this->oxarticles__oxvarcount->value) {
01241 return $this->getVariants();
01242 }
01243 }
01244
01253 public function getAdminVariants( $sLanguage = null )
01254 {
01255 $myConfig = $this->getConfig();
01256
01257 $oVariants = oxNew( 'oxarticlelist');
01258
01259 if ( is_null($sLanguage) ) {
01260 $oVariants->getBaseObject()->setLanguage(oxLang::getInstance()->getBaseLanguage());
01261 } else {
01262 $oVariants->getBaseObject()->setLanguage($sLanguage);
01263 }
01264
01265 $sSql = 'select * from oxarticles where oxparentid = "'.$this->getId().'" order by oxsort ';
01266
01267 $oVariants->selectString( $sSql);
01268
01269 //if we have variants then depending on config option the parent may be non buyable
01270 if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01271 //$this->blNotBuyable = true;
01272 $this->_blNotBuyableParent = true;
01273 }
01274
01275 return $oVariants;
01276 }
01277
01285 public function getCategory()
01286 {
01287 startPRofile( 'getCategory' );
01288
01289 $oCategory = oxNew( 'oxcategory' );
01290 $oCategory->setLanguage( $this->getLanguage() );
01291
01292 // variant handling
01293 $sOXID = $this->getId();
01294 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01295 $sOXID = $this->oxarticles__oxparentid->value;
01296 }
01297
01298 $oStr = getStr();
01299 $sWhere = $oCategory->getSqlActiveSnippet();
01300 $sSelect = $this->_generateSearchStr( $sOXID );
01301 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime ";
01302
01303 // category not found ?
01304 if ( !$oCategory->assignRecord( $sSelect ) ) {
01305
01306 $sSelect = $this->_generateSearchStr( $sOXID, true );
01307 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere ;
01308
01309 // looking for price category
01310 if ( !$oCategory->assignRecord( $sSelect ) ) {
01311 $oCategory = null;
01312 }
01313 }
01314
01315 stopPRofile( 'getCategory' );
01316 return $oCategory;
01317 }
01318
01327 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01328 {
01329 $myConfig = $this->getConfig();
01330 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01331 return self::$_aArticleCats[$this->getId()];
01332 }
01333
01334 // variant handling
01335 $sOXID = $this->getId();
01336 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01337 $sOXID = $this->oxarticles__oxparentid->value;
01338 }
01339
01340 // we do not use lists here as we dont need this overhead right now
01341 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01342 $oDB = oxDb::getDb(true);
01343 $rs = $oDB->execute( $sSql );
01344
01345
01346 $aRet = array();
01347 $iHitMax = 0;
01348 if ($rs != false && $rs->recordCount() > 0) {
01349 while (!$rs->EOF) {
01350 $aRet[] = $rs->fields['oxcatnid'];
01351 $rs->moveNext();
01352 }
01353 }
01354
01355 return self::$_aArticleCats[$this->getId()] = $aRet;
01356 }
01357
01366 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01367 {
01368 $sO2CView = $this->_getObjectViewName('oxobject2category');
01369 $sCatView = $this->_getObjectViewName('oxcategories');
01370 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01371 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 ';
01372 if ( $blActCats ) {
01373 $sSelect .= "and oxcategories.oxhidden = 0 and (select count(cats.oxid) from $sCatView as cats where cats.oxrootid = oxcategories.oxrootid and cats.oxleft < oxcategories.oxleft and cats.oxright > oxcategories.oxright and ( cats.oxhidden = 1 or cats.oxactive".(($this->getLanguage())?"_".$this->getLanguage():"")." = 0 ) ) = 0 ";
01374 }
01375 $sSelect .= 'order by oxobject2category.oxtime ';
01376 return $sSelect;
01377 }
01378
01388 public function getVendor( $blShopCheck = true )
01389 {
01390 if ( ( $sVendorId = $this->getVendorId() ) ) {
01391 $oVendor = oxNew( 'oxvendor' );
01392 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01393 $oVendor = oxNew( 'oxi18n' );
01394 $oVendor->init('oxvendor');
01395 $oVendor->setReadOnly( true );
01396 $sVendorId = $this->oxarticles__oxvendorid->value;
01397 }
01398 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01399 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01400 $oVendor->setReadOnly( true );
01401 }
01402 return $oVendor;
01403 }
01404 return null;
01405 }
01406
01414 public function getVendorId( $blForceReload = false )
01415 {
01416 $sVendorId = false;
01417 if ( $this->oxarticles__oxvendorid->value ) {
01418 if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01419 return self::$_aArticleVendors[$this->getId()];
01420 }
01421 $oDb = oxDb::getDb();
01422 $sVendorIdQuoted = $oDb->quote($this->oxarticles__oxvendorid->value);
01423 $sQ = "select oxid from ".getViewName('oxvendor')." where oxid=$sVendorIdQuoted";
01424 self::$_aArticleVendors[$this->getId()] = $sVendorId = $oDb->getOne( $sQ );
01425 }
01426 return $sVendorId;
01427 }
01428
01436 public function getManufacturerId( $blForceReload = false )
01437 {
01438 $sManufacturerId = false;
01439 if ( $this->oxarticles__oxmanufacturerid->value ) {
01440 if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01441 return self::$_aArticleManufacturers[$this->getId()];
01442 }
01443 $oDb = oxDb::getDb();
01444 $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid=".$oDb->quote($this->oxarticles__oxmanufacturerid->value);
01445 self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = $oDb->getOne( $sQ );
01446 }
01447 return $sManufacturerId;
01448 }
01449
01459 public function getManufacturer( $blShopCheck = true )
01460 {
01461 $oManufacturer = oxNew( 'oxmanufacturer' );;
01462 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01463 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01464 $oManufacturer->setReadOnly( true );
01465 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01466 }
01467
01468 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01469 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01470 $oManufacturer->setReadOnly( true );
01471 }
01472 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01473 } else {
01474 $oManufacturer = null;
01475 }
01476
01477 return $oManufacturer;
01478 }
01479
01488 public function inCategory( $sCatNid)
01489 {
01490 return in_array( $sCatNid, $this->getCategoryIds());
01491 }
01492
01501 public function isAssignedToCategory( $sCatId )
01502 {
01503 // variant handling
01504 $sOXID = $this->getId();
01505 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01506 $sOXID = $this->oxarticles__oxparentid->value;
01507 }
01508
01509 $oDB = oxDb::getDb();
01510 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01511 $sOXID = $oDB->getOne( $sSelect);
01512 // article is assigned to passed category!
01513 if ( isset( $sOXID) && $sOXID) {
01514 return true;
01515 }
01516
01517 // maybe this category is price category ?
01518 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01519 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01520 if ( $dPriceFromTo > 0) {
01521 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01522 $sOXID = $oDB->getOne( $sSelect);
01523 // article is assigned to passed category!
01524 if ( isset( $sOXID) && $sOXID) {
01525 return true;
01526 }
01527 }
01528 }
01529 return false;
01530 }
01531
01537 public function getTPrice()
01538 {
01539 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01540 return;
01541 }
01542 // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01543 if ( $this->_oTPrice !== null ) {
01544 return $this->_oTPrice;
01545 }
01546
01547 $this->_oTPrice = oxNew( 'oxPrice' );
01548 $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01549
01550 $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01551 $this->_applyCurrency( $this->_oTPrice );
01552
01553 return $this->_oTPrice;
01554 }
01555
01561 public function skipDiscounts()
01562 {
01563 // allready loaded skip discounts config
01564 if ( $this->_blSkipDiscounts !== null )
01565 return $this->_blSkipDiscounts;
01566
01567 if ( $this->oxarticles__oxskipdiscounts->value )
01568 return true;
01569
01570 $sO2CView = getViewName('oxobject2category');
01571 $sSelect = "select 1 from $sO2CView as oxobject2category left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01572 $sSelect .= 'where oxobject2category.oxobjectid="'.$this->getId().'" and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 and oxcategories.oxskipdiscounts = "1" ';
01573
01574 return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01575 }
01576
01584 public function setPrice(oxPrice $oPrice)
01585 {
01586 $this->_oPrice = $oPrice;
01587 }
01588
01597 public function getBasePrice( $dAmount = 1 )
01598 {
01599 // override this function if you want e.g. different prices
01600 // for diff. usergroups.
01601
01602 // Performance
01603 $myConfig = $this->getConfig();
01604 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01605 return;
01606
01607 // GroupPrice or DB price ajusted by AmountPrice
01608 $dPrice = $this->_getAmountPrice( $dAmount );
01609
01610
01611 return $dPrice;
01612 }
01613
01619 public function getPrice()
01620 {
01621 $myConfig = $this->getConfig();
01622 // Performance
01623 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01624 return;
01625 }
01626 // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01627 if ( $this->_oPrice ) {
01628 return $this->_oPrice;
01629 }
01630
01631 $this->_oPrice = oxNew( 'oxPrice' );
01632
01633 // get base
01634 $this->_oPrice->setPrice( $this->getBasePrice() );
01635
01636 // price handling
01637 if ( !$this->_blCalcPrice ) {
01638 return $this->_oPrice;
01639 }
01640
01641 $this->_calculatePrice( $this->_oPrice );
01642
01643 return $this->_oPrice;
01644 }
01645
01653 protected function _calculatePrice( $oPrice )
01654 {
01655 // apply VAT only if configuration requires it
01656 if ( !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01657 $this->_applyVAT( $oPrice, $this->getArticleVat() );
01658 }
01659
01660 // apply currency
01661 $this->_applyCurrency( $oPrice );
01662 // apply discounts
01663 if ( !$this->skipDiscounts() ) {
01664 $oDiscountList = oxDiscountList::getInstance();
01665 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts($this, $this->getArticleUser() ) );
01666 }
01667
01668 return $oPrice;
01669 }
01670
01678 public function setArticleUser($oUser)
01679 {
01680 $this->_oUser = $oUser;
01681 }
01682
01688 public function getArticleUser()
01689 {
01690 if ($this->_oUser) {
01691 return $this->_oUser;
01692 }
01693 return $this->getUser();
01694 }
01695
01705 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01706 {
01707 $oUser = $oBasket->getBasketUser();
01708 $this->setArticleUser($oUser);
01709
01710 $oBasketPrice = oxNew( 'oxPrice' );
01711
01712 // get base price
01713 $dBasePrice = $this->getBasePrice( $dAmount );
01714
01715 // applying select list price
01716 $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01717
01718 // setting price
01719 $oBasketPrice->setPrice( $dBasePrice );
01720
01721 // apply VAT
01722 $this->_applyVat( $oBasketPrice, oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket ) );
01723
01724 // apply currency
01725 $this->_applyCurrency( $oBasketPrice );
01726
01727 // apply discounts
01728 if ( !$this->skipDiscounts() ) {
01729 // apply general discounts
01730 $oDiscountList = oxDiscountList::getInstance();
01731 $oDiscountList->applyDiscounts( $oBasketPrice, $oDiscountList->getArticleDiscounts( $this, $oUser ) );
01732 }
01733
01734 // returning final price object
01735 return $oBasketPrice;
01736 }
01737
01750 public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01751 {
01752 $oDiscountList = oxDiscountList::getInstance();
01753 return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01754 }
01755
01764 public function delete( $sOXID = null )
01765 {
01766 if ( !$sOXID ) {
01767 $sOXID = $this->getId();
01768 }
01769 if ( !$sOXID ) {
01770 return false;
01771 }
01772
01773
01774 $this->load( $sOXID );
01775 $this->_deletePics();
01776 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01777 $this->_deleteVariantRecords( $sOXID );
01778 $rs = $this->_deleteRecords( $sOXID );
01779
01780 oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01781
01782 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01783
01784 return $rs->EOF;
01785 }
01786
01795 public function updateSoldAmount( $dAmount = 0 )
01796 {
01797 if ( !$dAmount ) {
01798 return;
01799 }
01800
01801 $this->beforeUpdate();
01802
01803 // article is not variant - should be updated current amount
01804 if ( !$this->oxarticles__oxparentid->value ) {
01805 //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01806 $dAmount = (double)$dAmount;
01807 $oDb = oxDb::getDb();
01808 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount, oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01809 } elseif ( $this->oxarticles__oxparentid->value) {
01810 // article is variant - should be updated this article parent amount
01811 $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01812 $oUpdateArticle->updateSoldAmount( $dAmount );
01813 }
01814
01815 $this->onChange( ACTION_UPDATE );
01816
01817 return $rs;
01818 }
01819
01825 public function disableReminder()
01826 {
01827 $oDB = oxDb::getDb(true);
01828 return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01829 }
01830
01837 public function save()
01838 {
01839 $myConfig = $this->getConfig();
01840
01841 $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01842 $this->oxarticles__oxicon = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01843 $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01844 for ($i=1; $i <= $iPicCount; $i++) {
01845 if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01846 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01847 }
01848 }
01849 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
01850 for ($i=1; $i <= $iZoomPicCount; $i++) {
01851 if ( isset($this->{'oxarticles__oxzoom'.$i}) ) {
01852 $this->{'oxarticles__oxzoom'.$i}->setValue(basename($this->{'oxarticles__oxzoom'.$i}->value));
01853 }
01854 }
01855
01856 $blRet = parent::save();
01857
01858 // save article long description
01859 $this->setArticleLongDesc();
01860 // load article images after save
01861 $this->_assignPictureValues();
01862
01863 return $blRet;
01864 }
01865
01866
01873 public function getPictureGallery()
01874 {
01875 $myConfig = $this->getConfig();
01876
01877 //initialize
01878 $blMorePic = false;
01879 $aArtPics = array();
01880 $aArtIcons = array();
01881 $iActPicId = 1;
01882 $sActPic = $this->getPictureUrl( $iActPicId );
01883
01884 if ( oxConfig::getParameter( 'actpicid' ) ) {
01885 $iActPicId = oxConfig::getParameter('actpicid');
01886 }
01887
01888 $oStr = getStr();
01889 $iCntr = 0;
01890 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01891 for ( $i = 1; $i <= $iPicCount; $i++) {
01892 $sPicVal = $this->getPictureUrl( $i );
01893 $sIcoVal = $this->getIconUrl( $i );
01894 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg')) {
01895 if ($iCntr) {
01896 $blMorePic = true;
01897 }
01898 $aArtIcons[$i]= $sIcoVal;
01899 $aArtPics[$i]= $sPicVal;
01900 $iCntr++;
01901 }
01902 if ($iActPicId == $i) {
01903 $sActPic = $sPicVal;
01904 }
01905 }
01906
01907 $blZoomPic = false;
01908 $aZoomPics = array();
01909 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
01910 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
01911 $sVal = $this->getZoomPictureUrl($j);
01912 if ( !$oStr->strstr($sVal, 'nopic.jpg')) {
01913 if ($this->getConfig()->getConfigParam('blFormerTplSupport')) {
01914 $sVal = $this->_sDynImageDir."/".$sVal;
01915 }
01916 $blZoomPic = true;
01917 $aZoomPics[$c]['id'] = $c;
01918 $aZoomPics[$c]['file'] = $sVal;
01919 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01920 if (!$sVal) {
01921 $aZoomPics[$c]['file'] = "nopic.jpg";
01922 }
01923 $c++;
01924 }
01925 }
01926
01927 $aPicGallery = array('ActPicID' => $iActPicId,
01928 'ActPic' => $sActPic,
01929 'MorePics' => $blMorePic,
01930 'Pics' => $aArtPics,
01931 'Icons' => $aArtIcons,
01932 'ZoomPic' => $blZoomPic,
01933 'ZoomPics' => $aZoomPics);
01934
01935 return $aPicGallery;
01936 }
01937
01951 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
01952 {
01953 $myConfig = $this->getConfig();
01954
01955 if (!isset($sOXID)) {
01956 if ( $this->getId()) {
01957 $sOXID = $this->getId();
01958 }
01959 if (!isset ($sOXID)) {
01960 $sOXID = $this->oxarticles__oxid->value;
01961 }
01962 if ($this->oxarticles__oxparentid->value) {
01963 $sParentID = $this->oxarticles__oxparentid->value;
01964 }
01965 }
01966 if (!isset($sOXID)) {
01967 return;
01968 }
01969
01970 //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
01971 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
01972 //if article has variants then updating oxvarstock field
01973 //getting parent id
01974 if (!isset($sParentID)) {
01975 $oDb = oxDb::getDb();
01976 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
01977 $sParentID = $oDb->getOne($sQ);
01978 }
01979 //if we have parent id then update stock
01980 if ($sParentID) {
01981 $this->_onChangeUpdateStock($sParentID);
01982 }
01983 }
01984 //if we have parent id then update count
01985 //update count even if blUseStock is not active
01986 if ($sParentID) {
01987 $this->_onChangeUpdateVarCount($sParentID);
01988 }
01989
01990 $sId = ( $sParentID ) ? $sParentID : $sOXID;
01991 $this->_onChangeUpdateMinVarPrice( $sId );
01992
01993 }
01994
02001 public function getCustomVAT()
02002 {
02003 if ( isset($this->oxarticles__oxvat->value) ) {
02004 return $this->oxarticles__oxvat->value;
02005 }
02006 }
02007
02015 public function checkForStock( $dAmount )
02016 {
02017 $myConfig = $this->getConfig();
02018 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02019 return true;
02020 }
02021
02022 // fetching DB info as its up-to-date
02023 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02024 $rs = oxDb::getDb(true)->Execute( $sQ );
02025
02026 $iOnStock = 0;
02027 $iStockFlag = 0;
02028 if ( $rs !== false && $rs->recordCount() > 0 ) {
02029 $iOnStock = $rs->fields['oxstock'];
02030 $iStockFlag = $rs->fields['oxstockflag'];
02031
02032 // dodger : fremdlager is also always considered as on stock
02033 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02034 return true;
02035 }
02036 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02037 //2007-09-04 MK this if is NEVER true, because upper return in if $iStockFlag == 1 or $iStockFlag == 4
02038 /* if ( $iStockFlag == 1 || $iStockFlag == 4 ) {
02039 $iOnStock = ceil( $iOnStock );
02040 } else {*/
02041 $iOnStock = floor( $iOnStock );
02042 //}
02043 }
02044 }
02045
02046 if ( $iOnStock >= $dAmount ) {
02047 return true;
02048 } else {
02049 if ( $iOnStock > 0 ) {
02050 return $iOnStock;
02051 } else {
02052 $oEx = oxNew( 'oxArticleInputException' );
02053 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02054 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02055 return false;
02056 }
02057 }
02058 }
02059
02060
02068 public function getArticleLongDesc($sOXID = null)
02069 {
02070
02071 if ( !$sOXID ) {
02072 $sOXID = $this->oxarticles__oxid->value;
02073 }
02074
02075 if ($sOXID == $this->oxarticles__oxid->value) {
02076 if (isset($this->oxarticles__oxlongdesc) && ($this->oxarticles__oxlongdesc instanceof oxField) && $this->oxarticles__oxlongdesc->value) {
02077 return $this->oxarticles__oxlongdesc;
02078 }
02079 }
02080
02081 $myConfig = $this->getConfig();
02082
02083 if ( $sOXID ) {
02084 $sLangField = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02085 $oDb = oxDb::getDb();
02086 $this->_setLongDesc($oDb->getOne( "select oxlongdesc{$sLangField} from oxartextends where oxid = ".$oDb->quote($sOXID) ));
02087 } else {
02088 // TODO: check if keeping fldname is needed in non-admin mode
02089 $this->oxarticles__oxlongdesc = new oxField();
02090 $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02091 $this->oxarticles__oxlongdesc->table = 'oxarticles';
02092 $this->oxarticles__oxlongdesc->fldtype = 'text';
02093 }
02094
02095 return $this->oxarticles__oxlongdesc;
02096 }
02097
02105 protected function _setLongDesc($sDbValue)
02106 {
02107 // TODO: eliminate code below
02108 // hack, if editor screws up text, htmledit tends to do so
02109 $sDbValue = str_replace( '&nbsp;', ' ', $sDbValue );
02110 $sDbValue = str_replace( '&', '&', $sDbValue );
02111 $sDbValue = str_replace( '"', '"', $sDbValue );
02112 $sDbValue = str_replace( '&lang=', '&lang=', $sDbValue);
02113 //
02114
02115 $oStr = getStr();
02116 $blHasSmarty = $oStr->strstr( $sDbValue, '[{' );
02117 $blHasPhp = $oStr->strstr( $sDbValue, '<?' );
02118 $myConfig = oxConfig::getInstance();
02119 if ( ( $blHasSmarty || $blHasPhp ) && ($myConfig->getConfigParam( 'blExport' ) || !$this->isAdmin() ) && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
02120 $sDbValue = oxUtilsView::getInstance()->parseThroughSmarty( $sDbValue, $this->getId() );
02121 }
02122 $this->oxarticles__oxlongdesc = new oxField($sDbValue, oxField::T_RAW);
02123 // TODO: check if keeping fldname is needed in non-admin mode
02124 $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02125 $this->oxarticles__oxlongdesc->table = 'oxarticles';
02126 $this->oxarticles__oxlongdesc->fldtype = 'text';
02127 }
02128
02134 public function setArticleLongDesc()
02135 {
02136
02137 if ( $this->_blEmployMultilanguage ) {
02138 // update or insert article long description
02139 if ($this->oxarticles__oxlongdesc instanceof oxField) {
02140 $sLongDesc = $this->oxarticles__oxlongdesc->getRawValue();
02141 } else {
02142 $sLongDesc = $this->oxarticles__oxlongdesc->value;
02143 }
02144 $this->_saveArtLongDesc($this->getLanguage(), $sLongDesc);
02145 } else {
02146 $oArtExt = oxNew('oxi18n');
02147 $oArtExt->init('oxartextends');
02148 $aObjFields = $oArtExt->_getAllFields(true);
02149 foreach ($aObjFields as $sKey => $sValue ) {
02150 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02151 $sField = $this->_getFieldLongName($sKey);
02152 if (isset($this->$sField)) {
02153 $iLang = $oArtExt->_getFieldLang($sKey);
02154 $sLongDesc = null;
02155 if ($this->$sField instanceof oxField) {
02156 $sLongDesc = $this->$sField->getRawValue();
02157 } elseif (is_object($this->$sField)) {
02158 $sLongDesc = $this->$sField->value;
02159 }
02160 if (isset($sLongDesc)) {
02161 $this->_saveArtLongDesc($iLang, $sLongDesc);
02162 }
02163 }
02164 }
02165 }
02166 }
02167 }
02168
02174 public function getAttributes()
02175 {
02176
02177 if ($this->_oAttributeList) {
02178 return $this->_oAttributeList;
02179 }
02180
02181 $oAttributeList = oxNew( 'oxattributelist' );
02182 $oAttributeList->loadAttributes( $this->getId());
02183 //if config option is set then the value for this object is also set
02184 //2007-02-09T
02185 $this->_oAttributeList = $oAttributeList;
02186
02187 return $oAttributeList;
02188 }
02189
02197 public function appendLink( $sAddParams )
02198 {
02199 if ( $this->_sDetailLink === null ) {
02200 $this->_sDetailLink = $this->getLink();
02201 }
02202 $this->_sDetailLink .= (( strpos( $this->_sDetailLink, '?' ) !== false ) ? '&' : '?' ) . $sAddParams;
02203 }
02204
02212 public function getLink($iLang = null)
02213 {
02214 if (isset($iLang)) {
02215 $iLang = (int) $iLang;
02216 if ($iLang == (int) $this->getLanguage()) {
02217 $iLang = null;
02218 }
02219 }
02220 if ( $this->_sDetailLink === null || isset($iLang) ) {
02221
02222 if ( oxUtils::getInstance()->seoIsActive() ) {
02223 $oxdetaillink = oxSeoEncoderArticle::getInstance()->getArticleUrl( $this, $iLang, $this->_iLinkType);
02224 } else {
02225 $oxdetaillink = $this->getStdLink($iLang);
02226 }
02227
02228 if (isset($iLang)) {
02229 return $oxdetaillink;
02230 } else {
02231 $this->_sDetailLink = $oxdetaillink;
02232 }
02233 }
02234
02235 return $this->_sDetailLink;
02236 }
02237
02245 public function setLinkType( $iType )
02246 {
02247 // resetting detaisl link, to force new
02248 $this->_sDetailLink = null;
02249
02250 // setting link type
02251 $this->_iLinkType = (int) $iType;
02252 }
02253
02261 public function getStdLink($iLang = null)
02262 {
02263 //always returns shop url, not admin
02264 $this->_sStdLink = $this->getConfig()->getShopHomeURL( $iLang, false );
02265 $this->_sStdLink .= "cl=details&anid=".$this->getId();
02266
02267 $blSeo = oxUtils::getInstance()->seoIsActive();
02268 if ( !$blSeo || $this->_iLinkType != 0 ) {
02269
02270 if ( !$blSeo ) {
02271 $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
02272 if ( $iPgNr > 0 ) {
02273 $this->_sStdLink .= "&pgNr={$iPgNr}";
02274 }
02275 }
02276
02277 if ( ( $sCat = oxConfig::getParameter( 'cnid' ) ) ) {
02278 $this->_sStdLink .= "&cnid={$sCat}";
02279 }
02280
02281 if ( ( $sCat = oxConfig::getParameter( 'mnid' ) ) ) {
02282 $this->_sStdLink .= "&mnid={$sCat}";
02283 }
02284
02285 $sListType = oxConfig::getParameter( 'listtype' );
02286 if ( !isset( $sListType ) ) {
02287 // view defined list type
02288 $sListType = $this->getConfig()->getGlobalParameter( 'listtype' );
02289 }
02290
02291 // list type
02292 if ( $sListType ) {
02293 $this->_sStdLink .= "&listtype={$sListType}";
02294 }
02295
02296 if (!$blSeo && isset($iLang)) {
02297 $iLang = (int) $iLang;
02298 if ($iLang != (int) $this->getLanguage()) {
02299 $this->_sStdLink .= "&lang={$iLang}";
02300 }
02301 }
02302 }
02303
02304 return $this->_sStdLink = $this->getSession()->processUrl( $this->_sStdLink );
02305 }
02306
02314 public function getStdTagLink( $sTag )
02315 {
02316 $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02317 return $sStdTagLink . "cl=details&anid=".$this->getId()."&listtype=tag&searchtag=".rawurlencode( $sTag );
02318 }
02319
02325 public function getTags()
02326 {
02327 $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02328 $sQ = "select $sTagField from oxartextends where oxid = '".$this->getId()."'";
02329 $sTags = oxDb::getDb(true)->getOne($sQ);
02330 $oTagCloud = oxNew('oxtagcloud');
02331 $sTags = $oTagCloud->trimTags($sTags);
02332 return $sTags;
02333 }
02334
02342 public function saveTags($sTags)
02343 {
02344 $sTags = mysql_real_escape_string($sTags);
02345 $oTagCloud = oxNew('oxtagcloud');
02346 $oTagCloud->resetTagCache();
02347 $sTags = $oTagCloud->prepareTags($sTags);
02348 $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02349 $sQ = "update oxartextends set $sTagField = '$sTags' where oxid = '".$this->getId()."'";
02350 return oxDb::getDb()->execute($sQ);
02351
02352 }
02353
02361 public function addTag($sTag)
02362 {
02363 $sTag = mysql_real_escape_string($sTag);
02364
02365 $oTagCloud = oxNew('oxtagcloud');
02366 $oTagCloud->resetTagCache();
02367 $sTag = $oTagCloud->prepareTags($sTag);
02368
02369 $sField = "oxartextends.OXTAGS".oxLang::getInstance()->getLanguageTag();
02370 $sQ = "insert into oxartextends (oxartextends.OXID, $sField) values ('".$this->getId()."', '{$sTag}')
02371 ON DUPLICATE KEY update $sField = CONCAT(TRIM($sField), ' $sTag') ";
02372
02373 return oxDb::getDb()->Execute($sQ);
02374 }
02375
02381 public function getMediaUrls()
02382 {
02383 if ($this->_aMediaUrls) {
02384 return $this->_aMediaUrls;
02385 }
02386
02387 $this->_aMediaUrls = oxNew("oxlist");
02388 $this->_aMediaUrls->init("oxmediaurl");
02389 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02390
02391 $sQ = "select * from oxmediaurls where oxobjectid = '".$this->getId()."'";
02392 $this->_aMediaUrls->selectString($sQ);
02393
02394 return $this->_aMediaUrls;
02395 }
02396
02402 public function getDynImageDir()
02403 {
02404 return $this->_sDynImageDir;
02405 }
02406
02412 public function getDispSelList()
02413 {
02414 if ($this->_aDispSelList === null) {
02415 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02416 $this->_aDispSelList = $this->getSelectLists();
02417 }
02418 }
02419 return $this->_aDispSelList;
02420 }
02421
02427 public function getMoreDetailLink()
02428 {
02429 if ( $this->_sMoreDetailLink == null ) {
02430
02431 // and assign special article values
02432 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02433
02434 // not always it is okey, as not all the time active category is the same as primary article cat.
02435 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02436 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02437 }
02438 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02439 $this->_sMoreDetailLink = $this->getSession()->processUrl( $this->_sMoreDetailLink );
02440 }
02441
02442 return $this->_sMoreDetailLink;
02443 }
02444
02450 public function getToBasketLink()
02451 {
02452 if ( $this->_sToBasketLink == null ) {
02453 $myConfig = $this->getConfig();
02454
02455 if ( oxUtils::getInstance()->isSearchEngine() ) {
02456 $this->_sToBasketLink = $this->getLink();
02457 } else {
02458 // and assign special article values
02459 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02460
02461 // override some classes as these should never showup
02462 $sActClass = oxConfig::getParameter( 'cl' );
02463 if ( $sActClass == 'thankyou') {
02464 $sActClass = 'basket';
02465 }
02466 $this->_sToBasketLink .= 'cl='.$sActClass;
02467
02468 // this is not very correct
02469 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02470 $this->_sToBasketLink .= '&cnid='.$sActCat;
02471 }
02472
02473 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02474
02475 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02476 $this->_sToBasketLink .= '&tpl='.$sTpl;
02477 }
02478 }
02479
02480 $this->_sToBasketLink = $this->getSession()->processUrl( $this->_sToBasketLink );
02481 }
02482
02483 return $this->_sToBasketLink;
02484 }
02485
02491 public function getStockStatus()
02492 {
02493 return $this->_iStockStatus;
02494 }
02495
02501 public function getDeliveryDate()
02502 {
02503 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02504 return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02505 } else {
02506 return false;
02507 }
02508 }
02509
02515 public function getFTPrice()
02516 {
02517 if ( $oPrice = $this->getTPrice() ) {
02518 if ( $oPrice->getBruttoPrice() ) {
02519 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02520 }
02521 } else {
02522 return null;
02523 }
02524 }
02525
02531 public function getFPrice()
02532 {
02533 if ( $oPrice = $this->getPrice() ) {
02534 return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02535 } else {
02536 return null;
02537 }
02538 }
02539
02545 public function getPricePerUnit()
02546 {
02547 return $this->_fPricePerUnit;
02548 }
02549
02555 public function isParentNotBuyable()
02556 {
02557 return $this->_blNotBuyableParent;
02558 }
02559
02565 public function isNotBuyable()
02566 {
02567 return $this->_blNotBuyable;
02568 }
02569
02577 public function setBuyableState( $blBuyable = false )
02578 {
02579 $this->_blNotBuyable = !$blBuyable;
02580 }
02581
02587 public function getVariantList()
02588 {
02589 return $this->_oVariantList;
02590 }
02591
02599 public function setSelectlist( $aSelList )
02600 {
02601 $this->_aDispSelList = $aSelList;
02602 }
02603
02611 public function getPictureUrl( $iIndex )
02612 {
02613 return $this->getConfig()->getPictureUrl( $this->{"oxarticles__oxpic".$iIndex}->value );
02614 }
02615
02623 public function getIconUrl( $iIndex = '')
02624 {
02625 if (!$iIndex) {
02626 $sFile = $this->oxarticles__oxicon->value;
02627 } else {
02628 $sFile = $this->{'oxarticles__oxpic' . $iIndex . '_ico'}->value;
02629 }
02630
02631 $sFile = str_replace('nopic.jpg', 'nopic_ico.jpg', $sFile);
02632
02633 //$sFile = $this->getConfig()->getPictureUrl( 'icon/' ). basename($sFile);
02634 $sFile = $this->getConfig()->getPictureUrl( $sFile );
02635
02636 return $sFile;
02637 }
02638
02644 public function getThumbnailUrl()
02645 {
02646 //return $this->getConfig()->getPictureUrl( $this->oxarticles__oxthumb->value );
02647 return $this->getConfig()->getPictureUrl( '0/' ) . basename($this->oxarticles__oxthumb->value);
02648 }
02649
02657 public function getZoomPictureUrl($iIndex)
02658 {
02659 return $this->getConfig()->getPictureUrl( $this->{'oxarticles__oxzoom'.$iIndex}->value );
02660 }
02661
02667 public function getFileUrl()
02668 {
02669 return $this->getConfig()->getPictureUrl( '0/' );
02670 }
02671
02677 public function getPriceFromPrefix()
02678 {
02679 $sPricePrefics = '';
02680 if ( $this->_blIsRangePrice) {
02681 $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02682 }
02683
02684 return $sPricePrefics;
02685 }
02686
02695 protected function _saveArtLongDesc($iLang, $sValue)
02696 {
02697 $oDB = oxDb::getDb();
02698 $iLang = (int) $iLang;
02699 $sLangField = ($iLang > '0') ? '_'.$iLang : '';
02700 $sLongDesc = $oDB->quote($sValue);
02701 $sLongDescSQL = "insert into oxartextends (oxartextends.OXID, oxartextends.OXLONGDESC{$sLangField})
02702 VALUES ('".$this->getId()."', {$sLongDesc})
02703 ON DUPLICATE KEY update oxartextends.OXLONGDESC{$sLangField} = {$sLongDesc} ";
02704
02705 $oDB->execute($sLongDescSQL);
02706 }
02707
02714 protected function _skipSaveFields()
02715 {
02716 $myConfig = $this->getConfig();
02717
02718 $this->_aSkipSaveFields = array();
02719
02720 $this->_aSkipSaveFields[] = 'oxtimestamp';
02721 $this->_aSkipSaveFields[] = 'oxlongdesc';
02722 $this->_aSkipSaveFields[] = 'oxinsert';
02723
02724 if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02725 $this->_aSkipSaveFields[] = 'oxparentid';
02726 }
02727
02728 }
02729
02739 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02740 {
02741 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02742 // add prices of the same discounts
02743 if ( array_key_exists ($sKey, $aDiscounts) ) {
02744 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02745 } else {
02746 $aDiscounts[$sKey] = $oDiscount;
02747 }
02748 }
02749 return $aDiscounts;
02750 }
02751
02757 protected function _getGroupPrice()
02758 {
02759 $dPrice = $this->oxarticles__oxprice->value;
02760
02761 $oUser = $this->getArticleUser();
02762 if ( $oUser ) {
02763 if ( $oUser->inGroup( 'oxidpricea' ) ) {
02764 $dPrice = $this->oxarticles__oxpricea->value;
02765 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
02766 $dPrice = $this->oxarticles__oxpriceb->value;
02767 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
02768 $dPrice = $this->oxarticles__oxpricec->value;
02769 }
02770 }
02771
02772 // #1437/1436C - added config option, and check for zero A,B,C price values
02773 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
02774 $dPrice = $this->oxarticles__oxprice->value;
02775 }
02776
02777 return $dPrice;
02778 }
02779
02788 protected function _getAmountPrice($dAmount = 1)
02789 {
02790 $myConfig = $this->getConfig();
02791
02792 startProfile( "_getAmountPrice" );
02793
02794 $dPrice = $this->_getGroupPrice();
02795 $oAmtPrices = $this->_getAmountPriceList();
02796 foreach ($oAmtPrices as $oAmPrice) {
02797 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
02798 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
02799 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
02800 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
02801 }
02802 }
02803
02804 stopProfile( "_getAmountPrice" );
02805 return $dPrice;
02806 }
02807
02816 protected function _modifySelectListPrice( &$dPrice, $aChosenList = null )
02817 {
02818 $myConfig = $this->getConfig();
02819 // #690
02820 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
02821
02822 $aSelLists = $this->getSelectLists();
02823 foreach ( $aSelLists as $key => $aSel) {
02824 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
02825 $oSel = $aSel[$aChosenList[$key]];
02826 if ( $oSel->priceUnit =='abs' ) {
02827 $dPrice += $oSel->price;
02828 } elseif ( $oSel->priceUnit =='%' ) {
02829 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
02830 }
02831 }
02832 }
02833 }
02834 return $dPrice;
02835 }
02836
02837
02845 protected function _fillAmountPriceList($oAmPriceList)
02846 {
02847 $myConfig = $this->getConfig();
02848 $myUtils = oxUtils::getInstance();
02849
02850 //modifying price
02851 $oCur = $myConfig->getActShopCurrencyObject();
02852
02853 $oUser = $this->getArticleUser();
02854
02855 $oDiscountList = oxDiscountList::getInstance();
02856 $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
02857
02858 $oLowestPrice = null;
02859
02860 $dBasePrice = $this->_getGroupPrice();
02861 $oLang = oxLang::getInstance();
02862
02863 $dArticleVat = null;
02864 if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
02865 $dArticleVat = $this->getArticleVat();
02866 }
02867
02868 // trying to find lowest price value
02869 foreach ($oAmPriceList as $sId => $oItem) {
02870 $oItemPrice = oxNew( 'oxprice' );
02871 if ( $oItem->oxprice2article__oxaddabs->value) {
02872 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
02873 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
02874 $this->_applyCurrency( $oItemPrice, $oCur );
02875 } else {
02876 $oItemPrice->setPrice( $dBasePrice );
02877 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
02878 }
02879
02880 if (isset($dArticleVat)) {
02881 $this->_applyVAT($oItemPrice, $dArticleVat);
02882 }
02883
02884 if (!$oLowestPrice) {
02885 $oLowestPrice = $oItemPrice;
02886 } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
02887 $oLowestPrice = $oItemPrice;
02888 }
02889
02890 $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
02891 $oAmPriceList[$sId]->fnetprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
02892 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
02893 }
02894
02895 $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
02896 return $oAmPriceList;
02897 }
02898
02904 protected function _getVariantsIds()
02905 {
02906 $aSelect = array();
02907 $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->getId()."' " );
02908 if ( $oRs != false && $oRs->recordCount() > 0 ) {
02909 while (!$oRs->EOF) {
02910 $aSelect[] = $oRs->fields['oxid'];
02911 $oRs->moveNext();
02912 }
02913 }
02914 return $aSelect;
02915 }
02916
02922 public function getArticleVat()
02923 {
02924 if (!isset($this->_dArticleVat)) {
02925 $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
02926 }
02927 return $this->_dArticleVat;
02928 }
02929
02938 protected function _applyVAT( oxPrice $oPrice, $dVat )
02939 {
02940 startProfile(__FUNCTION__);
02941 $oPrice->setVAT( $dVat );
02942 if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
02943 $oPrice->setUserVat( $dVat );
02944 }
02945 stopProfile(__FUNCTION__);
02946 }
02947
02955 public function applyVats( oxPrice $oPrice )
02956 {
02957 $this->_applyVAT($oPrice,
02958 $this->getArticleVat()
02959 );
02960 }
02961
02972 protected function _applyDiscounts( $oPrice, $aDiscounts )
02973 {
02974 $oDiscountList = oxDiscountList::getInstance();
02975 $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
02976 }
02977
02985 public function applyDiscountsForVariant( $oPrice )
02986 {
02987 // apply discounts
02988 if ( !$this->skipDiscounts() ) {
02989 $oDiscountList = oxDiscountList::getInstance();
02990 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
02991 }
02992 }
02993
03002 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03003 {
03004 if ( !$oCur ) {
03005 $oCur = $this->getConfig()->getActShopCurrencyObject();
03006 }
03007
03008 $oPrice->multiply($oCur->rate);
03009 }
03010
03019 protected function _getIcon()
03020 {
03021 // #1479/1179M - Article icon automatic generation
03022 //if set to do not generate.
03023 $myConfig = $this->getConfig();
03024
03025 if (!$myConfig->getConfigParam( 'blAutoIcons' ) ) {
03026 if ($this->oxarticles__oxicon->value) {
03027 return basename($this->oxarticles__oxicon->value);
03028 } else {
03029 $sQ = "UPDATE oxarticles SET oxicon = 'nopic_ico.jpg' WHERE oxid = '".$this->getId()."'";
03030 oxDb::getDb()->execute($sQ);
03031 return 'nopic_ico.jpg';
03032 }
03033 }
03034
03035 // if set to generate and icon already exist
03036 if ( $this->oxarticles__oxicon->value && strpos( $this->oxarticles__oxicon->value, 'nopic_ico.jpg') === false ) {
03037 return basename($this->oxarticles__oxicon->value);
03038 }
03039
03040 //we don't have an icon yet so lets make one
03041 if ($this->oxarticles__oxthumb->value && strpos( $this->oxarticles__oxthumb->value, 'nopic.jpg') === false && function_exists('gd_info')) {
03042
03043 $sSourceFile = $this->oxarticles__oxthumb->value;
03044 $sTargetFile = str_replace('_th', '_ico', $sSourceFile);
03045
03046 if ($sSourceFile == $sTargetFile) {
03047 $sPattern = '/(\.[a-z0-9]*$)/i';
03048 $sTargetFile = preg_replace($sPattern, '_ico\\1', $sTargetFile);
03049 }
03050
03051 $sTarget = $myConfig->getAbsDynImageDir().'/icon/'. basename($sTargetFile);
03052 $sSource = $myConfig->getAbsDynImageDir().'/0/'. basename($sSourceFile);
03053
03054 if (!$myConfig->getConfigParam( 'sIconsize' ) ) {
03055 $myConfig->setConfigParam( 'sIconsize', '56*42' );
03056 }
03057
03058 $aSize = explode('*', $myConfig->getConfigParam( 'sIconsize' ) );
03059 $iX = $aSize[0];
03060 $iY = $aSize[1];
03061
03062 oxUtilspic::getInstance()->resizeImage( $sSource, $sTarget, $iX, $iY );
03063
03064 $sResult = $sTargetFile;
03065 } else {
03066 $sResult = 'nopic_ico.jpg';
03067 }
03068
03069
03070 $sIconFile = basename($sResult);
03071
03072 $oDb = oxDb::getDb();
03073
03074 $sQ = "UPDATE oxarticles SET oxicon = ".$oDb->quote($sIconFile)." WHERE oxid = '".$this->getId()."'";
03075 $oDb->execute($sQ);
03076
03077 return $sIconFile;
03078 }
03079
03080
03089 protected function _getAttribsString(&$sAttribs, &$iCnt)
03090 {
03091
03092 $oDB = oxDb::getDb(true);
03093 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03094 $sAttribs = '';
03095 $blSep = false;
03096 $rs = $oDB->execute( $sSelect);
03097 $iCnt = 0;
03098 if ($rs != false && $rs->recordCount() > 0) {
03099 while (!$rs->EOF) {
03100 if ( $blSep) {
03101 $sAttribs .= ' or ';
03102 }
03103 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03104 $blSep = true;
03105 $iCnt++;
03106 $rs->moveNext();
03107 }
03108 }
03109 }
03110
03119 protected function _getSimList($sAttribs, $iCnt)
03120 {
03121 $myConfig = $this->getConfig();
03122 $oDB = oxDb::getDb(true);
03123
03124
03125 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03126
03127 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03128 $iAttrPercent = 0.70;
03129 }
03130
03131 $iHitMin = ceil( $iCnt * $iAttrPercent );
03132
03133
03134 $aList= array();
03135 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03136 ( $sAttribs )
03137 and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03138 group by t1.oxobjectid having count(*) >= $iHitMin ";
03139
03140 $rs = $oDB->selectLimit( $sSelect, 20, 0);
03141 if ($rs != false && $rs->recordCount() > 0) {
03142 while (!$rs->EOF) {
03143 $oTemp = new stdClass();
03144 $oTemp->cnt = $rs->fields['cnt'];
03145 $oTemp->id = $rs->fields['oxobjectid'];
03146 $aList[] = $oTemp;
03147 $rs->moveNext();
03148 }
03149 }
03150 return $aList;
03151 }
03152
03161 protected function _generateSimListSearchStr($sArticleTable, $aList)
03162 {
03163 $myConfig = $this->getConfig();
03164 $sFieldList = $this->getSelectFields();
03165 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03166 $blSep = false;
03167 $iCnt = 0;
03168 $oDb = oxDb::getDb();
03169 foreach ( $aList as $oTemp) {
03170 if ( $blSep) {
03171 $sSearch .= ',';
03172 }
03173 $sSearch .= $oDb->quote($oTemp->id);
03174 $blSep = true;
03175 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03176 break;
03177 }
03178 $iCnt++;
03179 }
03180
03181
03182
03183 $sSearch .= ') ';
03184
03185
03186 $sSearch .= ' order by rand() ';
03187
03188 return $sSearch;
03189 }
03190
03199 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03200 {
03201 $sCatView = getViewName( 'oxcategories' );
03202 $sO2CView = getViewName( 'oxobject2category' );
03203
03204
03205 if ( !$blSearchPriceCat ) {
03206 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03207 {$sCatView}.oxid = oxobject2category.oxcatnid
03208 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03209 } else {
03210 $sSelect = "select {$sCatView}.* from {$sCatView} where
03211 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03212 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03213 }
03214 return $sSelect;
03215 }
03216
03222 protected function _generateSearchStrForCustomerBought()
03223 {
03224 $sArtTable = $this->_getObjectViewName( 'oxarticles' );
03225 $sOrderArtTable = getViewName( 'oxorderarticles' );
03226
03227
03228 $sIn = " '{$this->oxarticles__oxid->value}' ";
03229 if ( $this->oxarticles__oxparentid->value ) {
03230
03231
03232 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03233 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03234
03235 } else {
03236 $sParentIdForVariants = $this->getId();
03237 }
03238
03239
03240 $oDb = oxDb::getDb(true);
03241 $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03242 if ( $oRs != false && $oRs->recordCount() > 0) {
03243 while ( !$oRs->EOF ) {
03244 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03245 $oRs->moveNext();
03246 }
03247 }
03248
03249 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03250 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03251
03252
03253 $sQ = "select distinct {$sArtTable}.* from (
03254 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03255 ) as suborder
03256 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03257 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03258 where {$sArtTable}.oxid not in ( {$sIn} )
03259 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03260
03261
03262
03263
03264
03265
03266
03267
03268
03269
03270 return $sQ;
03271 }
03272
03282 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03283 {
03284 $sCategoryView = getViewName('oxcategories');
03285 $sO2CView = getViewName('oxobject2category');
03286 $sLangPrefix = (($this->getLanguage())?'_'.$this->getLanguage():'');
03287
03288 $oDb = oxDb::getDb();
03289 $sOXID = $oDb->quote($sOXID);
03290 $sCatId = $oDb->quote($sCatId);
03291
03292 if (!$dPriceFromTo) {
03293 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03294 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03295 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03296 $sSelect .= "and oxcategories.oxactive$sLangPrefix = 1 order by oxobject2category.oxtime ";
03297 } else {
03298 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03299 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03300 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03301 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03302 }
03303 return $sSelect;
03304 }
03305
03311 protected function _getAmountPriceList()
03312 {
03313 if ($this->_oAmountPriceList) {
03314 return $this->_oAmountPriceList;
03315 }
03316
03317 $myConfig = $this->getConfig();
03318
03319 $sArtID = $this->getId();
03320
03321
03322 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03323 $sArtID = $this->oxarticles__oxparentid->value;
03324 }
03325
03326
03327 $sArtID = mysql_real_escape_string($sArtID);
03328
03329
03330 $oAmPriceList = oxNew( 'oxlist');
03331 $oAmPriceList->init('oxbase', 'oxprice2article');
03332
03333 $sShopID = $myConfig->getShopID();
03334 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03335 $sShopSelect = '1';
03336 } else {
03337 $sShopSelect = " oxshopid = '$sShopID' ";
03338 }
03339
03340 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03341
03342
03343 $oBasePrice = $this->_getGroupPrice();
03344 foreach ($oAmPriceList as $oAmPrice) {
03345 if ($oAmPrice->oxprice2article__oxaddperc->value) {
03346 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03347 }
03348 }
03349
03350 $this->_oAmountPriceList = $oAmPriceList;
03351 return $oAmPriceList;
03352 }
03353
03361 protected function _isFieldEmpty($sFieldName)
03362 {
03363 $mValue = $this->$sFieldName->value;
03364
03365 if (is_null($mValue)) {
03366 return true;
03367 }
03368
03369 if ($mValue === '') {
03370 return true;
03371 }
03372
03373 $aDoubleCopyFields = array('oxarticles__oxprice',
03374 'oxarticles__oxvat');
03375
03376 if (!$mValue && in_array($sFieldName, $aDoubleCopyFields)) {
03377 return true;
03378 }
03379
03380
03381 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03382 return true;
03383 }
03384
03385 $sFieldName = strtolower($sFieldName);
03386
03387 if ($mValue == "nopic_ico.jpg" && $sFieldName == 'oxarticles__oxicon') {
03388 return true;
03389 }
03390
03391 if ($mValue == "nopic.jpg" && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom')) {
03392 return true;
03393 }
03394
03395 return false;
03396 }
03397
03405 protected function _assignParentFieldValue($sFieldName)
03406 {
03407 if (!($oParentArticle = $this->_getParentAricle())) {
03408 return;
03409 }
03410
03411 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03412
03413
03414 if ( $oParentArticle->$sCopyFieldName != null ) {
03415
03416
03417 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03418 continue;
03419 }
03420
03421
03422 $aNonCopyFields = array('oxarticles__oxinsert',
03423 'oxarticles__oxtimestamp',
03424 'oxarticles__oxnid',
03425 'oxarticles__oxid',
03426 'oxarticles__oxparentid');
03427
03428 $aCopyParentField = array('oxarticles__oxnonmaterial',
03429 'oxarticles__oxfreeshipping',
03430 'oxarticles__oxremindactive');
03431
03432 if (in_array($sCopyFieldName, $aNonCopyFields)) {
03433 return;
03434 }
03435
03436
03437
03438
03439 if ($sFieldName == "oxicon" && !$this->_isFieldEmpty("oxarticles__oxthumb") && $this->oxarticles__oxthumb->value != $oParentArticle->oxarticles__oxthumb->value && $this->getConfig()->getConfigParam( 'blAutoIcons' ) ) {
03440 return ;
03441 }
03442
03443
03444
03445
03446 if ($this->_isFieldEmpty($sCopyFieldName) || in_array($sCopyFieldName, $aCopyParentField)) {
03447 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03448 }
03449
03450
03451
03452
03453
03454
03455
03456
03457
03458
03459
03460
03461
03462
03463
03464
03465
03466
03467
03468
03469
03470
03471
03472
03473
03474
03475
03476 }
03477 }
03478
03484 protected function _getParentAricle()
03485 {
03486 $sParentId = $this->oxarticles__oxparentid->value;
03487 if (!$sParentId) {
03488 return null;
03489 }
03490 if (isset(self::$_aLoadedParents[$sParentId])) {
03491 return self::$_aLoadedParents[$sParentId];
03492 } else {
03493 $oParentArticle = oxNew( 'oxarticle' );
03494 $oParentArticle->_blSkipAbPrice = true;
03495 $oParentArticle->_blLoadPrice = false;
03496 $oParentArticle->_blLoadVariants = false;
03497 $oParentArticle->load( $sParentId);
03498 self::$_aLoadedParents[$sParentId] = $oParentArticle;
03499 return $oParentArticle;
03500 }
03501 }
03502
03508 protected function _assignParentFieldValues()
03509 { startProfile('articleAssignParentInternal');
03510 if ( $this->oxarticles__oxparentid->value) {
03511
03512 if ( !$this->isAdmin() || ($this->_blLoadParentData && $this->isAdmin() ) ) {
03513 foreach ($this->_aFieldNames as $sFieldName => $sVal) {
03514 $this->_assignParentFieldValue($sFieldName);
03515 }
03516
03517
03518 $oParentArticle = $this->_getParentAricle();
03519 if ( !$this->oxarticles__oxlongdesc->value ) {
03520 $this->oxarticles__oxlongdesc = $oParentArticle->oxarticles__oxlongdesc;
03521 }
03522
03523 }
03524 } elseif ( $this->oxarticles__oxid->value ) {
03525
03526
03527 startProfile("loadVariants");
03528 $this->_oVariantList = $this->getVariants();
03529 stopProfile("loadVariants");
03530
03531
03532
03533
03534
03535
03536 }
03537 stopProfile('articleAssignParentInternal');
03538
03539 }
03540
03546 protected function _assignNotBuyableParent()
03547 {
03548 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03549 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03550 $this->_blNotBuyableParent = true;
03551
03552 }
03553 }
03554
03560 protected function _assignPictureValues()
03561 {
03562 $myConfig = $this->getConfig();
03563 $this->oxarticles__oxicon = new oxField($this->_getIcon());
03564
03565
03566 $sNoPic = 'nopic.jpg';
03567 $sNoPicIcon = 'nopic_ico.jpg';
03568
03569 if ( isset($this->_aFieldNames["oxthumb"]) && !$this->oxarticles__oxthumb->value) {
03570 $this->oxarticles__oxthumb = new oxField($sNoPic);
03571 }
03572
03573
03574
03575
03576
03577 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03578 for ( $i=1; $i<= $iPicCount; $i++ ) {
03579 if ( isset($this->_aFieldNames["oxpic".$i]) && !$this->{'oxarticles__oxpic'.$i}->value ) {
03580 $this->{'oxarticles__oxpic'.$i} = new oxField($sNoPic);
03581 }
03582 }
03583
03584 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
03585 for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03586 if ( isset($this->_aFieldNames["oxzoom".$i]) && !$this->{'oxarticles__oxzoom'.$i}->value) {
03587 $this->{'oxarticles__oxzoom'.$i} = new oxField($sNoPic);
03588 }
03589 }
03590
03591 if ( !$this->isAdmin() ) {
03592
03593 if ( isset($this->_aFieldNames["oxthumb"])) {
03594 $this->oxarticles__oxthumb->setValue('0/'.basename($this->oxarticles__oxthumb->value));
03595 }
03596 if ( isset($this->_aFieldNames["oxicon"])) {
03597 $this->oxarticles__oxicon = new oxField('icon/'.basename($this->oxarticles__oxicon->value));
03598 }
03599
03600 $myUtilsPic = oxUtilsPic::getInstance();
03601 for ( $i=1; $i<= $iPicCount; $i++ ) {
03602 $sFieldName = 'oxarticles__oxpic'.$i;
03603 if ( isset($this->_aFieldNames["oxpic".$i])) {
03604 $sIconFieldName = 'oxarticles__oxpic'.$i.'_ico';
03605 $this->$sIconFieldName = new oxField($i.'/'.basename($myUtilsPic->iconName($this->$sFieldName->value)));
03606 $this->$sFieldName = new oxField($i.'/'.basename($this->$sFieldName->value));
03607 }
03608 }
03609 for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03610 if ( isset($this->_aFieldNames["oxzoom".$i])) {
03611 $this->{'oxarticles__oxzoom'.$i} = new oxField('z'.$i.'/'.basename($this->{'oxarticles__oxzoom'.$i}->value));
03612 }
03613 }
03614 }
03615
03616 }
03617
03623 protected function _assignStock()
03624 {
03625 $myConfig = $this->getConfig();
03626
03627
03628
03629
03630
03631 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03632 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03633 }
03634
03635 $this->_iStockStatus = 0;
03636
03637
03638 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03639
03640 $iStock = $this->oxarticles__oxstock->value;
03641
03642 if ($this->_blNotBuyableParent) {
03643 $iStock = $this->oxarticles__oxvarstock->value;
03644 }
03645
03646
03647 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03648 $this->_iStockStatus = 1;
03649 }
03650
03651
03652 if ($iStock <= 0) {
03653 $this->_iStockStatus = -1;
03654 }
03655 }
03656
03657
03658
03659 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstock->value <= 0 && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03660 $this->_blNotBuyable = true;
03661 }
03662
03663
03664 if ($this->_blNotBuyable && $this->_iVarStock) {
03665 $this->_blNotBuyable = false;
03666
03667 $this->_blNotBuyableParent = true;
03668 }
03669
03670
03671
03672
03673 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03674 $this->_blNotBuyable = true;
03675 }
03676
03677
03678 if ($this->_blNotBuyableParent && count($this->_oVariantList) == 0) {
03679 $this->_blNotBuyable = true;
03680 }
03681 }
03682
03688 protected function _assignPrices()
03689 {
03690 $myConfig = $this->getConfig();
03691
03692
03693 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03694 return;
03695 }
03696
03697
03698 $dPrice = $this->getPrice()->getBruttoPrice();
03699
03700 $oCur = $myConfig->getActShopCurrencyObject();
03701
03702 if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03703 $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03704 }
03705
03706
03707
03708 $this->_applyRangePrice();
03709 }
03710
03716 protected function _assignPersistentParam()
03717 {
03718
03719 $aPersParam = oxSession::getVar( 'persparam');
03720 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03721 $this->_aPersistParam = $aPersParam[$this->getId()];
03722 }
03723 }
03724
03730 protected function _assignDynImageDir()
03731 {
03732 $myConfig = $this->getConfig();
03733
03734 $sThisShop = $this->oxarticles__oxshopid->value;
03735
03736 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03737 $this->dabsimagedir = $myConfig->getPictureDir( false );
03738 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03739 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03740 }
03741
03747 protected function _assignComparisonListFlag()
03748 {
03749
03750
03751 $aItems = oxConfig::getParameter('aFiltcompproducts');
03752 if ( isset( $aItems[$this->getId()])) {
03753 $this->_blIsOnComparisonList = true;
03754 }
03755 }
03756
03762 protected function _assignAttributes()
03763 {
03764
03765
03766 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03767 $this->getAttributes();
03768 }
03769 }
03770
03771
03779 protected function _insert()
03780 {
03781
03782 $iInsertTime = time();
03783 $now = date('Y-m-d H:i:s', $iInsertTime);
03784 $this->oxarticles__oxinsert = new oxField( $now );
03785 $this->oxarticles__oxtimestamp = new oxField( $now );
03786 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03787 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03788 }
03789
03790 return parent::_insert();
03791 }
03792
03798 protected function _update()
03799 {
03800
03801 $this->_skipSaveFields();
03802
03803 $myConfig = $this->getConfig();
03804
03805
03806 return parent::_update();
03807 }
03808
03816 protected function _deleteRecords($sOXID)
03817 {
03818 $oDB = oxDb::getDb();
03819
03820 $sOXID = $oDB->quote($sOXID);
03821
03822
03823 $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
03824 $oDB->execute( $sDelete);
03825
03826
03827 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03828 $oDB->execute( $sDelete);
03829
03830 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03831 $oDB->execute( $sDelete);
03832
03833 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03834 $oDB->execute( $sDelete);
03835
03836 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03837 $oDB->execute( $sDelete);
03838
03839 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03840 $oDB->execute( $sDelete);
03841
03842 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03843 $oDB->execute( $sDelete);
03844
03845 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03846 $oDB->execute( $sDelete);
03847
03848
03849 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03850 $oDB->execute( $sDelete);
03851
03852 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03853 $oDB->execute( $sDelete);
03854
03855 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03856 $rs = $oDB->execute( $sDelete );
03857
03858 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03859 $rs = $oDB->execute( $sDelete );
03860
03861
03862 return $rs;
03863 }
03864
03872 protected function _deleteVariantRecords($sOXID)
03873 {
03874 $oDB = oxDb::getDb();
03875
03876 $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDB->quote($sOXID);
03877 $rs = $oDB->execute( $sVariants);
03878 if ($rs != false && $rs->recordCount() > 0) {
03879 while (!$rs->EOF) {
03880 $this->delete( $rs->fields[0]);
03881 $rs->moveNext();
03882 }
03883 }
03884 }
03885
03895 protected function _resetCacheAndArticleCount( $sOxid )
03896 {
03897 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03898 }
03899
03905 protected function _deletePics()
03906 {
03907 $myUtilsPic = oxUtilsPic::getInstance();
03908 $myConfig = $this->getConfig();
03909
03910
03911 $blThumbDeleted = $myUtilsPic->safePictureDelete( $this->oxarticles__oxthumb->value, $myConfig->getAbsDynImageDir().'/0', 'oxarticles', 'oxthumb' );
03912
03913 if ( $blThumbDeleted ) {
03914 $myUtilsPic->safePictureDelete('icon/'.$this->oxarticles__oxicon->value, $myConfig->getAbsDynImageDir(), 'oxarticles', 'oxicon' );
03915 }
03916
03917
03918
03919
03920
03921
03922 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03923 $sAbsDynImageDir = $myConfig->getAbsDynImageDir();
03924 for ( $i = 1; $i <= $iPicCount; $i++ ) {
03925
03926 $sPicFName = $this->{'oxarticles__oxpic'.$i}->value;
03927 $myUtilsPic->safePictureDelete($sPicFName, $sAbsDynImageDir.'/'.$i, 'oxarticles', 'oxpic'.$i );
03928 }
03929
03930 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
03931 for ( $i = 1; $i <= $iZoomPicCount; $i++ ) {
03932 if ( isset($this->{'oxarticles__oxzoom'.$i}) ) {
03933 $myUtilsPic->safePictureDelete($this->{'oxarticles__oxzoom'.$i}->value, $sAbsDynImageDir.'/z'.$i, 'oxarticles', 'oxzoom'.$i );
03934 }
03935 }
03936
03937 }
03938
03948 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
03949 {
03950
03951 $myUtilsCount = oxUtilsCount::getInstance();
03952
03953 if ( $sVendorId ) {
03954 $myUtilsCount->resetVendorArticleCount( $sVendorId );
03955 }
03956
03957 if ( $sManufacturerId ) {
03958 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
03959 }
03960
03961
03962 $oDb = oxDb::getDb();
03963 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
03964 $oRs = $oDb->execute( $sQ );
03965 if ( $oRs !== false && $oRs->recordCount() > 0) {
03966 while ( !$oRs->EOF ) {
03967 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
03968 $oRs->moveNext();
03969 }
03970 }
03971 }
03972
03980 protected function _onChangeUpdateStock( $sParentID )
03981 {
03982 $oDb = oxDb::getDb();
03983 $sParentIdQuoted = $oDb->quote($sParentID);
03984 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
03985 $rs = $oDb->execute($sQ);
03986 $iOldStock = $rs->fields[0];
03987 $iVendorID = $rs->fields[1];
03988 $iManufacturerID = $rs->fields[2];
03989
03990 $sQ = 'select sum(oxstock) from oxarticles where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
03991 $iStock = (float) $oDb->getOne( $sQ );
03992
03993 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
03994 $oDb->execute( $sQ );
03995
03996
03997
03998 if ( $iStock < 0 ) {
03999 $iStock = 0;
04000 }
04001 if ( $iOldStock < 0 ) {
04002 $iOldStock = 0;
04003 }
04004 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04005
04006
04007 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04008 }
04009 }
04010
04018 protected function _onChangeUpdateVarCount( $sParentID )
04019 {
04020 $oDb = oxDb::getDb();
04021 $sParentIdQuoted = $oDb->quote($sParentID);
04022 $sQ = 'select count(*) as varcount from oxarticles where oxparentid = '.$sParentIdQuoted;
04023 $iVarCount = (int) $oDb->getOne($sQ);
04024
04025 $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = '.$sParentIdQuoted;
04026 $oDb->execute($sQ);
04027 }
04028
04036 protected function _onChangeUpdateMinVarPrice( $sParentID )
04037 {
04038 $oDb = oxDb::getDb();
04039 $sParentIdQuoted = $oDb->quote($sParentID);
04040
04041 $sQ = 'select min(oxprice) as varminprice from oxarticles where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted;
04042
04043 if ( $this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) ) {
04044 $sQ .= ' or oxid = '.$sParentIdQuoted;
04045 } else {
04046 $sQ .= ' or (oxid = '.$sParentIdQuoted.' and oxvarcount=0)';
04047 }
04048 $sQ .= ')';
04049 $dVarMinPrice = $oDb->getOne($sQ);
04050 if ( $dVarMinPrice ) {
04051 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04052 $oDb->execute($sQ);
04053 }
04054 }
04055
04056
04062 protected function _applyRangePrice()
04063 {
04064
04065 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04066 return;
04067 }
04068
04069 $this->_blIsRangePrice = false;
04070
04071
04072 if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04073 return;
04074 }
04075
04076 $aPrices = array();
04077
04078 if (!$this->_blNotBuyableParent) {
04079 $aPrices[] = $this->getPrice()->getBruttoPrice();
04080 }
04081
04082 if (count($this->_oVariantList)) {
04083 foreach ($this->_oVariantList as $sKey => $oVariant) {
04084 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04085 }
04086 }
04087
04088
04089
04090
04091
04092
04093 if (count($aPrices)) {
04094 $dMinPrice = $aPrices[0];
04095 $dMaxPrice = $aPrices[0];
04096 foreach ($aPrices as $dPrice) {
04097 if ($dMinPrice > $dPrice) {
04098 $dMinPrice = $dPrice;
04099 }
04100
04101 if ($dMaxPrice < $dPrice) {
04102 $dMaxPrice = $dPrice;
04103 }
04104 }
04105 }
04106
04107 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04108 $this->getPrice()->setBruttoPriceMode();
04109 $this->getPrice()->setPrice($dMinPrice);
04110 }
04111
04112 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04113 $this->getPrice()->setBruttoPriceMode();
04114 $this->getPrice()->setPrice($dMinPrice);
04115 $this->_blIsRangePrice = true;
04116 }
04117
04118 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04119 $this->getPrice()->setBruttoPriceMode();
04120 $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04121 $this->_blIsRangePrice = true;
04122 $this->_calculatePrice( $this->getPrice() );
04123 }
04124 }
04125
04132 public function getProductId()
04133 {
04134 return $this->getId();
04135 }
04136
04142 public function getProductParentId()
04143 {
04144 return $this->oxarticles__oxparentid->value;
04145 }
04146
04152 public function isOrderArticle()
04153 {
04154 return false;
04155 }
04156
04162 public function isVariant()
04163 {
04164 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04165 }
04166 }