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