SOLVED - Display Product List with Variants

  • Posts: 24
  • Thank you received: 1
12 years 1 month ago #66329

I'm looking for a way to create a product list/table that shows all available products, including all children. The idea behind this is allowing the user to simply add all the items he wants to the cart instead of having to choose between variants on all the product pages.
What I got so far, is reading directly from the database and displaying all the product info I want:

<?php
$myDatabase = JFactory::getDBO();
$query = "SELECT * FROM #__hikashop_product WHERE 1";
$myDatabase->setQuery($query);
$result = $myDatabase->query();
$rows = $myDatabase->loadAssocList();
?>

<table>
	<tr>
		<td>name</td>
		<td>code</td>
	</tr>
<?php
foreach($rows as $row){ 
	if(!strstr($row['product_code'],"N")){
?>
	<tr>
		<td><?php echo $row['product_name']; ?></td>
		<td><?php echo $row['product_code']; ?></td>
	</tr>
<?php }} ?>
</table>

Displaying the correct prices, however, is way more difficult. We have different discounts, currencies...
Is there any way to do this properly?

Thanks for any help,
nik

Last edit: 12 years 1 month ago by nik.mess.

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

  • Posts: 82818
  • Thank you received: 13362
  • MODERATOR
12 years 1 month ago #66516

For the prices, it's quite easy.
You should call the getListingPrices function of the class.currency of HikaShop:
$class = hikashop_get('class.currency');
$class->getListingPrices($rows,hikashop_getZone(),hikashop_getCurrency());

the prices will then be in the attribute prices of each element of $rows.

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

  • Posts: 24
  • Thank you received: 1
12 years 1 month ago #66544

I tried to implement your method. However, there is no attribute prices when I print $rows with print_r. This:

$query = "SELECT * FROM #__hikashop_product WHERE 1";
$myDatabase->setQuery($query);
$result = $myDatabase->query();
$productRows = $myDatabase->loadAssocList();
$myCurrencyHelper = hikashop_get('class.currency');
$myCurrencyHelper->getListingPrices($productRows,hikashop_getZone(),hikashop_getCurrency());
print_r($productRows);
just gives me a lot of this:
Array ( [0] => Array ( [product_id] => 3177 [product_parent_id] => 3128 [product_name] => random name [product_description] => [product_quantity] => -1 [product_code] => 1234-5678 [product_published] => 1 [product_hit] => 0 [product_created] => 1347941053 [product_sale_start] => 0 [product_sale_end] => 0 [product_delay_id] => 0 [product_tax_id] => 0 [product_type] => variant [product_vendor_id] => 0 [product_manufacturer_id] => 0 [product_url] => [product_weight] => 0.000 [product_keywords] => [product_weight_unit] => kg [product_modified] => 1347941053 [product_meta_description] => [product_dimension_unit] => m [product_width] => 0.000 [product_length] => 0.000 [product_height] => 0.000 [product_max_per_order] => 0 [product_access] => all [product_group_after_purchase] => [product_min_per_order] => 0 [product_contact] => 0 [product_last_seen_date] => 0 [product_sales] => 0 [product_waitlist] => 0 [product_layout] => [product_average_score] => 0 [product_total_vote] => 0 [product_page_title] => [label_color] => multi-color [amount] => ) [1] => Array (...

What should I pass to
getListingPrices()
?

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

  • Posts: 82818
  • Thank you received: 13362
  • MODERATOR
12 years 1 month ago #66660

The problem is that you're using loadAssocList to load your products list.
We always use loadObjectList in HikaShop in such case.
You should give to that function an array of product objects and not an array of arrays and it will work.

The following user(s) said Thank You: nik.mess

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

  • Posts: 24
  • Thank you received: 1
12 years 1 month ago #66831

Thank you very much! Got it working with objects.

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

Time to create page: 0.059 seconds
Powered by Kunena Forum