KonaKart Community Forum

Installation / Configuration => Programming of KonaKart => Topic started by: JimmyBlue on December 09, 2011, 09:41:55 am

Title: Dynamic Prices using konakart
Post by: JimmyBlue on December 09, 2011, 09:41:55 am
Hi Folks,

I'm currently working on a web shop project. The shop has the following requirement:
The prices are dynamic. The price should be fetched through webservices.

Is there an opportunity to change only one distinct method which is invoked by all the other relevant functions to get the price.
Currently my solution works on different API-functions that all have to be adapted.

There has to be adapted GetProducts(), GetAllProducts(), AddToBasket(), UpdateBasket(), GetBestSellers and
the corresponding WithOptions functions.

Regards Jimmy
Title: Re: Dynamic Prices using konakart
Post by: ryan on December 09, 2011, 10:12:21 am
If you fetch all of you prices through web services (and not just the final price added to the cart) won't this make it very slow when you retrieve an array of products? Won't it also stop you sorting and filtering by price?
Title: Re: Dynamic Prices using konakart
Post by: JimmyBlue on December 09, 2011, 10:32:18 am
Hi ryan,

you're right. That should not be the solution. Well then I have to adapt all the functions.

But there is another issue:
When the customer wants to add a product to the cart (Basket) how can I use the external
price. Konakart always fetches the prices from the shop. When I adapt the function AddToBasket(WithOptions)
so that the product price is set dynamically, the basketprice doesn't adopt this price and calculate the correct
basketprice.

And using the method setFinalInc/ExTax does not fit the case when the customer already has the product inside
his cart. Otherwise he would get the price for only one product.

What do you suggest me to do ?

Regards Jimmy
Title: Re: Dynamic Prices using konakart
Post by: ryan on December 09, 2011, 10:35:22 am
Take a look at http://www.konakart.com/docs/usingBasketPrice.html
Title: Re: Dynamic Prices using konakart
Post by: JimmyBlue on December 09, 2011, 02:11:47 pm
Quote from: ryan on December 09, 2011, 10:35:22 am
Take a look at http://www.konakart.com/docs/usingBasketPrice.html


Yeah I also tried to follow those instructions. The problem is, that a customer probably already has that kind of product in his basket.
Then if you add an additional one, there are two products inside the basket but at the price of one. (Cause

b.setFinalPriceExTax(new BigDecimal("22.22"));

always refers to the whole basket).

I already tried this proceeding...

Regards Jimmy
Title: Re: Dynamic Prices using konakart
Post by: ryan on December 09, 2011, 02:30:02 pm
You have control over the price and you know what's in the basket, so you can set the price to what you want. You may even want to give a discount if he has a high quantity.
Title: Re: Dynamic Prices using konakart
Post by: JimmyBlue on December 12, 2011, 10:00:38 am
That's right,

but I don't know whats currently in the cart. A little example:

A customer inserted a product A into the cart.
After a while he says to hisself "I like to add an additional product A to the cart" (Not inside the cart but
from a product dialog).

If the function which inserts the additional product A does something like basket.setFinalPriceExTax
the already inserted product A isn't taken into consideration. And I'm not able to get information from
the actual cart from those functions. That's my problem.

Regards Jimmy
Title: Re: Dynamic Prices using konakart
Post by: ryan on December 12, 2011, 10:22:21 am
Try getBasketItemsPerCustomer()
Title: Re: Dynamic Prices using konakart
Post by: JimmyBlue on December 14, 2011, 01:24:24 pm
getBasketItemsPerCustomer() is a quite useful function.

But do you know why it is only once possible to set the FinalPriceExTax?
Only the first invocation of the function addtobasketwithoptions is able to adapt
this variable by using the function setFinalPriceExTax(). The second invocation doesn't
have an impact.
But I want to change the tax on every invocation.

What do you suggest?
Title: Re: Dynamic Prices using konakart
Post by: ryan on December 14, 2011, 01:29:38 pm
Sorry but I don't understand what you're saying.
Title: Re: Dynamic Prices using konakart
Post by: JimmyBlue on December 14, 2011, 01:38:48 pm
There is an API function called addToBasketWithOptions(), which is invoked when a customer adds a product to the basket.

Inside the function I calculate the new price of the basket dependent on the count of already existing products inside the cart
with the same productid.

But on the second invocation of the function addToBasketWithOptions() the function setFinalPriceExTax() has no consequence.
Title: Re: Dynamic Prices using konakart
Post by: ryan on December 14, 2011, 01:47:48 pm
In this mode you can't update existing basket items by changing the quantity since it would have to calculate the average price of what was already there plus the new price. All you need to do is to delete the current basket item and add your new one with the quantity and price set by you.
Title: Re: Dynamic Prices using konakart
Post by: JimmyBlue on December 14, 2011, 02:15:20 pm
You're absolutely right.  :)

That helped me a lot. You saved my day with your great help. I appreciate it.

Regards Jimmy