cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Change sales item description from plugin

JoergAldinger
Active Contributor
0 Likes
511

Hello all, hello rzieschang , hello kfrick ,

We have a small method that tries to change the item description when added from a different unit of measure. E.g. When the barcode for a "Coca Cola" is scanned and the barcode belongs to a six-pack, we want to have the description read "Coca Cola - Six-Pack". However we have trouble in both the events BEFORE and AFTER:

@PluginAt(pluginClass=ReceiptPosService.class, method="addSalesItem", where=POSITION.BEFORE)
public void AddSaleItem(Object proxy, Object[] args, StackTraceElement callStack) throws BreakExecutionException
{
    ReceiptEntity receipt = (ReceiptEntity)args[0];
    receipt.getSalesItems().stream().forEach(item -> {
        if(!item.getDescription().contains(item.getQuantityTypeCodeName()) 
           && !item.getQuantityTypeCode().equals("-1"))
            item.setDescription(item.getDescription() + " - " + item.getQuantityTypeCodeName());
    });
    BroadcasterHolder.INSTANCE.getBroadcaster().broadcastPluginEventForPath("RECEIPT_REFRESH", null);
}

The problem with the BEFORE event above is that the screen doesn't show the updated description until you add another item. It basically always excludes the current item being added.

The problem with the same in the AFTER method is that in FP10 it causes all cash-in/out transactions to fail with an exception, even if we add no plugin code at all:

@PluginAt(pluginClass = ReceiptPosService.class, method = "addSalesItem", where = PluginAt.POSITION.AFTER)
public void UpdateSaleItemAFTER(Object proxy, Object[] args, Object returnValue, StackTraceElement callStack) throws InvalidStateException
{
   // do nothing, or anything
}

I'm not sure if the exception caused by this is actually a bug, but I guess it might be.

Do you have any suggestions on properly updating the item description when adding it?

Maybe we have to:

  1. Use the BEFORE event
  2. Instantiate a new SalesItemEntity
  3. Populate our new SalesItemEntity with the required information
  4. Add it to the ReceiptEntity
  5. Signal to CCO that we added the item manually already?

Any pointers would be welcome!

Thanks and best regards,

Joerg.

Accepted Solutions (1)

Accepted Solutions (1)

Klaus_Frick
Active Participant
0 Likes

Hello joerg.ceo

I forgot that, here the complete construct.

@PluginAt(pluginClass=ReceiptPosService.class, method="addSalesItem", where=POSITION.AFTER)
    public Object UpdateSaleItemAFTER(Object proxy, Object args[], Object ret, StackTraceElement stack){
    // do nothing, or anything

  return ret;
}

Best Regards

Klaus

JoergAldinger
Active Contributor

Hello Klaus!

That worked! Apparently the returnValue is of a different type depending on whether it's a sales item being added or a cash-in/out transaction. Instead of checking the args.length() we decided to go with checking "returnValue instanceof ReceiptEntity" to escape from any modifications in the case of cash transactions, because we don't know if the args.length() could be changed in a future update.

Thanks again,

Joerg.

Answers (1)

Answers (1)

Klaus_Frick
Active Participant
0 Likes

Hello joerg.ceo

The AFTER Method should be the right one for this. But it you are using it wrong - it should look like this:

@PluginAt(pluginClass=ReceiptPosService.class, method="addSalesItem", where=POSITION.AFTER)
    public Object UpdateSaleItemAFTER(Object proxy, Object args[], Object ret, StackTraceElement stack){
    // do nothing, or anything
}

I also do not see any errors. But as this event also occurs with cash-in/cash-out transactions, you have to verify the args.length. When args.length is 2, then it is likely to be a cash-in transaction....

Best Regards

Klaus

JoergAldinger
Active Contributor
0 Likes

Hello Klaus,

Thanks for your response!

You indicate here that the method needs to return an object. Can you specify which object needs to be returned? The ReceiptEntity, the proxy object, or...?

Thanks!

Joerg.