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         $oDb = oxDb::getDb();
00049         $sOxid = oxConfig::getParameter( 'oxid' );
00050         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00051 
00052         // category selected or not ?
00053         if ( !$sOxid && $sSynchOxid ) {
00054             $sQAdd  = " from $sArticleTable where 1 ";
00055             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':"and $sArticleTable.oxparentid = '' ";
00056         } else {
00057             // selected category ?
00058             if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00059                 $sQAdd  = " from $sO2CView left join $sArticleTable on ";
00060                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?"($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00061                 $sQAdd .= " where $sO2CView.oxcatnid = ".$oDb->quote( $sOxid )." and $sArticleTable.oxid is not null ";
00062 
00063                 // resetting
00064                 $sId = null;
00065             } else {
00066                 $sQAdd  = " from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00067                 $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sOxid )." and oxobject2discount.oxtype = 'oxarticles' ";
00068             }
00069         }
00070 
00071         if ( $sSynchOxid && $sSynchOxid != $sOxid) {
00072             // dodger performance
00073             $sSubSelect .= " select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00074             $sSubSelect .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchOxid )." and oxobject2discount.oxtype = 'oxarticles' ";
00075 
00076             if ( stristr( $sQAdd, 'where' ) === false )
00077                 $sQAdd .= ' where ';
00078             else
00079                 $sQAdd .= ' and ';
00080             $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
00081         }
00082 
00083         return $sQAdd;
00084     }
00085 
00091     public function removediscart()
00092     {
00093         $aChosenArt = $this->_getActionIds( 'oxobject2discount.oxid' );
00094         if ( oxConfig::getParameter( 'all' ) ) {
00095 
00096             $sQ = parent::_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00097             oxDb::getDb()->Execute( $sQ );
00098 
00099         } elseif ( is_array( $aChosenArt ) ) {
00100             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00101             oxDb::getDb()->Execute( $sQ );
00102         }
00103     }
00104 
00110     public function adddiscart()
00111     {
00112         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00113         $soxId      = oxConfig::getParameter( 'synchoxid');
00114 
00115         // adding
00116         if ( oxConfig::getParameter( 'all' ) ) {
00117             $sArticleTable = $this->_getViewName('oxarticles');
00118             $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00119         }
00120         if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00121             foreach ( $aChosenArt as $sChosenArt) {
00122                 $oObject2Discount = oxNew( "oxbase" );
00123                 $oObject2Discount->init( 'oxobject2discount' );
00124                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00125                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenArt);
00126                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxarticles");
00127                 $oObject2Discount->save();
00128             }
00129         }
00130     }
00131 }