Total Weight in Cart

  • Posts: 109
  • Thank you received: 5
10 years 1 month ago #175969

-- HikaShop version -- : 2.3.3
-- Joomla version -- : 3.3.6

Hello, there.

Good evening!

Please could you let me know the php code to display the total weight in the Cart?

Please see attached for illustration.

Thanks.

Take care!

Attachments:

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

  • Posts: 12953
  • Thank you received: 1778
10 years 1 month ago #175977

Hello,
You'll just have to edit the "cart" file of the "product" view of your front-end template via "Hikashop->Display->Views" and add these lines :

<th class="hikashop_cart_module_product_weight_title hikashop_cart_title">
            Total Weight
          </th>
Just after these lines :
<th class="hikashop_cart_module_product_price_title hikashop_cart_title">
            <?php echo JText::_('CART_PRODUCT_PRICE'); ?>
          </th>
And add these lines :
              ?>
              <td class="hikashop_cart_module_product_price_value hikashop_cart_value">
                <?php
                $total_product_weight = $row->product_weight * $row->cart_product_quantity;
                echo $total_product_weight . ' ' . $row->product_weight_unit
                ?>
              </td>
              <?php
Just after theses lines
              if($this->params->get('show_price',1)){ ?>
              <td class="hikashop_cart_module_product_price_value hikashop_cart_value">
                <?php
                $this->row=&$row;
                echo $this->loadTemplate();
                ?>
              </td>
              <?php }

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

  • Posts: 109
  • Thank you received: 5
10 years 1 month ago #176174

Thanks, Mohamed Thelji.

Apologies for not making it clearer before. The view that I was referring to is the "Cart in the Checkout" view (i.e. the checkout/cart.php) file and the total that I am looking for is the sum of the weights of all the products in the cart.

Thanks.

Take care!

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #176207

Hi,

So you need to add the following code in the <tfoot> part of the "checkout / cart" view.

<?php
$totalWeight = 0;
$weightUnit = '';
foreach($this->rows as $i => $row){
	if(empty($row->cart_product_quantity)) continue;
	if($group && $row->cart_product_option_parent_id) continue;
	$totalWeight = $totalWeight + ($row->product->weight * $row->cart_product_quantity);
	$weightUnit = $row->product_weight_unit;
}
?>
<tr>
	<?php echo $td; ?>
	<td id="hikashop_checkout_cart_payment_title" class="hikashop_cart_payment_title hikashop_cart_title">
		<?php echo JText::_('Weight'); ?>
	</td>
	<td class="hikashop_cart_weight_value">
		<span class="hikashop_checkout_cart_weight">
			<?php echo $totalWeight.' '.$weightUnit; ?>
		</span>
	</td>
</tr>

The following user(s) said Thank You: Ed_Hika

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

  • Posts: 26
  • Thank you received: 0
9 years 5 months ago #206282

Hi,
I am after displaying the total cart weight on checkout as well. I add the above code (from Xavier) to the "checkout / cart.php" view but I am only seeing "Weight 0 kg". I have added a weight to my products but the total weight doesn't seem to be added together and displayed correctly.

Is there something I am missing? Has anyone else had success with the above code?

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

  • Posts: 13201
  • Thank you received: 2322
9 years 5 months ago #206303

Hi,

Please set the error reporting level to "maximum" in the Joomla configuration.
This will give us more informations if any error message is displayed.

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

  • Posts: 26
  • Thank you received: 0
9 years 4 months ago #206574

Hi,

Thanks I have turned on error reporting and these are the errors:

Notice: Undefined property: stdClass::$product in - on line 472
Notice: Trying to get property of non-object in - on line 472

Line 472 is the following from the newly added code:
$totalWeight = $totalWeight + ($row->product->weight * $row->cart_product_quantity);

Sorry, I don't have a lot of PHP knowledge, so my apologies if there is an obvious solution I don't see.

thanks,

Last edit: 9 years 4 months ago by Reev3r.

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

  • Posts: 13201
  • Thank you received: 2322
9 years 4 months ago #206617

Hi,

My bad, please replace $row->product->weight by $row->product_weight

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

  • Posts: 26
  • Thank you received: 0
9 years 4 months ago #206849

Hi,

Fantastic.

Changing the to line below, worked perfectly!

$totalWeight = $totalWeight + ($row->product_weight * $row->cart_product_quantity);

Thanks!

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

  • Posts: 45
  • Thank you received: 0
  • Hikashop Business
7 years 3 months ago #275451

Hi,

And in Hikashop 3.1.1 is the same?
I try and the code in show_block_cart.php file and in the line with the code "foreach($this->rows as $i => $row){" i've the follow errors:
- Notice: Undefined property: CheckoutViewCheckout::$rows in ...
- Warning: Invalid argument supplied for foreach() in ...

I want to show the total weight of order.

Thanks!

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 3 months ago #275452

Hello,

HikaShop 3 cart object already contains information about the total weight, information about the package.
In the new cart view, the loop is not more made on $this->rows but directly in the cart products ; but at the end, it's reading the same information but we do not put cart products into the "rows" variable anymore because you can easily get the cart content.

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: 45
  • Thank you received: 0
  • Hikashop Business
7 years 3 months ago #275472

Hi,
Can you help to show the total weight in cart checkout?

Thanks!

Best regards,
Bruno Simões

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
7 years 3 months ago #275481

Hi,

As Jerome said, the total weight is already calculated for you.
So you just need to display it if you want.
For example, with such code in show_block_cart :

echo $cart->package[weight']['value'] . ' ' . $cart->package[weight']['unit'];

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

  • Posts: 45
  • Thank you received: 0
  • Hikashop Business
7 years 3 months ago #275516

Hi Nicolas,

Thanks for your help!!

Best regards

Last edit: 7 years 3 months ago by bsimoes.

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

  • Posts: 45
  • Thank you received: 0
  • Hikashop Business
7 years 3 months ago #275864

Hi,
It is possible add the total weight of order in backend in the detail of a order?
How?

Best regards

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 3 months ago #275866

Hello,

I'm afraid that I can't say yes.

Because an order is something fixed in the past ; the products of the order can evolve, change.
It is also possible that the products do not exist anymore in your database.
But HikaShop keep some information at the moment when the ordre is made, like the name or the price. Unfortunately, it cannot save all data of products.

That's why, if the weight is added, it will be an information read from the database and it could be an incorrect information. HikaShop would not have the possibility to know it and warn the user.
That's how it is not something that would be integrated into the HIkaShop core but that's something that you could add in your end thanks to overrides.

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: 45
  • Thank you received: 0
  • Hikashop Business
7 years 3 months ago #275908

Hi,

Ok, but i suggest that in future versions you could add the total weight in the order time.
For example, this is important to my costumer (the owner and the administrator of online store) to know the total weight of the order before shipping.

This is my suggestion.

Thanks,

Best regards

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
7 years 3 months ago #275910

Hello,

Thank you for your feedback.
We will take it under consideration for the future improvement of the shipping management (with the implementations around the shipping tracking and the partial order statuses)

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.

Time to create page: 0.085 seconds
Powered by Kunena Forum