private function getCategory()

in Controller/Pixel/ProductInfoForAddToCart.php [36:50]


    private function getCategory($product)
    {
        $category_ids = $product->getCategoryIds();
        if (count($category_ids) > 0) {
            $category_names = [];
            $category_model = $this->_fbeHelper->getObject(\Magento\Catalog\Model\Category::class);
            foreach ($category_ids as $category_id) {
                $category = $category_model->load($category_id);
                $category_names[] = $category->getName();
            }
            return addslashes(implode(',', $category_names));
        } else {
            return null;
        }
    }