Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show product image on user favorites page #114

Merged
merged 1 commit into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/app/core/services/product.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getUserFavoriteProducts } from './../../user/reducers/selector';
import { getTaxonomies } from './../../product/reducers/selectors';
import { Taxonomy } from './../models/taxonomy';
import { HttpClient } from '@angular/common/http';
Expand Down Expand Up @@ -48,7 +49,9 @@ export class ProductService {

removeFromFavorite(id: number): Observable<{}> { return this.http.delete<{}>(`favorite_products/${id}`) }

getFavoriteProducts(): Observable<Array<Product>> { return this.http.get<Array<Product>>(`favorite_products`) }
getFavoriteProducts(): Observable<Array<Product>> { return this.http.get<Array<Product>>(`favorite_products.json`) }

getUserFavoriteProducts(): Observable<Array<Product>> { return this.http.get<Array<Product>>(`spree/user_favorite_products.json`) }

// tslint:disable-next-line:max-line-length
getProducts_by_taxon(id: number): Observable<Array<Product>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<tr>
<td>
<img [src]="getProductImageUrl()" width="150px" height="150px">
</td>
<td>{{ product.name }}</td>
<td>{{ product.description }}</td>
<td>
<button (click)="removeFromFavorite(product.id)" class="btn btn-primary">Remove</button>
</td>
</tr>
</tr>
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ export class FavoriteProductListItemComponent implements OnInit {
});
}

getProductImageUrl() {
// tslint:disable-next-line:max-line-length
return environment.apiEndpoint + `/spree/products/${this.product.master.images[0].id}/product/${this.product.master.images[0].attachment_file_name}`
}

}
2 changes: 1 addition & 1 deletion src/app/user/effects/user.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class UserEffects {
@Effect()
GetUserFavoriteProducts$: Observable<Action> = this.actions$
.ofType(UserActions.GET_USER_FAVORITE_PRODUCTS)
.switchMap(() => this.productService.getFavoriteProducts())
.switchMap(() => this.productService.getUserFavoriteProducts())
.map((products) => this.userActions.getUserFavoriteProductsSuccess(products));

}