Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Shopify] Add Metafields to Products and Variants (#26185)
This is a PR without a dedicated issue as it's part of delivery for development agreed directly with @AndreiPanko Here's the overview of the changes: Obsolete fields: • Obsoleted Value Type as it‘s no longer used in Shopify API -> Replaced with Type field • Obsoleted Owner Resource field. I‘m not sure why this was a free text that was then always populated through a case statement. It‘s replaced with an Owner Type field that is an Enum. New enums and interfaces: • „Shpfy Metafield Type“ and „Shpfy IMetafield Type“ – Used for handling the metafield type. The interface defines if the type has a special AssistEdit, logic to execute the assist edit, and validations when free input is allowed for a value. I have a couple of questions here, see below. Rating, Rich Text, and List Types are not included, Rating and Rich Text options are added but commented out so it‘s clear that it was intentional. It also has String and Integer types which are there to support backward compatibility, if old values are still in Shopify. • „Shpfy Metafield Owner Type“ and „Shpfy IMetafield Owner Type“ – Used for building the full owner resource ID (gid://shopify/<ownerType>/<ownerId>) and for retrieving metafield IDs of a single resource (used during export, to identify which metafields should be sent for update based on UpdatedAt) • Metafield Dimenion/Volume/Weight Type – three enums to support a selection of Units when assist editing these metafield types Pages: • „Shpfy Metafields“ – used for viewing and editing metafields for a resource. It‘s only editable if Shop is syncing Products to Shopify and Can update Shopify products. On Insert of a new record, it‘s immediately sent to Shopify and is only inserted in the DB when we get back the Shopify ID for the metafield. Types that have AssistEdit functionality defined cannot be edited directly on the line. OnValidate of Value a check is executed to ensure value is correct for a type. • „Shpfy Metafield Assist Edit“ – used for assist edit of complex metafield types. It has several groups defined, and only the appropriate one is displayed to the user. • Action for display metafields for a resource has been added to the Products and Variants pages. GraphQL query changes: • ProductById and VariantById have been modified so that they retrieve the first 50 metafields (previously the first 10). Previously there was a filter to only retrieve Metafields with the „Microsoft.Dynamics365.BusinessCentral“ namespace. I‘ve removed that to get all the metafields of a resource. • ProductMetafieldIds and VariantMetafieldIds were added. These are used during the export of metafields to determine which BC metafields should be sent for an update • MetafieldsSet – This is used to create/update metafields for a resource Changes to API codeunits: • Product API – on UpdateShopifyProductFields a metafields part of JSON is now passed to Metafields API where it creates or updates Metafields in BC based on information retrieved from Shopify • Variant API – on UpdateShopifyVariantFields the metafields part of the JSON is passed to Metafields API, same as above. • „Shpfy Product Export“ – on UpdateProductData execute Metafields API to update/create metafields for the product and all variants that belong to the product • „Metafield API“ – Implements logic to parse the „metafields“JSON that is retrieved with products/variants during import and creates/updates metafield records in BC. Adds logic to export metafields for a specific resource. Only sends an update for metafields that have a lower UpdatedAt timestamp than BC record‘s last updated at timestamp. It batches the Metafields to 25 at a time, as that‘s the max MetafieldsSet mutation can handle as per the documentation. Added logic to delete metafields on delete of a product/variant A couple of questions or concerns: • New metafields that get created in Shopify do not have a Metafield Definition attached to them. Should we care about this right now? If yes, should we also store metafield definitions in BC, or just create new definitions if any are missing in Shopify? • I‘ve obsoleted the two fields and one enum, should I be wrapping the obsoletions in some preprocessing symbols? Which one? • I‘m doing some regex validations when checking if the value of metafield is correct. I‘m not sure if the one for mixed reference and file reference is correct. I‘d appreciate it if someone could take a look at that. • If value validation fails, it throws a pretty „simple“ error message right now, should I make this more expressive? • Currently, the „update metafields“ has no error handling in place if the update query fails. Technically I‘m trying to catch everything on data input, but there can always be unexpected situations. How should I handle this? • The code for sending the metafield to Shopify immediately after it‘s inserted through UI is currently on the Page‘s OnInsertRecord trigger. I‘m not sure about it, should I move it to the table trigger? The hesitation is because there already is some logic on the table from the partial implementation of metafields on Customers. • I‘ve placed interface implementations in a separate folder under Codeunits folder, that‘s not the usual practice on MS apps, so I wanted to double-check it. • Money metafield type needs to have the same currency as the shop, which leads to this completely separate code path after validating the Value. I‘m not sure if there‘s a better approach to handle this. • I saw that most procedures in the app have documentation triggers that are not really beneficial. I‘ve only added them to the public or internal procedures. I‘ve also skipped on most object documentation triggers. Fixes #26819 Fixes [AB#443908](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/443908) --------- Co-authored-by: Tine Staric <[email protected]> Co-authored-by: Jesper Schulz-Wedde <[email protected]> Co-authored-by: Onat Buyukakkus <[email protected]>
- Loading branch information