- Posts: 30
- Thank you received: 2
Display Product Weight in original format/unit
6 years 7 months ago #317074
by jtquinto
Display Product Weight in original format/unit was created by jtquinto
-- 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)
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)
Please Log in or Create an account to join the conversation.
6 years 7 months ago #317079
by nicolas
Replied by nicolas on topic Display Product Weight in original format/unit
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.
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.
6 years 6 months ago #317323
by jtquinto
Replied by jtquinto on topic Display Product Weight in original format/unit
Please Log in or Create an account to join the conversation.
6 years 6 months ago #317328
by nicolas
Replied by nicolas on topic Display Product Weight in original format/unit
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:
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:
Code:
$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.
6 years 6 months ago #317352
by jtquinto
Replied by jtquinto on topic Display Product Weight in original format/unit
Great! That did it. 
Thanks, Nicolas!
Thanks, Nicolas!
Please Log in or Create an account to join the conversation.
Time to create page: 0.072 seconds