Main product name in order view

  • Posts: 764
  • Thank you received: 59
  • Hikashop Business
11 months 2 weeks ago #274699

Hi,

Could someone give me quick tip how to get main product name in show->order view.

Successfully done in cart and product views with "&product->main_product_name;" but cant find a way to do it in order view.

I need to separate product name from characteristic values...

Thanks

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

  • Posts: 1776
  • Thank you received: 247
  • MODERATOR
11 months 2 weeks ago #274715

Hello,

Sorry but I'm not sure to understand the context can you add a screenshot to see on which view you want this ?
Awaiting news from you.

Regards

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

  • Posts: 764
  • Thank you received: 59
  • Hikashop Business
11 months 2 weeks ago #274721

Hi,

As I said I need it in the order show view. Image attached.

Tried something like this but it doesn't work:

$product->order_main_product_name;

Also did var_dump but don't see main product name there...

Thanks

Attachments:

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

  • Posts: 155
  • Thank you received: 58
  • Hikashop Business
11 months 2 weeks ago #274779

Hi,

three possible ways to do it:
- if you use a colon ( : ) or other character in your product titles to separate the main product name and characteristic name, you can simply do a substring up to the colon to get the main product name

- if not, the characteristic name is available in the value $product->characteristic_value, so you can subtract this from your $product->order_product_name to get only the main product name


Or if you really need to, you can load the main product and get its name. First load the product class:

$productClass = hikashop_get('class.product');
Then in the foreach product loop get the main product name if it has a product_parent_id value other than zero:
if($productData->product_parent_id){
	echo $productClass->get($product->product_parent_id)->product_name;
}

Hope that helps.

The following user(s) said Thank You: kyratn

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

  • Posts: 764
  • Thank you received: 59
  • Hikashop Business
11 months 2 weeks ago #274780

Hi,

Thanks GW.
Not sure why but I don't like substring...Used foreach loop and that did the trick.

Have a great evening

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

  • Posts: 764
  • Thank you received: 59
  • Hikashop Business
11 months 1 week ago #275503

Hi,

Another issue here.
Added image and main product name to order details. All shows fine. However after pressing button print in vex pop up the image and product name disappears. Image shows barcode img instead product image... Can't find why would this happen. Any help here?

This is the part of code where image and product name is generated:

