OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
attribute_main_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', 'oxobject2attribute', 0, 0, 1 )
37  )
38  );
39 
45  protected function _getQuery()
46  {
47  $myConfig = $this->getConfig();
48  $oDb = oxDb::getDb();
49 
50  $sArticleTable = $this->_getViewName('oxarticles');
51  $sO2CategoryView = $this->_getViewName('oxobject2category');
52  $sO2AttributeView = $this->_getViewName('oxobject2attribute');
53 
54  $sDelId = oxConfig::getParameter( 'oxid' );
55  $sSynchDelId = oxConfig::getParameter( 'synchoxid' );
56 
57  // category selected or not ?
58  if ( !$sDelId) {
59  // dodger performance
60  $sQAdd = " from $sArticleTable where 1 ";
61  $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
62  } elseif ( $sSynchDelId && $sDelId != $sSynchDelId ) {
63  // selected category ?
64  $sQAdd = " from $sO2CategoryView as oxobject2category left join $sArticleTable on ";
65  $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArticleTable.oxid=oxobject2category.oxobjectid or $sArticleTable.oxparentid=oxobject2category.oxobjectid)":" $sArticleTable.oxid=oxobject2category.oxobjectid ";
66  $sQAdd .= " where oxobject2category.oxcatnid = " . $oDb->quote( $sDelId ) . " ";
67  } else {
68  $sQAdd = " from $sO2AttributeView left join $sArticleTable on $sArticleTable.oxid=$sO2AttributeView.oxobjectid ";
69  $sQAdd .= " where $sO2AttributeView.oxattrid = " . $oDb->quote( $sDelId ) . " and $sArticleTable.oxid is not null ";
70  }
71 
72  if ( $sSynchDelId && $sSynchDelId != $sDelId ) {
73  $sQAdd .= " and $sArticleTable.oxid not in ( select $sO2AttributeView.oxobjectid from $sO2AttributeView where $sO2AttributeView.oxattrid = " . $oDb->quote( $sSynchDelId ) . " ) ";
74  }
75 
76  return $sQAdd;
77  }
78 
86  protected function _addFilter( $sQ )
87  {
88  $sQ = parent::_addFilter( $sQ );
89 
90  // display variants or not ?
91  if ( $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
92  $sQ .= ' group by '.$this->_getViewName( 'oxarticles' ).'.oxid ';
93 
94  $oStr = getStr();
95  if ( $oStr->strpos( $sQ, "select count( * ) " ) === 0 ) {
96  $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
97  }
98  }
99  return $sQ;
100  }
101 
107  public function removeAttrArticle()
108  {
109  $aChosenCat = $this->_getActionIds( 'oxobject2attribute.oxid' );
110 
111 
112  if ( oxConfig::getParameter( 'all' ) ) {
113  $sO2AttributeView = $this->_getViewName('oxobject2attribute');
114 
115  $sQ = parent::_addFilter( "delete $sO2AttributeView.* ".$this->_getQuery() );
116  oxDb::getDb()->Execute( $sQ );
117  } elseif ( is_array( $aChosenCat ) ) {
118  $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
119  oxDb::getDb()->Execute( $sQ );
120  }
121  }
122 
128  public function addAttrArticle()
129  {
130  $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
131  $soxId = oxConfig::getParameter( 'synchoxid' );
132 
133  // adding
134  if ( oxConfig::getParameter( 'all' ) ) {
135  $sArticleTable = $this->_getViewName( 'oxarticles' );
136  $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
137  }
138 
139  $oAttribute = oxNew( "oxattribute" );
140 
141  if ( $oAttribute->load( $soxId) && is_array( $aAddArticle ) ) {
142  foreach ( $aAddArticle as $sAdd ) {
143  $oNewGroup = oxNew( "oxbase" );
144  $oNewGroup->init( "oxobject2attribute" );
145  $oNewGroup->oxobject2attribute__oxobjectid = new oxField( $sAdd );
146  $oNewGroup->oxobject2attribute__oxattrid = new oxField( $oAttribute->oxattribute__oxid->value );
147  $oNewGroup->save();
148 
149  }
150  }
151  }
152 }