small medium large xlarge

Generic-user-small
17 Aug 2009, 13:56
Barry Mccall (4 posts)

My problem lies in the last 2 bullets. I added code to make the newly selected items grow into place, and in fact it is interfering with the next step when I start removing them from the cart. the problem is this.

store_helper.rb

def hidden_tr_if(condition, attributes = {})
  if condition
    attributes["style"] = "display: none" 
  end
  attrs = tag_options(attributes.stringify_keys)
  "<tr #{attrs}>" 
end

_cart_item.erb

<% if cart_item == @current_item %>
	<%= hidden_tr_if(cart_item.quantity == 1 && request.xhr?, :id => "current_item") %>
	
<% else %>
	<tr>
<% end %>

		<td><%= cart_item.quantity %>&times;</td>
		<td><%=h cart_item.title %></td>
		<td class="item-price"><%= number_to_currency(cart_item.price) %></td>
		<td><%= link_to_remote "&times;",
    {:url => {:action => :remove_from_cart, :id => cart_item.product}},
    {:href => url_for(:action => :remove_from_cart, :id => cart_item.product)} %></td>
	</tr>

this line:

<% if cart_item == @current_item %>
	<%= hidden_tr_if(cart_item.quantity == 1 && request.xhr?, :id => "current_item") %>

messes up my display when I have an item with the quantity of 2 when I decrement it once, quantity of 1 remains but is is immediatly hidden.

if so I changed this line to this:

<% if cart_item == @current_item %>
	<%= hidden_tr_if(cart_item.quantity == 0 && request.xhr?, :id => "current_item") %>

Decrementing works, but I get the flickering artifact of the non-hidden first item when I add a product for the first time. I tried a few hacks but I am still a novice at ruby/html/js. I have come to the conclusion that I need a way to hide the product when its quantity increments up from 0 to 1, but if it decrements from 2 to 1 to not hide it.

Any help on this would be appreciated

You must be logged in to comment