I solved this and will be moving onto the Vendr Complex Variant import etc.
Here is my solution from a CSV file data source that originated from Wordpress/WooCommerce. This may be of use to you in the future, feel free to use as you see fit.
//need to have the editor alias from vendr to tell CMS import to only run this when we are importing into the Vendr Price field
[FieldProvider(PropertyEditorAlias = "Vendr.Price")]
public class VendrCurrencyFieldProvider : IFieldProvider
{
private readonly IContentService _contentService;
public VendrCurrencyFieldProvider(IContentService contentService)
{
_contentService = contentService;
}
public object Parse(object value, ImportPropertyInfo property, FieldProviderOptions fieldProviderOptions)
{
//create new decimal to hold value
var price = new Decimal();
//if value is blank in your source file (I used CSV) then compensate for that and place a value you
//would know into the price field so you can either manually change it or account for it in some way
if(value != null && value.AsString() != "")
{
price = Decimal.Parse(value.AsString());
}
else
{
price = Decimal.Parse("1234.56");
}
//create the data structure you need to send the data in
//in the case of Vendr.Price you need { currencyId guid (found in back office) , price value from source file }
var data = new Dictionary<string, decimal> {
{ "05c1c00a-fd2d-41f9-b5af-017d7c739f60", price }
};
//serialize the data and return the value - done
return JsonConvert.SerializeObject(data);
}
}
Great it's solved Kyle and thanks that we can use this... I was about to reply on your original question that you were missing the Fieldprovider attribute
CMS Import to convert a CSV value to Vendr Price
Richard,
I am tryign to use a custom IFieldProvider class to convert a csv value to a Vendr Price.
Speaking with Matt it looks like the object structure should be like this:
However, when I run my import it does not fire my custom controller Parse method at all, am i missing something here?
If I get this working, my plan is to take a stab at the complex variants for Vendr as well, but I need to take baby steps here.
Here is my current class I am working with:
It just takes in the current value and grabs the price and I create the data structure and serialize it before sending it back.
Thanks
Richard,
I solved this and will be moving onto the Vendr Complex Variant import etc.
Here is my solution from a CSV file data source that originated from Wordpress/WooCommerce. This may be of use to you in the future, feel free to use as you see fit.
Great it's solved Kyle and thanks that we can use this... I was about to reply on your original question that you were missing the Fieldprovider attribute
Best,
Richard
is working on a reply...