0

I have a weird problem where I want to store products from my shop in a session. This works well, except for some products. The shop is part of a cms where all products are rendered the same way. When someone adds a product to the shop this will be serialized and send with ajax to a script.

Almost all items are stored, but for some reason some items don't get stored. I can't find a connection or anything and I don't get any errors returned.

So this is the code that stores the product in a session:

$storeItemNumber = (string)$post['itemcode'];
                $storeItem = array($storeItemNumber => array(
                        'title' => $post['title'],
                        'price' => $post['price'],
                        'quantity' => $post['quantity']
                    )
                );
                $shopSession->$storeItemNumber = $storeItem;

This is an example of a product that gets stored:

 array('010101000' => array(
  'title' => 'Product title - 15',
 'price' => '28.95',
 'quantity' => '1',
));

This is an example of a product that doesn't get stored:

 array('400002001' => array(
  'title' => 'Product title - Pink',
 'price' => '5.50',
 'quantity' => '1',
));

I already checked if the data gets through alright and it does right until the saving of it in a session.

What could possibly be a reason?

Rick de Graaf
  • 968
  • 1
  • 14
  • 35

1 Answers1

0

Had a look with a friend of mine and we both concluded it had something to do with the numbers. So I changed the function to the following and Now I'm able to add all the products without a problem.

I'll leave this question open for the time being, because I'm really curious why some numbers are stored and others not and what is a better/cleaner solution then mine.

Rick de Graaf
  • 968
  • 1
  • 14
  • 35