motorcity Posted January 12, 2013 Share Posted January 12, 2013 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] => ) ) Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/ Share on other sites More sharing options...
salathe Posted January 12, 2013 Share Posted January 12, 2013 $products[0]['vendors_id'] = 15; Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405213 Share on other sites More sharing options...
Christian F. Posted January 12, 2013 Share Posted January 12, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405219 Share on other sites More sharing options...
motorcity Posted January 12, 2013 Author Share Posted January 12, 2013 $products[0]['vendors_id'] = 15; Thanks You! Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405229 Share on other sites More sharing options...
motorcity Posted January 13, 2013 Author Share Posted January 13, 2013 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'}; Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405338 Share on other sites More sharing options...
Barand Posted January 13, 2013 Share Posted January 13, 2013 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405396 Share on other sites More sharing options...
DavidAM Posted January 13, 2013 Share Posted January 13, 2013 A little bit of code would help, too. You could be fighting a scope issue here. Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405399 Share on other sites More sharing options...
motorcity Posted January 13, 2013 Author Share Posted January 13, 2013 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" Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405400 Share on other sites More sharing options...
motorcity Posted January 13, 2013 Author Share Posted January 13, 2013 (edited) 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 January 13, 2013 by motorcity Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405412 Share on other sites More sharing options...
Barand Posted January 13, 2013 Share Posted January 13, 2013 echo $orders->product[0]['vendor_id'] Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405413 Share on other sites More sharing options...
motorcity Posted January 14, 2013 Author Share Posted January 14, 2013 echo $orders->product[0]['vendor_id'] Not able to get anything out of this. tried $order & $orders, product & products, vendor & vendors & most / all? possible combinations. Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405421 Share on other sites More sharing options...
motorcity Posted January 14, 2013 Author Share Posted January 14, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405425 Share on other sites More sharing options...
Barand Posted January 14, 2013 Share Posted January 14, 2013 So now you know how to access it, it's a small step to $order->products[0]['vendors_id'] = 15; Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405426 Share on other sites More sharing options...
Jessica Posted January 14, 2013 Share Posted January 14, 2013 Is that really not stored in a database? Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405427 Share on other sites More sharing options...
motorcity Posted January 14, 2013 Author Share Posted January 14, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405430 Share on other sites More sharing options...
Jessica Posted January 14, 2013 Share Posted January 14, 2013 The vendor id for a specific product ought to be stored in a database. Not changed in the code. Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405433 Share on other sites More sharing options...
motorcity Posted January 14, 2013 Author Share Posted January 14, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405441 Share on other sites More sharing options...
Jessica Posted January 14, 2013 Share Posted January 14, 2013 Then you'll want to find the code which generates that array. Otherwise you will indeed have to change it on every page that accesses that array, as you've already discovered. Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405443 Share on other sites More sharing options...
motorcity Posted January 14, 2013 Author Share Posted January 14, 2013 Right! So can we safely assume that for whatever illogical reason we are going back to the db to double dip on which vendors_id is going to be the one for this product on this order? Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405447 Share on other sites More sharing options...
Jessica Posted January 14, 2013 Share Posted January 14, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405448 Share on other sites More sharing options...
motorcity Posted January 14, 2013 Author Share Posted January 14, 2013 (edited) I've probably been the wrong way since birth. But that's a different subject. 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 January 14, 2013 by motorcity Quote Link to comment https://forums.phpfreaks.com/topic/273072-change-a-value-in-multidimensional-array/#findComment-1405452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.