/** * 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 purchasable has * categories but not principal category. */ public function testFixPurchasableWhenNoPrincipalCategoryButCategories() { $purchasable = $this->getNewCategorizablePurchasable(1); $category = $this->getNewCategory(1); $purchasable->addCategory($category); self::$categoryIntegrityFixer->fixCategoriesIntegrity($purchasable); $principalCategory = $purchasable->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'); }