mageworx/module-deliverydate-graph-ql

MageWorx送货日期扩展的Graph QL插件

安装: 144

依赖: 0

建议者: 0

安全: 0

星星: 0

关注者: 4

分支: 0

开放问题: 1

类型:magento2-module

1.2.0 2023-06-12 11:00 UTC

This package is auto-updated.

Last update: 2024-09-12 13:53:30 UTC


README

为MageWorx Magento 2送货日期扩展提供GraphQL API模块。

安装

1) 使用composer安装(从packagist)

  • 执行以下命令: composer require mageworx/module-deliverydate-graph-ql

2) 复制粘贴方法

  • 下载此模块并将其上传到app/code/MageWorx/DeliveryDateGraphQl目录 (如果不存在,请先创建“DeliveryDateGraphQl”)

如何使用

1. deliveryDate查询返回指定购物车所选送货日期的信息。

查询属性定义如下

cart_id: String! - The unique ID of the cart to query.

默认情况下,您可以使用以下属性

day: String     - Delivery day, like 2022-05-11
time: String    - Delivery time, like 00:00_23:59
comment: String - Delivery comment given by a customer

请求

query ($magentoCartId: String!) {
    deliveryDate(cart_id: $magentoCartId) {
        day
        time
        comment
    }
}

响应

{
    "data": {
        "deliveryDate": {
            "day": "2022-05-11",
            "time": "14:00_16:00",
            "comment": "Hello GraphQL"
        }
    }
}

注意

以下是我们示例中使用的变量

{
    "magentoCartId": "{{graphQLCartId}}"
}

其中 {{graphQLCartId}} 是如VVEmRZMaLRgH1NZ7kkZXWJKIfZiIhbvP这样的字符串(遮蔽报价ID)。

2. availableDeliveryDates查询返回购物车所有可用送货日期(含时间)的信息。

查询属性定义如下

cart_id: String!        - The unique ID of the cart to query.
method: String          - Shipping method code in carriercode_methodcode format. Returns the result for all methods if not specified.
start_day_index: Int    - Offset of days from which the calculation starts. Returns the result from tooday if not specified.
end_day_index: Int      - Number of days to calculate. Returns the result till "Max Delivery Period" if not specified (could be different per Delivery Option configuration).

默认情况下,您可以使用以下属性

method: String                  - Shipping method code in carriercode_methodcode format.
day_limits: [DeliveryDayLimit]  - List of available limits for that method and cart

DeliveryDayLimit对象

day_index: Int                      - Index of the day from today (from 0).
date_formatted: String              - Date formatted using format selected in store configuration.
date: String                        - Date in standard Y-m-d format.
extra_charge: ExtraCharge           - Extra charge for that day.
time_limits: [DeliveryTimeLimit]    - Limits by time when available.

DeliveryTimeLimit对象

from: String              - Time from in hh:mm format.
to: String                - Time to in hh:mm format.
extra_charge: ExtraCharge - Extra charge for that time slot. Summed up with a surcharge from the delivery day settings.

ExtraCharge对象

amount: Float           - Amount in selected currency (in cart currency).
formatted: String       - Formatted according selected locale (with currency symbol).
currency_symbol: String - Currency symbol.
currency_code: String   - Currency code.

请求

query ($magentoCartId: String!) {
    availableDeliveryDates(
        cart_id: $magentoCartId
        method: "flatrate_flatrate"
        start_day_index: 2
        end_day_index: 10
    ) {
        method,
        day_limits {
            day_index
            date_formatted
            date
            extra_charge {
                amount
                formatted
                currency_code
                currency_symbol
            }
            time_limits {
                from
                to
                extra_charge {
                    amount
                    formatted
                    currency_code
                    currency_symbol
                }
            }
        }
    }
}

响应

