Display Product Weight in original format/unit

  • Posts: 30
  • Thank you received: 2
4 years 7 months ago #317074

-- HikaShop version -- : Business 4.2.2

I'm trying to display the product weight in the Shopping Cart (and Checkout Cart), but when I access $product->product_weight and $product->product_weight_unit, it shows them in the general cart weight.

For example: a 50g product and a 1Kg product show "0.05kg" and "1,000kg", respectively. I'd like to be able show them as "50g" and "1Kg" on the product line-items.

How can I show the product weight in their original unit/values? (items have "50g" and "1kg" as their actual weight entries)

Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 7 months ago #317079

Hi,

In the variable $product of the view file used to display this area, the weight and unit are converted during the loading of the cart so that the total weight of the cart can be calculated for shipping methods.
So to get the original weight and unit, you should find them in the attributes $product->product_weight_orig and $product->product_weight_unit_orig or you can even reload the product data from the hikashop_product table with a MySQL query if necessary.

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

  • Posts: 30
  • Thank you received: 2
4 years 7 months ago #317323

Hi, Nicolas. Thanks for the reply.

I tried displaying $product->product_weight_orig in the checkout cart block view but I got the same output.
The first 0.5Kg is the output of $product->product_weight, and the one in parentheses is for $product->product_weight_orig.

Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 7 months ago #317328

Hi,

And you confirm that this product has 500g configured in its settings ? Not 0.5kg ?
Then just reload the data from the database like that:

$class = hikashop_get('class.product');
$data = $class->get($product->product_id);
echo $data->product_weight.' '.$data->product_weight_unit;

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

  • Posts: 30
  • Thank you received: 2
4 years 7 months ago #317352

Great! That did it. :)
Thanks, Nicolas!

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

Time to create page: 0.079 seconds
Powered by Kunena Forum