2

I have an application using PHP CodeIgniter's Cart library. And I need this output, to send info to google analytics:

$itemsga = array(
array('sku'=>'SDFSDF', 'name'=>'Shoes', 'category'=>'Footwear', 'price'=>'100', 'quantity'=>'1'),
array('sku'=>'123DSW', 'name'=>'Sandles', 'category'=>'Footwear', 'price'=>'87', 'quantity'=>'1'),
array('sku'=>'UHDF93', 'name'=>'Socks', 'category'=>'Footwear', 'price'=>'5.99', 'quantity'=>'2')
);

To achieve that, I created this code:

$itemsga = array(
  foreach ($this->cart->contents() as $items){
    array(
    'sku'              => $items['id'],
    'name'             => $items['name'],
    'price'            => $items['price'],
    'quantity'         => $items['qty'],
    ),
  }//endforeach
);

For some reason I'm getting a white screen. No error displayed but my array is not being built.

I know this might be a stupid question, but I got stuck. Can someone help me?

Cheers!

0

1 Answer 1

1

Change your code to:-

$itemsga = array(); // define array variable
  foreach ($this->cart->contents() as $items){
    $itemsga[] = array(
    'sku'              => $items['id'],
    'name'             => $items['name'],
    'price'            => $items['price'],
    'quantity'         => $items['qty'],
    ); // done indexing and add complete array to each index.
  }//endforeach
Sign up to request clarification or add additional context in comments.

1 Comment

Great to hear that. Please mark it as an answer. it will help others also. thanks.:):):)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.