Skip to content

Beta

Các component App Bridge này còn mới, và API có thể thay đổi ở bản phát hành minor trong giai đoạn beta. Hành vi của chúng được kiểm tra trong Shopify admin thật bằng một bộ E2E chạy cục bộ. Nếu có gì không hoạt động, hãy mở issue.

Tích hợp thiết bị và nền tảng ​

Các API mà Shopify xếp vào nhóm tích hợp thiết bị và nền tảng, cùng các type chỉ chúng dùng. Trên trang này: PosApi, ScannerApi, WebVitalsApi.

PosApi ​

interface

cart: PosCart

Provides methods to read and modify the current POS cart, including line items, discounts, customers, and properties.

close: PosClose

Closes the app and returns to the POS screen.

device: PosDevice

Returns information about the POS device, including its name and serial number. Rejects when the host does not answer, or answers without a device.

location: PosLocation

Returns information about the current POS location, including its ID, name, address, and status. Rejects when the host does not answer, or answers without a location.

Được dùng trong: useAppBridge(), ShopifyGlobal

PosCart ​

type
ts
type PosCart = Required<_PosCart>;

Tham chiếu: _PosCartĐược dùng trong: PosApi

PosClose ​

function
ts
type PosClose = () => Promise<void>;

Được dùng trong: PosApi

PosDevice ​

function
ts
type PosDevice = () => Promise<Device>;

Tham chiếu: DeviceĐược dùng trong: PosApi

PosLocation ​

function
ts
type PosLocation = () => Promise<Location>;

Tham chiếu: LocationĐược dùng trong: PosApi

_PosCart ​

interface

fetch?(): Promise<Cart>

Fetch the current cart.

subscribe?(onSubscribe: CartSubscriber): Unsubscribe

Subscribe the cart changes.

setCustomer?(customer: Customer): Promise<void>

Add a new or existing customer to the cart.

removeCustomer?(): Promise<void>

Remove the current customer from the cart.

addAddress?(address: Address): Promise<void>

Add a new address to a customer.

updateAddress?(index: number, address: Address): Promise<void>

Update an address for a customer.

applyCartDiscount?(type: DiscountType, discountDescription: string, amount: string): Promise<void>

Apply a percentage or fixed amount discount to the whole cart.

applyCartCodeDiscount?(code: string): Promise<void>

Apply a code discount to the whole cart.

removeCartDiscount?(): Promise<void>

Remove the discount applied to the whole cart.

removeAllDiscounts?(disableAutomaticDiscounts: boolean): Promise<void>

Clears all applied discounts from the cart and optionally disables automatic discounts.

addCartProperties?(properties: Record<string, string>): Promise<void>

Add properties for the cart.

removeCartProperties?(keys: string[]): Promise<void>

Remove properties from the cart.

addCustomSale?(customSale: CustomSale): Promise<void>

Add custom sale for the cart.

clear?(): Promise<void>

Clear all contents from the cart.

addLineItem?(variantId: number, quantity: number): Promise<void>

Add a product to the cart.

updateLineItem?(uuid: string, quantity: number): Promise<void>

Make changes to a line item in the cart.

removeLineItem?(uuid: string): Promise<void>

Remove a line item in the cart.

setLineItemDiscount?(uuid: string, type: DiscountType, discountDescription: string, amount: string): Promise<void>

Apply a discount to a line item.

removeLineItemDiscount?(uuid: string): Promise<void>

Remove a discount from a line item.

addLineItemProperties?(uuid: string, properties: Record<string, string>): Promise<void>

Add properties to a line item.

removeLineItemProperties?(uuid: string, properties: string[]): Promise<void>

Remove properties from a line item.

Được dùng trong: PosCart

Device ​

interface

name: string

The name of the device.

serialNumber: string

The unique ID associated device ID and app ID..

Được dùng trong: PosDevice

Location ​

interface

id: number

The ID of current location.

active: boolean

The status of current location.

name: string

The name of current location.

locationType?: string

The type of current location.

address1?: string

The primary address of current location.

address2?: string

