Copied to clipboard

Flag this post as spam?

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


  • progproger 52 posts 130 karma points
    Oct 02, 2015 @ 10:50
    progproger
    0

    How to programmatically add product with variants in one method

    Hi,

    I'd like to add product with variants. Is there any examples?

    Thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Oct 02, 2015 @ 11:19
  • progproger 52 posts 130 karma points
    Oct 06, 2015 @ 10:28
    progproger
    0

    Hi Rusty,

    Thanks for this.

    Could you please help me to update also ProductVariant attribute name programmatically? In insert mode it works fine

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Oct 06, 2015 @ 16:12
    Rusty Swayne
    0

    @progproger - At the moment, I think the easiest way would be to update the merchProductOption name field (for the option name) or merchProductAttribute name field (for an option choice name) directly in the database.

    You should then clear the runtime cache (space in the web.config or something) and rebuild the product index.

    I don't know why this has not come up before ... these should be editable ... I'll add it to issues.merchello.com as a feature request.

    http://issues.merchello.com/youtrack/issue/M-880

  • Tito 314 posts 623 karma points
    Oct 19, 2015 @ 08:53
    Tito
    0

    Hi @Rusty,

    Im trying to create products programatically but i cant find where the ProductVariantDetachedContent class is:

    genericSoap.DetachedContents.Add(
                   new ProductVariantDetachedContent(
                       genericSoap.ProductVariantKey,
                       detachedContentType,
                       "en-US",
                       new DetachedDataValuesCollection(
                           new[]
                                {
                                    new KeyValuePair<string, string>(
                                        "description",
                                        "\"<p>A substance used with water for washing and cleaning, made of a compound of natural oils or fats with sodium hydroxide or another strong alkali, and typically having perfume and coloring added.</p>\""),
                                    new KeyValuePair<string, string>(
                                        "brief",
                                        "\"Generic soap.\""),
                                    new KeyValuePair<string, string>(
                                        "image",
                                        "{ \"focalPoint\": { \"left\": 0.5, \"top\": 0.5 }, \"src\": \"/media/1038/bathbombs.jpg\" }"), 
                                }))
                       {
                           CanBeRendered = true
                       });
    

    In Baazar source it compiles but in my project it cant be found. In Bazaar i see this class is into the Merchello.Core dll but i have copied Bazaar's Merchello dlls into my bin folders but it cant find it anyway.. what am i doing wrong? my imports are:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    using Merchello;
    using Merchello.Core;
    using Merchello.Core.Models;
    using Merchello.Core.Models.Interfaces;
    using Merchello.Core.Models.DetachedContent;
    using Merchello.Core.Models.EntityBase;
    
    using Umbraco.Core;
    using Umbraco.Core.Services;
    
  • Tito 314 posts 623 karma points
    Oct 20, 2015 @ 12:37
    Tito
    0

    I have created a new project inside the Baazar solution and tried to use this clases:

    using Merchello.Core;
    using Merchello.Core.Gateways.Shipping.FixedRate;
    using Merchello.Core.Models;
    using Merchello.Core.Models.DetachedContent;
    
    using Umbraco.Core.Services;
    
    
    namespace ClassLibrary1
    {
        public class Class1
        {
            public void Test()
            {
                var merchelloServices = Merchello.Core.MerchelloContext.Current.Services;
                Merchello.Core.Services.IDetachedContentTypeService detachedContentTypeService =
                   ((Merchello.Core.Services.ServiceContext)merchelloServices).DetachedContentTypeService;
    
                Merchello.Core.Models.DetachedContent.ProductVariantDetachedContent variant = null;
    
    
            }
        }
    }
    

    It seems to be a problem with the class protection, as visual studio states:

    Error   2   'Merchello.Core.Services.IDetachedContentTypeService' no es accesible debido a su nivel de protección   D:\Webs\umbracos\Merchello-merchello-dev\src\ClassLibrary1\Class1.cs    22  37  ClassLibrary1
    
    Error   4   'Merchello.Core.Models.DetachedContent.ProductVariantDetachedContent' no es accesible debido a su nivel de protección   D:\Webs\umbracos\Merchello-merchello-dev\src\ClassLibrary1\Class1.cs    25  51  ClassLibrary1
    

    It says "It is not accesible due to the protection level", i dont know why it works on Baazaar project and not in mine, how can use this classes in my project? i see ProductVariantDetachedContent is internal but not IDetachedContentTypeService.

    please i need help, I am stuck with this...

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Oct 20, 2015 @ 16:26
    Rusty Swayne
    0

    Ok - the reason this works in the Bazaar is because internals are visible to that project (because of the installer) so I need to change IDetachedContentTypeService interface.

    http://issues.merchello.com/youtrack/issue/M-885

  • Owen Pattison 18 posts 39 karma points
    Nov 18, 2015 @ 15:04
    Owen Pattison
    0

    Hello Rusty,

    I'm having trouble adding detached content to a product, yesterday i had the same issue as Tito, where the DetachedContentTypeService was private, ive since updated to the changes you made and i get the following message when i try and call the service.

    Attempt by method 'Core.Controllers.ProductImportController.AddProduct(System.Object)' to access method 'Merchello.Core.Services.ServiceContext.get_DetachedContentTypeService()' failed.
    

    This is the action:

            public void AddProduct(object productOptions)
        {
            var merchelloServices = MerchelloContext.Current.Services;
    
            var product = merchelloServices.ProductService.CreateProductWithKey("Axe product 3", "AXE0003", (decimal)29.99);
    
            product.AddToCollection(Guid.Parse("62FE73DC-1CC4-484A-AED2-343D530A6960"));
    
            var contentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType("BazaarProductContent");
    
            var detachedContentTypeService = ((ServiceContext)merchelloServices).DetachedContentTypeService;
    
            var detachedContentType = detachedContentTypeService.CreateDetachedContentType(EntityType.Product, contentType.Key, "Bazaar Product");
    
            product.DetachedContents.Add(
                new ProductVariantDetachedContent(
                    product.ProductVariantKey,
                    detachedContentType,
                    "en-US",
                new DetachedDataValuesCollection(
                    new[]
                        {
                            new KeyValuePair<string, string>("description", "\"<p><span>Brand new description</span></p>\""),
                            new KeyValuePair<string, string>("brief", "\"test string for brief\"")
                        }
                    ))
                {
                    CanBeRendered = true
                }
            );
    
            merchelloServices.ProductService.Save(product);
        }
    

    Do you have any idea's why this might be happening?

    Thanks, Owen.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 18, 2015 @ 16:39
    Rusty Swayne
    0

    @Owen - I publicized the DetachedContentTypeService and a couple of classes. The update is in Merchello 1.13.1 which I released yesterday.

    What version of Merchello are you running?

  • Owen Pattison 18 posts 39 karma points
    Nov 18, 2015 @ 16:42
    Owen Pattison
    0

    I updated to 1.13.1 this morning and I've been trying to use the service as above but i get the error stated it seems to fallover when i make the call to

    var detachedContentTypeService = ((ServiceContext)merchelloServices).DetachedContentTypeService;
    

    and therefore does not add my additional product details

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 18, 2015 @ 19:02
    Rusty Swayne
    1

    @Owen

    I wrote an example class in a separate library that works to prove that I could programatically add a product with content without having access to internals:

      namespace Merch.Example.ImportProduct
      {
          using System;
          using System.Collections.Generic;
          using System.Linq;
    
          using Merchello.Core;
          using Merchello.Core.Models.DetachedContent;
    
          using Umbraco.Core;
    
    public class ImportProduct
    {
        public void DoImport()
        {
            var product = MerchelloContext.Current.Services.ProductService.CreateProductWithKey("Axe product 3", Guid.NewGuid().ToString(), (decimal)29.99);
    
            var contentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType("BazaarProductContent");
    
            var detachedContentTypeService = MerchelloContext.Current.Services.DetachedContentTypeService;
    
            var detachedContentType =
                detachedContentTypeService.GetDetachedContentTypesByContentTypeKey(contentType.Key).FirstOrDefault();
    
            product.DetachedContents.Add(
                new ProductVariantDetachedContent(
                    product.ProductVariantKey,
                    detachedContentType,
                    "en-US",
                    new DetachedDataValuesCollection(
                        new[]
                            {
                                new KeyValuePair<string, string>(
                                    "description",
                                    "\"<p><span>Made with real avocados, this Avocado Moisturizing Bar is great for dry skin. Layers of color are achieved by using oxide colorants. Scented with Wasabi Fragrance Oil, this soap smells slightly spicy, making it a great choice for both men and women. To ensure this soap does not overheat, place in the freezer to keep cool and prevent gel phase.</span></p>\""),
                                new KeyValuePair<string, string>(
                                    "brief",
                                    "\"Avocado Moisturizing Bar is great for dry skin.\""),
                                new KeyValuePair<string, string>(
                                    "image",
                                    "{ \"focalPoint\": { \"left\": 0.5, \"top\": 0.5 }, \"src\": \"/media/1035/avocadobars.jpg\" }"),
                            }))
                {
                    CanBeRendered = true
                });
    
    
            MerchelloContext.Current.Services.ProductService.Save(product);
    
        }
      }
    }
    

    Looking at your code, you should not need to create a DetachedContentType if you are using the one that gets installed with the Bazaar installer:

      // the following line will create a new DetachedContentType
      var detachedContentType = detachedContentTypeService.CreateDetachedContentType(EntityType.Product, contentType.Key, "Bazaar Product");
    

    Retrieving an existing content type

      var detachedContentType =
                detachedContentTypeService.GetDetachedContentTypesByContentTypeKey(contentType.Key).FirstOrDefault();
    

    I did have to rebuild the product Examine Index to see my product in the Back Office - I'll have to look into that, but after rebuilding everything works as intended and the data was saved to the database just fine.

  • Owen Pattison 18 posts 39 karma points
    Nov 19, 2015 @ 11:29
    Owen Pattison
    0

    @Rusty Thanks for thee quick response to this, I've established this morning there was a error with some of the dll's; in the upgrade process i would assume there has been conflict this solved the issue of the missing action.

    Also a valid point about calling a created type and I'm sure the next error would have been the fact i was trying to create an existing detached content type so thanks for that amendment.

    With regards to the indexing thing i can confirm i also have the same error.

    Thanks for the help though.

  • Tito 314 posts 623 karma points
    Oct 20, 2015 @ 17:52
    Tito
    0

    Buff i was getting crazy! :)

    I think it is the same for Merchello.Core.Models.DetachedContent.ProductVariantDetachedContent?

    Could i change it myself on the source and compile it?

    Thanks!

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Oct 20, 2015 @ 18:42
    Rusty Swayne
    0

    You can always do that. I need to review the ramifications of making those public before I put it into a release though =)

  • Tito 314 posts 623 karma points
    Oct 20, 2015 @ 18:52
    Tito
    0

    OK, but i prefer not touching the source, to avoid future problems in updates. Please let me know when you plan to release it because i need to import the products for my project using the detached content

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Oct 20, 2015 @ 18:55
    Rusty Swayne
    0

    Even if you did compile it to do your import and then updated to the next version and it was reset - it should not make a difference ...

  • Tito 314 posts 623 karma points
    Oct 21, 2015 @ 12:29
    Tito
    0

    OK Rusty, i have changed the source code making this methods/classes public and now it compiles.

    I have imported a product and when i only import a product it goes well. The problem is when i import the product with detached data. I get this error when i try to show the product:

    Can not convert Null to Int32.

    my code to show the products:

    @foreach (var item in products)
            {
                item.SpecifyCulture("es-ES");
                <tr>
                    <td>@item.Name</td>
                    <td>@item.GetPropertyValue("ano")</td>
                    <td>@item.GetPropertyValue("precioOriginal")€</td>
                    <td>@item.Price.ToString("N")€</td>
                </tr>
    
            }
    

    Its weird because if i show the products just after importing, it shows them ok, the error is the second time, as if it occurs when reading from the caché.

    And when i navigate to "Products" in Merchello's Backoffice i get this:

    Received an error from the server Failed to search products

    The 'ObjectContent' type failed to serialize the response body for content type 'application/json; charset=utf-8'.

    EXCEPTION DETAILS:

    System.InvalidOperationException: The 'ObjectContent' type failed to serialize the response body for content type 'application/json; charset=utf-8'.

    So i think the problem is the json stored in the "merchProductVariantDetachedContent" table, but i cant see any problem:

    7f82ebf6-6600-40f5-9253-c8c8ba8c32c1    0f096384-5a54-4836-aa9a-807120796faf    es-ES   f4e3d001-5798-4ed0-8efa-bd056d94181a    [{"Key":"ano","Value":"\"1900\""},{"Key":"precioOriginal","Value":"\"10\""}]    NULL    alfa-145146faro-izquierdo   True    2015-10-21 14:16:48.897 2015-10-21 14:16:48.897
    72f2a7ad-e71b-4ae7-9088-a9cdd5054c8f    87280fc7-87ee-45bc-a223-f2bb1193ca8c    es-ES   f4e3d001-5798-4ed0-8efa-bd056d94181a    [{"Key":"ano","Value":"\"1994\""},{"Key":"precioOriginal","Value":"\"34,50\""}] NULL    alfa-145146faro-derecho True    2015-10-21 14:06:57.353 2015-10-21 13:42:29.877
    

    The second line is a product inserted by hand in the backoffice. The first one corresponds with the imported product. I cant see the error, may be another database table?

    My code inserting the product:

    producto.DetachedContents.Add(
                        GetProductVariantDetachedContent(item, "es-ES", producto.ProductVariantKey, detachedContentType)
                    );
    
    private static ProductVariantDetachedContent GetProductVariantDetachedContent(Articulo item, string cultureName, Guid productVariantKey, IDetachedContentType detachedContentType)
            {
                return new ProductVariantDetachedContent(
                        productVariantKey,
                        detachedContentType,
                        cultureName,
                        new DetachedDataValuesCollection(
                            new[]
                                {
                                    new KeyValuePair<string,string>(
                                        "precioOriginal", "\"" + item.Precio.ToString("N") + "\""
                                        ),
                                    new KeyValuePair<string,string>(
                                        "ano", "\"" + item.Year.ToString() + "\""
                                        )
                                    //new KeyValuePair<string, string>(
                                    //    "description",
                                    //    "\"<p><span>Made with real avocados, this Avocado Moisturizing Bar is great for dry skin. Layers of color are achieved by using oxide colorants. Scented with Wasabi Fragrance Oil, this soap smells slightly spicy, making it a great choice for both men and women. To ensure this soap does not overheat, place in the freezer to keep cool and prevent gel phase.</span></p>\""),
                                    //new KeyValuePair<string, string>(
                                    //    "brief",
                                    //    "\"Avocado Moisturizing Bar is great for dry skin.\""),
                                    //new KeyValuePair<string, string>(
                                    //    "image",
                                    //    "{ \"focalPoint\": { \"left\": 0.5, \"top\": 0.5 }, \"src\": \"/media/1035/avocadobars.jpg\" }"), 
                                }))
                                {
                                    CanBeRendered = true
                                };
            }
        }
    
  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Oct 21, 2015 @ 15:51
    Rusty Swayne
    0

    @Tito,

    How many languages do you have setup in Umbraco? The back office is going to expect that there is an entry for each language, even if there are no values.

  • Tito 314 posts 623 karma points
    Oct 21, 2015 @ 16:24
    Tito
    0

    There is the default language (en-US) and i have added spanish language (es-ES). I think it is not the reason, i have tried importing both languages:

     producto.DetachedContents.Add(
                        GetProductVariantDetachedContent(item, "es-ES", producto.ProductVariantKey, detachedContentType)
                    );
                    producto.DetachedContents.Add(
                        GetProductVariantDetachedContent(item, "en-US", producto.ProductVariantKey, detachedContentType)
                    );
                    merchelloServices.ProductService.Save(producto);
    

    And i get the same errors. Database rows:

    927153be-d20a-4c37-83f1-cf4d328c888d    e4d4d56e-b6ba-4387-be48-5f66163c9d91    en-US   f4e3d001-5798-4ed0-8efa-bd056d94181a    [{"Key":"ano","Value":"\"1994\""},{"Key":"precioOriginal","Value":"\"34,50\""}] NULL    alfa-145146faro-izquierdo   True    2015-10-21 18:20:01.900 2015-10-21 18:20:01.900
    c87a3c10-49c5-41f0-b3f4-304c57576901    e4d4d56e-b6ba-4387-be48-5f66163c9d91    es-ES   f4e3d001-5798-4ed0-8efa-bd056d94181a    [{"Key":"ano","Value":"\"1994\""},{"Key":"precioOriginal","Value":"\"34,50\""}] NULL    alfa-145146faro-izquierdo   True    2015-10-21 18:20:01.837 2015-10-21 18:20:01.837
    72f2a7ad-e71b-4ae7-9088-a9cdd5054c8f    87280fc7-87ee-45bc-a223-f2bb1193ca8c    es-ES   f4e3d001-5798-4ed0-8efa-bd056d94181a    [{"Key":"ano","Value":"\"1994\""},{"Key":"precioOriginal","Value":"\"34,50\""}] NULL    alfa-145146faro-derecho True    2015-10-21 14:06:57.353 2015-10-21 13:42:29.877
    

    You can see the first two are the rows in both languages. The third line it is a product created from the backoffice, only storing the spanish language, so it works with only one language. By the way, if i delete the first two rows, i get the same errors, so i guess the problem is in another db table?

  • Simon 4 posts 76 karma points
    Oct 23, 2015 @ 03:17
    Simon
    0

    I'm trying to do the same thing (programatically create Products with detached content) and I've hit the same kinds of errors.

    This is the stacktrace for the error the UI gives when trying to load the product section in the BackOffice:

    {
      "Message":"An error has occurred.",
      "ExceptionMessage":"The 'ObjectContent' type failed to serialize the  response body for content type 'application/json; charset=utf-8'.",
      "ExceptionType":"System.InvalidOperationException",
      "StackTrace":null,
      "InnerException":
      {
      "Message":"An error has occurred.",
      "ExceptionMessage":"Can not convert Null to Int32.",
      "ExceptionType":"System.ArgumentException",
      "StackTrace":"   at Newtonsoft.Json.Linq.JToken.op_Explicit(JToken value)\r\n
        at Merchello.Web.Models.ContentEditing.ExamineDisplayExtensions.GetProductVariantDetachedContentDisplayCollection(SearchResult result, String alias)
          in c:\\Working Repositories\\GitHub\\Merchello\\src\\Merchello.Web\\Models\\ContentEditing\\ExamineDisplayExtensions.cs:line 252\r\n
       at Merchello.Web.Models.ContentEditing.ExamineDisplayExtensions.ToProductVariantDisplay(SearchResult result)
          in c:\\Working Repositories\\GitHub\\Merchello\\src\\Merchello.Web\\Models\\ContentEditing\\ExamineDisplayExtensions.cs:line 57\r\n
       at Merchello.Web.Models.ContentEditing.ExamineDisplayExtensions.ToProductDisplay(SearchResult result, Func`2 getProductVariants)
          in c:\\Working Repositories\\GitHub\\Merchello\\src\\Merchello.Web\\Models\\ContentEditing\\ExamineDisplayExtensions.cs:line 39\r\n
       at Merchello.Web.Search.CachedProductQuery.PerformMapSearchResultToDisplayObject(SearchResult result)
         in c:\\Working Repositories\\GitHub\\Merchello\\src\\Merchello.Web\\Search\\CachedProductQuery.cs:line 803\r\n
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n
       ... remainder removed ...
    

    If I look at ExamineDisplayExtensions line 252 I see this:

    var pvdc = new ProductVariantDetachedContent(jtoken.GetValue("ProductVariantKey").ToObject<Guid>(), contentType, j.Value<string>("CultureName"), new DetachedDataValuesCollection(dataValues))
    {
        Key = jtoken.GetValue("Key").ToObject<Guid>(),
        Slug = jtoken.SelectToken("Slug").ToString(),
        TemplateId = (int)j.SelectToken("TemplateId"),
        CanBeRendered = bool.Parse(jtoken.SelectToken("CanBeRendered").ToString()),
        CreateDate = contentType.CreateDate,
        UpdateDate = contentType.UpdateDate
    };
    

    Prime suspect is the TemplateId, I guess. In my case this field is Null in the database - but for all products, even ones created via the UI that work just fine.

    This method is parsing the results of an Examine search which seems to be storing things as JSON. So it would appear that the problem is that the detached content we are creating programatically is not being added to the Examine index properly.

    I don't have a solution yet, but I thought I'd share what I've found. The investigation continues...

    Simon

  • Simon 4 posts 76 karma points
    Oct 23, 2015 @ 03:28
    Simon
    0

    Further to that, after checking the Examine indexes - the existing (working) content has TemplateId = 0, even though the database has a value of null. My new product (broken) has TemplateId = null.

    In my case, the Umbraco content type I am using for this detached data does not have a template associated with it - I'm using the detached content for data values, not for presentation content.

  • Tito 314 posts 623 karma points
    Oct 26, 2015 @ 16:05
    Tito
    0

    Thanks @Simon!

    @Rusty any update on this?

  • Simon 4 posts 76 karma points
    Oct 27, 2015 @ 21:21
    Simon
    2

    I've found that if I specify a Template for my detached content (even though I don't need one), then the Examine Index seems to behave itself. I created a new template and attached it to my 'extended product data' document type, and then I could write code like this:

    var umbracoContentType = umbracoContext.Application.Services.ContentTypeService.GetContentType("ExtendedProductData");
    
    ....
    
    if (umbracoContentType.DefaultTemplate != null)
    {
        detachedContent.TemplateId = umbracoContentType.DefaultTemplate.Id;
    }
    
  • Harvey 28 posts 122 karma points
    Aug 05, 2017 @ 20:01
    Harvey
    0

    Thanks for this comment, this solved my issue!

  • Tito 314 posts 623 karma points
    Oct 28, 2015 @ 09:42
    Tito
    0

    Thanks @Simon, now it works!!

    One thing, if i navigate to the product url it gaves me an error. This is the code i use to query the products:

      var products = merchelloHelper.Query.Product.Search(1, 10).Items
            .Select(x => ((ProductDisplay)x).AsProductContent())
                     .Where(x => x != null && x.Available);
    
    @foreach (var item in products)
            {
                item.SpecifyCulture("es-ES");
                <a href="@item.Url">@item.Name</a>
    
            }
    

    The url is something like this:

    http://localhost:63398/alfa-145146faro-antiniebla-dch/

    And this is the error when i navigate to that url (template for product is empty):

    [ArgumentException: Can not convert Null to Int32.]
       Newtonsoft.Json.Linq.JToken.op_Explicit(JToken value) +181
       Merchello.Web.Models.ContentEditing.ExamineDisplayExtensions.GetProductVariantDetachedContentDisplayCollection(SearchResult result, String alias) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\Models\ContentEditing\ExamineDisplayExtensions.cs:252
       Merchello.Web.Models.ContentEditing.ExamineDisplayExtensions.ToProductVariantDisplay(SearchResult result) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\Models\ContentEditing\ExamineDisplayExtensions.cs:57
       Merchello.Web.Models.ContentEditing.ExamineDisplayExtensions.ToProductDisplay(SearchResult result, Func`2 getProductVariants) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\Models\ContentEditing\ExamineDisplayExtensions.cs:39
       Merchello.Web.Search.CachedProductQuery.PerformMapSearchResultToDisplayObject(SearchResult result) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\Search\CachedProductQuery.cs:803
       System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +164
       System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +121
       Merchello.Web.Search.CachedProductQuery.GetBySlug(String slug) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\Search\CachedProductQuery.cs:150
       Merchello.Web.MerchelloHelper.TypedProductContentBySlug(String slug) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\MerchelloHelper.cs:155
       Merchello.Web.Routing.ContentFinderProductBySlug.TryFindContent(PublishedContentRequest contentRequest) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\Routing\ContentFinderProductBySlug.cs:48
       Umbraco.Web.Routing.PublishedContentRequestEngine.<FindPublishedContent>b__28(IContentFinder finder) +40
       System.Linq.Enumerable.Any(IEnumerable`1 source, Func`2 predicate) +146
       Umbraco.Web.Routing.PublishedContentRequestEngine.FindPublishedContent() +435
       Umbraco.Web.Routing.PublishedContentRequestEngine.FindPublishedContentAndTemplate() +297
       Umbraco.Web.Routing.PublishedContentRequestEngine.PrepareRequest() +192
       Umbraco.Web.Routing.PublishedContentRequest.Prepare() +36
       Umbraco.Web.UmbracoModule.ProcessRequest(HttpContextBase httpContext) +761
       Umbraco.Web.UmbracoModule.<Init>b__8(Object sender, EventArgs e) +132
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
    
  • Eric Mailloux 10 posts 30 karma points
    Mar 03, 2016 @ 05:39
    Eric Mailloux
    0

    Hi,

    Same problem here ! Merchello 1.14.1, Umbraco 7.3.8 I create product and DetachedContents for a import script. After creation, product list stop working till i flush indexes. Try the TemplateID trics, wont work. Error complain about JSON, serialisation and template. Could someone help me ?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Mar 09, 2016 @ 17:26
    Rusty Swayne
    0

    Sorry Eric,

    Trying to get caught up after uWestFest. Is your import script using Merchello services or are you going database direct?

  • Eric Mailloux 10 posts 30 karma points
    Mar 09, 2016 @ 18:10
    Eric Mailloux
    0

    Merchello Service...

    My code look like this:

    [WebMethod]

    public int insertOeuvre(string artisteId, string oeuvreId, DateTime creationDate, DateTime ModificationDate, string titre, string format, string description_fr, string description_en, double prix, bool vendu)
    {
        var productService = MerchelloContext.Current.Services.ProductService;
        var product = productService.CreateProductWithKey(titre, oeuvreId, Convert.ToDecimal(prix), true);
        var mediaFileName = oeuvreId.ToString() + ".jpg";
        var artistes = Services.ContentService.GetById(baseContent).Children().Where(x => x.GetValue<string>("inventoryId") == artisteId);
    
    
        if (artistes != null && artistes.Count() > 0 && product != null)
        {
            Guid artisteGuid = new Guid(artistes.First().GetValue("collectionKey").ToString());
            product.CreateDate = creationDate;
            product.UpdateDate = ModificationDate;
            product.Manufacturer = artistes.First().Name;
            product.ManufacturerModelNumber = artisteId;
            product.Available = true;
    
            var colectionService = MerchelloContext.Current.Services.EntityCollectionService;
            Merchello.Core.Models.Interfaces.IEntityCollection artisteCollection = colectionService.GetByKey(artisteGuid);
            Merchello.Core.Models.Interfaces.IEntityCollection lesArtistesCollection = colectionService.GetByKey(lesArtistesEntityKey);
            product.AddToCollection(artisteCollection.Key);
            product.AddToCollection(lesArtistesCollection.Key);
    
            var contentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType("OeuvreProductContent");
    
            var detachedContentTypeService = MerchelloContext.Current.Services.DetachedContentTypeService;
            var detachedContentType = detachedContentTypeService.GetDetachedContentTypesByContentTypeKey(contentType.Key).FirstOrDefault();
    
    
            product.DetachedContents.Add(
            new Merchello.Core.Models.DetachedContent.ProductVariantDetachedContent(
                product.ProductVariantKey,
                detachedContentType,
                "en-US",
                new Merchello.Core.Models.DetachedContent.DetachedDataValuesCollection(
                    new[]
                        {
                            new KeyValuePair<string, string>(
                                "description",
                                "\"" + description_en + "\""),
                            new KeyValuePair<string, string>(
                                "format",
                               "\"" + format + "\""),
                            new KeyValuePair<string, string>(
                                "image",
                                "{ \"src\": \"/media/" + mediaFileName + "\" }"),
                        }))
            {
                CanBeRendered = true
            });
    
            product.DetachedContents.Add(
            new Merchello.Core.Models.DetachedContent.ProductVariantDetachedContent(
                product.ProductVariantKey,
                detachedContentType,
                "fr-CA",
                new Merchello.Core.Models.DetachedContent.DetachedDataValuesCollection(
                    new[]
                        {
                            new KeyValuePair<string, string>(
                                "description",
                                "\"" + description_fr + "\""),
                            new KeyValuePair<string, string>(
                                "format",
                                "\"" + format + "\""),
                            new KeyValuePair<string, string>(
                                "image",
                                "{ \"src\": \"/media/" + mediaFileName + "\" }"),
                        }))
            {
                CanBeRendered = true
            });
            if (contentType.DefaultTemplate != null) { 
                product.DetachedContents[0].TemplateId = contentType.DefaultTemplate.Id;
                product.DetachedContents[1].TemplateId = contentType.DefaultTemplate.Id;
            }
            productService.Save(product);
    
            return 1;
        }
        else {
            return -1;
        }
    

    I did try with detached content with template, whitout, assigned or not, seems, that patch does not work for me.

  • Eric Mailloux 10 posts 30 karma points
    Mar 16, 2016 @ 15:09
    Eric Mailloux
    0

    Merchello services. Please, look a my post bellow. This is the error in the frontend:

    [ArgumentNullException: Cnnot be null. Parameter name : detachedContentType]
    

    Umbraco.Core.Mandate.That(Boolean condition, Func1 defer) +31 Merchello.Core.Models.DetachedContent.ProductVariantDetachedContent..ctor(Guid productVariantKey, IDetachedContentType detachedContentType, String cultureName, DetachedDataValuesCollection detachedDataValuesCollection) +189 Merchello.Web.Models.ContentEditing.ExamineDisplayExtensions.GetProductVariantDetachedContentDisplayCollection(SearchResult result, String alias) +682 Merchello.Web.Models.ContentEditing.ExamineDisplayExtensions.ToProductVariantDisplay(SearchResult result) +1803 Merchello.Web.Models.ContentEditing.ExamineDisplayExtensions.ToProductDisplay(SearchResult result, Func2 getProductVariants) +39 Merchello.Web.Search.CachedProductQuery.PerformMapSearchResultToDisplayObject(SearchResult result) +81 System.Linq.WhereSelectEnumerableIterator2.MoveNext() +223 System.Linq.Enumerable.FirstOrDefault(IEnumerable1 source) +147 Merchello.Web.Search.CachedProductQuery.GetDisplayObject(Guid key) +267 Merchello.Web.Search.QueryResultFactory1.<BuildQueryResult>b__2(Guid x) +15 System.Linq.WhereSelectListIterator2.MoveNext() +243 System.Linq.WhereSelectEnumerableIterator2.MoveNext() +118 System.Linq.WhereSelectEnumerableIterator2.MoveNext() +118 System.Linq.Buffer1..ctor(IEnumerable1 source) +153 System.Linq.Enumerable.ToArray(IEnumerable`1 source) +106 Merchello.Bazaar.Models.ViewModels.ProductCollectionModel.Initialize() +217

  • Eric Mailloux 10 posts 30 karma points
    Apr 13, 2016 @ 01:35
    Eric Mailloux
    0

    Rusty, i'm about to finish my project and the importation système still cause issue. Did you look a my problems ? Are you still there ?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Apr 13, 2016 @ 15:43
    Rusty Swayne
    0

    Hey Eric,

    I am still here =)

    I have it on the task list to look at in greater detail during the current sprint, but have not hit that task as of yet. I think this is the same problem that Richard from CMSImport are running into - it is a priority.

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Apr 18, 2016 @ 06:25
    Richard Soeteman
    1

    Hi Rusty,

    I found out when run Mertchello built from VS I did not get this error, maybe that helps?

    Best,

    Richard

  • Eric Mailloux 10 posts 30 karma points
    Jun 14, 2016 @ 03:12
    Eric Mailloux
    0

    Rusty,

    I did took time to inspect index. First, i put raise event to false in my save call. From now everyting look good, no more problem. When i it save on a product or rebuild the index, my problem came back. Look like indexation problem. To recover my data, i remove all index (drop file in temp). After that trick that cannot be implemted in production.... i look at the index and see a difference...

    This is the working index:

    detachedContents: [
        {"Key":"7bc6ae16-bffe-4f15-9db0-7bbec934689d",
        "DetachedContentType":{
            "$id":"1",
            "EntityTfKey":"9f923716-a022-4089-a110-1e9b4e1f2ad1",
            "Name":"OeuvreProductContent",
            "ContentTypeKey":"d7291000-4bf5-7ea1-53e0-be7d0c44eb1e",
            "CreateDate":"2016-06-13T19:13:49.433Z",
            "UpdateDate":"2016-06-13T19:13:49.433Z",
            "Key":"f32bf834-fd5a-459c-b3a9-d750d3bfe173"},
            "CultureName":"en-US",
            "TemplateId":1191,
            "ProductVariantKey":"c82bd9b7-ea37-4780-b6cf-e07d3acb031e",
            "Slug":"avoir-limpression-quil-est-plus-tard-ici-quailleurs",
            "CanBeRendered":true,
            "DetachedDataValues":[
                {"Key":"idArtiste","Value":"\"2\""},
                {"Key":"vendu","Value":"\"1\""},
                {"Key":"description","Value":"\"Oil\""},
                {"Key":"nomDeLartiste","Value":"\"Guy paquet\""},
                {"Key":"format","Value":"\"10 X 30\""},
                {"Key":"image","Value":"{\"src\":\"/media/Iris006.jpg\",\"focalPoint\":{\"left\":0.5,\"top\":0.5}}"}],
        "CreateDate":"2016-06-13T22:35:35.24Z",
        "UpdateDate":"2016-06-13T22:46:40.1667779-04:00"},
        {"Key":"a650e73f-30b1-4ac6-b9d6-6e80d8291d2f",
        "DetachedContentType":
            {"$id":"2",
            "EntityTfKey":"9f923716-a022-4089-a110-1e9b4e1f2ad1",
            "Name":"OeuvreProductContent",
            "ContentTypeKey":"d7291000-4bf5-7ea1-53e0-be7d0c44eb1e",
            "CreateDate":"2016-06-13T19:13:49.433Z",
            "UpdateDate":"2016-06-13T19:13:49.433Z",
            "Key":"f32bf834-fd5a-459c-b3a9-d750d3bfe173"},
            "CultureName":"fr-CA",
            "TemplateId":0,
            "ProductVariantKey":"c82bd9b7-ea37-4780-b6cf-e07d3acb031e",
            "Slug":"avoir-limpression-quil-est-plus-tard-ici-quailleurs",
            "CanBeRendered":true,
            "DetachedDataValues":[
                {"Key":"idArtiste","Value":"\"2\""},
                {"Key":"vendu","Value":""},
                {"Key":"description","Value":"\"Huile\""},
                {"Key":"nomDeLartiste","Value":"\"Guy paquet\""},
                {"Key":"format","Value":"\"10 X 30\""},
                {"Key":"image","Value":"{\r\n \"src\": \"/media/Iris006.jpg\"\r\n}"}],
        "CreateDate":"2016-06-13T22:35:35.25Z",
        "UpdateDate":"2016-06-13T22:46:40.173283-04:00"}
    ] 
    

    This is the bad one :

    detachedContents: 
    [
        {"Key":"7bc6ae16-bffe-4f15-9db0-7bbec934689d",
        "DetachedContentType":{
            "$id":"1",
            "EntityTfKey":"9f923716-a022-4089-a110-1e9b4e1f2ad1",
            "Name":"OeuvreProductContent",
            "ContentTypeKey":"d7291000-4bf5-7ea1-53e0-be7d0c44eb1e",
            "CreateDate":"2016-06-13T19:13:49.433Z",
            "UpdateDate":"2016-06-13T19:13:49.433Z",
            "Key":"f32bf834-fd5a-459c-b3a9-d750d3bfe173"},
            "CultureName":"en-US",
            "TemplateId":1191,
            "ProductVariantKey":"c82bd9b7-ea37-4780-b6cf-e07d3acb031e",
            "Slug":"avoir-limpression-quil-est-plus-tard-ici-quailleurs",
            "CanBeRendered":true,
            "DetachedDataValues":[
                {"Key":"idArtiste","Value":"\"2\""},
                {"Key":"vendu","Value":"1"},
                {"Key":"description","Value":"\"Oil\""},
                {"Key":"nomDeLartiste","Value":"\"Guy paquet\""},
                {"Key":"format","Value":"\"10 X 30\""},
                {"Key":"image","Value":"{\r\n \"src\": \"/media/Iris006.jpg\",\r\n \"focalPoint\": {\r\n \"left\": 0.5,\r\n \"top\": 0.5\r\n }\r\n}"}],
                "CreateDate":"2016-06-13T22:35:35.2415743-04:00",
                "UpdateDate":"2016-06-13T22:38:05.5933004-04:00"},
        {"Key":"a650e73f-30b1-4ac6-b9d6-6e80d8291d2f",
        "DetachedContentType":{
            "$ref":"1"},
            "CultureName":"fr-CA",
            "TemplateId":0,
            "ProductVariantKey":"c82bd9b7-ea37-4780-b6cf-e07d3acb031e",
            "Slug":"avoir-limpression-quil-est-plus-tard-ici-quailleurs",
            "CanBeRendered":true,
            "DetachedDataValues":[
                {"Key":"idArtiste","Value":"\"2\""},
                {"Key":"vendu","Value":"\"True\""},
                {"Key":"description","Value":"\"Huile\""},
                {"Key":"nomDeLartiste","Value":"\"Guy paquet\""},
                {"Key":"format","Value":"\"10 X 30\""},
                {"Key":"image","Value":"{\"src\":\"/media/Iris006.jpg\"}"}],
                "CreateDate":"2016-06-13T22:35:35.2495815-04:00",
                "UpdateDate":"2016-06-13T22:38:05.6042927-04:00"}
    ] 
    

    You can see than the second content miss some field !!!!

  • Eric Mailloux 10 posts 30 karma points
    Jun 14, 2016 @ 03:54
    Eric Mailloux
    0

    Same thing here, non bug if code insert product in debug mode.

  • Eric Mailloux 10 posts 30 karma points
    Jul 21, 2016 @ 05:05
    Eric Mailloux
    0

    A few month later, try to make some work around whitout any success. Rusty, did you look a my last post ?

  • Eric Mailloux 10 posts 30 karma points
    Aug 11, 2016 @ 15:05
    Eric Mailloux
    0

    Hi Rusty, are you still there ?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 11, 2016 @ 21:32
    Rusty Swayne
    0

    LOL - yep. I'm still alive. Are you still having this issue?

    What version of Merchello are you using?

  • Steve Borg 28 posts 99 karma points
    Jun 13, 2017 @ 13:55
    Steve Borg
    0

    Hi,

    We are now experiencing this problem even with simplified code based on Rusty's post above.

    It does look to be related to templateId being null in the Examine indexes even though we have a template associated with the extended data document type and even if we set the templateId programmatically in the extended data code.

    Incidentally, if I create the same product exactly but with options then we don't get the problem.

    Did anyone ever get to a resolution of this problem? Please reply if you did.

    Best regards,

    Steve

  • Steve Borg 28 posts 99 karma points
    Jun 22, 2017 @ 08:53
    Steve Borg
    1

    Possible solution / Workaround:

    In our particular case this was only a problem where we had a simple product (i.e. no options) AND where there is more than one language.

    It seems to be an issue with Examine regarding the $ref tags. Kudos to my colleague for identifying the issue and a possible solution.

    Workaround:

    Create the product with fake option information. Then add all the extended content for each language. Save the product. Then remove the option information and re-save the product.

    Possible solution:

    A change to Merchello at file: Merchello.Core/Models/DetachedContent/DetachedContentType.cs

    Add the following attribute to the DetachedContentType class:

    [JsonObject(IsReference = false)]
    

    We are not sure if this will cause any issues but have been using it the last week.

    I hope this helps someone.

    Best regards,

    Steve

  • Arjan Woldring 124 posts 231 karma points
    Mar 10, 2018 @ 11:42
    Arjan Woldring
    0

    This helped me a lot. It all has to do with more than 1 language configured in Umbraco.

    We have standard English (US) and Dutch (NL) and are using CMSImport. If we have both languages, we got the detachedcontenttype null error.

    If we delete in our case the English language in Umbraco, then the import runs without problems.

    Nevertheless, would love to have this fixed. Multi language would still be very nice :P

  • Simon 692 posts 1068 karma points
    Jul 03, 2019 @ 14:01
    Simon
    0

    Hi Steve, What do you mean by <

    Thanks

  • Simon 692 posts 1068 karma points
    Jul 03, 2019 @ 14:20
    Simon
    0

    Hi Steve, can you share some code pleasE?

Please Sign in or register to post replies

Write your reply to:

Draft