jacobarriola / woographql-product-bundles
将 WooCommerce 产品捆绑支持添加到 WPGraphQL 架构。
0.0.4
2021-04-24 00:46 UTC
Requires
- php: >=7.1.0
This package is not auto-updated.
Last update: 2024-09-21 16:48:52 UTC
README
将 WooCommerce 产品捆绑支持添加到您的 WPGraphQL 架构。
要求
- PHP +7.1
- WordPress +5.0
- WPGraphQL +1
- WooGraphQL +0.8.0
- WooCommerce +4.7.0
- WooCommerce 产品捆绑 +0.5.0
文档
添加到购物车突变
目前,由于需要额外数据,添加到购物车是一个不同的突变。这个突变模仿现有的 WooGraphQL addToCart,但有几点不同。
本质上,它试图模仿底层产品捆绑的 API,该 API 可在 https://docs.woocommerce.com/document/bundles/bundles-functions-reference/#add_bundle_to_cart 找到
mutation addToCartBundle(input: { clientMutationId: "123" quantity: 1 productId: 456789 extraData : SEE_BELOW } ) { ... }
extraData 输入是一个 JSON 值。
参数
object index:捆绑项目 IDproduct_id:捆绑项目的产品 IDquantity:捆绑项目的数量variation_id:所选变体的变体 ID,如果适用attributes:一个对象,键为attribute_ATTRIBUTE_SLUG,值为属性值,如果适用
示例
{
"765": {
"product_id": "9876",
"quantity": "1",
"optional_selected": "yes",
"variation_id": "4321",
"attributes": {
"attribute_pa_color": "red",
"attribute_pa_size": "2xl"
}
},
"896": {
"product_id": "1234",
"quantity": "1"
}
}
在这个示例中,捆绑包含两个捆绑项目,765 和 896。 765 是一个可变产品(由 product_id: 9876 指定)。需要 variation_id 和属性。另一方面,896 是一个简单产品。它只传递 product_id。
待办事项
- 为
allowedVariations和defaultVariationAttributes返回适当的类型,而不是 JSON - 简化
addToCartBundle或将其与核心addToCart突变合并