Klasse für die Funktionen die von ajax aufgerufen werden.
[B]Name: cm_discount_groups_block_ajax.php[/B]
<?php
/**
* Class manages discount groups
*/
class cm_discount_groups_block_ajax extends ajaxListComponent
{
/**
* Columns array
*
* @var array
*/
protected $_aColumns = array('container1' => array( // field , table, visible, multilanguage, ident
array('oxtitle', 'oxgroups', 1, 0, 0),
array('oxid', 'oxgroups', 0, 0, 0),
array('oxid', 'oxgroups', 0, 0, 1),
),
'container2' => array(
array('oxtitle', 'oxgroups', 1, 0, 0),
array('oxid', 'oxgroups', 0, 0, 0),
array('oxid', 'oxobject_block2discount', 0, 0, 1),
)
);
/**
* Returns SQL query for data to fetch
*
* @return string
*/
protected function _getQuery()
{
$oConfig = $this->getConfig();
// active AJAX component
$sGroupTable = $this->_getViewName('oxgroups');
$oDb = oxDb::getDb();
$sId = $oConfig->getRequestParameter('oxid');
$sSynchId = $oConfig->getRequestParameter('synchoxid');
// category selected or not ?
if (!$sId) {
$sQAdd = " from {$sGroupTable} where 1 ";
} else {
$sQAdd = " from oxobject_block2discount, {$sGroupTable} where {$sGroupTable}.oxid=oxobject_block2discount.oxobjectid ";
$sQAdd .= " and oxobject_block2discount.oxdiscountid = " . $oDb->quote($sId) .
" and oxobject_block2discount.oxtype = 'oxgroups' ";
}
if ($sSynchId && $sSynchId != $sId) {
$sQAdd .= " and {$sGroupTable}.oxid not in ( select {$sGroupTable}.oxid " .
"from oxobject_block2discount, {$sGroupTable} where {$sGroupTable}.oxid=oxobject_block2discount.oxobjectid " .
" and oxobject_block2discount.oxdiscountid = " . $oDb->quote($sSynchId) .
" and oxobject_block2discount.oxtype = 'oxgroups' ) ";
}
return $sQAdd;
}
/**
* Removes user group from discount config
*/
public function removeDiscGroup()
{
$oConfig = $this->getConfig();
$aRemoveGroups = $this->_getActionIds('oxobject_block2discount.oxid');
if ($oConfig->getRequestParameter('all')) {
$sQ = $this->_addFilter("delete oxobject_block2discount.* " . $this->_getQuery());
oxDb::getDb()->Execute($sQ);
} elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
$sRemoveGroups = implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups));
$sQ = "delete from oxobject_block2discount where oxobject_block2discount.oxid in (" . $sRemoveGroups . ") ";
oxDb::getDb()->Execute($sQ);
}
}
/**
* Adds user group to discount config
*/
public function addDiscGroup()
{
$oConfig = $this->getConfig();
$aChosenCat = $this->_getActionIds('oxgroups.oxid');
$soxId = $oConfig->getRequestParameter('synchoxid');
if ($oConfig->getRequestParameter('all')) {
$sGroupTable = $this->_getViewName('oxgroups');
$aChosenCat = $this->_getAll($this->_addFilter("select $sGroupTable.oxid " . $this->_getQuery()));
}
if ($soxId && $soxId != "-1" && is_array($aChosenCat)) {
foreach ($aChosenCat as $sChosenCat) {
$oObject2Discount = oxNew("oxbase");
$oObject2Discount->init('oxobject_block2discount');
$oObject2Discount->oxobject_block2discount__oxdiscountid = new oxField($soxId);
$oObject2Discount->oxobject_block2discount__oxobjectid = new oxField($sChosenCat);
$oObject2Discount->oxobject_block2discount__oxtype = new oxField("oxgroups");
$oObject2Discount->save();
}
}
}
}
Klasse mit überladener Funktion, damit die geblockten Benutzergruppen auch berücksichtig werden.:
[B]Name: cm_oxdiscountlist.php[/B]
<?php
class cm_oxdiscountlist extendscm_oxdiscountlist_parent
{
/**
* If any shops category has "skip discounts" status this parameter value will be true
*
* @var bool
*/
protected $_hasSkipDiscountCategories = null;
/**
* Creates discount list filter SQL to load current state discount list
*
* @param object $oUser user object
*
* @return string
*/
protected function _getFilterSelect($oUser)
{
$oBaseObject = $this->getBaseObject();
$sTable = $oBaseObject->getViewName();
$sQ = "select " . $oBaseObject->getSelectFields() . " from $sTable ";
$sQ .= "where " . $oBaseObject->getSqlActiveSnippet() . ' ';
// defining initial filter parameters
$sUserId = null;
$sGroupIds = null;
$sCountryId = $this->getCountryId($oUser);
$oDb = oxDb::getDb();
// checking for current session user which gives additional restrictions for user itself, users group and country
if ($oUser) {
// user ID
$sUserId = $oUser->getId();
// user group ids
foreach ($oUser->getUserGroups() as $oGroup) {
if ($sGroupIds) {
$sGroupIds .= ', ';
}
$sGroupIds .= $oDb->quote($oGroup->getId());
}
}
$sUserTable = getViewName('oxuser');
$sGroupTable = getViewName('oxgroups');
$sCountryTable = getViewName('oxcountry');
$sCountrySql = $sCountryId ? "EXISTS(select oxobject2discount.oxid from oxobject2discount where oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxcountry' and oxobject2discount.OXOBJECTID=" . $oDb->quote($sCountryId) . ")" : '0';
$sUserSql = $sUserId ? "EXISTS(select oxobject2discount.oxid from oxobject2discount where oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxuser' and oxobject2discount.OXOBJECTID=" . $oDb->quote($sUserId) . ")" : '0';
$sGroupSql = $sGroupIds ? "EXISTS(select oxobject2discount.oxid from oxobject2discount where oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxgroups' and oxobject2discount.OXOBJECTID in ($sGroupIds) ) and (select oxid from oxobject_block2discount where oxobject_block2discount.OXDISCOUNTID=$sTable.OXID and oxobject_block2discount.oxtype='oxgroups' and oxobject_block2discount.OXOBJECTID in ($sGroupIds) LIMIT 1) is null" : '0';
$sQ .= "and (
select
if(EXISTS(select 1 from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid and oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxcountry' LIMIT 1),
$sCountrySql,
1) &&
if(EXISTS(select 1 from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid and oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxuser' LIMIT 1),
$sUserSql,
1) &&
if(EXISTS(select 1 from oxobject2discount, $sGroupTable where $sGroupTable.oxid=oxobject2discount.oxobjectid and oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxgroups' LIMIT 1 UNION select 1 from oxobject_block2discount, $sGroupTable where $sGroupTable.oxid=oxobject_block2discount.oxobjectid and oxobject_block2discount.OXDISCOUNTID=$sTable.OXID and oxobject_block2discount.oxtype='oxgroups' LIMIT 1),
$sGroupSql,
1)
)";
return $sQ;
}
}
Die beiden Language Dateien Deutsch/English
[B]Name: cm_lang.php[/B]
<?php
$sLangName = "Deutsch";
// -------------------------------
// RESOURCE IDENTITFIER = STRING
// -------------------------------
$aLang = array(
//Navigation
'charset' => 'ISO-8859-15',
'CM_GENERAL_BLOCKGROUPS' => 'Benutzergruppen blocken',
);
[B]
Name: cm_lang.php[/B]
<?php
$sLangName = "English";
// -------------------------------
// RESOURCE IDENTITFIER = STRING
// -------------------------------
$aLang = array(
//Navigation
'charset' => 'ISO-8859-15',
'CM_GENERAL_BLOCKGROUPS' => 'Block Usersgroups',
);
Hier noch das SQL zum Erstellen der entsprechenden Tabelle in der die geblockten Benutzergruppen abgespeichert werden:
CREATE TABLE oxobject_block2discount like oxobject2discount;
Zur Anmerkung und um Verwirrung zu vermeiden: Wenn Benutzern explizit Rabatte zugeordnet werden, aber die Benutzer in geblockten Benutzergruppen, die für den Rabatt eingestellt wurden, drin sind bekommen Sie den Rabatt nicht.
Falls jemand noch Verbesserungsvorschläge hat oder Fehler findet immer ehr damit. 