Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need to find specific item in $order


Octane

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

Link to comment
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
Link to comment
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.

Link to comment
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;
  }

Link to comment
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://www.oscommerce.com/forums/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!

Link to comment
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;
    }
  }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...