generated from deco-sites/fashion
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67a403e
commit 85e4d38
Showing
14 changed files
with
285 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { itemToAnalyticsItem, useCart } from "apps/wap/hooks/useCart.ts"; | ||
import Button from "./common.tsx"; | ||
|
||
function CartButton() { | ||
const { loading, cart } = useCart(); | ||
const { subtotal, itens } = cart.value ?? {}; | ||
|
||
return ( | ||
<Button | ||
currency="BRL" | ||
loading={loading.value} | ||
total={subtotal?.valor ?? 0} | ||
items={(itens ?? []).map((item, index) => | ||
itemToAnalyticsItem({ ...item! }, index) | ||
)} | ||
/> | ||
); | ||
} | ||
|
||
export default CartButton; |
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,59 @@ | ||
import { itemToAnalyticsItem, useCart } from "apps/wap/hooks/useCart.ts"; | ||
import BaseCart from "../common/Cart.tsx"; | ||
|
||
function Cart() { | ||
const { cart, loading, updateItem, updateCoupon, removeItem } = useCart(); | ||
const items = cart.value?.itens ?? []; | ||
|
||
const total = cart.value?.subtotal?.valor ?? 0; | ||
const subtotal = cart.value?.subtotal?.valor ?? 0; | ||
const locale = "pt-BR"; | ||
const currency = "BRL"; | ||
const coupon = cart.value?.coupon ?? undefined; | ||
|
||
return ( | ||
<BaseCart | ||
items={items.map((item) => ({ | ||
image: { src: item!.imagem!, alt: "product image" }, | ||
quantity: item!.quantidade!, | ||
name: item!.nome!, | ||
price: { sale: item!.precos.precoPor!, list: item!.precos.precoDe! }, | ||
}))} | ||
total={total} | ||
subtotal={subtotal} | ||
discounts={0} | ||
locale={locale} | ||
currency={currency} | ||
loading={loading.value} | ||
freeShippingTarget={1000} | ||
coupon={coupon} | ||
checkoutHref={`/checkout/carrinho/`} | ||
onAddCoupon={(code) => updateCoupon({ hashCupom: code })} | ||
onUpdateQuantity={(quantidade: number, index: number) => | ||
quantidade === 0 | ||
? removeItem({ | ||
tipo: "produto", | ||
idProduto: items[index]?.hash.idProduto, | ||
idAtributoSimples: items[index]?.hash.idAtributoSimples, | ||
idUnidadeVenda: items[index]?.hash.idUnidadeVenda, | ||
idArmazem: items[index]?.hash.idArmazem, | ||
}) | ||
: updateItem({ | ||
tipo: "produto", | ||
quantidade, | ||
idProduto: items[index]?.hash.idProduto, | ||
idAtributoSimples: items[index]?.hash.idAtributoSimples, | ||
idUnidadeVenda: items[index]?.hash.idUnidadeVenda, | ||
idArmazem: items[index]?.hash.idArmazem, | ||
}) | ||
} | ||
itemToAnalyticsItem={(index) => { | ||
const item = items[index]; | ||
|
||
return item && itemToAnalyticsItem(item, index); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export default Cart; |
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,33 @@ | ||
import { useCart } from "apps/wap/hooks/useCart.ts"; | ||
import Button, { Props as BtnProps } from "./common.tsx"; | ||
|
||
export interface Props extends Omit<BtnProps, "onAddItem"> { | ||
productID: string; | ||
idAtributoSimples: number; | ||
} | ||
|
||
function AddToCartButton({ | ||
productID, | ||
eventParams, | ||
idAtributoSimples = 0, | ||
}: Props) { | ||
const { addItems } = useCart(); | ||
|
||
const onAddItem = () => | ||
addItems({ | ||
tipo: "produto", | ||
itens: [ | ||
{ | ||
idProduto: Number(productID), | ||
quantidade: 1, | ||
idAtributoSimples, | ||
idUnidadeVenda: 0, | ||
idArmazem: 0, | ||
}, | ||
], | ||
}); | ||
|
||
return <Button onAddItem={onAddItem} eventParams={eventParams} />; | ||
} | ||
|
||
export default AddToCartButton; |
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
Oops, something went wrong.