appirits/comable

View on GitHub
frontend/app/views/comable/carts/show.slim

Summary

Maintainability
Test Coverage
#carts
  section.cart.col-sm-8
    h1
      = Comable.t('shopping_cart')

    - if current_comable_user.cart.errors.any?
      .errors
        ul
          - current_comable_user.cart.errors.full_messages.each do |message|
            li = message

    - if current_comable_user.cart.empty?
      = Comable.t('carts.empty')
    - else
      table
        thead
          tr
            th
            th
              = Comable.t('price')
            th
              = Comable.t('quantity')
            th

        tbody
          - current_comable_user.cart.each do |cart_item|
            - stock = cart_item.stock
            - product = stock.product
            tr
              td
                .name
                  = link_to stock.name_with_sku, comable.product_path(product)
                .caption
                  = product.caption
                - if cart_item.unstocked?
                  .error.soldout = Comable.t('soldout')
              td.price
                = number_to_currency product.price
              td.quantity
                = form_tag comable.cart_path, method: :put do
                  .form-inline.form-group
                    - selected = cart_item.quantity
                    = select_tag :quantity, options_for_select(1.upto([10, selected].max).to_a, selected)
                    = hidden_field_tag :stock_id, stock.id
                    = submit_tag Comable.t('actions.update'), class: 'btn-default'
              td
                = link_to Comable.t('actions.destroy'), comable.cart_path(stock_id: stock.id), method: :delete

  - if current_comable_user.cart.any?
    section.order.col-sm-4
      table
        thead
          tr
            th colspan="2"
              = form_for current_order, as: :order, url: comable.checkout_cart_path, method: :put do |f|
                = f.submit Comable.t('checkout'), class: 'btn btn-primary btn-lg btn-block'
        tbody
          tr.price
            th.text-right
              = Comable.t('item_total_price')
            td
              = number_to_currency current_comable_user.cart.price
          tr.count
            th.text-right
              = Comable.t('item_total_quantity')
            td
              = number_with_delimiter current_comable_user.cart.count