imsujan276 / shopify_flutter

A flutter package that works as a bridge between your Shopify Store and Flutter Application
https://pub.dev/packages/shopify_flutter
MIT License
26 stars 27 forks source link

Add SellingPlanAllocation in Product #64

Open abubakarflutter opened 5 months ago

abubakarflutter commented 5 months ago

Hi, I want the Selling Plan Allocation in the Product example response is given below, you can view more details from the following link.

https://shopify.dev/docs/api/storefront/2024-01/objects/SellingPlanAllocation

  1. As far i know, Selling Plan Allocation is the subscriptions on a certain product.
  2. subscription will be set by enabling any subscription app from shopify store - here is the free Shopify Subscriptions
  3. After enabling you have to add the subscriiption options for by selecting products and then those details will be fetched by this sellingPlanAllocation

here is the GraphQL query i used


      product(id: "$productId") {
        id
        title
        variants(first: 10) {
          edges {
            node {
              id
              quantityAvailable
              requiresShipping
              sellingPlanAllocations(first: 10) {
                edges {
                  node {
                    sellingPlan {
                      id
                      name
                      description
                      options {
                        name
                        value
                      }
                      priceAdjustments {
                        orderCount
                        adjustmentValue {
                          ... on SellingPlanPercentagePriceAdjustment {
                            adjustmentPercentage
                          }
                          ... on SellingPlanFixedAmountPriceAdjustment {
                            adjustmentAmount {
                              amount
                              currencyCode
                            }
                          }
                        }
                      }
                    }
                    priceAdjustments {
                      compareAtPrice {
                        amount
                        currencyCode
                      }
                      price {
                        amount
                        currencyCode
                      }
                      perDeliveryPrice {
                        amount
                        currencyCode
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }  ```

And here is the response 
when no subscription for any product

``` {
  "data": {
    "product": {
      "id": "gid://shopify/Product/9030657081656",
      "title": "Autumn and Winter New Half Turtleneck Cashmere Sweater For Women",
      "variants": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/ProductVariant/47958725886264",
              "quantityAvailable": 211,
              "requiresShipping": true,
              "sellingPlanAllocations": {
                "edges": []
              }
            }
          },
          {
            "node": {
              "id": "gid://shopify/ProductVariant/47958726279480",
              "quantityAvailable": 211,
              "requiresShipping": true,
              "sellingPlanAllocations": {
                "edges": []
              }
            }
          }
        ]
      }
    }
  }
} ```

and here is the response when subscriptions are actually available for that product 

``` {
  "data": {
    "product": {
      "id": "gid://shopify/Product/9030561300792",
      "title": "2Pcs/Set Lapel Short Sleeve",
      "variants": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/ProductVariant/47958549758264",
              "quantityAvailable": -5,
              "requiresShipping": true,
              "sellingPlanAllocations": {
                "edges": [
                  {
                    "node": {
                      "sellingPlan": {
                        "id": "gid://shopify/SellingPlan/694523429176",
                        "name": "Weekly subscription",
                        "description": "",
                        "options": [
                          {
                            "name": "Deliver every",
                            "value": "week"
                          }
                        ],
                        "priceAdjustments": [
                          {
                            "orderCount": null,
                            "adjustmentValue": {
                              "adjustmentPercentage": 0
                            }
                          }
                        ]
                      },
                      "priceAdjustments": [
                        {
                          "compareAtPrice": {
                            "amount": 5.18,
                            "currencyCode": "USD"
                          },
                          "price": {
                            "amount": 5.18,
                            "currencyCode": "USD"
                          },
                          "perDeliveryPrice": {
                            "amount": 5.18,
                            "currencyCode": "USD"
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            }
          },
          {
            "node": {
              "id": "gid://shopify/ProductVariant/47958549791032",
              "quantityAvailable": 999,
              "requiresShipping": true,
              "sellingPlanAllocations": {
                "edges": [
                  {
                    "node": {
                      "sellingPlan": {
                        "id": "gid://shopify/SellingPlan/694523429176",
                        "name": "Weekly subscription",
                        "description": "",
                        "options": [
                          {
                            "name": "Deliver every",
                            "value": "week"
                          }
                        ],
                        "priceAdjustments": [
                          {
                            "orderCount": null,
                            "adjustmentValue": {
                              "adjustmentPercentage": 0
                            }
                          }
                        ]
                      },
                      "priceAdjustments": [
                        {
                          "compareAtPrice": {
                            "amount": 5.18,
                            "currencyCode": "USD"
                          },
                          "price": {
                            "amount": 5.18,
                            "currencyCode": "USD"
                          },
                          "perDeliveryPrice": {
                            "amount": 5.18,
                            "currencyCode": "USD"
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            }
          },

          {
            "node": {
              "id": "gid://shopify/ProductVariant/47958550053176",
              "quantityAvailable": 999,
              "requiresShipping": true,
              "sellingPlanAllocations": {
                "edges": [
                  {
                    "node": {
                      "sellingPlan": {
                        "id": "gid://shopify/SellingPlan/694523429176",
                        "name": "Weekly subscription",
                        "description": "",
                        "options": [
                          {
                            "name": "Deliver every",
                            "value": "week"
                          }
                        ],
                        "priceAdjustments": [
                          {
                            "orderCount": null,
                            "adjustmentValue": {
                              "adjustmentPercentage": 0
                            }
                          }
                        ]
                      },
                      "priceAdjustments": [
                        {
                          "compareAtPrice": {
                            "amount": 4.94,
                            "currencyCode": "USD"
                          },
                          "price": {
                            "amount": 4.94,
                            "currencyCode": "USD"
                          },
                          "perDeliveryPrice": {
                            "amount": 4.94,
                            "currencyCode": "USD"
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  }
} ```
imsujan276 commented 5 months ago

Hi @abubakarflutter

Thank you for opening the issue.

I have no plan to add the SellingPlanAllocation in the products yet. But I am always open for PR.