OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
attribute_main_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', 'oxobject2attribute', 0, 0, 1)
38  )
39  );
40 
46  protected function _getQuery()
47  {
48  $myConfig = $this->getConfig();
49  $oDb = oxDb::getDb();
50 
51  $sArticleTable = $this->_getViewName('oxarticles');
52  $sOCatView = $this->_getViewName('oxobject2category');
53  $sOAttrView = $this->_getViewName('oxobject2attribute');
54 
55  $sDelId = oxRegistry::getConfig()->getRequestParameter('oxid');
56  $sSynchDelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
57 
58  // category selected or not ?
59  if (!$sDelId) {
60  // performance
61  $sQAdd = " from $sArticleTable where 1 ";
62  $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArticleTable.oxparentid = '' ";
63  } elseif ($sSynchDelId && $sDelId != $sSynchDelId) {
64  // selected category ?
65  $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
66  $sSqlIfTrue = " ( {$sArticleTable}.oxid=oxobject2category.oxobjectid " .
67  "or {$sArticleTable}.oxparentid=oxobject2category.oxobjectid)";
68  $sSqlIfFalse = " {$sArticleTable}.oxid=oxobject2category.oxobjectid ";
69  $sVariantSelectionSql = $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFalse;
70  $sQAdd = " from {$sOCatView} as oxobject2category left join {$sArticleTable} on {$sVariantSelectionSql}" .
71  " where oxobject2category.oxcatnid = " . $oDb->quote($sDelId) . " ";
72  } else {
73  $sQAdd = " from {$sOAttrView} left join {$sArticleTable} " .
74  "on {$sArticleTable}.oxid={$sOAttrView}.oxobjectid " .
75  "where {$sOAttrView}.oxattrid = " . $oDb->quote($sDelId) .
76  " and {$sArticleTable}.oxid is not null ";
77  }
78 
79  if ($sSynchDelId && $sSynchDelId != $sDelId) {
80  $sQAdd .= " and {$sArticleTable}.oxid not in ( select {$sOAttrView}.oxobjectid from {$sOAttrView} " .
81  "where {$sOAttrView}.oxattrid = " . $oDb->quote($sSynchDelId) . " ) ";
82  }
83 
84  return $sQAdd;
85  }
86 
94  protected function _addFilter($sQ)
95  {
96  $sQ = parent::_addFilter($sQ);
97 
98  // display variants or not ?
99  if ($this->getConfig()->getConfigParam('blVariantsSelection')) {
100  $sQ .= ' group by ' . $this->_getViewName('oxarticles') . '.oxid ';
101 
102  $oStr = getStr();
103  if ($oStr->strpos($sQ, "select count( * ) ") === 0) {
104  $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
105  }
106  }
107 
108  return $sQ;
109  }
110 
114  public function removeAttrArticle()
115  {
116  $aChosenCat = $this->_getActionIds('oxobject2attribute.oxid');
117 
118 
119  if (oxRegistry::getConfig()->getRequestParameter('all')) {
120  $sO2AttributeView = $this->_getViewName('oxobject2attribute');
121 
122  $sQ = parent::_addFilter("delete $sO2AttributeView.* " . $this->_getQuery());
123  oxDb::getDb()->Execute($sQ);
124  } elseif (is_array($aChosenCat)) {
125  $sChosenCategories = implode(", ", oxDb::getInstance()->quoteArray($aChosenCat));
126  $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . $sChosenCategories . ") ";
127  oxDb::getDb()->Execute($sQ);
128  }
129  }
130 
134  public function addAttrArticle()
135  {
136  $aAddArticle = $this->_getActionIds('oxarticles.oxid');
137  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
138 
139  // adding
140  if (oxRegistry::getConfig()->getRequestParameter('all')) {
141  $sArticleTable = $this->_getViewName('oxarticles');
142  $aAddArticle = $this->_getAll($this->_addFilter("select $sArticleTable.oxid " . $this->_getQuery()));
143  }
144 
145  $oAttribute = oxNew("oxattribute");
146 
147  if ($oAttribute->load($soxId) && is_array($aAddArticle)) {
148  foreach ($aAddArticle as $sAdd) {
149  $oNewGroup = oxNew("oxbase");
150  $oNewGroup->init("oxobject2attribute");
151  $oNewGroup->oxobject2attribute__oxobjectid = new oxField($sAdd);
152  $oNewGroup->oxobject2attribute__oxattrid = new oxField($oAttribute->oxattribute__oxid->value);
153  $oNewGroup->save();
154 
155  }
156  }
157  }
158 }