/** * @return ResourceModel\Category\Collection */ public function getCategories() { $ids = $this->getCategoryIds(); $ids[] = 0; $collection = $this->categoryFactory->create()->getCollection()->addAttributeToSelect(['name', 'url_key'])->addFieldToFilter('entity_id', $ids); return $collection; }
public function test_method_create_should_return_a_valid_category_instance() { $category = ["_id" => 1234, "_value" => "VALUE", "_remain" => 3]; $newCategory = CategoryFactory::create($category); $this->assertInstanceOf('Tufesa\\Service\\Type\\Category', $newCategory); $this->assertEquals($category["_id"], $newCategory->getId()); $this->assertEquals($category["_value"], $newCategory->getValue()); $this->assertEquals($category["_remain"], $newCategory->getRemain()); }
/** * @param string $pathInfo * @return bool|DataObject */ public function match($pathInfo) { $identifier = trim($pathInfo, '/'); $parts = explode('/', $identifier); if (count($parts) >= 1) { $parts[count($parts) - 1] = $this->trimSuffix($parts[count($parts) - 1]); } if ($parts[0] != $this->config->getBaseRoute()) { return false; } if (count($parts) > 1) { unset($parts[0]); $parts = array_values($parts); $urlKey = implode('/', $parts); $urlKey = urldecode($urlKey); $urlKey = $this->trimSuffix($urlKey); } else { $urlKey = ''; } if ($urlKey == '') { return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'index', 'params' => []]); } if ($parts[0] == 'search') { return new DataObject(['module_name' => 'blog', 'controller_name' => 'search', 'action_name' => 'result', 'params' => []]); } if ($parts[0] == 'tag' && isset($parts[1])) { $tag = $this->tagFactory->create()->getCollection()->addFieldToFilter('url_key', $parts[1])->getFirstItem(); if ($tag->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'tag', 'action_name' => 'view', 'params' => ['id' => $tag->getId()]]); } else { return false; } } if ($parts[0] == 'author' && isset($parts[1])) { $author = $this->authorFactory->create()->getCollection()->addFieldToFilter('user_id', $parts[1])->getFirstItem(); if ($author->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'author', 'action_name' => 'view', 'params' => ['id' => $author->getId()]]); } else { return false; } } if ($parts[0] == 'rss' && isset($parts[1])) { $category = $this->categoryFactory->create()->getCollection()->addFieldToFilter('url_key', $parts[1])->getFirstItem(); if ($category->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'rss', 'params' => ['id' => $category->getId()]]); } else { return false; } } elseif ($parts[0] == 'rss') { return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'rss', 'params' => []]); } $post = $this->postFactory->create()->getCollection()->addAttributeToFilter('url_key', $urlKey)->getFirstItem(); if ($post->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'post', 'action_name' => 'view', 'params' => ['id' => $post->getId()]]); } $category = $this->categoryFactory->create()->getCollection()->addAttributeToFilter('url_key', $urlKey)->getFirstItem(); if ($category->getId()) { return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'view', 'params' => ['id' => $category->getId()]]); } return false; }