/*
* Used in view functions and in checkout when adding or updating cart
*/
public function canDisplayAddtocart()
{
$display_addtocart = $this->params->get('display_addtocart', 1);
$display_addtocart_access_levels = $this->params->get('display_addtocart_access_levels', '');
// 0) Display price for no one
if ($display_addtocart == 0) {
return false;
}
// 1) Display price for all
if ($display_addtocart == 1) {
return true;
}
// 2) Based on access levels
if ($display_addtocart == 2) {
$levels = $this->user->getAuthorisedViewLevels();
if (!is_array($display_addtocart_access_levels)) {
if (in_array((int) $display_addtocart_access_levels, $levels)) {
return true;
}
} else {
if (count(array_intersect($display_addtocart_access_levels, $levels))) {
return true;
}
}
return false;
}
// 3) Based on customer group
// If user is inside at least on customer group which allows displaying the add to cart, the add to cart can be displayed for him
if ($display_addtocart == 3) {
$userGroups = PhocacartGroup::getGroupsById($this->user->id, 1, 2);
if (!empty($userGroups)) {
foreach ($userGroups as $k => $v) {
if ($v['display_addtocart'] == 1 && $v['published'] == 1) {
return true;
}
}
}
return false;
}
return true;
// As default, display add to cart
}