Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Edgar Rasquin 326 posts 925 karma points
    Mar 11, 2021 @ 16:11
    Edgar Rasquin
    0

    Custom field for import prices in Vendr

    Hi there,

    I am struggeling with importing products in Vendr shop. Problem is as described here that the price is not imported due to the underlying data structure in Vendr where a price value is bound to the currency (as Guid).

    So the data structure of a price field in Vendr is:

    {
       "40603204-1990-4b33-8402-fe289b917d38": 2.51,
       "665f821f-ecf4-4d51-8939-f2c359aecd35": 1.57
    }
    

    Chatting with Matt Brailsford he recommended to post the issue here. So here is the class that I have come up with so far:

    using CMSImport.Extensions.Providers.FieldProviders;
    using CMSImport.Extensions.Providers.ImportProviders;
    using Umbraco.Core.Services;
    
    namespace CampusShop.Core.Controllers
    {
        public class CurrencyFieldProvider :IFieldProvider
        {
            private readonly IContentService _contentService;
            public CurrencyFieldProvider(IContentService contentService)
            {
                _contentService = contentService;
            }
    
            public object Parse(object value, ImportPropertyInfo property, FieldProviderOptions fieldProviderOptions)
            { 
                //EXAMPLE CODE PLEASE ??? FOR EXAMPLE
                var price = Decimal.Parse(value.AsString());
                var data = new Dictionary<string, decimal> {
                     { "6FD40872-83A8-473E-9DE4-F1305049F8D9", price }
                };    
                return JsonConvert.SerializeObject(data);
            }
        }
    }
    

    The above code is just a rough guess of how it could work. Can anyone please help me out with some example code for this?

    Thank you so much.

  • Tom Madden 253 posts 455 karma points MVP 4x c-trib
    Mar 11, 2021 @ 17:12
    Tom Madden
    1

    This rang a bell with me so I went looking for the code. It turns out I cheated and did this in Excel, then imported using CMS Import. Sorry it doesn't answer your question, but after searching for this I couldn't just ignore it,

    regards

    t

    enter image description here

  • Edgar Rasquin 326 posts 925 karma points
    Mar 11, 2021 @ 17:54
    Edgar Rasquin
    0

    Hi Tom,

    thank you very much for this workround. This would save me for now.

    Unfortunately, it does not work for me.

    I double checked that I have used the syntax the same way as it was in your example:

    {"6FD40872-83A8-473E-9DE4-F1305049F8D9": 4.9}
    

    Do I have to take care of something special?

  • Tom Madden 253 posts 455 karma points MVP 4x c-trib
    Mar 11, 2021 @ 19:24
    Tom Madden
    0

    I don't recall anything special. I might have had the field as a text field when I did the import, then changed it to a price field once the data was in place. Worth a try if you have a minute,

    regards

    t

  • Edgar Rasquin 326 posts 925 karma points
    Mar 12, 2021 @ 06:31
    Edgar Rasquin
    0

    I tried changing Vendr.Price to Textstring before Import and changed it back afterwards without success.

    But I recognized that the imported value got changed from:

    {"6FD40872-83A8-473E-9DE4-F1305049F8D9":25.3}
    

    to

    "{""6FD40872-83A8-473E-9DE4-F1305049F8D9"":25.3}"
    

    I than removed the quotation marks but it did not work either.

    How can I prevent the extra quotation marks that get generated?

  • Edgar Rasquin 326 posts 925 karma points
    Mar 12, 2021 @ 08:22
    Edgar Rasquin
    0

    I now changed the Guid to lower case.

    That did the trick. It works now.

    Thanks to everyone and have a funky friday ;)

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Mar 12, 2021 @ 08:24
    Richard Soeteman
    0

    Even better :-) Have a good Friday

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Mar 12, 2021 @ 08:22
    Richard Soeteman
    0

    Thanks Tom an Hi Edgar,

    Not sure where the GUID comes from but the extra quites is propablyu because it's a string object.

    Can't you make a simple class that holds a GUID and Decimal value. Fill a list of these objects and serialize those to string in the end of the FieldProvider?

    Best,

    Richard

  • Tom Madden 253 posts 455 karma points MVP 4x c-trib
    Mar 12, 2021 @ 08:23
    Tom Madden
    0

    Hi Edgar,

    glad you got it working,

    t

  • Tommy Swift 4 posts 72 karma points
    Mar 12, 2021 @ 10:15
    Tommy Swift
    0

    helped, thanks everyone)

  • Kyle Eck 130 posts 280 karma points
    Dec 16, 2021 @ 18:52
    Kyle Eck
    1

    Edgar,

    I know you got this working, however, this is how I accomplished this without having too modify my csv file (my file holds just a price)

    See this Link

Please Sign in or register to post replies

Write your reply to:

Draft