• Welcome to KonaKart Community Forum. Please login or sign up.
 

How to manipulate shown prices

Started by unic1988, December 10, 2008, 09:46:42 am

Previous topic - Next topic

unic1988

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.




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;
}

unic1988

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.

unic1988

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.

trevor

I'm afraid you've lost me. Could you summarize again what you are trying to achieve ?

unic1988

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!

trevor

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.

unic1988

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!

trevor

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  :)