Create Related Products column in Administrator

  • Posts: 12
  • Thank you received: 0
10 years 1 month ago #174300

Hello,

I'm trying to change the Administrator products listing to show the related products link in the list. (image in attachment




So far i was able to add the Title by adding the <td> on the right place.

My difficulty now is that i cannot get the related products title in the fields.
I enter this code in the product/listing.php file:

<td align="center">
<?php if($this->manage){ ?>
<a href="<?php echo hikashop_completeLink('product&task=edit&cid[]='.$row->product_related_id); ?>">
<?php } ?>
<?php echo $row->product_name; ?>
<?php if($this->manage){ ?>
</a>
<?php } ?>
</td>

But what i get is only the same product name...
Can you please tell me what can i do to make this possible?

Attachments:

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 1 month ago #174342

Hi,

Doing such modification require some development/PHP skills.
You have to perform an SQL query in order to get the related products for the products you will list.
For the moment the code display the product name of the current product in the loop ; but if you do not have loaded the related products, you won't be able to display them.

$query = 'SELECT a.*,b.* FROM '.hikashop_table('product_related').' AS a LEFT JOIN '.hikashop_table('product').' AS b ON a.product_related_id=b.product_id WHERE a.product_related_type=\'related\' AND a.product_id = '.$row->product_id;
$database->setQuery($query);
$related_products = $database->loadObjectList();

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Last edit: 10 years 1 month ago by Jerome.

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

  • Posts: 12
  • Thank you received: 0
10 years 1 month ago #174472

Thanks for the reply.

I'm sorry i'm still "very young" on PHP coding.

I'm trying to apply this to the code but i'm not having results with it.

Im doing this:

<td>
<?php 
$query = 'SELECT a.*,b.* FROM '.hikashop_table('product_related').' AS a LEFT JOIN '.hikashop_table('product').' AS b ON 										a.product_related_id=b.product_id WHERE a.product_related_type=\'related\' AND a.product_id = '.$row->product_id;
$database->setQuery($query);
$related_products = $database->loadObjectList();
?>
<?php echo $row->product_name; ?>
</td>

I'm calling the product_name after requesting the query but it's not working.

Can you help with this little bit of code?

Thanks

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

  • Posts: 12953
  • Thank you received: 1778
10 years 1 month ago #174511

Hello,
The code that Jerome gave you will just allow you to load the related products details on the "$related_products" object, now you'll just have to check what you have on that object and display the link of your related products.
Using that kind of code will probably do the job :

$database = JFactory::getDBO();
$query = 'SELECT a.*,b.* FROM '.hikashop_table('product_related').' AS a LEFT JOIN '.hikashop_table('product').' AS b ON a.product_related_id=b.product_id WHERE a.product_related_type=\'related\' AND a.product_id = '.$row->product_id;
$database->setQuery($query);
$related_products = $database->loadObjectList();
foreach($related_products as $key => $related_product){
    if(!empty($related_product)){
?>
<a href="<?php echo hikashop_completeLink('product&task=edit&cid[]='.$related_product->product_id); ?>">
<?php 
        echo $related_product->product_name.'</br>';
?>
</a><?php
}
}

Last edit: 10 years 1 month ago by Mohamed Thelji.

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

  • Posts: 12
  • Thank you received: 0
10 years 1 month ago #174566

Thanks for the reply... i try it under the <td></td> and it didn't work... i'm getting a blank page...

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

  • Posts: 12
  • Thank you received: 0
10 years 1 month ago #174623

IT's working now...

This is what i have done:

<td>
<?php
$database = JFactory::getDBO();
$query = 'SELECT a.*,b.* FROM '.hikashop_table('product_related').' AS a LEFT JOIN '.hikashop_table('product').' AS b ON a.product_related_id=b.product_id WHERE a.product_related_type=\'related\' AND a.product_id = '.$row->product_id;
$database->setQuery($query);
$related_products = $database->loadObjectList();
foreach($related_products as $key => $related_product){
 if(!empty($related_product)){
?>
<a href="<?php echo hikashop_completeLink('product&task=edit&cid[]='.$related_product->product_id); ?>">
<?php
 echo $related_product->product_name.'</br>';
?>
</a>
<?php
}
}
?>								
</td>

Many thanks for your support!

Best Regards,

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 1 month ago #174639

Hi,

Good to know that it is working now.

When you got full blank page, do not hesitate to check your PHP error log or to activate the Joomla debug mode (in the joomla global configuration).
You can also change the "error reporting" to "maxium" in the Joomla global configuration (server).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

Time to create page: 0.082 seconds
Powered by Kunena Forum