Inhalte aufrufen

Profilbild

How to create a custom VAT plugin?

adresszeile browser gleiche adresse safedataframe

  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
9 Antworten zu diesem Thema

#1 steveg

steveg

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 27 October 2015 - 17:24

Hi

 

I have been tasked with sorting out our online store, this is one of the products that I am looking at.

 

So far what I have seen is quite good, however, we will need to do a custom plug in that calculates the tax depending on what category the product falls under and (this is the important bit) certain products are either charged VAT on the quantity of that type of product.

 

eg.  

 

Type 1 products are VAT free for 200 piece or less, over 200 pieces then VAT is charged

Type 2 products are VAT free for 50 piece and over, VAT free for 50 piece and under.

 

 

The pieces are calculated from multiple order lines i.e. the customer may order two type 1 products and the second product knocks the quantity over the 200 piece threshold, therefore both order lines now require tax to be added.

 

Anyone know if this is 

 

A.  Possible ?

B.  The location of some kind of tutorial explaining how I can get going with this.

 

A "hello world" plugin tutorial would be ideal.

 

I'm OK with .NET & c# etc

 

Anyone help me out here ?!

 

Steve.



#2 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1118 Beiträge

Geschrieben: 28 October 2015 - 00:33

Please have a look at both core tax providers in Plugins/SmartStore.Tax/Providers to get a feeling for how a tax provider is implemented. The ITaxProvider interface is essential:

/// <summary>
/// Provides an interface for creating tax providers
/// </summary>
public partial interface ITaxProvider : IProvider
{
    /// <summary>
    /// Gets tax rate
    /// </summary>
    /// <param name="calculateTaxRequest">Tax calculation request</param>
    /// <returns>Tax</returns>
    CalculateTaxResult GetTaxRate(CalculateTaxRequest calculateTaxRequest);
}

Add your own plugin with a class that implements this interface. Now the tricky part in your special case is: the CalculateTaxRequest input parameter is shopping cart agnostic; meaning there's absolutely no info about the other cart items. Here comes the extension method SmartStore.Services.Customers.​CustomerExtentions.GetCartItems() to your rescue. You can always obtain the current cart items of any customer by calling:

var cartItems = calculateTaxRequest.Customer.GetCartItems(ShoppingCartType.ShoppingCart);

Rest is up to you  ;)


Murat Cakir
SmartStore AG


#3 steveg

steveg

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 28 October 2015 - 09:24

Hi

 

Thanks for the response,  gives me a bit to go on.

 

From what I can gather 

 

var cartItems = calculateTaxRequest.Customer.GetCartItems(ShoppingCartType.ShoppingCart);

 

will only give me information about the other product lines, however, there will be a need to recalculate the earlier order lines on the fly as newer order lines are created (or deleted / amended).  Or if older order lines are edited they will need to update the newer order lines accordingly.

 

Is this something that will be possible to achieve with the store?

 

Thanks

 

Steve.



#4 steveg

steveg

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 28 October 2015 - 12:46

Further more to the previous post.  After having a bit of a look round the solution.  I can't see an easy way of implementing what I need without a fair amount of recoding of the existing code.  How is this going to affect future updates from SmartStore?  It is looking like I will need quite a bit more than just a tax plugin as like you say at present each order line is completely disconnected from the others.

 

How are the updates handled ?

 

I don't want to end up in the position of every time there is an update having to put the project back together piece by piece.  Or having to recode sections for each update.  Nor do I want to make such drastic changes to the core code that updates are no longer possible.

 

Also the being able to "easily" update the already entered order lines, while another order line is open is still a concern for me.  I really need to know that this is definitely going to be doable with the SmartStore before I start.

 

Thanks



#5 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 28 October 2015 - 12:47

As far as I can see, all you need is the opportunity to manipulate the property ShoppingCartItem.IsTaxExempt.
Because it has a getter only, you are reduced on changing Product.IsTaxExempt. If you plan to change it, then you 
should also reset the entity state of the product to unchanged\unmodified.

Marcus Gesing

