Post by wafflemeister » Sat Sep 02, 2017 10:42 pm

There is a small piece of code that was added into my fedex module which checks on which product is in the cart and only quotes a fedex rate if a specific product is in the cart. Currently, it only quotes fedex rates if there is nothing else but product model 0055 in the cart. I would like to modify the code so that it quotes me a FedEx quote if there is product model 0055 or 0044, or both in the cart.

Code: Select all

$cartProds = $this->cart->getProducts();
if(count($cartProds) == 1) {
	foreach ($cartProds as $product) {
		if($product["model"] != "0055") {
			return array();
		}
	}
} else {
	return array();
}
Judging by my elementary coding skills, I believe it is first checking if there is only one product in the cart, if the product is not 0055 it quotes nothing, otherwise it starts to quote. My best guess would be to change it so that it checks if there is one or two products in the cart and then checks if the product/s is/are not 0055 or 0044, if true then it does nothing, else it quotes a rate.

Thank you in advance for your help!
Last edited by wafflemeister on Sat Sep 02, 2017 11:00 pm, edited 1 time in total.

Active Member

Posts

Joined
Fri Jun 21, 2013 11:10 pm

Post by yodapt » Sat Sep 02, 2017 10:58 pm

If I understood it right :

Code: Select all

$cartProds = $this->cart->getProducts();
if(count($cartProds) == 1) {
	foreach ($cartProds as $product) {
		if($product["model"] != "0055" OR $product["model"] != "0044") {
			return array();
		}
	}
} else {
	return array();
}

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by wafflemeister » Sat Sep 02, 2017 11:03 pm

Thank you yodapt.

How would you deal with...

Code: Select all

if(count($cartProds) == 1) {
Because if product 0055 and 0044 are in the basket then we have 2 items in the basket. Correct me if I am wrong but that if function only works if product count is equal to 1. Technically it should check for product count being 1 or 2, no?

Active Member

Posts

Joined
Fri Jun 21, 2013 11:10 pm

Post by yodapt » Sat Sep 02, 2017 11:38 pm

Ups, sorry, my fault ...

Code: Select all

$cartProds = $this->cart->getProducts();

$rate_flag = true;

foreach ($cartProds as $product) {
	if($product["model"] != "0055" OR $product["model"] != "0044") {
		$rate_flag = false;
	}
}

if ($rate_flag === false) {
	return array();
}

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by wafflemeister » Sun Sep 03, 2017 12:45 am

hmm.. that does not seem to work either, no shipping rate returned.

Active Member

Posts

Joined
Fri Jun 21, 2013 11:10 pm

Post by yodapt » Sun Sep 03, 2017 1:00 am

Replace OR with AND

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by wafflemeister » Sun Sep 03, 2017 1:08 am

Perfect, that fixed it :o Thank you very much!

Active Member

Posts

Joined
Fri Jun 21, 2013 11:10 pm
Who is online

Users browsing this forum: Yahoo [Bot] and 529 guests