How could I get the price of the product in php?

  • Posts: 2293
  • Thank you received: 315
9 years 3 months ago #210396

-- HikaShop version -- : 2.5.0
-- Joomla version -- : 5.4.3
-- PHP version -- : 5.6.3

I am try to modify search results so they can output the price of the products.

I am using this code to get the product by its id:

$productClass = hikashop_get('class.product');

$product=$productClass->get($product_id);

But I don't get the price of the product.

Yes, I can get it from the database but may be there are any ways to do it by your methods from the class?


Я не явлюсь официальной службой поддержки!
Я здесь добровольно!

Хочешь получить купон на скидку Hikashop? Спроси меня как!

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
9 years 3 months ago #210417

Hi,

You can get the prices of the product like this:

$config =& hikashop_config();
		$currencyClass = hikashop_get('class.currency');
		$main_currency = $currency_id = (int)$config->get('main_currency',1);
	 	$zone_id = explode(',',$config->get('main_tax_zone',0));

		if(count($zone_id)){
			$zone_id = array_shift($zone_id);
		}else{
			$zone_id=0;
		}
		$ids = array($product->product_id);
		$discount_before_tax = (int)$config->get('discount_before_tax',0);
		$currencyClass->getPrices($product,$ids,$currency_id,$main_currency,$zone_id,$discount_before_tax);
The prices of the product will be in a "prices" array in the $product object.

The following user(s) said Thank You: progreccor

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

  • Posts: 12
  • Thank you received: 0
9 years 3 months ago #211938

Hi

That code is not working here, but it seems to be a common issue (people cant load the prices).
Why not extend the hikashopProductClass with a 'getPrices($includetax)' method instead? (or something of the likes)

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
9 years 3 months ago #211941

Hi,

That code works fine, so you must be missing something in what you have before and/or after it.

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

Time to create page: 0.070 seconds
Powered by Kunena Forum