Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

add range weight condition to method defiction of a location zone of a delivery profile

Solved

add range weight condition to method defiction of a location zone of a delivery profile

Antonio84
Shopify Partner
53 1 3

Hello, I am trying to add a range weight conditions on a delivery profile, that's the code:

        query = """
            mutation deliveryProfileUpdate($id: ID!, $profile: DeliveryProfileInput!) 
                {  
                    deliveryProfileUpdate(id: $id, profile: $profile) 
                    {    
                        profile {      
                            id    
                        }    
                        userErrors {      
                            field      
                            message    
                        }
                    }
                }  
            """
        variables = {
            "id":"gid://shopify/DeliveryProfile/{}".format(did),
            "profile":{
                "locationGroupsToCreate": {
                        "locations": "gid://shopify/Location/{}".format(location_id),
                        "zonesToCreate":
                        {
                            "name": name,
                            "countries": countries,
                            "methodDefinitionsToCreate": [ { 
                                "name": "Spedizione standard",
                                "active": True,
                                # Set the rate definition for the delivery zone.
                                #"rateDefinition": { 
                                #    "price": { 
                                #        "amount": 0, "currencyCode": "EUR" 
                                #        },
                                #},
                                "rateDefinition": {
                                    "price": {
                                        "amount": 10.0,
                                        "currencyCode": "EUR"
                                    }
                                },
                                "weightConditionsToCreate": {
                                    "criteria": {
                                        "unit": "KILOGRAMS",
                                        "value": weight,
                                    },
                                    "operator": "GREATER_THAN_OR_EQUAL_TO"
                                }                          
                                } for weight in weights
                            ] + [
                            { 
                                "name": "Spedizione standard",
                                "active": True,
                                # Set the rate definition for the delivery zone.
                                #"rateDefinition": { 
                                #    "price": { 
                                #        "amount": 0, "currencyCode": "EUR" 
                                #        },
                                #},
                                "rateDefinition": {
                                    "price": {
                                        "amount": 10.0,
                                        "currencyCode": "EUR"
                                    }
                                },
                                "weightConditionsToCreate": {
                                    "criteria": {
                                        "unit": "KILOGRAMS",
                                        "value": weight,
                                    },
                                    "operator": "LESS_THAN_OR_EQUAL_TO"
                                }
                            } for weight in weights                                
                            ]
                        }
                    }
            }
        }
        result = shopify.GraphQL().execute(query, variables=variables)

How to properly set the range, like the code above it doesn't work I have to fille the minumum weight and maximum weight, how to achieve that?

 

Accepted Solution (1)

Antonio84
Shopify Partner
53 1 3

This is an accepted solution.

I have solved, for someone who is interested to create a range weight, you need to add a list of 

wieghtConditionsToCreate:

"weightConditionsToCreate": [ { 
                                    "criteria": {
                                        "unit": "KILOGRAMS",
                                        "value": weight_and_price["weights"]["min"],
                                    },
                                    "operator": "GREATER_THAN_OR_EQUAL_TO"
                                },
                                 {
                                    "criteria": {
                                        "unit": "KILOGRAMS",
                                        "value": weight_and_price["weights"]["max"],
                                    },
                                    "operator": "LESS_THAN_OR_EQUAL_TO"
                                }
                                ]

 

View solution in original post

Reply 1 (1)

Antonio84
Shopify Partner
53 1 3

This is an accepted solution.

I have solved, for someone who is interested to create a range weight, you need to add a list of 

wieghtConditionsToCreate:

"weightConditionsToCreate": [ { 
                                    "criteria": {
                                        "unit": "KILOGRAMS",
                                        "value": weight_and_price["weights"]["min"],
                                    },
                                    "operator": "GREATER_THAN_OR_EQUAL_TO"
                                },
                                 {
                                    "criteria": {
                                        "unit": "KILOGRAMS",
                                        "value": weight_and_price["weights"]["max"],
                                    },
                                    "operator": "LESS_THAN_OR_EQUAL_TO"
                                }
                                ]