public function fixCategoriesIntegrity(CategorizableInterface $categorizable)
    {
        $principalCategory = $categorizable->getPrincipalCategory();
        $categories = $categorizable->getCategories();

        if ($principalCategory instanceof CategoryInterface) {
            /**
             * The product has a principal category but this one is not assigned
             * as product category so this one is added.
             */
            $categorizable->addCategory($principalCategory);
        } elseif (!$categories->isEmpty()) {

            /**
             * The product does not have principal category but has categories
             * assigned so the first category is assigned as principal category.
             */
            $categorizable->setPrincipalCategory($categories->first());
        }
    }
public function fixCategoriesIntegrity(CategorizableInterface $categorizable)
    {
        $principalCategory = $categorizable->getPrincipalCategory();
        $categories = $categorizable->getCategories();

        if ($principalCategory instanceof CategoryInterface) {
            /**
             * The product has a principal category but this one is not assigned
             * as product category so this one is added.
             */
            $categorizable->addCategory($principalCategory);
        } elseif (!$categories->isEmpty()) {

            /**
             * The product does not have principal category but has categories
             * assigned so the first category is assigned as principal category.
             */
            $categorizable->setPrincipalCategory($categories->first());
        }
    }
public function fixCategoriesIntegrity ( CategorizableInterface $ categorizable ) { $ principalCategory = $ categorizable -> getPrincipalCategory ( ) ; $ categories = $ categorizable -> getCategories ( ) ; if ( $ principalCategory instanceof CategoryInterface ) { /**
             * The product has a principal category but this one is not assigned
             * as product category so this one is added.
             */ $ categorizable -> addCategory ( $ principalCategory ) ; } elseif ( ! $ categories -> isEmpty ( ) ) { /**
             * The product does not have principal category but has categories
             * assigned so the first category is assigned as principal category.
             */ $ categorizable -> setPrincipalCategory ( $ categories -> first ( ) ) ; } }
Fixes the categories of a categorizable object.

@param CategorizableInterface $categorizable Categorizable instance
Fixes the categories of a categorizable object .