How to propagate the rounding configuration in a Kentico store settings for custom calculations? - rounding

I am developing a commerce site in Kentico 11 CMS and, in addition to a product price, need to compute its insurance cost based on a user’s input.
Kentico allows to configure a price rounding option in Store configuration application -> Store settings -> General tab and I would like to use it for my custom calculations too, so that my bespoke functionality rounds the result according to the number of decimal places as per the global store setting.
As per Kentico documentation you can customise the global rounding by creation of a Service class implementing IRoundingService interface with the Round() method according to your specific requirements and a SeviceFactory class implementing IRoundingServiceFactory interface with the GetRoundingService() method. Ideally, I would like to avoid this as I am happy with the standard financial rounding option in Kentico and simply want to apply it to my custom functionality for consistency.

You can retrieve the rounding service for the context site as follows:
using CMS.Core;
using CMS.Ecommerce;
using CMS.SiteProvider;
IRoundingService roundingService = Service.Resolve<IRoundingServiceFactory().GetRoundingService(SiteContext.CurrentSiteID);
Then call the rounding method as roundingService.Round(insurance, currency) passing to it a decimal value and the current currency.
The current currency you can get as below:
CurrencyInfo currencyInfo = ECommerceContext.CurrentCurrency;

Related

Does Hybris commerce have price override capability

Does Hybris commerce have price override or appeasements capability at Order level or Item level.
There are mulitple ways how that can be done in hybris, one example is using ASM (assisted service module) that offers special promotions that can be granted by a service agent.
There might also be ways to achieve this using the cs-cockpit (customer service cockpit), I haven't looked into that deeper though.
For ASM documentation look e.g. here: https://help.hybris.com/6.3.0/hcd/8ac06f10866910148d8c850e15b102d2.html
Hope this helps a bit.
It really depends on what exactly are you trying to achieve. If you like some sort of a discount or promotions, you can see the link provided by Sebastion. In the wiki you can also find other promotion and discount engines. Another solution would be to have multiple price rows per product. Hybris supports this. For example for a particular product, you can set a special price for a special customer or customerGroup. Also the same way you can set different prices for different quantities. For example an apple costs 1$ but if you buy 100, the price goes to 0.75$.
More information about the pricerows: here
Keep in mind that Hybris is highly customizable so you can also override some logic from the PriceFactory but i would recommend using first the out of the box price features and then try overriding the PriceFactory.

Azure Search Distance filter with variable distance

Suppose I have the following scenario:
A search UI to allow individuals to find plumbers who are able to service their home location.
When a plumber enters their info into the system, they provide their coordinates and a maximum distance they are willing to travel.
The individual can then enter their home coordinates and should be presented with a list of plumbers who are eligible.
Looking at the Azure Search geo.distance function, I cannot see how to do this. Scenarios where the searcher provides a distance are well covered but not where the distance is different for each search record.
The documentation provides the following example:
$filter=geo.distance(location, geography'POINT(-122.131577 47.678581)') le 10
This works correctly but if I try and change the 10 to the maxDistance field, it fails with
Comparison must be between a field, range variable or function call
and a literal value
My requirement seems fairly basic but am now wondering if this is currently possible with Azure Search?
I found an azure feedback suggestion asking for this feature but no news on if/when it will be implemented. Therefore it is safe to assume that this scenario is not currently supported.
To add to Paul's answer, one possible workaround is to use a conservatively large constant value instead of referencing the maxDistance field in your $filter expression. Then, you can filter the resulting list of plumbers on the client to take each plumber's max distance into account and produce final list of plumbers.

Dynamics CRM 2011 Calculate Ratios

