Copied to clipboard

Flag this post as spam?

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


  • Claudiu Bria 34 posts 146 karma points
    Oct 31, 2017 @ 19:46
    Claudiu Bria
    0

    Price agreements thru data modifier task

    Hi,

    I'm using the following code for a data modifier:

    public override Attempt<IProductVariantDataModifierData> PerformTask(IProductVariantDataModifierData value)
    {
        decimal valuePrice = value.Price;
        var customerContext = new CustomerContext(UmbracoContext.Current);
        if (!customerContext.CurrentCustomer.IsAnonymous)
        {
            var customer = (ICustomer)customerContext.CurrentCustomer;
            var priceAgreement = customer.AjourPriceAgreement(value.Name);
            if (priceAgreement != null)
            {
                var startDateConditionPassed = true;
                var endDateConditionMetPassed = true;
                var today = DateTime.Today;
                if (priceAgreement.StartDate != null && today < priceAgreement.StartDate.Value)
                {
                    startDateConditionPassed = false;
                }
                if (priceAgreement.EndDate != null && today > priceAgreement.EndDate.Value)
                {
                    endDateConditionMetPassed = false;
                }
                if (startDateConditionPassed && endDateConditionMetPassed)
                {
                    //value.OnSale = true;
                    //value.SalePrice = priceAgreement.Price;
                    value.ModifyData("OnSale", true);
                    value.ModifyData("SalePrice", priceAgreement.Price);
                }
            }
        }
        //            value.Price = valuePrice;
        return Attempt<IProductVariantDataModifierData>.Succeed(value);
    }
    

    The code resides in App_Code, hence, in merchello.config:

    <taskChain alias="MerchelloHelperProductDataModifiers">
      <tasks>
        <task type="AjourWebShop.Ajour.AjourProductPriceAgreementDataModifier, App_Code" />
        <task type="Merchello.Web.DataModifiers.Product.IncludeTaxInProductPriceDataModifierTask, Merchello.Web" />
      </tasks>
    </taskChain>
    

    The problem is at runtime I get two errors about a lambda expression not being able to be compiled, and finally i get Model.FeatureProducts object null in FtStore.cshtml

    Anyone, please, can you see what am I doing wrong ?

  • Claudiu Bria 34 posts 146 karma points
    Nov 02, 2017 @ 08:40
    Claudiu Bria
    0

    Anyone please ?

    Rusty, please ?

    Here's one of the exceptions i get:

    enter image description here

    Apparently it is caused by the line:

            var customerContext = new CustomerContext(UmbracoContext.Current);
    

    inside AjourMerchelloExt.DataModifiers.Product.AjourProductPriceAgreementDataModifierTask.cs

  • Claudiu Bria 34 posts 146 karma points
    Nov 02, 2017 @ 10:33
    Claudiu Bria
    0

    Another exception is this:

    enter image description here

    Anyone, please ?

  • Alex Clavelle 13 posts 124 karma points
    Dec 29, 2017 @ 20:06
    Alex Clavelle
    0

    Hey friend, can you post the entire contents of your data modifier class? I may have an idea of what's wrong.

Please Sign in or register to post replies

Write your reply to:

Draft