Any extra information associated with the address (Apartment #, Suite #, Unit #, etc.).

zip?: string

The ZIP or postal code of the address.

city?: string

The name of the city.

province?: string

TThe province or state of the address.

countryCode?: string

The Country Code in ISO 3166-1 (alpha-2) format.

countryName?: string

The country of the address.

phone?: string

The phone number of the location.

Được dùng trong: PosLocation

Address ​

interface

address1?: string

The customer's primary address.

address2?: string

Any extra information associated with the address (Apartment #, Suite #, Unit #, etc.).

city?: string

The name of the customer's city.

company?: string

The company name associated with address.

firstName?: string

The first name of the customer.

lastName?: string

The last name of the customer.

phone?: string

The phone number of the customer.

province?: string

The province or state of the address.

country?: string

The country of the address.

zip?: string

The ZIP or postal code of the address.

name?: string

The name of the address.

provinceCode?: string

The acronym of the province or state.

countryCode?: string

The Country Code in ISO 3166-1 (alpha-2) format.

Được dùng trong: _PosCart

Cart ​

interface

subTotal: string

The total cost of the current cart including discounts, but before taxes and shipping. Value is based on the shop's existing currency settings.

taxTotal: string

The sum of taxes for the current cart. Value is based on the shop's existing currency settings.

grandTotal: string

The total cost of the current cart, after taxes and discounts have been applied. Value is based on the shop's existing currency settings.

cartDiscount?: Discount

The current discount applied to the entire cart.

cartDiscounts?: Discount[]

All current discounts applied to the entire cart and line items.

customer?: Customer

The customer associated to the current cart.

lineItems: LineItem[]

A list of lineItem objects.

properties: Record<string, string>

A list of objects containing cart properties.

Được dùng trong: CartSubscriber, _PosCart

CartSubscriber ​

function
ts
type CartSubscriber = (cart: Cart) => void;

Tham chiếu: CartĐược dùng trong: _PosCart

Customer ​

interface

id: number

The ID of existing customer.

email?: string

The email for a new customer.

firstName?: string

The first name for new customer.

lastName?: string

The last name for new customer.

note?: string

The note for new customer.

Được dùng trong: Cart, _PosCart

CustomSale ​

interface

price: number

Price of line item

quantity: number

Quantity of line item.

title: string

Title of line item.

taxable: boolean

If line item charges tax.

Được dùng trong: _PosCart

DiscountType ​

type
ts
type DiscountType = "Percentage" | "FixedAmount";

Được dùng trong: Discount, _PosCart

Unsubscribe ​

function
ts
type Unsubscribe = () => void;

Được dùng trong: _PosCart

Discount ​

interface

amount: number

Amount of discount. Only for fixed or percentage discounts.

discountDescription?: string

Description of discount.

type: DiscountType

Type of discount.

Được dùng trong: Cart, LineItem

LineItem ​

interface

uuid: string

Unique id of line item

price?: number

Price of line item

quantity: number

Quantity of line item.

title?: string

Title of line item.

variantId?: number

Variant identifier for line item.

productId?: number

Product identifier for line item.

discounts: Discount[]

Discount applied to line item.

taxable: boolean

If line item charges tax.

sku?: string

Stock keeping unit of the line item.

vendor?: string

Vendor of line item.

properties: { [key: string]: string; }

Properties of the line item.

isGiftCard: boolean

If the line item is a gift card.

Được dùng trong: Cart

ScannerApi ​

interface

capture(): Promise<ScannerPayload>

Opens the device camera to scan a barcode. Returns a Promise that resolves to a ScannerPayload containing the scanned data. A new call to capture rejects a pending call with an AbortError.

Được dùng trong: useAppBridge(), ShopifyGlobal

ScannerPayload ​

interface

data: string

The scanned barcode data as a string.

Được dùng trong: useAppBridge(), ScannerApi

WebVitalsApi ​

interface

onReport?: (callback: WebVitalsCallback | null) => Promise<void>

Registers a callback to receive Web Vitals performance data. Pass null to unregister a previously registered callback.

Được dùng trong: useAppBridge(), ShopifyGlobal

WebVitalsCallback ​

function
ts
type WebVitalsCallback = (payload: WebVitalsReport) => void | Promise<void>;

Tham chiếu: WebVitalsReportĐược dùng trong: WebVitalsApi

WebVitalsReport ​

interface

metrics: WebVitalsMetric[]

The array of Web Vitals metric measurements included in this report.

Được dùng trong: WebVitalsCallback

WebVitalsMetric ​

interface

id: string

A unique identifier for this metric measurement instance.

name: string

The name of the metric, such as LCP, FCP, CLS, INP, or TTFB.

value: number

The measured value of the metric. Units depend on the metric name (milliseconds for timing metrics, unitless for CLS).

country?: string

The country code where the metric was collected, if available.

version?: string

The App Bridge build version that produced the metric, in the form <package-version> or <package-version>+<short-commit-sha>. Used to attribute reports to a specific deploy.

Được dùng trong: WebVitalsReport

Phát hành theo giấy phép MIT. Logo Vue của Evan You, CC BY-NC-SA 4.0.