Jump to content
Octane

Need to find specific item in $order

Recommended Posts

I have a certain product that cannot be sent by airmail. I am trying to modify my shipping module to throw an error if this product is in their cart.

 

My php skills are very basic. Please excuse the stupid question. I do need to sort this out though.

 

I've tried the following:

$foundproduct = false;

if (in_array("product", $order)) {
 $foundproduct = true;
}

 

This gives me the following error:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in catalog/includes/modules/shipping/salargeparcel.php on line 186

 

Can someone please give me the correct php?

 

Thanks

Share this post


Link to post
Share on other sites

$foundproduct = false;

if (in_array(X, $cart->get_products())) {
 $foundproduct = true;
}

 

Change X to the ID of the product.

 

What you do with foundproduct = true is up to you.

 

Edit: you might needf to global the $cart in the shipping module

Edited by burt

Share this post


Link to post
Share on other sites

Thanks for the quick reply. I still can't seem to get it to work. This is the code I've got:

$foundultra = false;
if (in_array("Ultra Race Fuel Concentrate", $cart->get_products())) {
 $foundultra = true;
}

However when I test for it, it always tests false. The product is in the array:

 

print_r ($cart->get_products());

Array

(

[0] => Array

(

[id] => 31

[name] => Street Octane Booster

[model] => 3 RON

[image] => Street.jpg

[price] => 50.0000

[quantity] => 1

[weight] => 0.22

[final_price] => 50

[tax_class_id] => 0

[attributes] =>

)

 

[1] => Array

(

[id] => 29

[name] => Ultra Race Fuel Concentrate

[model] => 6-10 RON

[image] => Ultra.jpg

[price] => 250.0000

[quantity] => 1

[weight] => 1.15

[final_price] => 250

[tax_class_id] => 0

[attributes] =>

)

 

)

 

This shouldn't be that difficult. I'm wondering about myself today.

Share this post


Link to post
Share on other sites

This is what I'm trying to do:

 

  if (in_array("Ultra Race Fuel Concentrate", $cart->get_products())) {
    $this->quotes = array('id' => $this->code,
						  'module' => MODULE_SHIPPING_SALARGEPARCEL_TEXT_TITLE,
						  'methods' => array(array('title' => $this->quotes['error'])));
    $this->quotes['error'] = 'NF Ultra Race Fuel Concentrate cannot be shipped by airmail.';

    return $this->quotes;
  }

Share this post


Link to post
Share on other sites

Ultra Race Fuel Concentrate will always return false, you have to use the product ID, if more than 1 product you'll need to comma seperate the id's and explode them.

 

Read this thread for help, a lot of the code you need is written, just needs slight modification:

http://forums.oscommerce.com/topic/395429-restricting-certain-products-from-paypal-payments/


Follow the community build:

BS3 to osCommerce Responsive from the Get Go!

Check out the new construction:

Admin Gone to Total BS!

Share this post


Link to post
Share on other sites

Thank you WebSource 5, that gave me the info I needed. I got it working. Here is my final source:

  $products = $cart->get_products();
  for ($i=0, $n=sizeof($products); $i<$n; $i++) {
    if ($products[$i]['name']=="Ultra Race Fuel Concentrate") {
	  $this->quotes = array('id' => $this->code,
						    'module' => MODULE_SHIPPING_SALARGEPARCEL_TEXT_TITLE,
						    'methods' => array(array('title' => $this->quotes['error'])));
	  $this->quotes['error'] = 'NF Ultra Race Fuel Concentrate cannot be shipped by airmail.';
   return $this->quotes;
    }
  }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×