Products on joomla article pages

  • Posts: 57
  • Thank you received: 2
12 years 10 months ago #34910

Hi,

I need to display some products with name, descriptio, price and a link to a related product-listing page on joomla article pages based on php code.
I have found the code for displaying products, whose IDs are known, but I only have the product names and their codes, because theese are related on the displaying article. The Hikashop producs class seems to offer no function for that. Is there any other way to do it? Or did I look at the wrong places?

Thanks.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #34942

Hi,

What code are you using ?
There is not one function to retrieve all the information of one product in the product class. You woudl have to look at the function show of the view components/com_hikashop/views/product/view.html.php

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

  • Posts: 57
  • Thank you received: 2
12 years 10 months ago #34965

Hi,

sorry, of course, no single function. I used this code which worked, if I have an ID, which I don't have:

if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){
echo 'This module can not work without the Hikashop Component';
return;
};

$id='15';

$productClass = hikashop_get('class.product');
$product = $productClass ->get($id);
$currencyClass = hikashop_get('class.currency');
$products = array(&$product);
$ids = array($id);
$config =& hikashop_config();
$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;
}
$discount_before_tax = (int)$config->get('discount_before_tax',0);
$currencyClass->getPrices($products,$ids,hikashop_getCurrency(),$main_currency,$zone_id,$discount_before_tax);
error_log("1");
echo "xxxxxxxxxx".$products[0]->product_name.$products[0]->product_code;
error_log("2");



sorry again, the code from the "show" function is much too complex for me.
As I wrote, I only need description and prices for a couple of given product_names. May be you could be a little more specific...

Thanks.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #35000

That's great. You're not missing much.

The product description:
$products[0]->product_description

The price:
$currencyClass->format($products[0]->prices[0]->price_value,$products[0]->prices[0]->price_currency_id)

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

  • Posts: 57
  • Thank you received: 2
12 years 10 months ago #35026

yes, but this is retrieved through the product_id, I only know the product_name of the product, that I am locking for.

Thanks!

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

  • Posts: 57
  • Thank you received: 2
12 years 10 months ago #35031

this works for me, but is it correct (from your point of view)?

<?php

defined('k_buex') or die('Restricted access');


if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) {
echo 'This module can not work without the Hikashop Component';
return;
};


$thenames=array("'Bunken Tech Sans Condensed-Pro-CFF-Book Italic'","'Bunken Tech Sans Condensed-Std-WEB-Survival Pack'");


//Load required Classes
$productClass = hikashop_get('class.product');
$currencyClass = hikashop_get('class.currency');
//prices stuff
$config =& hikashop_config();
$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;
}

//get IDs for Names
$query = 'SELECT product_id FROM '.hikashop_table('product').' WHERE product_name IN ('.implode(',',$thenames).')';
$productClass->database->setQuery($query);
$idarr=$productClass->database->loadResultArray();


if (!$idarr){
print_r("nix drin");
return;
}

foreach ($idarr as $id) {
$product = $productClass ->get($id);
$products = array(&$product);
$ids = array($id);
$currencyClass->getPrices($products,$ids,hikashop_getCurrency(),$main_currency,$zone_id,$discount_before_tax);
echo $currencyClass->format($products[0]->prices[0]->price_value,$products[0]->prices[0]->price_currency_id);

}
?>


Thanks.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #35061

Ah yes. You can do like that yes.
That's not the most efficient way of doing it as the getPrices call will have to do several queries each time but it will work.
You could have done like that:
$query = 'SELECT product_id FROM '.hikashop_table('product').' WHERE product_name IN ('.implode(',',$thenames).')';
$productClass->database->setQuery($query);
$products=$productClass->database->loadObjectList('product_id');

$currencyClass->getPrices($products,array_keys($products),hikashop_getCurrency(),$main_currency,$zone_id,$discount_before_tax);

foreach($products as $product){
echo $currencyClass->format($product->prices[0]->price_value,$product->prices[0]->price_currency_id);
}

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

Time to create page: 0.064 seconds
Powered by Kunena Forum