Back to PhocacartAccessRights class

Method canDisplayPrice

public
canDisplayPrice
()

Method canDisplayPrice - Source code

public function canDisplayPrice()
{
    $display_price = $this->params->get('display_price', 1);
    $display_price_access_levels = $this->params->get('display_price_access_levels', '');
    // 0) Display price for no one
    if ($display_price == 0) {
        return false;
    }
    // 1) Display price for all
    if ($display_price == 1) {
        return true;
    }
    // 2) Based on access levels
    if ($display_price == 2) {
        $levels = $this->user->getAuthorisedViewLevels();
        if (!is_array($display_price_access_levels)) {
            if (in_array((int) $display_price_access_levels, $levels)) {
                return true;
            }
        } else {
            if (count(array_intersect($display_price_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 price, the price can be displayed for him
    if ($display_price == 3) {
        $userGroups = PhocacartGroup::getGroupsById($this->user->id, 1, 2);
        if (!empty($userGroups)) {
            foreach ($userGroups as $k => $v) {
                if ($v['display_price'] == 1 && $v['published'] == 1) {
                    return true;
                }
            }
        }
        return false;
    }
    return true;
    // As default, display prices
}