KonaKart Community Forum

Installation / Configuration => Programming of KonaKart => Topic started by: unic1988 on December 10, 2008, 09:46:42 am

Title: How to manipulate shown prices
Post by: unic1988 on December 10, 2008, 09:46:42 am
Hello,

First fo all: Please excuse my terrible english, its not my native language.


Here are my Questions:

1.)
I need to manipulate the shown prices everywhere in the Shop depending on the User. When I took a look in the .jsp's I found some methods like getPriceIncTax(), getPriceExTax(), formatPrice()... is it possible to edit these Methods? I couldn't find the .java files containing these methods.

If this is not possible (what I am expecting) is there another way to manipulate the price that is shown to the User, without replacing every call of getPriceIncTex()/getPriceExTax()? Notice: I don't want to manipulate the Price in the Database!!!

2.)
If I manipulated the price that is shown to the user, and the user decides to buy the product, i need to insert the user-depending-price into my list of orders and not the price that is in the database. After a while of searching through the custom/ Folder i found the class CheckoutConfirmationSubmitAction.java, is this the one i need to modify for my purpose?
If this is the one could anyone tell me what I need to do to modify the price that is saved for the order?

Beside I would be very pleased If anyone could give a link to my where I can find a little Tutorial, that explains how I tell KonaKart to use my modified CheckoutConfirmationSubmitAction.class .

Big thanks for all answers,

I hope my Purpose is possible :)

Title: Re: How to manipulate shown prices
Post by: trevor on December 10, 2008, 11:33:29 am
Hi,

1) What you could do is to use the custom engine ( http://www.konakart.com/engine_customization_faq.php ) and do some post processing on the API calls that get products to change the price.

2) Yes, you have to change the prices on the order products before saving the order. The actual order is created in CheckoutDeliveryAction but at this point it hasn't been saved yet and will show the prices of the products from the DB.

The action classes are in konakart_custom.jar . During development you can put your edited classes under konakart/WEB-INF/classes/com/konakart etc. since they will get picked up before the ones in the jar. Once you are happy, you could create your own jar. Try running .\bin\ant -p from the custom directory. There will be an ant target to build the custom jars.
Title: Re: How to manipulate shown prices
Post by: unic1988 on December 10, 2008, 01:46:04 pm
Hi,

thank you for the very fast and good help! I played around with the KKCustomEng, modifiyed GetProductsPerCategory.java and it worked. Now I have one more Question:

I could solve my Problem by editing GetProductsPerCategory, GetProductsPerManufacturer, ... etc. , but I would really like only to modify one single method or class that reads a product from the database. Can you tell me if such a class exists, so that I only modify one class that is used by GetProductsPerCategory, GetProductsPerManufactuerer, ... etc. to get a Product from the database? Because if I have only one class modified it should be much easier to upgrade to newer versions of KonaKart without much Problems.

Sorry for asking such simple things, but I don't know any other way to check if such a Class exists.

Thanks for each answer!

Title: Re: How to manipulate shown prices
Post by: trevor on December 10, 2008, 02:06:43 pm
No, you have to do it in the 3 or 4 API calls that get products. However, as long as your actual processing code isn't duplicated in each method, then the customisation just consists of a method call to your code in each KK API call. This should be easy to maintain.
Title: Re: How to manipulate shown prices
Post by: unic1988 on December 12, 2008, 12:15:41 pm
Hello,

I have another simple Question:

To change the Price everywhere it gets displayed I edited the following classes:

- GetAllProducts
- GetAllSpecials
- GetAlsoPurchased
- GetBestSellers
- GetProduct
- GetProductNotificationsPerCustomer
- GetProductsPerCategory
- GetProductsPerCategoryPerManufacturer 
- GetProductsPerManufacturer
- GetRelatedProducts
- GetSpecialsPerCategory
- SearchForProducts

and it works well so far.

But there is one place where my modifications take no effect, the customers shopping cart. Does anyone know which method/class gets called when KonaKart asks for the prices of the cart-items?

I tried it with 'GetBasketItemsPerCustomer'. I tried to getProduct(), manipulateIt() and setProduct() for each item in BasketIf[] but that took no effect.

Thanks for all answers!
Title: Re: How to manipulate shown prices
Post by: julie on December 12, 2008, 02:15:40 pm
Try changing the finalPrice attributes of the basket items. These prices take into account the quantity and also whether any product options have been selected.
Title: Re: How to manipulate shown prices
Post by: unic1988 on December 12, 2008, 02:45:29 pm
My Problem is, that I don't know where I have to manipulate the Price, that its shown in the Shopping cart. I figured out that GetBasketItemsPerCustomer is called when a new Item gets added to the cart, but it seems not to get called when I klick on 'cart contents'.

