Blue Yourself - Addie, Bo, Janice, Rana#23
Blue Yourself - Addie, Bo, Janice, Rana#23add2point71dots wants to merge 359 commits intoAda-C7:masterfrom
Conversation
custom method in_cart? added
janice/styling
…Through a method to choose a random photo in the category model. Messed around with the latest migration (un-commenting time-stamp).
Pimped out category views. Also tweaked a few oversights in the CSS. …
Pimped out category views. Also tweaked a few oversights in the CSS. …
Attempting to correct a grammatical error in a commit message!
Bt make orderitem controller
…tax error in orderitem.rb
added some orderitem controller tests and fixed validation method syn…
Al/order bug fix
Rs/products/create
Al/vendor index
trying to fix tests
janice/vendor styling
Final attempt for vendor polish.
fixed nil cart bug
makes number appear in cart on all pages
Added styling to order management.
Al/vendor title
Formatted checkout. It's rugged. But it's decent.
bEtsyWhat We're Looking For
|
| end | ||
| # if the prduct has already been added to the cart, then store the current inventory of that product into item_quantity | ||
| if @cart.orderitems.find_by(product_id: params[:orderitem][:product_id]) | ||
| item_quantity = @cart.orderitems.find_by(product_id: params[:orderitem][:product_id]).quantity |
There was a problem hiding this comment.
Here you're re-querying the database which is unnecessary. The above result should be stored in a variable so you don't do a duplicate query.
| # shopper attemps to add a new item to a cart without specifying quantity | ||
| elsif quantity == 0 | ||
| flash[:failure] = "You must add at least 1 item to the cart" | ||
| redirect_to product_path(product.id) |
There was a problem hiding this comment.
Room to DRY up these conditionals since only the first line is unique within each statement.
| end | ||
|
|
||
| def fulfillment_cancelled | ||
| render 'fulfillment', layout: 'fulfillment-template' |
There was a problem hiding this comment.
Seems like since each of these controller actions are the same, that you don't need separate controller actions for this action.
| end | ||
| else | ||
| session[:vendor_id] = vendor.id | ||
| flash[:success] = "Logged in successfully!" |
There was a problem hiding this comment.
Duplication here you can avoid by putting outside the conditional statement
|
|
||
| private | ||
|
|
||
| def tally_earnings |
There was a problem hiding this comment.
This is not appropriate for the controller and should all be within the model
| <%= f.label :email %><%= f.text_field :email%> | ||
| <%= f.label :street_address %><%= f.text_area :street_address%> <br> | ||
| <%= f.label :city %><%= f.text_field :city %> | ||
| <%= f.label :state %><%= f.select :state, [ |
There was a problem hiding this comment.
This drop down is cool! In the future - you could use "locales" and put this type of thing into a separate file so that it's not directly in your view
| @@ -0,0 +1,18 @@ | |||
| <h1> <%= filter %> </h1> | |||
| <% @order_items.where(status: filter).each do | order_item | %> | |||
There was a problem hiding this comment.
The filtering generally should not be done within the view - but rather the controller (or even the model). Whatever order items you're looking for should be passed to the view - already filtered
| <% @vendor.products.each do |product| %> | ||
| <section class='product'> | ||
| <h4 class="name"><%= product.name %></h4> | ||
| <h4 class="price">$<%= sprintf('%.2f', product.price) %></h4> |
There was a problem hiding this comment.
Might be good to create a view helper for this in the future so that you can format all prices the same way across all views without needing to duplicate this logic
| it "won't create a new orderitem instance if product already exists in the cart" do | ||
| @cart.add_to_cart({ :orderitem => { product_id: products(:five).id, quantity: 1 } }) | ||
| before = @cart.orderitems.count | ||
| @cart.add_to_cart({ :orderitem => { product_id: products(:five).id, quantity: 1 } }) |
There was a problem hiding this comment.
These tests seems to be using this hash throughout so it would be good to DRY this up and use a shared variable
| end | ||
|
|
||
| it "rejects invalid categories" do | ||
| invalid_categories = ['at', 'do', 'phd thesis', 1337, nil] |
There was a problem hiding this comment.
I like the way you're using this array to test multiple scenarios for the same outcome
3568d9c to
74fb478
Compare
bEtsy
Congratulations! You're submitting your assignment! These comprehension questions should be answered by all members of your team, not by a single teammate.
Comprehension Questions