/**
  * Before an update we check that the product categories are right.
  *
  * @param PreUpdateEventArgs $event The pre update event.
  */
 public function preUpdate(PreUpdateEventArgs $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof ProductInterface) {
         $this->categoryIntegrityFixer->fixProduct($entity);
     }
 }
 /**
  * Before an update we check that the product categories are right.
  *
  * @param PreUpdateEventArgs $event The pre update event.
  */
 public function preUpdate(PreUpdateEventArgs $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof CategorizableInterface) {
         $this->categoryIntegrityFixer->fixCategoriesIntegrity($entity);
     }
 }
 /**
  * Test that the principal category is assigned when a product has
  * categories but not principal category.
  */
 public function testFixProductWhenNoPrincipalCategoryButCategories()
 {
     $product = $this->getNewProduct(1);
     $category = $this->getNewCategory(1);
     $product->addCategory($category);
     self::$categoryIntegrityFixer->fixProduct($product);
     $principalCategory = $product->getPrincipalCategory();
     $this->assertInstanceOf(get_class($category), $principalCategory, 'The principal category should be assigned');
     $this->assertEquals(1, $principalCategory->getId(), 'The category assigned as principal category is not the one expected');
 }