discount_articles.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00004                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00005                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00006                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00007                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00008                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00009                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00010                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00011                                         ),
00012                      'container2' => array(
00013                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00014                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00015                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00016                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00017                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00018                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00019                                         array( 'oxid',     'oxobject2discount', 0, 0, 1 )
00020                                         )
00021                     );
00022 
00026 class ajaxComponent extends ajaxListComponent
00027 {
00033     protected $_blAllowExtColumns = true;
00034 
00040     protected function _getQuery()
00041     {
00042         $myConfig = $this->getConfig();
00043 
00044         $sArticleTable = $this->_getViewName('oxarticles');
00045         $sCatTable     = $this->_getViewName('oxcategories');
00046         $sO2CView      = $this->_getViewName('oxobject2category');
00047 
00048         $sOxid      = oxConfig::getParameter( 'oxid' );
00049         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00050 
00051         // category selected or not ?
00052         if ( !$sOxid && $sSynchOxid ) {
00053             $sQAdd  = " from $sArticleTable where 1 ";
00054             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':"and $sArticleTable.oxparentid = '' ";
00055         } else {
00056             // selected category ?
00057             if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00058                 $sQAdd  = " from $sO2CView left join $sArticleTable on ";
00059                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?"($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00060                 $sQAdd .= " where $sO2CView.oxcatnid = '$sOxid' and $sArticleTable.oxid is not null ";
00061 
00062                 // resetting
00063                 $sId = null;
00064             } else {
00065                 $sQAdd  = " from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00066                 $sQAdd .= " and oxobject2discount.oxdiscountid = '$sOxid' and oxobject2discount.oxtype = 'oxarticles' ";
00067             }
00068         }
00069 
00070         if ( $sSynchOxid && $sSynchOxid != $sOxid) {
00071             // dodger performance
00072             $sSubSelect .= " select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00073             $sSubSelect .= " and oxobject2discount.oxdiscountid = '$sSynchOxid' and oxobject2discount.oxtype = 'oxarticles' ";
00074 
00075             if ( stristr( $sQAdd, 'where' ) === false )
00076                 $sQAdd .= ' where ';
00077             else
00078                 $sQAdd .= ' and ';
00079             $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
00080         }
00081 
00082         return $sQAdd;
00083     }
00084 
00090     public function removediscart()
00091     {
00092         $aChosenArt = $this->_getActionIds( 'oxobject2discount.oxid' );
00093         if ( oxConfig::getParameter( 'all' ) ) {
00094 
00095             $sQ = parent::_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00096             oxDb::getDb()->Execute( $sQ );
00097 
00098         } elseif ( is_array( $aChosenArt ) ) {
00099             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00100             oxDb::getDb()->Execute( $sQ );
00101         }
00102     }
00103 
00109     public function adddiscart()
00110     {
00111         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00112         $soxId      = oxConfig::getParameter( 'synchoxid');
00113 
00114         // adding
00115         if ( oxConfig::getParameter( 'all' ) ) {
00116             $sArticleTable = $this->_getViewName('oxarticles');
00117             $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00118         }
00119         if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00120             foreach ( $aChosenArt as $sChosenArt) {
00121                 $oObject2Discount = oxNew( "oxbase" );
00122                 $oObject2Discount->init( 'oxobject2discount' );
00123                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00124                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenArt);
00125                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxarticles");
00126                 $oObject2Discount->save();
00127             }
00128         }
00129     }
00130 }