public function testOnDuplicateAfterSourceProductNotLinkedWithCategory() { $this->category->getProducts()->clear(); $event = new ProductDuplicateAfterEvent($this->product, $this->sourceProduct); $this->listener->onDuplicateAfter($event); $this->assertCount(0, $this->category->getProducts()); }
/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $title = new LocalizedFallbackValue(); $title->setString('Master catalog'); $category = new Category(); $category->addTitle($title); $manager->persist($category); $manager->flush($category); }
/** * @param Category $root * @param array $categories */ protected function addCategories(Category $root, array $categories) { if (!$categories) { return; } foreach ($categories as $title => $nestedCategories) { $categoryTitle = new LocalizedFallbackValue(); $categoryTitle->setString($title); $category = new Category(); $category->addTitle($categoryTitle); $root->addChildCategory($category); $this->addCategories($category, $nestedCategories); } }
/** * @param Category $category * @param Product[] $products */ protected function removeProducts(Category $category, array $products) { /** @var $product Product */ foreach ($products as $product) { $category->removeProduct($product); } }
/** * @param string $title * @param int $parentId * * @return int */ protected function assertCreate($title, $parentId) { $crawler = $this->client->request('GET', $this->getUrl('orob2b_catalog_category_create', ['id' => $parentId])); /** @var Form $form */ $form = $crawler->selectButton('Save and Close')->form(); $form['orob2b_catalog_category[titles][values][default]'] = $title; if ($parentId === $this->masterCatalog->getId()) { $appendProducts = $this->getProductBySku(LoadProductData::TEST_PRODUCT_01)->getId() . ', ' . $this->getProductBySku(LoadProductData::TEST_PRODUCT_02)->getId(); } else { $appendProducts = $this->getProductBySku(LoadProductData::TEST_PRODUCT_04)->getId(); } $form['orob2b_catalog_category[appendProducts]'] = $appendProducts; $form->setValues(['input_action' => 'save_and_stay']); $this->client->followRedirects(true); $crawler = $this->client->submit($form); $result = $this->client->getResponse(); $this->assertHtmlResponseStatusCodeEquals($result, 200); $this->assertContains('Category has been saved', $crawler->html()); return $this->getCategoryIdByUri($this->client->getRequest()->getRequestUri()); }
public function testToString() { $value = 'test'; $title = new LocalizedFallbackValue(); $title->setString($value); $category = new Category(); $category->addTitle($title); $this->assertEquals($value, (string) $category); }
/** * Returns an array formatted as: * array( * 'id' => int, // tree item id * 'parent' => int, // tree item parent id * 'text' => string // tree item label * ) * * @param Category $entity * @return array */ protected function formatEntity($entity) { return ['id' => $entity->getId(), 'parent' => $entity->getParentCategory() ? $entity->getParentCategory()->getId() : '#', 'text' => $entity->getDefaultTitle()->getString(), 'state' => ['opened' => $entity->getParentCategory() === null]]; }
/** * @Route("/create/{id}", name="orob2b_catalog_category_create", requirements={"id"="\d+"}) * @Template("OroB2BCatalogBundle:Category:update.html.twig") * @Acl( * id="orob2b_catalog_category_create", * type="entity", * class="OroB2BCatalogBundle:Category", * permission="CREATE" * ) * @param Category $parentCategory * @return array|RedirectResponse */ public function createAction(Category $parentCategory) { $category = new Category(); $category->setParentCategory($parentCategory); return $this->update($category); }