I've created two workflows that count the number of leads and the number of a custom entity called Legal cases. I would like to come up with a ratio for reporting purposes that calculates legal cases/leads. The workflow updates two fields on the forms (leads and cases) every time one of the entity is created. I tried to use the following code:
function calculate()
{
var val1 = Xrm.Page.entity.attributes.get['getlead_casecounters'].getValue();
var val2 = Xrm.Page.entity.attributes.get['getlead_leadcounter'].getValue();
if(val1==null)return;
if(val2==null)return;
var result = val1 / val2;
Xrm.Page.entity.attributes.get['getlead_casetoleadratio'].setValue(result);
}
The problem is that the casetoleadratio field doesn't appear to update. Any thoughts or recommendations?
Take a look at https://stackoverflow.com/a/11923059/2295317 I think it's exactly what you are trying to do. Basically that last line should be:
Xrm.Page.getAttribute("getlead_casetoleadratio").setValue(result);
If that doesn't do it then maybe try to force a save using:
Xrm.Page.Data.Entity.Save();
as seen here: https://stackoverflow.com/a/18635688/2295317
The best way to show arithmetic calculations is by coding them directly inside your reports.
There’s no good place to store these calculations in CRM anyway since CRM only knows how to store data per a single record.
Eventually, any elegant solution that needs calculation beyond the basics (max, average, min, sum, count, percentage) will require some kind of coding, which it seems you’re trying to avoid.
For the record, client side (javaScript) functions that you include in your forms only run inside the your browser in the context of a single record that you create or update.
WF will not / cannot run these functions. To run functionally in WF you need to write custom workflow activities or plug-ins using c# for example.

Dynamics CRM 2011: custom entity fields that calculate something

I need certain custom entity fields to calculate and display values based on operations on the data in the system.
For example an a booking system implementation with contacts and custom entity: tickets. There is a one-many relationship between contact and tickets.I would like to create a field that calculates and displays in the contact form:
frequent flyers: more than 10 tickets bought.
a field that displays yes or no based on whether a first class ticket has ever been purchased. Ticket ref would start with say, FCxxx
If this isn't possible perhaps someone could suggest an alt method for displaying this info?
This is possible and you have some ways to do that: Workflow or Plug-in.
If you make a lot of calculations i think the best way is doing a plug-in. You can register in post create event of tickets entity and there you can make all this calculations and update the custom fields of contact entity.
You can check some tutorials about developing a plug-in:
http://mscrmshop.blogspot.pt/2010/10/crm-2011-plugin-tutorial.html
http://msdn.microsoft.com/en-us/library/gg695782.aspx
http://crmconsultancy.wordpress.com/2010/10/25/plugins-in-crm-2011/
Specific information about registering a plug-in:
http://msdn.microsoft.com/en-us/library/hh237515.aspx
In SDK you can find more examples.
As far I'm aware, it's not possible to achieve without coding. So, if you're looking for a way to customize it by mousing, you might be just out of luck.
If you wish to display that information upon retrieval of the a customer, it's probably fastest to get it using JavaScript. You can add a custom script to onload event. However, that means that you'll have to write JavaScript so if you're not into coding you'll have problems.
If you do know how to code, perhaps creating a plugin with C# is the most preferred way (that's what I'd do at least). The advantage of that lies in extensibility, should you realize that you wish to perform more operations.
Also, if you wish to store the computed values, you'll have to go with a plugin. Otherwise, only GUI operations will perform the computations. If a program will enter/retrieve data in the background, you can't rely that the values will be computed, unless you listen to the messages of Retrieve, Create etc.

Lookup field with multiple locations for SharePoint 2010

Folks!
In my recent project I’ve faced with the situation when I need to develop “tricky” Custom Field Type (CFT) for Share Point 2010. That CFT must behave like an Out-Of-The-Box Lookup Field, but it must point to couple of different locations. For example, the Lookup field can be pointed to the web A, list B in the web A and to the some field in the list B – let’s call that like a Location, but my field must be able to point to many Locations at the same time. In addition to that main requirement, my CFT must be sortable, filterable and represent an ability to search by EQUAL using CAML, like a Lookup field. Does anybody faced with such tasks? SharePoint masters, please, instruct me with the RIGHT path!!!

Resources