dw.extensions.facebook.FacebookProduct
defines a data structure that
contains the Facebook representation of a B2C Commerce product. The product is passed to a hook
you can use to customize the default transformation of a product in the B2C Commerce schema to
the Facebook catalog feed export schema.
In addition, a customization hook, com.demandware.plugin.facebook.FacebookFeedHooks, is included for optional implementation in customer custom cartridges. This interface defines the hooks that can be implemented to customize the data included in Facebook feed exports.
Name | Signature | Description |
dw.extensions.facebook.feed.transformProduct | dw.system.Status transformProduct( dw.catalog.Product product, dw.extensions.facebook.FacebookProduct facebookProduct ) | Called after default transformation of given Commerce Cloud product to Facebook product as part of the catalog feed export. |
The feed export generates a Facebook tab-delimited file. You can implement the hooks described previously to customize the default transformation from Product system attributes.
Following is an example of how to define a hook to map product attributes to Facebook product feed attributes:
{
"hooks": "./cartridge/scripts/hooks.json"
}
{
"hooks": [
{
"name": "dw.extensions.facebook.feed.transformProduct",
"script": "./facebook.js"
}
]
}
{
"hooks": [
{
"name": "some.other.hook.name",
"script": "./some-file.js"
}, {
"name": "dw.extensions.facebook.feed.transformProduct",
"script": "./facebook.js"
}
]
}
exports.transformProduct = function (product, facebookProduct) {
// Map the Product "shortDescription" system attribute value to the Facebook product feed "title"
// by default the Product "name" system attribute value is mapped to "title" so Commerce Cloud overrides this
facebookProduct.setTitle(product.shortDescription.markup);
// Map the Product "facebookDescription" custom attribute value to the Facebook product feed "description"
// by default the Product "shortDescription" system attribute value is mapped to "description" so Commerce Cloud overrides this
facebookProduct.setDescription(product.custom.facebookDescription);
};
You can put whatever code you want in the exports.transformProduct function. The code in the example is just to show how it works.
You don't have to use the script name "facebook.js" to contain the hook. However, if you already have hooks in your custom cartridge that are all implemented in an existing script file, you could add this Facebook code in that script file and not create a new one.