This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 218
/
order-summary-item.js
122 lines (116 loc) · 3.6 KB
/
order-summary-item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import Label from '@woocommerce/base-components/label';
import ProductPrice from '@woocommerce/base-components/product-price';
import ProductName from '@woocommerce/base-components/product-name';
import { getCurrency } from '@woocommerce/blocks-checkout';
import PropTypes from 'prop-types';
import Dinero from 'dinero.js';
/**
* Internal dependencies
*/
import ProductBackorderBadge from '../product-backorder-badge';
import ProductImage from '../product-image';
import ProductLowStockBadge from '../product-low-stock-badge';
import ProductMetadata from '../product-metadata';
const OrderSummaryItem = ( { cartItem } ) => {
const {
images,
low_stock_remaining: lowStockRemaining = null,
show_backorder_badge: showBackorderBadge = false,
name,
permalink,
prices,
quantity,
short_description: shortDescription,
description: fullDescription,
item_data: itemData = [],
variation,
} = cartItem;
const currency = getCurrency( prices );
const regularPriceSingle = Dinero( {
amount: parseInt( prices.raw_prices.regular_price, 10 ),
precision: parseInt( prices.raw_prices.precision, 10 ),
} )
.convertPrecision( currency.minorUnit )
.getAmount();
const unconvertedLinePrice = Dinero( {
amount: parseInt( prices.raw_prices.price, 10 ),
precision: parseInt( prices.raw_prices.precision, 10 ),
} );
const linePriceSingle = unconvertedLinePrice
.convertPrecision( currency.minorUnit )
.getAmount();
const linePrice = unconvertedLinePrice
.multiply( quantity )
.convertPrecision( currency.minorUnit )
.getAmount();
return (
<div className="wc-block-components-order-summary-item">
<div className="wc-block-components-order-summary-item__image">
<div className="wc-block-components-order-summary-item__quantity">
<Label
label={ quantity }
screenReaderLabel={ sprintf(
/* translators: %d number of products of the same type in the cart */
__( '%d items', 'woo-gutenberg-products-block' ),
quantity
) }
/>
</div>
<ProductImage image={ images.length ? images[ 0 ] : {} } />
</div>
<div className="wc-block-components-order-summary-item__description">
<ProductName
disabled={ true }
name={ name }
permalink={ permalink }
/>
<ProductPrice
currency={ currency }
price={ linePriceSingle }
regularPrice={ regularPriceSingle }
className="wc-block-components-order-summary-item__individual-prices"
priceClassName="wc-block-components-order-summary-item__individual-price"
regularPriceClassName="wc-block-components-order-summary-item__regular-individual-price"
/>
{ showBackorderBadge ? (
<ProductBackorderBadge />
) : (
!! lowStockRemaining && (
<ProductLowStockBadge
lowStockRemaining={ lowStockRemaining }
/>
)
) }
<ProductMetadata
shortDescription={ shortDescription }
fullDescription={ fullDescription }
itemData={ itemData }
variation={ variation }
/>
</div>
<div className="wc-block-components-order-summary-item__total-price">
<ProductPrice currency={ currency } price={ linePrice } />
</div>
</div>
);
};
OrderSummaryItem.propTypes = {
cartItems: PropTypes.shape( {
images: PropTypes.array,
low_stock_remaining: PropTypes.number,
name: PropTypes.string.isRequired,
permalink: PropTypes.string,
prices: PropTypes.shape( {
price: PropTypes.string,
regular_price: PropTypes.string,
} ),
quantity: PropTypes.number,
summary: PropTypes.string,
variation: PropTypes.array,
} ),
};
export default OrderSummaryItem;