baby_in_magento

frk

Apr 2nd, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.39 KB | None | 0 0
  1. import React, { useState, useEffect } from 'react';
  2. import { FormattedMessage, useIntl } from 'react-intl';
  3. import Price from '../../Price/price';
  4. import { usePriceSummary } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary';
  5. import Button from '@magento/venia-ui/lib/components/Button';
  6. import { useStyle } from '@magento/venia-ui/lib/classify';
  7. import defaultClasses from '@magento/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.module.css';
  8. import DiscountSummary from './discountSummary';
  9. import GiftCardSummary from './giftCardSummary';
  10. import GiftOptionsSummary from './giftOptionsSummary';
  11. import ShippingSummary from './shippingSummary';
  12. import TaxSummary from './taxSummary';
  13. import secured from './Images/secured.svg';
  14. import { useSelector, useDispatch } from 'react-redux';
  15. import { sendQuotation } from '../../../reducers/CustomReducer';
  16. import { GTMEventTrigger } from '../../../lib/util/GTMEventTrigger';
  17. import PointsRedeem from './PointsRedeem'
  18. import { useCartPage } from '../../../talons/CartPage/useCartPage';
  19. import { netcoreEvent } from '../../../initialize-netcore.js';
  20. import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
  21. import { gql, useQuery } from '@apollo/client';
  22.  
  23. const PriceSummary = props => {
  24. const { isUpdating, pointsDiscount, cartItems } = props;
  25. const classes = useStyle(defaultClasses, props.classes);
  26. const talonProps = usePriceSummary();
  27. const CartUpdateProps = useCartPage();
  28. const { getCartDetails } = CartUpdateProps;
  29.  
  30. const {
  31. handleProceedToCheckout,
  32. hasError,
  33. hasItems,
  34. isCheckout,
  35. isLoading,
  36. flatData
  37. } = talonProps;
  38. const { formatMessage } = useIntl();
  39.  
  40. const dispatch = useDispatch();
  41.  
  42. const customData = useSelector(state => state.custom);
  43. const { storeUserInfo, removePointsInfo, redeemPointsInfo } = customData;
  44.  
  45. const isStoreUser = storeUserInfo?.isStorefrontUser;
  46.  
  47. const handleSendQuotation = () => {
  48. dispatch(sendQuotation());
  49. };
  50.  
  51. const {
  52. subtotal,
  53. total,
  54. discounts,
  55. giftCards,
  56. giftOptions,
  57. taxes,
  58. shipping
  59. } = flatData;
  60.  
  61. useEffect(() => {
  62. getCartDetails()
  63. }, [pointsDiscount])
  64.  
  65. const GET_PRODUCT_DETAILS = gql`
  66. query getProducts($sku:[String]){
  67. products(filter: { sku:{in:$sku} }) {
  68. items{
  69. id
  70. sku
  71. uid
  72. name
  73. stock_status
  74. price_range {
  75. maximum_price {
  76. final_price {
  77. currency
  78. value
  79. }
  80. regular_price {
  81. currency
  82. value
  83. }
  84. discount {
  85. amount_off
  86. }
  87. }
  88. }
  89. categories {
  90. uid
  91. name
  92. is_anchor
  93. url_key
  94. url_path
  95. level
  96. display_mode
  97. default_sort_by
  98. description
  99. }
  100. small_image{
  101. url
  102. label
  103. }
  104. url_key
  105. }
  106. }
  107. }
  108.  
  109. `
  110. let cartInfo = cartItems && cartItems?.map((item) => {
  111. return item?.product?.sku;
  112.  
  113. });
  114. var {error,loading,data} = useQuery(GET_PRODUCT_DETAILS, {
  115. fetchPolicy: 'cache-and-network',
  116. nextFetchPolicy: 'cache-first',
  117. variables: {
  118. sku:cartInfo
  119.  
  120. }
  121. });
  122. let categories = data?.products?.items[0]?.categories?.map(({name}) => name);
  123. const allCartItems = cartItems && cartItems?.map((item) => {
  124. return {
  125. 'prid' : item?.product?.uid,
  126. 'name': item?.product?.name,
  127. 'brand' : 'glow',
  128. 'price': item?.prices?.row_total.value,
  129. 'sale_price': item?.prices?.row_total.value,
  130. 'prqt': item.quantity,
  131. 'product_image': item?.product?.thumbnail?.url,
  132. 'price': item?.prices?.row_total.value,
  133. 'currency': item?.prices?.price?.currency,
  134. 'produrl': resourceUrl(`${location.host}/${item?.product?.url_key}` || ''),
  135. }
  136. });
  137. const isPriceUpdating = isUpdating || isLoading;
  138. const priceClass = isPriceUpdating ? classes.priceUpdating : classes.price;
  139. const totalPriceClass = isPriceUpdating
  140. ? classes.priceUpdating
  141. : classes.totalPrice;
  142.  
  143. const totalPriceLabel = isCheckout
  144. ? formatMessage({
  145. id: 'priceSummary.total',
  146. defaultMessage: 'Total'
  147. })
  148. : formatMessage({
  149. id: 'priceSummary.estimatedTotal',
  150. defaultMessage: 'Estimated Total'
  151. });
  152.  
  153.  
  154. if (hasError) {
  155. return (
  156. <div className={classes.root}>
  157. <span className={classes.errorText}>
  158. <FormattedMessage
  159. id={'priceSummary.errorText'}
  160. defaultMessage={
  161. 'Something went wrong. Please refresh and try again.'
  162. }
  163. />
  164. </span>
  165. </div>
  166. );
  167. } else if (!hasItems) {
  168. return null;
  169. }
  170.  
  171. const proceedToCheckoutButton = !isCheckout ? (
  172. <div
  173. className={classes.checkoutButton_container + ' mt-[-0.5rem] pb-4'}
  174. >
  175. <Button
  176. disabled={isPriceUpdating}
  177. priority={'high'}
  178. onClick={() => {
  179. handleProceedToCheckout();
  180. GTMEventTrigger({ route: window.location.pathname, event: 'proceed_checkout', title: document.title })
  181. netcoreEvent('dispatch', 'Checkout', {
  182. "total_items" : cartItems?.length,
  183. "amount" : total?.value,
  184. "Currency" : total.currency,
  185. "items" : allCartItems
  186. });
  187. }}
  188. data-cy="PriceSummary-checkoutButton"
  189. className="font-lato text-[12px] w-full mt-4 text-[#fff] px-6 py-3 tracking-[2.4px] rounded-[10px] uppercase bg-[#181A1D] checkout-button-section"
  190. >
  191. <FormattedMessage
  192. id={'priceSummary.checkoutButton1'}
  193. defaultMessage={'PROCEED TO CHECKOUT'}
  194. />
  195. </Button>
  196. </div>
  197. ) : null;
  198.  
  199. const sendQuotationButton = !isCheckout ? (
  200. <div
  201. className={
  202. classes.checkoutButton_container +
  203. ' mt-[-0.5rem] pb-4 send-quotation-btn'
  204. }
  205. >
  206. <Button
  207. disabled={isPriceUpdating}
  208. priority={'high'}
  209. onClick={() => handleSendQuotation()}
  210. data-cy="PriceSummary-checkoutButton"
  211. className="font-lato text-[12px] w-full mt-4 text-[#fff] px-6 py-3 tracking-[2.4px] rounded-[10px] uppercase bg-[#181A1D]"
  212. >
  213. <FormattedMessage
  214. id={'priceSummary.checkoutButton1'}
  215. defaultMessage={'SEND PRICE LIST'}
  216. />
  217. </Button>
  218. </div>
  219. ) : null;
  220.  
  221. const printQuotationButton = !isCheckout ? (
  222. <div
  223. className={
  224. classes.checkoutButton_container +
  225. ' mt-[-0.5rem] pb-4 send-quotation-btn'
  226. }
  227. >
  228. <Button
  229. disabled={isPriceUpdating}
  230. priority={'high'}
  231. onClick={() => print()}
  232. data-cy="PriceSummary-printButton"
  233. className="font-lato text-[12px] w-full -mt-3 text-[#fff] px-6 py-3 tracking-[2.4px] rounded-[10px] uppercase bg-[#181A1D]"
  234. >
  235. <FormattedMessage
  236. id={'priceSummary.checkoutButton1'}
  237. defaultMessage={'PRINT'}
  238. />
  239. </Button>
  240. </div>
  241. ) : null;
  242.  
  243.  
  244. return (
  245. <div className={classes.root} data-cy="PriceSummary-root">
  246. <div className="px-[20px] py-[16px] bg-[#F1F5EB] rounded-[10px] main_order_summary_section">
  247. <h1 className="font-regular text-[20px] text-[#181A1D] order_summary_section border-b-[#CED8C3] border-b-[1px] mb-[20px] pb-[20px] border-b-solid">
  248. Cart Summary
  249. </h1>
  250. <ul>
  251. <li className={classes.lineItems + ' text-[14px]'}>
  252. <span
  253. data-cy="PriceSummary-lineItemLabel"
  254. className={
  255. classes.lineItemLabel +
  256. ' font-lato font-regular text-[#181A1D]'
  257. }
  258. >
  259. <FormattedMessage
  260. id={'priceSummary.lineItemLabel1'}
  261. defaultMessage={'Sub Total'}
  262. />
  263. </span>
  264. <span
  265. data-cy="PriceSummary-subtotalValue"
  266. className={
  267. priceClass +
  268. ' font-lato font-medium text-[14px] text-[#181A1D]'
  269. }
  270. >
  271. <Price
  272. value={subtotal.value}
  273. currencyCode={subtotal.currency}
  274. />
  275. </span>
  276. </li>
  277. <li className={classes.lineItems}>
  278. <GiftCardSummary
  279. classes={{
  280. lineItemLabel: classes.lineItemLabel,
  281. price: priceClass
  282. }}
  283. data={giftCards}
  284. />
  285. </li>
  286. <li className={classes.lineItems}>
  287. <GiftOptionsSummary
  288. classes={{
  289. lineItemLabel: classes.lineItemLabel,
  290. price: priceClass
  291. }}
  292. data={giftOptions}
  293. />
  294. </li>
  295. <li className={classes.lineItems + ' text-[14px]'}>
  296. <TaxSummary
  297. classes={{
  298. lineItemLabel: classes.lineItemLabel,
  299. price: priceClass
  300. }}
  301. data={taxes}
  302. isCheckout={isCheckout}
  303. />
  304. </li>
  305.  
  306. <DiscountSummary
  307. classes={{
  308. lineItems: classes.lineItems,
  309. lineItemLabel: classes.lineItemLabel,
  310. price: priceClass
  311. }}
  312. data={discounts}
  313. />
  314. <PointsRedeem
  315. classes={{
  316. lineItems: classes.lineItems,
  317. lineItemLabel: classes.lineItemLabel,
  318. price: priceClass
  319. }}
  320.  
  321. pointsDiscount={pointsDiscount}
  322. currency={"INR"}
  323. />
  324. <li className={classes.lineItems}>
  325. <ShippingSummary
  326. classes={{
  327. lineItemLabel:
  328. classes.lineItemLabel +
  329. ' font-lato font-regular text-[14px] text-[#181A1D]',
  330. price:
  331. priceClass +
  332. ' font-lato font-regular text-[14px] text-[#181A1D]'
  333. }}
  334. data={shipping}
  335. isCheckout={isCheckout}
  336. />
  337. </li>
  338.  
  339. <li className="flex items-center justify-between mt-4 pt-3 pb-4">
  340. <div>
  341. <span className="font-lato font-semibold text-[22px] text-[#181A1D]">
  342. Total
  343. </span>
  344. </div>
  345. <div>
  346.  
  347. <li className={classes.lineItems + ' gap-0'}>
  348. <span
  349. data-cy="PriceSummary-subtotalValue"
  350. className={
  351. priceClass +
  352. ' font-lato font-semibold text-[22px] text-[#181A1D]'
  353. }
  354. >
  355. <Price
  356. value={total.value}
  357. currencyCode={subtotal.currency}
  358. />
  359. </span>
  360. </li>
  361. </div>
  362. </li>
  363. {isStoreUser
  364. ? sendQuotationButton
  365. : proceedToCheckoutButton}
  366. {isStoreUser ? printQuotationButton : null}
  367. </ul>
  368. </div>
  369. <section className="flex bg-[#F8F5FA] rounded-[10px] p-4 mt-4 items-center justify-between secured_section">
  370. <div className="flex flex-col items-center">
  371. <img
  372. src={secured}
  373. alt="secured payment"
  374. className="w-[50px] h-[50px] mb-3"
  375. />
  376. <span className="font-lato text-[12px] text-[#181A1D] text-center">
  377. Secured Payments
  378. </span>
  379. </div>
  380. <div className="flex flex-col items-center">
  381. <img
  382. src={secured}
  383. alt="Genuine products"
  384. className="w-[50px] h-[50px] mb-3"
  385. />
  386. <span className="font-lato text-[12px] text-[#181A1D] text-center">
  387. Genuine Products
  388. </span>
  389. </div>
  390. <div className="flex flex-col items-center">
  391. <img
  392. src={secured}
  393. alt="Brand warranty"
  394. className="w-[50px] h-[50px] mb-3"
  395. />
  396. <span className="font-lato text-[12px] text-[#181A1D] text-center">
  397. Brand Warranty
  398. </span>
  399. </div>
  400. </section>
  401. </div>
  402. );
  403. };
  404.  
  405. export default PriceSummary;
  406.  
Add Comment
Please, Sign In to add comment