@@ -2,27 +2,37 @@ import { combineReducers } from 'redux'
22import cart , * as fromCart from './cart'
33import products , * as fromProducts from './products'
44
5+ export default combineReducers ( {
6+ cart,
7+ products
8+ } )
9+
10+ function getAddedIds ( state ) {
11+ return fromCart . getAddedIds ( state . cart )
12+ }
13+
14+ function getQuantity ( state , id ) {
15+ return fromCart . getQuantity ( state . cart , id )
16+ }
17+
18+ function getProduct ( state , id ) {
19+ return fromProducts . getProduct ( state . products , id )
20+ }
21+
522export function getTotal ( state ) {
6- return fromCart . getAddedIds ( state . cart ) . reduce ( ( total , id ) =>
7- total + (
8- fromProducts . getProduct ( state . products , id ) . price *
9- fromCart . getQuantity ( state . cart , id )
10- ) ,
23+ return getAddedIds ( state ) . reduce ( ( total , id ) =>
24+ total + getProduct ( state , id ) . price * getQuantity ( state , id ) ,
1125 0
1226 ) . toFixed ( 2 )
1327}
1428
1529export function getCartProducts ( state ) {
16- return fromCart . getAddedIds ( state . cart ) . map ( id => Object . assign (
30+ return getAddedIds ( state ) . map ( id => Object . assign (
1731 { } ,
18- fromProducts . getProduct ( state . products , id ) ,
32+ getProduct ( state , id ) ,
1933 {
20- quantity : fromCart . getQuantity ( state . cart , id )
34+ quantity : getQuantity ( state , id )
2135 }
2236 ) )
2337}
2438
25- export default combineReducers ( {
26- cart,
27- products
28- } )
0 commit comments