Adding records to scProductMeta through snippet

I did a bulk import into site_content from a CSV file from my client (setting all the new resources to class_key=scProductResource).

Is there a programmatic way of adding these new resources to the scProductMeta table via snippet? I tried creating a new scProductMeta object, but the resource field looks like it can’t be set from a snippet context.

I have around 100 products that were added that need to be associated with the scProductMeta table, so any automated way of doing this would be appreciated.

Hey @blue148,

Seeing your code would be useful, but I suspect you may be using $meta->fromArray(), which has protection on some fields, like resource.

The way to set those instead relies on using the more verbose $meta->set('resource', $resourceId).

Originally, I was attempting to set the field values on object construct:
$product = $modx->newObject(‘scProductMeta’, array(‘resource’=>$resource->get('id)));

Breaking it into two steps (create new object first, then set the value via $product->set) seems to have worked.

Thanks

1 Like