Page 1 of 1

Product Creation

Posted: Mon Nov 24, 2014 7:14 pm
by dingdong985
Hi,

I'm new to broadleaf commerce. Currently I'm setting up my development environment using oracle database.
I was creating a product in admin, and if not mistaken, this will create a record in BLC_SKU as well.
I manage to display this product, as well as get its defaultSku.
However, i encountered a problem when add to cart, it always hit with error, The requested skuId of " + sku.getId() + " is no longer active.
I debug the code and found out that, the checking in the isActive() under skuImpl.java is false. This is due to hasDefaultSku() is returning false.
protected boolean hasDefaultSku() {
return (product != null && product.getDefaultSku() != null && !getId().equals(product.getDefaultSku().getId()));
}
This part in the SkuImpl.java, all product here is null. When I check database, BLC_PRODUCT_SKU_XREF do not have any record available. This issue solve when I manually add a recrod into this table. M
May I know why record is not created by default int BLC_PRODUCT_SKU_XREF when create Product? Is this is the behaviour or is there anything i miss out?

Thanks

Re: Product Creation

Posted: Tue Dec 02, 2014 8:12 pm
by phillipuniverse
This is correct behavior; that sku is the defaultSku, and so hasDefaultSku() returns false.

The entirety of the isActive() method is copied below:

Code: Select all

public boolean isActive() {
    if (
activeStartDate == null && activeEndDate == null && hasDefaultSku()) {
        return 
lookupDefaultSku().isActive();
    }
    if (
LOG.isDebugEnabled()) {
        if (!
DateUtil.isActive(getActiveStartDate(), getActiveEndDate(), true)) {
            
LOG.debug("sku, " id ", inactive due to date");
        }
    }
    return 
DateUtil.isActive(getActiveStartDate(), getActiveEndDate(), true);
}
 


Because hasDefaultSku() is false, then this falls down below that if statement, where the active date ranges are checked. In this case, DateUtil.isActive() checks to make sure that the current date falls between the active start and end date. If the start date is null, then this will fail. If the end date is null, it assumes that the Sku will be active from the activeStartDate until forever. If the endDate is non-null, then it will return true if the current date falls in-between that.

To fix your problem, this should be a simple matter of setting the 'Active Start Date' field to a date in the past (or the current date) in the admin.

Let us know if you still have issues.