Currently converting an extension that was written...
# suitecommerce
c
Currently converting an extension that was written for SCA 2019.1 to be compliant for SC 2020.2. I don’t have access to the original developer….. perhaps someone could provide insight to why the original developer extended the Item.KeyMapping? Basically the PDP includes a child view that displays accessories items, if the added value to the Item.KeyMapping is “True”. My question is….. what is the advantage or why extend Item.KeyMapping? Could the same be achieved if I was to create a helper file and reference the method in my view?
Copy code
function _hasAccessories(item) {
    return item.get('custitem_cust_field') && item.get('custitem_cust_field') !== ' ';
}

ItemKeyMapping.getKeyMapping = _.wrap(ItemKeyMapping.getKeyMapping, function wrapGetKeyMapping(getKeyMappingFn) {

    var keyMapping = getKeyMappingFn.apply(this, _.toArray(arguments).slice(1));

    _(keyMapping).extend({
        _hasAccessories: _hasAccessories
    });

    return keyMapping;
});
s
ItemKeyMapping is kinda like an API for items where myriad item properties are made available through a single reliable interface. Extending it with a custom property would therefore make that value available every time the item model was used
c
It appears that the Item.KeyMapping module is NOT an allowed core module permitted to be include in an extension. What would be an acceptable workaround if any?
s
Well, modifying Item.KeyMapping is a kinda lazy way of ensuring that your property is available when you want it. I think the correct thing to do would be to simply request the item model when you need it and pull the value directly from that.
👍 1