Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create return #181

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions blocks/commerce-create-return/commerce-create-return.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* stylelint-disable no-empty-source */

body:not(.columns) main div.order-create-return {
margin-top: var(--spacing-large);
}
15 changes: 15 additions & 0 deletions blocks/commerce-create-return/commerce-create-return.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable import/no-unresolved */
/* eslint-disable import/no-extraneous-dependencies */
import { render as orderRenderer } from '@dropins/storefront-order/render.js';
import { CreateReturn } from '@dropins/storefront-order/containers/CreateReturn.js';
import { checkIsAuthenticated } from '../../scripts/configs.js';
import { ORDER_DETAILS_PATH, CUSTOMER_ORDER_DETAILS_PATH } from '../../scripts/constants.js';

// Initialize
import '../../scripts/initializers/order.js';

export default async function decorate(block) {
await orderRenderer.render(CreateReturn, {
routeReturnSuccess: (orderData) => (checkIsAuthenticated() ? `${CUSTOMER_ORDER_DETAILS_PATH}?orderRef=${orderData.number}` : `${ORDER_DETAILS_PATH}?orderRef=${orderData.token}`),
})(block);
}
13 changes: 12 additions & 1 deletion blocks/commerce-order-status/commerce-order-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
import { render as orderRenderer } from '@dropins/storefront-order/render.js';
import { OrderStatus } from '@dropins/storefront-order/containers/OrderStatus.js';
import { checkIsAuthenticated } from '../../scripts/configs.js';
import { CREATE_RETURN_PATH, CUSTOMER_CREATE_RETURN_PATH } from '../../scripts/constants.js';

// Initialize
import '../../scripts/initializers/order.js';

