Is there as way to display the vendor's name with the productin the cart?

  • Posts: 238
  • Thank you received: 21
  • Hikamarket Multivendor Hikashop Business Hikashop Essential
3 weeks 6 days ago #362061

-- HikaShop version -- : 5.1.0
-- HikaMarket version -- : 4.1.1
-- Joomla version -- : 4.4.6
-- PHP version -- : 8.1.29

On the product page, when "Sold by" is enabled, it displays "Sold by <vendor name>.

Is there a way to display the vendor's name in cart/show.php next to each product's name?

I thought it would be called via:

<?php
	if(!empty($this->extra_data['products'])) {
		foreach($this->extra_data['products'] as $key => $content) {
?>			<td class="hikashop_order_item_<?php echo $key; ?>_value"><?php
				if(isset($product->extra_data[$key]))
					echo $product->extra_data[$key];
			?>

The name appears in emails and the backend order, but we want to display it in the cart and checkout.

Thanks!

Last edit: 3 weeks 6 days ago by jazzmang. Reason: Added code reference

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

  • Posts: 26090
  • Thank you received: 4018
  • MODERATOR
3 weeks 4 days ago #362066

Hello,

That's right, HikaMarket does load the vendor data during "product listing" but it doesn't load them during the "cart load" or "cart display".
Loading that data every time would be unoptimized since the cart is loaded a lot of time and you don't need to display the vendor name every time. For the "cart display", since you can have multiple displays, it could perform multiple time the same job.

It would require the right way to only load when necessary.
Otherwise, it would need to add some code in the HikaShop view in order to list the vendors in the cart and load their data.
You can see similar code in HikaShop, in the "product class" with the function "processViewFront" or in the "mail class" in the function "processOrdernotificationTemplate".

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.

  • Posts: 238
  • Thank you received: 21
  • Hikamarket Multivendor Hikashop Business Hikashop Essential
3 weeks 3 days ago #362088

We have the cart set to limit to one vendor, so I really only need to display it once.

Does that make a difference in avoiding multiple calls or in how to handle adding the extra code?

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

  • Posts: 238
  • Thank you received: 21
  • Hikamarket Multivendor Hikashop Business Hikashop Essential
3 weeks 3 days ago #362089

Jerome wrote: You can see similar code in HikaShop, in the "product class" with the function "processViewFront" or in the "mail class" in the function "processOrdernotificationTemplate".


I've done a text search for those function names and cannot find them.

I looked in classes/product.php and classes/mail.php, too, but did not find them either.

Can you point me to where these functions are in 5.1.0?

Last edit: 3 weeks 3 days ago by jazzmang.

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

  • Posts: 26090
  • Thank you received: 4018
  • MODERATOR
3 weeks 3 days ago #362093

Hello,

We're talking about HikaMarket ; not HikaShop.
HikaMarket 5.1.0 doesn't exist, yet.
www.hikashop.com/support/documentation/1...arket-changelog.html

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.
The following user(s) said Thank You: jazzmang

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

  • Posts: 238
  • Thank you received: 21
  • Hikamarket Multivendor Hikashop Business Hikashop Essential
3 weeks 2 days ago #362113

Sorry, I misunderstood which software classes you were referencing.

I was thinking of HikaShop because the ultimate target was the shopping cart view.

I believe I got it worked out to display what I wanted.

In case someone else was interested, this is what I came up with:

	$db = JFactory::getDBO();
	$app = JFactory::getApplication();
        $config = hikamarket::config();
        $vendor_id = $product->product_vendor_id;
        $query = 'SELECT * FROM '.hikamarket::table('vendor').' WHERE vendor_id = ' . $vendor_id;
	$db->setQuery($query);
        $vendor = $db->loadObject();
        $vendor->alias = (empty($vendor->vendor_alias)) ? $vendor->vendor_name : $vendor->vendor_alias;
	$vendorLink = '<a href="'.hikamarket::completeLink('vendor&task=show&cid=' . $vendor->vendor_id . '&name=' . $vendor->alias ).'">' . $vendor->vendor_name . '</a>';
	echo '<br/><span class="hikamarket_vendor">' .JText::sprintf('SOLD_BY_VENDOR', $vendorLink). '</span>';

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

  • Posts: 26090
  • Thank you received: 4018
  • MODERATOR
3 weeks 2 days ago #362114

Hello,

For optimisation, the best is to perform a loop in order to collect all vendors.

$vendor_ids = [1 => 1];
foreach($cart->products as $product) {
    $vendor_id = (int)$product->product_vendor_id;
    if($vendor_id > 0)
        $vendor_ids[$vendor_id] = $vendor_id;
}
Then load all vendors of your cart
$query = 'SELECT vendor_id, vendor_name, vendor_alias FROM '.hikamarket::table('vendor').' WHERE vendor_id IN ('.implode(',', $vendor_ids).')';
$db = JFactory::getDBO();
$db->setQuery($query);
$vendors = $db->loadObjectList('vendor_id');
Then in your listing you can retrieve the vendor
$vendor = $vendors[(int)$product->product_vendor_id ?? 1];
And display its name and generate the SEF URL with alias.

By doing that, you will have just one SQL query to load all vendors ; otherwise you are doing one SQL query per item in the cart.

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.

Moderators: Obsidev
Time to create page: 0.078 seconds
Powered by Kunena Forum