Get product price

  • Posts: 52
  • Thank you received: 3
9 months 1 week ago #359659

-- HikaShop version -- : 5.0.3
-- Joomla version -- : 5
-- PHP version -- : 8.1

Hi.
I have my product id in a third party component in my website. how can i display the product price there just like the way i show it in hikashop ? (with or without discount)

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

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
9 months 1 week ago #359668

Hi,

You could use a content tag:
www.hikashop.com/support/documentation/1...-product-insert.html
That's an easy way to display a product (name, price, add to cart button, etc) anywhere on your website, as long as you have the product_id since it doesn't require any coding.

Now, if you want to get the price of a product programatically and you only have the id of the product, you can do like this:

<?php 
// load HikaShop
if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }

// get the product's main data
$productClass = hikashop_get('class.product');
$product = $productClass->get($product_id);

// load the prices
$ids = array($product_id);
$options = array('no_discounts' => false);
$currencyClass = hikashop_get('class.currency');
$currencyClass->getProductPrices($product, $ids, $options);

// a product can potentially have several prices (for different quantities for example)
$prices = $product->prices;

// display the prices
foreach($prices as $price) {
 echo $currencyClass->format($price->price_value_with_tax, $price->price_currency_id);
}

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

  • Posts: 52
  • Thank you received: 3
9 months 1 week ago #359689

thank you alot
the shortcode {product}{/product} doesnt worked in my code. (I'm using it in minitek livesearch module)

the code you sent worked very well but it just showed the original price, not the price after discount applied on

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

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
9 months 6 days ago #359697

Hi,

The shortcode can work anywhere on the website. If it doesn't get replaced, I can only think that you didn't use it in a correct way, or the "HikaShop product tag translation plugin" is disabled in the Joomla plugins manager ( that's the plugin which converts the code to the actual HTML).

Regarding the price with discount, it's hard to say why without more information on how you're using the code.
For example, the function getProductPrices will load the discounts based on the current user user groups.
If the discounts you're using are restricted based on the user group, based on the context where you're running this code, the current user might not have access to the discounts.
Could you provide more information on the context ? What is the full code you're using ? How is the code called ? How did you add it to minitek livesearch module ?
And could you provide a screenshot of the settings of a discount which is not taken into account ?

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

  • Posts: 52
  • Thank you received: 3
9 months 2 days ago #359828

i havent any restriction on user groups
the only restriction is that i set the discount end date

i have created a template override for miniteklivesearch module and placed the code in there

I attached the screenshot

Attachments:

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

  • Posts: 52
  • Thank you received: 3
9 months 2 days ago #359829

in the code you sent, i changed

$options = array('no_discounts' => false);

to

$options = array('no_discounts' => true);

and now I'm getting discounted price !!

The following user(s) said Thank You: nicolas

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

Time to create page: 0.069 seconds
Powered by Kunena Forum