Inheritance: extends Sonata\CoreBundle\Model\ManagerInterface
 /**
  * {@inheritdoc}
  */
 public function synchronizeVariationsCategories(ProductInterface $product, ArrayCollection $variations = null)
 {
     if (in_array('productCategories', $this->getVariationFields())) {
         return;
     }
     if (!$variations) {
         $variations = $product->getVariations();
     }
     $productCategories = $product->getProductCategories();
     /** @var ProductInterface $variation */
     foreach ($variations as $variation) {
         // browsing variation categories and remove excessing categories
         foreach ($variation->getCategories() as $variationCategory) {
             if ($variationCategory && !$productCategories->contains($variationCategory)) {
                 $this->productCategoryManager->removeCategoryFromProduct($variation, $variationCategory);
             }
         }
         // browsing Product categories and add missing categories
         foreach ($productCategories as $productCategory) {
             $category = $productCategory->getCategory();
             if ($category && !$variation->getCategories()->contains($category)) {
                 $this->productCategoryManager->addCategoryToProduct($variation, $category, $productCategory->getMain());
             }
         }
     }
 }
示例#2
0
 /**
  * Gets the HTML associated with the category menu title
  *
  * @param CategoryInterface $category A category instance
  * @param int               $limit    A limit for calculation (fixed to 500 by default)
  *
  * @return string
  */
 protected function getCategoryTitle(CategoryInterface $category, $limit = 500)
 {
     $count = $this->categoryManager->getProductCount($category, $limit);
     return sprintf("%s <span class=\"badge pull-right\">%d%s</span>", $category->getName(), $count, $count > $limit ? '+' : '');
 }