Post by tristanojbacon » Tue Mar 19, 2013 4:11 am

Hello,

Our products have recently gained interest from members of the British Forces serving overseas, and we'd like to start selling to them.
We sell loose leaf tea using our online store, and send them in our own packaging. The shipping extension serves us well for UK addresses, so that's all fine.

For those of you who aren't aware The British Armed Forces have their own Post service, called the British Forces Post Office (known locally as BFPO), which delivers mail to soldiers serving overseas. It's cheaper than regular mail, as it is subsidized by the British Government. For the purpose of this post, the details can be found here: https://www.gov.uk/british-forces-post-office-services.

Now, instead of creating/paying for a brand new shipping option extension that is separate to the Royal Mail option, I want to include BFPO as an option within the Royal Mail extension, in the same way that First Class Standard, Second Class Recorded etc. are options. I've gone and replaced the 'Surface' option (what even is that?!) in both the Admin front-end, and in the controller/model/view/language files. All I have done is copy/paste the First Class Standard Post code, and adjusted the prefixes to 'bfpo' across the files all.
The BFPO tab shows up in the Admin section all fine, and I can enable/disable and enter weight-based rates as normal. However, when I do a test order in the checkout, the BFPO option does now show up in the Shipping Method section. The only option is the Royal Mail First Class, which is the only other option that I have enabled.

The Code:
catalog/model/shipping/royal_mail.php

Code: Select all

// 1st Class Standard
			if ($this->config->get('royal_mail_1st_class_standard_status') && $address['iso_code_2'] == 'GB') {
				$cost = 0;
				$insurance = 0;
				
				$rates = explode(',', $this->config->get('royal_mail_1st_class_standard_rate'));
				
				foreach ($rates as $rate) {
					$data = explode(':', $rate);
				
					if ($data[0] >= $weight) {
						if (isset($data[1])) {
							$cost = $data[1];
						}
				
						break;
					}
				}
				
				$rates = explode(',', $this->config->get('royal_mail_1st_class_standard_insurance'));
				
				foreach ($rates as $rate) {
					$data = explode(':', $rate);
				
					if ($data[0] >= $sub_total) {
						if (isset($data[1])) {
							$insurance = $data[1];
						}
				
						break;
					}
				}
				
				if ((float)$cost) {
					$title = $this->language->get('text_1st_class_standard');
					
					if ($this->config->get('royal_mail_display_weight')) {
						$title .= ' (' . $this->language->get('text_weight') . ' ' . $this->weight->format($weight, $this->config->get('config_weight_class_id')) . ')';
					}
				
					if ($this->config->get('royal_mail_display_insurance') && (float)$insurance) {
						$title .= ' (' . $this->language->get('text_insurance') . ' ' . $this->currency->format($insurance) . ')';
					}		
					
					$quote_data['1st_class_standard'] = array(
						'code'         => 'royal_mail.1st_class_standard',
						'title'        => $title,
						'cost'         => $cost,
						'tax_class_id' => $this->config->get('royal_mail_tax_class_id'),
						'text'         => $this->currency->format($this->tax->calculate($cost, $this->config->get('royal_mail_tax_class_id'), $this->config->get('config_tax')))
					);
				}
			}
// BFPO
			if ($this->config->get('bfpo_status') && $address['iso_code_2'] == 'GB') {
				$cost = 0;
				$insurance = 0;
				
				$rates = explode(',', $this->config->get('bfpo_rate'));
				
				foreach ($rates as $rate) {
					$data = explode(':', $rate);
				
					if ($data[0] >= $weight) {
						if (isset($data[1])) {
							$cost = $data[1];
						}
				
						break;
					}
				}
				
				$rates = explode(',', $this->config->get('bfpo_insurance'));
				
				foreach ($rates as $rate) {
					$data = explode(':', $rate);
				
					if ($data[0] >= $sub_total) {
						if (isset($data[1])) {
							$insurance = $data[1];
						}
				
						break;
					}
				}
				
				if ((float)$cost) {
					$title = $this->language->get('text_bfpo');
					
					if ($this->config->get('royal_mail_display_weight')) {
						$title .= ' (' . $this->language->get('text_weight') . ' ' . $this->weight->format($weight, $this->config->get('config_weight_class_id')) . ')';
					}
				
					$quote_data['bfpo'] = array(
						'code'         => 'bfpo',
						'title'        => $title,
						'cost'         => $cost,
						'tax_class_id' => $this->config->get('royal_mail_tax_class_id'),
						'text'         => $this->currency->format($this->tax->calculate($cost, $this->config->get('royal_mail_tax_class_id'), $this->config->get('config_tax')))
					);
				}
			}
As said previously, I copied and pasted the 1st Class Standard and changed the prefixes to BFPO where applicable.

Any ideas as to what's going wrong?

Thanks


Posts

Joined
Tue Mar 19, 2013 3:35 am

Post by tristanojbacon » Thu Mar 28, 2013 4:57 am

Can someone please help me out on this! Am still struggling to get it up and running, and we have soldiers who are keen on buying some of our tea!

Thanks


Posts

Joined
Tue Mar 19, 2013 3:35 am

Post by iheartny2008 » Mon May 26, 2014 8:08 pm

Did you manage to figure this out? My client has asked me to do this on her website - any help is appreciated :)

Newbie

Posts

Joined
Wed May 22, 2013 7:55 am

Post by OpenCart Addons » Mon May 26, 2014 10:15 pm

tristanojbacon wrote:Can someone please help me out on this! Am still struggling to get it up and running, and we have soldiers who are keen on buying some of our tea!

Thanks
There's a small issue in the script you've shown. Make the following change:

Replace This:

Code: Select all

'code'         => 'bfpo',
With This:

Code: Select all

'code'         => 'royal_mail.bfpo',
Also make sure that the fields in the admin panel are renamed correctly so that the information is saved to the database under the correct names.


Cheers,
Joel.

Canada's Leading Expert In OpenCart Development & Certified OpenCart Development Partner Image


User avatar
Active Member

Posts

Joined
Thu Nov 24, 2011 10:51 am
Location - Canada
Who is online

Users browsing this forum: No registered users and 6 guests