Guest User

Untitled

a guest
Jan 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. public function addingItem($id)
  2. {
  3. $product = Product::where('id', $id)->firstOrFail();
  4.  
  5. Cart::add(array(
  6. 'id' => $product->id,
  7. 'name' => $product->title,
  8. 'price' => $product->price,
  9. 'quantity' => 1,
  10. 'attributes' => array(),
  11. ));
  12. Session::flash('success', 'This product added to your cart successfully.');
  13. return redirect()->back();
  14. }
  15.  
  16. public function addingItem($id)
  17. {
  18. $product = Product::where('id', $id)->firstOrFail();
  19. //newly added
  20. foreach($product->suboptions as $subs) {
  21. $title = $subs->title;
  22. $price = $subs->price;
  23. }
  24.  
  25. $customAttributes = [
  26. 'attr' => [
  27. 'label' => $subs->title,
  28. 'price' => $subs->price,
  29. ]
  30. ];
  31.  
  32. Cart::add(array(
  33. 'id' => $product->id,
  34. 'name' => $product->title,
  35. 'price' => $product->price,
  36. 'quantity' => 1,
  37. 'attributes' => array($customAttributes), //and added here
  38. ));
  39. Session::flash('success', 'This product added to your cart successfully.');
  40. return redirect()->back();
  41. }
  42.  
  43. Cart::add(array(
  44. array(
  45. 'id' => 456,
  46. 'name' => 'Sample Item 1',
  47. 'price' => 67.99,
  48. 'quantity' => 4,
  49. 'attributes' => array()
  50. ),
  51. array(
  52. 'id' => 568,
  53. 'name' => 'Sample Item 2',
  54. 'price' => 69.25,
  55. 'quantity' => 4,
  56. 'attributes' => array(
  57. 'size' => 'L',
  58. 'color' => 'blue'
  59. )
  60. ),
  61. ));
Add Comment
Please, Sign In to add comment