03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

E-Commerce 261<br />

23 this.setCategory = function(category) {<br />

24 self.category = category;<br />

25 };<br />

26<br />

27 // ...<br />

28<br />

29 });<br />

.<br />

This was extracted from public/js/shared.js.<br />

Let’s move on to the shopping basket. We need to be able to add items to it, remove items from it<br />

and change quantity values.<br />

1 app.factory("BasketService", function($cookies) {<br />

2<br />

3 var products = JSON.parse($cookies.products || "[]");<br />

4<br />

5 return {<br />

6<br />

7 "getProducts" : function() {<br />

8 return products;<br />

9 },<br />

10<br />

11 "add" : function(product) {<br />

12<br />

13 products.push({<br />

14 "id" : product.id,<br />

15 "name" : product.name,<br />

16 "price" : product.price,<br />

17 "total" : product.price * 1,<br />

18 "quantity" : 1<br />

19 });<br />

20<br />

21 this.store();<br />

22<br />

23 },<br />

24<br />

25 "remove" : function(product) {<br />

26<br />

27 for (var i = 0; i < products.length; i++) {

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!