I need one single Class / Method where I can make my pricemanipulations, like the ones I have when I call getProduct() or getProductPerCategory() etc. and beside its important that I don't have to make modifications in the jsp's.
Title: Re: How to manipulate shown prices
Post by: julie on December 12, 2008, 02:51:38 pm
That's because it is saved in the session. Try modifying the attributes I mentioned in the previous post.
Title: Re: How to manipulate shown prices
Post by: unic1988 on December 12, 2008, 04:08:24 pm
Ok, it works, thank you!

But every solution brings a new Problem  :-\

When the User is not logged in "Sub-Total" shows the correct value that equals the sum of all modified product prices. But when the User is logged in it equals the sum of the product prices that are in the database.

I saw that "kkEng.getBasketMgr().getBasketTotal()" in CartTile.jsp is the method that prints Sub-Total.
Can you tell me which API call I have to modify to get the the Sub-total value that equals the sum of all modified prices, or why this method returns another value when the user is logged in?
Title: Re: How to manipulate shown prices
Post by: julie on December 12, 2008, 04:27:05 pm
Take a look at ShowCartItemsAction.java .

A temporary order is created with the customer details if he is logged in or with the details of a "default" customer if he isn't logged in. If no default customer is present, then no temp order is created which is what is happening in your case when you get the correct sub total. You should see an exception in the log.

This temporary order is used to get shipping costs and any promotion discounts etc. so that a customer is aware of these before starting the checkout process. All you need to do is to comment out the line where createTempOrder() is called and you should just see your sub total .
Title: Re: How to manipulate shown prices
Post by: unic1988 on December 17, 2008, 08:37:08 am
Ok that seems to work,thank you very much, but what happens when I klick on "checkout"?

I took a look at the URL and saw that EditCartSubmit.do gets called, so In checked EditCartSubmitAction.java for where Checkout-information is gathered, but i found nothing. Then I saw that
...

if (ecf.getGoToCheckout().equalsIgnoreCase("true"))
{
    return mapping.findForward("CheckoutDelivery");
}

...
seems to redirect to CheckoutDeliveryAction if "checkout" is klicked. Is that right? Because I can't find the place where to edit the final Price Information for the Order, please help me
Title: Re: How to manipulate shown prices
Post by: julie on December 17, 2008, 08:43:55 am
Quoteseems to redirect to CheckoutDeliveryAction if "checkout" is klicked. Is that right?

Yes
Title: Re: How to manipulate shown prices
Post by: unic1988 on December 17, 2008, 09:42:37 am
Well, can you tell me where I have to manipulate an OrderIf or a BasketIf? I looked through CheckoutDeliveryAction.java, CheckoutPaymentAction.java and CheckoutConfirmationAction.java but I can't figure out where to do that.
Or is there maybe the possibility to do that in an API call, that would be much better for me.

I think then it should be fnished.

Title: Re: How to manipulate shown prices
Post by: unic1988 on December 17, 2008, 04:00:12 pm
If someone has the same problem: I solved it by editing createOrder.java and createOrderWithOptions.java.
Now everything seems to work  :)
____________________________________________________________

Next Question:

I want to manipulate the Prices according to the actual Customer and it works well in most cases by calling kkEng.getCustomer(sessionId);
There are only two places where it doesn't work and I can't figure out why: GetAllProducts.java and GetAllSpecials.java .

As you know the sessionId is passed as an parameter into those classes as in many other of those API-Calls too, such as GetProduct.java or GetOrder.java. Apart from GetAllSpecials/GetAllProducts, I have access to the Customer by calling kkEng.getCustomer(sessionId) if the User is logged in. So I really don't know what I am making wrong... or is it a bug that the sessionId is not available in those two classes?

Please help me

Title: Re: How to manipulate shown prices
Post by: julie on December 17, 2008, 05:39:39 pm
The session id should be set to a valid value if the customer is logged in.
Title: Re: How to manipulate shown prices
Post by: unic1988 on December 19, 2008, 12:08:30 pm
I will show you what my Problem is:

I made a Screenshot showing the situation i worry about. At the momment my pricemanipulation-method returns 9,999.99 € if the sessionId is null, 1,111.11 € otherwise. As you can see, the User is logged in. The prices at the "latest products"-panel are showing the value I want (1,111.11), so at this point the sessionId is not null. But the Price at the "whats new"-product is showing 9,999.99 , what means, that in this case the sessionId is null. I found out, that I have to edit GetAllProducts.java to manipulate the price of the "whats new"-panel. The same Problem occurs at the "Specials"-panel.

