Sonata\ProductBundle\Entity\BaseProduct::hasOneMainCategory PHP Method

hasOneMainCategory() public method

public hasOneMainCategory ( )
    public function hasOneMainCategory()
    {
        if ($this->getCategories()->count() == 0) {
            return false;
        }
        $has = false;
        foreach ($this->getProductCategories() as $productCategory) {
            if ($productCategory->getMain()) {
                if ($has) {
                    $has = false;
                    break;
                }
                $has = true;
            }
        }
        return $has;
    }