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, oxIUrl
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 $_blHasMdVariants = false;
00122
00126 protected $_iVarStock = 0;
00127
00132 protected $_oVariantList = array();
00133
00138 protected $_blIsOnComparisonList = false;
00139
00144 protected $_oUser = null;
00145
00151 protected $_blLoadPrice = true;
00152
00156 protected $_blSkipAbPrice = false;
00157
00164 protected $_fPricePerUnit = null;
00165
00169 protected $_blLoadParentData = false;
00170
00174 protected $_blSkipAssign = false;
00175
00181 protected $_blSkipDiscounts = null;
00182
00187 protected $_oAttributeList = null;
00188
00189
00195 protected $_blIsRangePrice = false;
00196
00202 protected $_aMediaUrls = null;
00203
00209 static protected $_aLoadedParents;
00210
00216 static protected $_aSelList;
00217
00223 protected $_aDispSelList;
00224
00230 protected $_blIsSeoObject = true;
00231
00237 protected $_oAmountPriceList = null;
00238
00247 protected $_iLinkType = 0;
00248
00254 protected $_sStdLink = null;
00255
00261 protected $_sDynImageDir = null;
00262
00268 protected $_sMoreDetailLink = null;
00269
00275 protected $_sToBasketLink = null;
00276
00282 protected $_iStockStatus = null;
00283
00289 protected $_oTPrice = null;
00290
00296 protected $_oAmountPriceInfo = null;
00297
00303 protected $_dAmountPrice = null;
00304
00310 protected $_sDetailLink = null;
00311
00317 protected static $_aArticleManufacturers = array();
00318
00324 protected static $_aArticleVendors = array();
00325
00331 protected static $_aArticleCats = array();
00332
00338 protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00339 'oxarticles__oxtimestamp',
00340 'oxarticles__oxnid',
00341 'oxarticles__oxid',
00342 'oxarticles__oxparentid');
00343
00349 protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00350 'oxarticles__oxfreeshipping',
00351 'oxarticles__oxremindactive');
00352
00358 protected $_oMdVariants = null;
00359
00368 public function __construct($aParams = null)
00369 {
00370 if ( $aParams && is_array($aParams)) {
00371 foreach ( $aParams as $sParam => $mValue) {
00372 $this->$sParam = $mValue;
00373 }
00374 }
00375 parent::__construct();
00376 $this->init( 'oxarticles' );
00377
00378 $this->_blIsRangePrice = false;
00379 }
00380
00388 public function __isset( $sName )
00389 {
00390 if ( $sName == 'oxarticles__oxlongdesc' ) {
00391
00392 $this->getArticleLongDesc();
00393 return true;
00394 }
00395 return isset( $this->$sName );
00396 }
00397
00406 public function __get($sName)
00407 {
00408 $myUtils = oxUtils::getInstance();
00409 switch ($sName) {
00410
00411
00412
00413
00414 case 'netprice':
00415 case 'netPrice':
00416 $mVal = $myUtils->fRound($this->getPrice()->getNettoPrice());
00417 break;
00418 case 'brutPrice':
00419 return $myUtils->fRound($this->getPrice()->getBruttoPrice());
00420 break;
00421 case 'vatPercent':
00422 return $this->getPrice()->getVAT();
00423 break;
00424 case 'vat':
00425 return $this->getPrice()->getVATValue();
00426 break;
00427 case 'fnetprice':
00428 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($this->getPrice()->getNettoPrice()));
00429 break;
00430 case 'fprice':
00431 return $this->getFPrice();
00432 break;
00433
00434
00435 case 'dtprice':
00436 if ( $oPrice = $this->getTPrice() ) {
00437 return $myUtils->fRound($oPrice->getBruttoPrice());
00438 break;
00439 } else {
00440 return null;
00441 break;
00442 }
00443 case 'tvat':
00444 if ( $oPrice = $this->getTPrice() ) {
00445 return $oPrice->getVATValue();
00446 break;
00447 } else {
00448 return null;
00449 break;
00450 }
00451 case 'ftprice':
00452 if ( $oPrice = $this->getTPrice() ) {
00453 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($oPrice->getBruttoPrice()) );
00454 break;
00455 } else {
00456 return null;
00457 break;
00458 }
00459 case 'oxarticles__oxlongdesc':
00460 return $this->getArticleLongDesc($this->getId());
00461 break;
00462 case 'foxdelivery':
00463 return $this->getDeliveryDate();
00464 break;
00465 case 'sItemKey':
00466 return $this->getItemKey();
00467 break;
00468 case 'selectlist':
00469 return $this->_aDispSelList = $this->getDispSelList();
00470 break;
00471 case 'blNotBuyable':
00472 return $this->isNotBuyable();
00473 break;
00474 case 'blNotBuyableParent':
00475 return $this->isParentNotBuyable();
00476 break;
00477 case 'blIsOnComparisonList':
00478 return $this->isOnComparisonList();
00479 break;
00480 case 'oVariantlist' :
00481 return $this->_oVariantList;
00482 break;
00483 case 'fPricePerUnit' :
00484 return $this->getPricePerUnit();
00485 break;
00486 case 'dimagedir' :
00487 return $this->_sDynImageDir = $this->getDynImageDir();
00488 break;
00489 case 'oxmoredetaillink' :
00490 return $this->_sMoreDetailLink = $this->getMoreDetailLink();
00491 break;
00492 case 'amountpricelist' :
00493 return $this->loadAmountPriceInfo();
00494 break;
00495 case 'stockstatus' :
00496 return $this->getStockStatus();
00497 break;
00498 case 'tobasketlink' :
00499 return $this->getToBasketLink();
00500 break;
00501 case 'oxdetaillink' :
00502 return $this->getLink();
00503 break;
00504 case 'aSelectlist' :
00505 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00506 return $this->aSelectlist = $this->getSelectLists();
00507 }
00508 return;
00509 break;
00510
00511
00512 }
00513
00514 $this->$sName = parent::__get($sName);
00515 if ( $this->$sName ) {
00516 $this->_assignParentFieldValue($sName);
00517 }
00518
00519 if ($sName == "oxarticles__oxthumb" || $sName == "oxarticles__oxicon" || strpos($sName, "oxarticles__oxpic") === 0 || strpos($sName, "oxarticles__oxzoom") === 0) {
00520 $this->_assignPictureValues();
00521 return $this->$sName;
00522 }
00523
00524 return $this->$sName;
00525 }
00526
00534 public function setId( $sId = null )
00535 {
00536 $sId = parent::setId( $sId );
00537
00538
00539 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00540
00541 return $sId;
00542 }
00543
00551 public function getTableNameForActiveSnippet( $blForceCoreTable = false )
00552 {
00553 $sTable = $this->getCoreTableName();
00554
00555 return $sTable;
00556 }
00557
00567 public function getActiveCheckQuery( $blForceCoreTable = false )
00568 {
00569 $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00570
00571
00572 $sQ = " $sTable.oxactive = 1 ";
00573
00574
00575 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00576 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00577 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00578 }
00579
00580 return $sQ;
00581 }
00582
00596 public function getStockCheckQuery( $blForceCoreTable = false )
00597 {
00598 $myConfig = $this->getConfig();
00599 $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00600
00601 $sQ = "";
00602
00603
00604 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00605 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00606
00607 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00608 $sTimeCheckQ = '';
00609 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00610 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00611 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00612 }
00613 $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 ) ) ";
00614 }
00615 }
00616
00617 return $sQ;
00618 }
00619
00631 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = false )
00632 {
00633 $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00634 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00635
00636
00637 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $blRemoveNotOrderables ) {
00638 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and ( $sTable.oxstockflag = 1 or $sTable.oxstockflag = 4 ) ) ) ";
00639 }
00640
00641 return $sQ;
00642 }
00643
00651 public function getSqlActiveSnippet( $blForceCoreTable = false )
00652 {
00653 $myConfig = $this->getConfig();
00654
00655
00656 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00657
00658
00659 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00660
00661
00662 return "( $sQ ) ";
00663 }
00664
00672 public function setSkipAssign($blSkipAssign)
00673 {
00674 $this->_blSkipAssign = $blSkipAssign;
00675 }
00676
00684 public function disablePriceLoad( $oArticle )
00685 {
00686 $oArticle->_blLoadPrice = false;
00687 }
00688
00694 public function getItemKey()
00695 {
00696 return $this->_sItemKey;
00697 }
00698
00706 public function setItemKey($sItemKey)
00707 {
00708 $this->_sItemKey = $sItemKey;
00709 }
00710
00718 public function setNoVariantLoading( $blLoadVariants )
00719 {
00720 $this->_blLoadVariants = !$blLoadVariants;
00721 }
00722
00728 public function isBuyable()
00729 {
00730 if ($this->_blNotBuyableParent) {
00731 return false;
00732 }
00733
00734 return !$this->_blNotBuyable;
00735 }
00736
00742 public function getPersParams()
00743 {
00744 return $this->_aPersistParam;
00745 }
00746
00752 public function isOnComparisonList()
00753 {
00754 return $this->_blIsOnComparisonList;
00755 }
00756
00764 public function setOnComparisonList( $blOnList )
00765 {
00766 $this->_blIsOnComparisonList = $blOnList;
00767 }
00768
00776 public function setLoadParentData($blLoadParentData)
00777 {
00778 $this->_blLoadParentData = $blLoadParentData;
00779 }
00780
00788 public function setSkipAbPrice( $blSkipAbPrice = null )
00789 {
00790 $this->_blSkipAbPrice = $blSkipAbPrice;
00791 }
00792
00798 public function getSearchableFields()
00799 {
00800 $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00801 $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00802
00803 return $aFields;
00804 }
00805
00806
00814 public function isMultilingualField($sFieldName)
00815 {
00816 switch ($sFieldName) {
00817 case "oxlongdesc":
00818 case "oxtags":
00819 return true;
00820 }
00821
00822 return parent::isMultilingualField($sFieldName);
00823 }
00824
00830 public function isVisible()
00831 {
00832
00833
00834 $myConfig = $this->getConfig();
00835 if ( ( $sPrevId = oxConfig::getParameter( 'preview' ) ) &&
00836 ( $sAdminSid = oxUtilsServer::getInstance()->getOxCookie( 'admin_sid' ) ) ) {
00837
00838 $oDb = oxDb::getDb();
00839 $sPrevId = $oDb->quote( $sPrevId );
00840 $sAdminSid = $oDb->quote( $sAdminSid );
00841 $sTable = getViewName( 'oxuser' );
00842
00843 return (bool) $oDb->getOne( "select 1 from $sTable where MD5( CONCAT( {$sAdminSid}, {$sTable}.oxid, {$sTable}.oxpassword, {$sTable}.oxrights ) ) = $sPrevId" );
00844 }
00845
00846
00847 $sNow = date('Y-m-d H:i:s');
00848 if ( !$this->oxarticles__oxactive->value &&
00849 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00850 $this->oxarticles__oxactiveto->value < $sNow
00851 )) {
00852 return false;
00853 }
00854
00855
00856 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
00857 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
00858 return false;
00859 }
00860
00861 return true;
00862 }
00863
00872 public function assign( $aRecord)
00873 {
00874 startProfile('articleAssign');
00875
00876
00877
00878 parent::assign( $aRecord);
00879
00880 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00881
00882
00883 if ($this->_blSkipAssign) {
00884 return;
00885 }
00886
00887 $this->_assignParentFieldValues();
00888 $this->_assignNotBuyableParent();
00889 $this->_assignPictureValues();
00890 $this->_assignStock();
00891 startProfile('articleAssignPrices');
00892 $this->_assignPrices();
00893 stopProfile('articleAssignPrices');
00894 $this->_assignPersistentParam();
00895 $this->_assignDynImageDir();
00896 $this->_assignComparisonListFlag();
00897 $this->_assignAttributes();
00898
00899
00900
00901
00902 stopProfile('articleAssign');
00903 }
00904
00915 public function load( $oxID)
00916 {
00917
00918 $this->_blNotBuyableParent = false;
00919
00920 $blRet = parent::load( $oxID);
00921
00922
00923 $this->oxarticles__oxinsert = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00924 $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00925
00926 return $blRet;
00927 }
00928
00936 public function addToRatingAverage( $iRating)
00937 {
00938 $dOldRating = $this->oxarticles__oxrating->value;
00939 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00940 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00941 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00942 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00943 $dRatingCnt = (int)($dOldCnt + 1);
00944
00945 oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00946 }
00947
00953 public function getArticleRatingAverage()
00954 {
00955 return round( $this->oxarticles__oxrating->value, 1);
00956 }
00957
00963 public function getReviews()
00964 {
00965 $myConfig = $this->getConfig();
00966
00967 $aIds = array($this->getId());
00968
00969 if ( $this->oxarticles__oxparentid->value ) {
00970 $aIds[] = $this->oxarticles__oxparentid->value;
00971 }
00972
00973
00974 if ( $myConfig->getConfigParam( 'blShowVariantReviews' ) ) {
00975 $aAdd = $this->_getVariantsIds();
00976 if (is_array($aAdd)) {
00977 $aIds = array_merge($aIds, $aAdd);
00978 }
00979 }
00980
00981 $oReview = oxNew('oxreview');
00982 $oRevs = $oReview->loadList('oxarticle', $aIds);
00983
00984
00985 if ( $oRevs->count() < 1 ) {
00986 return null;
00987 }
00988
00989 return $oRevs;
00990 }
00991
00997 public function getCrossSelling()
00998 {
00999 $oCrosslist = oxNew( "oxarticlelist");
01000 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
01001 if ( $oCrosslist->count() ) {
01002 return $oCrosslist;
01003 }
01004 }
01005
01011 public function getAccessoires()
01012 {
01013 $myConfig = $this->getConfig();
01014
01015
01016 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01017 return;
01018 }
01019
01020 $oAcclist = oxNew( "oxarticlelist");
01021 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01022 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01023
01024 if ( $oAcclist->count()) {
01025 return $oAcclist;
01026 }
01027 }
01028
01034 public function getSimilarProducts()
01035 {
01036
01037 $myConfig = $this->getConfig();
01038 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01039 return;
01040 }
01041
01042 $sArticleTable = $this->_getObjectViewName('oxarticles');
01043
01044 $sAttribs = '';
01045 $iCnt = 0;
01046 $this->_getAttribsString($sAttribs, $iCnt);
01047
01048 if ( !$sAttribs) {
01049 return null;
01050 }
01051
01052
01053
01054
01055
01056
01057 $aList = $this->_getSimList($sAttribs, $iCnt);
01058
01059 if ( count( $aList ) ) {
01060 uasort( $aList, 'cmpart');
01061
01062 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01063
01064 $oSimilarlist = oxNew( 'oxarticlelist' );
01065 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01066 $oSimilarlist->selectString( $sSearch);
01067
01068 return $oSimilarlist;
01069 }
01070 }
01071
01077 public function getCustomerAlsoBoughtThisProducts()
01078 {
01079
01080 $myConfig = $this->getConfig();
01081 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01082 return;
01083 }
01084
01085
01086 $sQ = $this->_generateSearchStrForCustomerBought();
01087
01088 $oArticles = oxNew( 'oxarticlelist' );
01089 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01090 $oArticles->selectString( $sQ );
01091 if ( $oArticles->count() ) {
01092 return $oArticles;
01093 }
01094 }
01095
01102 public function loadAmountPriceInfo()
01103 {
01104 $myConfig = $this->getConfig();
01105 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01106 return array();
01107 }
01108
01109 if ( $this->_oAmountPriceInfo !== null ) {
01110 return $this->_oAmountPriceInfo;
01111 }
01112
01113 $oAmPriceList = $this->_getAmountPriceList();
01114
01115 if ( count( $oAmPriceList ) ) {
01116 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01117 return $this->_oAmountPriceInfo;
01118 }
01119
01120 return array();
01121 }
01122
01130 public function getSelectLists($sKeyPrefix = null)
01131 {
01132
01133
01134 $sKey = $this->getId();
01135 if ( isset( $sKeyPrefix ) ) {
01136 $sKey = $sKeyPrefix.'__'.$this->getId();
01137 }
01138
01139 if ( self::$_aSelList[$sKey]) {
01140 return self::$_aSelList[$sKey];
01141 }
01142
01143
01144 $oLists = oxNew( 'oxlist' );
01145 $oLists->init('oxselectlist');
01146 $sSLViewName = getViewName('oxselectlist');
01147 $sSelect = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01148 $sSelect .= 'where oxobject2selectlist.oxobjectid=\''.$this->getId().'\' ';
01149 //sorting
01150 $sSelect .= ' order by oxobject2selectlist.oxsort';
01151
01152 $oLists->selectString( $sSelect );
01153
01154 //#1104S if this is variant ant it has no selectlists, trying with parent
01155 if ( $this->oxarticles__oxparentid->value && $oLists->count() == 0 ) {
01156 $sParentQuoted = oxDb::getDb()->quote($this->oxarticles__oxparentid->value);
01157 //#1496C - select fixed ( * => $sSLViewName.*)
01158 $sSelect = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01159 $sSelect .= "where oxobject2selectlist.oxobjectid=$sParentQuoted ";
01160 //sorting
01161 $sSelect .= ' order by oxobject2selectlist.oxsort';
01162 $oLists->selectString( $sSelect);
01163 }
01164
01165 $dVat = 0;
01166 if ( $this->getPrice() != null ) {
01167 $dVat = $this->getPrice()->getVat();
01168 }
01169
01170 $iCnt = 0;
01171 self::$_aSelList[$sKey] = array();
01172 foreach ( $oLists as $oSelectlist ) {
01173 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01174 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01175 $iCnt++;
01176 }
01177 return self::$_aSelList[$sKey];
01178 }
01179
01187 protected function _hasAnyVariant( $blForceCoreTable = false )
01188 {
01189 $sArticleTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
01190 return (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='".$this->getId()."'" );
01191 }
01192
01198 public function hasMdVariants()
01199 {
01200 return $this->_blHasMdVariants;
01201 }
01202
01210 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = false )
01211 {
01212 if ( $blRemoveNotOrderables && $this->_aVariants ) {
01213 return $this->_aVariants;
01214 } elseif ( !$blRemoveNotOrderables && $this->_aVariantsWithNotOrderables ) {
01215 return $this->_aVariantsWithNotOrderables;
01216 }
01217
01218 $myConfig = $this->getConfig();
01219 if ( !$this->_blLoadVariants ||
01220 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01221 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01222 return array();
01223 }
01224
01225 //do not load me as a parent later
01226 self::$_aLoadedParents[$this->getId()] = $this;
01227
01228 //load simple variants for lists
01229 if ( $this->_isInList() ) {
01230 $oVariants = oxNew( 'oxsimplevariantlist' );
01231 $oVariants->setParent( $this );
01232 } else {
01233 //loading variants
01234 $oVariants = oxNew( 'oxarticlelist' );
01235 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01236 }
01237
01238 $this->_iVarStock = $this->oxarticles__oxvarstock->value;
01239 if ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) {
01240
01241 startProfile("selectVariants");
01242 $blUseCoreTable = $blForceCoreTable;
01243 $oBaseObject = $oVariants->getBaseObject();
01244 $sArticleTable = $this->getTableNameForActiveSnippet( $blUseCoreTable );
01245
01246 $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01247 $this->getActiveCheckQuery( $blUseCoreTable ) .
01248 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01249 " order by $sArticleTable.oxsort";
01250
01251 $oVariants->selectString( $sSelect );
01252
01253 //if this is multidimensional variants, make additional processing
01254 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01255 $oMdVariants = oxNew( "oxVariantHandler" );
01256 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01257 }
01258 stopProfile("selectVariants");
01259 }
01260
01261 //if we have variants then depending on config option the parent may be non buyable
01262 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01263 $this->_blNotBuyableParent = true;
01264 }
01265
01266 //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01267 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $oVariants->count() == 0 && $this->_blHasVariants ) {
01268 $this->_blNotBuyable = true;
01269 }
01270
01271 // cache
01272 if ( $blRemoveNotOrderables ) {
01273 $this->_aVariants = $oVariants;
01274 } else {
01275 $this->_aVariantsWithNotOrderables = $oVariants;
01276 }
01277
01278 return $oVariants;
01279 }
01280
01286 public function getSimpleVariants()
01287 {
01288 if ( $this->oxarticles__oxvarcount->value) {
01289 return $this->getVariants();
01290 }
01291 }
01292
01301 public function getAdminVariants( $sLanguage = null )
01302 {
01303 $myConfig = $this->getConfig();
01304
01305 $oVariants = oxNew( 'oxarticlelist');
01306
01307 if ( is_null($sLanguage) ) {
01308 $oVariants->getBaseObject()->setLanguage(oxLang::getInstance()->getBaseLanguage());
01309 } else {
01310 $oVariants->getBaseObject()->setLanguage($sLanguage);
01311 }
01312
01313 $sSql = 'select * from oxarticles where oxparentid = "'.$this->getId().'" order by oxsort ';
01314
01315 $oVariants->selectString( $sSql);
01316
01317 //if we have variants then depending on config option the parent may be non buyable
01318 if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01319 //$this->blNotBuyable = true;
01320 $this->_blNotBuyableParent = true;
01321 }
01322
01323 return $oVariants;
01324 }
01325
01333 public function getCategory()
01334 {
01335 startPRofile( 'getCategory' );
01336
01337 $oCategory = oxNew( 'oxcategory' );
01338 $oCategory->setLanguage( $this->getLanguage() );
01339
01340 // variant handling
01341 $sOXID = $this->getId();
01342 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01343 $sOXID = $this->oxarticles__oxparentid->value;
01344 }
01345
01346 $oStr = getStr();
01347 $sWhere = $oCategory->getSqlActiveSnippet();
01348 $sSelect = $this->_generateSearchStr( $sOXID );
01349 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01350
01351 // category not found ?
01352 if ( !$oCategory->assignRecord( $sSelect ) ) {
01353
01354 $sSelect = $this->_generateSearchStr( $sOXID, true );
01355 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01356
01357 // looking for price category
01358 if ( !$oCategory->assignRecord( $sSelect ) ) {
01359 $oCategory = null;
01360 }
01361 }
01362
01363 stopPRofile( 'getCategory' );
01364 return $oCategory;
01365 }
01366
01375 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01376 {
01377 $myConfig = $this->getConfig();
01378 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01379 return self::$_aArticleCats[$this->getId()];
01380 }
01381
01382 // variant handling
01383 $sOXID = $this->getId();
01384 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01385 $sOXID = $this->oxarticles__oxparentid->value;
01386 }
01387
01388 // we do not use lists here as we dont need this overhead right now
01389 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01390 $oDB = oxDb::getDb(true);
01391 $rs = $oDB->execute( $sSql );
01392
01393
01394 $aRet = array();
01395 $iHitMax = 0;
01396 if ($rs != false && $rs->recordCount() > 0) {
01397 while (!$rs->EOF) {
01398 $aRet[] = $rs->fields['oxcatnid'];
01399 $rs->moveNext();
01400 }
01401 }
01402
01403 return self::$_aArticleCats[$this->getId()] = $aRet;
01404 }
01405
01414 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01415 {
01416 $sO2CView = $this->_getObjectViewName('oxobject2category');
01417 $sCatView = $this->_getObjectViewName('oxcategories');
01418 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01419 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 ';
01420 if ( $blActCats ) {
01421 $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 ";
01422 }
01423 $sSelect .= 'order by oxobject2category.oxtime ';
01424 return $sSelect;
01425 }
01426
01436 public function getVendor( $blShopCheck = true )
01437 {
01438 if ( ( $sVendorId = $this->getVendorId() ) ) {
01439 $oVendor = oxNew( 'oxvendor' );
01440 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01441 $oVendor = oxNew( 'oxi18n' );
01442 $oVendor->init('oxvendor');
01443 $oVendor->setReadOnly( true );
01444 $sVendorId = $this->oxarticles__oxvendorid->value;
01445 }
01446 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01447 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01448 $oVendor->setReadOnly( true );
01449 }
01450 return $oVendor;
01451 }
01452 return null;
01453 }
01454
01462 public function getVendorId( $blForceReload = false )
01463 {
01464 $sVendorId = false;
01465 if ( $this->oxarticles__oxvendorid->value ) {
01466 if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01467 return self::$_aArticleVendors[$this->getId()];
01468 }
01469 $oDb = oxDb::getDb();
01470 $sVendorIdQuoted = $oDb->quote($this->oxarticles__oxvendorid->value);
01471 $sQ = "select oxid from ".getViewName('oxvendor')." where oxid=$sVendorIdQuoted";
01472 self::$_aArticleVendors[$this->getId()] = $sVendorId = $oDb->getOne( $sQ );
01473 }
01474 return $sVendorId;
01475 }
01476
01484 public function getManufacturerId( $blForceReload = false )
01485 {
01486 $sManufacturerId = false;
01487 if ( $this->oxarticles__oxmanufacturerid->value ) {
01488 if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01489 return self::$_aArticleManufacturers[$this->getId()];
01490 }
01491 $oDb = oxDb::getDb();
01492 $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid=".$oDb->quote($this->oxarticles__oxmanufacturerid->value);
01493 self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = $oDb->getOne( $sQ );
01494 }
01495 return $sManufacturerId;
01496 }
01497
01507 public function getManufacturer( $blShopCheck = true )
01508 {
01509 $oManufacturer = oxNew( 'oxmanufacturer' );;
01510 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01511 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01512 $oManufacturer->setReadOnly( true );
01513 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01514 }
01515
01516 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01517 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01518 $oManufacturer->setReadOnly( true );
01519 }
01520 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01521 } else {
01522 $oManufacturer = null;
01523 }
01524
01525 return $oManufacturer;
01526 }
01527
01535 public function inCategory( $sCatNid)
01536 {
01537 return in_array( $sCatNid, $this->getCategoryIds());
01538 }
01539
01548 public function isAssignedToCategory( $sCatId )
01549 {
01550 // variant handling
01551 $sOXID = $this->getId();
01552 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01553 $sOXID = $this->oxarticles__oxparentid->value;
01554 }
01555
01556 $oDB = oxDb::getDb();
01557 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01558 $sOXID = $oDB->getOne( $sSelect);
01559 // article is assigned to passed category!
01560 if ( isset( $sOXID) && $sOXID) {
01561 return true;
01562 }
01563
01564 // maybe this category is price category ?
01565 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01566 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01567 if ( $dPriceFromTo > 0) {
01568 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01569 $sOXID = $oDB->getOne( $sSelect);
01570 // article is assigned to passed category!
01571 if ( isset( $sOXID) && $sOXID) {
01572 return true;
01573 }
01574 }
01575 }
01576 return false;
01577 }
01578
01584 public function getTPrice()
01585 {
01586 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01587 return;
01588 }
01589 // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01590 if ( $this->_oTPrice !== null ) {
01591 return $this->_oTPrice;
01592 }
01593
01594 $this->_oTPrice = oxNew( 'oxPrice' );
01595 $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01596
01597 $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01598 $this->_applyCurrency( $this->_oTPrice );
01599
01600 return $this->_oTPrice;
01601 }
01602
01608 public function skipDiscounts()
01609 {
01610 // allready loaded skip discounts config
01611 if ( $this->_blSkipDiscounts !== null )
01612 return $this->_blSkipDiscounts;
01613
01614 if ( $this->oxarticles__oxskipdiscounts->value )
01615 return true;
01616
01617 $sO2CView = getViewName('oxobject2category');
01618 $sSelect = "select 1 from $sO2CView as oxobject2category left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01619 $sSelect .= 'where oxobject2category.oxobjectid="'.$this->getId().'" and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 and oxcategories.oxskipdiscounts = "1" ';
01620
01621 return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01622 }
01623
01631 public function setPrice(oxPrice $oPrice)
01632 {
01633 $this->_oPrice = $oPrice;
01634 }
01635
01644 public function getBasePrice( $dAmount = 1 )
01645 {
01646 // override this function if you want e.g. different prices
01647 // for diff. usergroups.
01648
01649 // Performance
01650 $myConfig = $this->getConfig();
01651 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01652 return;
01653
01654 // GroupPrice or DB price ajusted by AmountPrice
01655 $dPrice = $this->_getAmountPrice( $dAmount );
01656
01657
01658 return $dPrice;
01659 }
01660
01666 public function getPrice()
01667 {
01668 $myConfig = $this->getConfig();
01669 // Performance
01670 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01671 return;
01672 }
01673 // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01674 if ( $this->_oPrice ) {
01675 return $this->_oPrice;
01676 }
01677
01678 $this->_oPrice = oxNew( 'oxPrice' );
01679
01680 // get base
01681 $this->_oPrice->setPrice( $this->getBasePrice() );
01682
01683 // price handling
01684 if ( !$this->_blCalcPrice ) {
01685 return $this->_oPrice;
01686 }
01687
01688 $this->_calculatePrice( $this->_oPrice );
01689
01690 return $this->_oPrice;
01691 }
01692
01700 protected function _calculatePrice( $oPrice )
01701 {
01702 // apply VAT only if configuration requires it
01703 if ( !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01704 $this->_applyVAT( $oPrice, $this->getArticleVat() );
01705 }
01706
01707 // apply currency
01708 $this->_applyCurrency( $oPrice );
01709 // apply discounts
01710 if ( !$this->skipDiscounts() ) {
01711 $oDiscountList = oxDiscountList::getInstance();
01712 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts($this, $this->getArticleUser() ) );
01713 }
01714
01715 return $oPrice;
01716 }
01717
01725 public function setArticleUser($oUser)
01726 {
01727 $this->_oUser = $oUser;
01728 }
01729
01735 public function getArticleUser()
01736 {
01737 if ($this->_oUser) {
01738 return $this->_oUser;
01739 }
01740 return $this->getUser();
01741 }
01742
01752 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01753 {
01754 $oUser = $oBasket->getBasketUser();
01755 $this->setArticleUser($oUser);
01756
01757 $oBasketPrice = oxNew( 'oxPrice' );
01758
01759 // get base price
01760 $dBasePrice = $this->getBasePrice( $dAmount );
01761
01762 // applying select list price
01763 $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01764
01765 // setting price
01766 $oBasketPrice->setPrice( $dBasePrice );
01767
01768 // apply VAT
01769 $this->_applyVat( $oBasketPrice, oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket ) );
01770
01771 // apply currency
01772 $this->_applyCurrency( $oBasketPrice );
01773
01774 // apply discounts
01775 if ( !$this->skipDiscounts() ) {
01776 // apply general discounts
01777 $oDiscountList = oxDiscountList::getInstance();
01778 $oDiscountList->applyDiscounts( $oBasketPrice, $oDiscountList->getArticleDiscounts( $this, $oUser ) );
01779 }
01780
01781 // returning final price object
01782 return $oBasketPrice;
01783 }
01784
01797 public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01798 {
01799 $oDiscountList = oxDiscountList::getInstance();
01800 return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01801 }
01802
01811 public function delete( $sOXID = null )
01812 {
01813 if ( !$sOXID ) {
01814 $sOXID = $this->getId();
01815 }
01816 if ( !$sOXID ) {
01817 return false;
01818 }
01819
01820
01821 $this->load( $sOXID );
01822 $this->_deletePics();
01823 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01824 $this->_deleteVariantRecords( $sOXID );
01825 $rs = $this->_deleteRecords( $sOXID );
01826
01827 oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01828
01829 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01830
01831 return $rs->EOF;
01832 }
01833
01842 public function updateSoldAmount( $dAmount = 0 )
01843 {
01844 if ( !$dAmount ) {
01845 return;
01846 }
01847
01848 $this->beforeUpdate();
01849
01850 // article is not variant - should be updated current amount
01851 if ( !$this->oxarticles__oxparentid->value ) {
01852 //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01853 $dAmount = (double)$dAmount;
01854 $oDb = oxDb::getDb();
01855 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount, oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01856 } elseif ( $this->oxarticles__oxparentid->value) {
01857 // article is variant - should be updated this article parent amount
01858 $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01859 $oUpdateArticle->updateSoldAmount( $dAmount );
01860 }
01861
01862 $this->onChange( ACTION_UPDATE );
01863
01864 return $rs;
01865 }
01866
01872 public function disableReminder()
01873 {
01874 $oDB = oxDb::getDb(true);
01875 return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01876 }
01877
01884 public function save()
01885 {
01886 $myConfig = $this->getConfig();
01887
01888 $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01889 $this->oxarticles__oxicon = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01890 $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01891 for ($i=1; $i <= $iPicCount; $i++) {
01892 if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01893 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01894 }
01895 }
01896 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
01897 for ($i=1; $i <= $iZoomPicCount; $i++) {
01898 if ( isset($this->{'oxarticles__oxzoom'.$i}) ) {
01899 $this->{'oxarticles__oxzoom'.$i}->setValue(basename($this->{'oxarticles__oxzoom'.$i}->value));
01900 }
01901 }
01902
01903 $blRet = parent::save();
01904
01905 // save article long description
01906 $this->setArticleLongDesc();
01907 // load article images after save
01908 $this->_assignPictureValues();
01909
01910 return $blRet;
01911 }
01912
01913
01920 public function getPictureGallery()
01921 {
01922 $myConfig = $this->getConfig();
01923
01924 //initialize
01925 $blMorePic = false;
01926 $aArtPics = array();
01927 $aArtIcons = array();
01928 $iActPicId = 1;
01929 $sActPic = $this->getPictureUrl( $iActPicId );
01930
01931 if ( oxConfig::getParameter( 'actpicid' ) ) {
01932 $iActPicId = oxConfig::getParameter('actpicid');
01933 }
01934
01935 $oStr = getStr();
01936 $iCntr = 0;
01937 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01938 for ( $i = 1; $i <= $iPicCount; $i++) {
01939 $sPicVal = $this->getPictureUrl( $i );
01940 $sIcoVal = $this->getIconUrl( $i );
01941 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg')) {
01942 if ($iCntr) {
01943 $blMorePic = true;
01944 }
01945 $aArtIcons[$i]= $sIcoVal;
01946 $aArtPics[$i]= $sPicVal;
01947 $iCntr++;
01948 }
01949 if ($iActPicId == $i) {
01950 $sActPic = $sPicVal;
01951 }
01952 }
01953
01954 $blZoomPic = false;
01955 $aZoomPics = array();
01956 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
01957 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
01958 $sVal = $this->getZoomPictureUrl($j);
01959 if ( !$oStr->strstr($sVal, 'nopic.jpg')) {
01960 if ($this->getConfig()->getConfigParam('blFormerTplSupport')) {
01961 $sVal = $this->_sDynImageDir."/".$sVal;
01962 }
01963 $blZoomPic = true;
01964 $aZoomPics[$c]['id'] = $c;
01965 $aZoomPics[$c]['file'] = $sVal;
01966 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01967 if (!$sVal) {
01968 $aZoomPics[$c]['file'] = "nopic.jpg";
01969 }
01970 $c++;
01971 }
01972 }
01973
01974 $aPicGallery = array('ActPicID' => $iActPicId,
01975 'ActPic' => $sActPic,
01976 'MorePics' => $blMorePic,
01977 'Pics' => $aArtPics,
01978 'Icons' => $aArtIcons,
01979 'ZoomPic' => $blZoomPic,
01980 'ZoomPics' => $aZoomPics);
01981
01982 return $aPicGallery;
01983 }
01984
01998 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
01999 {
02000 $myConfig = $this->getConfig();
02001
02002 if (!isset($sOXID)) {
02003 if ( $this->getId()) {
02004 $sOXID = $this->getId();
02005 }
02006 if (!isset ($sOXID)) {
02007 $sOXID = $this->oxarticles__oxid->value;
02008 }
02009 if ($this->oxarticles__oxparentid->value) {
02010 $sParentID = $this->oxarticles__oxparentid->value;
02011 }
02012 }
02013 if (!isset($sOXID)) {
02014 return;
02015 }
02016
02017 //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02018 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02019 //if article has variants then updating oxvarstock field
02020 //getting parent id
02021 if (!isset($sParentID)) {
02022 $oDb = oxDb::getDb();
02023 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02024 $sParentID = $oDb->getOne($sQ);
02025 }
02026 //if we have parent id then update stock
02027 if ($sParentID) {
02028 $this->_onChangeUpdateStock($sParentID);
02029 }
02030 }
02031 //if we have parent id then update count
02032 //update count even if blUseStock is not active
02033 if ($sParentID) {
02034 $this->_onChangeUpdateVarCount($sParentID);
02035 }
02036
02037 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02038 $this->_onChangeUpdateMinVarPrice( $sId );
02039
02040 }
02041
02048 public function getCustomVAT()
02049 {
02050 if ( isset($this->oxarticles__oxvat->value) ) {
02051 return $this->oxarticles__oxvat->value;
02052 }
02053 }
02054
02062 public function checkForStock( $dAmount )
02063 {
02064 $myConfig = $this->getConfig();
02065 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02066 return true;
02067 }
02068
02069 // fetching DB info as its up-to-date
02070 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02071 $rs = oxDb::getDb(true)->Execute( $sQ );
02072
02073 $iOnStock = 0;
02074 $iStockFlag = 0;
02075 if ( $rs !== false && $rs->recordCount() > 0 ) {
02076 $iOnStock = $rs->fields['oxstock'];
02077 $iStockFlag = $rs->fields['oxstockflag'];
02078
02079 // dodger : fremdlager is also always considered as on stock
02080 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02081 return true;
02082 }
02083 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02084 //2007-09-04 MK this if is NEVER true, because upper return in if $iStockFlag == 1 or $iStockFlag == 4
02085 /* if ( $iStockFlag == 1 || $iStockFlag == 4 ) {
02086 $iOnStock = ceil( $iOnStock );
02087 } else {*/
02088 $iOnStock = floor( $iOnStock );
02089 //}
02090 }
02091 }
02092
02093 if ( $iOnStock >= $dAmount ) {
02094 return true;
02095 } else {
02096 if ( $iOnStock > 0 ) {
02097 return $iOnStock;
02098 } else {
02099 $oEx = oxNew( 'oxArticleInputException' );
02100 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02101 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02102 return false;
02103 }
02104 }
02105 }
02106
02107
02115 public function getArticleLongDesc($sOXID = null)
02116 {
02117
02118 if ( !$sOXID ) {
02119 $sOXID = $this->oxarticles__oxid->value;
02120 }
02121
02122 if ($sOXID == $this->oxarticles__oxid->value) {
02123 if (isset($this->oxarticles__oxlongdesc) && ($this->oxarticles__oxlongdesc instanceof oxField) && $this->oxarticles__oxlongdesc->value) {
02124 return $this->oxarticles__oxlongdesc;
02125 }
02126 }
02127
02128 $myConfig = $this->getConfig();
02129
02130 if ( $sOXID ) {
02131 $sLangField = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02132 $oDb = oxDb::getDb();
02133 $this->_setLongDesc($oDb->getOne( "select oxlongdesc{$sLangField} from oxartextends where oxid = ".$oDb->quote($sOXID) ));
02134 } else {
02135 // TODO: check if keeping fldname is needed in non-admin mode
02136 $this->oxarticles__oxlongdesc = new oxField();
02137 $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02138 $this->oxarticles__oxlongdesc->table = 'oxarticles';
02139 $this->oxarticles__oxlongdesc->fldtype = 'text';
02140 }
02141
02142 return $this->oxarticles__oxlongdesc;
02143 }
02144
02152 protected function _setLongDesc($sDbValue)
02153 {
02154 // TODO: eliminate code below
02155 // hack, if editor screws up text, htmledit tends to do so
02156 $sDbValue = str_replace( '&nbsp;', ' ', $sDbValue );
02157 $sDbValue = str_replace( '&', '&', $sDbValue );
02158 $sDbValue = str_replace( '"', '"', $sDbValue );
02159 $sDbValue = str_replace( '&lang=', '&lang=', $sDbValue);
02160 //
02161
02162 $oStr = getStr();
02163 $blHasSmarty = $oStr->strstr( $sDbValue, '[{' );
02164 $blHasPhp = $oStr->strstr( $sDbValue, '<?' );
02165 $myConfig = oxConfig::getInstance();
02166 if ( ( $blHasSmarty || $blHasPhp ) && ($myConfig->getConfigParam( 'blExport' ) || !$this->isAdmin() ) && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
02167 $sDbValue = oxUtilsView::getInstance()->parseThroughSmarty( $sDbValue, $this->getId() );
02168 }
02169 $this->oxarticles__oxlongdesc = new oxField($sDbValue, oxField::T_RAW);
02170 // TODO: check if keeping fldname is needed in non-admin mode
02171 $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02172 $this->oxarticles__oxlongdesc->table = 'oxarticles';
02173 $this->oxarticles__oxlongdesc->fldtype = 'text';
02174 }
02175
02181 public function setArticleLongDesc()
02182 {
02183
02184 if ( $this->_blEmployMultilanguage ) {
02185 // update or insert article long description
02186 if ($this->oxarticles__oxlongdesc instanceof oxField) {
02187 $sLongDesc = $this->oxarticles__oxlongdesc->getRawValue();
02188 } else {
02189 $sLongDesc = $this->oxarticles__oxlongdesc->value;
02190 }
02191 $this->_saveArtLongDesc($this->getLanguage(), $sLongDesc);
02192 } else {
02193 $oArtExt = oxNew('oxi18n');
02194 $oArtExt->init('oxartextends');
02195 $aObjFields = $oArtExt->_getAllFields(true);
02196 foreach ($aObjFields as $sKey => $sValue ) {
02197 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02198 $sField = $this->_getFieldLongName($sKey);
02199 if (isset($this->$sField)) {
02200 $iLang = $oArtExt->_getFieldLang($sKey);
02201 $sLongDesc = null;
02202 if ($this->$sField instanceof oxField) {
02203 $sLongDesc = $this->$sField->getRawValue();
02204 } elseif (is_object($this->$sField)) {
02205 $sLongDesc = $this->$sField->value;
02206 }
02207 if (isset($sLongDesc)) {
02208 $this->_saveArtLongDesc($iLang, $sLongDesc);
02209 }
02210 }
02211 }
02212 }
02213 }
02214 }
02215
02221 public function getAttributes()
02222 {
02223
02224 if ($this->_oAttributeList) {
02225 return $this->_oAttributeList;
02226 }
02227
02228 $oAttributeList = oxNew( 'oxattributelist' );
02229 $oAttributeList->loadAttributes( $this->getId());
02230 //if config option is set then the value for this object is also set
02231 //2007-02-09T
02232 $this->_oAttributeList = $oAttributeList;
02233
02234 return $oAttributeList;
02235 }
02236
02244 public function appendLink( $sAddParams )
02245 {
02246 if ( $this->_sDetailLink === null ) {
02247 $this->_sDetailLink = $this->getLink();
02248 }
02249 $this->_sDetailLink .= (( strpos( $this->_sDetailLink, '?' ) !== false ) ? '&' : '?' ) . $sAddParams;
02250 }
02251
02259 public function getLink($iLang = null)
02260 {
02261 if (isset($iLang)) {
02262 $iLang = (int) $iLang;
02263 if ($iLang == (int) $this->getLanguage()) {
02264 $iLang = null;
02265 }
02266 }
02267 if ( $this->_sDetailLink === null || isset($iLang) ) {
02268
02269 if ( oxUtils::getInstance()->seoIsActive() ) {
02270 $oxdetaillink = oxSeoEncoderArticle::getInstance()->getArticleUrl( $this, $iLang, $this->_iLinkType);
02271 } else {
02272 $oxdetaillink = $this->getStdLink($iLang);
02273 }
02274
02275 if (isset($iLang)) {
02276 return $oxdetaillink;
02277 } else {
02278 $this->_sDetailLink = $oxdetaillink;
02279 }
02280 }
02281
02282 return $this->_sDetailLink;
02283 }
02284
02292 public function setLinkType( $iType )
02293 {
02294 // resetting detaisl link, to force new
02295 $this->_sDetailLink = null;
02296
02297 // setting link type
02298 $this->_iLinkType = (int) $iType;
02299 }
02300
02306 public function getLinkType()
02307 {
02308 return $this->_iLinkType;
02309 }
02310
02311
02320 public function getStdLink($iLang = null, $aParams = array() )
02321 {
02322 //always returns shop url, not admin
02323 $this->_sStdLink = $this->getConfig()->getShopHomeURL( $iLang, false );
02324 $this->_sStdLink .= "cl=details&anid=".$this->getId();
02325
02326 if ( !isset($aParams['cnid']) ) {
02327 $aParams['cnid'] = oxConfig::getParameter( 'cnid' );
02328 }
02329 foreach ($aParams as $key => $value) {
02330 if ( $value ) {
02331 $this->_sStdLink .= "&$key=$value";
02332 }
02333 }
02334
02335 $blSeo = oxUtils::getInstance()->seoIsActive();
02336 if ( !$blSeo || $this->_iLinkType != 0 ) {
02337
02338 if ( !$blSeo ) {
02339 $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
02340 if ( $iPgNr > 0 ) {
02341 $this->_sStdLink .= "&pgNr={$iPgNr}";
02342 }
02343 }
02344
02345 if ( ( $sCat = oxConfig::getParameter( 'mnid' ) ) ) {
02346 $this->_sStdLink .= "&mnid={$sCat}";
02347 }
02348
02349 $sListType = oxConfig::getParameter( 'listtype' );
02350 if ( !isset( $sListType ) ) {
02351 // view defined list type
02352 $sListType = $this->getConfig()->getGlobalParameter( 'listtype' );
02353 }
02354
02355 // list type
02356 if ( $sListType ) {
02357 $this->_sStdLink .= "&listtype={$sListType}";
02358 }
02359
02360 if (!$blSeo && isset($iLang)) {
02361 $iLang = (int) $iLang;
02362 if ($iLang != (int) $this->getLanguage()) {
02363 $this->_sStdLink .= "&lang={$iLang}";
02364 }
02365 }
02366 }
02367
02368 return $this->_sStdLink = $this->getSession()->processUrl( $this->_sStdLink );
02369 }
02370
02379 public function getMainLink( $iLang = null )
02380 {
02381 if (isset($iLang)) {
02382 $iLang = (int) $iLang;
02383 if ($iLang == (int) $this->getLanguage()) {
02384 $iLang = null;
02385 }
02386 }
02387 if ( oxUtils::getInstance()->seoIsActive() ) {
02388 return oxSeoEncoderArticle::getInstance()->getArticleMainUrl( $this, $iLang );
02389 } else {
02390 return $this->getStdLink($iLang, array('cnid'=>''));
02391 }
02392 }
02393
02401 public function getStdTagLink( $sTag )
02402 {
02403 $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02404 return $sStdTagLink . "cl=details&anid=".$this->getId()."&listtype=tag&searchtag=".rawurlencode( $sTag );
02405 }
02406
02412 public function getTags()
02413 {
02414 $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02415 $sQ = "select $sTagField from oxartextends where oxid = '".$this->getId()."'";
02416 $sTags = oxDb::getDb(true)->getOne($sQ);
02417 $oTagCloud = oxNew('oxtagcloud');
02418 $sTags = $oTagCloud->trimTags($sTags);
02419 return $sTags;
02420 }
02421
02429 public function saveTags($sTags)
02430 {
02431 $sTags = mysql_real_escape_string($sTags);
02432 $oTagCloud = oxNew('oxtagcloud');
02433 $oTagCloud->resetTagCache();
02434 $sTags = $oTagCloud->prepareTags($sTags);
02435 $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02436 $sQ = "update oxartextends set $sTagField = '$sTags' where oxid = '".$this->getId()."'";
02437 return oxDb::getDb()->execute($sQ);
02438
02439 }
02440
02448 public function addTag($sTag)
02449 {
02450 $sTag = mysql_real_escape_string($sTag);
02451
02452 $oTagCloud = oxNew('oxtagcloud');
02453 $oTagCloud->resetTagCache();
02454 $sTag = $oTagCloud->prepareTags($sTag);
02455
02456 $sField = "oxartextends.OXTAGS".oxLang::getInstance()->getLanguageTag();
02457 $sQ = "insert into oxartextends (oxartextends.OXID, $sField) values ('".$this->getId()."', '{$sTag}')
02458 ON DUPLICATE KEY update $sField = CONCAT(TRIM($sField), ' $sTag') ";
02459
02460 return oxDb::getDb()->Execute($sQ);
02461 }
02462
02468 public function getMediaUrls()
02469 {
02470 if ($this->_aMediaUrls) {
02471 return $this->_aMediaUrls;
02472 }
02473
02474 $this->_aMediaUrls = oxNew("oxlist");
02475 $this->_aMediaUrls->init("oxmediaurl");
02476 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02477
02478 $sQ = "select * from oxmediaurls where oxobjectid = '".$this->getId()."'";
02479 $this->_aMediaUrls->selectString($sQ);
02480
02481 return $this->_aMediaUrls;
02482 }
02483
02489 public function getDynImageDir()
02490 {
02491 return $this->_sDynImageDir;
02492 }
02493
02499 public function getDispSelList()
02500 {
02501 if ($this->_aDispSelList === null) {
02502 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02503 $this->_aDispSelList = $this->getSelectLists();
02504 }
02505 }
02506 return $this->_aDispSelList;
02507 }
02508
02514 public function getMoreDetailLink()
02515 {
02516 if ( $this->_sMoreDetailLink == null ) {
02517
02518 // and assign special article values
02519 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02520
02521 // not always it is okey, as not all the time active category is the same as primary article cat.
02522 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02523 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02524 }
02525 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02526 $this->_sMoreDetailLink = $this->getSession()->processUrl( $this->_sMoreDetailLink );
02527 }
02528
02529 return $this->_sMoreDetailLink;
02530 }
02531
02537 public function getToBasketLink()
02538 {
02539 if ( $this->_sToBasketLink == null ) {
02540 $myConfig = $this->getConfig();
02541
02542 if ( oxUtils::getInstance()->isSearchEngine() ) {
02543 $this->_sToBasketLink = $this->getLink();
02544 } else {
02545 // and assign special article values
02546 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02547
02548 // override some classes as these should never showup
02549 $sActClass = oxConfig::getParameter( 'cl' );
02550 if ( $sActClass == 'thankyou') {
02551 $sActClass = 'basket';
02552 }
02553 $this->_sToBasketLink .= 'cl='.$sActClass;
02554
02555 // this is not very correct
02556 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02557 $this->_sToBasketLink .= '&cnid='.$sActCat;
02558 }
02559
02560 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02561
02562 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02563 $this->_sToBasketLink .= '&tpl='.$sTpl;
02564 }
02565 }
02566
02567 $this->_sToBasketLink = $this->getSession()->processUrl( $this->_sToBasketLink );
02568 }
02569
02570 return $this->_sToBasketLink;
02571 }
02572
02578 public function getStockStatus()
02579 {
02580 return $this->_iStockStatus;
02581 }
02582
02588 public function getDeliveryDate()
02589 {
02590 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02591 return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02592 } else {
02593 return false;
02594 }
02595 }
02596
02602 public function getFTPrice()
02603 {
02604 if ( $oPrice = $this->getTPrice() ) {
02605 if ( $oPrice->getBruttoPrice() ) {
02606 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02607 }
02608 } else {
02609 return null;
02610 }
02611 }
02612
02618 public function getFPrice()
02619 {
02620 if ( $oPrice = $this->getPrice() ) {
02621 return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02622 } else {
02623 return null;
02624 }
02625 }
02626
02632 public function getPricePerUnit()
02633 {
02634 return $this->_fPricePerUnit;
02635 }
02636
02642 public function isParentNotBuyable()
02643 {
02644 return $this->_blNotBuyableParent;
02645 }
02646
02652 public function isNotBuyable()
02653 {
02654 return $this->_blNotBuyable;
02655 }
02656
02664 public function setBuyableState( $blBuyable = false )
02665 {
02666 $this->_blNotBuyable = !$blBuyable;
02667 }
02668
02674 public function getVariantList()
02675 {
02676 return $this->_oVariantList;
02677 }
02678
02686 public function setSelectlist( $aSelList )
02687 {
02688 $this->_aDispSelList = $aSelList;
02689 }
02690
02698 public function getPictureUrl( $iIndex )
02699 {
02700 return $this->getConfig()->getPictureUrl( $this->{"oxarticles__oxpic".$iIndex}->value );
02701 }
02702
02710 public function getIconUrl( $iIndex = '')
02711 {
02712 if (!$iIndex) {
02713 $sFile = $this->oxarticles__oxicon->value;
02714 } else {
02715 $sFile = $this->{'oxarticles__oxpic' . $iIndex . '_ico'}->value;
02716 }
02717
02718 $sFile = str_replace('nopic.jpg', 'nopic_ico.jpg', $sFile);
02719
02720 //$sFile = $this->getConfig()->getPictureUrl( 'icon/' ). basename($sFile);
02721 $sFile = $this->getConfig()->getPictureUrl( $sFile );
02722
02723 return $sFile;
02724 }
02725
02731 public function getThumbnailUrl()
02732 {
02733 //return $this->getConfig()->getPictureUrl( $this->oxarticles__oxthumb->value );
02734 return $this->getConfig()->getPictureUrl( '0/' ) . basename($this->oxarticles__oxthumb->value);
02735 }
02736
02744 public function getZoomPictureUrl($iIndex)
02745 {
02746 return $this->getConfig()->getPictureUrl( $this->{'oxarticles__oxzoom'.$iIndex}->value );
02747 }
02748
02754 public function getFileUrl()
02755 {
02756 return $this->getConfig()->getPictureUrl( '0/' );
02757 }
02758
02764 public function getPriceFromPrefix()
02765 {
02766 $sPricePrefics = '';
02767 if ( $this->_blIsRangePrice) {
02768 $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02769 }
02770
02771 return $sPricePrefics;
02772 }
02773
02782 protected function _saveArtLongDesc($iLang, $sValue)
02783 {
02784 $oDB = oxDb::getDb();
02785 $iLang = (int) $iLang;
02786 $sLangField = ($iLang > '0') ? '_'.$iLang : '';
02787 $sLongDesc = $oDB->quote($sValue);
02788 $sLongDescSQL = "insert into oxartextends (oxartextends.OXID, oxartextends.OXLONGDESC{$sLangField})
02789 VALUES ('".$this->getId()."', {$sLongDesc})
02790 ON DUPLICATE KEY update oxartextends.OXLONGDESC{$sLangField} = {$sLongDesc} ";
02791
02792 $oDB->execute($sLongDescSQL);
02793 }
02794
02801 protected function _skipSaveFields()
02802 {
02803 $myConfig = $this->getConfig();
02804
02805 $this->_aSkipSaveFields = array();
02806
02807 $this->_aSkipSaveFields[] = 'oxtimestamp';
02808 $this->_aSkipSaveFields[] = 'oxlongdesc';
02809 $this->_aSkipSaveFields[] = 'oxinsert';
02810
02811 if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02812 $this->_aSkipSaveFields[] = 'oxparentid';
02813 }
02814
02815 }
02816
02826 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
02827 {
02828 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
02829 // add prices of the same discounts
02830 if ( array_key_exists ($sKey, $aDiscounts) ) {
02831 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
02832 } else {
02833 $aDiscounts[$sKey] = $oDiscount;
02834 }
02835 }
02836 return $aDiscounts;
02837 }
02838
02844 protected function _getGroupPrice()
02845 {
02846 $dPrice = $this->oxarticles__oxprice->value;
02847
02848 $oUser = $this->getArticleUser();
02849 if ( $oUser ) {
02850 if ( $oUser->inGroup( 'oxidpricea' ) ) {
02851 $dPrice = $this->oxarticles__oxpricea->value;
02852 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
02853 $dPrice = $this->oxarticles__oxpriceb->value;
02854 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
02855 $dPrice = $this->oxarticles__oxpricec->value;
02856 }
02857 }
02858
02859 // #1437/1436C - added config option, and check for zero A,B,C price values
02860 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
02861 $dPrice = $this->oxarticles__oxprice->value;
02862 }
02863
02864 return $dPrice;
02865 }
02866
02875 protected function _getAmountPrice($dAmount = 1)
02876 {
02877 $myConfig = $this->getConfig();
02878
02879 startProfile( "_getAmountPrice" );
02880
02881 $dPrice = $this->_getGroupPrice();
02882 $oAmtPrices = $this->_getAmountPriceList();
02883 foreach ($oAmtPrices as $oAmPrice) {
02884 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
02885 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
02886 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
02887 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
02888 }
02889 }
02890
02891 stopProfile( "_getAmountPrice" );
02892 return $dPrice;
02893 }
02894
02903 protected function _modifySelectListPrice( &$dPrice, $aChosenList = null )
02904 {
02905 $myConfig = $this->getConfig();
02906 // #690
02907 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
02908
02909 $aSelLists = $this->getSelectLists();
02910 foreach ( $aSelLists as $key => $aSel) {
02911 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
02912 $oSel = $aSel[$aChosenList[$key]];
02913 if ( $oSel->priceUnit =='abs' ) {
02914 $dPrice += $oSel->price;
02915 } elseif ( $oSel->priceUnit =='%' ) {
02916 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
02917 }
02918 }
02919 }
02920 }
02921 return $dPrice;
02922 }
02923
02924
02932 protected function _fillAmountPriceList($oAmPriceList)
02933 {
02934 $myConfig = $this->getConfig();
02935 $myUtils = oxUtils::getInstance();
02936
02937 //modifying price
02938 $oCur = $myConfig->getActShopCurrencyObject();
02939
02940 $oUser = $this->getArticleUser();
02941
02942 $oDiscountList = oxDiscountList::getInstance();
02943 $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
02944
02945 $oLowestPrice = null;
02946
02947 $dBasePrice = $this->_getGroupPrice();
02948 $oLang = oxLang::getInstance();
02949
02950 $dArticleVat = null;
02951 if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
02952 $dArticleVat = $this->getArticleVat();
02953 }
02954
02955 // trying to find lowest price value
02956 foreach ($oAmPriceList as $sId => $oItem) {
02957 $oItemPrice = oxNew( 'oxprice' );
02958 if ( $oItem->oxprice2article__oxaddabs->value) {
02959 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
02960 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
02961 $this->_applyCurrency( $oItemPrice, $oCur );
02962 } else {
02963 $oItemPrice->setPrice( $dBasePrice );
02964 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
02965 }
02966
02967 if (isset($dArticleVat)) {
02968 $this->_applyVAT($oItemPrice, $dArticleVat);
02969 }
02970
02971 if (!$oLowestPrice) {
02972 $oLowestPrice = $oItemPrice;
02973 } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
02974 $oLowestPrice = $oItemPrice;
02975 }
02976
02977 $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
02978 $oAmPriceList[$sId]->fnetprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
02979 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
02980 }
02981
02982 $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
02983 return $oAmPriceList;
02984 }
02985
02991 protected function _getVariantsIds()
02992 {
02993 $aSelect = array();
02994 $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->getId()."' " );
02995 if ( $oRs != false && $oRs->recordCount() > 0 ) {
02996 while (!$oRs->EOF) {
02997 $aSelect[] = $oRs->fields['oxid'];
02998 $oRs->moveNext();
02999 }
03000 }
03001 return $aSelect;
03002 }
03003
03009 public function getArticleVat()
03010 {
03011 if (!isset($this->_dArticleVat)) {
03012 $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03013 }
03014 return $this->_dArticleVat;
03015 }
03016
03025 protected function _applyVAT( oxPrice $oPrice, $dVat )
03026 {
03027 startProfile(__FUNCTION__);
03028 $oPrice->setVAT( $dVat );
03029 if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03030 $oPrice->setUserVat( $dVat );
03031 }
03032 stopProfile(__FUNCTION__);
03033 }
03034
03042 public function applyVats( oxPrice $oPrice )
03043 {
03044 $this->_applyVAT($oPrice,
03045 $this->getArticleVat()
03046 );
03047 }
03048
03059 protected function _applyDiscounts( $oPrice, $aDiscounts )
03060 {
03061 $oDiscountList = oxDiscountList::getInstance();
03062 $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03063 }
03064
03072 public function applyDiscountsForVariant( $oPrice )
03073 {
03074 // apply discounts
03075 if ( !$this->skipDiscounts() ) {
03076 $oDiscountList = oxDiscountList::getInstance();
03077 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03078 }
03079 }
03080
03089 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03090 {
03091 if ( !$oCur ) {
03092 $oCur = $this->getConfig()->getActShopCurrencyObject();
03093 }
03094
03095 $oPrice->multiply($oCur->rate);
03096 }
03097
03106 protected function _getIcon()
03107 {
03108 // #1479/1179M - Article icon automatic generation
03109 //if set to do not generate.
03110 $myConfig = $this->getConfig();
03111
03112 if (!$myConfig->getConfigParam( 'blAutoIcons' ) ) {
03113 if ($this->oxarticles__oxicon->value) {
03114 return basename($this->oxarticles__oxicon->value);
03115 } else {
03116 $sQ = "UPDATE oxarticles SET oxicon = 'nopic_ico.jpg' WHERE oxid = '".$this->getId()."'";
03117 oxDb::getDb()->execute($sQ);
03118 return 'nopic_ico.jpg';
03119 }
03120 }
03121
03122 // if set to generate and icon already exist
03123 if ( $this->oxarticles__oxicon->value && strpos( $this->oxarticles__oxicon->value, 'nopic_ico.jpg') === false ) {
03124 return basename($this->oxarticles__oxicon->value);
03125 }
03126
03127 //we don't have an icon yet so lets make one
03128 if ($this->oxarticles__oxthumb->value && strpos( $this->oxarticles__oxthumb->value, 'nopic.jpg') === false && function_exists('gd_info')) {
03129
03130 $sSourceFile = $this->oxarticles__oxthumb->value;
03131 $sTargetFile = str_replace('_th', '_ico', $sSourceFile);
03132
03133 if ($sSourceFile == $sTargetFile) {
03134 $sPattern = '/(\.[a-z0-9]*$)/i';
03135 $sTargetFile = preg_replace($sPattern, '_ico\\1', $sTargetFile);
03136 }
03137
03138 $sTarget = $myConfig->getAbsDynImageDir().'/icon/'. basename($sTargetFile);
03139 $sSource = $myConfig->getAbsDynImageDir().'/0/'. basename($sSourceFile);
03140
03141 if (!$myConfig->getConfigParam( 'sIconsize' ) ) {
03142 $myConfig->setConfigParam( 'sIconsize', '56*42' );
03143 }
03144
03145 $aSize = explode('*', $myConfig->getConfigParam( 'sIconsize' ) );
03146 $iX = $aSize[0];
03147 $iY = $aSize[1];
03148
03149 oxUtilspic::getInstance()->resizeImage( $sSource, $sTarget, $iX, $iY );
03150
03151 $sResult = $sTargetFile;
03152 } else {
03153 $sResult = 'nopic_ico.jpg';
03154 }
03155
03156
03157 $sIconFile = basename($sResult);
03158
03159 $oDb = oxDb::getDb();
03160
03161 $sQ = "UPDATE oxarticles SET oxicon = ".$oDb->quote($sIconFile)." WHERE oxid = '".$this->getId()."'";
03162 $oDb->execute($sQ);
03163
03164 return $sIconFile;
03165 }
03166
03167
03176 protected function _getAttribsString(&$sAttribs, &$iCnt)
03177 {
03178
03179 $oDB = oxDb::getDb(true);
03180 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03181 $sAttribs = '';
03182 $blSep = false;
03183 $rs = $oDB->execute( $sSelect);
03184 $iCnt = 0;
03185 if ($rs != false && $rs->recordCount() > 0) {
03186 while (!$rs->EOF) {
03187 if ( $blSep) {
03188 $sAttribs .= ' or ';
03189 }
03190 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03191 $blSep = true;
03192 $iCnt++;
03193 $rs->moveNext();
03194 }
03195 }
03196 }
03197
03206 protected function _getSimList($sAttribs, $iCnt)
03207 {
03208 $myConfig = $this->getConfig();
03209 $oDB = oxDb::getDb(true);
03210
03211
03212 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03213
03214 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03215 $iAttrPercent = 0.70;
03216 }
03217
03218 $iHitMin = ceil( $iCnt * $iAttrPercent );
03219
03220
03221 $aList= array();
03222 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03223 ( $sAttribs )
03224 and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03225 group by t1.oxobjectid having count(*) >= $iHitMin ";
03226
03227 $rs = $oDB->selectLimit( $sSelect, 20, 0);
03228 if ($rs != false && $rs->recordCount() > 0) {
03229 while (!$rs->EOF) {
03230 $oTemp = new stdClass();
03231 $oTemp->cnt = $rs->fields['cnt'];
03232 $oTemp->id = $rs->fields['oxobjectid'];
03233 $aList[] = $oTemp;
03234 $rs->moveNext();
03235 }
03236 }
03237 return $aList;
03238 }
03239
03248 protected function _generateSimListSearchStr($sArticleTable, $aList)
03249 {
03250 $myConfig = $this->getConfig();
03251 $sFieldList = $this->getSelectFields();
03252 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03253 $blSep = false;
03254 $iCnt = 0;
03255 $oDb = oxDb::getDb();
03256 foreach ( $aList as $oTemp) {
03257 if ( $blSep) {
03258 $sSearch .= ',';
03259 }
03260 $sSearch .= $oDb->quote($oTemp->id);
03261 $blSep = true;
03262 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03263 break;
03264 }
03265 $iCnt++;
03266 }
03267
03268
03269
03270 $sSearch .= ') ';
03271
03272
03273 $sSearch .= ' order by rand() ';
03274
03275 return $sSearch;
03276 }
03277
03286 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03287 {
03288 $sCatView = getViewName( 'oxcategories' );
03289 $sO2CView = getViewName( 'oxobject2category' );
03290
03291
03292 if ( !$blSearchPriceCat ) {
03293 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03294 {$sCatView}.oxid = oxobject2category.oxcatnid
03295 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03296 } else {
03297 $sSelect = "select {$sCatView}.* from {$sCatView} where
03298 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03299 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03300 }
03301 return $sSelect;
03302 }
03303
03309 protected function _generateSearchStrForCustomerBought()
03310 {
03311 $sArtTable = $this->_getObjectViewName( 'oxarticles' );
03312 $sOrderArtTable = getViewName( 'oxorderarticles' );
03313
03314
03315 $sIn = " '{$this->oxarticles__oxid->value}' ";
03316 if ( $this->oxarticles__oxparentid->value ) {
03317
03318
03319 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03320 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03321
03322 } else {
03323 $sParentIdForVariants = $this->getId();
03324 }
03325
03326
03327 $oDb = oxDb::getDb(true);
03328 $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03329 if ( $oRs != false && $oRs->recordCount() > 0) {
03330 while ( !$oRs->EOF ) {
03331 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03332 $oRs->moveNext();
03333 }
03334 }
03335
03336 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03337 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03338
03339
03340 $sQ = "select distinct {$sArtTable}.* from (
03341 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03342 ) as suborder
03343 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03344 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03345 where {$sArtTable}.oxid not in ( {$sIn} )
03346 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03347
03348
03349
03350
03351
03352
03353
03354
03355
03356
03357 return $sQ;
03358 }
03359
03369 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03370 {
03371 $sCategoryView = getViewName('oxcategories');
03372 $sO2CView = getViewName('oxobject2category');
03373 $sLangPrefix = (($this->getLanguage())?'_'.$this->getLanguage():'');
03374
03375 $oDb = oxDb::getDb();
03376 $sOXID = $oDb->quote($sOXID);
03377 $sCatId = $oDb->quote($sCatId);
03378
03379 if (!$dPriceFromTo) {
03380 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03381 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03382 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03383 $sSelect .= "and oxcategories.oxactive$sLangPrefix = 1 order by oxobject2category.oxtime ";
03384 } else {
03385 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03386 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03387 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03388 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03389 }
03390 return $sSelect;
03391 }
03392
03398 protected function _getAmountPriceList()
03399 {
03400 if ($this->_oAmountPriceList) {
03401 return $this->_oAmountPriceList;
03402 }
03403
03404 $myConfig = $this->getConfig();
03405
03406 $sArtID = $this->getId();
03407
03408
03409 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03410 $sArtID = $this->oxarticles__oxparentid->value;
03411 }
03412
03413
03414 $sArtID = mysql_real_escape_string($sArtID);
03415
03416
03417 $oAmPriceList = oxNew( 'oxlist');
03418 $oAmPriceList->init('oxbase', 'oxprice2article');
03419
03420 $sShopID = $myConfig->getShopID();
03421 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03422 $sShopSelect = '1';
03423 } else {
03424 $sShopSelect = " oxshopid = '$sShopID' ";
03425 }
03426
03427 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03428
03429
03430 $oBasePrice = $this->_getGroupPrice();
03431 foreach ($oAmPriceList as $oAmPrice) {
03432 if ($oAmPrice->oxprice2article__oxaddperc->value) {
03433 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03434 }
03435 }
03436
03437 $this->_oAmountPriceList = $oAmPriceList;
03438 return $oAmPriceList;
03439 }
03440
03448 protected function _isFieldEmpty($sFieldName)
03449 {
03450 $mValue = $this->$sFieldName->value;
03451
03452 if (is_null($mValue)) {
03453 return true;
03454 }
03455
03456 if ($mValue === '') {
03457 return true;
03458 }
03459
03460 $aDoubleCopyFields = array('oxarticles__oxprice',
03461 'oxarticles__oxvat');
03462
03463 if (!$mValue && in_array($sFieldName, $aDoubleCopyFields)) {
03464 return true;
03465 }
03466
03467
03468 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03469 return true;
03470 }
03471
03472 $sFieldName = strtolower($sFieldName);
03473
03474 if ($mValue == "nopic_ico.jpg" && $sFieldName == 'oxarticles__oxicon') {
03475 return true;
03476 }
03477
03478 if ($mValue == "nopic.jpg" && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom')) {
03479 return true;
03480 }
03481
03482 return false;
03483 }
03484
03492 protected function _assignParentFieldValue($sFieldName)
03493 {
03494 if (!($oParentArticle = $this->getParentArticle())) {
03495 return;
03496 }
03497
03498 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03499
03500
03501 if ( $oParentArticle->$sCopyFieldName != null ) {
03502
03503
03504 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03505 continue;
03506 }
03507
03508
03509 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03510 return;
03511 }
03512
03513
03514 if ($sFieldName == "oxicon" && !$this->_isFieldEmpty("oxarticles__oxthumb") && $this->oxarticles__oxthumb->value != $oParentArticle->oxarticles__oxthumb->value && $this->getConfig()->getConfigParam( 'blAutoIcons' ) ) {
03515 return ;
03516 }
03517
03518
03519
03520
03521 if ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03522 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03523 }
03524
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535
03536
03537
03538
03539
03540
03541
03542
03543
03544
03545
03546
03547
03548
03549
03550
03551 }
03552 }
03553
03559 public function getParentArticle()
03560 {
03561 $sParentId = $this->oxarticles__oxparentid->value;
03562 if (!$sParentId) {
03563 return null;
03564 }
03565 if (isset(self::$_aLoadedParents[$sParentId])) {
03566 return self::$_aLoadedParents[$sParentId];
03567 } else {
03568 $oParentArticle = oxNew( 'oxarticle' );
03569 $oParentArticle->_blSkipAbPrice = true;
03570 $oParentArticle->_blLoadPrice = false;
03571 $oParentArticle->_blLoadVariants = false;
03572 $oParentArticle->load( $sParentId);
03573 self::$_aLoadedParents[$sParentId] = $oParentArticle;
03574 return $oParentArticle;
03575 }
03576 }
03577
03585 protected function _getParentAricle()
03586 {
03587 return $this->getParentArticle();
03588 }
03589
03595 protected function _assignParentFieldValues()
03596 { startProfile('articleAssignParentInternal');
03597 if ( $this->oxarticles__oxparentid->value) {
03598
03599 if ( !$this->isAdmin() || ($this->_blLoadParentData && $this->isAdmin() ) ) {
03600 foreach ($this->_aFieldNames as $sFieldName => $sVal) {
03601 $this->_assignParentFieldValue($sFieldName);
03602 }
03603
03604
03605 $oParentArticle = $this->getParentArticle();
03606 if ( !$this->oxarticles__oxlongdesc->value ) {
03607 $this->oxarticles__oxlongdesc = $oParentArticle->oxarticles__oxlongdesc;
03608 }
03609
03610 }
03611 } elseif ( $this->oxarticles__oxid->value ) {
03612
03613
03614 startProfile("loadVariants");
03615 $this->_oVariantList = $this->getVariants();
03616 stopProfile("loadVariants");
03617
03618
03619
03620
03621
03622
03623 }
03624 stopProfile('articleAssignParentInternal');
03625
03626 }
03627
03633 protected function _assignNotBuyableParent()
03634 {
03635 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03636 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03637 $this->_blNotBuyableParent = true;
03638
03639 }
03640 }
03641
03647 protected function _assignPictureValues()
03648 {
03649 $myConfig = $this->getConfig();
03650 $this->oxarticles__oxicon = new oxField($this->_getIcon());
03651
03652
03653 $sNoPic = 'nopic.jpg';
03654 $sNoPicIcon = 'nopic_ico.jpg';
03655
03656 if ( isset($this->_aFieldNames["oxthumb"]) && !$this->oxarticles__oxthumb->value) {
03657 $this->oxarticles__oxthumb = new oxField($sNoPic);
03658 }
03659
03660
03661
03662
03663
03664 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03665 for ( $i=1; $i<= $iPicCount; $i++ ) {
03666 if ( isset($this->_aFieldNames["oxpic".$i]) && !$this->{'oxarticles__oxpic'.$i}->value ) {
03667 $this->{'oxarticles__oxpic'.$i} = new oxField($sNoPic);
03668 }
03669 }
03670
03671 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
03672 for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03673 if ( isset($this->_aFieldNames["oxzoom".$i]) && !$this->{'oxarticles__oxzoom'.$i}->value) {
03674 $this->{'oxarticles__oxzoom'.$i} = new oxField($sNoPic);
03675 }
03676 }
03677
03678 if ( !$this->isAdmin() ) {
03679
03680 if ( isset($this->_aFieldNames["oxthumb"])) {
03681 $this->oxarticles__oxthumb->setValue('0/'.basename($this->oxarticles__oxthumb->value));
03682 }
03683 if ( isset($this->_aFieldNames["oxicon"])) {
03684 $this->oxarticles__oxicon = new oxField('icon/'.basename($this->oxarticles__oxicon->value));
03685 }
03686
03687 $myUtilsPic = oxUtilsPic::getInstance();
03688 for ( $i=1; $i<= $iPicCount; $i++ ) {
03689 $sFieldName = 'oxarticles__oxpic'.$i;
03690 if ( isset($this->_aFieldNames["oxpic".$i])) {
03691 $sIconFieldName = 'oxarticles__oxpic'.$i.'_ico';
03692 $this->$sIconFieldName = new oxField($i.'/'.basename($myUtilsPic->iconName($this->$sFieldName->value)));
03693 $this->$sFieldName = new oxField($i.'/'.basename($this->$sFieldName->value));
03694 }
03695 }
03696 for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03697 if ( isset($this->_aFieldNames["oxzoom".$i])) {
03698 $this->{'oxarticles__oxzoom'.$i} = new oxField('z'.$i.'/'.basename($this->{'oxarticles__oxzoom'.$i}->value));
03699 }
03700 }
03701 }
03702
03703 }
03704
03710 protected function _assignStock()
03711 {
03712 $myConfig = $this->getConfig();
03713
03714
03715
03716
03717
03718 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03719 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03720 }
03721
03722 $this->_iStockStatus = 0;
03723
03724
03725 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03726
03727 $iStock = $this->oxarticles__oxstock->value;
03728
03729 if ($this->_blNotBuyableParent) {
03730 $iStock = $this->oxarticles__oxvarstock->value;
03731 }
03732
03733
03734 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03735 $this->_iStockStatus = 1;
03736 }
03737
03738
03739 if ($iStock <= 0) {
03740 $this->_iStockStatus = -1;
03741 }
03742 }
03743
03744
03745
03746 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstock->value <= 0 && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03747 $this->_blNotBuyable = true;
03748 }
03749
03750
03751 if ($this->_blNotBuyable && $this->_iVarStock) {
03752 $this->_blNotBuyable = false;
03753
03754 $this->_blNotBuyableParent = true;
03755 }
03756
03757
03758
03759
03760 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03761 $this->_blNotBuyable = true;
03762 }
03763
03764
03765 if ($this->_blNotBuyableParent && count($this->_oVariantList) == 0) {
03766 $this->_blNotBuyable = true;
03767 }
03768 }
03769
03775 protected function _assignPrices()
03776 {
03777 $myConfig = $this->getConfig();
03778
03779
03780 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03781 return;
03782 }
03783
03784
03785 $dPrice = $this->getPrice()->getBruttoPrice();
03786
03787 $oCur = $myConfig->getActShopCurrencyObject();
03788
03789 if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03790 $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03791 }
03792
03793
03794
03795 $this->_applyRangePrice();
03796 }
03797
03803 protected function _assignPersistentParam()
03804 {
03805
03806 $aPersParam = oxSession::getVar( 'persparam');
03807 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03808 $this->_aPersistParam = $aPersParam[$this->getId()];
03809 }
03810 }
03811
03817 protected function _assignDynImageDir()
03818 {
03819 $myConfig = $this->getConfig();
03820
03821 $sThisShop = $this->oxarticles__oxshopid->value;
03822
03823 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03824 $this->dabsimagedir = $myConfig->getPictureDir( false );
03825 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03826 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03827 }
03828
03834 protected function _assignComparisonListFlag()
03835 {
03836
03837
03838 $aItems = oxConfig::getParameter('aFiltcompproducts');
03839 if ( isset( $aItems[$this->getId()])) {
03840 $this->_blIsOnComparisonList = true;
03841 }
03842 }
03843
03849 protected function _assignAttributes()
03850 {
03851
03852
03853 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03854 $this->getAttributes();
03855 }
03856 }
03857
03858
03866 protected function _insert()
03867 {
03868
03869 $iInsertTime = time();
03870 $now = date('Y-m-d H:i:s', $iInsertTime);
03871 $this->oxarticles__oxinsert = new oxField( $now );
03872 $this->oxarticles__oxtimestamp = new oxField( $now );
03873 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03874 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03875 }
03876
03877 return parent::_insert();
03878 }
03879
03885 protected function _update()
03886 {
03887
03888 $this->_skipSaveFields();
03889
03890 $myConfig = $this->getConfig();
03891
03892
03893 return parent::_update();
03894 }
03895
03903 protected function _deleteRecords($sOXID)
03904 {
03905 $oDB = oxDb::getDb();
03906
03907 $sOXID = $oDB->quote($sOXID);
03908
03909
03910 $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
03911 $oDB->execute( $sDelete);
03912
03913
03914 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03915 $oDB->execute( $sDelete);
03916
03917 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03918 $oDB->execute( $sDelete);
03919
03920 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03921 $oDB->execute( $sDelete);
03922
03923 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03924 $oDB->execute( $sDelete);
03925
03926 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03927 $oDB->execute( $sDelete);
03928
03929 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03930 $oDB->execute( $sDelete);
03931
03932 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03933 $oDB->execute( $sDelete);
03934
03935
03936 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03937 $oDB->execute( $sDelete);
03938
03939 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03940 $oDB->execute( $sDelete);
03941
03942 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03943 $rs = $oDB->execute( $sDelete );
03944
03945 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03946 $rs = $oDB->execute( $sDelete );
03947
03948
03949 return $rs;
03950 }
03951
03959 protected function _deleteVariantRecords($sOXID)
03960 {
03961 $oDB = oxDb::getDb();
03962
03963 $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDB->quote($sOXID);
03964 $rs = $oDB->execute( $sVariants);
03965 if ($rs != false && $rs->recordCount() > 0) {
03966 while (!$rs->EOF) {
03967 $this->delete( $rs->fields[0]);
03968 $rs->moveNext();
03969 }
03970 }
03971 }
03972
03982 protected function _resetCacheAndArticleCount( $sOxid )
03983 {
03984 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
03985 }
03986
03992 protected function _deletePics()
03993 {
03994 $myUtilsPic = oxUtilsPic::getInstance();
03995 $myConfig = $this->getConfig();
03996
03997
03998 $blThumbDeleted = $myUtilsPic->safePictureDelete( $this->oxarticles__oxthumb->value, $myConfig->getAbsDynImageDir().'/0', 'oxarticles', 'oxthumb' );
03999
04000 if ( $blThumbDeleted ) {
04001 $myUtilsPic->safePictureDelete('icon/'.$this->oxarticles__oxicon->value, $myConfig->getAbsDynImageDir(), 'oxarticles', 'oxicon' );
04002 }
04003
04004
04005
04006
04007
04008
04009 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04010 $sAbsDynImageDir = $myConfig->getAbsDynImageDir();
04011 for ( $i = 1; $i <= $iPicCount; $i++ ) {
04012
04013 $sPicFName = $this->{'oxarticles__oxpic'.$i}->value;
04014 $myUtilsPic->safePictureDelete($sPicFName, $sAbsDynImageDir.'/'.$i, 'oxarticles', 'oxpic'.$i );
04015 }
04016
04017 $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' );
04018 for ( $i = 1; $i <= $iZoomPicCount; $i++ ) {
04019 if ( isset($this->{'oxarticles__oxzoom'.$i}) ) {
04020 $myUtilsPic->safePictureDelete($this->{'oxarticles__oxzoom'.$i}->value, $sAbsDynImageDir.'/z'.$i, 'oxarticles', 'oxzoom'.$i );
04021 }
04022 }
04023
04024 }
04025
04035 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04036 {
04037
04038 $myUtilsCount = oxUtilsCount::getInstance();
04039
04040 if ( $sVendorId ) {
04041 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04042 }
04043
04044 if ( $sManufacturerId ) {
04045 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04046 }
04047
04048
04049 $oDb = oxDb::getDb();
04050 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04051 $oRs = $oDb->execute( $sQ );
04052 if ( $oRs !== false && $oRs->recordCount() > 0) {
04053 while ( !$oRs->EOF ) {
04054 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04055 $oRs->moveNext();
04056 }
04057 }
04058 }
04059
04067 protected function _onChangeUpdateStock( $sParentID )
04068 {
04069 $oDb = oxDb::getDb();
04070 $sParentIdQuoted = $oDb->quote($sParentID);
04071 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04072 $rs = $oDb->execute($sQ);
04073 $iOldStock = $rs->fields[0];
04074 $iVendorID = $rs->fields[1];
04075 $iManufacturerID = $rs->fields[2];
04076
04077 $sQ = 'select sum(oxstock) from oxarticles where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04078 $iStock = (float) $oDb->getOne( $sQ );
04079
04080 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04081 $oDb->execute( $sQ );
04082
04083
04084
04085 if ( $iStock < 0 ) {
04086 $iStock = 0;
04087 }
04088 if ( $iOldStock < 0 ) {
04089 $iOldStock = 0;
04090 }
04091 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04092
04093
04094 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04095 }
04096 }
04097
04105 protected function _onChangeUpdateVarCount( $sParentID )
04106 {
04107 $oDb = oxDb::getDb();
04108 $sParentIdQuoted = $oDb->quote($sParentID);
04109 $sQ = 'select count(*) as varcount from oxarticles where oxparentid = '.$sParentIdQuoted;
04110 $iVarCount = (int) $oDb->getOne($sQ);
04111
04112 $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = '.$sParentIdQuoted;
04113 $oDb->execute($sQ);
04114 }
04115
04123 protected function _onChangeUpdateMinVarPrice( $sParentID )
04124 {
04125 $oDb = oxDb::getDb();
04126 $sParentIdQuoted = $oDb->quote($sParentID);
04127
04128 $sQ = 'select min(oxprice) as varminprice from oxarticles where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted;
04129
04130 if ( $this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) ) {
04131 $sQ .= ' or oxid = '.$sParentIdQuoted;
04132 } else {
04133 $sQ .= ' or (oxid = '.$sParentIdQuoted.' and oxvarcount=0)';
04134 }
04135 $sQ .= ')';
04136 $dVarMinPrice = $oDb->getOne($sQ);
04137 if ( $dVarMinPrice ) {
04138 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04139 $oDb->execute($sQ);
04140 }
04141 }
04142
04143
04149 protected function _applyRangePrice()
04150 {
04151
04152 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04153 return;
04154 }
04155
04156 $this->_blIsRangePrice = false;
04157
04158
04159 if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04160 return;
04161 }
04162
04163 $aPrices = array();
04164
04165 if (!$this->_blNotBuyableParent) {
04166 $aPrices[] = $this->getPrice()->getBruttoPrice();
04167 }
04168
04169 if (count($this->_oVariantList)) {
04170 foreach ($this->_oVariantList as $sKey => $oVariant) {
04171 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04172 }
04173 }
04174
04175
04176
04177
04178
04179
04180 if (count($aPrices)) {
04181 $dMinPrice = $aPrices[0];
04182 $dMaxPrice = $aPrices[0];
04183 foreach ($aPrices as $dPrice) {
04184 if ($dMinPrice > $dPrice) {
04185 $dMinPrice = $dPrice;
04186 }
04187
04188 if ($dMaxPrice < $dPrice) {
04189 $dMaxPrice = $dPrice;
04190 }
04191 }
04192 }
04193
04194 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04195 $this->getPrice()->setBruttoPriceMode();
04196 $this->getPrice()->setPrice($dMinPrice);
04197 }
04198
04199 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04200 $this->getPrice()->setBruttoPriceMode();
04201 $this->getPrice()->setPrice($dMinPrice);
04202 $this->_blIsRangePrice = true;
04203 }
04204
04205 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04206 $this->getPrice()->setBruttoPriceMode();
04207 $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04208 $this->_blIsRangePrice = true;
04209 $this->_calculatePrice( $this->getPrice() );
04210 }
04211 }
04212
04219 public function getProductId()
04220 {
04221 return $this->getId();
04222 }
04223
04229 public function getProductParentId()
04230 {
04231 return $this->oxarticles__oxparentid->value;
04232 }
04233
04239 public function isOrderArticle()
04240 {
04241 return false;
04242 }
04243
04249 public function isVariant()
04250 {
04251 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04252 }
04253
04259 public function isMdVariant()
04260 {
04261 $oMdVariant = oxNew( "oxVariantHandler" );
04262
04263 return $oMdVariant->isMdVariant();
04264 }
04265
04273 public function getSqlForPriceCategories($sFields = '')
04274 {
04275 if (!$sFields) {
04276 $sFields = 'oxid';
04277 }
04278 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04279 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04280 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04281 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04282 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04283 }
04284
04292 public function inPriceCategory( $sCatNid )
04293 {
04294 $oDb = oxDb::getDb();
04295
04296 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04297 $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04298 return (bool) $oDb->getOne(
04299 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04300 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04301 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04302 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04303 .")"
04304 );
04305 }
04306
04312 public function getMdVariants()
04313 {
04314 if ( $this->_oMdVariants ) {
04315 return $this->_oMdVariants;
04316 }
04317
04318 $oParentArticle = $this->getParentArticle();
04319 if ( $oParentArticle ) {
04320 $oVariants = $oParentArticle->getVariants();
04321 } else {
04322 $oVariants = $this->getVariants();
04323 }
04324
04325 $oVariantHandler = oxNew( "oxVariantHandler" );
04326 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04327
04328 return $this->_oMdVariants;
04329 }
04330
04336 public function getMdSubvariants()
04337 {
04338 return $this->getMdVariants()->getMdSubvariants();
04339 }
04340 }