Ama2on is e-commerce website where buyers can search for products they like. They can see the price and select affordable one.
Live Site: Ama2on
Product Controller
def index
if (params[:query] == nil)
@products = Product.all
render "api/products/index"
else
@products = Product.findBySubstring(params[:query].strip)
render "api/products/index"
end
end
Search function
search() {
if (this.state.input === undefined || this.state.input === "") {
return null;
}
this.props.fetchProducts(this.state.input);
this.props.history.push("/search?query=" + escape(this.state.input));
}
There is page where details of product are shown to the user.
update(cartItemId) {
const cartItem = this.props.cartItems[cartItemId];
if (
!this.state.updatedQty[cartItemId] ||
this.state.updatedQty[cartItemId] === cartItem.quantity
) {
return;
}
let updatedCartItem = {
product_id: cartItem.product_id,
quantity: this.state.updatedQty[cartItemId] - cartItem.quantity,
};
this.props.createCartItem(updatedCartItem).then(() => {
let updatedQty = Object.assign({}, this.state.updatedQty);
updatedQty[cartItemId] = undefined;
this.setState({
updatedQty,
});
});
}