scandipwa/quote-graphql

N/A

安装次数: 192,407

依赖者: 3

建议者: 0

安全: 0

星标: 7

关注者: 5

分支: 31

类型:magento2-module

3.1.0 2024-07-14 20:32 UTC

README

QuoteGraphQl 提供了 Checkout 步骤的基本类型和解析器。

端点描述

此处所有端点应接受与 API 相同的数据。有关 API 参考,请参阅 此链接

重要提示:以下的所有突变和查询操作无需指定 quote_id 参数(或 quoteId)。如果没有指定任何报价 ID,解析器将尝试从 Auth 标头中加载报价 ID,其中应包含身份验证令牌。如果传递了 quoteId,它将视为客户请求,因此 quote_id 应该进行编码。

重要提示:此端点是 Magento 2 GraphQL Quote 端点 的替代方案,该端点在服务器上存储授权客户的 quote_id(使用 state-full 方法)。

getCartForCustomer

此端点允许获取完整的购物车数据(项目 + 总计)。

query GetCartForCustomer ($_guestCartId_0: String) {
    getCartForCustomer(guestCartId: $_guestCartId_0) {
        id
        tax_amount
        subtotal
        discount_amount
        subtotal_with_discount
        grand_total
        items {
            item_id
            qty
            product {
                price {
                    maximalPrice {
                        amount {
                            value
                            currency
                        }
                        adjustments {
                            code
                            amount {
                                value
                                currency
                            }
                        }
                    }
                }
            }
        }
    }
}
{
  "_guestCartId_0":"xIXmScRLWb5ntIEsYe2ymzrVXYraivGx"
}

saveCartItem

cartItem 类型现在实现了 CartItemId 的子类型,允许通过多个之一进行引用:item_id 或产品 SKU。在未来的版本中,当 "sku" 和 "item_id" 被删除时,这将变为非空。

此端点允许根据默认 API 负载数据结构提交项目到购物车。以下示例是将简单产品选项添加到购物车的简单示例。

mutation SaveCartItem ($_cartItem_0: CartItemInput!, $_guestCartId_0: String) {
    saveCartItem(cartItem: $_cartItem_0, guestCartId: $_guestCartId_0) {
        getCartForCustomer(guestCartId: $_guestCartId_0) {
            id
            tax_amount
            subtotal
            discount_amount
            subtotal_with_discount
            grand_total
            items {
                item_id
                qty
                product {
                    price {
                        maximalPrice {
                            amount {
                                value
                                currency
                            }
                            adjustments {
                                code
                                amount {
                                    value
                                    currency
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
{
  "_cartItem_0":{
    "sku":"Test simple product",
    "product_type":"simple",
    "qty":1,
    "product_option": {
        "extension_attributes":{}
    }
  },
  "_guestCartId_0":"xIXmScRLWb5ntIEsYe2ymzrVXYraivGx"
}

removeCartItem

mutation RemoveCartItem($item_id: Int!, $_guestCartId_0: String) {
    removeCartItem(item_id: $item_id, guestCartId: $_guestCartId_0) {
        getCartForCustomer(guestCartId: $_guestCartId_0) {
            id
            tax_amount
            subtotal
            discount_amount
            subtotal_with_discount
            grand_total
            items {
                item_id
                qty
                product {
                    price {
                        maximalPrice {
                            amount {
                                value
                                currency
                            }
                            adjustments {
                                code
                                amount {
                                    value
                                    currency
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
{
   "item_id": 1,
   "quoteId": "s44Xcnya8dmbysAeNTOozFsZCh8tyCH9"
}

estimateShippingCosts

mutation EstimateShippingCosts(
    $guestCartId: String!
    $address: EstimateShippingCostsAddress!
) {
    estimateShippingCosts(address: $address, guestCartId: $guestCartId) {
        carrier_code
        method_code
        carrier_title
        method_title
        error_message
        amount
        base_amount
        price_excl_tax
        price_incl_tax
        available
    }
}
{
  "guestCartId": "s44Xcnya8dmbysAeNTOozFsZCh8tyCH9",
  "address": {
      "region": "New York",
      "region_id": 43,
      "region_code": "NY",
      "country_id": "US",
      "street": [
      	"123 Oak Ave"
      ],
      "postcode": "10577",
      "city": "Purchase",
      "firstname": "Jane",
      "lastname": "Doe",
      "customer_id": 4,
      "email": "jdoe@example.com",
      "telephone": "(512) 555-1111",
      "same_as_billing": 1
  }
}

saveAddressInformation

mutation SaveAddressInformation(
  	$addressInformation: SaveAddressInformation!
  	$guestCartId: String
) {
	saveAddressInformation(
		addressInformation: $addressInformation,
    	guestCartId: $guestCartId
  	) {
  		payment_methods {
    		code
    		title
  		}
    	totals {
			grand_total
      		items {
        		name
        		qty
      		}
    	}
	}
}
{
   "guestCartId": "s44Xcnya8dmbysAeNTOozFsZCh8tyCH9",
   "addressInformation":{
      "shipping_address":{
         "region":"New York",
         "region_id":43,
         "region_code":"NY",
         "country_id":"US",
         "street":[
            "123 Oak Ave"
         ],
         "postcode":"10577",
         "city":"Purchase",
         "firstname":"Jane",
         "lastname":"Doe",
         "email":"jdoe@example.com",
         "telephone":"512-555-1111"
      },
      "billing_address":{
         "region":"New York",
         "region_id":43,
         "region_code":"NY",
         "country_id":"US",
         "street":[
            "123 Oak Ave"
         ],
         "postcode":"10577",
         "city":"Purchase",
         "firstname":"Jane",
         "lastname":"Doe",
         "email":"jdoe@example.com",
         "telephone":"512-555-1111"
      },
      "shipping_carrier_code":"flatrate",
      "shipping_method_code":"flatrate"
   }
}

savePaymentInformationAndPlaceOrder

mutation SavePaymentInformationAndPlaceOrder(
  $paymentInformation: PaymentInformation!,
  $guestCartId: String,
) {
  	savePaymentInformationAndPlaceOrder(
  		paymentInformation: $paymentInformation,
    	guestCartId: $guestCartId
  ) {
  	orderID
  }
}
{
  "guestCartId": "s44Xcnya8dmbysAeNTOozFsZCh8tyCH9",
  "paymentInformation": {
    "paymentMethod": {
        "method": "checkmo"
    },
    "billing_address":{
       "region":"New York",
       "region_id":43,
       "region_code":"NY",
       "country_id":"US",
       "street":[
          "123 Oak Ave"
       ],
       "postcode":"10577",
       "city":"Purchase",
       "firstname":"Jane",
       "lastname":"Doe",
       "email":"jdoe@example.com",
       "telephone":"512-555-1111"
    }
  }
}