nozzlegear / ShopifySharp

ShopifySharp is a .NET library that helps developers easily authenticate with and manage Shopify stores.
https://nozzlegear.com/shopify-development-handbook
MIT License
742 stars 309 forks source link

Added SmartCollectionRules.ConditionObjectId #949

Closed alonghurst closed 10 months ago

alonghurst commented 10 months ago

https://github.com/nozzlegear/ShopifySharp/issues/933

This change allows reading/writing of SmartCollectionRules which use metafields in SmartCollections.

Shopify Docs: https://shopify.dev/docs/api/admin-rest/2023-07/resources/smartcollection

It can be used to create a metafield rule in a smart collection as follows (example shows for a product metafield):

var rule = new SmartCollectionRule
{
    Column = "product_metafield_definition",
    Relation = "equals",
    Condition = value
    ConditionObjectId = conditionObjectId
};

I found the most straightforward way to find the ConditionObjectId for a given product metafield was to inspect the HTML of the Settings / Custom Data page in my store and find the ids there:

<li id="gid://shopify/MetafieldDefinition/123456789" class="Polaris-IndexTable__TableRow_1a85o">

where 123456789 is to be used as conditionObjectId.

nozzlegear commented 10 months ago

Published in 6.6.1 on Nuget. Thanks for contributing!