Post by ckonig » Fri Jun 24, 2011 5:41 pm

Hello everyone.
I create my own Shipping Method, which is dependent on the categories. The calculation of the costs works great. When I go through the checkout process, the shipping costs are shown correctly on the checkout/shipping page, but when i go further to the confirmation page, the costs for shipping are displayed as '0'.
I am not sure where to start. Obviously, on the checkout/shipping the getQuote method is used to determine the shipping costs. But on the confirmation page not.
This is my code:

Code: Select all

<?php
class ModelShippingCategorybased extends Model {
	function getQuote($address) {
		$this->load->language('shipping/category_based');
		$products = $this->cart->getProducts();
		$this->load->model('catalog/product');
		$this->load->model('catalog/category');
		$highest = 0;
		foreach($products as $product){
			$cats = $this->model_catalog_product->getCategories($product['product_id']);
			
			$categories = array();
			foreach($cats as $cat){
				$realcat = $this->model_catalog_category->getCategory($cat['category_id']);
				$categories[] = $realcat;
				
				while($realcat['parent_id']!=0){
					$realcat = $this->model_catalog_category->getCategory($realcat['parent_id']);
					$categories[] = $realcat;	
				}
			}
			
			foreach($categories as $cat){
				$category = $this->model_catalog_category->getCategory($cat['category_id']);
			
				$costs = $category['shipping_cost'];
				if($costs > $highest){
					$highest = $costs;
				}
			}
		}	
			$status = TRUE;
		
		
		$method_data = array();
	
		if ($status) {
			$quote_data = array();
			
      		$quote_data['category_based'] = array(
        		'id'           => 'category_based.category_based',
        		'title'        => $this->language->get('text_description'),
        		'cost'         => $this->currency->format($highest),
        		'tax_class_id' => 0,
				'text'         => $this->currency->format($highest)
      		);

      		$method_data = array(
        		'id'         => 'category_based',
        		'title'      => $this->language->get('text_title'),
        		'quote'      => $quote_data,
				'sort_order' => $this->config->get('category_based_sort_order'),
        		'error'      => FALSE
      		);
		}
	
		return $method_data;
	}
}
?>

User avatar
Active Member

Posts

Joined
Wed Feb 16, 2011 4:26 pm
Location - Netherlands

Post by ckonig » Fri Jun 24, 2011 7:24 pm

SOLVED!
changed

Code: Select all

$quote_data['category_based'] = array(
        		'id'           => 'category_based.category_based',
        		'title'        => $this->language->get('text_description'),
        		'cost'         => $this->currency->format($highest),
        		'tax_class_id' => 0,
				'text'         => $this->currency->format($highest)
      		);
to

Code: Select all

$quote_data['category_based'] = array(
        		'id'           => 'category_based.category_based',
        		'title'        => $this->language->get('text_description'),
        		'cost'         => $highest,
        		'tax_class_id' => 0,
				'text'         => $this->currency->format($highest)
      		);

User avatar
Active Member

Posts

Joined
Wed Feb 16, 2011 4:26 pm
Location - Netherlands

Post by Qphoria » Fri Jun 24, 2011 8:39 pm

Correct.

Always deal with the raw cost in your default currency with no tax or formatting as opencart always uses that for the base calculation so that it is always consistent with different currencies and taxes

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 1 guest