forked from ecomplus/storefront
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(the-cart): add TheCart component
- Loading branch information
Showing
6 changed files
with
307 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script src="./js/TheCart.js"></script> | ||
<template lang="html" src="./html/TheCart.html"></template> | ||
<style lang="scss" src="./scss/TheCart.scss"></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<div class="cart"> | ||
<transition-group enter-active-class="animated fadeInDown"> | ||
<div | ||
class="row" | ||
v-if="cart.items.length" | ||
key="list"> | ||
<div class="col-md-7 col-lg-8"> | ||
<div class="cart__list"> | ||
<slot | ||
name="list" | ||
v-bind="{ items: cart.items }"> | ||
<transition-group | ||
enter-active-class="animated fadeInDown" | ||
leave-active-class="animated fadeOutUp faster position-absolute" | ||
> | ||
<cart-item | ||
v-for="item in cart.items" | ||
:key="item._id" | ||
:item="item" | ||
:name-max-length="80" | ||
/> | ||
</transition-group> | ||
</slot> | ||
</div> | ||
|
||
<recommended-items col-class-name="col-6 col-lg-3"/> | ||
|
||
<slot name="back-shopping"> | ||
<div class="cart__back d-none d-md-block my-4"> | ||
<a | ||
class="cart__btn-back btn btn-link" | ||
role="button" | ||
href="/" | ||
> | ||
<i class="fas fa-arrow-left mr-1"></i> | ||
{{ i19continueShopping }} | ||
</a> | ||
</div> | ||
</slot> | ||
</div> | ||
|
||
<div class="col-md-5 col-lg-4 mt-3 mt-md-0"> | ||
<div class="cart__info"> | ||
<slot name="info"> | ||
<div class="cart__summary-row"> | ||
<span>Subtotal</span> | ||
<div>{{ formatMoney(cart.subtotal) }}</div> | ||
</div> | ||
|
||
<transition enter-active-class="animated fadeInDown"> | ||
<div | ||
class="cart__summary-row mt-1" | ||
v-if="amount.discount"> | ||
<span> | ||
<i class="fas fa-tag mr-1"></i> | ||
{{ i19discount }} | ||
</span> | ||
<div>{{ formatMoney(amount.discount) }}</div> | ||
</div> | ||
</transition> | ||
|
||
<shipping-calculator | ||
class="cart__shipping" | ||
:can-select-services="true" | ||
:shipped-items="cart.items" | ||
@select-service="val => $emit('shipping-service', val)" | ||
@update:zip-code="val => $emit('update:zipCode', val)" | ||
/> | ||
|
||
<div class="cart__summary-row cart__total"> | ||
<span>Total</span> | ||
<a-prices | ||
:product="{ price: amount.total || cart.subtotal }" | ||
:discount-option="{ value: amount.discount }" | ||
:is-literal="true" | ||
/> | ||
</div> | ||
|
||
<slot name="checkout"> | ||
<a | ||
class="cart__btn-checkout btn btn-lg btn-block btn-success" | ||
role="button" | ||
:href="checkoutUrl" | ||
> | ||
<span class="mr-1"> | ||
<i class="fas fa-shopping-bag"></i> | ||
</span> | ||
{{ i19checkout }} | ||
</a> | ||
|
||
<a | ||
class="cart__btn-back btn btn-block btn-outline-secondary d-md-none" | ||
role="button" | ||
href="/" | ||
> | ||
<i class="fas fa-arrow-left mr-1"></i> | ||
{{ i19continueShopping }} | ||
</a> | ||
</slot> | ||
</slot> | ||
</div> | ||
|
||
<slot name="discount-applier"> | ||
<discount-applier | ||
class="cart__discount" | ||
:amount="amount" | ||
:coupon-code.sync="localDiscountCoupon" | ||
:is-coupon-applied="Boolean(discountCoupon && amount.discount)" | ||
@set-discount-rule="discountRule => $emit('set-discount-rule', discountRule)" | ||
:modules-payload="modulesPayload" | ||
/> | ||
</slot> | ||
</div> | ||
</div> | ||
|
||
<div | ||
v-else | ||
class="cart__empty" | ||
key="empty" | ||
> | ||
<slot name="empty"> | ||
<p class="lead text-muted"> | ||
{{ i19emptyCart }} ... | ||
</p> | ||
<a class="btn btn-primary" href="/"> | ||
<span class="mr-1"> | ||
<i class="fas fa-arrow-left"></i> | ||
</span> | ||
{{ i19continueShopping }} | ||
</a> | ||
</slot> | ||
</div> | ||
</transition-group> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { | ||
$ecomConfig, | ||
i18n, | ||
formatMoney | ||
} from '@ecomplus/utils' | ||
|
||
import ecomCart from '@ecomplus/shopping-cart' | ||
import APrices from './../APrices.vue' | ||
import CartItem from './../CartItem.vue' | ||
import DiscountApplier from './../DiscountApplier.vue' | ||
import ShippingCalculator from './../ShippingCalculator.vue' | ||
import RecommendedItems from './../RecommendedItems.vue' | ||
|
||
import { | ||
i19checkout, | ||
i19continueShopping, | ||
i19discount, | ||
i19emptyCart | ||
} from '@ecomplus/i18n' | ||
|
||
export default { | ||
name: 'TheCart', | ||
|
||
components: { | ||
APrices, | ||
CartItem, | ||
DiscountApplier, | ||
ShippingCalculator, | ||
RecommendedItems | ||
}, | ||
|
||
props: { | ||
ecomCart: { | ||
type: Object, | ||
default () { | ||
return ecomCart | ||
} | ||
}, | ||
lang: { | ||
type: String, | ||
default: $ecomConfig.get('lang') | ||
}, | ||
checkoutUrl: { | ||
type: String, | ||
default: '/app/#/checkout' | ||
}, | ||
amount: { | ||
type: Object, | ||
default () { | ||
return {} | ||
} | ||
}, | ||
discountCoupon: String, | ||
baseModulesRequestData: { | ||
type: Object, | ||
default () { | ||
return {} | ||
} | ||
} | ||
}, | ||
|
||
computed: { | ||
i19checkout: () => i18n(i19checkout), | ||
i19continueShopping: () => i18n(i19continueShopping), | ||
i19discount: () => i18n(i19discount), | ||
i19emptyCart: () => i18n(i19emptyCart), | ||
modulesPayload () { | ||
return this.baseModulesRequestData | ||
}, | ||
cart () { | ||
return this.ecomCart.data | ||
}, | ||
localDiscountCoupon: { | ||
get () { | ||
return this.discountCoupon | ||
}, | ||
set (couponCode) { | ||
this.$emit('update:discountCoupon', couponCode) | ||
} | ||
} | ||
}, | ||
|
||
methods: { | ||
formatMoney | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
.cart { | ||
&__empty { | ||
width: 100%; | ||
text-align: center; | ||
} | ||
|
||
.cart-item { | ||
padding-top: 1rem; | ||
border-top: 1px dotted var(--gray); | ||
|
||
&__name { | ||
margin-bottom: .5rem; | ||
} | ||
} | ||
|
||
&__discount { | ||
margin: 1.5rem 0 1rem; | ||
|
||
@media (max-width: 575.98px) { | ||
margin: .5rem 0; | ||
} | ||
} | ||
|
||
&__info { | ||
border-radius: .25rem; | ||
padding: 1rem; | ||
background: var(--light); | ||
} | ||
|
||
&__summary-row { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
text-align: right; | ||
|
||
> span { | ||
color: var(--gray); | ||
} | ||
} | ||
|
||
&__shipping { | ||
margin: 1rem 0; | ||
} | ||
|
||
&__total { | ||
margin: 1rem 0; | ||
|
||
.prices { | ||
&__value { | ||
font-size: 1.5rem; | ||
} | ||
} | ||
} | ||
} | ||
|