mageworx / module-giftcards-graphql
MageWorx 礼品卡 GraphQL
Requires
- magento/framework: >=102.0.0 <104
- magento/module-catalog: >= 102.0.0 < 105
- magento/module-quote-graph-ql: >= 100.3.2 < 100.5
- magento/module-ui: >= 100.1.0
- magento/module-url-rewrite-graph-ql: >= 100.4.2 < 100.5
- mageworx/module-giftcardsbase: >= 2.8.2
README
为 MageWorx Magento 2 礼品卡 扩展提供的 GraphQL API 模块。
安装
1) 使用 composer (从 Packagist) 安装
- 执行以下命令:
composer require mageworx/module-giftcards-graphql
2) 复制粘贴方法
- 下载此模块并将其上传到
app/code/MageWorx/GiftCardsGraphQl
目录 (如果不存在,请先创建 "GiftCardsGraphQl")
使用方法
1. mwGiftCardInfo 查询返回关于礼品卡的信息。
查询属性定义如下
code: String! Gift Card code
默认情况下,可以使用以下属性
status: String @doc(description: "Status")
balance: MwGiftCardBalance @doc(description: "Current Balance")
valid_till: String @doc(description: "Valid till")
MwGiftCardBalance 对象
value: Float @doc(description: "Balance Value")
currency_code: String @doc(description: "A three-letter currency code, such as USD or EUR")
label: String @doc(description: "Balance Label")
请求
{
mwGiftCardInfo(code: "N8Q48-UWIII-8YGZ7") {
status
valid_till
balance {
value
currency_code
label
}
}
}
响应
{ "data": { "mwGiftCardInfo": { "status": "Active", "valid_till": "Unlimited", "balance": { "value": 13.4, "currency_code": "USD", "label": "$13.40" } } } }
2. applyMwGiftCardToCart 变更允许您将任何礼品卡添加到购物车。
语法
mutation: {applyMwGiftCardToCart(input: ApplyMwGiftCardToCartInput): ApplyMwGiftCardToCartOutput}
ApplyMwGiftCardToCartInput 对象必须包含以下属性
cart_id: String! @doc(description:"The unique ID that identifies the customer's cart")
gift_card_code: String! @doc(description: "Gift Card code")
ApplyMwGiftCardToCartOutput 对象包含购物车对象。
cart: Cart! @doc(description: "Describes the contents of the specified shopping cart")
购物车对象
applied_mw_gift_cards: [AppliedMwGiftCards] @doc(description:"An array of applied Gift Cards")
AppliedMwGiftCards 对象
code: String @doc(description: "Gift Card code")
remaining: MwGiftCardBalance @doc(description: "Remaining balance")
applied: MwGiftCardBalance @doc(description: "Applied balance to the current cart")
MwGiftCardBalance 对象
value: Float @doc(description: "Balance Value")
currency_code: String @doc(description: "A three-letter currency code, such as USD or EUR")
label: String @doc(description: "Balance Label")
请求
mutation {
applyMwGiftCardToCart(
input: {
cart_id: "W0UKfmRGFp62p3H47MFfVupsnq1GFUxv"
gift_card_code: "N8Q48-UWIII-8YGZ7"
}
) {
cart {
applied_mw_gift_cards {
code
remaining {
value
currency_code
label
}
applied {
value
currency_code
label
}
}
}
}
}
响应
{ "data": { "applyMwGiftCardToCart": { "cart": { "applied_mw_gift_cards": [ { "code": "N8Q48-UWIII-8YGZ7", "remaining": { "value": 0, "currency_code": "USD", "label": "$0.00" }, "applied": { "value": 13.4, "currency_code": "USD", "label": "$13.40" } } ] } } } }
3. removeMwGiftCardFromCart 变更允许您从购物车中删除礼品卡。
语法
mutation: {removeMwGiftCardFromCart(input: RemoveMwGiftCardToCartInput): RemoveMwGiftCardFromCartOutput}
RemoveMwGiftCardToCartInput 对象必须包含以下属性
cart_id: String! @doc(description:"The unique ID that identifies the customer's cart")
gift_card_code: String! @doc(description: "Gift Card code")
RemoveMwGiftCardFromCartOutput 对象包含购物车对象。
cart: Cart! @doc(description: "Describes the contents of the specified shopping cart")
购物车对象
applied_mw_gift_cards: [AppliedMwGiftCards] @doc(description:"An array of applied Gift Cards")
AppliedMwGiftCards 对象
code: String @doc(description: "Gift Card code")
remaining: MwGiftCardBalance @doc(description: "Remaining balance")
applied: MwGiftCardBalance @doc(description: "Applied balance to the current cart")
MwGiftCardBalance 对象
value: Float @doc(description: "Balance Value")
currency_code: String @doc(description: "A three-letter currency code, such as USD or EUR")
label: String @doc(description: "Balance Label")
请求
mutation {
removeMwGiftCardFromCart(
input: {
cart_id: "W0UKfmRGFp62p3H47MFfVupsnq1GFUxv"
gift_card_code: "N8Q48-UWIII-8YGZ7"
}
) {
cart {
applied_mw_gift_cards {
code
remaining {
value
currency_code
label
}
applied {
value
currency_code
label
}
}
}
}
}
响应
{ "data": { "removeMwGiftCardFromCart": { "cart": { "applied_mw_gift_cards": null } } } }
4. 礼品卡产品
此请求允许您检索关于 MageWorx 礼品卡产品的信息。
MageWorxGiftCards 实现 ProductInterface。MageWorxGiftCards 对象包含以下属性
mageworx_gc_type: MageWorxGiftCardTypeEnum @doc(description: "Either EMAIL, PRINT, or OFFLINE")
mageworx_gc_additional_price: [MageWorxGiftCardAdditionalPrice] @doc(description: "Additional Prices")
mageworx_gc_customer_groups: [MageWorxGiftCardCustomerGroup] @doc(description: "Available for Customer Groups")
mageworx_gc_allow_open_amount: Boolean @doc(description: "Allow Open Amount")
mageworx_gc_open_amount_min: Float @doc(description: "Open Amount Min Value")
mageworx_gc_open_amount_max: Float @doc(description: "Open Amount Max Value")
amount_display_mode: Int @doc(description: "Amount Display Mode") amount_placeholder: String @doc(description: "Custom Amount Placeholder") from_name_placeholder: String @doc(description: "From Name Placeholder") to_name_placeholder: String @doc(description: "To Name Placeholder") to_email_placeholder: String @doc(description: "To Email Placeholder") message_placeholder: String @doc(description: "Message Placeholder")
MageWorxGiftCardAdditionalPrice 属性
value: Float @doc(description: "Additional Price")
label: String @doc(description: "Additional Price Label")
MageWorxGiftCardCustomerGroup 属性
id: Int @doc(description: "Customer Group ID")
请求
{
products(filter: { sku: { eq: "MWgift" } }) {
items {
name
... on MageWorxGiftCards {
mageworx_gc_type
mageworx_gc_additional_price
{
value
label
}
mageworx_gc_customer_groups
{
id
}
mageworx_gc_allow_open_amount
mageworx_gc_open_amount_min
mageworx_gc_open_amount_max
amount_display_mode
amount_placeholder
from_name_placeholder
to_name_placeholder
to_email_placeholder
message_placeholder
}
}
}
}
响应
{ "data": { "products": { "items": [ { "name": "MWgift", "mageworx_gc_type": "EMAIL", "mageworx_gc_additional_price": [ { "value": 30, "label": "$30.00" } ], "mageworx_gc_customer_groups": [ { "id": 0 }, { "id": 1 } ], "mageworx_gc_allow_open_amount": false, "mageworx_gc_open_amount_min": 20, "mageworx_gc_open_amount_max": 30, "amount_display_mode": 0, "amount_placeholder": "Test amount", "from_name_placeholder": "Test \"From Name\" Placeholder", "to_name_placeholder": "Test \"To Name\" Placeholder", "to_email_placeholder": "Test \"To Email\" Placeholder", "message_placeholder": "Test message" } ] } } }
5. MageWorxGiftCardsCartItem 实现
The MageWorxGiftCardsCartItem 对象实现 CartItemInterface。MageWorxGiftCardsCartItem 对象包含以下属性
mail_from: String @doc(description: "From Name")
mail_to: String @doc(description: "To Name")
mail_to_email: String @doc(description: "To E-mail")
mail_message: String @doc(description: "Message")
mail_delivery_date: String @doc(description: "Delivery Date")
customizable_options: [SelectedCustomizableOption]
请求
{
cart(cart_id: "kPi7RAFpz6qNJMEYDmjwXenMWvj5NqSz") {
items {
id
product {
name
sku
}
quantity
prices {
price {
value
currency
}
}
... on MageWorxGiftCardsCartItem {
mail_from,
mail_to,
mail_to_email,
mail_message,
mail_delivery_date
}
}
}
}
响应
{ "data": { "cart": { "items": [ { "id": "122", "product": { "name": "Fusion Backpack", "sku": "24-MB02" }, "quantity": 4, "prices": { "price": { "value": 59, "currency": "USD" } } }, { "id": "123", "product": { "name": "Strive Shoulder Pack", "sku": "24-MB04" }, "quantity": 1, "prices": { "price": { "value": 32, "currency": "USD" } } }, { "id": "126", "product": { "name": "MW Gift mail", "sku": "MW-Gift-mail" }, "quantity": 4, "prices": { "price": { "value": 5, "currency": "USD" } }, "mail_from": "John", "mail_to": "Doe", "mail_to_email": "j.doe@mageworx.com", "mail_message": "Hello, John!!!", "mail_delivery_date": "Jul 8, 2020" } ] } } }
6. addGiftCardProductsToCart 变更允许您将任何礼品卡产品添加到购物车。
语法
mutation: {addGiftCardProductsToCart(input: AddGiftCardProductsToCartInput): AddGiftCardProductsToCartOutput}
The AddGiftCardProductsToCartInput 对象必须包含以下属性
cart_id: String!
cart_items: [GiftCardProductCartItemInput!]!
GiftCardProductCartItemInput 对象
data: CartItemInput!
gift_card_product_options: GiftCardProductOptionsInput
customizable_options:[CustomizableOptionInput!]
GiftCardProductOptionsInput 对象
card_amount: String! @doc(description: "Card Value")
card_amount_other: Float @doc(description: "Other Card Value")
mail_from: String @doc(description: "From Name")
mail_to: String @doc(description: "To Name")
mail_to_email: String @doc(description: "To E-mail")
mail_message: String @doc(description: "Message")
mail_delivery_date_user_value: String @doc(description: "Delivery Date")
The AddGiftCardProductsToCartOutput 对象包含购物车对象
cart: Cart!
请求
mutation {
addGiftCardProductsToCart(
input: {
cart_id: "kPi7RAFpz6qNJMEYDmjwXenMWvj5NqSz"
cart_items: [
{
data: {
quantity: 1
sku: "MW-Gift-mail"
},
gift_card_product_options:
{
card_amount: "other_amount"
card_amount_other: 5
mail_from: "John"
mail_to: "Doe"
mail_to_email: "j.doe@mageworx.com"
mail_message: "Hello, John!!!"
mail_delivery_date_user_value: "07/08/2020"
}
}
]
}
) {
cart {
items {
product {
name
sku
}
quantity
prices {
price {
value
currency
}
}
... on MageWorxGiftCardsCartItem {
mail_from,
mail_to,
mail_to_email,
mail_message,
mail_delivery_date
}
}
}
}
}
响应
{ "data": { "addGiftCardProductsToCart": { "cart": { "items": [ { "product": { "name": "Strive Shoulder Pack", "sku": "24-MB04" }, "quantity": 1, "prices": { "price": { "value": 32, "currency": "USD" } } }, { "product": { "name": "MW Gift mail", "sku": "MW-Gift-mail" }, "quantity": 4, "prices": { "price": { "value": 5, "currency": "USD" } }, "mail_from": "John", "mail_to": "Doe", "mail_to_email": "j.doe@mageworx.com", "mail_message": "Hello, John!!!", "mail_delivery_date": "Jul 8, 2020" } ] } } } }