1

When I have the custom components below one object/property is not persisting. The list component is really just a container to hold a collection of ChildComponents of type AdjustmentExtendedComponent. When I add AdjustmentExtendedListComponent to a cart line on an Order and persist the order everything saves to the database except the AwardedAdjustment property. Is it completely missing from the json in the database.

using Sitecore.Commerce.Core;

namespace MyClient.Commerce.Plugin.Pricing.Components
{
    public class AdjustmentExtendedListComponent : Component
    {

    }
}

using MyClient.Commerce.Shared.Enums;
using Sitecore.Commerce.Core;
using Sitecore.Commerce.Plugin.Pricing;
using Sitecore.Framework.Conditions;

namespace MyClient.Commerce.Plugin.Pricing.Components
{
    public class AdjustmentExtendedComponent : Component
    {
        // used in Azure after deserialize
        public string AdjustmentType { get; set; }

        public AwardedAdjustment AssociatedAdjustment { get; }

        public DiscountCode DiscountCode { get; }

        public decimal AdjustmentRate { get; }

        public string TaxExemptReasonCode { get; set; }

        public AdjustmentExtendedComponent()
        {
        }

        public AdjustmentExtendedComponent(AwardedAdjustment associatedAdjustment, decimal adjustmentRate)
        {
            Condition.Requires(associatedAdjustment, nameof(associatedAdjustment)).IsNotNull();

            AssociatedAdjustment = associatedAdjustment;

            AdjustmentRate = adjustmentRate;

            AdjustmentType = ((AwardedAdjustment)associatedAdjustment)?.AdjustmentType;
        }

        public AdjustmentExtendedComponent(AwardedAdjustment associatedAdjustment, DiscountCode discountCode)
        {
            Condition.Requires(associatedAdjustment, nameof(associatedAdjustment)).IsNotNull();

            AssociatedAdjustment = associatedAdjustment;

            DiscountCode = discountCode;

            AdjustmentType = ((AwardedAdjustment)associatedAdjustment)?.AdjustmentType;
        }
    }
}
  • Thanks - my eye's betrayed me! – M. Brandel Jul 3 at 15:02
2

You must add setters to your properties, like:

public AwardedAdjustment AssociatedAdjustment { get; set; }

public DiscountCode DiscountCode { get; set; }

public decimal AdjustmentRate { get; set; }
0

Not sure what inside in AwardedAdjustment class, but you can try below things:

    //apply setter in your property
    public AwardedAdjustment AssociatedAdjustment { get; set; }

    //Constructor 
    public AdjustmentExtendedComponent()
    {
         //initialize here
         AssociatedAdjustment = new AwardedAdjustment(); 
    }

Hope it will fix your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.