OXID eShop CE  4.10.0
 All Classes Namespaces Files Functions Variables Pages
article_accessories_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', 'oxaccessoire2article', 0, 0, 1)
38  )
39  );
40 
46  protected function _getQuery()
47  {
48  $myConfig = $this->getConfig();
49  $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
50  $sSynchSelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
51  $oDb = oxDb::getDb();
52 
53  $sArticleTable = $this->_getViewName('oxarticles');
54  $sView = $this->_getViewName('oxobject2category');
55 
56  // category selected or not ?
57  if (!$sSelId) {
58  $sQAdd = " from {$sArticleTable} where 1 ";
59  $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and {$sArticleTable}.oxparentid = '' ";
60  } else {
61  // selected category ?
62  if ($sSynchSelId && $sSelId != $sSynchSelId) {
63  $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
64  $sSqlIfTrue = " ( {$sArticleTable}.oxid=$sView.oxobjectid " .
65  "or {$sArticleTable}.oxparentid=$sView.oxobjectid )";
66  $sSqlIfFals = " {$sArticleTable}.oxid=$sView.oxobjectid ";
67  $sVariantSelectionSql = $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFals;
68 
69  $sQAdd = " from $sView left join {$sArticleTable} on {$sVariantSelectionSql}" .
70  " where $sView.oxcatnid = " . $oDb->quote($sSelId) . " ";
71  } else {
72  $sQAdd = " from oxaccessoire2article left join {$sArticleTable} " .
73  "on oxaccessoire2article.oxobjectid={$sArticleTable}.oxid " .
74  " where oxaccessoire2article.oxarticlenid = " . $oDb->quote($sSelId) . " ";
75  }
76  }
77 
78  if ($sSynchSelId && $sSynchSelId != $sSelId) {
79  // performance
80  $sSubSelect .= " select oxaccessoire2article.oxobjectid from oxaccessoire2article ";
81  $sSubSelect .= " where oxaccessoire2article.oxarticlenid = " . $oDb->quote($sSynchSelId) . " ";
82  $sQAdd .= " and {$sArticleTable}.oxid not in ( $sSubSelect ) ";
83  }
84 
85  // skipping self from list
86  $sId = ($sSynchSelId) ? $sSynchSelId : $sSelId;
87  $sQAdd .= " and {$sArticleTable}.oxid != " . $oDb->quote($sId) . " ";
88 
89  // creating AJAX component
90  return $sQAdd;
91  }
92 
96  public function removeArticleAcc()
97  {
98  $aChosenArt = $this->_getActionIds('oxaccessoire2article.oxid');
99  // removing all
100  if (oxRegistry::getConfig()->getRequestParameter('all')) {
101 
102  $sQ = $this->_addFilter("delete oxaccessoire2article.* " . $this->_getQuery());
103  oxDb::getDb()->Execute($sQ);
104 
105  } elseif (is_array($aChosenArt)) {
106  $sChosenArticles = implode(", ", oxDb::getInstance()->quoteArray($aChosenArt));
107  $sQ = "delete from oxaccessoire2article where oxaccessoire2article.oxid in ({$sChosenArticles}) ";
108  oxDb::getDb()->Execute($sQ);
109  }
110 
111 
112  }
113 
117  public function addArticleAcc()
118  {
119  $oArticle = oxNew("oxarticle");
120  $aChosenArt = $this->_getActionIds('oxarticles.oxid');
121  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
122 
123  // adding
124  if (oxRegistry::getConfig()->getRequestParameter('all')) {
125  $sArtTable = $this->_getViewName('oxarticles');
126  $aChosenArt = $this->_getAll(parent::_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
127  }
128 
129  if ($oArticle->load($soxId) && $soxId && $soxId != "-1" && is_array($aChosenArt)) {
130  foreach ($aChosenArt as $sChosenArt) {
131  $oNewGroup = oxNew("oxbase");
132  $oNewGroup->init("oxaccessoire2article");
133  $oNewGroup->oxaccessoire2article__oxobjectid = new oxField($sChosenArt);
134  $oNewGroup->oxaccessoire2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
135  $oNewGroup->oxaccessoire2article__oxsort = new oxField(0);
136  $oNewGroup->save();
137  }
138 
139  }
140  }
141 }