Product price for different user group

  • Posts: 31
  • Thank you received: 0
7 years 2 months ago #52375

I have normal price for products that is visible for non-registered and registered users (same for both). But I have one more user group "Studio Customers" for which I have different prices. Now I have problem with displaying that price when user is logged as "Studio Customer".

The problem is that the normal prices is also visible in product view, but I want to display only price for that usergroup. So in the end I have 2 product prices visible. It happens only when I'm in product view, in modules and everything it is showing the correct price, only one price for that product group.

p.s.
I'm using Joomla 2.5 and Business HikaShop.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 0
7 years 2 months ago #52376

I found a way in a listing-price.php (added comment in code //manually added), which I hacked a bit, but now I have slight problems :)

1. I'm using simplified registration method, so when user register he automatically log in. This "hack" is not applied in that moment, user needs to log out and log in again for these changes to be visible. Hmmm?!?!
2. From all modules prices somehow dissapear..I guess that is not so normal behavior :)

p.s.
I'm using 3pd plugin, so I can choose Joomla user group within HikaShop registration. Also my Joomla usergroup have ID = 9.

<?php
/**
 * @package		HikaShop for Joomla!
 * @version		1.5.6
 * @author		hikashop.com
 * @copyright	(C) 2010-2012 HIKARI SOFTWARE. All rights reserved.
 * @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>
<span class="hikashop_product_price_full">
    <?php
    if (empty($this->row->prices)) {
        echo JText::_('FREE_PRICE');
    } else {
        $first = true;
        echo JText::_('PRICE_BEGINNING');
        $i = 0;
        foreach ($this->row->prices as $price) {
            if ($first)
                $first = false;
            else
                echo JText::_('PRICE_SEPARATOR');
            if (isset($price->price_min_quantity) && empty($this->cart_product_price) && $price->price_min_quantity > 1) {
                echo '<span class="hikashop_product_price_with_min_qty hikashop_product_price_for_at_least_' . $price->price_min_quantity . '">';
            }
            $classes = array('hikashop_product_price hikashop_product_price_' . $i); 
            if (!empty($this->row->discount)) {
                $classes[] = 'hikashop_product_price_with_discount';
            }
            $user = & JFactory::getUser(); //manually added
            if ((in_array('9', $user->groups)) && ($i == 0) && (isset($_GET['cid']))) { //manually added
                echo ''; //manually added
            }else{ //manually added
                echo '<span class="' . implode(' ', $classes) . '">';

                if ($this->params->get('price_with_tax')) {
                    echo $this->currencyHelper->format($price->price_value_with_tax, $price->price_currency_id);
                }
                if ($this->params->get('price_with_tax') == 2) {
                    echo JText::_('PRICE_BEFORE_TAX');
                }
                if ($this->params->get('price_with_tax') == 2 || !$this->params->get('price_with_tax')) {
                    echo $this->currencyHelper->format($price->price_value, $price->price_currency_id);
                }
                if ($this->params->get('price_with_tax') == 2) {
                    echo JText::_('PRICE_AFTER_TAX');
                }
                if ($this->params->get('show_original_price') && !empty($price->price_orig_value)) {
                    echo JText::_('PRICE_BEFORE_ORIG');
                    if ($this->params->get('price_with_tax')) {
                        echo $this->currencyHelper->format($price->price_orig_value_with_tax, $price->price_orig_currency_id);
                    }
                    if ($this->params->get('price_with_tax') == 2) {
                        echo JText::_('PRICE_BEFORE_TAX');
                    }
                    if ($this->params->get('price_with_tax') == 2 || !$this->params->get('price_with_tax')) {
                        echo $this->currencyHelper->format($price->price_orig_value, $price->price_orig_currency_id);
                    }
                    if ($this->params->get('price_with_tax') == 2) {
                        echo JText::_('PRICE_AFTER_TAX');
                    }
                    echo JText::_('PRICE_AFTER_ORIG');
                }

                echo '</span> ';
                if (!empty($this->row->discount)) {
                    if ($this->params->get('show_discount') == 1) {
                        echo '<span class="hikashop_product_discount">' . JText::_('PRICE_DISCOUNT_START');
                        if (bccomp($this->row->discount->discount_flat_amount, 0, 5) !== 0) {
                            echo $this->currencyHelper->format(-1 * $this->row->discount->discount_flat_amount, $price->price_currency_id);
                        } elseif (bccomp($this->row->discount->discount_percent_amount, 0, 5) !== 0) {
                            echo -1 * $this->row->discount->discount_percent_amount . '%';
                        }
                        echo JText::_('PRICE_DISCOUNT_END') . '</span>';
                    } elseif ($this->params->get('show_discount') == 2) {
                        echo '<span class="hikashop_product_price_before_discount">' . JText::_('PRICE_DISCOUNT_START');
                        if ($this->params->get('price_with_tax')) {
                            echo $this->currencyHelper->format($price->price_value_without_discount_with_tax, $price->price_currency_id);
                        }
                        if ($this->params->get('price_with_tax') == 2) {
                            echo JText::_('PRICE_BEFORE_TAX');
                        }
                        if ($this->params->get('price_with_tax') == 2 || !$this->params->get('price_with_tax')) {
                            echo $this->currencyHelper->format($price->price_value_without_discount, $price->price_currency_id);
                        }
                        if ($this->params->get('price_with_tax') == 2) {
                            echo JText::_('PRICE_AFTER_TAX');
                        }
                        if ($this->params->get('show_original_price') && !empty($price->price_orig_value_without_discount_with_tax)) {
                            echo JText::_('PRICE_BEFORE_ORIG');
                            if ($this->params->get('price_with_tax')) {
                                echo $this->currencyHelper->format($price->price_orig_value_without_discount_with_tax, $price->price_orig_currency_id);
                            }
                            if ($this->params->get('price_with_tax') == 2) {
                                echo JText::_('PRICE_BEFORE_TAX');
                            }
                            if ($this->params->get('price_with_tax') == 2 || !$this->params->get('price_with_tax') && !empty($price->price_orig_value_without_discount)) {
                                echo $this->currencyHelper->format($price->price_orig_value_without_discount, $price->price_orig_currency_id);
                            }
                            if ($this->params->get('price_with_tax') == 2) {
                                echo JText::_('PRICE_AFTER_TAX');
                            }
                            echo JText::_('PRICE_AFTER_ORIG');
                        }
                        echo JText::_('PRICE_DISCOUNT_END') . '</span>';
                    } elseif ($this->params->get('show_discount') == 3) {
                        
                    }
                }
                if (isset($price->price_min_quantity) && empty($this->cart_product_price)) {
                    if ($price->price_min_quantity > 1) {
                        echo JText::sprintf('PER_UNIT_AT_LEAST_X_BOUGHT', $price->price_min_quantity);
                    } else {
                        echo JText::_('PER_UNIT');
                    }
                }

                if ($this->params->get('show_price_weight')) {
                    if (!empty($this->element->product_id) && isset($this->row->product_weight) && bccomp($this->row->product_weight, 0, 3)) {
                        echo JText::_('PRICE_SEPARATOR') . '<span class="hikashop_product_price_per_weight_unit">';
                        if ($this->params->get('price_with_tax')) {
                            $weight_price = $price->price_value_with_tax / $this->row->product_weight;
                            echo $this->currencyHelper->format($weight_price, $price->price_currency_id) . ' / ' . JText::_($this->row->product_weight_unit);
                        }
                        if ($this->params->get('price_with_tax') == 2) {
                            echo JText::_('PRICE_BEFORE_TAX');
                        }
                        if ($this->params->get('price_with_tax') == 2 || !$this->params->get('price_with_tax')) {
                            $weight_price = $price->price_value / $this->row->product_weight;
                            echo $this->currencyHelper->format($weight_price, $price->price_currency_id) . ' / ' . JText::_($this->row->product_weight_unit);
                        }
                        if ($this->params->get('price_with_tax') == 2) {
                            echo JText::_('PRICE_AFTER_TAX');
                        }
                        echo '</span>';
                    }
                }
                if (isset($price->price_min_quantity) && empty($this->cart_product_price) && $price->price_min_quantity > 1) {
                    echo '</span>';
                }
            }//manually added
            $i++;
        }

        echo JText::_('PRICE_END');
    }
    ?></span>

Last edit: 7 years 2 months ago by zvone.

Please Log in or Create an account to join the conversation.

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
7 years 2 months ago #52430

There should be no need for hacks to do that.
Just set the access levels to the prices so that one is limited to registered/unregistered users and the other one to that special group. Make sure that a user in the special group is not in the registered group in the joomla user group manager as otherwise he would see both prices as you had.

The following user(s) said Thank You: zvone

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 0
7 years 2 months ago #52443

Oh my...

The problem was that I didn't changed product price permissions for public/registered useres, I thought it automatically display only one price if someone is from other user group.

Thanks very much on help.

Please Log in or Create an account to join the conversation.

  • Posts: 25
  • Thank you received: 0
5 months 2 weeks ago #304495

I need to do the same thing for "regions"

We need different prices for different locations/states based on zipcodes, but cant do it based off access levels because users are not logged in.

Where can I modify this object $this->row->prices in listing_price.php ? Ive found a lot of items relating to this in currency.php, however nothing I can find will modify or add items to this object.


Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
5 months 1 week ago #304503

Hi,

If the users are not logged in, how do you know their zip code ?

It is indeed in administrator/components/com_hikashop/classes/currency.php that the prices are loaded.
The prices are loaded with two functions: getPrices and getProductsPrices
In both, the prices are loaded from the database with the line:
$prices = $this->database->loadObjectList();
and then, they are filtered out based on the different restrictions etc.
So what you could do is add your custom code just after that line to add or remove prices to that $prices array based on the region of the user.

The following user(s) said Thank You: cworthen75

Please Log in or Create an account to join the conversation.

  • Posts: 25
  • Thank you received: 0
5 months 1 week ago #304523

Thank you for the reply.

We have a little custom code that we ask the customer for their zipcode if not logged in.

We could utilize your current tax system if we can pass that zipcode and match it to the zipcode in the Tax Rule.

What would the best way to go about passing this variable on the product listing page to the functions you mentioned earlier?

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 25
  • Thank you received: 0
5 months 1 week ago #304528

Im also noticing there is a getListingPrices function. If we modify the getPrices function will that trickle down into the getListingPrices ?

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 25
  • Thank you received: 0
5 months 1 week ago #304540

Ive actually got it figured out.

Only thing Im still trying to figure out is when I change Product tax category to a different category (in Tax rule), the tax no longer takes effect.

Can you explain what Im doing wrong or how to fix?

Thank you!:) :) :) :) :)

Please Log in or Create an account to join the conversation.

  • Posts: 25
  • Thank you received: 0
5 months 1 week ago #304541

Nevermind, I guess thats because it has to be tied to the product. No more help needed for now.

Thank you!

Please Log in or Create an account to join the conversation.

Time to create page: 0.079 seconds
Powered by Kunena Forum