Skip to content

Commit

Permalink
Display unit price on /cart page
Browse files Browse the repository at this point in the history
 - Use a new class to specify css customization
 - Add to `line_item.rb` a fake method: `unit_price_price_and_unit` @andrewpbrett will change it with real values.
 - Add a new variable: $text-xs to specify small font-size
  • Loading branch information
jibees committed Feb 16, 2021
1 parent 6a8d2c5 commit 037e9d6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/darkswarm/cart-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
}
}

.unit-price {
color: $grey-500;
font-size: $text-xs;
}


input {
&.ng-invalid-stock,
&.ng-invalid-number {
Expand Down
2 changes: 2 additions & 0 deletions app/assets/stylesheets/darkswarm/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ $shop-sidebar-overlay: rgba(0, 0, 0, 0.5);
$transition-sidebar: 250ms ease-in-out 0s;

$padding-small: 0.5rem;

$text-xs: 0.75rem;
6 changes: 6 additions & 0 deletions app/models/spree/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ def unit_value
final_weight_volume / quantity
end

def unit_price_price_and_unit
price = Spree::Money.new((rand * 10).round(2), currency: currency)
unit = ["item", "kg"].sample
price.to_html + " / " + unit
end

def scoper
@scoper ||= OpenFoodNetwork::ScopeVariantToHub.new(order.distributor)
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/spree/orders/_line_item.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

%td.text-right.cart-item-price{"data-hook" => "cart_item_price"}
= line_item.single_display_amount_with_adjustments.to_html
%br
%span.unit-price
= line_item.unit_price_price_and_unit
%td.text-center.cart-item-quantity{"data-hook" => "cart_item_quantity"}
- finalized_quantity = @order.completed? ? line_item.quantity : 0
= item_form.number_field :quantity,
Expand Down

0 comments on commit 037e9d6

Please sign in to comment.