Merge branch 'ticket/r12890-upgrade-give-a-gift-2' into dev

This commit is contained in:
Rodney Figaro 2017-04-27 17:45:28 +02:00
commit d22dc86e3d
2 changed files with 14 additions and 38 deletions

View File

@ -815,9 +815,20 @@ class GiveAGift extends Module
*/
public function getRangesFilteredBy(array $category_ids, $customer, $full_informations = false, $active = false)
{
$config_groups = $this->getConfigCustomerGroups();
$customer_category_ids = $customer->getCategoriesReductionFilteredByGroups($config_groups);
// checked if gifts are allowed to be displayed for this customer
$keys_config_group_ids = array_flip($this->getConfigCustomerGroups());
$is_allowed = false;
foreach ($customer->getGroups() as $id_group) {
if (isset($keys_config_group_ids[$id_group])) {
$is_allowed = true;
}
}
if (!$is_allowed) {
return array();
}
// get all gifts for the given categories
$ranges = array();
$gifts = $this->getAllGifts($full_informations, $active);
@ -825,8 +836,7 @@ class GiveAGift extends Module
{
$product = new Product($gift['gift_product']);
// product must be in the given categories and the group categories
if (!(in_array($product->id_category_default, $category_ids) &&
in_array($product->id_category_default, $customer_category_ids))) {
if (!in_array($product->id_category_default, $category_ids)) {
continue;
}

View File

@ -104,38 +104,4 @@ class Customer extends CustomerCore
return self::$_customer_groups_cat_reduc[$id_customer];
}
/**
* Ticket 12890
* @return array of the categories of the customer
*/
private static $_customer_cat = array();
public function getCategoriesReductionFilteredByGroups(array $group_ids)
{
$id_customer = $this->id;
if (isset(self::$_customer_cat[$id_customer])) {
return self::$_customer_cat[$id_customer];
}
self::$_customer_cat[$id_customer] = array();
$result = Db::getInstance()->executeS('
SELECT cg.`id_group`, gr.`id_category`
FROM '._DB_PREFIX_.'customer_group cg
JOIN '._DB_PREFIX_.'group_reduction gr ON gr.id_group = cg.id_group
WHERE cg.`id_customer` = '.(int)$this->id.'
AND cg.`id_group` IN ('.implode(',', array_map('pSQL', $group_ids)).')'
);
foreach ($result as $group) {
if (!isset(self::$_customer_cat[$id_customer])) {
self::$_customer_cat[$id_customer] = array();
}
self::$_customer_cat[$id_customer][] = (int)$group['id_category'];
}
return self::$_customer_cat[$id_customer];
}
}