Jump to content

Change a value in multidimensional array


motorcity

Recommended Posts

I'm trying to change the vendors_id based on some other conditions in oscommerce shopping_cart.php (php version 5.2.9)

 

Here's the output from <?php print_r($products); ?>

Array ( [0] => Array ( [id] => 1 [name] => 07261/07561 Tool Holder 24in [model] => 07261 [image] => 0010041.JPG [price] => 15.0600 [quantity] => 10 [weight] => 4.1700 [length] => 26.750 [width] => 9.750 [height] => 5.500 [ready_to_ship] => [ups_shipable] => 1 [shelf_pack] => 6 [velocity_code] => A [inventory] => 143 [final_price] => 15.06 [tax_class_id] => 1 [vendors_id] => 6 [vendors_name] => 29 - 50 UI [attributes] => ) [] => 15 )

 

$switchme = ($products['vendors_id']);
$products[$switchme] = '15';

 

I've tried a bunch of things here that didn't work. As I understand it the first array allows purchase of multiple items, I'm never getting into the right spot. Without the above code the printout looks like this;

 

Array ( [0] => Array ( [id] => 1 [name] => 07261/07561 Tool Holder 24in [model] => 07261 [image] => 0010041.JPG [price] => 15.0600 [quantity] => 4 [weight] => 4.1700 [length] => 26.750 [width] => 9.750 [height] => 5.500 [ready_to_ship] => [ups_shipable] => 1 [shelf_pack] => 6 [velocity_code] => A [inventory] => 143 [final_price] => 15.06 [tax_class_id] => 1 [vendors_id] => 6 [vendors_name] => 29 - 50 UI [attributes] => ) )

Link to comment
Share on other sites

Notice this bit:

Array ( [0] => Array 

 

It tells you that $Products is an array, containing another array. A 2 dimensional array, in other words.

You're trying to use it as a single-dimension array, which is not going to work.

 

Thanks. This works just fine $products[0]['vendors_id'] = '15';

But it isn't actually doing what I'm trying to do. In the next file checkout_shipping.php the vendors_id returns to what it was originally.

order Object ( [info] => Array ( [order_status] => 1 [currency] => USD [currency_value] => 1.00000000 [payment_method] => [cc_type] => [cc_owner] => [cc_number] => [cc_expires] => [shipping_method] => [shipping_cost] => [subtotal] => 60.24 [shipping_tax] => [tax] => 0 [tax_groups] => Array ( [unknown tax rate] => 0 ) [comments] => [total] => 60.24 ) [totals] => Array ( ) [products] => Array ( [0] => Array ( [qty] => 4 [name] => 07261/07561 Tool Holder 24in [model] => 07261 [tax] => 0 [tax_description] => Unknown tax rate [price] => 15.0600 [final_price] => 15.06 [vendors_id] => 6 [vendors_name] => 29 - 50 UI [weight] => 4.1700 [id] => 1 ) ) [customer] => Array ( [firstname] => richard [lastname] => brown [company] => [street_address] => ......omitted a bunch more........there are 12 different arrays enclosed here

 

This doesn't through any errors, but it doesn't do it either

$info{$products[0]['vendors_id'] = '15'};

Link to comment
Share on other sites

It would help us, and you, immensely if you were to use something like this to output your array

 

echo '<pre>',print_r($array, true),'</pre>';

 

Thank you very much! I've been trying to find some way to make sense of this for hours;

 

order Object
(
[info] => Array
 (
	 [order_status] => 1
	 [currency] => USD
	 [currency_value] => 1.00000000
	 [payment_method] =>
	 [cc_type] =>
	 [cc_owner] =>
	 [cc_number] =>
	 [cc_expires] =>
	 [shipping_method] =>
	 [shipping_cost] =>
	 [subtotal] => 768.06
	 [shipping_tax] =>
	 [tax] => 0
	 [tax_groups] => Array
		 (
			 [unknown tax rate] => 0
		 )
	 [comments] =>
	 [total] => 768.06
 )
[totals] => Array
 (
 )
[products] => Array
 (
	 [0] => Array
		 (
			 [qty] => 51
			 [name] => 07261/07561 Tool Holder 24in
			 [model] => 07261
			 [tax] => 0
			 [tax_description] => Unknown tax rate
			 [price] => 15.0600
			 [final_price] => 15.06
			 [vendors_id] => 6
			 [vendors_name] => 29 - 50 UI
			 [weight] => 4.1700
			 [id] => 1
		 )
 )

That's not the whole thing but I'm sure it's good enough.

Nothing I've tried so far addresses the first part, "order Object"

Link to comment
Share on other sites

A little bit of code would help, too. You could be fighting a scope issue here.

Lost my post back to you. Seemed like the formum just died.

All I have is a database field, if true, and several other things work out, switch the vendors_id. There are a number of other files, classes, and functions that go into this big array. This is oscommerce 2.2rc2a all the vendors stuff is from a well established contribution called multi vendor shipping.

That established. It doesn't make sense to me that my new field above, the vendor_id, and the product_id all come from the same db table, we put it all together in the shopping_cart.php then we're going to query the db one more time to find out which vendor_id to use.

 

I guess I need to read up on foreach() here to make a change to "order Object", is that about right?

Edited by motorcity
Link to comment
Share on other sites

Okay, my bad. We do display the number 6 in the tab title (as early as I cound put it in there)

<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo $order->products[0]['vendors_id'];
echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">

 

This is in checkout_shipping.php the second file, Of course, 6 is the original value. We want it to be 15.

Link to comment
Share on other sites

I really appreciate all the help. Thanks to all. Unfortunately, it still switches back to the original vendor when you click on checkout. It must be in a class or function. The advice followed here absolutely changes whats in the array but I'm missing something along the line.

 

Hello Jessica, not quite sure I understand the question.

Link to comment
Share on other sites

The vendor id for a specific product ought to be stored in a database. Not changed in the code.

Normally that's exactly the way it is. What I'm trying to do is set a switch to change from any vendor to one special vendor. This is because under certain conditions we'll direct ship an item from a different location based on quantity and price. If the switch is false, or quantity or price do not qualify, shipping will be through the normal vendor, the one in the db.

Link to comment
Share on other sites

Don't take this the wrong way but do you understand how PHP works?

Every page load, unless you've stored information in the session, that information has to be selected from the database again. 

 

Simply changing the value right before it's displayed on one page would not affect the other pages. 

 

 

You said you're using something that is supposed to support "multi vendor shipping" - you shouldn't have to be touching the code at all. 

Link to comment
Share on other sites

I've probably been the wrong way since birth. But that's a different subject. :tease-01:

Thanks. I think you nailed it here. I have to get the alternate vendor into the session, or hard code it throughout the checkout process. Perhaps I could add a good old tep function and call it from each file or find where the array gets into the session.

 

Regarding mvs, which is great, one thing you can't do is switch vendors. If a product is always shipped from one place, one way, its fine. We're trying to modify that because that's not how it actually works for for us.

Edited by motorcity
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.