Post by chiefk » Fri Jul 10, 2009 7:52 pm

Hi.my weight based shipping is not working.I use grams, have enabled shipping in products & grams.i use e.g 500:3.35,1000:4.45.So 2 products @ 500g each=1000g therefore £4.45.It only defaults to £3.35.
An ideas?
p/s i notice also that in products the grams weight is e.g 250.00.is there a bug maybe confusing' the cart?
Last edited by i2Paq on Thu Feb 18, 2010 1:26 am, edited 1 time in total.
Reason: Topic title adjusted

New member

Posts

Joined
Fri May 22, 2009 7:52 pm

Post by alexdaydreaming » Thu Jul 16, 2009 5:58 pm

You could try to use 0.5 instead of 500, 0.25 rather than 250 and so on..

New member

Posts

Joined
Thu May 14, 2009 10:33 am

Post by Daniel » Thu Jul 16, 2009 8:10 pm

I think there is a problem due to the formatting of the weights inthe shopping cart class. This will be fixed int he next version.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by amcc » Fri Jul 17, 2009 1:18 am

[removed]
Last edited by amcc on Fri Feb 09, 2018 7:24 pm, edited 1 time in total.

New member

Posts

Joined
Sat Jun 27, 2009 5:17 am

Post by amcc » Fri Jul 17, 2009 2:00 am

[removed]
Last edited by amcc on Fri Feb 09, 2018 7:46 pm, edited 1 time in total.

New member

Posts

Joined
Sat Jun 27, 2009 5:17 am

Post by Qphoria » Fri Jul 17, 2009 2:46 am

amcc wrote:how can this be fixed daniel 8-)
Daniel wrote:I think there is a problem due to the formatting of the weights inthe shopping cart class. This will be fixed int he next version.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by amcc » Fri Jul 17, 2009 3:49 am

[removed]
Last edited by amcc on Fri Feb 09, 2018 7:25 pm, edited 1 time in total.

New member

Posts

Joined
Sat Jun 27, 2009 5:17 am

Post by Daniel » Fri Jul 17, 2009 6:56 am

replace your weight class with this:

Code: Select all

<?php
final class Weight {
	private $classes = array();
	private $rules = array();
	
	public function __construct() {
    	$this->config = Registry::get('config');
		$this->db = Registry::get('db');
		$this->language = Registry::get('language');

		$weight_class_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "weight_class WHERE language_id = '" . (int)$this->language->getId() . "'");
    
    	foreach ($weight_class_query->rows as $result) {
      		$this->classes[$result['weight_class_id']] = array(
        		'unit'  => $result['unit'],
        		'title' => $result['title']
      		);
    	}
		
    	$weight_rule_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "weight_rule");
	
    	foreach ($weight_rule_query->rows as $result) {
      		$this->rules[$result['from_id']][$result['to_id']] = $result['rule'];
    	}
  	}
	  
  	public function convert($value, $from, $to) {
    	if ($from == $to) {
      		return $value;
    	} else {
      		return $value * (float)$this->rules[$from][$to];
    	}
  	}

	public function format($value, $weight_class_id, $decimal_point = '.', $thousand_point = ',') {
    	return number_format($value, 2, $decimal_point, $thousand_point) . $this->classes[$weight_class_id]['unit'];
  	}
}
?>
replace your shopping cart class with this:

Code: Select all

<?php
final class Cart {
  	public function __construct() {
		$this->config = Registry::get('config');
		$this->session = Registry::get('session');
		$this->db = Registry::get('db');
		$this->language = Registry::get('language');
		$this->tax = Registry::get('tax');
		$this->weight = Registry::get('weight');

		if (!is_array(@$this->session->data['cart'])) {
      		$this->session->data['cart'] = array();
    	}
	}
	      
