Skip to content

Commit

Permalink
Show groups in current shop context, only.
Browse files Browse the repository at this point in the history
Provided by @chitmann with pull request #876, thank you very much!

Traumflug's review edits:

 - Squashed 11 commits into one.

 - Some whitespace nitpicking.

 - Used 'sg' instead of 'shop_group' in SQL code to meet
   formatting guidelines.

 - Backticks around field names in SQL code for the same reason.

 - Moved method description from the commit message to the method
   comment.
  • Loading branch information
chitzmann authored and Traumflug committed May 2, 2019
1 parent a2767f3 commit 469a569
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions classes/Group.php
Expand Up @@ -97,7 +97,11 @@ public function __construct($id = null, $idLang = null, $idShop = null)

/**
* @param int $idLang
* @param int|bool $idShop
* @param int|bool $idShop: false --> Return all groups.
* true --> Return groups associated with
* current shop (from context).
* number --> Return groups associated with the
* specific shop with this ID.
*
* @return array|false|mysqli_result|null|PDOStatement|resource
*
Expand All @@ -109,15 +113,17 @@ public function __construct($id = null, $idLang = null, $idShop = null)
public static function getGroups($idLang, $idShop = false)
{
$shopCriteria = '';
if ($idShop) {
if (is_int($idShop)) {
$shopCriteria = ' INNER JOIN `'._DB_PREFIX_.'group_shop` gs ON (gs.`id_group` = g.`id_group` AND gs.`id_shop` = '.$idShop.')';
} elseif ($idShop) {
$shopCriteria = Shop::addSqlAssociation('group', 'g');
}

return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
(new DbQuery())
->select('DISTINCT g.`id_group`, g.`reduction`, g.`price_display_method`, gl.`name`')
->from('group', 'g')
->leftJoin('group_lang', 'gl', 'g.`id_group` = gl.`id_group` AND gl.`id_lang` = '.(int) $idLang)
->leftJoin('group_lang', 'gl', 'g.`id_group` = gl.`id_group` AND gl.`id_lang` = '.(int) $idLang.$shopCriteria)
->orderBy('g.`id_group` ASC')
);
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminCategoriesController.php
Expand Up @@ -685,7 +685,7 @@ public function renderForm()
'type' => 'group',
'label' => $this->l('Group access'),
'name' => 'groupBox',
'values' => Group::getGroups($this->context->language->id),
'values' => Group::getGroups($this->context->language->id, true),
'info_introduction' => $this->l('You now have three default customer groups.'),
'unidentified' => $unidentifiedGroupInformation,
'guest' => $guestGroupInformation,
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminPaymentController.php
Expand Up @@ -297,7 +297,7 @@ public function renderView()
'icon' => 'icon-money',
],
[
'items' => Group::getGroups($this->context->language->id),
'items' => Group::getGroups($this->context->language->id, true),
'title' => $this->l('Group restrictions'),
'desc' => $this->l('Please mark each checkbox for the customer group(s), for which you want the payment module(s) to be available.'),
'name_id' => 'group',
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminProductsController.php
Expand Up @@ -3844,7 +3844,7 @@ public function initFormPrices($obj)
if ($obj->id) {
$shops = Shop::getShops();
$countries = Country::getCountries($this->context->language->id);
$groups = Group::getGroups($this->context->language->id);
$groups = Group::getGroups($this->context->language->id, true);
$currencies = Currency::getCurrencies();
$attributes = $obj->getAttributesGroups((int) $this->context->language->id);
$combinations = [];
Expand Down

0 comments on commit 469a569

Please sign in to comment.