- Posts: 61
- Thank you received: 3
Get product price
- demoisellegol
-
Topic Author
- Offline
Less
More
2 years 6 months ago #359659
by demoisellegol
Get product price was created by demoisellegol
-- 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)
-- 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.
2 years 6 months ago #359668
by nicolas
Replied by nicolas on topic Get product price
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:
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:
Code:
<?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.
- demoisellegol
-
Topic Author
- Offline
Less
More
- Posts: 61
- Thank you received: 3
2 years 6 months ago #359689
by demoisellegol
Replied by demoisellegol on topic Get product price
thank you alot
the shortcode 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
the shortcode 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.
2 years 6 months ago #359697
by nicolas
Replied by nicolas on topic Get product price
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 ?
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.
- demoisellegol
-
Topic Author
- Offline
Less
More
- Posts: 61
- Thank you received: 3
2 years 6 months ago #359828
by demoisellegol
Replied by demoisellegol on topic Get product price
Please Log in or Create an account to join the conversation.
- demoisellegol
-
Topic Author
- Offline
Less
More
- Posts: 61
- Thank you received: 3
2 years 6 months ago #359829
by demoisellegol
Replied by demoisellegol on topic Get product price
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 !!
$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.278 seconds