November Happy Hour will be moved to Thursday December 5th.

Issue With Picking Commerce Items Dialog (11.8.2)

Vote:
 

We have many blocks that we have created that are designed to allow the picking of a commerce product/variant, these have the standard ContentReference property such as below

        /// 
        /// Gets or sets the product content reference.
        /// 
        /// 
        /// The product content reference.
        /// 
        [Display(
            Name = "Product/Course Variant",
            Description = "The variant to be added to the basket - will use the variant on the page level by default if empty",
            GroupName = SystemTabNames.Content,
            Order = 10
        )]
        [UIHint(EPiServer.Commerce.UIHint.ProductVariation)]
        [AllowedTypes(typeof(SupplierProductVariant), typeof(CourseScheduleVariant))]
        public virtual ContentReference ProductContentReference { get; set; }

However when this picker is shown it seems to show the variant in both the node as well as the product when it should only be shown in the product level and this make it really difficult to use.

We have tried using the Commerce UiHints as shown above EPiServer.Commerce.UIHint.CatalogEntry and EPiServer.Commerce.UIHint.ProductVariation but it always seems to have this issue.

Is there any workaround for this anyone knows?

#191993
May 03, 2018 12:36
Vote:
 

This can be considered a bug. However what is the right way to do it is up to discussion. I'll file a bug so we can discuss and will get back to you.

#192013
May 03, 2018 14:34
Vote:
 

In the meantime, you can resolve that issue by creating a new editor descriptor for it.

Let's do it as following steps:

Create editor descriptor class

[EditorDescriptorRegistration(TargetType = typeof(ContentReference), UIHint = "TopLevelProductVariation")]
public class TopLevelProductVariationReferenceEditorDescriptor : ContentReferenceEditorDescriptor<CatalogContentBase>
{
    public TopLevelProductVariationReferenceEditorDescriptor()
    {
        ClientEditingClass = "your-dojo-client-resources-folder/widget/TopLevelCatalogContentSelector";
    }

    public override string RepositoryKey
    {
        get { return CatalogRepositoryDescriptor.RepositoryKey; }
    }
}

Create content selector dojo widget

(TopLevelCatalogContentSelector widget defined in above step)

define([
    // dojo
    "dojo/_base/declare",
    "dojo/aspect",
    // epi
    "epi-cms/widget/ContentSelector"
], function (
    // dojo
    declare,
    aspect,
    // epi
    ContentSelector
) {
        return declare([ContentSelector], {
            _getDialog: function () {
                // tags:
                //      protected extensions

                var dialog = this.inherited(arguments);
                if (this.dialog && this.contentSelectorDialog) {
                    this.own(
                        aspect.before(this.contentSelectorDialog.tree.model.store, "query", function (query, queryOptions) {
                            query.toplevel = true;
                        }, true),
                        aspect.around(this.contentSelectorDialog.tree, "selectContent", function (originalMethod) {
                            return function (contentReferenceAsString, setFocus, needParentRefresh, onComplete) {
                                if (this.selectedItem.contentLink === contentReferenceAsString) {
                                    return;
                                }

                                originalMethod.apply(this, arguments);
                            };
                        })
                    );
                }

                return dialog;
            }
        });
    });

Use it in your code

/// <summary>
/// Gets or sets the product content reference.
/// </summary>
/// <value>
/// The product content reference.
/// </value>
[Display(
    Name = "Product/Course Variant",
    Description = "The variant to be added to the basket - will use the variant on the page level by default if empty",
    GroupName = SystemTabNames.Content,
    Order = 10
)]
[UIHint("TopLevelProductVariation")]
[AllowedTypes(typeof(SupplierProductVariant), typeof(CourseScheduleVariant))]
public virtual ContentReference ProductContentReference { get; set; }
#192201
Edited, May 10, 2018 5:33
Vote:
 

Updated code for TopLevelCatalogContentSelector widget

define([
    // dojo
    "dojo/_base/declare",
    "dojo/aspect",
    // epi
    "epi-cms/widget/ContentSelector"
], function (
    // dojo
    declare,
    aspect,
    // epi
    ContentSelector
) {
        return declare([ContentSelector], {
            _getDialog: function () {
                // tags:
                //      protected extensions

                var dialog = this.inherited(arguments);
                if (this.dialog && this.contentSelectorDialog) {
                    this.own(
                        aspect.before(this.contentSelectorDialog.tree.model.store, "query", function (query, queryOptions) {
                            query.toplevel = true;
                        }, true),
                        aspect.around(this.contentSelectorDialog.tree, "selectContent", function (originalMethod) {
                            return function (contentReferenceAsString, setFocus, needParentRefresh, onComplete) {
                                if ((this.selectedItem && this.selectedItem.contentLink) === contentReferenceAsString) {
                                    return;
                                }

                                originalMethod.apply(this, arguments);
                            };
                        })
                    );
                }

                return dialog;
            }
        });
    });
#192595
Edited, May 21, 2018 3:45
Vote:
 
<p>A <a href="/documentation/Release-Notes/ReleaseNote/?releaseNoteId=COM-7106">fix for this issue</a> was released today, as part of Commerce 12.3.0.</p>
#193739
Jun 04, 2018 16:59
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.