{
  "data": {
    "availableDeliveryDates": [
      {
        "method": "flatrate_flatrate",
        "day_limits": [
          {
            "day_index": 5,
            "date_formatted": "14-June-2023",
            "date": "2023-06-14",
            "extra_charge": null,
            "time_limits": [
              {
                "from": "09:00",
                "to": "12:00",
                "extra_charge": {
                  "amount": 0,
                  "formatted": "",
                  "currency_code": "EUR",
                  "currency_symbol": ""
                }
              },
              {
                "from": "11:00",
                "to": "16:00",
                "extra_charge": {
                  "amount": 0,
                  "formatted": "",
                  "currency_code": "EUR",
                  "currency_symbol": ""
                }
              },
              {
                "from": "15:00",
                "to": "20:00",
                "extra_charge": {
                  "amount": 4.5409,
                  "formatted": "€4.54",
                  "currency_code": "EUR",
                  "currency_symbol": ""
                }
              }
            ]
          },
          {
            "day_index": 6,
            "date_formatted": "15-June-2023",
            "date": "2023-06-15",
            "extra_charge": null,
            "time_limits": [
              {
                "from": "09:00",
                "to": "12:00",
                "extra_charge": {
                  "amount": 0,
                  "formatted": "",
                  "currency_code": "EUR",
                  "currency_symbol": ""
                }
              },
              {
                "from": "11:00",
                "to": "16:00",
                "extra_charge": {
                  "amount": 0,
                  "formatted": "",
                  "currency_code": "EUR",
                  "currency_symbol": ""
                }
              },
              {
                "from": "15:00",
                "to": "20:00",
                "extra_charge": {
                  "amount": 4.5409,
                  "formatted": "€4.54",
                  "currency_code": "EUR",
                  "currency_symbol": ""
                }
              }
            ]
          }
        ]
      }
    ]
  }
}

3. setDeliveryDateOnCart变异允许您将送货日期和时间设置到购物车中。

语法

mutation: {setDeliveryDateOnCart(input: SetDeliveryDateOnCartInput): Cart}

SetDeliveryDateOnCartInput对象必须包含以下属性

cart_id: String!                    - The unique ID of a `Cart` object.
delivery_date: DeliveryDateInput!   - Selected delivery date, time (optional) and comment (optional).

The DeliveryDateInput对象必须包含以下属性

day: String!    - A string that identifies a delivery day in standard format Y-m-d.
time: String    - A string that identifies a delivery time diapason in "12:00_23:59" fromat. Must be a valid time.
comment: String - Comment for delivery. Any additional information from customer. Visible to customer by default.

请求

mutation ($magentoCartId: String!) {
    setDeliveryDateOnCart(
        input: {
            cart_id: $magentoCartId,
            delivery_date: {
                day: "2022-05-11"
                time: "14:00_16:00"
                comment: "Hello GraphQL"
            }
        }
    ) {
        delivery_date {
            day
            time
            comment
        }
    }
}

响应

{
    "data": {
        "setDeliveryDateOnCart": {
            "delivery_date": {
                "day": "2022-05-11",
                "time": "14:00_16:00",
                "comment": "Hello GraphQL"
            }
        }
    }
}

4. removeDeliveryDateFromCart变异允许您从购物车中删除所选的送货日期和时间(如果存在)。

语法

mutation: {removeDeliveryDateFromCart(cart_id: String!): Cart}

请求

mutation ($magentoCartId: String!) {
    removeDeliveryDateFromCart (cart_id: $magentoCartId) {
        delivery_date {
            day
            time
            comment
        }
    }
}

响应

{
    "data": {
        "removeDeliveryDateFromCart": {
            "delivery_date": {
                "day": "",
                "time": "",
                "comment": ""
            }
        }
    }
}

5. delivery_date对象也存在于购物车类型中。

默认情况下,您可以使用以下属性

day: String     - Delivery day, like 2022-05-11
time: String    - Delivery time, like 00:00_23:59
comment: String - Delivery comment given by a customer

请求

{
  customerCart {
    id
    items {
      id
      product {
        name
        sku
      }
      quantity
    }
    delivery_date {
        day 
        time
        comment
    }
  }
}

响应

{
    "data": {
        "customerCart": {
            "id": "VVEmRZMaLRgH1NZ7kkZXWJKIfZiIhbvP",
            "items": [
                {
                    "id": "37",
                    "product": {
                        "name": "A",
                        "sku": "A"
                    },
                    "quantity": 1
                }
            ],
            "delivery_date": {
                "day": "2022-05-11",
                "time": "14:00_16:00",
                "comment": "Hello GraphQL"
            }
        }
    }
}