Post by jakuba » Tue Apr 14, 2015 9:58 pm

Hi, I need custom Opencart 1.5.4 code. Now it is sum of weight of all products in cart but I need use only product with highest weight in cart. Can you help me where custom this? Thank you

In cart is is product with 1 lb, 5 lb, 10 lb which is total 16 lb but I need display and in shipping modules use only highest weight which is 10 lb.

Active Member

Posts

Joined
Fri Jul 08, 2011 12:51 am
Location - CZ-Prague

Post by chulcha » Thu Apr 30, 2015 2:05 am

Code: Select all

$max_weight = 0; $id_max = 0;	
		foreach ($this->cart->getProducts() as $product) {
if ($product['weight']> $max_weight) { $max_weight = $product['weight']; $id_max= $product['product_id'];}
catalog/controller/module/cart.php

Active Member

Posts

Joined
Fri Jul 18, 2014 4:39 pm

Post by jakuba » Fri May 08, 2015 1:52 am

This is not working for me. OC 154. Where put it this code? Line sensitive?

Active Member

Posts

Joined
Fri Jul 08, 2011 12:51 am
Location - CZ-Prague

Post by chulcha » Fri May 08, 2015 4:11 pm

I have not original file from oc154

1. /catalog/controller/checkout/cart.php

search next code
if ($this->cart->hasProducts()
than

$points_total = 0;

foreach ($this->cart->getProducts() as $product) {
if ($product['points']) {
$points_total += $product['points'];
}
}
change

Code: Select all

//add
$max_weight = 0; $id_max = 0;   
//add
      foreach ($this->cart->getProducts() as $product) {
//add
if ($product['weight']> $max_weight) { $max_weight = $product['weight']; $id_max= $product['product_id'];}
//add
				if ($product['points']) {
					$points_total += $product['points'];
				}
			}

After this cycle will be variable $id_max item ID_PRODUCT with maximum value, $max_weight - max weight
and 0 if not wieght.

2.

catalog/controller/module/cart.php

search

Code: Select all

		$this->data['products'] = array();
			
		foreach ($this->cart->getProducts() as $product) {
and insert into

Code: Select all

    $max_weight = 0; $id_max = 0;   
          foreach ($this->cart->getProducts() as $product) {
    if ($product['weight']> $max_weight) { $max_weight = $product['weight']; $id_max= $product['product_id'];}

Active Member

Posts

Joined
Fri Jul 18, 2014 4:39 pm
Who is online

Users browsing this forum: Bing [Bot] and 13 guests