  	public function getProducts() {
		$product_data = array();
		
    	foreach ($this->session->data['cart'] as $key => $value) {
      		$array = explode(':', $key);
      		$product_id = $array[0];
      		$quantity = $value;

      		if (isset($array[1])) {
        		$options = explode('.', $array[1]);
      		} else {
        		$options = array();
      		} 
	 
      		$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->language->getId() . "' AND p.date_available <= NOW() AND p.status = '1'");
      	  	
			if ($product_query->num_rows) {
      			$option_price = 0;

      			$option_data = array();
      
      			foreach ($options as $product_option_value_id) {
        		 	$option_value_query = $this->db->query("SELECT pov.product_option_id, povd.name, pov.price, pov.prefix FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "product_option_value_description povd ON (pov.product_option_value_id = povd.product_option_value_id) WHERE pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND pov.product_id = '" . (int)$product_id . "' AND povd.language_id = '" . (int)$this->language->getId() . "' ORDER BY pov.sort_order");
					
					if ($option_value_query->num_rows) {
						$option_query = $this->db->query("SELECT pod.name FROM " . DB_PREFIX . "product_option po LEFT JOIN " . DB_PREFIX . "product_option_description pod ON (po.product_option_id = pod.product_option_id) WHERE po.product_option_id = '" . (int)$option_value_query->row['product_option_id'] . "' AND po.product_id = '" . (int)$product_id . "' AND pod.language_id = '" . (int)$this->language->getId() . "' ORDER BY po.sort_order");
						
        				if ($option_value_query->row['prefix'] == '+') {
          					$option_price = $option_price + $option_value_query->row['price'];
        				} elseif ($option_value_query->row['prefix'] == '-') {
          					$option_price = $option_price - $option_value_query->row['price'];
        				}
        
        				$option_data[] = array(
          					'product_option_value_id' => $product_option_value_id,
          					'name'                    => $option_query->row['name'],
          					'value'                   => $option_value_query->row['name'],
          					'prefix'                  => $option_value_query->row['prefix'],
          					'price'                   => $option_value_query->row['price']
        				);
					}
      			}
				
				$product_discount_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_query->row['product_id'] . "' AND quantity <= '" . (int)$quantity . "' ORDER BY quantity DESC LIMIT 1");
				
				if ($product_discount_query->num_rows) {
					$discount = $product_discount_query->row['discount'];
				} else {
					$discount = 0;
				}

				$product_special_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_query->row['product_id'] . "' AND date_start < NOW() AND date_end > NOW() LIMIT 1");
				
				if ($product_special_query->num_rows) {
					$price = $product_special_query->row['price'];
				} else {
					$price = $product_query->row['price'];
				}

				$download_data = array();     		
				
				$download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download p2d LEFT JOIN " . DB_PREFIX . "download d ON (p2d.download_id = d.download_id) LEFT JOIN " . DB_PREFIX . "download_description dd ON (d.download_id = dd.download_id) WHERE p2d.product_id = '" . (int)$product_id . "' AND dd.language_id = '" . (int)$this->language->getId() . "'");
			
				foreach ($download_query->rows as $download) {
        			$download_data[] = array(
          				'download_id' => $download['download_id'],
						'name'        => $download['name'],
						'filename'    => $download['filename'],
						'mask'        => $download['mask'],
						'remaining'   => $download['remaining']
        			);
				}
				
      			$product_data[$key] = array(
        			'key'             => $key,
        			'product_id'      => $product_query->row['product_id'],
        			'name'            => $product_query->row['name'],
        			'model'           => $product_query->row['model'],
					'shipping'        => $product_query->row['shipping'],
        			'image'           => $product_query->row['image'],
        			'option'          => $option_data,
					'download'        => $download_data,
        			'quantity'        => $quantity,
					'stock'           => ($quantity <= $product_query->row['quantity']),
        			'price'           => ($price + $option_price),
					'discount'        => $discount,
        			'total'           => (($price + $option_price) - $discount) * $quantity,
        			'tax_class_id'    => $product_query->row['tax_class_id'],
        			'weight'          => $product_query->row['weight'],
        			'weight_class_id' => $product_query->row['weight_class_id']
      			);
			} else {
				$this->remove($key);
			}
    	}
		
		return $product_data;
  	}
		  
  	public function add($product_id, $qty = 1, $options = array()) {
    	if (!$options) {
      		$key = $product_id;
    	} else {
      		$key = $product_id . ':' . implode('.', $options);
    	}
    	
		if (((int)$qty) && ($qty > 0)) {
    		if (!isset($this->session->data['cart'][$key])) {
      			$this->session->data['cart'][$key] = $qty;
    		} else {
      			$this->session->data['cart'][$key] += $qty;
    		}
		}
  	}

  	public function update($key, $qty) {
    	if (((int)$qty) && ($qty > 0)) {
      		$this->session->data['cart'][$key] = $qty;
    	} else {
	  		$this->remove($key);
		}
  	}

  	public function remove($key) {
		if (isset($this->session->data['cart'][$key])) {
     		unset($this->session->data['cart'][$key]);
  		}
	}

  	public function clear() {
		$this->session->data['cart'] = array();
  	}
  	
  	public function getWeight() {
		$weight = 0;
	
    	foreach ($this->getProducts() as $product) {
      		$weight += $this->weight->convert($product['weight'] * $product['quantity'], $product['weight_class_id'], $this->config->get('config_weight_class_id'));
    	}
	
		return $weight;
	}

  	public function getSubTotal() {
		$total = 0;
		
		foreach ($this->getProducts() as $product) {
			$total += $product['total'];
		}

		return $total;
  	}
	
	public function getTaxes() {
		$taxes = array();
		
		foreach ($this->getProducts() as $product) {
			if ($product['tax_class_id']) {
				if (!isset($taxes[$product['tax_class_id']])) {
					$taxes[$product['tax_class_id']] = $product['total'] / 100 * $this->tax->getRate($product['tax_class_id']);
				} else {
					$taxes[$product['tax_class_id']] += $product['total'] / 100 * $this->tax->getRate($product['tax_class_id']);
				}
			}
		}
		
		return $taxes;
  	}

  	public function getTotal() {
		$total = 0;
		
		foreach ($this->getProducts() as $product) {
			$total += $this->tax->calculate($product['total'], $product['tax_class_id'], $this->config->get('config_tax'));
		}

		return $total;
  	}
  	
  	public function countProducts() {
		$total = 0;
		
		foreach ($this->session->data['cart'] as $value) {
			$total += $value;
		}
		
    	return $total;
  	}
	  
  	public function hasProducts() {
    	return count($this->session->data['cart']);
  	}
  
  	public function hasStock() {
		$stock = TRUE;
		
		foreach ($this->getProducts() as $product) {
			if (!$product['stock']) {
	    		$stock = FALSE;
			}
		}
		
    	return $stock;
  	}
  
  	public function hasShipping() {
		$shipping = FALSE;
		
		foreach ($this->getProducts() as $product) {
	  		if ($product['shipping']) {
	    		$shipping = TRUE;
				
				break;
	  		}		
		}
		
		return $shipping;
	}
}
?>

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by amcc » Sun Jul 19, 2009 2:38 am

