Drupal Commerce and Facebook Product Catalog

Drupal Commerce and Facebook Product Catalog

As of writing this article, there is no module that allows you to create a Facebook Product Catalog in combination with Drupal 8 and Drupal Commerce 2.x. That's why I'm open-sourcing my custom solution today.

But first, what is a Facebook Catalog? 

A Facebook Catalog is a container that holds information about your products, like images, links, descriptions, prices, and much more. After you create a catalog and add your products, you can create ads and connect to Facebook and Instagram to show people items from your catalog. 

Facebook will pick the best option for each specific consumer based on their interests and behavior. Dynamic Product Ads can show potential customers products they have previously seen or added to cart on your website.

For all this to work first make sure that you have Facebook Pixel installed on your website. My colleague Andor and I created a Facebook Pixel module for Drupal 8.

To find out more about the module go to the Simple Facebook Pixel project page. It's essential to properly set up the pixel. If not, you won’t be able to get your dynamic ads to work properly.

The simplest way to add products to a catalog is to expose all your products in an XML file that is publicly available on your website. Given how simple this is, I guess that people who need this functionality are also using custom solutions and that's why we don't have any publicly available modules.

My module is NOT plug-and-play. The module is working on one of my sites, but it probably won't work on your site without some modification, unless you have exactly the same fields as I have.

Also, for bigger catalogs with thousands of products, the module might need some refactoring to avoid a time out on the server. Using a batch process to generate and store the XML file somewhere in the cache is probably the way to go.

Commerce Product Catalog is available in the following repository:

https://github.com/gnikolovski/commerce_facebook_catalog

If I can be of assistance, please do not hesitate to contact me.

About the author

Goran Nikolovski is a highly experienced Drupal developer with an extensive skill set that includes PHP, MySQL, HTML, CSS and Javascript. He has experience with large Drupal sites and Drupal Commerce 2.x integration, and he is author of several Drupal modules.

You may also like

2019 recap

As 2019 draws to a close, it’s time for a traditional recap post where I reflect on the best things that happened to me during the year. 

An alternative to Menu Token module

As of writing this blog post, the Menu Token module for Drupal 8 is still in the alpha version and it might not work in all cases. That's why having an alternative solution is great. The alternative to using the Menu Token module for Drupal 8 is to use Menu link plugins.