TaxCalculation (applicationContext.xml) - broadleaf-commerce

I am trying to inlcude tax calculation on the site that I am building and I want to use the out of the box SimpleTaxProvider
I am trying to follow this link
https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/pricing/tax/simple-tax-provider#
I have to include the bean definition within my Spring application context file
This may be a noob question but I am confused. Where I am supposed to find this file?
*EDIT:
I understand that I have to do an annotation based configuration but it is not clear to me how
Thanks in advance!!

solved by one of the contributors at github:
https://github.com/BroadleafCommerce/DemoSite/issues/45
I am posting a solution here for anyone interested:
#Configuration
public class MyTaxConfiguration {
#Merge("blTaxProviders")
public List<?> myTaxProviders(SimpleTaxProvider blSimpleTaxProvider) {
//merge
return Arrays.asList(blSimpleTaxProvider);
}
#Bean
SimpleTaxProvider blSimpleTaxProvider(){
SimpleTaxProvider smpl=new SimpleTaxProvider();
Map<String,Double> map= new HashMap();
map.put("SPAIN", 0.08); //example1
map.put("US", 0.1); //example2
map.put("FRANCE", 0.2); //example3
smpl.setItemCountryTaxRateMap(map);
return smpl;
}
}

Related

GlobalChannelInterceptor pass array of patterns

I am Spring Integration 4.3.13 and trying to pass patterns when configuring #GlobalChannelInterceptor
Here is the example
#Configuration
public class IntegrationConfig{
#Bean
#GlobalChannelInterceptor(patterns = "${spring.channel.interceptor.patterns:*}")
public ChannelInterceptor channelInterceptor(){
return new ChannelInterceptorImpl();
}
}
properties file has following values:
spring.channel.interceptor.patterns=*intchannel, *event
I am using direct channels with names that end with these two string
springintchannel
registrationevent
With the above config, both the channels should have interceptor configured but it is not getting configured.
The comma-separate value isn't support there currently.
I agree that we need to fix it, so feel free to raise a JIRA on the matter and we will file a solution from some other place.
Meanwhile you can do this as a workaround:
#Bean
public GlobalChannelInterceptorWrapper channelInterceptorWrapper(#Value("${spring.channel.interceptor.patterns:*}") String[] patterns) {
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper = new GlobalChannelInterceptorWrapper(channelInterceptor());
globalChannelInterceptorWrapper.setPatterns(patterns);
return globalChannelInterceptorWrapper;
}

Spring Integration support for non-conforming services

Spring-WS provides the following support as part of their template.
http://docs.spring.io/spring-ws/site/apidocs/org/springframework/ws/client/core/WebServiceTemplate.html#setCheckConnectionForFault(boolean)
Trying to determine if Spring Integration exposes this. Found the following from 2012, however I was hoping it would be part of the framework.
http://forum.spring.io/forum/spring-projects/integration/119981-ws-outbound-gateway-and-soap-fault
No, we don't support yet.
As I said there: feel free to raise a JIRA issue! :-)
Example configuration based on explanation from 2012 link ...
#Bean
#Description("Workaround for non conforming services")
AbstractWebServiceOutboundGateway initializeWebserviceGateway(
#Qualifier("wsOutboundGateway.handler") Object bean) {
Advised advised = (Advised) bean;
AbstractWebServiceOutboundGateway gateway = null;
try {
gateway = (AbstractWebServiceOutboundGateway) advised
.getTargetSource().getTarget();
} catch (Exception e) {
throw new IllegalStateException("Unable to configure webServiceTemplate for non conforming services");
}
DirectFieldAccessor dfa = new DirectFieldAccessor(gateway);
WebServiceTemplate wst = (WebServiceTemplate) dfa
.getPropertyValue("webServiceTemplate");
wst.setCheckConnectionForError(false);
wst.setCheckConnectionForFault(false);
return gateway;
}

Trying "Messaging via attribute" from the documentation

I'm trying to get the hung of catel but have a problem.
Trying "Messaging via attribute" gets an compile error.
'Catel.MVVM.ViewModelBase.GetService(object)' is obsolete: 'GetService is no longer >recommended. It is better to inject all dependencies (which the TypeFactory fully supports) >Will be removed in version 4.0.0.'
private void OnCmdExecute()
{
var mediator = GetService<IMessageMediator>();
mediator.SendMessage("Test Value");
}
[MessageRecipient]
private void ShowMessage(string value)
{
var messageService = GetService<IMessageService>();
messageService.Show(value);
}
I'm using 3.9.
A hint and a code snippet whould be good help.
Thanks for your attention.
The GetService is marked obsolete. You have 2 options:
1) If you are using a view model, simply let the services be injected in the constructor:
private readonly IMessageMediator _messageMediator;
private readonly IMessageService _messageService;
public MyViewModel(IMessageMediator messageMediator, IMessageService messageService)
{
Argument.IsNotNull(() => messageMediator);
Argument.IsNotNull(() => messageService);
_messageMediator = messageMediator;
_messageService= messageService;
}
2) Use the GetDependencyResolver extension method:
var dependencyResolver = this.GetDependencyResolver();
var messageMediator = dependencyResolver.Resolve<IMessageMediator>();
Solution 1 is the recommended way.
Thanks for your answer.
I also found a good example in the "Catel.Examples" solution, link to download

