S
S
semki0962019-04-26 10:37:34
Laravel
semki096, 2019-04-26 10:37:34

How to properly display items in the shopping cart?

Id and quantity of goods are stored in the session. Getting cart data from session, here is my cart data array

array:3 [▼
  60 => array:2 [▼
    "item_id" => "60"
    "quantity" => 1
  ]
  3 => array:2 [▼
    "item_id" => "3"
    "quantity" => 1
  ]
  72 => array:2 [▼
    "item_id" => "72"
    "quantity" => 3
  ]
]

Now I need to display them in the shopping cart. How to do it right? Probably something like this . But in this collection, you still need to add a quantity, and in the future a number of parameters such as color, etc. I mean, it's kind of difficult. I would be grateful for advice.
$products = Product::find([60, 3, 72]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2019-04-26
@semki096

Well, yes, that's about it. When you pull the cart, pull all the products by id, convert to a collection and then go through the cart and add the "product" key with the corresponding product you pulled earlier.
Further with this, either in the view, or to the front. Sobsno everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question