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