Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding multiple items, saving to db #24

Open
lstables opened this issue Dec 11, 2014 · 4 comments
Open

Adding multiple items, saving to db #24

lstables opened this issue Dec 11, 2014 · 4 comments

Comments

@lstables
Copy link

I'm having an issue (or me not understanding) how to to save more than one item to my database.

If i die and dump Cart::contents() i get the following: which shows two items.

      protected 'addModifier' => int 1
      protected 'data' => 
        array (size=11)
          'id' => string '100' (length=3)
          'name' => string 'Beautiful Evening Dress' (length=23)
          'price' => string '35.00' (length=5)
          'quantity' => string '1' (length=1)
          'image' => string 'dtTCkLMT3C7lrYE6b1afd6H1hH5IyJ6hYnPWhQbHwkGgCIfhmaTsP9kUhxUr.jpg' (length=64)
          'path' => string 'category/new-in' (length=15)
          'description' => string 'Beautiful Evening Dress ' (length=24)
          'stock' => string '0' (length=1)
          'delivery' => string '3.99' (length=4)
          'colour' => string 'Black' (length=5)
          'size' => string '22' (length=2)
  '6de83ad2f06a80ee5b06ead51cb74fb5' => 
    object(Moltin\Cart\Item)[137]
      protected 'identifier' => string '6de83ad2f06a80ee5b06ead51cb74fb5' (length=32)
      protected 'store' => 
        object(Moltin\Cart\Storage\LaravelSession)[138]
          protected 'identifier' => null
          public 'id' => string '66f7ef23c389dcafb9394506a5b5d934' (length=32)
      protected 'tax' => 
        object(Moltin\Tax\Tax)[139]
          protected 'percentage' => int 0
          protected 'deductModifier' => int 1
          protected 'addModifier' => int 1
      protected 'data' => 
        array (size=11)
          'id' => string '53' (length=2)
          'name' => string 'Black and Silver Pattern dress with Sequins ' (length=44)
          'price' => string '25.00' (length=5)
          'quantity' => string '1' (length=1)
          'image' => string 'USoWtjCsby50.jpg' (length=16)
          'path' => string 'category/new-in' (length=15)
          'description' => string 'Black and Silver Pattern dress with Sequins ' (length=44)
          'stock' => string '1' (length=1)
          'delivery' => string '3.99' (length=4)
          'colour' => string 'Patterned' (length=9)
          'size' => string '14' (length=2)

So the question is, how do i save these items to the DB?

@jHoldroyd @AJSturrock @outrunthewolf

@lstables
Copy link
Author

Anyone will to help on this?

@outrunthewolf
Copy link

Direct help with your DB integration is a bit out of scope of this repo.

But off the top of my head, I would simply loop through the cart object collecting each item, its data, and push that to your database.

@jHoldroyd
Copy link

If all you're looking to do is store your carts in a database then the best way would be to create a new storage driver. Take a look at Storage/Runtime.php for the methods you need and create a mysql version. Upon initialising your cart you can use the new custom class, meaning your carts are always in the database and upto date.

Having said that, what it sounds like you're really trying to do is store orders, which is outside the scope of the cart package and not something we can really help with.

@lstables
Copy link
Author

I have a foreach loop but it doesn't insert multiple items would i need to pass [] as well to then store as multiple currently it only stores one item even if there' 3 in the cart contents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants