Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Facing issues in calculating discounts

Vote:
 

Hi Team,

I am facing issue in applyign discounts based on segment mapped to campaigns 

The below line is returning object reference error  at Mediachase.Commerce.Security.SecurityContext.GetCurrentUserProfile() in CalculateDiscountActivity.cs

CustomerProfileWrapper profile = SecurityContext.Current.CurrentUserProfile as CustomerProfileWrapper

It is a disconnected architecture. We are using webapi to create purchaseorder and apply promotions.

Is there anyway to get the CustomerProfileWrapper

I tried the below way but is returning null 

var profile = Mediachase.Commerce.Customers.Profile.CustomerProfile.Create(customerContact.UserId) as CustomerProfileWrapper;

Also Please confirm if the below code is used for mapping to segments while calculating discounts.

if (profile != null)
{

SetContext(MarketingContext.ContextConstants.CustomerProfile, profile);

CustomerContact customerContact = CustomerContext.Current.GetContactForUser(user);
if (customerContact != null)
{
SetContext(MarketingContext.ContextConstants.CustomerContact, customerContact);

Guid accountId = (Guid)customerContact.PrimaryKeyId;
Guid organizationId = Guid.Empty;
if (customerContact.ContactOrganization != null)
{
organizationId = (Guid)customerContact.ContactOrganization.PrimaryKeyId;
}

SetContext(MarketingContext.ContextConstants.CustomerSegments, MarketingContext.Current.GetCustomerSegments(accountId, organizationId));
}
}

Thanks in advance

Thanks,

Manjeera T

#157863
Sep 23, 2016 11:41
Vote:
 

Hi,

It would help if you can take the screenshots of your campaign, promotion settings. And what do you have in MarketingContext.Current.GetCustomerSegments(accountId, organizationId)?

Segment is a less known concept of Commerce btw - so it might take some times before you get answers :)

Regards,

/Q

#157866
Sep 23, 2016 14:00
Vote:
 

Hi Quan,

I have created a segment and mapped it to Campaign. This Campaign I have selected while creating promotion.

I am not able to attach the screenshots here.

MarketingContext.Current.GetCustomerSegments(accountId, organizationId) --> is returning 2 rows which contains 7,9. But the segment selected in campaign is "PM OLB" which is 10. This is returning wrong results.

organizationId is also not there for the user.

The below details are from segment table

SegmentId    Name
7                 ECOM
8                OLB
9                 all
10              PM OLB

In CalculateDiscountActivity, Do we require CustomerProfileWrapper?

CustomerProfileWrapper profile = SecurityContext.Current.CurrentUserProfile as CustomerProfileWrapper;

if (profile != null)
{

SetContext(MarketingContext.ContextConstants.CustomerProfile, profile);

CustomerContact customerContact = CustomerContext.Current.GetContactForUser(user);
if (customerContact != null)
{
SetContext(MarketingContext.ContextConstants.CustomerContact, customerContact);

Guid accountId = (Guid)customerContact.PrimaryKeyId;
Guid organizationId = Guid.Empty;
if (customerContact.ContactOrganization != null)
{
organizationId = (Guid)customerContact.ContactOrganization.PrimaryKeyId;
}

SetContext(MarketingContext.ContextConstants.CustomerSegments, MarketingContext.Current.GetCustomerSegments(accountId, organizationId));
}
}

Thanks,

Manjeera T

#157868
Sep 23, 2016 14:34
Vote:
 

Hi Quan,

I found like the below is failing for getting segments.

return ((IExpressionValidator)MarketingContext.Current.ExpressionValidatorClassInfo.CreateInstance()).Eval(key, expr, context);

Any response on this is much appeciated.

Thanks in Advance

Thanks,

Manjeera T

#158309
Sep 27, 2016 11:24
* 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.