GWT-GXT FileUploadField

I tried making a form in GXT to upload files, but I see more examples on the net, I failed to make it work a simple FileUploadField to save the file locally.
Cde fragment:
formPanel = new FormPanel();
formPanel.setBodyBorder(false);
formPanel.setHeaderVisible(false);
formPanel.setAction(GWT.getModuleBaseURL() + "fileUpload");
formPanel.setEncoding(Encoding.MULTIPART);
formPanel.setMethod(Method.POST);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
formPanel.setHeaderVisible(true);
fileUploadField = new FileUploadField();
fileUploadField.setName("fileName");
fileUploadField.setAllowBlank(false);
fileUploadField.setFieldLabel("Archivo");
fileUploadField.addListener(Events.OnChange, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent BaseEvent) {
aSubmitButton.setEnabled(true);
}
});
aSubmitButton = new Button("OK");
aSubmitButton.setEnabled(false);
aSubmitButton.setId("submit_button");
aSubmitButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
#Override
public void componentSelected(ButtonEvent inButtonEvent) {
formPanel.submit();
}
});
The above code is the declaration of FormPanel and FileUploadField.
We use gwtupload-0.6.3-compat.jar library to do the job.
Basically, the idea is that on the server side you need to create a servlet, which is going to be accepting your uploaded files. The mentioned library provides UploadAction servlet extension facilitating that.
On the client side you can use one of gwtupload components. We use MultiUploader for instance. That's literally a few lines of code there. Main code is in the listener:
private IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
public void onFinish(IUploader uploader) {
if (uploader.getStatus() == Status.SUCCESS) {
// What you want to do when file is uploaded.
}
}
};
The rest is taken care of by the component. Since the library is for GWT, it comes with source code, so you can see what it's doing behind the scene and read extensive comments in the code.
Free to use of course.

Is it possible to create an orchard autoroute using contents of a custom type property?

I have an Orchard cms module with some additional Content types set up and have added an AutoRoute component via code.
Everything works perfectly, however I am not happy with the default permalink pattern.
What I am trying to do is add a custom pattern and use one of the public properties in my content type. In my case the custom type has a public property called ClubName and I would like that to be used (It makes more sense from a routing perspective).
The Orchard part class name is called TrackPart.
I have tried {Content.TrackPart.ClubName}, {Content.Track.ClubName}, {ContentItem.TrackPart.ClubName},{Content.TrackPart.ClubName} and various other variations but nothing seems to be working.
I am really new to Orchard so there is a high chance I am missing something simple.
Any help would be greatly appreciated.
In response to feedback from #Bertrand-le-roy I created my own token by copying an example token. I can now get see the token in the drop down menu and select it. However the route pattern is still not working.
I can only assume that I have misunderstood the Evaluate() function's context.For usage. It looks like I am not getting the data I need
Here is what I have so far.
public class TrackPartTokens : ITokenProvider {
private readonly IContentManager _contentManager;
public TrackPartTokens(IContentManager contentManager) {
_contentManager = contentManager;
}
public Localizer T { get; set; }
public void Describe(dynamic context) {
context.For("Track", T("Track"), T("Tokens for Track"))
.Token("ClubName", T("ClubName"), T("The name of the club."))
;
}
public void Evaluate(dynamic context) {
context.For<TrackPart>("Track")
.Token("ClubName", (Func<TrackPart, object>)(field => field.ClubName))
.Chain("ClubName", "ClubName", (Func<TrackPart, object>)(field =>field.ClubName))
;
}</code>
The above code was based on the DateTimeField token inside the Orchard.Fields module.
context.For("DateTimeField")
.Token("Date", (Func)(field => field.DateTime))
.Chain("Date", "Date", (Func)(field => field.DateTime));
I had the same issue.
After some troubleshooting I managed to get the autoroute working by changing my implementaion to the following (adapted to your example, note that your setup might require some changes to the linq-function):
In your tokens-class:
First add a using System.Linq statement.
Then change your Evaluate implementation to the following:
context.For<IContent>("Content")
.Token("ClubName", (Func<IContent>, object>)(content =>
content.ContentItem.Parts.OfType<TrackPart>().First().ClubName));
Make sure your AutoroutePart settings in Migrations.cs uses the Content-prefix. Like:
.WithPart("AutoroutePart", partBuilder =>
partBuilder
.WithSetting("AutorouteSettings.AllowCustomPattern", "true")
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")
.WithSetting("AutorouteSettings.PatternDefinitions",
#"[{Name:'Track', Pattern:'{Content.ClubName}',
Description:'Your description'}]")
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
There seems to be some problems with the TokenManager-class in Orchard source that only allows the target-parameter to equal "Content" in order for the call: _data.TryGetValue(target, out value) to work (TokenManager.cs, line 67). I have tried a number of different setups but the _data-dictionary always only contain the "Content" key.
You'll have to make your own token. It's really easy. Copy a working example.

Resources