article_bundle_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class article_bundle_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     );
00031 
00037     protected function _getQuery()
00038     {
00039         $myConfig = $this->getConfig();
00040         $oDb = oxDb::getDb();
00041         $sArticleTable = $this->_getViewName('oxarticles');
00042         $sView = $this->_getViewName('oxobject2category');
00043 
00044         $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
00045         $sSynchSelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00046 
00047         // category selected or not ?
00048         if (!$sSelId) {
00049             $sQAdd = " from $sArticleTable where 1 ";
00050             $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArticleTable.oxparentid = '' ";
00051         } else {
00052             // selected category ?
00053             if ($sSynchSelId) {
00054                 $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
00055                 $sSqlIfTrue = " ({$sArticleTable}.oxid=oxobject2category.oxobjectid " .
00056                               "or {$sArticleTable}.oxparentid=oxobject2category.oxobjectid)";
00057                 $sSqlIfFalse = " $sArticleTable.oxid=oxobject2category.oxobjectid ";
00058                 $sVariantsSqlSnippet = $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFalse;
00059 
00060                 $sQAdd = " from {$sView} as oxobject2category left join {$sArticleTable} on {$sVariantsSqlSnippet}" .
00061                          " where oxobject2category.oxcatnid = " . $oDb->quote($sSelId) . " ";
00062             }
00063         }
00064         // #1513C/#1826C - skip references, to not existing articles
00065         $sQAdd .= " and $sArticleTable.oxid IS NOT NULL ";
00066 
00067         // skipping self from list
00068         $sQAdd .= " and $sArticleTable.oxid != " . $oDb->quote($sSynchSelId) . " ";
00069 
00070         return $sQAdd;
00071     }
00072 
00080     protected function _addFilter($sQ)
00081     {
00082         $sArtTable = $this->_getViewName('oxarticles');
00083         $sQ = parent::_addFilter($sQ);
00084 
00085         // display variants or not ?
00086         $sQ .= $this->getConfig()->getConfigParam('blVariantsSelection') ? ' group by ' . $sArtTable . '.oxid ' : '';
00087 
00088         return $sQ;
00089     }
00090 
00094     public function removeArticleBundle()
00095     {
00096         $oDb = oxDb::getDb();
00097         $sQuotedChosenArt = $oDb->quote(oxRegistry::getConfig()->getRequestParameter('oxid'));
00098 
00099         $sQ = "update oxarticles set oxarticles.oxbundleid = '' where oxarticles.oxid  =  {$sQuotedChosenArt} ";
00100         $oDb->Execute($sQ);
00101     }
00102 
00106     public function addArticleBundle()
00107     {
00108         $oDb = oxDb::getDb();
00109         $sQuotedChosenArt = $oDb->quote(oxRegistry::getConfig()->getRequestParameter('oxbundleid'));
00110         $sQuotedOxId = $oDb->quote(oxRegistry::getConfig()->getRequestParameter('oxid'));
00111 
00112         $sQ = "update oxarticles set oxarticles.oxbundleid =  {$sQuotedChosenArt} " .
00113               "where oxarticles.oxid  =  {$sQuotedOxId} ";
00114         $oDb->Execute($sQ);
00115     }
00116 }