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

Addresses are being deleted completely from the system when changed in PaymentinfoModel

richard_tro
Discoverer
0 Kudos
534

Summary:

When changing the billingaddress for an InvoicePaymentInfo of a cart, the address that was set there before, gets deleted completely from the system and therefore will disappear everywhere, where it was referenced (for example at a b2bunit).

Situation:

  • A b2bunit has references to several addresses, that are marked as billing address.

  • In the checkout one of these addresses is set in the cart by setting the address in the field billingaddress of the paymentinfomodel.

  • When the address in the paymentinfomodel is changed again, the address that was first set, is deleted from the system and therefore is also removed from the b2bunit

Code:

Here is the code, in which the address is set. "setBillingAddress" removes the address, that was set before, completely from the system:

 final CommerceCheckoutParameter parameter = createCommerceCheckoutParameter(cartModel, true); InvoicePaymentInfoModel invoicePaymentInfoModel = (InvoicePaymentInfoModel) getCart().getPaymentInfo();
 
 // this is where it happens!
 invoicePaymentInfoModel.setBillingAddress(addressModel);
 
 parameter.setPaymentInfo(invoicePaymentInfoModel);
 

Question:

  • How does the address, that has been set in the b2bunit and also set in the InvoicePaymentinfoModel before, get removed?

  • Are there any hooks / interceptors in place that do this?

  • Is there some preliminary work necessary to make sure the address does not get deleted?

Accepted Solutions (0)

Answers (1)

Answers (1)

ahalbig
Discoverer
0 Kudos

The issue is, that PaymentInfo.billingAddress is an partOf Relationship, which means that whenever you set the value the old value gets deleted by the PartOfManager as it is assumed like its owned by PaymentInfo. The same issue applies when you delete the PaymentInfo itself.

So when you assign to "partof" fields values, you must ensure you are working with clones. You cannot "reuse" existing item references like assinging directly the default delivery address of an "Customer".