Post by AHaa » Sat Oct 23, 2010 6:56 am

Hi,

Opencart 1.4.9.1

I have spent over an hour to find a solution, but with no luck.

I would like to know the height of the product in cm. How is that possible? I know how to get the products from the cart and that the products have the height attribute, but it can be in cm or mm or whatever, so it doesn't help.

I found some kind of a solution here: http://www.phena109.com/?p=83

The only problem is that it doesn't work. I created a function

Code: Select all

	public function getMaxHeight() {
		$max_height = 0;
	
    	foreach ($this->getProducts() as $product) {
			//height in cm
			$prod_height = $this->measurement->convert($product['height'],
				$product['measurement_id'], 1);
			if ($prod_height > $max_height) {
				$max_height = $prod_height;
			}
		}
			
		return $max_height;
	}
to cart.php and added the line

Code: Select all

$this->measurement = $registry->get('measurement');
to the construct section, but it gives me an error:
Fatal error: Call to a member function convert() on a non-object in /home/ahaa/public_html/shop/system/library/cart.php on line 196

Any solution to get the heights for the products in the same measurement unit?

Newbie

Posts

Joined
Fri Oct 22, 2010 4:10 pm

Post by kedgetech » Sat Oct 23, 2010 7:59 am

Hi there Its good point. I will look into it.

User avatar
Active Member

Posts

Joined
Mon Mar 22, 2010 5:20 pm
Location - USA, Australia, India

Post by AHaa » Sun Oct 24, 2010 5:13 am

Is this a wrong forum to ask that kind of a thing? Only 18 views in this topic...

I have not succeeded yet, so any help is highly appreciated! Do you have any idea, kedgetech? I've almost done a shipping module for Finnish postal service, but I need to know the height of the product to finish it.

Newbie

Posts

Joined
Fri Oct 22, 2010 4:10 pm

Post by simplywebsites » Thu Nov 10, 2011 8:55 am

Hi,

Did you found any solution?


Posts

Joined
Mon Oct 31, 2011 8:28 am
Location - chrustchurch, new zealand

Post by straightlight » Thu Nov 24, 2011 12:25 pm

simplywebsites wrote:Hi,

Did you found any solution?
I just developed a similarity which now supports universal max type of height you wish to get calculated from the product height.

In system/library/cart.php file,

find:

Code: Select all

public function hasDownload() {
		$download = false;
		
		foreach ($this->getProducts() as $product) {
	  		if ($product['download']) {
	    		$download = true;
				
				break;
	  		}		
		}
		
		return $download;
	}
add below:

Code: Select all

public function getMaxHeightByType($type) {
		$measurement = array();
		foreach ($this->getProducts() as $product) {
			if ((float)$product['height'] > 0) {
				// cm to inches.
				if ((int)$type == 1) {
					$measurement[] = number_format((float)$product['height'] * 0.3937, 2);
					
				// cm to feet.
				} elseif ((int)$type == 2) {
					$measurement[] = number_format((float)$product['height'] * 0.03281, 2);
					
				// cm to millimeters.					
				} elseif ((int)$type == 3) {
					$measurement[] = number_format((float)$product['height'] * 10, 2);
					
				// cm to meters.
				} elseif ((int)$type == 4) {
					$measurement[] = number_format((float)$product['height'] * 0.01, 2);

				// feet to cm
				} elseif ((int)$type == 5) {
					$measurement[] = number_format((float)$product['height'] * 30.48, 2);
					
				// feet to meters.
				} elseif ((int)$type == 6) {
					$measurement[] = number_format((float)$product['height'] * 0.3048, 2);
					
				// feet to inches.
				} elseif ((int)$type == 7) {
					$measurement[] = number_format((float)$product['height'] * 12, 2);
						
				// feet to yards.
				} elseif ((int)$type == 8) {
					$measurement[] = number_format((float)$product['height'] * 0.3333, 2);
				
				// feet to miles.
				} elseif ((int)$type == 9) {
					$measurement[] = number_format((float)$product['height'] * 0.0001893939, 2);
					
				// inches to mm.
				} elseif ((int)$type == 10) {
					$measurement[] = number_format((float)$product['height'] * 25.4, 2);
				
				// inches to cm.
				} elseif ((int)$type == 11) {
					$measurement[] = number_format((float)$product['height'] * 2.54, 2);
				
				// inches to meters.
				} elseif ((int)$type == 12) {
					$measurement[] = number_format((float)$product['height'] * 0.0254, 2);
					
				// inches to feet.
				} elseif ((int)$type == 13) {
					$measurement[] = number_format((float)$product['height'] * 0.083333, 2);
				
				// km to meters.
				} elseif ((int)$type == 14) {
					$measurement[] = number_format((float)$product['height'] * 1000, 2);
				
				// km to miles.
				} elseif ((int)$type == 15) {
					$measurement[] = number_format((float)$product['height'] * 0.62137, 2);
				
				// meters to feet.
				} elseif ((int)$type == 16) {
					$measurement[] = number_format((float)$product['height'] * 3.28, 2);
				
				// meters to yards.				
				} elseif ((int)$type == 17) {
					$measurement[] = number_format((float)$product['height'] * 1.0936, 2);
				
				// meters to cm.
				} elseif ((int)$type == 18) {
					$measurement[] = number_format((float)$product['height'] * 100, 2);
				
				// meters to km.				
				} elseif ((int)$type == 19) {
					$measurement[] = number_format((float)$product['height'] * 0.001, 2);
				
				// miles to km.
				} elseif ((int)$type == 20) {
					$measurement[] = number_format((float)$product['height'] * 1.609, 2);
				
				// miles to feet.
				} elseif ((int)$type == 21) {
					$measurement[] = number_format((float)$product['height'] * 5280, 2);
				
				// mm to inches.
				} elseif ((int)$type == 22) {
					$measurement[] = number_format((float)$product['height'] * 0.03937, 2);
				
				// mm to cm.
				} elseif ((int)$type == 23) {
					$measurement[] = number_format((float)$product['height'] * 0.1, 2);
				
				// mm to meters.
				} elseif ((int)$type == 24) {
					$measurement[] = number_format((float)$product['height'] * 0.001, 2);
					
				// yards to meters.
				} elseif ((int)$type == 25) {
					$measurement[] = number_format((float)$product['height'] * 0.9144, 2);
					
				// yards to feet.
				} elseif ((int)$type == 26) {
					$measurement[] = number_format((float)$product['height'] * 3, 2);
				}
			}
		}
		
		return max($measurement);
	}
In addition, the returned value is in decimal of 2 as per the shipping gateway requirements. Each type number are identified from the method I posted above.

Use: There's no need to get or to set anything from the registry for this method. From the controllers, you can use: $results = $this->cart->getMaxHeightByType(x). Replace the x with your number and you can see the results from $results variable once you pass it through $this->data and integrate it into the themes.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Sat Nov 26, 2011 10:45 am

I just found a constructor in OpenCart that seem to already convert the height from any classes that may exist and compares from the configuration to balance the results.

Code: Select all

$height = $this->length->convert($product_info['height'], $this->config->get('config_length_class_id'), $product_info['length_class_id']);
Note: Change $product_info to the related object name.

Although, there doesn't seem to be a height_class_id from the product table nor a height class table which may be the reason why you reported this since right now the class ID, even from the width and height are based on the length oddly ...

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 4 guests