export default async function decorate(block) {
await orderRenderer.render(OrderStatus, {
routeCreateReturn: (orderData) => (checkIsAuthenticated() ? `/customer/create-return?orderId=${orderData.id}` : `/create-return?orderId=${orderData.id}`),
routeCreateReturn: ({ token, number: orderNumber }) => {
const isAuthenticated = checkIsAuthenticated();

const { searchParams } = new URL(window.location.href);
const orderRefFromUrl = searchParams.get('orderRef');
const newOrderRef = isAuthenticated ? orderNumber : token;

const encodedOrderRef = encodeURIComponent(orderRefFromUrl || newOrderRef);

return checkIsAuthenticated() ? `${CUSTOMER_CREATE_RETURN_PATH}?orderRef=${encodedOrderRef}` : `${CREATE_RETURN_PATH}?orderRef=${encodedOrderRef}`;
},
routeOnSuccess: () => '/cart',
})(block);
}
44 changes: 33 additions & 11 deletions scripts/__dropins__/storefront-order/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! Copyright 2024 Adobe
All Rights Reserved. */
import{Initializer as I}from"@dropins/tools/lib.js";import{events as d}from"@dropins/tools/event-bus.js";import{f as n,h as m}from"./chunks/fetch-graphql.js";import{g as P,r as U,s as Y,a as q,b as Q}from"./chunks/fetch-graphql.js";import{h as l}from"./chunks/network-error.js";import{P as u,a as _,G as c,O as p,B as O,R as h,c as T}from"./chunks/transform-order-details.js";import{O as D,A as R}from"./chunks/getGuestOrder.graphql.js";import{t as G}from"./chunks/getCustomer.js";import{a as H,g as K}from"./chunks/getCustomer.js";import{g as J}from"./chunks/getAttributesForm.js";import{g as W}from"./chunks/getStoreConfig.js";import{g as Z}from"./chunks/getCustomerOrdersReturn.js";import{c as re,r as te}from"./chunks/requestGuestOrderCancel.js";import{r as se}from"./chunks/reorderItems.js";import"@dropins/tools/fetch-graphql.js";import"./chunks/convertCase.js";const b=`
import{Initializer as I}from"@dropins/tools/lib.js";import{events as d}from"@dropins/tools/event-bus.js";import{f as n,h as m}from"./chunks/fetch-graphql.js";import{g as U,r as q,s as z,a as Y,b as Q}from"./chunks/fetch-graphql.js";import{h as l}from"./chunks/network-error.js";import{P as u,a as _,G as p,O as c,B as O,R as D,c as b}from"./chunks/transform-order-details.js";import{O as h,A as R}from"./chunks/getGuestOrder.graphql.js";import{t as f}from"./chunks/getCustomer.js";import{g as K,a as j}from"./chunks/getCustomer.js";import{g as V}from"./chunks/getAttributesForm.js";import{g as X}from"./chunks/getStoreConfig.js";import{g as ee}from"./chunks/getCustomerOrdersReturn.js";import{g as te,r as ae}from"./chunks/requestReturn.js";import{c as de,r as oe}from"./chunks/requestGuestOrderCancel.js";import{r as ne}from"./chunks/reorderItems.js";import"@dropins/tools/fetch-graphql.js";import"./chunks/convertCase.js";import"./chunks/transform-attributes-form.js";const G=`
query ORDER_BY_NUMBER($orderNumber: String!) {
customer {
orders(
Expand All @@ -17,9 +17,28 @@ query ORDER_BY_NUMBER($orderNumber: String!) {
carrier
shipping_method
is_virtual
returns {
returns(pageSize: 50) {
...OrderReturns
}
items_eligible_for_return {
...OrderItemDetails
... on BundleOrderItem {
...BundleOrderItemDetails
}
... on GiftCardOrderItem {
...GiftCardDetails
product {
...ProductDetails
}
}
... on DownloadableOrderItem {
product_name
downloadable_links {
sort_order
title
}
}
}
applied_coupons {
code
}
Expand Down Expand Up @@ -88,13 +107,13 @@ query ORDER_BY_NUMBER($orderNumber: String!) {
}
${u}
${_}
${c}
${p}
${c}
${O}
${D}
${R}
${h}
`,f=async(e,r,t)=>await n(b,{method:"GET",cache:"force-cache",variables:{orderNumber:e}}).then(a=>{var s;return(s=a.errors)!=null&&s.length?m(a.errors):T(t??"orderData",a,r)}).catch(l),y=`
${R}
${D}
`,T=async(e,r,t)=>await n(G,{method:"GET",cache:"force-cache",variables:{orderNumber:e}}).then(a=>{var s;return(s=a.errors)!=null&&s.length?m(a.errors):b(t??"orderData",a,r)}).catch(l),g=`
query ORDER_BY_TOKEN($token: String!) {
guestOrderByToken(input: { token: $token }) {
email
Expand All @@ -110,7 +129,10 @@ query ORDER_BY_TOKEN($token: String!) {
gift_receipt_included
available_actions
is_virtual
returns {
items_eligible_for_return {
...OrderItemDetails
}
returns(pageSize: 50) {
...OrderReturns
}
payment_methods {
Expand Down Expand Up @@ -182,10 +204,10 @@ query ORDER_BY_TOKEN($token: String!) {
}
${u}
${_}
${c}
${p}
${c}
${O}
${D}
${R}
${h}
`,A=async(e,r)=>await n(y,{method:"GET",cache:"no-cache",variables:{token:e}}).then(t=>{var a;return(a=t.errors)!=null&&a.length?m(t.errors):G(t,r)}).catch(l),$=async e=>{var i;const r=(e==null?void 0:e.orderRef)??"",t=(e==null?void 0:e.returnRef)??"",a=r&&typeof(e==null?void 0:e.orderRef)=="string"&&((i=e==null?void 0:e.orderRef)==null?void 0:i.length)>20,s=(e==null?void 0:e.orderData)??null;if(s){d.emit("order/data",{...s,returnNumber:t});return}if(!r){console.error("Order Token or number not received.");return}const o=a?await A(r,t):await f(r,t,"orderData");o?d.emit("order/data",{...o,returnNumber:t}):d.emit("order/error",{source:"order",type:"network",error:"The data was not received."})},E=new I({init:async e=>{const r={};E.config.setConfig({...r,...e}),$(e).catch(console.error)},listeners:()=>[]}),v=E.config;export{re as cancelOrder,v as config,n as fetchGraphQl,J as getAttributesForm,P as getConfig,H as getCustomer,Z as getCustomerOrdersReturn,K as getGuestOrder,f as getOrderDetailsById,W as getStoreConfig,A as guestOrderByToken,E as initialize,U as removeFetchGraphQlHeader,se as reorderItems,te as requestGuestOrderCancel,Y as setEndpoint,q as setFetchGraphQlHeader,Q as setFetchGraphQlHeaders};
${R}
${D}
`,A=async(e,r)=>await n(g,{method:"GET",cache:"no-cache",variables:{token:e}}).then(t=>{var a;return(a=t.errors)!=null&&a.length?m(t.errors):f(t,r)}).catch(l),y=async e=>{var i;const r=(e==null?void 0:e.orderRef)??"",t=(e==null?void 0:e.returnRef)??"",a=r&&typeof(e==null?void 0:e.orderRef)=="string"&&((i=e==null?void 0:e.orderRef)==null?void 0:i.length)>20,s=(e==null?void 0:e.orderData)??null;if(s){d.emit("order/data",{...s,returnNumber:t});return}if(!r){console.error("Order Token or number not received.");return}const o=a?await A(r,t):await T(r,t,"orderData");o?d.emit("order/data",{...o,returnNumber:t}):d.emit("order/error",{source:"order",type:"network",error:"The data was not received."})},E=new I({init:async e=>{const r={};E.config.setConfig({...r,...e}),y(e).catch(console.error)},listeners:()=>[]}),v=E.config;export{de as cancelOrder,v as config,n as fetchGraphQl,V as getAttributesForm,te as getAttributesList,U as getConfig,K as getCustomer,ee as getCustomerOrdersReturn,j as getGuestOrder,T as getOrderDetailsById,X as getStoreConfig,A as guestOrderByToken,E as initialize,q as removeFetchGraphQlHeader,ne as reorderItems,oe as requestGuestOrderCancel,ae as requestReturn,z as setEndpoint,Y as setFetchGraphQlHeader,Q as setFetchGraphQlHeaders};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AttributesFormModel } from '../../data/models';

export declare const getAttributesList: (entityType: string) => Promise<AttributesFormModel[] | [
]>;
//# sourceMappingURL=getAttributesList.d.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const GET_ATTRIBUTES_LIST = "\n query GET_ATTRIBUTES_LIST($entityType: AttributeEntityTypeEnum!) {\n attributesList(entityType: $entityType) {\n items {\n ... on CustomerAttributeMetadata {\n multiline_count\n sort_order\n validate_rules {\n name\n value\n }\n }\n ... on ReturnItemAttributeMetadata {\n sort_order\n }\n code\n label\n default_value\n frontend_input\n is_unique\n is_required\n options {\n is_default\n label\n value\n }\n }\n errors {\n type\n message\n }\n }\n }\n";
//# sourceMappingURL=getAttributesList.graphql.d.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './getAttributesList';
//# sourceMappingURL=index.d.ts.map
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export declare const PRODUCT_DETAILS_FRAGMENT = "\n fragment ProductDetails on ProductInterface {\n __typename\n canonical_url\n url_key\n uid\n name\n sku\n only_x_left_in_stock\n stock_status\n thumbnail {\n label\n url\n }\n price_range {\n maximum_price {\n regular_price {\n currency\n value\n }\n }\n }\n }\n";
export declare const PRICE_DETAILS_FRAGMENT = "\n fragment PriceDetails on OrderItemInterface {\n prices {\n price_including_tax {\n value\n currency\n }\n original_price {\n value\n currency\n }\n original_price_including_tax {\n value\n currency\n }\n price {\n value\n currency\n }\n }\n }\n";
export declare const GIFT_CARD_DETAILS_FRAGMENT = "\n fragment GiftCardDetails on GiftCardOrderItem {\n ...PriceDetails\n gift_message {\n message\n }\n gift_card {\n recipient_name\n recipient_email\n sender_name\n sender_email\n message\n }\n }\n";
export declare const ORDER_ITEM_DETAILS_FRAGMENT = "\n fragment OrderItemDetails on OrderItemInterface {\n __typename\n status\n product_name\n product_url_key\n id\n quantity_ordered\n quantity_shipped\n quantity_canceled\n quantity_invoiced\n quantity_refunded\n quantity_returned\n product_sale_price {\n value\n currency\n }\n selected_options {\n label\n value\n }\n product {\n ...ProductDetails\n }\n ...PriceDetails\n }\n";
export declare const ORDER_ITEM_DETAILS_FRAGMENT = "\n fragment OrderItemDetails on OrderItemInterface {\n __typename\n status\n product_sku\n eligible_for_return\n product_name\n product_url_key\n id\n quantity_ordered\n quantity_shipped\n quantity_canceled\n quantity_invoiced\n quantity_refunded\n product_sale_price {\n value\n currency\n }\n selected_options {\n label\n value\n }\n product {\n ...ProductDetails\n }\n ...PriceDetails\n }\n";
export declare const BUNDLE_ORDER_ITEM_DETAILS_FRAGMENT = "\n fragment BundleOrderItemDetails on BundleOrderItem {\n ...PriceDetails\n bundle_options {\n uid\n label\n values {\n uid\n product_name\n }\n }\n }\n";
//# sourceMappingURL=orderItemsFragment.graphql.d.ts.map
2 changes: 2 additions & 0 deletions scripts/__dropins__/storefront-order/api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export * from './getAttributesForm';
export * from './getCustomer';
export * from './getStoreConfig';
export * from './getCustomerOrdersReturn';
export * from './getAttributesList';
export * from './requestReturn';
export * from './cancelOrder';
export * from './requestGuestOrderCancel';
export * from './reorderItems';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const REQUEST_RETURN_ORDER = "\nmutation REQUEST_RETURN_ORDER($input: RequestReturnInput!) {\n requestReturn(input: $input) {\n return {\n uid\n status\n number\n created_at\n }\n }\n}\n";
//# sourceMappingURL=requestReturn.graphql.d.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './requestReturn';
//# sourceMappingURL=index.d.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RequestReturnProps } from '../../types';

export declare const requestReturn: (form: RequestReturnProps) => Promise<{
uid: string;
number: string;
status: string;
createdAt: string;
}>;
//# sourceMappingURL=requestReturn.d.ts.map
2 changes: 1 addition & 1 deletion scripts/__dropins__/storefront-order/chunks/OrderCancel.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading