Jump to content

Recommended Posts

Hey all,

 

I think this is the right spot for this question but if its not i apologize.

 

I'm starting work on someones ecommerce site and I have this cart object being passed to the shipping information. I need to be able to loop through the cart and pull out the model and sku of the items but im having a really hard time looping through this. Here is a sample of one of the cart objects with one product in it

 

object(Cart)#5 (15) {
  ["message"]=>
  array(0) {
  }
  ["cart_id"]=>
  string(5) "18613"
  ["cart_hash"]=>
  string(32) "d98994620956e6bf916c18d870d8917a"
  ["promo_code"]=>
  string( "TESTSHIP"
  ["coupon_code"]=>
  string(0) ""
  ["coupon_attempts"]=>
  int(0)
  ["coupon"]=>
  NULL
  ["discount_code"]=>
  NULL
  ["discount"]=>
  NULL
  ["offer"]=>
  string( "WDRTGY67"
  ["date_created"]=>
  string(19) "2008-06-23 23:23:00"
  ["date_last_accessed"]=>
  string(26) "2008-06-23 23:34:46.578065"
  ["tracking_manager"]=>
  object(TrackingManager)#6 (1) {
    ["attempt_log:private"]=>
    NULL
  }
  ["products"]=>
  array(1) {
    [3768888]=>
    array(2) {
      ["quantity"]=>
      string(1) "1"
      ["product"]=>
      object(Product)#7 (27) {
        ["message"]=>
        array(0) {
        }
        ["id"]=>
        string(7) "3768888"
        ["offer"]=>
        bool(true)
        ["group_code"]=>
        NULL
        ["ship_method"]=>
        string(2) "  "
        ["drop_ship_vendor"]=>
        string(4) "OFMI"
        ["edp_no"]=>
        string(5) "10207"
        ["model"]=>
        string(5) "OM700"
        ["description"]=>
        string(23) "Big & Tall Fabric Chair"
        ["status"]=>
        string(2) "T1"
        ["weight"]=>
        string(7) "70.0000"
        ["ship_class"]=>
        string(0) ""
        ["color"]=>
        string(5) "Black"
        ["sku"]=>
        string(15) "OF CHRBA 001 BK"
        ["price"]=>
        string(6) "339.00"
        ["break_1"]=>
        string(1) "0"
        ["break_1_price"]=>
        string(4) "0.00"
        ["break_2"]=>
        string(1) "0"
        ["break_2_price"]=>
        string(4) "0.00"
        ["break_3"]=>
        string(1) "0"
        ["break_3_price"]=>
        string(4) "0.00"
        ["break_4"]=>
        string(1) "0"
        ["break_4_price"]=>
        string(4) "0.00"
        ["length"]=>
        string(2) "23"
        ["width"]=>
        string(2) "27"
        ["depth"]=>
        string(1) "0"
        ["post_hand"]=>
        string(4) "0.00"
      }
    }
  }
  ["quick_buys:private"]=>
  NULL
}

 

here is the code that is taking the cart object in my shipping helper class

 

function setCart(&$cart){
      $this->cart = $cart;
      $this->products = $cart->products;
   }

 

so now products is just whats in the products array in the cart object. i have the following loop to go through and get the quantity

 

foreach($this->products as $k => $v){

         
         for($i=0; $i < $this->products[$k]['quantity'] ; $i++){
            $ups_rc->addProduct($prod);
            $usps_rc->addProduct($prod);
         }
      }

 

So now, i can access the data one level in but i cant figure out how to loop through the 'product' array inside that and pull the model number and sku.. How do i go about doing this? im new to this advanced of arrays. Sorry for a long description for a simple question, i just wanted to make sure anyone would understand what i was asking.

 

Thanks in advance =-)

Link to comment
https://forums.phpfreaks.com/topic/111870-object-array-issue/
Share on other sites

Mind showing your class code, at the very least the parts that show how the object data (SKU, model number, etc) is actually stored?  I hate reading through var_dump output...makes everything look like an array.  It would be beneficial to see it for all involved classes, so not just the individual products, but the cart and shipping manager to.     

Link to comment
https://forums.phpfreaks.com/topic/111870-object-array-issue/#findComment-574374
Share on other sites

But each product is an object, so perhaps (I'm not familiar with vardump's output, and I'm assuming the class vars are public):

$this->products[$k]['product']->model

$this->products[$k]['product']->sku

 

In this code,

foreach($this->products as $k => $v){         
  for($i=0; $i < $this->products[$k]['quantity'] ; $i++){
    $ups_rc->addProduct($prod);
    $usps_rc->addProduct($prod);
  }
}

Where does $prod come from? Seems to be an error.

Link to comment
https://forums.phpfreaks.com/topic/111870-object-array-issue/#findComment-580966
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.