[removed]
Last edited by amcc on Fri Feb 09, 2018 7:43 pm, edited 1 time in total.

New member

Posts

Joined
Sat Jun 27, 2009 5:17 am

Post by Qphoria » Sun Jul 19, 2009 2:48 am

Had you asked "Is there a quick fix I can apply now before the next release" then that would have gotten you help sooner than posting 5 of the same question in different forums.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by amcc » Sun Jul 19, 2009 2:49 am

[removed]
Last edited by amcc on Fri Feb 09, 2018 7:26 pm, edited 1 time in total.

New member

Posts

Joined
Sat Jun 27, 2009 5:17 am

Post by amcc » Sun Jul 19, 2009 2:50 am

[removed]
Last edited by amcc on Fri Feb 09, 2018 7:26 pm, edited 1 time in total.

New member

Posts

Joined
Sat Jun 27, 2009 5:17 am

Post by Daniel » Sun Jul 19, 2009 3:39 am

I will release the next version tonight.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by urfrd_dipak » Thu Feb 18, 2010 1:07 am

I have replace two class as per you posted above but i get the following error.
Fatal error: Call to undefined method Language::getId() in D:\xampp\htdocs\opencart_v1.4\upload\system\library\weight.php on line 11

Newbie

Posts

Joined
Wed Dec 23, 2009 12:10 am

Post by Qphoria » Thu Feb 18, 2010 1:20 am

This is no longer an issue and the code above is not meant for 1.4.0

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by i2Paq » Thu Feb 18, 2010 1:26 am

urfrd_dipak wrote:I have replace two class as per you posted above but i get the following error.
Fatal error: Call to undefined method Language::getId() in D:\xampp\htdocs\opencart_v1.4\upload\system\library\weight.php on line 11
Why?

What is your problem then?

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by glennjamieson » Tue Jul 03, 2012 4:15 pm

hi there

i think i have this set up correctly, as the shipping option is coming up at checkout, but it is not being added to total price.does anyone have any ideas?

site id: http://doggielicioustreats.com/index.ph ... ommon/home

Thanks

Newbie

Posts

Joined
Tue Jul 03, 2012 4:13 pm
Who is online

Users browsing this forum: No registered users and 4 guests