Smartstore AG


#6 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 28 October 2015 - 12:50

"Definitely", nobody can say that for sure. It's worth a try.


Marcus Gesing

Smartstore AG


#7 steveg

steveg

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 29 October 2015 - 09:47

 

 

"Definitely", nobody can say that for sure. It's worth a try.

 

 

Nobody can say for sure?  Do you not know your product?   That comment alone has put me off using SmartStoreNet as a solution.

 

It is not "worth a try" if the product is incapable of the functionality that I require.  If the admins have zero clue on this I can only imagine what the rest of the support will be like.

 

Plus you have not really answered any of my questions from the last couple of posts.  Updates?

 

Your really not selling this to me.



#8 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 29 October 2015 - 11:20

What I mean is that nobody of us has ever tried to manipulate a shopping cart that way. An answer like "yes definitely possible" would be possible
if a solution exist. But out of the box there is no solution for your kind of product taxing or order line manipulation. The product is not 
incapable of the functionality that you require, because a) I showed you a way of how that could be achieved and b) it's an open source shopping cart
solution where the code can be adjusted to your requirements by forking or making pull requests. Doing so minimizes the risk of conflicts between your
code and core code.

Marcus Gesing

Smartstore AG


#9 steveg

steveg

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 29 October 2015 - 15:01

I am worried that I will have to do some pretty serious recoding to get the functionality that I desire.  I don't want to end up in a situation that every time an update is released to the store that I spend ages trying to re-incorporate all of my changes into a new project.

 

Nor do I want to branch the project so that no new updates are possible.

 

Basically I don't want to end up painting myself into a corner with this and I certainly do not want to spend the next X amount of weeks/months putting this solution together and it not be suitable for our needs at the end of the day.

 

Your not the only company that I am looking at for this solution and I'm not just going to start rolling with the first thing that I see (your the second one that I am looking at).

 

I am going to be the one responsible for this project from start to finish and then maintaining it.  So I am wanting

 

A.  A flexible product (feature rich & easy to code in)

B.  Easy to apply updates

C.  Mobile friendly (which you are)

D.  Great support  (first impressions here are a bit hmmmmmm....  That's not to say I'm totally put off, but this tread isn't really helping your cause)

 

I'm not trying to cause friction or have a go, I just want to make sure that the product that I settle on is going to be the best fit for our needs, and spending weeks working on a solution initially just to see if it will actually fit our requirements, isn't really an option.



#10 Michael Herzog

Michael Herzog

    SmartStore AG

  • Administrators
  • 3498 Beiträge

Geschrieben: 29 October 2015 - 16:11

Hi,

 

normally the only adaptions that will require to change code in the core solution are alterations of entities.

Mostly alterations can also be handeled within a plugin. If for example you want to change something within a service class

you could register your own service within the plugin and overide only the methods you want to change and invoke base methods 

of the original service for everything else (without implementing them yourself). With action filters you can replace or enhance every

action method out of your plugin. Etc.

 

Regarding changes of code in the core solution: consider using a programm like source tree. With such a programm,

you can easily stash all of your alterations and apply them anew (with one click and a clearly arranged list of merge conflicts, if there are any)

once you've performed an update. 

 

If you branch the project it doesn't mean you're not able to perform updates anymore. You can always merge your code with the updated 

original code. If no automerging is possible for some of your files, you will also be informed about the files that need to be merged 

manually.

 

Concluding: Once you've established a solid (and clean) workflow, you should be able to perform updates within one or two hours no matter how many 

lines of code you have changed. 

 

One last word about our support:

We make a living out of our support services so we put a lot of effort in it to make it perfect. The answers we provide in this forum are not part of our official support programm. 

 

 

 

If the admins have zero clue 

 

We know our product very well but the topic on how to maintain code changes is very large and you could write several pages about this,

which we simply won't do on request in our free support forum.

 

I hope I could help you a little with the information about code maintanance. If there are any open questions please ask again within this thread.

 

Regards,

Michael Herzog


Michael Herzog
Smartstore AG