Hevelop / Facebookpixel

Magento1 module for Facebook Conversion Tracking and Custom Audience
GNU Affero General Public License v3.0
5 stars 2 forks source link

Make product_catalog_id optional #3

Open JEreth opened 7 years ago

JEreth commented 7 years ago

In some scenarios a product_catalog_id is not neceassary. However, if it is not added in admin it breaks the tracking code since there is an empty value in frontend a la ''product_catalog_id: }"

Better check if catalog_id is set before adding it to the tacking code. This can be done by moving it to a extra function like that: protected function getProductCatalogId() { return (Mage::helper('hevelop_facebookpixel')->getProductCatalogId()!='') ? "', product_catalog_id: " . Mage::helper('hevelop_facebookpixel')->getProductCatalogId() : ''; }

And call it in the code function like that:

$pixelCat = "fbq('track', 'ViewContent', {content_category: '" . addslashes($currCat->getName()) . "', content_ids: ['" . implode("','", $productIds) . "'], content_type: 'product'". $this->getProductCatalogId() . "});";

bordeo commented 7 years ago

Thank you @JEreth for your contribution. We take care as soon as possible.