summaryrefslogblamecommitdiff
path: root/iridescence/src/components/cart/CartItem.vue
blob: c99d7143213c288df667079ac102249d33f6037c (plain) (tree)
1
          


















                                                        

                  
























                                                                 

                    
 




                                                                              
                



              



                
















                                                                           



                                                          


                                                        
     
   

         
<template>
  <div>
    <hr />
    <article class="media" id="cartItem">
      <figure class="media-left">
        <p class="image is-64x64">
          <img :src="thumbnail" :title="product.name" />
        </p>
      </figure>
      <div class="media-content">
        <nav class="level">
          <div class="level-left">
            <div class="level-item">
              <div class="content">
                <strong>
                  <p>
                    {{ product.name }}
                  </p>
                </strong>
              </div>
            </div>
          </div>
          <div class="level-right">
            <div class="level-item">Subtotal: {{ dollars }}</div>
            <div class="level-item">
              <div class="field has-addons">
                <p class="control is-expanded">
                  <a class="button is-static is-fullwidth">
                    {{ inCart }} in cart
                  </a>
                </p>
                <div class="control">
                  <a
                    @click="incrementCartQuantity(-1)"
                    class="button is-info is-outlined"
                  >
                    -
                  </a>
                </div>
                <div class="control">
                  <a
                    @click="incrementCartQuantity(1)"
                    class="button is-info is-outlined"
                  >
                    +
                  </a>
                </div>
              </div>
            </div>

            <div class="level-item">
              <button class="button is-outlined is-danger" @click="removeAll">
                Remove
              </button>
            </div>
          </div>
        </nav>
      </div>
    </article>
  </div>
</template>

<script>
export default {
  name: "CartItem",
  props: {
    id: Number,
    inCart: Number
  },
  computed: {
    product() {
      return this.$store.state.products.find(p => p.id == this.id);
    },
    dollars() {
      return "$ " + ((this.product.cents * this.inCart) / 100).toFixed(2);
    },
    thumbnail() {
      return (
        process.env.VUE_APP_IMAGE_ROOT + "/" + this.product.photo_thumbnail
      );
    }
  },
  methods: {
    incrementCartQuantity(by) {
      this.$store.commit("cartItem", { id: this.id, by });
    },
    removeAll() {
      this.$store.commit("removeItemFromCart", this.id);
    }
  }
};
</script>