<?php
	$k=0;
	$group = $this->config->get('group_options',0);
    $productClass = hikashop_get('class.product');
    $imageHelper = hikashop_get('helper.image');
    $width = (int)$this->config->get('cart_thumbnail_x', 100);
	$height = (int)$this->config->get('cart_thumbnail_y', 144);
	$image_options = array(
		'default' => true,
		'forcesize' => $this->config->get('image_force_size', true),
		'scale' => $this->config->get('image_scale_mode','inside')
	);
	foreach($this->order->products as $product) {
		if(!empty($product->product_id) && !empty($this->products[ (int)$product->product_id ]))
			$productData = $this->products[ (int)$product->product_id ];
		if($group && $product->order_product_option_parent_id)
			continue;
?>
							<tr class="row<?php echo $k;?>">
								<td class="hikashop_cart_product_image_value hikashop_cart_product_name_value">
                                  <div class="hikashop_cart_product_image_thumb">

									<a class="hikashop_order_product_link" href="<?php echo hikashop_contentLink('product&task=show&cid='.$product->product_id.$url_itemid, $productData); ?>">

      <?php
		$image_path = (!empty($product->images) ? @$product->images[0]->file_path : '');
		$img = $imageHelper->getThumbnail($image_path, array('width' => $width, 'height' => $height), $image_options);
		if($img->success) {
			echo '<img class="hikashop_cart_product_image" title="'.$this->escape(@$product->images[0]->file_description).'" alt="'.$this->escape(@$product->images[0]->file_name).'" src="'.$img->url.'" style="float:left; margin-right:3px;" />';
		}
      ?>       

									</a>

		</div>		
                                  
                                     <div class="hikashop_cart_product_name"><h3>             
									<a class="hikashop_order_product_link" href="<?php echo hikashop_contentLink('product&task=show&cid='.$product->product_id.$url_itemid, $productData); ?>">                        
											<?php if($productData->product_parent_id){
	                                           echo $productClass->get($product->product_parent_id)->product_name;
                                            } ?>
											<?php if($this->config->get('show_code')) { ?>
												<span class="hikashop_product_code_order"><?php echo $product->order_product_code; ?></span>
											<?php } ?>

Thanks

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

  • Posts: 62718
  • Thank you received: 8985
  • MODERATOR
11 months 1 week ago #275505

Hi,

If the image and name are displayed before clicking on the button, then I can only think that it is something linked to the browser removing them for some reason during the print process.
What if you try with another browser ?

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

  • Posts: 764
  • Thank you received: 59
  • Hikashop Business
11 months 1 week ago #275544

Hi,

I don't think it is a browser related.
Inspecting code with firebug i see that image path is like this:

"media/com_hikashop/upload/thumbnails/144x100fsO/my_image.jpg"

But when in vex pop up image path is like this:

"media/com_hikashop/upload/thumbnails/144x100fsO/barcode.jpg"

So product image isn't loaded and instead it shows barcode.


Same issue with main product name. Using this to get main product name and to show variant of that product:

<?php if($productData->product_parent_id){
	                                           echo $productClass->get($product->product_parent_id)->product_name;
                                            } ?>

<div class="hikashop_cart_product_variant">
                                       <?php  foreach ( $product->order_product_options as $variant){
                                           echo ' '.$variant->characteristic_value;
                                       } ?>
                                      </div>

Now in vex pop up name isn't printed but variant is.

Using default code for name like this works fine: "$product->order_product_name;"


Kind Regards

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

  • Posts: 62718
  • Thank you received: 8985
  • MODERATOR
11 months 1 week ago #275546

Hi,

Your code for the product name is strange.
in the if condition you're using $productData but inside the if, you're using $product
So either you want to use always $product or always $productData because otherwise, it doesn't make sense.
Now I don't see why it would be different between the page and the popup. It's probably a matter of caching if there is a difference. So either from the browser or the website.

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

  • Posts: 764
  • Thank you received: 59
  • Hikashop Business
11 months 1 week ago #275588

Hi,

Nicolas could you please try to add image to order show view and see if it is working for you?

I have used a clean protostar template and added this code to display image:

<?php
    $imageHelper = hikashop_get('helper.image');
    $width = (int)$this->config->get('cart_thumbnail_x', 100);
	$height = (int)$this->config->get('cart_thumbnail_y', 144);
	$image_options = array(
		'default' => true,
		'forcesize' => $this->config->get('image_force_size', true),
		'scale' => $this->config->get('image_scale_mode','inside')
	);
         $image_path = (!empty($product->images) ? @$product->images[0]->file_path : '');
		$img = $imageHelper->getThumbnail($image_path, array('width' => $width, 'height' => $height), $image_options);
		if($img->success) {
			echo '<img class="hikashop_cart_product_image" title="'.$this->escape(@$product->images[0]->file_description).'" alt="'.$this->escape(@$product->images[0]->file_name).'" src="'.$img->url.'" style="float:left; margin-right:3px;" />';
		}

And it still doesnt work. Tried different browser and cleaned cache....Please take a look into attached image.

Thanks

Attachments:

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

  • Posts: 62718
  • Thank you received: 8985
  • MODERATOR
11 months 1 week ago #275608

Hi,

In your code, you get the image file_path from that variable:

@$product->images

That variable is not available in the invoice.
You would have to add the code below at the top of the view file :
$class = hikashop_get('class.order');
$this->order = $class->loadFullOrder($this->order->order_id,true);

The following user(s) said Thank You: kyratn

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

  • Posts: 764
  • Thank you received: 59
  • Hikashop Business
11 months 1 week ago #275637

Hi,

I took that part of the code from the cart view.
Added your code and it is working now.

Thank you

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

Time to create page: 0.113 seconds
Powered by Kunena Forum