(http://img116.imageshack.us/img116/2206/kkes8.th.jpg) (http://img116.imageshack.us/my.php?image=kkes8.jpg)


Here is some Code how i modified GetAllProducts.java :

public class GetAllProducts
{
    KKEng kkEng = null;

    /**
     * Constructor
     */
     public GetAllProducts(KKEng _kkEng)
     {
         kkEng = _kkEng;
     }

     public ProductsIf getAllProducts(String sessionId, DataDescriptorIf dataDesc, int languageId) throws KKException
     {
        ProductsIf products = kkEng.getAllProducts(sessionId, dataDesc, languageId);
PriceManipulator pm = new PriceManipulator();
products = pm.manipulatePrice(sessionId, kkEng, products);
return products;
     }
}


The method that manipulates the price only does the following simple calculation(quantity is set to 1, if the manipulated product is not an object of type BasketIf):

if(sessionId != null)
{
return 1111.11*quantity;
}
else
{
return 9999.99*quantity;
}
Title: Re: How to manipulate shown prices
Post by: unic1988 on December 19, 2008, 01:17:12 pm
By the way: is it possible to access the session-object from an Api-Call to do some setAttribute() and getAttribute()? This is not absolutly necessary because I think i can save all important information in a customers custom-field, but I expect sessions to be faster than playing around with very large String-Objects.
Title: Re: How to manipulate shown prices
Post by: unic1988 on January 07, 2009, 09:02:53 am
Does noone have an Idea? I don't know how to solve this without the full sourcecode of KonaKart, so I really need your help.
Title: Re: How to manipulate shown prices
Post by: trevor on January 07, 2009, 09:09:58 am
I'm afraid you've lost me. Could you summarize again what you are trying to achieve ?
Title: Re: How to manipulate shown prices
Post by: unic1988 on January 07, 2009, 10:06:03 am
My aim is to modify the prices of all products in Konakart according to the customer who is looking at them. So I wrote a little pricemanipulation-class with only one important method that consumes the sessionId of the user, an isntance of the kkCustomEngine, an originalProductPrice and the quantity of the product thats price is going to geht manipulated.

To make my modifications happen to all prices everywhere in Konakart I  edited some API-calls like GetAllProducts or GetAllSpecials as in the code above. Nearly everything works fine apart from the prices shown in the "Whats new" and the "Specials" panel. At the moment my pricemodification method only looks if there is an sessionId and then sets the price to 1111.11 € if there is one, 9999.99 € otherwise.
As you can see in the Picture that I have added to one of my previous posts most of the prices get modified right if the user is logged in (set to 1111.11 €), but in the "Whats new" and the "Specials" panel my method seems not to be able to find a sessionId, so the price is set to 9999.99 €. I cant understand why, because the sessionId that is passed to GetAllProducts/GetAllSpecials (according to my tests those two are the API-Calls that return the productIf-Objects for "Whats new" and "Specials") should be the same as in every other API-Call. Do you have an idea what mistakes I am making? Or is it maybe a Bug (what I don't believe)?

Another Problem is, that I want to save which Products prices I have already modified, so I thought it would be suggestive to save this information in the session-object, but how can I get Access to it from an API-Call? Because from my knowledge about http and stuff a HttpServletRequest-object is needed to retrieve the session-object. Maybe you have an idea how to get the session or how I could save some user-dependend information for a while.

I am thankfull for all answers you can give me!
Title: Re: How to manipulate shown prices
Post by: trevor on January 07, 2009, 10:20:36 am
QuoteNearly everything works fine apart from the prices shown in the "Whats new" and the "Specials" panel.


The problem here is that these are cached globally for all users (for performance reasons) and so the price doesn't change. This abnormal behavior has been fixed in the next release out shortly. Your best bet at the moment is to call your price modification code from the JSP to transform the price before display.

QuoteAnother Problem is, that I want to save which Products prices I have already modified, so I thought it would be suggestive to save this information in the session-object, but how can I get Access to it from an API-Call?


Don't confuse the KonaKart sessionId with the application session object. The KonaKart server is stateless and uses the sessionId for security checks. The session you should be using is the session saved by the servlet engine. Take a look at the BaseAction class to see how we save KKAppEng on the session.
Title: Re: How to manipulate shown prices
Post by: unic1988 on January 07, 2009, 10:35:01 am
Well modifying the jsp's is not an option for me, so im going to wait for the next release and for now I subordinate the problem with the "Whats new" and the "Specials" panel.

Thank you for your explanation of what the "sessionId" is, so I don't have to try to get access to the session and can look for another solution to save some information about the user.

By the way I want to thank you and all other admins here for your help, this forum is really usefull!
Title: Re: How to manipulate shown prices
Post by: trevor on January 07, 2009, 10:42:35 am
QuoteBy the way I want to thank you and all other admins here for your help, this forum is really usefull!


Thanks. Please let us know when you are live and don't forget the "Powered By KonaKart" link  :)