OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
article_crossselling_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_blAllowExtColumns = true;
14 
20  protected $_aColumns = array( 'container1' => array( // field , table, visible, multilanguage, ident
21  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
22  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
23  array( 'oxean', 'oxarticles', 1, 0, 0 ),
24  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
25  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
26  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
27  array( 'oxid', 'oxarticles', 0, 0, 1 )
28  ),
29  'container2' => array(
30  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
31  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
32  array( 'oxean', 'oxarticles', 1, 0, 0 ),
33  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
34  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
35  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
36  array( 'oxid', 'oxobject2article', 0, 0, 1 )
37  )
38  );
39 
45  protected function _getQuery()
46  {
47  $myConfig = $this->getConfig();
48  $sArticleTable = $this->_getViewName( 'oxarticles' );
49  $sO2CView = $this->_getViewName( 'oxobject2category' );
50 
51  $sSelId = oxConfig::getParameter( 'oxid' );
52  $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
53  $oDb = oxDb::getDb();
54 
55  // category selected or not ?
56  if ( !$sSelId ) {
57  $sQAdd = " from $sArticleTable where 1 ";
58  $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )? '':" and $sArticleTable.oxparentid = '' ";
59  } elseif ( $sSynchSelId && $sSelId != $sSynchSelId ) {
60  // selected category ?
61  $sQAdd = " from $sO2CView as oxobject2category left join $sArticleTable on ";
62  $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ($sArticleTable.oxid=oxobject2category.oxobjectid or $sArticleTable.oxparentid=oxobject2category.oxobjectid)":" $sArticleTable.oxid=oxobject2category.oxobjectid ";
63  $sQAdd .= " where oxobject2category.oxcatnid = " . $oDb->quote( $sSelId ) . " ";
64  } elseif ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
65  $sQAdd = " from oxobject2article ";
66  $sQAdd .= " inner join $sArticleTable on ( oxobject2article.oxobjectid = $sArticleTable.oxid ";
67  $sQAdd .= " or oxobject2article.oxarticlenid = $sArticleTable.oxid ) ";
68  $sQAdd .= " where ( oxobject2article.oxarticlenid = " . $oDb->quote( $sSelId ) . " or oxobject2article.oxobjectid = " . $oDb->quote( $sSelId ) . " ) ";
69  $sQAdd .= " and $sArticleTable.oxid != " . $oDb->quote( $sSelId ) . " ";
70  } else {
71  $sQAdd = " from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
72  $sQAdd .= " where oxobject2article.oxarticlenid = " . $oDb->quote( $sSelId ) . " ";
73  }
74 
75  if ( $sSynchSelId && $sSynchSelId != $sSelId) {
76  if ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
77  $sSubSelect = "select $sArticleTable.oxid from oxobject2article left join $sArticleTable on (oxobject2article.oxobjectid=$sArticleTable.oxid or oxobject2article.oxarticlenid=$sArticleTable.oxid) ";
78  $sSubSelect .= "where (oxobject2article.oxarticlenid = " . $oDb->quote( $sSynchSelId ) . " or oxobject2article.oxobjectid = " . $oDb->quote( $sSynchSelId ) . " )";
79  } else {
80  $sSubSelect = "select $sArticleTable.oxid from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
81  $sSubSelect .= "where oxobject2article.oxarticlenid = " . $oDb->quote( $sSynchSelId ) . " ";
82  }
83 
84  $sSubSelect .= " and $sArticleTable.oxid IS NOT NULL ";
85  $sQAdd .= " and $sArticleTable.oxid not in ( $sSubSelect ) ";
86  }
87 
88  // #1513C/#1826C - skip references, to not existing articles
89  $sQAdd .= " and $sArticleTable.oxid IS NOT NULL ";
90 
91  // skipping self from list
92  $sId = ( $sSynchSelId ) ? $sSynchSelId : $sSelId ;
93  $sQAdd .= " and $sArticleTable.oxid != " . $oDb->quote( $sId ) . " ";
94 
95  return $sQAdd ;
96  }
97 
103  public function removeArticleCross()
104  {
105  $aChosenArt = $this->_getActionIds( 'oxobject2article.oxid' );
106  // removing all
107  if ( oxConfig::getParameter( 'all' ) ) {
108  $sQ = $this->_addFilter( "delete oxobject2article.* ".$this->_getQuery() );
109  oxDb::getDb()->Execute( $sQ );
110  } elseif ( is_array( $aChosenArt ) ) {
111  $sQ = "delete from oxobject2article where oxobject2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
112  oxDb::getDb()->Execute( $sQ );
113  }
114 
115  }
116 
122  public function addArticleCross()
123  {
124  $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
125  $soxId = oxConfig::getParameter( 'synchoxid');
126 
127  // adding
128  if ( oxConfig::getParameter( 'all' ) ) {
129  $sArtTable = $this->_getViewName('oxarticles');
130  $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
131  }
132 
133  $oArticle = oxNew( "oxarticle" );
134  if ( $oArticle->load( $soxId) && $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
135  foreach ( $aChosenArt as $sAdd ) {
136  $oNewGroup = oxNew( 'oxbase' );
137  $oNewGroup->init( 'oxobject2article' );
138  $oNewGroup->oxobject2article__oxobjectid = new oxField($sAdd);
139  $oNewGroup->oxobject2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
140  $oNewGroup->oxobject2article__oxsort = new oxField(0);
141  $oNewGroup->save();
142  }
143 
144  }
145  }
146 }