Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function addingItem($id)
- {
- $product = Product::where('id', $id)->firstOrFail();
- Cart::add(array(
- 'id' => $product->id,
- 'name' => $product->title,
- 'price' => $product->price,
- 'quantity' => 1,
- 'attributes' => array(),
- ));
- Session::flash('success', 'This product added to your cart successfully.');
- return redirect()->back();
- }
- public function addingItem($id)
- {
- $product = Product::where('id', $id)->firstOrFail();
- //newly added
- foreach($product->suboptions as $subs) {
- $title = $subs->title;
- $price = $subs->price;
- }
- $customAttributes = [
- 'attr' => [
- 'label' => $subs->title,
- 'price' => $subs->price,
- ]
- ];
- Cart::add(array(
- 'id' => $product->id,
- 'name' => $product->title,
- 'price' => $product->price,
- 'quantity' => 1,
- 'attributes' => array($customAttributes), //and added here
- ));
- Session::flash('success', 'This product added to your cart successfully.');
- return redirect()->back();
- }
- Cart::add(array(
- array(
- 'id' => 456,
- 'name' => 'Sample Item 1',
- 'price' => 67.99,
- 'quantity' => 4,
- 'attributes' => array()
- ),
- array(
- 'id' => 568,
- 'name' => 'Sample Item 2',
- 'price' => 69.25,
- 'quantity' => 4,
- 'attributes' => array(
- 'size' => 'L',
- 'color' => 'blue'
- )
- ),
- ));
Add Comment
Please, Sign In to add comment