00001 <?php
00002
00003
00004 define( 'OXARTICLE_LINKTYPE_CATEGORY', 0 );
00005 define( 'OXARTICLE_LINKTYPE_VENDOR', 1 );
00006 define( 'OXARTICLE_LINKTYPE_MANUFACTURER', 2 );
00007 define( 'OXARTICLE_LINKTYPE_PRICECATEGORY', 3 );
00008 define( 'OXARTICLE_LINKTYPE_TAG', 4 );
00009 define( 'OXARTICLE_LINKTYPE_RECOMM', 5 );
00010
00017 class oxArticle extends oxI18n implements oxIArticle, oxIUrl
00018 {
00024 protected $_sCoreTbl = 'oxarticles';
00025
00031 protected $_sClassName = 'oxarticle';
00032
00038 protected $_blUseLazyLoading = true;
00039
00045 protected $_sItemKey;
00046
00052 protected $_blCalcPrice = true;
00053
00058 protected $_oPrice = null;
00059
00065 protected $_dArticleVat = null;
00066
00072 protected $_aPersistParam = null;
00073
00079 protected $_blNotBuyable = false;
00080
00087 protected $_blLoadVariants = true;
00088
00094 protected $_aVariants = null;
00095
00101 protected $_aVariantsWithNotOrderables = null;
00102
00111 protected $_blNotBuyableParent = false;
00112
00117 protected $_blHasVariants = false;
00118
00122 protected $_blHasMdVariants = false;
00123
00127 protected $_iVarStock = 0;
00128
00133 protected $_oVariantList = array();
00134
00139 protected $_blIsOnComparisonList = false;
00140
00145 protected $_oUser = null;
00146
00152 protected $_blLoadPrice = true;
00153
00157 protected $_blSkipAbPrice = false;
00158
00165 protected $_fPricePerUnit = null;
00166
00170 protected $_blLoadParentData = false;
00171
00175 protected $_blSkipAssign = false;
00176
00182 protected $_blSkipDiscounts = null;
00183
00188 protected $_oAttributeList = null;
00189
00190
00196 protected $_blIsRangePrice = false;
00197
00203 protected $_aMediaUrls = null;
00204
00210 static protected $_aLoadedParents;
00211
00217 static protected $_aSelList;
00218
00224 protected $_aDispSelList;
00225
00231 protected $_blIsSeoObject = true;
00232
00238 protected $_oAmountPriceList = null;
00239
00248 protected $_iLinkType = 0;
00249
00255 protected $_aStdUrls = array();
00256
00262 protected $_aSeoUrls = array();
00263
00269 protected $_aSeoAddParams = array();
00270
00276 protected $_aStdAddParams = array();
00277
00283 protected $_sDynImageDir = null;
00284
00290 protected $_sMoreDetailLink = null;
00291
00297 protected $_sToBasketLink = null;
00298
00304 protected $_iStockStatus = null;
00305
00311 protected $_oTPrice = null;
00312
00318 protected $_oAmountPriceInfo = null;
00319
00325 protected $_dAmountPrice = null;
00326
00332 protected static $_aArticleManufacturers = array();
00333
00339 protected static $_aArticleVendors = array();
00340
00346 protected static $_aArticleCats = array();
00347
00353 protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00354 'oxarticles__oxtimestamp',
00355 'oxarticles__oxnid',
00356 'oxarticles__oxid',
00357 'oxarticles__oxparentid');
00358
00364 protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00365 'oxarticles__oxfreeshipping',
00366 'oxarticles__oxremindactive');
00367
00373 protected $_oMdVariants = null;
00374
00383 public function __construct($aParams = null)
00384 {
00385 if ( $aParams && is_array($aParams)) {
00386 foreach ( $aParams as $sParam => $mValue) {
00387 $this->$sParam = $mValue;
00388 }
00389 }
00390 parent::__construct();
00391 $this->init( 'oxarticles' );
00392
00393 $this->_blIsRangePrice = false;
00394 }
00395
00403 public function __isset( $sName )
00404 {
00405 if ( $sName == 'oxarticles__oxlongdesc' ) {
00406
00407 $this->getArticleLongDesc();
00408 return true;
00409 }
00410 return isset( $this->$sName );
00411 }
00412
00421 public function __get($sName)
00422 {
00423 $myUtils = oxUtils::getInstance();
00424 switch ($sName) {
00425
00426
00427
00428
00429 case 'netprice':
00430 case 'netPrice':
00431 $mVal = $myUtils->fRound($this->getPrice()->getNettoPrice());
00432 break;
00433 case 'brutPrice':
00434 return $myUtils->fRound($this->getPrice()->getBruttoPrice());
00435 break;
00436 case 'vatPercent':
00437 return $this->getPrice()->getVAT();
00438 break;
00439 case 'vat':
00440 return $this->getPrice()->getVATValue();
00441 break;
00442 case 'fnetprice':
00443 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($this->getPrice()->getNettoPrice()));
00444 break;
00445 case 'fprice':
00446 return $this->getFPrice();
00447 break;
00448
00449
00450 case 'dtprice':
00451 if ( $oPrice = $this->getTPrice() ) {
00452 return $myUtils->fRound($oPrice->getBruttoPrice());
00453 break;
00454 } else {
00455 return null;
00456 break;
00457 }
00458 case 'tvat':
00459 if ( $oPrice = $this->getTPrice() ) {
00460 return $oPrice->getVATValue();
00461 break;
00462 } else {
00463 return null;
00464 break;
00465 }
00466 case 'ftprice':
00467 if ( $oPrice = $this->getTPrice() ) {
00468 return oxLang::getInstance()->formatCurrency( $myUtils->fRound($oPrice->getBruttoPrice()) );
00469 break;
00470 } else {
00471 return null;
00472 break;
00473 }
00474 case 'oxarticles__oxlongdesc':
00475 return $this->getArticleLongDesc($this->getId());
00476 break;
00477 case 'foxdelivery':
00478 return $this->getDeliveryDate();
00479 break;
00480 case 'sItemKey':
00481 return $this->getItemKey();
00482 break;
00483 case 'selectlist':
00484 return $this->_aDispSelList = $this->getDispSelList();
00485 break;
00486 case 'blNotBuyable':
00487 return $this->isNotBuyable();
00488 break;
00489 case 'blNotBuyableParent':
00490 return $this->isParentNotBuyable();
00491 break;
00492 case 'blIsOnComparisonList':
00493 return $this->isOnComparisonList();
00494 break;
00495 case 'oVariantlist' :
00496 return $this->_oVariantList;
00497 break;
00498 case 'fPricePerUnit' :
00499 return $this->getPricePerUnit();
00500 break;
00501 case 'dimagedir' :
00502 return $this->_sDynImageDir = $this->getDynImageDir();
00503 break;
00504 case 'oxmoredetaillink' :
00505 return $this->_sMoreDetailLink = $this->getMoreDetailLink();
00506 break;
00507 case 'amountpricelist' :
00508 return $this->loadAmountPriceInfo();
00509 break;
00510 case 'stockstatus' :
00511 return $this->getStockStatus();
00512 break;
00513 case 'tobasketlink' :
00514 return $this->getToBasketLink();
00515 break;
00516 case 'oxdetaillink' :
00517 return $this->getLink();
00518 break;
00519 case 'aSelectlist' :
00520 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00521 return $this->aSelectlist = $this->getSelectLists();
00522 }
00523 return;
00524 break;
00525
00526
00527 }
00528
00529 $this->$sName = parent::__get($sName);
00530 if ( $this->$sName ) {
00531 $this->_assignParentFieldValue($sName);
00532 }
00533
00534
00535 if ($sName == "oxarticles__oxthumb" || $sName == "oxarticles__oxicon" || (strpos($sName, "oxarticles__oxpic") === 0 && $sName != "oxarticles__oxpicsgenerated") || strpos($sName, "oxarticles__oxzoom") === 0) {
00536 $this->_assignPictureValues( $sName );
00537 return $this->$sName;
00538 }
00539
00540 return $this->$sName;
00541 }
00542
00550 public function setId( $sId = null )
00551 {
00552 $sId = parent::setId( $sId );
00553
00554
00555 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00556
00557 return $sId;
00558 }
00559
00567 public function getTableNameForActiveSnippet( $blForceCoreTable = false )
00568 {
00569 $sTable = $this->getCoreTableName();
00570
00571 return $sTable;
00572 }
00573
00583 public function getActiveCheckQuery( $blForceCoreTable = false )
00584 {
00585 $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00586
00587
00588 $sQ = " $sTable.oxactive = 1 ";
00589
00590
00591 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00592 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00593 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00594 }
00595
00596 return $sQ;
00597 }
00598
00612 public function getStockCheckQuery( $blForceCoreTable = false )
00613 {
00614 $myConfig = $this->getConfig();
00615 $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00616
00617 $sQ = "";
00618
00619
00620 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00621 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00622
00623 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00624 $sTimeCheckQ = '';
00625 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00626 $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00627 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00628 }
00629 $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 ) ) ";
00630 }
00631 }
00632
00633 return $sQ;
00634 }
00635
00647 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = false )
00648 {
00649 $sTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
00650 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00651
00652
00653 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00654 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00655 if ( $blRemoveNotOrderables ) {
00656 $sQ .= " and $sTable.oxstockflag != 3 ";
00657 }
00658 $sQ .= " ) ) ";
00659 }
00660
00661 return $sQ;
00662 }
00663
00671 public function getSqlActiveSnippet( $blForceCoreTable = false )
00672 {
00673 $myConfig = $this->getConfig();
00674
00675
00676 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00677
00678
00679 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00680
00681
00682 return "( $sQ ) ";
00683 }
00684
00692 public function setSkipAssign($blSkipAssign)
00693 {
00694 $this->_blSkipAssign = $blSkipAssign;
00695 }
00696
00704 public function disablePriceLoad( $oArticle )
00705 {
00706 $oArticle->_blLoadPrice = false;
00707 }
00708
00714 public function getItemKey()
00715 {
00716 return $this->_sItemKey;
00717 }
00718
00726 public function setItemKey($sItemKey)
00727 {
00728 $this->_sItemKey = $sItemKey;
00729 }
00730
00738 public function setNoVariantLoading( $blLoadVariants )
00739 {
00740 $this->_blLoadVariants = !$blLoadVariants;
00741 }
00742
00748 public function isBuyable()
00749 {
00750 if ($this->_blNotBuyableParent) {
00751 return false;
00752 }
00753
00754 return !$this->_blNotBuyable;
00755 }
00756
00762 public function getPersParams()
00763 {
00764 return $this->_aPersistParam;
00765 }
00766
00772 public function isOnComparisonList()
00773 {
00774 return $this->_blIsOnComparisonList;
00775 }
00776
00784 public function setOnComparisonList( $blOnList )
00785 {
00786 $this->_blIsOnComparisonList = $blOnList;
00787 }
00788
00796 public function setLoadParentData($blLoadParentData)
00797 {
00798 $this->_blLoadParentData = $blLoadParentData;
00799 }
00800
00808 public function setSkipAbPrice( $blSkipAbPrice = null )
00809 {
00810 $this->_blSkipAbPrice = $blSkipAbPrice;
00811 }
00812
00818 public function getSearchableFields()
00819 {
00820 $aSkipFields = array("oxblfixedprice", "oxicon", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00821 $aFields = array_diff( array_keys($this->_aFieldNames), $aSkipFields );
00822
00823 return $aFields;
00824 }
00825
00826
00834 public function isMultilingualField($sFieldName)
00835 {
00836 switch ($sFieldName) {
00837 case "oxlongdesc":
00838 case "oxtags":
00839 return true;
00840 }
00841
00842 return parent::isMultilingualField($sFieldName);
00843 }
00844
00850 public function isVisible()
00851 {
00852
00853
00854 $myConfig = $this->getConfig();
00855 if ( ( $sPrevId = oxConfig::getParameter( 'preview' ) ) &&
00856 ( $sAdminSid = oxUtilsServer::getInstance()->getOxCookie( 'admin_sid' ) ) ) {
00857
00858 $oDb = oxDb::getDb();
00859 $sPrevId = $oDb->quote( $sPrevId );
00860 $sAdminSid = $oDb->quote( $sAdminSid );
00861 $sTable = getViewName( 'oxuser' );
00862
00863 return (bool) $oDb->getOne( "select 1 from $sTable where MD5( CONCAT( {$sAdminSid}, {$sTable}.oxid, {$sTable}.oxpassword, {$sTable}.oxrights ) ) = $sPrevId" );
00864 }
00865
00866
00867 $sNow = date('Y-m-d H:i:s');
00868 if ( !$this->oxarticles__oxactive->value &&
00869 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00870 $this->oxarticles__oxactiveto->value < $sNow
00871 )) {
00872 return false;
00873 }
00874
00875
00876 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
00877 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
00878 return false;
00879 }
00880
00881 return true;
00882 }
00883
00892 public function assign( $aRecord)
00893 {
00894 startProfile('articleAssign');
00895
00896
00897
00898 parent::assign( $aRecord);
00899
00900 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00901
00902
00903 if ($this->_blSkipAssign) {
00904 return;
00905 }
00906
00907 $this->_assignParentFieldValues();
00908 $this->_assignNotBuyableParent();
00909
00910 $this->_assignAllPictureValues();
00911
00912 $this->_assignStock();
00913 startProfile('articleAssignPrices');
00914 $this->_assignPrices();
00915 stopProfile('articleAssignPrices');
00916 $this->_assignPersistentParam();
00917 $this->_assignDynImageDir();
00918 $this->_assignComparisonListFlag();
00919 $this->_assignAttributes();
00920
00921
00922
00923
00924 stopProfile('articleAssign');
00925 }
00926
00937 public function load( $oxID)
00938 {
00939
00940 $this->_blNotBuyableParent = false;
00941
00942 $blRet = parent::load( $oxID);
00943
00944
00945 $this->oxarticles__oxinsert = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxinsert->value));
00946 $this->oxarticles__oxtimestamp = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxtimestamp->value));
00947
00948 return $blRet;
00949 }
00950
00958 public function addToRatingAverage( $iRating)
00959 {
00960 $dOldRating = $this->oxarticles__oxrating->value;
00961 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00962 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00963 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00964 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00965 $dRatingCnt = (int) ($dOldCnt + 1);
00966
00967 oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->getId().'" ' );
00968 }
00969
00975 public function getArticleRatingAverage()
00976 {
00977 return round( $this->oxarticles__oxrating->value, 1);
00978 }
00979
00985 public function getReviews()
00986 {
00987 $myConfig = $this->getConfig();
00988
00989 $aIds = array($this->getId());
00990
00991 if ( $this->oxarticles__oxparentid->value ) {
00992 $aIds[] = $this->oxarticles__oxparentid->value;
00993 }
00994
00995
00996 if ( $myConfig->getConfigParam( 'blShowVariantReviews' ) ) {
00997 $aAdd = $this->_getVariantsIds();
00998 if (is_array($aAdd)) {
00999 $aIds = array_merge($aIds, $aAdd);
01000 }
01001 }
01002
01003 $oReview = oxNew('oxreview');
01004 $oRevs = $oReview->loadList('oxarticle', $aIds);
01005
01006
01007 if ( $oRevs->count() < 1 ) {
01008 return null;
01009 }
01010
01011 return $oRevs;
01012 }
01013
01019 public function getCrossSelling()
01020 {
01021 $oCrosslist = oxNew( "oxarticlelist");
01022 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
01023 if ( $oCrosslist->count() ) {
01024 return $oCrosslist;
01025 }
01026 }
01027
01033 public function getAccessoires()
01034 {
01035 $myConfig = $this->getConfig();
01036
01037
01038 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01039 return;
01040 }
01041
01042 $oAcclist = oxNew( "oxarticlelist");
01043 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01044 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01045
01046 if ( $oAcclist->count()) {
01047 return $oAcclist;
01048 }
01049 }
01050
01056 public function getSimilarProducts()
01057 {
01058
01059 $myConfig = $this->getConfig();
01060 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01061 return;
01062 }
01063
01064 $sArticleTable = $this->_getObjectViewName('oxarticles');
01065
01066 $sAttribs = '';
01067 $iCnt = 0;
01068 $this->_getAttribsString($sAttribs, $iCnt);
01069
01070 if ( !$sAttribs) {
01071 return null;
01072 }
01073
01074 $aList = $this->_getSimList($sAttribs, $iCnt);
01075
01076 if ( count( $aList ) ) {
01077 uasort( $aList, 'cmpart');
01078
01079 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01080
01081 $oSimilarlist = oxNew( 'oxarticlelist' );
01082 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01083 $oSimilarlist->selectString( $sSearch);
01084
01085 return $oSimilarlist;
01086 }
01087 }
01088
01094 public function getCustomerAlsoBoughtThisProducts()
01095 {
01096
01097 $myConfig = $this->getConfig();
01098 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01099 return;
01100 }
01101
01102
01103 $sQ = $this->_generateSearchStrForCustomerBought();
01104
01105 $oArticles = oxNew( 'oxarticlelist' );
01106 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01107 $oArticles->selectString( $sQ );
01108 if ( $oArticles->count() ) {
01109 return $oArticles;
01110 }
01111 }
01112
01119 public function loadAmountPriceInfo()
01120 {
01121 $myConfig = $this->getConfig();
01122 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice) {
01123 return array();
01124 }
01125
01126 if ( $this->_oAmountPriceInfo === null ) {
01127 $this->_oAmountPriceInfo = array();
01128 if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01129 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01130
01131 }
01132 }
01133 return $this->_oAmountPriceInfo;
01134 }
01135
01143 public function getSelectLists($sKeyPrefix = null)
01144 {
01145
01146
01147 $sKey = $this->getId();
01148 if ( isset( $sKeyPrefix ) ) {
01149 $sKey = $sKeyPrefix.'__'.$this->getId();
01150 }
01151
01152 if ( !isset( self::$_aSelList[$sKey] ) ) {
01153
01154 $oLists = oxNew( 'oxlist' );
01155 $oLists->init('oxselectlist');
01156 $sSLViewName = getViewName('oxselectlist');
01157 $sSelect = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01158 $sSelect .= 'where oxobject2selectlist.oxobjectid=\''.$this->getId().'\' ';
01159 //sorting
01160 $sSelect .= ' order by oxobject2selectlist.oxsort';
01161
01162 $oLists->selectString( $sSelect );
01163
01164 //#1104S if this is variant ant it has no selectlists, trying with parent
01165 if ( $this->oxarticles__oxparentid->value && $oLists->count() == 0 ) {
01166 $sParentQuoted = oxDb::getDb()->quote($this->oxarticles__oxparentid->value);
01167 //#1496C - select fixed ( * => $sSLViewName.*)
01168 $sSelect = "select $sSLViewName.* from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
01169 $sSelect .= "where oxobject2selectlist.oxobjectid=$sParentQuoted ";
01170 //sorting
01171 $sSelect .= ' order by oxobject2selectlist.oxsort';
01172 $oLists->selectString( $sSelect);
01173 }
01174
01175 $dVat = 0;
01176 if ( $this->getPrice() != null ) {
01177 $dVat = $this->getPrice()->getVat();
01178 }
01179
01180 $iCnt = 0;
01181 self::$_aSelList[$sKey] = array();
01182 foreach ( $oLists as $oSelectlist ) {
01183 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01184 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01185 $iCnt++;
01186 }
01187 }
01188 return self::$_aSelList[$sKey];
01189 }
01190
01198 protected function _hasAnyVariant( $blForceCoreTable = false )
01199 {
01200 $sArticleTable = $this->getTableNameForActiveSnippet( $blForceCoreTable );
01201 return (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='".$this->getId()."'" );
01202 }
01203
01209 public function hasMdVariants()
01210 {
01211 return $this->_blHasMdVariants;
01212 }
01213
01222 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = false )
01223 {
01224 if ( $blRemoveNotOrderables && $this->_aVariants ) {
01225 return $this->_aVariants;
01226 } elseif ( !$blRemoveNotOrderables && $this->_aVariantsWithNotOrderables ) {
01227 return $this->_aVariantsWithNotOrderables;
01228 }
01229
01230 $myConfig = $this->getConfig();
01231 if ( !$this->_blLoadVariants ||
01232 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01233 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01234 return array();
01235 }
01236
01237 //do not load me as a parent later
01238 self::$_aLoadedParents[$this->getId()] = $this;
01239
01240 //load simple variants for lists
01241 if ( $this->_isInList() ) {
01242 $oVariants = oxNew( 'oxsimplevariantlist' );
01243 $oVariants->setParent( $this );
01244 } else {
01245 //loading variants
01246 $oVariants = oxNew( 'oxarticlelist' );
01247 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01248 }
01249
01250 $this->_iVarStock = $this->oxarticles__oxvarstock->value;
01251 if ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) {
01252
01253 startProfile("selectVariants");
01254 $blUseCoreTable = $blForceCoreTable;
01255 $oBaseObject = $oVariants->getBaseObject();
01256 $sArticleTable = $this->getTableNameForActiveSnippet( $blUseCoreTable );
01257
01258 $sSelect = "select ".$oBaseObject->getSelectFields()." from $sArticleTable where " .
01259 $this->getActiveCheckQuery( $blUseCoreTable ) .
01260 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01261 " order by $sArticleTable.oxsort";
01262
01263 $oVariants->selectString( $sSelect );
01264
01265 //if this is multidimensional variants, make additional processing
01266 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01267 $oMdVariants = oxNew( "oxVariantHandler" );
01268 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01269 }
01270 stopProfile("selectVariants");
01271 }
01272
01273 //if we have variants then depending on config option the parent may be non buyable
01274 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01275 $this->_blNotBuyableParent = true;
01276 }
01277
01278 //if we have variants, but all variants are incative means article may be non buyable (depends on config option)
01279 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $oVariants->count() == 0 && $this->_blHasVariants ) {
01280 $this->_blNotBuyable = true;
01281 }
01282
01283 // cache
01284 if ( $blRemoveNotOrderables ) {
01285 $this->_aVariants = $oVariants;
01286 } else {
01287 $this->_aVariantsWithNotOrderables = $oVariants;
01288 }
01289
01290 return $oVariants;
01291 }
01292
01298 public function getSimpleVariants()
01299 {
01300 if ( $this->oxarticles__oxvarcount->value) {
01301 return $this->getVariants();
01302 }
01303 }
01304
01313 public function getAdminVariants( $sLanguage = null )
01314 {
01315 $myConfig = $this->getConfig();
01316
01317 $oVariants = oxNew( 'oxarticlelist');
01318
01319 if ( is_null($sLanguage) ) {
01320 $oVariants->getBaseObject()->setLanguage(oxLang::getInstance()->getBaseLanguage());
01321 } else {
01322 $oVariants->getBaseObject()->setLanguage($sLanguage);
01323 }
01324
01325 $sSql = 'select * from oxarticles where oxparentid = "'.$this->getId().'" order by oxsort ';
01326
01327 $oVariants->selectString( $sSql);
01328
01329 //if we have variants then depending on config option the parent may be non buyable
01330 if (!$myConfig->getConfigParam( 'blVariantParentBuyable' ) && ($oVariants->count() > 0)) {
01331 //$this->blNotBuyable = true;
01332 $this->_blNotBuyableParent = true;
01333 }
01334
01335 return $oVariants;
01336 }
01337
01345 public function getCategory()
01346 {
01347 startPRofile( 'getCategory' );
01348
01349 $oCategory = oxNew( 'oxcategory' );
01350 $oCategory->setLanguage( $this->getLanguage() );
01351
01352 // variant handling
01353 $sOXID = $this->getId();
01354 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01355 $sOXID = $this->oxarticles__oxparentid->value;
01356 }
01357
01358 $oStr = getStr();
01359 $sWhere = $oCategory->getSqlActiveSnippet();
01360 $sSelect = $this->_generateSearchStr( $sOXID );
01361 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01362
01363 // category not found ?
01364 if ( !$oCategory->assignRecord( $sSelect ) ) {
01365
01366 $sSelect = $this->_generateSearchStr( $sOXID, true );
01367 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01368
01369 // looking for price category
01370 if ( !$oCategory->assignRecord( $sSelect ) ) {
01371 $oCategory = null;
01372 }
01373 }
01374
01375 stopPRofile( 'getCategory' );
01376 return $oCategory;
01377 }
01378
01387 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01388 {
01389 $myConfig = $this->getConfig();
01390 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01391 return self::$_aArticleCats[$this->getId()];
01392 }
01393
01394 // variant handling
01395 $sOXID = $this->getId();
01396 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01397 $sOXID = $this->oxarticles__oxparentid->value;
01398 }
01399
01400 // we do not use lists here as we dont need this overhead right now
01401 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01402 $oDB = oxDb::getDb(true);
01403 $rs = $oDB->execute( $sSql );
01404
01405
01406 $aRet = array();
01407
01408 if ($rs != false && $rs->recordCount() > 0) {
01409 while (!$rs->EOF) {
01410 $aRet[] = $rs->fields['oxcatnid'];
01411 $rs->moveNext();
01412 }
01413 }
01414
01415 // adding price categories if such exists
01416 $sSql = $this->getSqlForPriceCategories();
01417
01418 $oDB = oxDb::getDb( true );
01419 $rs = $oDB->execute( $sSql );
01420
01421 if ($rs != false && $rs->recordCount() > 0) {
01422 while (!$rs->EOF) {
01423
01424 if ( is_array( $rs->fields ) ) {
01425 $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01426 }
01427
01428
01429 if ( !$aRet[$rs->fields['oxid']] ) {
01430 $aRet[] = $rs->fields['oxid'];
01431 }
01432 $rs->moveNext();
01433 }
01434 }
01435
01436 return self::$_aArticleCats[$this->getId()] = $aRet;
01437 }
01438
01447 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01448 {
01449 $sO2CView = $this->_getObjectViewName('oxobject2category');
01450 $sCatView = $this->_getObjectViewName('oxcategories');
01451 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01452 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 ';
01453 if ( $blActCats ) {
01454 $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 ";
01455 }
01456 $sSelect .= 'order by oxobject2category.oxtime ';
01457 return $sSelect;
01458 }
01459
01469 public function getVendor( $blShopCheck = true )
01470 {
01471 if ( ( $sVendorId = $this->getVendorId() ) ) {
01472 $oVendor = oxNew( 'oxvendor' );
01473 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01474 $oVendor = oxNew( 'oxi18n' );
01475 $oVendor->init('oxvendor');
01476 $oVendor->setReadOnly( true );
01477 $sVendorId = $this->oxarticles__oxvendorid->value;
01478 }
01479 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01480 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
01481 $oVendor->setReadOnly( true );
01482 }
01483 return $oVendor;
01484 }
01485 return null;
01486 }
01487
01495 public function getVendorId( $blForceReload = false )
01496 {
01497 $sVendorId = false;
01498 if ( $this->oxarticles__oxvendorid->value ) {
01499 if ( !$blForceReload && isset( self::$_aArticleVendors[$this->getId()] ) ) {
01500 return self::$_aArticleVendors[$this->getId()];
01501 }
01502 $oDb = oxDb::getDb();
01503 $sVendorIdQuoted = $oDb->quote($this->oxarticles__oxvendorid->value);
01504 $sQ = "select oxid from ".getViewName('oxvendor')." where oxid=$sVendorIdQuoted";
01505 self::$_aArticleVendors[$this->getId()] = $sVendorId = $oDb->getOne( $sQ );
01506 }
01507 return $sVendorId;
01508 }
01509
01517 public function getManufacturerId( $blForceReload = false )
01518 {
01519 $sManufacturerId = false;
01520 if ( $this->oxarticles__oxmanufacturerid->value ) {
01521 if ( !$blForceReload && isset( self::$_aArticleManufacturers[$this->getId()])) {
01522 return self::$_aArticleManufacturers[$this->getId()];
01523 }
01524 $oDb = oxDb::getDb();
01525 $sQ = "select oxid from ".getViewName('oxmanufacturers')." where oxid=".$oDb->quote($this->oxarticles__oxmanufacturerid->value);
01526 self::$_aArticleManufacturers[$this->getId()] = $sManufacturerId = $oDb->getOne( $sQ );
01527 }
01528 return $sManufacturerId;
01529 }
01530
01540 public function getManufacturer( $blShopCheck = true )
01541 {
01542 $oManufacturer = oxNew( 'oxmanufacturer' );;
01543 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01544 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01545 $oManufacturer->setReadOnly( true );
01546 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01547 }
01548
01549 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01550 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01551 $oManufacturer->setReadOnly( true );
01552 }
01553 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01554 } else {
01555 $oManufacturer = null;
01556 }
01557
01558 return $oManufacturer;
01559 }
01560
01568 public function inCategory( $sCatNid)
01569 {
01570 return in_array( $sCatNid, $this->getCategoryIds());
01571 }
01572
01581 public function isAssignedToCategory( $sCatId )
01582 {
01583 // variant handling
01584 $sOXID = $this->getId();
01585 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01586 $sOXID = $this->oxarticles__oxparentid->value;
01587 }
01588
01589 $oDB = oxDb::getDb();
01590 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01591 $sOXID = $oDB->getOne( $sSelect);
01592 // article is assigned to passed category!
01593 if ( isset( $sOXID) && $sOXID) {
01594 return true;
01595 }
01596
01597 // maybe this category is price category ?
01598 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01599 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01600 if ( $dPriceFromTo > 0) {
01601 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01602 $sOXID = $oDB->getOne( $sSelect);
01603 // article is assigned to passed category!
01604 if ( isset( $sOXID) && $sOXID) {
01605 return true;
01606 }
01607 }
01608 }
01609 return false;
01610 }
01611
01617 public function getTPrice()
01618 {
01619 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01620 return;
01621 }
01622 // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01623 if ( $this->_oTPrice !== null ) {
01624 return $this->_oTPrice;
01625 }
01626
01627 $this->_oTPrice = oxNew( 'oxPrice' );
01628 $this->_oTPrice->setPrice( $this->oxarticles__oxtprice->value );
01629
01630 $this->_applyVat( $this->_oTPrice, $this->getArticleVat() );
01631 $this->_applyCurrency( $this->_oTPrice );
01632
01633 return $this->_oTPrice;
01634 }
01635
01641 public function skipDiscounts()
01642 {
01643 // allready loaded skip discounts config
01644 if ( $this->_blSkipDiscounts !== null )
01645 return $this->_blSkipDiscounts;
01646
01647 if ( $this->oxarticles__oxskipdiscounts->value )
01648 return true;
01649
01650 $sO2CView = getViewName('oxobject2category');
01651 $sSelect = "select 1 from $sO2CView as oxobject2category left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01652 $sSelect .= 'where oxobject2category.oxobjectid="'.$this->getId().'" and oxcategories.oxactive'.(($this->getLanguage())?'_'.$this->getLanguage():'').' = 1 and oxcategories.oxskipdiscounts = "1" ';
01653
01654 return $this->_blSkipDiscounts = ( oxDb::getDb()->getOne($sSelect) == 1 );
01655 }
01656
01664 public function setPrice(oxPrice $oPrice)
01665 {
01666 $this->_oPrice = $oPrice;
01667 }
01668
01677 public function getBasePrice( $dAmount = 1 )
01678 {
01679 // override this function if you want e.g. different prices
01680 // for diff. usergroups.
01681
01682 // Performance
01683 $myConfig = $this->getConfig();
01684 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01685 return;
01686
01687 // GroupPrice or DB price ajusted by AmountPrice
01688 $dPrice = $this->_getAmountPrice( $dAmount );
01689
01690
01691 return $dPrice;
01692 }
01693
01701 public function getPrice( $dAmount = 1 )
01702 {
01703 $myConfig = $this->getConfig();
01704 // Performance
01705 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01706 return;
01707 }
01708
01709 // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
01710 if ( $dAmount != 1 || $this->_oPrice === null ) {
01711 $oPrice = oxNew( 'oxPrice' );
01712
01713 // get base
01714 $oPrice->setPrice( $this->getBasePrice( $dAmount ) );
01715
01716 // price handling
01717 if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01718 return $this->_oPrice = $oPrice;
01719 }
01720
01721 $this->_calculatePrice( $oPrice );
01722 if ( $dAmount != 1 ) {
01723 return $oPrice;
01724 }
01725
01726 $this->_oPrice = $oPrice;
01727 }
01728 return $this->_oPrice;
01729 }
01730
01738 protected function _calculatePrice( $oPrice )
01739 {
01740 // apply VAT only if configuration requires it
01741 if ( !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01742 $this->_applyVAT( $oPrice, $this->getArticleVat() );
01743 }
01744
01745 // apply currency
01746 $this->_applyCurrency( $oPrice );
01747 // apply discounts
01748 if ( !$this->skipDiscounts() ) {
01749 $oDiscountList = oxDiscountList::getInstance();
01750 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts($this, $this->getArticleUser() ) );
01751 }
01752
01753 return $oPrice;
01754 }
01755
01763 public function setArticleUser($oUser)
01764 {
01765 $this->_oUser = $oUser;
01766 }
01767
01773 public function getArticleUser()
01774 {
01775 if ($this->_oUser) {
01776 return $this->_oUser;
01777 }
01778 return $this->getUser();
01779 }
01780
01790 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01791 {
01792 $oUser = $oBasket->getBasketUser();
01793 $this->setArticleUser($oUser);
01794
01795 $oBasketPrice = oxNew( 'oxPrice' );
01796
01797 // get base price
01798 $dBasePrice = $this->getBasePrice( $dAmount );
01799
01800 // applying select list price
01801 $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01802
01803 // setting price
01804 $oBasketPrice->setPrice( $dBasePrice );
01805
01806 // apply VAT
01807 $this->_applyVat( $oBasketPrice, oxVatSelector::getInstance()->getBasketItemVat( $this, $oBasket ) );
01808
01809 // apply currency
01810 $this->_applyCurrency( $oBasketPrice );
01811
01812 // apply discounts
01813 if ( !$this->skipDiscounts() ) {
01814 // apply general discounts
01815 $oDiscountList = oxDiscountList::getInstance();
01816 $oDiscountList->applyDiscounts( $oBasketPrice, $oDiscountList->getArticleDiscounts( $this, $oUser ) );
01817 }
01818
01819 // returning final price object
01820 return $oBasketPrice;
01821 }
01822
01835 public function applyBasketDiscounts(oxPrice $oPrice, $aDiscounts, $dAmount = 1)
01836 {
01837 $oDiscountList = oxDiscountList::getInstance();
01838 return $oDiscountList->applyBasketDiscounts( $oPrice, $aDiscounts, $dAmount );
01839 }
01840
01849 public function delete( $sOXID = null )
01850 {
01851 if ( !$sOXID ) {
01852 $sOXID = $this->getId();
01853 }
01854 if ( !$sOXID ) {
01855 return false;
01856 }
01857
01858
01859 $this->load( $sOXID );
01860 $this->_deletePics();
01861 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01862 $this->_deleteVariantRecords( $sOXID );
01863 $rs = $this->_deleteRecords( $sOXID );
01864
01865 oxSeoEncoderArticle::getInstance()->onDeleteArticle($this);
01866
01867 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01868
01869 return $rs->EOF;
01870 }
01871
01880 public function updateSoldAmount( $dAmount = 0 )
01881 {
01882 if ( !$dAmount ) {
01883 return;
01884 }
01885
01886 $this->beforeUpdate();
01887
01888 // article is not variant - should be updated current amount
01889 if ( !$this->oxarticles__oxparentid->value ) {
01890 //updating by SQL query, due to wrong behaviour if saving article using not admin mode
01891 $dAmount = (double) $dAmount;
01892 $oDb = oxDb::getDb();
01893 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
01894 } elseif ( $this->oxarticles__oxparentid->value) {
01895 // article is variant - should be updated this article parent amount
01896 $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
01897 $oUpdateArticle->updateSoldAmount( $dAmount );
01898 }
01899
01900 $this->onChange( ACTION_UPDATE );
01901
01902 return $rs;
01903 }
01904
01910 public function disableReminder()
01911 {
01912 $oDB = oxDb::getDb(true);
01913 return $oDB->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDB->quote($this->oxarticles__oxid->value));
01914 }
01915
01922 public function save()
01923 {
01924 $myConfig = $this->getConfig();
01925
01926 $this->oxarticles__oxthumb = new oxField(basename($this->oxarticles__oxthumb->value), oxField::T_RAW);
01927 $this->oxarticles__oxicon = new oxField(basename($this->oxarticles__oxicon->value), oxField::T_RAW);
01928 $iPicCount = $myConfig->getConfigParam( 'iPicCount');
01929 for ($i=1; $i <= $iPicCount; $i++) {
01930 if ( isset($this->{'oxarticles__oxpic'.$i}) ) {
01931 $this->{'oxarticles__oxpic'.$i}->setValue(basename($this->{'oxarticles__oxpic'.$i}->value));
01932 }
01933 }
01934
01935 $blRet = parent::save();
01936
01937 // save article long description
01938 $this->setArticleLongDesc();
01939
01940 // load article images after save
01941 $this->_assignAllPictureValues();
01942
01943 return $blRet;
01944 }
01945
01946
01953 public function getPictureGallery()
01954 {
01955 $myConfig = $this->getConfig();
01956
01957 //initialize
01958 $blMorePic = false;
01959 $aArtPics = array();
01960 $aArtIcons = array();
01961 $iActPicId = 1;
01962 $sActPic = $this->getPictureUrl( $iActPicId );
01963
01964 if ( oxConfig::getParameter( 'actpicid' ) ) {
01965 $iActPicId = oxConfig::getParameter('actpicid');
01966 }
01967
01968 $oStr = getStr();
01969 $iCntr = 0;
01970 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
01971 $blCheckActivePicId = true;
01972
01973 for ( $i = 1; $i <= $iPicCount; $i++) {
01974 $sPicVal = $this->getPictureUrl( $i );
01975 $sIcoVal = $this->getIconUrl( $i );
01976 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') ) {
01977 if ($iCntr) {
01978 $blMorePic = true;
01979 }
01980 $aArtIcons[$i]= $sIcoVal;
01981 $aArtPics[$i]= $sPicVal;
01982 $iCntr++;
01983
01984 if ($iActPicId == $i) {
01985 $sActPic = $sPicVal;
01986 $blCheckActivePicId = false;
01987 }
01988
01989 } else if ( $blCheckActivePicId && $iActPicId <= $i) {
01990 // if picture is empty, setting active pic id to next
01991 // picture
01992 $iActPicId++;
01993 }
01994 }
01995
01996 $blZoomPic = false;
01997 $aZoomPics = array();
01998 $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
01999
02000 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02001 $sVal = $this->getZoomPictureUrl($j);
02002
02003 if ( !$oStr->strstr($sVal, 'nopic.jpg')) {
02004 if ($this->getConfig()->getConfigParam('blFormerTplSupport')) {
02005 $sVal = $this->_sDynImageDir."/".$sVal;
02006 }
02007 $blZoomPic = true;
02008 $aZoomPics[$c]['id'] = $c;
02009 $aZoomPics[$c]['file'] = $sVal;
02010 //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
02011 if (!$sVal) {
02012 $aZoomPics[$c]['file'] = "nopic.jpg";
02013 }
02014 $c++;
02015 }
02016 }
02017
02018 $aPicGallery = array('ActPicID' => $iActPicId,
02019 'ActPic' => $sActPic,
02020 'MorePics' => $blMorePic,
02021 'Pics' => $aArtPics,
02022 'Icons' => $aArtIcons,
02023 'ZoomPic' => $blZoomPic,
02024 'ZoomPics' => $aZoomPics);
02025
02026 return $aPicGallery;
02027 }
02028
02042 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02043 {
02044 $myConfig = $this->getConfig();
02045
02046 if (!isset($sOXID)) {
02047 if ( $this->getId()) {
02048 $sOXID = $this->getId();
02049 }
02050 if (!isset ($sOXID)) {
02051 $sOXID = $this->oxarticles__oxid->value;
02052 }
02053 if ($this->oxarticles__oxparentid->value) {
02054 $sParentID = $this->oxarticles__oxparentid->value;
02055 }
02056 }
02057 if (!isset($sOXID)) {
02058 return;
02059 }
02060
02061 //if (isset($sOXID) && !$myConfig->blVariantParentBuyable && $myConfig->blUseStock)
02062 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02063 //if article has variants then updating oxvarstock field
02064 //getting parent id
02065 if (!isset($sParentID)) {
02066 $oDb = oxDb::getDb();
02067 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02068 $sParentID = $oDb->getOne($sQ);
02069 }
02070 //if we have parent id then update stock
02071 if ($sParentID) {
02072 $this->_onChangeUpdateStock($sParentID);
02073 }
02074 }
02075 //if we have parent id then update count
02076 //update count even if blUseStock is not active
02077 if ($sParentID) {
02078 $this->_onChangeUpdateVarCount($sParentID);
02079 }
02080
02081 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02082 $this->_onChangeUpdateMinVarPrice( $sId );
02083
02084 // reseting articles count cache if stock has changed and some
02085 // articles goes offline (M:1448)
02086 if ( $sAction === ACTION_UPDATE_STOCK ) {
02087 $this->_onChangeStockResetCount( $sOXID );
02088 }
02089
02090 }
02091
02098 public function getCustomVAT()
02099 {
02100 if ( isset($this->oxarticles__oxvat->value) ) {
02101 return $this->oxarticles__oxvat->value;
02102 }
02103 }
02104
02113 public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02114 {
02115 $myConfig = $this->getConfig();
02116 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02117 return true;
02118 }
02119
02120 // fetching DB info as its up-to-date
02121 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = "'.$this->getId().'" ';
02122 $rs = oxDb::getDb(true)->Execute( $sQ );
02123
02124 $iOnStock = 0;
02125 $iStockFlag = 0;
02126 if ( $rs !== false && $rs->recordCount() > 0 ) {
02127 $iOnStock = $rs->fields['oxstock'] - $dArtStockAmount;
02128 $iStockFlag = $rs->fields['oxstockflag'];
02129
02130 // dodger : fremdlager is also always considered as on stock
02131 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02132 return true;
02133 }
02134 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02135 //2007-09-04 MK this if is NEVER true, because upper return in if $iStockFlag == 1 or $iStockFlag == 4
02136 /* if ( $iStockFlag == 1 || $iStockFlag == 4 ) {
02137 $iOnStock = ceil( $iOnStock );
02138 } else {*/
02139 $iOnStock = floor( $iOnStock );
02140 //}
02141 }
02142 }
02143
02144 if ( $iOnStock >= $dAmount ) {
02145 return true;
02146 } else {
02147 if ( $iOnStock > 0 ) {
02148 return $iOnStock;
02149 } else {
02150 $oEx = oxNew( 'oxArticleInputException' );
02151 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02152 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
02153 return false;
02154 }
02155 }
02156 }
02157
02158
02166 public function getArticleLongDesc($sOXID = null)
02167 {
02168
02169 if ( !$sOXID ) {
02170 $sOXID = $this->oxarticles__oxid->value;
02171 }
02172
02173 if ($sOXID == $this->oxarticles__oxid->value) {
02174 if (isset($this->oxarticles__oxlongdesc) && ($this->oxarticles__oxlongdesc instanceof oxField) && $this->oxarticles__oxlongdesc->value) {
02175 return $this->oxarticles__oxlongdesc;
02176 }
02177 }
02178
02179 $myConfig = $this->getConfig();
02180
02181 if ( $sOXID ) {
02182 $sLangField = oxLang::getInstance()->getLanguageTag($this->getLanguage());
02183 $oDb = oxDb::getDb();
02184 $this->_setLongDesc($oDb->getOne( "select oxlongdesc{$sLangField} from oxartextends where oxid = ".$oDb->quote($sOXID) ));
02185 } else {
02186 // TODO: check if keeping fldname is needed in non-admin mode
02187 $this->oxarticles__oxlongdesc = new oxField();
02188 $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02189 $this->oxarticles__oxlongdesc->table = 'oxarticles';
02190 $this->oxarticles__oxlongdesc->fldtype = 'text';
02191 }
02192
02193 return $this->oxarticles__oxlongdesc;
02194 }
02195
02203 protected function _setLongDesc($sDbValue)
02204 {
02205 // TODO: eliminate code below
02206 // hack, if editor screws up text, htmledit tends to do so
02207 $sDbValue = str_replace( '&nbsp;', ' ', $sDbValue );
02208 $sDbValue = str_replace( '&', '&', $sDbValue );
02209 $sDbValue = str_replace( '"', '"', $sDbValue );
02210 $sDbValue = str_replace( '&lang=', '&lang=', $sDbValue);
02211 //
02212
02213 $oStr = getStr();
02214 $blHasSmarty = $oStr->strstr( $sDbValue, '[{' );
02215 $blHasPhp = $oStr->strstr( $sDbValue, '<?' );
02216 $myConfig = oxConfig::getInstance();
02217 if ( ( $blHasSmarty || $blHasPhp ) && ($myConfig->getConfigParam( 'blExport' ) || !$this->isAdmin() ) && $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
02218 $sDbValue = oxUtilsView::getInstance()->parseThroughSmarty( $sDbValue, $this->getId() );
02219 }
02220 $this->oxarticles__oxlongdesc = new oxField($sDbValue, oxField::T_RAW);
02221 // TODO: check if keeping fldname is needed in non-admin mode
02222 $this->oxarticles__oxlongdesc->fldname = 'oxlongdesc';
02223 $this->oxarticles__oxlongdesc->table = 'oxarticles';
02224 $this->oxarticles__oxlongdesc->fldtype = 'text';
02225 }
02226
02232 public function setArticleLongDesc()
02233 {
02234
02235 if ( $this->_blEmployMultilanguage ) {
02236 // update or insert article long description
02237 if ($this->oxarticles__oxlongdesc instanceof oxField) {
02238 $sLongDesc = $this->oxarticles__oxlongdesc->getRawValue();
02239 } else {
02240 $sLongDesc = $this->oxarticles__oxlongdesc->value;
02241 }
02242 $this->_saveArtLongDesc($this->getLanguage(), $sLongDesc);
02243 } else {
02244 $oArtExt = oxNew('oxi18n');
02245 $oArtExt->init('oxartextends');
02246 $aObjFields = $oArtExt->_getAllFields(true);
02247 foreach ($aObjFields as $sKey => $sValue ) {
02248 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02249 $sField = $this->_getFieldLongName($sKey);
02250 if (isset($this->$sField)) {
02251 $iLang = $oArtExt->_getFieldLang($sKey);
02252 $sLongDesc = null;
02253 if ($this->$sField instanceof oxField) {
02254 $sLongDesc = $this->$sField->getRawValue();
02255 } elseif (is_object($this->$sField)) {
02256 $sLongDesc = $this->$sField->value;
02257 }
02258 if (isset($sLongDesc)) {
02259 $this->_saveArtLongDesc($iLang, $sLongDesc);
02260 }
02261 }
02262 }
02263 }
02264 }
02265 }
02266
02272 public function getAttributes()
02273 {
02274 if ( $this->_oAttributeList === null ) {
02275 $this->_oAttributeList = oxNew( 'oxattributelist' );
02276 $this->_oAttributeList->loadAttributes( $this->getId() );
02277 }
02278
02279 return $this->_oAttributeList;
02280 }
02281
02290 public function appendLink( $sAddParams, $iLang = null )
02291 {
02292 if ( $sAddParams ) {
02293 if ( $iLang === null ) {
02294 $iLang = $this->getLanguage();
02295 }
02296
02297 $this->_aSeoAddParams[$iLang] = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&" : "";
02298 $this->_aSeoAddParams[$iLang] .= $sAddParams;
02299 }
02300 }
02301
02310 public function getBaseSeoLink( $iLang, $blMain = false )
02311 {
02312 $oEncoder = oxSeoEncoderArticle::getInstance();
02313 if ( !$blMain ) {
02314 return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02315 }
02316 return $oEncoder->getArticleMainUrl( $this, $iLang );
02317 }
02318
02327 public function getLink( $iLang = null, $blMain = false )
02328 {
02329 if ( !oxUtils::getInstance()->seoIsActive() ) {
02330 return $this->getStdLink( $iLang );
02331 }
02332
02333 if ( $iLang === null ) {
02334 $iLang = $this->getLanguage();
02335 }
02336
02337 $iLinkType = $this->getLinkType();
02338 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02339 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02340 }
02341
02342 $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02343 if ( isset($this->_aSeoAddParams[$iLang])) {
02344 $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&' ).$this->_aSeoAddParams[$iLang];
02345 }
02346
02347 return $sUrl;
02348 }
02349
02358 public function getMainLink( $iLang = null )
02359 {
02360 return $this->getLink( $iLang, true );
02361 }
02362
02370 public function setLinkType( $iType )
02371 {
02372 // resetting detaisl link, to force new
02373 $this->_sDetailLink = null;
02374
02375 // setting link type
02376 $this->_iLinkType = (int) $iType;
02377 }
02378
02384 public function getLinkType()
02385 {
02386 return $this->_iLinkType;
02387 }
02388
02397 public function appendStdLink( $sAddParams, $iLang = null )
02398 {
02399 if ( $sAddParams ) {
02400 if ( $iLang === null ) {
02401 $iLang = $this->getLanguage();
02402 }
02403
02404 $this->_aStdAddParams[$iLang] = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&" : "";
02405 $this->_aStdAddParams[$iLang] .= $sAddParams;
02406 }
02407 }
02408
02418 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02419 {
02420 $sUrl = '';
02421 if ( $blFull ) {
02422 //always returns shop url, not admin
02423 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02424 }
02425
02426 $sUrl .= "index.php?cl=details" . ( $blAddId ? "&anid=".$this->getId() : "" );
02427 return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&". $this->_aStdAddParams[$iLang] : "" );
02428 }
02429
02438 public function getStdLink( $iLang = null, $aParams = array() )
02439 {
02440 if ( $iLang === null ) {
02441 $iLang = $this->getLanguage();
02442 }
02443
02444 if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02445 $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02446 }
02447
02448 return oxUtilsUrl::getInstance()->processStdUrl( $this->_aStdUrls[$iLang], $aParams, $iLang, $iLang != $this->getLanguage() );
02449 }
02450
02458 public function getStdTagLink( $sTag )
02459 {
02460 $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02461 return $sStdTagLink . "cl=details&anid=".$this->getId()."&listtype=tag&searchtag=".rawurlencode( $sTag );
02462 }
02463
02469 public function getTags()
02470 {
02471 $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02472 $sQ = "select $sTagField from oxartextends where oxid = '".$this->getId()."'";
02473 $sTags = oxDb::getDb(true)->getOne($sQ);
02474 $oTagCloud = oxNew('oxtagcloud');
02475 $sTags = $oTagCloud->trimTags($sTags);
02476 return $sTags;
02477 }
02478
02486 public function saveTags($sTags)
02487 {
02488 $sTags = mysql_real_escape_string($sTags);
02489 $oTagCloud = oxNew('oxtagcloud');
02490 $oTagCloud->resetTagCache();
02491 $sTags = $oTagCloud->prepareTags($sTags);
02492 $sTagField = "oxtags".oxLang::getInstance()->getLanguageTag($this->getLanguage());
02493 $sQ = "update oxartextends set $sTagField = '$sTags' where oxid = '".$this->getId()."'";
02494 return oxDb::getDb()->execute($sQ);
02495
02496 }
02497
02505 public function addTag($sTag)
02506 {
02507 $sTag = mysql_real_escape_string($sTag);
02508
02509 $oTagCloud = oxNew('oxtagcloud');
02510 $oTagCloud->resetTagCache();
02511 $sTag = $oTagCloud->prepareTags($sTag);
02512 $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02513 $sTailTag = $sTagSeparator.$sTag;
02514
02515 $sField = "oxartextends.OXTAGS".oxLang::getInstance()->getLanguageTag();
02516 $sQ = "insert into oxartextends (oxartextends.OXID, $sField) values ('".$this->getId()."', '{$sTag}')
02517 ON DUPLICATE KEY update $sField = CONCAT(TRIM($sField), '$sTailTag') ";
02518
02519 return oxDb::getDb()->Execute($sQ);
02520 }
02521
02527 public function getMediaUrls()
02528 {
02529 if ( $this->_aMediaUrls === null ) {
02530 $this->_aMediaUrls = oxNew("oxlist");
02531 $this->_aMediaUrls->init("oxmediaurl");
02532 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02533
02534 $sQ = "select * from oxmediaurls where oxobjectid = '".$this->getId()."'";
02535 $this->_aMediaUrls->selectString($sQ);
02536 }
02537 return $this->_aMediaUrls;
02538 }
02539
02545 public function getDynImageDir()
02546 {
02547 return $this->_sDynImageDir;
02548 }
02549
02555 public function getDispSelList()
02556 {
02557 if ($this->_aDispSelList === null) {
02558 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02559 $this->_aDispSelList = $this->getSelectLists();
02560 }
02561 }
02562 return $this->_aDispSelList;
02563 }
02564
02570 public function getMoreDetailLink()
02571 {
02572 if ( $this->_sMoreDetailLink == null ) {
02573
02574 // and assign special article values
02575 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02576
02577 // not always it is okey, as not all the time active category is the same as primary article cat.
02578 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02579 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02580 }
02581 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02582 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02583 }
02584
02585 return $this->_sMoreDetailLink;
02586 }
02587
02593 public function getToBasketLink()
02594 {
02595 if ( $this->_sToBasketLink == null ) {
02596 $myConfig = $this->getConfig();
02597
02598 if ( oxUtils::getInstance()->isSearchEngine() ) {
02599 $this->_sToBasketLink = $this->getLink();
02600 } else {
02601 // and assign special article values
02602 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02603
02604 // override some classes as these should never showup
02605 $sActClass = oxConfig::getParameter( 'cl' );
02606 if ( $sActClass == 'thankyou') {
02607 $sActClass = 'basket';
02608 }
02609 $this->_sToBasketLink .= 'cl='.$sActClass;
02610
02611 // this is not very correct
02612 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02613 $this->_sToBasketLink .= '&cnid='.$sActCat;
02614 }
02615
02616 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02617
02618 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02619 $this->_sToBasketLink .= '&tpl='.$sTpl;
02620 }
02621 }
02622 }
02623
02624 return $this->_sToBasketLink;
02625 }
02626
02632 public function getStockStatus()
02633 {
02634 return $this->_iStockStatus;
02635 }
02636
02642 public function getDeliveryDate()
02643 {
02644 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02645 return oxUtilsDate::getInstance()->formatDBDate( $this->oxarticles__oxdelivery->value);
02646 }
02647 return false;
02648 }
02649
02655 public function getFTPrice()
02656 {
02657 if ( $oPrice = $this->getTPrice() ) {
02658 if ( $oPrice->getBruttoPrice() ) {
02659 return oxLang::getInstance()->formatCurrency( oxUtils::getInstance()->fRound($oPrice->getBruttoPrice()));
02660 }
02661 }
02662 }
02663
02669 public function getFPrice()
02670 {
02671 if ( $oPrice = $this->getPrice() ) {
02672 return $this->getPriceFromPrefix().oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
02673 }
02674 }
02675
02681 public function getPricePerUnit()
02682 {
02683 return $this->_fPricePerUnit;
02684 }
02685
02691 public function isParentNotBuyable()
02692 {
02693 return $this->_blNotBuyableParent;
02694 }
02695
02701 public function isNotBuyable()
02702 {
02703 return $this->_blNotBuyable;
02704 }
02705
02713 public function setBuyableState( $blBuyable = false )
02714 {
02715 $this->_blNotBuyable = !$blBuyable;
02716 }
02717
02723 public function getVariantList()
02724 {
02725 return $this->_oVariantList;
02726 }
02727
02735 public function setSelectlist( $aSelList )
02736 {
02737 $this->_aDispSelList = $aSelList;
02738 }
02739
02747 public function getPictureUrl( $iIndex = '' )
02748 {
02749 if ( $iIndex ) {
02750
02751 if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02752 $this->_generateImages( $iIndex );
02753 }
02754
02755 $sPic = $iIndex . "/" . $this->_getPictureName( $iIndex );
02756
02757 return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02758 }
02759 }
02760
02768 protected function _getPictureName( $iIndex = '' )
02769 {
02770 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02771 $sPicName = basename($this->{"oxarticles__oxpic".$iIndex}->value);
02772 } else {
02773 $sPicName = "nopic.jpg";
02774 }
02775
02776 return $sPicName;
02777 }
02778
02787 public function getIconUrl( $iIndex = '')
02788 {
02789 if ( $this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02790
02791 $iIconIndex = ( $iIndex ) ? $iIndex : 1;
02792 //generating new images if needed
02793 if ( !$this->_hasGeneratedImage( $iIconIndex ) ) {
02794 $this->_generateImages( $iIconIndex );
02795 }
02796 }
02797
02798 $sIconName = $this->_getIconName( $iIndex );
02799
02800 if ( !$iIndex ) {
02801 $sPic = "icon/" . basename( $sIconName );
02802 } else {
02803 $sPic = $iIndex . "/" . basename( $sIconName );
02804 }
02805
02806 return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02807 }
02808
02817 protected function _getIconName( $iIndex = '' )
02818 {
02819 $oPictureHandler = oxPictureHandler::getInstance();
02820 $sIconName = "nopic_ico.jpg";
02821
02822 if ( !$iIndex ) {
02823 if ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02824 $sIconName = basename( $this->oxarticles__oxicon->value );
02825 } elseif ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 ) && $this->oxarticles__oxpic1->value ) {
02826 $sIconName = $oPictureHandler->getMainIconName( $this->oxarticles__oxpic1->value );
02827 }
02828 } else {
02829 if ( $this->_hasGeneratedImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02830 $sIconName = $oPictureHandler->getIconName( $this->{"oxarticles__oxpic".$iIndex}->value );
02831 }
02832 }
02833
02834 return $sIconName;
02835 }
02836
02842 public function getThumbnailUrl()
02843 {
02844 if ( $this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02845 //generating new images if needed
02846 if ( !$this->_hasGeneratedImage( 1 ) ) {
02847 $this->_generateImages( 1 );
02848 }
02849 }
02850
02851 $sPic = "0/" . $this->_getThumbnailName();
02852
02853 return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02854 }
02855
02861 protected function _getThumbnailName()
02862 {
02863 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02864 $sThumbName = basename($this->oxarticles__oxthumb->value);
02865 } else {
02866 if ( $this->_hasGeneratedImage( 1 ) && $this->_hasMasterImage( 1 ) && $this->oxarticles__oxpic1->value ) {
02867 $oPictureHandler = oxPictureHandler::getInstance();
02868 $sThumbName = $oPictureHandler->getThumbName( $this->oxarticles__oxpic1->value );
02869 } else {
02870 $sThumbName = "nopic.jpg";
02871 }
02872 }
02873
02874 return $sThumbName;
02875 }
02876
02884 public function getZoomPictureUrl( $iIndex = '' )
02885 {
02886 $iIndex = (int) $iIndex;
02887 if ( $iIndex > 0) {
02888 //generating new images if needed
02889 if ( $this->_isFieldEmpty( "oxarticles__oxzoom" . $iIndex ) ) {
02890 //generating new images if needed
02891 if ( !$this->_hasGeneratedImage( $iIndex ) ) {
02892 $this->_generateImages( $iIndex );
02893 }
02894 }
02895
02896 $sPic = "z{$iIndex}/" . $this->_getZoomPictureName( $iIndex );
02897
02898 return $this->getConfig()->getPictureUrl( $sPic, $this->isAdmin() );
02899 }
02900 }
02901
02909 protected function _getZoomPictureName( $iIndex = '' )
02910 {
02911 $sZoomField = "oxarticles__oxzoom" . $iIndex;
02912
02913 if ( !$this->_isFieldEmpty( $sZoomField ) ) {
02914 $sZoomName = basename( $this->$sZoomField->value );
02915 } else {
02916 if ( $this->_hasGeneratedImage( $iIndex ) && $this->_hasMasterImage( $iIndex ) && $this->{"oxarticles__oxpic".$iIndex}->value ) {
02917 $oPictureHandler = oxPictureHandler::getInstance();
02918 $sZoomName = $oPictureHandler->getZoomName( $this->{"oxarticles__oxpic".$iIndex}->value, $iIndex );
02919 } else {
02920 $sZoomName = "nopic.jpg";
02921 }
02922 }
02923
02924 return $sZoomName;
02925 }
02926
02932 public function getFileUrl()
02933 {
02934 return $this->getConfig()->getPictureUrl( '0/' );
02935 }
02936
02942 public function getPriceFromPrefix()
02943 {
02944 $sPricePrefics = '';
02945 if ( $this->_blIsRangePrice) {
02946 $sPricePrefics = oxLang::getInstance()->translateString('priceFrom').' ';
02947 }
02948
02949 return $sPricePrefics;
02950 }
02951
02960 protected function _saveArtLongDesc($iLang, $sValue)
02961 {
02962 $oDB = oxDb::getDb();
02963 $iLang = (int) $iLang;
02964 $sLangField = ($iLang > '0') ? '_'.$iLang : '';
02965 $sLongDesc = $oDB->quote($sValue);
02966 $sLongDescSQL = "insert into oxartextends (oxartextends.OXID, oxartextends.OXLONGDESC{$sLangField})
02967 VALUES ('".$this->getId()."', {$sLongDesc})
02968 ON DUPLICATE KEY update oxartextends.OXLONGDESC{$sLangField} = {$sLongDesc} ";
02969
02970 $oDB->execute($sLongDescSQL);
02971 }
02972
02978 protected function _skipSaveFields()
02979 {
02980 $myConfig = $this->getConfig();
02981
02982 $this->_aSkipSaveFields = array();
02983
02984 $this->_aSkipSaveFields[] = 'oxtimestamp';
02985 $this->_aSkipSaveFields[] = 'oxlongdesc';
02986 $this->_aSkipSaveFields[] = 'oxinsert';
02987
02988 if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
02989 $this->_aSkipSaveFields[] = 'oxparentid';
02990 }
02991
02992 }
02993
03003 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03004 {
03005 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03006 // add prices of the same discounts
03007 if ( array_key_exists ($sKey, $aDiscounts) ) {
03008 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03009 } else {
03010 $aDiscounts[$sKey] = $oDiscount;
03011 }
03012 }
03013 return $aDiscounts;
03014 }
03015
03021 protected function _getGroupPrice()
03022 {
03023 $dPrice = $this->oxarticles__oxprice->value;
03024
03025 $oUser = $this->getArticleUser();
03026 if ( $oUser ) {
03027 if ( $oUser->inGroup( 'oxidpricea' ) ) {
03028 $dPrice = $this->oxarticles__oxpricea->value;
03029 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
03030 $dPrice = $this->oxarticles__oxpriceb->value;
03031 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
03032 $dPrice = $this->oxarticles__oxpricec->value;
03033 }
03034 }
03035
03036 // #1437/1436C - added config option, and check for zero A,B,C price values
03037 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03038 $dPrice = $this->oxarticles__oxprice->value;
03039 }
03040
03041 return $dPrice;
03042 }
03043
03052 protected function _getAmountPrice($dAmount = 1)
03053 {
03054 $myConfig = $this->getConfig();
03055
03056 startProfile( "_getAmountPrice" );
03057
03058 $dPrice = $this->_getGroupPrice();
03059 $oAmtPrices = $this->_getAmountPriceList();
03060 foreach ($oAmtPrices as $oAmPrice) {
03061 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03062 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03063 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03064 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03065 }
03066 }
03067
03068 stopProfile( "_getAmountPrice" );
03069 return $dPrice;
03070 }
03071
03080 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03081 {
03082 $myConfig = $this->getConfig();
03083 // #690
03084 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03085
03086 $aSelLists = $this->getSelectLists();
03087 foreach ( $aSelLists as $key => $aSel) {
03088 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03089 $oSel = $aSel[$aChosenList[$key]];
03090 if ( $oSel->priceUnit =='abs' ) {
03091 $dPrice += $oSel->price;
03092 } elseif ( $oSel->priceUnit =='%' ) {
03093 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03094 }
03095 }
03096 }
03097 }
03098 return $dPrice;
03099 }
03100
03101
03109 protected function _fillAmountPriceList($oAmPriceList)
03110 {
03111 $myConfig = $this->getConfig();
03112 $myUtils = oxUtils::getInstance();
03113
03114 //modifying price
03115 $oCur = $myConfig->getActShopCurrencyObject();
03116
03117 $oUser = $this->getArticleUser();
03118
03119 $oDiscountList = oxDiscountList::getInstance();
03120 $aDiscountList = $oDiscountList->getArticleDiscounts( $this, $oUser );
03121
03122 $oLowestPrice = null;
03123
03124 $dBasePrice = $this->_getGroupPrice();
03125 $oLang = oxLang::getInstance();
03126
03127 $dArticleVat = null;
03128 if ( !$myConfig->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
03129 $dArticleVat = $this->getArticleVat();
03130 }
03131
03132 // trying to find lowest price value
03133 foreach ($oAmPriceList as $sId => $oItem) {
03134 $oItemPrice = oxNew( 'oxprice' );
03135 if ( $oItem->oxprice2article__oxaddabs->value) {
03136 $oItemPrice->setPrice( $oItem->oxprice2article__oxaddabs->value );
03137 $oDiscountList->applyDiscounts( $oItemPrice, $aDiscountList );
03138 $this->_applyCurrency( $oItemPrice, $oCur );
03139 } else {
03140 $oItemPrice->setPrice( $dBasePrice );
03141 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03142 }
03143
03144 if (isset($dArticleVat)) {
03145 $this->_applyVAT($oItemPrice, $dArticleVat);
03146 }
03147
03148 if (!$oLowestPrice) {
03149 $oLowestPrice = $oItemPrice;
03150 } elseif ($oLowestPrice->getBruttoPrice() > $oItemPrice->getBruttoPrice()) {
03151 $oLowestPrice = $oItemPrice;
03152 }
03153
03154 $oAmPriceList[$sId]->oxprice2article__oxaddabs = new oxField( $oLang->formatCurrency( $myUtils->fRound( $oItemPrice->getBruttoPrice(), $oCur ) ) );
03155 $oAmPriceList[$sId]->fnetprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getNettoPrice(), $oCur ) );
03156 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $myUtils->fRound($oItemPrice->getBruttoPrice(), $oCur ) );
03157 }
03158
03159 $this->_dAmountPrice = $myUtils->fRound( $oLowestPrice->getBruttoPrice() );
03160 return $oAmPriceList;
03161 }
03162
03168 protected function _getVariantsIds()
03169 {
03170 $aSelect = array();
03171 $oRs = oxDb::getDb(true)->execute( "select oxid from oxarticles where oxparentid = '".$this->getId()."' " );
03172 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03173 while (!$oRs->EOF) {
03174 $aSelect[] = $oRs->fields['oxid'];
03175 $oRs->moveNext();
03176 }
03177 }
03178 return $aSelect;
03179 }
03180
03186 public function getArticleVat()
03187 {
03188 if (!isset($this->_dArticleVat)) {
03189 $this->_dArticleVat = oxVatSelector::getInstance()->getArticleVat( $this );
03190 }
03191 return $this->_dArticleVat;
03192 }
03193
03202 protected function _applyVAT( oxPrice $oPrice, $dVat )
03203 {
03204 startProfile(__FUNCTION__);
03205 $oPrice->setVAT( $dVat );
03206 if ( ($dVat = oxVatSelector::getInstance()->getArticleUserVat($this)) !== false ) {
03207 $oPrice->setUserVat( $dVat );
03208 }
03209 stopProfile(__FUNCTION__);
03210 }
03211
03219 public function applyVats( oxPrice $oPrice )
03220 {
03221 $this->_applyVAT($oPrice,
03222 $this->getArticleVat()
03223 );
03224 }
03225
03236 protected function _applyDiscounts( $oPrice, $aDiscounts )
03237 {
03238 $oDiscountList = oxDiscountList::getInstance();
03239 $oDiscountList->applyDiscounts( $oPrice, $aDiscounts );
03240 }
03241
03249 public function applyDiscountsForVariant( $oPrice )
03250 {
03251 // apply discounts
03252 if ( !$this->skipDiscounts() ) {
03253 $oDiscountList = oxDiscountList::getInstance();
03254 $oDiscountList->applyDiscounts( $oPrice, $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() ) );
03255 }
03256 }
03257
03266 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03267 {
03268 if ( !$oCur ) {
03269 $oCur = $this->getConfig()->getActShopCurrencyObject();
03270 }
03271
03272 $oPrice->multiply($oCur->rate);
03273 }
03274
03275
03284 protected function _getAttribsString(&$sAttribs, &$iCnt)
03285 {
03286 // we do not use lists here as we dont need this overhead right now
03287 $oDB = oxDb::getDb(true);
03288 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid="'.$this->getId().'" ';
03289 $sAttribs = '';
03290 $blSep = false;
03291 $rs = $oDB->execute( $sSelect);
03292 $iCnt = 0;
03293 if ($rs != false && $rs->recordCount() > 0) {
03294 while (!$rs->EOF) {
03295 if ( $blSep) {
03296 $sAttribs .= ' or ';
03297 }
03298 $sAttribs .= 't1.oxattrid = '.$oDB->quote($rs->fields['oxattrid']).' ';
03299 $blSep = true;
03300 $iCnt++;
03301 $rs->moveNext();
03302 }
03303 }
03304 }
03305
03314 protected function _getSimList($sAttribs, $iCnt)
03315 {
03316 $myConfig = $this->getConfig();
03317 $oDB = oxDb::getDb(true);
03318
03319 // #523A
03320 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03321 // 70% same attributes
03322 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03323 $iAttrPercent = 0.70;
03324 }
03325 // #1137V iAttributesPercent = 100 doesnt work
03326 $iHitMin = ceil( $iCnt * $iAttrPercent );
03327
03328 // we do not use lists here as we dont need this overhead right now
03329 $aList= array();
03330 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03331 ( $sAttribs )
03332 and t1.oxobjectid != '".$this->oxarticles__oxid->value."'
03333 group by t1.oxobjectid having count(*) >= $iHitMin ";
03334
03335 $rs = $oDB->selectLimit( $sSelect, 20, 0);
03336 if ($rs != false && $rs->recordCount() > 0) {
03337 while (!$rs->EOF) {
03338 $oTemp = new stdClass(); // #663
03339 $oTemp->cnt = $rs->fields['cnt'];
03340 $oTemp->id = $rs->fields['oxobjectid'];
03341 $aList[] = $oTemp;
03342 $rs->moveNext();
03343 }
03344 }
03345 return $aList;
03346 }
03347
03356 protected function _generateSimListSearchStr($sArticleTable, $aList)
03357 {
03358 $myConfig = $this->getConfig();
03359 $sFieldList = $this->getSelectFields();
03360 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03361 $blSep = false;
03362 $iCnt = 0;
03363 $oDb = oxDb::getDb();
03364 foreach ( $aList as $oTemp) {
03365 if ( $blSep) {
03366 $sSearch .= ',';
03367 }
03368 $sSearch .= $oDb->quote($oTemp->id);
03369 $blSep = true;
03370 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03371 break;
03372 }
03373 $iCnt++;
03374 }
03375
03376 //#1741T
03377 //$sSearch .= ") and $sArticleTable.oxparentid = '' ";
03378 $sSearch .= ') ';
03379
03380 // #524A -- randomizing articles in attribute list
03381 $sSearch .= ' order by rand() ';
03382
03383 return $sSearch;
03384 }
03385
03394 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03395 {
03396 $sCatView = getViewName( 'oxcategories' );
03397 $sO2CView = getViewName( 'oxobject2category' );
03398
03399 // we do not use lists here as we dont need this overhead right now
03400 if ( !$blSearchPriceCat ) {
03401 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03402 {$sCatView}.oxid = oxobject2category.oxcatnid
03403 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03404 } else {
03405 $sSelect = "select {$sCatView}.* from {$sCatView} where
03406 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03407 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03408 }
03409 return $sSelect;
03410 }
03411
03417 protected function _generateSearchStrForCustomerBought()
03418 {
03419 $sArtTable = $this->_getObjectViewName( 'oxarticles' );
03420 $sOrderArtTable = getViewName( 'oxorderarticles' );
03421
03422 // fetching filter params
03423 $sIn = " '{$this->oxarticles__oxid->value}' ";
03424 if ( $this->oxarticles__oxparentid->value ) {
03425
03426 // adding article parent
03427 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03428 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03429
03430 } else {
03431 $sParentIdForVariants = $this->getId();
03432 }
03433
03434 // adding variants
03435 $oDb = oxDb::getDb(true);
03436 $oRs = $oDb->execute( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value)." " );
03437 if ( $oRs != false && $oRs->recordCount() > 0) {
03438 while ( !$oRs->EOF ) {
03439 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03440 $oRs->moveNext();
03441 }
03442 }
03443
03444 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03445 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03446
03447 // building sql (optimized)
03448 $sQ = "select distinct {$sArtTable}.* from (
03449 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03450 ) as suborder
03451 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03452 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03453 where {$sArtTable}.oxid not in ( {$sIn} )
03454 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03455
03456 /* non optimized, but could be used if index forcing is not supported
03457 // building sql
03458 $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
03459 select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
03460 ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
03461 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
03462 and ".$this->getSqlActiveSnippet();
03463 */
03464
03465 return $sQ;
03466 }
03467
03477 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03478 {
03479 $sCategoryView = getViewName('oxcategories');
03480 $sO2CView = getViewName('oxobject2category');
03481 $sLangPrefix = (($this->getLanguage())?'_'.$this->getLanguage():'');
03482
03483 $oDb = oxDb::getDb();
03484 $sOXID = $oDb->quote($sOXID);
03485 $sCatId = $oDb->quote($sCatId);
03486
03487 if (!$dPriceFromTo) {
03488 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03489 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03490 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03491 $sSelect .= "and oxcategories.oxactive$sLangPrefix = 1 order by oxobject2category.oxtime ";
03492 } else {
03493 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03494 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03495 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03496 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03497 }
03498 return $sSelect;
03499 }
03500
03506 protected function _getAmountPriceList()
03507 {
03508 if ($this->_oAmountPriceList) {
03509 return $this->_oAmountPriceList;
03510 }
03511
03512 $myConfig = $this->getConfig();
03513
03514 $sArtID = $this->getId();
03515
03516 // #1690C - Scale prices and variants
03517 if ( !$this->isAdmin() && $myConfig->getConfigParam( 'blVariantInheritAmountPrice' ) && $this->oxarticles__oxparentid->value ) {
03518 $sArtID = $this->oxarticles__oxparentid->value;
03519 }
03520
03521 // echo( "TODO replace oxlist usage here _collectAmPriceList".PHP_EOL);
03522 $sArtID = mysql_real_escape_string($sArtID);
03523
03524 //collecting assigned to article amount-price list
03525 $oAmPriceList = oxNew( 'oxlist');
03526 $oAmPriceList->init('oxbase', 'oxprice2article');
03527
03528 $sShopID = $myConfig->getShopID();
03529 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
03530 $sShopSelect = '1';
03531 } else {
03532 $sShopSelect = " oxshopid = '$sShopID' ";
03533 }
03534
03535 $oAmPriceList->selectString( "select * from oxprice2article where oxartid = '$sArtID' and $sShopSelect order by oxamount ");
03536
03537 // prepare abs prices if currently having percentages
03538 $oBasePrice = $this->_getGroupPrice();
03539 foreach ($oAmPriceList as $oAmPrice) {
03540 if ($oAmPrice->oxprice2article__oxaddperc->value) {
03541 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW);
03542 }
03543 }
03544
03545 $this->_oAmountPriceList = $oAmPriceList;
03546 return $oAmPriceList;
03547 }
03548
03556 protected function _isFieldEmpty($sFieldName)
03557 {
03558 $mValue = $this->$sFieldName->value;
03559
03560 if (is_null($mValue)) {
03561 return true;
03562 }
03563
03564 if ($mValue === '') {
03565 return true;
03566 }
03567
03568 $aDoubleCopyFields = array('oxarticles__oxprice',
03569 'oxarticles__oxvat');
03570
03571 if (!$mValue && in_array($sFieldName, $aDoubleCopyFields)) {
03572 return true;
03573 }
03574
03575
03576 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03577 return true;
03578 }
03579
03580 $sFieldName = strtolower($sFieldName);
03581
03582 if ( $sFieldName == 'oxarticles__oxicon' && strpos($mValue, "nopic_ico.jpg") !== false ) {
03583 return true;
03584 }
03585
03586 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03587 return true;
03588 }
03589
03590 return false;
03591 }
03592
03600 protected function _assignParentFieldValue($sFieldName)
03601 {
03602 if (!($oParentArticle = $this->getParentArticle())) {
03603 return;
03604 }
03605
03606 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03607
03608 // assigning only theese which parent article has
03609 if ( $oParentArticle->$sCopyFieldName != null ) {
03610
03611 // only overwrite database values
03612 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03613 continue;
03614 }
03615
03616 //do not copy certain fields
03617 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03618 return;
03619 }
03620
03621 //COPY THE VALUE
03622 // assigning images from parent only if variant has no master image (#1807)
03623 if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03624 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03625 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03626 }
03627 } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03628 // for zoom images checking master image with specified index
03629 $iIndex = (int) str_ireplace( "oxzoom", "", $sFieldName );
03630 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) ) {
03631 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03632 }
03633 } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03634 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03635 }
03636
03637 }
03638 }
03639
03645 public function getParentArticle()
03646 {
03647 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03648 if ( !isset( self::$_aLoadedParents[$sParentId] ) ) {
03649 self::$_aLoadedParents[$sParentId] = oxNew( 'oxarticle' );
03650 self::$_aLoadedParents[$sParentId]->_blSkipAbPrice = true;
03651 self::$_aLoadedParents[$sParentId]->_blLoadPrice = false;
03652 self::$_aLoadedParents[$sParentId]->_blLoadVariants = false;
03653 self::$_aLoadedParents[$sParentId]->load( $sParentId );
03654 }
03655 return self::$_aLoadedParents[$sParentId];
03656 }
03657 }
03658
03666 protected function _getParentAricle()
03667 {
03668 return $this->getParentArticle();
03669 }
03670
03676 protected function _assignParentFieldValues()
03677 { startProfile('articleAssignParentInternal');
03678 if ( $this->oxarticles__oxparentid->value) {
03679 // yes, we are in fact a variant
03680 if ( !$this->isAdmin() || ($this->_blLoadParentData && $this->isAdmin() ) ) {
03681 foreach ($this->_aFieldNames as $sFieldName => $sVal) {
03682 $this->_assignParentFieldValue($sFieldName);
03683 }
03684
03685 //assing long description
03686 $oParentArticle = $this->getParentArticle();
03687 if ( !$this->oxarticles__oxlongdesc->value ) {
03688 $this->oxarticles__oxlongdesc = $oParentArticle->oxarticles__oxlongdesc;
03689 }
03690
03691 }
03692 } elseif ( $this->oxarticles__oxid->value ) {
03693 // I am not a variant but I might have some
03694 //$this->_oVariantList = $this->getSimpleVariants();
03695 startProfile("loadVariants");
03696 $this->_oVariantList = $this->getVariants();
03697 stopProfile("loadVariants");
03698 // #1650M - article title with <br> tag
03699 // htmlspecialchars parses only 5 characters, so i have stiped out '<' and '>'
03700 /*
03701 if ( !$this->isAdmin() ) {
03702 $this->oxarticles__oxtitle->setValue(str_replace(array('&', "'", '"'), array('&', ''', '"'), $this->oxarticles__oxtitle->value));
03703 }*/
03704 }
03705 stopProfile('articleAssignParentInternal');
03706
03707 }
03708
03714 protected function _assignNotBuyableParent()
03715 {
03716 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03717 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03718 $this->_blNotBuyableParent = true;
03719
03720 }
03721 }
03722
03728 protected function _assignAllPictureValues()
03729 {
03730 $myConfig = $this->getConfig();
03731
03732 $this->_assignPictureValues( "oxarticles__oxicon" );
03733 $this->_assignPictureValues( "oxarticles__oxthumb" );
03734
03735 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03736 for ( $i=1; $i<= $iPicCount; $i++ ) {
03737 $this->_assignPictureValues( "oxarticles__oxpic".$i );
03738 }
03739
03740 if ( $iZoomPicCount = $myConfig->getConfigParam( 'iZoomPicCount' ) ) {
03741 for ( $i=1; $i<= $iZoomPicCount; $i++ ) {
03742 $this->_assignPictureValues( "oxarticles__oxzoom".$i );
03743 }
03744 }
03745 }
03746
03754 protected function _assignPictureValues( $sName='' )
03755 {
03756 if ( $this->isAdmin() || !$sName ) {
03757 return;
03758 }
03759
03760 $sFieldName = substr_replace( $sName, "", 0, 12);
03761 $myConfig = $this->getConfig();
03762
03763 // add directories
03764 if ( $sFieldName == 'oxicon' && isset($this->_aFieldNames["oxicon"]) ) {
03765 $this->oxarticles__oxicon = new oxField('icon/'.$this->_getIconName());
03766 return;
03767 }
03768
03769 if ( $sFieldName == 'oxthumb' && isset($this->_aFieldNames["oxthumb"]) ) {
03770 $this->oxarticles__oxthumb = new oxField('0/'.$this->_getThumbnailName());
03771 return;
03772 }
03773
03774 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03775
03776 if ( strpos($sFieldName, "oxpic") === 0 && isset($this->_aFieldNames[$sFieldName] ) ) {
03777
03778 $iIndex = (int) str_ireplace( "oxpic", "", $sFieldName );
03779
03780 if ( $iIndex > 0 && $iIndex < $iPicCount ) {
03781 $this->$sName = new oxField( $iIndex . '/'.$this->_getPictureName($iIndex) );
03782 $this->{$sName.'_ico'} = new oxField( $iIndex . '/'.$this->_getIconName($iIndex) );
03783 return;
03784 }
03785 }
03786
03787 if ( strpos($sFieldName, "oxzoom") === 0 ) {
03788
03789 $iIndex = (int) str_ireplace( "oxzoom", "", $sFieldName );
03790
03791 // if oxzoom or oxpic field with same index is setted, loading field values
03792 if ( isset($this->_aFieldNames[$sFieldName]) || isset($this->_aFieldNames["oxpic".$iIndex]) ) {
03793 if ( $iIndex > 0 && $iIndex < $iPicCount ) {
03794 $this->$sName = new oxField( 'z' . $iIndex.'/'.$this->_getZoomPictureName($iIndex) );
03795 return;
03796 }
03797 }
03798 }
03799 }
03800
03806 protected function _assignStock()
03807 {
03808 $myConfig = $this->getConfig();
03809 // -----------------------------------
03810 // stock
03811 // -----------------------------------
03812
03813 // #1125 A. must round (using floor()) value taken from database and cast to int
03814 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03815 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03816 }
03817 //GREEN light
03818 $this->_iStockStatus = 0;
03819
03820 // if we have flag /*1 or*/ 4 - we show always green light
03821 if ( $myConfig->getConfigParam( 'blUseStock' ) && /*$this->oxarticles__oxstockflag->value != 1 && */ $this->oxarticles__oxstockflag->value != 4) {
03822 //ORANGE light
03823 $iStock = $this->oxarticles__oxstock->value;
03824
03825 if ($this->_blNotBuyableParent) {
03826 $iStock = $this->oxarticles__oxvarstock->value;
03827 }
03828
03829
03830 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03831 $this->_iStockStatus = 1;
03832 }
03833
03834 //RED light
03835 if ($iStock <= 0) {
03836 $this->_iStockStatus = -1;
03837 }
03838 }
03839
03840
03841 // stock
03842 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstock->value <= 0 && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03843 $this->_blNotBuyable = true;
03844 }
03845
03846 //exceptional handling for variant parent stock:
03847 if ($this->_blNotBuyable && $this->_iVarStock) {
03848 $this->_blNotBuyable = false;
03849 //but then at least setting notBuaybleParent to true
03850 $this->_blNotBuyableParent = true;
03851 }
03852
03853 //special treatment for lists when blVariantParentBuyable config option is set to false
03854 //then we just hide "to basket" button.
03855 //if variants are not loaded in the list and this article has variants and parent is not buyable then this article is not buyable
03856 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03857 $this->_blNotBuyable = true;
03858 }
03859
03860 //setting to non buyable when variant list is empty (for example not loaded or inactive) and $this is non buyable parent
03861 if ($this->_blNotBuyableParent && count($this->_oVariantList) == 0) {
03862 $this->_blNotBuyable = true;
03863 }
03864 }
03865
03871 protected function _assignPrices()
03872 {
03873 $myConfig = $this->getConfig();
03874
03875 // Performance
03876 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03877 return;
03878 }
03879
03880 // compute price
03881 $dPrice = $this->getPrice()->getBruttoPrice();
03882
03883 $oCur = $myConfig->getActShopCurrencyObject();
03884 //price per unit handling
03885 if ((double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value) {
03886 $this->_fPricePerUnit = oxLang::getInstance()->formatCurrency($dPrice / (double) $this->oxarticles__oxunitquantity->value, $oCur);
03887 }
03888
03889
03890 //getting min and max prices of variants
03891 $this->_applyRangePrice();
03892 }
03893
03899 protected function _assignPersistentParam()
03900 {
03901 // Persistent Parameter Handling
03902 $aPersParam = oxSession::getVar( 'persparam');
03903 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03904 $this->_aPersistParam = $aPersParam[$this->getId()];
03905 }
03906 }
03907
03913 protected function _assignDynImageDir()
03914 {
03915 $myConfig = $this->getConfig();
03916
03917 $sThisShop = $this->oxarticles__oxshopid->value;
03918
03919 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03920 $this->dabsimagedir = $myConfig->getPictureDir( false ); //$sThisShop
03921 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop ); //$sThisShop
03922 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop ); //$sThisShop
03923 }
03924
03930 protected function _assignComparisonListFlag()
03931 {
03932 // #657 add a flag if article is on comparisonlist
03933
03934 $aItems = oxConfig::getParameter('aFiltcompproducts');
03935 if ( isset( $aItems[$this->getId()])) {
03936 $this->_blIsOnComparisonList = true;
03937 }
03938 }
03939
03945 protected function _assignAttributes()
03946 {
03947 //#1029T load attributes
03948 //#1078S removed check for module "Produktvergleich"
03949 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAttributes' ) ) {
03950 $this->getAttributes();
03951 }
03952 }
03953
03954
03962 protected function _insert()
03963 {
03964 // set oxinsert
03965 $iInsertTime = time();
03966 $now = date('Y-m-d H:i:s', $iInsertTime);
03967 $this->oxarticles__oxinsert = new oxField( $now );
03968 $this->oxarticles__oxtimestamp = new oxField( $now );
03969 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03970 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03971 }
03972
03973 return parent::_insert();
03974 }
03975
03981 protected function _update()
03982 {
03983
03984 $this->_skipSaveFields();
03985
03986 $myConfig = $this->getConfig();
03987
03988
03989 return parent::_update();
03990 }
03991
03999 protected function _deleteRecords($sOXID)
04000 {
04001 $oDB = oxDb::getDb();
04002
04003 $sOXID = $oDB->quote($sOXID);
04004
04005 //delete the record
04006 $sDelete = 'delete from '.$this->_sCoreTbl.' where oxid = '.$sOXID.' ';
04007 $oDB->execute( $sDelete);
04008
04009 //remove other records
04010 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
04011 $oDB->execute( $sDelete);
04012
04013 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
04014 $oDB->execute( $sDelete);
04015
04016 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
04017 $oDB->execute( $sDelete);
04018
04019 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
04020 $oDB->execute( $sDelete);
04021
04022 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
04023 $oDB->execute( $sDelete);
04024
04025 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
04026 $oDB->execute( $sDelete);
04027
04028 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
04029 $oDB->execute( $sDelete);
04030
04031 //#1508C - deleting oxobject2delivery entries added
04032 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04033 $oDB->execute( $sDelete);
04034
04035 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04036 $oDB->execute( $sDelete);
04037
04038 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04039 $rs = $oDB->execute( $sDelete );
04040
04041 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04042 $rs = $oDB->execute( $sDelete );
04043
04044
04045 return $rs;
04046 }
04047
04055 protected function _deleteVariantRecords($sOXID)
04056 {
04057 $oDB = oxDb::getDb();
04058
04059 $sVariants = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDB->quote($sOXID);
04060 $rs = $oDB->execute( $sVariants);
04061 if ($rs != false && $rs->recordCount() > 0) {
04062 while (!$rs->EOF) {
04063 $this->delete( $rs->fields[0]);
04064 $rs->moveNext();
04065 }
04066 }
04067 }
04068
04078 protected function _resetCacheAndArticleCount( $sOxid )
04079 {
04080 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04081 }
04082
04088 protected function _deletePics()
04089 {
04090 $myUtilsPic = oxUtilsPic::getInstance();
04091 $myConfig = $this->getConfig();
04092 $oPictureHandler = oxPictureHandler::getInstance();
04093
04094
04095 $oPictureHandler->deleteMainIcon( $this );
04096
04097
04098 $oPictureHandler->deleteThumbnail( $this );
04099
04100 $sAbsDynImageDir = $myConfig->getAbsDynImageDir();
04101
04102
04103 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04104 for ( $i = 1; $i <= $iPicCount; $i++ ) {
04105 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04106 }
04107 }
04108
04118 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04119 {
04120
04121 $myUtilsCount = oxUtilsCount::getInstance();
04122
04123 if ( $sVendorId ) {
04124 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04125 }
04126
04127 if ( $sManufacturerId ) {
04128 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04129 }
04130
04131
04132 $oDb = oxDb::getDb();
04133 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04134 $oRs = $oDb->execute( $sQ );
04135 if ( $oRs !== false && $oRs->recordCount() > 0) {
04136 while ( !$oRs->EOF ) {
04137 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04138 $oRs->moveNext();
04139 }
04140 }
04141 }
04142
04150 protected function _onChangeUpdateStock( $sParentID )
04151 {
04152 $oDb = oxDb::getDb();
04153 $sParentIdQuoted = $oDb->quote($sParentID);
04154 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04155 $rs = $oDb->execute($sQ);
04156 $iOldStock = $rs->fields[0];
04157 $iVendorID = $rs->fields[1];
04158 $iManufacturerID = $rs->fields[2];
04159
04160 $sQ = 'select sum(oxstock) from oxarticles where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04161 $iStock = (float) $oDb->getOne( $sQ );
04162
04163 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04164 $oDb->execute( $sQ );
04165
04166
04167
04168 if ( $iStock < 0 ) {
04169 $iStock = 0;
04170 }
04171 if ( $iOldStock < 0 ) {
04172 $iOldStock = 0;
04173 }
04174 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04175
04176
04177 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04178 }
04179 }
04180
04188 protected function _onChangeStockResetCount( $sOxid )
04189 {
04190 $myConfig = $this->getConfig();
04191
04192 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04193 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04194
04195 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04196 }
04197 }
04198
04206 protected function _onChangeUpdateVarCount( $sParentID )
04207 {
04208 $oDb = oxDb::getDb();
04209 $sParentIdQuoted = $oDb->quote($sParentID);
04210 $sQ = 'select count(*) as varcount from oxarticles where oxparentid = '.$sParentIdQuoted;
04211 $iVarCount = (int) $oDb->getOne($sQ);
04212
04213 $sQ = 'update oxarticles set oxvarcount = '.$iVarCount.' where oxid = '.$sParentIdQuoted;
04214 $oDb->execute($sQ);
04215 }
04216
04224 protected function _onChangeUpdateMinVarPrice( $sParentID )
04225 {
04226 $oDb = oxDb::getDb();
04227 $sParentIdQuoted = $oDb->quote($sParentID);
04228
04229 $sQ = 'select min(oxprice) as varminprice from oxarticles where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted;
04230
04231 if ( $this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) ) {
04232 $sQ .= ' or oxid = '.$sParentIdQuoted;
04233 } else {
04234 $sQ .= ' or (oxid = '.$sParentIdQuoted.' and oxvarcount=0)';
04235 }
04236 $sQ .= ')';
04237 $dVarMinPrice = $oDb->getOne($sQ);
04238 if ( $dVarMinPrice ) {
04239 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04240 $oDb->execute($sQ);
04241 }
04242 }
04243
04244
04250 protected function _applyRangePrice()
04251 {
04252
04253 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04254 return;
04255 }
04256
04257 $this->_blIsRangePrice = false;
04258
04259
04260 if ($this->_blSkipAbPrice || !$this->_blNotBuyableParent) {
04261 return;
04262 }
04263
04264 $aPrices = array();
04265
04266 if (!$this->_blNotBuyableParent) {
04267 $aPrices[] = $this->getPrice()->getBruttoPrice();
04268 }
04269
04270 if (count($this->_oVariantList)) {
04271 foreach ($this->_oVariantList as $sKey => $oVariant) {
04272 $aPrices[] = $oVariant->getPrice()->getBruttoPrice();
04273 }
04274 }
04275
04276
04277
04278
04279
04280
04281 if (count($aPrices)) {
04282 $dMinPrice = $aPrices[0];
04283 $dMaxPrice = $aPrices[0];
04284 foreach ($aPrices as $dPrice) {
04285 if ($dMinPrice > $dPrice) {
04286 $dMinPrice = $dPrice;
04287 }
04288
04289 if ($dMaxPrice < $dPrice) {
04290 $dMaxPrice = $dPrice;
04291 }
04292 }
04293 }
04294
04295 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04296 $this->getPrice()->setBruttoPriceMode();
04297 $this->getPrice()->setPrice($dMinPrice);
04298 }
04299
04300 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04301 $this->getPrice()->setBruttoPriceMode();
04302 $this->getPrice()->setPrice($dMinPrice);
04303 $this->_blIsRangePrice = true;
04304 }
04305
04306 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04307 $this->getPrice()->setBruttoPriceMode();
04308 $this->getPrice()->setPrice($this->oxarticles__oxvarminprice->value);
04309 $this->_blIsRangePrice = true;
04310 $this->_calculatePrice( $this->getPrice() );
04311 }
04312 }
04313
04320 public function getProductId()
04321 {
04322 return $this->getId();
04323 }
04324
04330 public function getProductParentId()
04331 {
04332 return $this->oxarticles__oxparentid->value;
04333 }
04334
04340 public function isOrderArticle()
04341 {
04342 return false;
04343 }
04344
04350 public function isVariant()
04351 {
04352 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04353 }
04354
04360 public function isMdVariant()
04361 {
04362 $oMdVariant = oxNew( "oxVariantHandler" );
04363
04364 return $oMdVariant->isMdVariant($this);
04365 }
04366
04374 public function getSqlForPriceCategories($sFields = '')
04375 {
04376 if (!$sFields) {
04377 $sFields = 'oxid';
04378 }
04379 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04380 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04381 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04382 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04383 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04384 }
04385
04393 public function inPriceCategory( $sCatNid )
04394 {
04395 $oDb = oxDb::getDb();
04396
04397 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04398 $sQuotedCnid = oxDb::getDb()->quote( $sCatNid );
04399 return (bool) $oDb->getOne(
04400 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04401 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04402 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04403 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04404 .")"
04405 );
04406 }
04407
04413 public function getMdVariants()
04414 {
04415 if ( $this->_oMdVariants ) {
04416 return $this->_oMdVariants;
04417 }
04418
04419 $oParentArticle = $this->getParentArticle();
04420 if ( $oParentArticle ) {
04421 $oVariants = $oParentArticle->getVariants();
04422 } else {
04423 $oVariants = $this->getVariants();
04424 }
04425
04426 $oVariantHandler = oxNew( "oxVariantHandler" );
04427 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04428
04429 return $this->_oMdVariants;
04430 }
04431
04437 public function getMdSubvariants()
04438 {
04439 return $this->getMdVariants()->getMdSubvariants();
04440 }
04441
04442
04451 protected function _generateImages( $iIndex )
04452 {
04453 if ( isset($this->_aFieldNames["oxpic".$iIndex]) && !$this->_hasGeneratedImage( $iIndex ) ) {
04454 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) && $this->_hasMasterImage( $iIndex ) ) {
04455 $oPictureHandler = oxPictureHandler::getInstance();
04456 $oPictureHandler->generateArticlePictures( $this, $iIndex );
04457 }
04458 }
04459 }
04460
04469 public function updateAmountOfGeneratedPictures( $iTotalGenerated )
04470 {
04471 $sQ = "UPDATE oxarticles SET oxpicsgenerated = '$iTotalGenerated' WHERE oxid = '".$this->getId()."'";
04472 oxDb::getDb()->execute($sQ);
04473
04474 $this->oxarticles__oxpicsgenerated = new oxField( $iTotalGenerated );
04475 }
04476
04485 protected function _hasGeneratedImage( $iIndex )
04486 {
04487 if ( $iIndex > (int) $this->oxarticles__oxpicsgenerated->value ) {
04488 return false;
04489 }
04490
04491 return true;
04492 }
04493
04501 protected function _hasMasterImage( $iIndex )
04502 {
04503 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04504
04505 if ( $sPicName == "nopic.jpg" ) {
04506 return false;
04507 }
04508
04509 $sMasterPic = $iIndex . "/" . $sPicName;
04510
04511 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04512 return true;
04513 }
04514
04515 return false;
04516 }
04517
04526 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04527 {
04528 if ( $sFieldName ) {
04529 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04530 return $this->$sFieldName->value;
04531 }
04532 }
04533 }