Post by Passko » Sun Feb 05, 2023 12:20 am

I have OC 3.0.3.8, custom theme.

I want to show a custom message on checkout page something like this: Approximate order weight: 0.5 kg


I am selling Resistors, Capacitors and other elements like these.
Because they are extremely lightweight ,sometimes their weight is under 1 gram, the default weight class is "gram" and I want to keep it that way.

In the controller file I inserted:

$data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point'));

The output on checkout is for example "10g".

I want to show total weight in "kg" with 3 digits after decimal point - so the above example have to become 0.010kg.

How can I achieve this?

Newbie

Posts

Joined
Thu Jan 15, 2015 7:47 pm

Post by ADD Creative » Sun Feb 05, 2023 1:17 am

As you want 3 decimal places it probably easiest to do this. Otherwise you would need to make changes to the weight class.

Code: Select all

$data['weight'] = number_format($this->cart->getWeight() / 1000, 3, $this->language->get('decimal_point'), $this->language->get('thousand_point')) . 'kg';

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Passko » Sun Feb 05, 2023 3:39 pm

ADD Creative wrote:
Sun Feb 05, 2023 1:17 am
As you want 3 decimal places it probably easiest to do this. Otherwise you would need to make changes to the weight class.

Code: Select all

$data['weight'] = number_format($this->cart->getWeight() / 1000, 3, $this->language->get('decimal_point'), $this->language->get('thousand_point')) . 'kg';
Thanks man. Your decision works like a charm.

I have one more question.

On checkout page, there is an option for customers to increase or decrease quantity in cart by pressing Up or Down arrows or input new quantity in the input field.

Is it possible the total weight of the cart to be dynamically changed, when the arrows are pressed or new quantity is inserted.

Which file usually is responsible for updating the cart - checkout.twig file or .js file?

Attachments

Capture.JPG

Capture.JPG (10.33 KiB) Viewed 469 times


Newbie

Posts

Joined
Thu Jan 15, 2015 7:47 pm

Post by xxvirusxx » Sun Feb 05, 2023 3:56 pm

Passko wrote:
Sun Feb 05, 2023 3:39 pm
On checkout page, there is an option for customers to increase or decrease quantity in cart by pressing Up or Down arrows or input new quantity in the input field.
Not on Default theme...

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România
Who is online

Users browsing this forum: jagall, SohBH and 257 guests