article_crossselling_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class article_crossselling_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_blAllowExtColumns = true;
00015 
00021     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00022         array('oxartnum', 'oxarticles', 1, 0, 0),
00023         array('oxtitle', 'oxarticles', 1, 1, 0),
00024         array('oxean', 'oxarticles', 1, 0, 0),
00025         array('oxmpn', 'oxarticles', 0, 0, 0),
00026         array('oxprice', 'oxarticles', 0, 0, 0),
00027         array('oxstock', 'oxarticles', 0, 0, 0),
00028         array('oxid', 'oxarticles', 0, 0, 1)
00029     ),
00030                                  'container2' => array(
00031                                      array('oxartnum', 'oxarticles', 1, 0, 0),
00032                                      array('oxtitle', 'oxarticles', 1, 1, 0),
00033                                      array('oxean', 'oxarticles', 1, 0, 0),
00034                                      array('oxmpn', 'oxarticles', 0, 0, 0),
00035                                      array('oxprice', 'oxarticles', 0, 0, 0),
00036                                      array('oxstock', 'oxarticles', 0, 0, 0),
00037                                      array('oxid', 'oxobject2article', 0, 0, 1)
00038                                  )
00039     );
00040 
00046     protected function _getQuery()
00047     {
00048         $myConfig = $this->getConfig();
00049         $sArticleTable = $this->_getViewName('oxarticles');
00050         $sView = $this->_getViewName('oxobject2category');
00051 
00052         $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
00053         $sSynchSelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00054         $oDb = oxDb::getDb();
00055 
00056         // category selected or not ?
00057         if (!$sSelId) {
00058             $sQAdd = " from {$sArticleTable} where 1 ";
00059             $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and {$sArticleTable}.oxparentid = '' ";
00060         } elseif ($sSynchSelId && $sSelId != $sSynchSelId) {
00061             // selected category ?
00062             $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
00063             $sSqlIfTrue = " ({$sArticleTable}.oxid=oxobject2category.oxobjectid " .
00064                           "or {$sArticleTable}.oxparentid=oxobject2category.oxobjectid)";
00065             $sSqlIfFalse = " {$sArticleTable}.oxid=oxobject2category.oxobjectid ";
00066             $sVariantsSelectionSnippet = $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFalse;
00067 
00068             $sQAdd = " from {$sView} as oxobject2category left join {$sArticleTable} on {$sVariantsSelectionSnippet}" .
00069                      " where oxobject2category.oxcatnid = " . $oDb->quote($sSelId) . " ";
00070         } elseif ($myConfig->getConfigParam('blBidirectCross')) {
00071             $sQAdd = " from oxobject2article " .
00072                      " inner join {$sArticleTable} on ( oxobject2article.oxobjectid = {$sArticleTable}.oxid " .
00073                      " or oxobject2article.oxarticlenid = {$sArticleTable}.oxid ) " .
00074                      " where ( oxobject2article.oxarticlenid = " . $oDb->quote($sSelId) .
00075                      " or oxobject2article.oxobjectid = " . $oDb->quote($sSelId) . " ) " .
00076                      " and {$sArticleTable}.oxid != " . $oDb->quote($sSelId) . " ";
00077         } else {
00078             $sQAdd = " from oxobject2article left join {$sArticleTable} " .
00079                      "on oxobject2article.oxobjectid={$sArticleTable}.oxid " .
00080                      " where oxobject2article.oxarticlenid = " . $oDb->quote($sSelId) . " ";
00081         }
00082 
00083         if ($sSynchSelId && $sSynchSelId != $sSelId) {
00084             if ($myConfig->getConfigParam('blBidirectCross')) {
00085                 $sSubSelect = "select {$sArticleTable}.oxid from oxobject2article " .
00086                               "left join {$sArticleTable} on (oxobject2article.oxobjectid={$sArticleTable}.oxid " .
00087                               "or oxobject2article.oxarticlenid={$sArticleTable}.oxid) " .
00088                               "where (oxobject2article.oxarticlenid = " . $oDb->quote($sSynchSelId) .
00089                               " or oxobject2article.oxobjectid = " . $oDb->quote($sSynchSelId) . " )";
00090             } else {
00091                 $sSubSelect = "select {$sArticleTable}.oxid from oxobject2article " .
00092                               "left join {$sArticleTable} on oxobject2article.oxobjectid={$sArticleTable}.oxid " .
00093                               "where oxobject2article.oxarticlenid = " . $oDb->quote($sSynchSelId) . " ";
00094             }
00095 
00096             $sSubSelect .= " and {$sArticleTable}.oxid IS NOT NULL ";
00097             $sQAdd .= " and {$sArticleTable}.oxid not in ( $sSubSelect ) ";
00098         }
00099 
00100         // #1513C/#1826C - skip references, to not existing articles
00101         $sQAdd .= " and {$sArticleTable}.oxid IS NOT NULL ";
00102 
00103         // skipping self from list
00104         $sId = ($sSynchSelId) ? $sSynchSelId : $sSelId;
00105         $sQAdd .= " and {$sArticleTable}.oxid != " . $oDb->quote($sId) . " ";
00106 
00107         return $sQAdd;
00108     }
00109 
00113     public function removeArticleCross()
00114     {
00115         $aChosenArt = $this->_getActionIds('oxobject2article.oxid');
00116         // removing all
00117         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00118             $sQ = $this->_addFilter("delete oxobject2article.* " . $this->_getQuery());
00119             oxDb::getDb()->Execute($sQ);
00120         } elseif (is_array($aChosenArt)) {
00121             $sChosenArticles = implode(", ", oxDb::getInstance()->quoteArray($aChosenArt));
00122             $sQ = "delete from oxobject2article where oxobject2article.oxid in (" . $sChosenArticles . ") ";
00123             oxDb::getDb()->Execute($sQ);
00124         }
00125 
00126     }
00127 
00131     public function addArticleCross()
00132     {
00133         $aChosenArt = $this->_getActionIds('oxarticles.oxid');
00134         $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00135 
00136         // adding
00137         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00138             $sArtTable = $this->_getViewName('oxarticles');
00139             $aChosenArt = $this->_getAll(parent::_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
00140         }
00141 
00142         $oArticle = oxNew("oxarticle");
00143         if ($oArticle->load($soxId) && $soxId && $soxId != "-1" && is_array($aChosenArt)) {
00144             foreach ($aChosenArt as $sAdd) {
00145                 $oNewGroup = oxNew('oxbase');
00146                 $oNewGroup->init('oxobject2article');
00147                 $oNewGroup->oxobject2article__oxobjectid = new oxField($sAdd);
00148                 $oNewGroup->oxobject2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
00149                 $oNewGroup->oxobject2article__oxsort = new oxField(0);
00150                 $oNewGroup->save();
00151             }
00152 
00153         }
00154     }
00155 }