Search code examples
intershop

How to decode COMPUTEDITEMS field on BASKET table


I am trying to see how the basket was calculated by inspecting COMPUTEDITEMS field in BASKET table, i see that is base64 encoded and I tried decoding it in VSCode, without the "BASE64:" at start, but it doesn't work, it just outputs some random characters(also tried changing encoding mode of file but didn't help, it was UTF-8). Could you provide example how this field can be decoded.

COMPUTEDITEMS field in BASKET table


Solution

  • There is an easier way to do what you're trying to achieve. When deployed your Intershop Commerce Management server as development environment you can find a cartridge named dev_basketinfo. It contains a pipeline called InspectBasket with start nodes like Start and DownloadDiagram. Internally it gets the current basket and displays information about the calculation steps, which rule has been executed, etc.

    The harder way would be to connect to the database and read the stored value directly. Computed items column can be accessed using standard JDBC means. You need to process the contents as character large object (clob). After that you can do:

    StringReader reader = new StringReader(clob.getSubString(BASE64_PREFIX.length(),
                (int)clob.length() - BASE64_PREFIX.length()));
    InputStream inputStream = new InflaterInputStream(new Base64InputStream(new ReaderInputStream(reader)));
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
    

    ReaderInputStream is coming from apache commons.