Rodik
Rodik

Reputation: 271

SAP CX (HYBRIS) : How to remove deleted products from the saved cart

Hello I'm having a problem to access to My Saved carts, I have a 500 error. Because a cart in the list of saved carts contains a product is coming null from /commercefacades/order/impl/DefaultSaveCartFacade.java, It no longer exists in our repository.

So, the problem happens when we want to convert SavedCartModel CartModel to SavedCartData CartData. The populator which populates the product data is called :

public class ProductBasicPopulator<SOURCE extends ProductModel, TARGET extends ProductData> extends
    AbstractProductPopulator<SOURCE, TARGET>
{
    private ProductConfigurableChecker productConfigurableChecker;

@Override
public void populate(final SOURCE productModel, final TARGET productData) throws ConversionException
{
    productData.setName((String) getProductAttribute(productModel, ProductModel.NAME));
    productData.setManufacturer((String) getProductAttribute(productModel, ProductModel.MANUFACTURERNAME));

    productData.setAverageRating(productModel.getAverageRating());
    if (productModel.getVariantType() != null)
    {
        productData.setVariantType(productModel.getVariantType().getCode());
    }
    if (productModel instanceof VariantProductModel)
    {
        final VariantProductModel variantProduct = (VariantProductModel) productModel;
        productData.setBaseProduct(variantProduct.getBaseProduct() != null ? variantProduct.getBaseProduct().getCode() : null);
    }
    productData.setPurchasable(Boolean.valueOf(productModel.getVariantType() == null && isApproved(productModel)));
    productData.setConfigurable(Boolean.valueOf(getProductConfigurableChecker().isProductConfigurable(productModel)));
    productData.setConfiguratorType(getProductConfigurableChecker().getFirstConfiguratorType(productModel));
}
// code
}

ProductModel which is passed in the first parameter of the populate method is null and consequently a Null Pointer Exception is thrown.

How could I handle this case? Is there a method to remove products that no longer exist from saved carts ? Or another solution that could correct this problem without removing the saved cart.

Please help me how to resolve this issue. Thanks in advance. Regards,

Upvotes: 1

Views: 983

Answers (1)

mkysoft
mkysoft

Reputation: 5758

How you delete product?

Generally we are checking existing carts and remove item, calculated = false before delete.

On the other hand, product deletion doesn't good concept. If you delete product, orders, consignments, etc getting problem. You need to mark these products as not sellable instead of delete.

Upvotes: 0

Related Questions