本文整理汇总了PHP中Magento\Catalog\Model\Category类的典型用法代码示例。如果您正苦于以下问题:PHP Category类的具体用法?PHP Category怎么用?PHP Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->_category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Category');
$this->_category->load(5);
$layer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\Category', ['data' => ['current_category' => $this->_category]]);
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\Filter\\Category', ['layer' => $layer]);
}
示例2: ajaxRequestResponse
/**
* Build response for ajax request
*
* @param \Magento\Catalog\Model\Category $category
* @param \Magento\Backend\Model\View\Result\Page $resultPage
*
* @return \Magento\Framework\Controller\Result\Json
*
* @deprecated
*/
protected function ajaxRequestResponse($category, $resultPage)
{
// prepare breadcrumbs of selected category, if any
$breadcrumbsPath = $category->getPath();
if (empty($breadcrumbsPath)) {
// but if no category, and it is deleted - prepare breadcrumbs from path, saved in session
$breadcrumbsPath = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->getDeletedPath(true);
if (!empty($breadcrumbsPath)) {
$breadcrumbsPath = explode('/', $breadcrumbsPath);
// no need to get parent breadcrumbs if deleting category level 1
if (count($breadcrumbsPath) <= 1) {
$breadcrumbsPath = '';
} else {
array_pop($breadcrumbsPath);
$breadcrumbsPath = implode('/', $breadcrumbsPath);
}
}
}
$eventResponse = new \Magento\Framework\DataObject(['content' => $resultPage->getLayout()->getUiComponent('category_form')->getFormHtml() . $resultPage->getLayout()->getBlock('category.tree')->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'), 'messages' => $resultPage->getLayout()->getMessagesBlock()->getGroupedHtml(), 'toolbar' => $resultPage->getLayout()->getBlock('page.actions.toolbar')->toHtml()]);
$this->_eventManager->dispatch('category_prepare_ajax_response', ['response' => $eventResponse, 'controller' => $this]);
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->_objectManager->get('Magento\\Framework\\Controller\\Result\\Json');
$resultJson->setHeader('Content-type', 'application/json', true);
$resultJson->setData($eventResponse->getData());
return $resultJson;
}
示例3: createCategory
/**
* Creates a new child category for $parentCategory
*
* @param \Magento\Catalog\Model\Category $parentCategory
* @return \Magento\Catalog\Model\Category
*/
protected function createCategory($parentCategory)
{
/** @var \Magento\Catalog\Model\Category $category */
$category = $this->objectManager->create('Magento\\Catalog\\Model\\Category');
$category->setStoreId(self::DEFAULT_STORE_ID)->setParentId($parentCategory->getId())->setName(self::NAMES_PREFIX . $this->titlesGenerator->generateCategoryTitle())->setAttributeSetId($category->getDefaultAttributeSetId())->setLevel($parentCategory->getLevel() + 1)->setPath($parentCategory->getPath())->setIsActive(1)->save();
return $category;
}
示例4: aroundGetUrlInstance
public function aroundGetUrlInstance(Category $category, \Closure $proceed)
{
if ($category->getStoreId() == 0) {
return $proceed();
} else {
return $this->objectManager->create(self::FRONTEND_URL)->setStoreId($category->getStoreId());
}
}
示例5: aroundReindex
/**
* Reindex category's products after reindexing the category
*
* @param \Magento\Catalog\Model\Category $subject The cateogry being reindexed
* @param callable $proceed The parent function we are plugged on
* : Magento\Catalog\Model\Category::reindex()
*
* @return \Magento\Catalog\Model\Category
*/
public function aroundReindex(\Magento\Catalog\Model\Category $subject, callable $proceed)
{
$proceed();
if (!empty($subject->getAffectedProductIds())) {
$this->processFullTextIndex($subject->getAffectedProductIds());
}
return;
}
示例6: testAddCatalogToTopMenuItemsWithFlat
public function testAddCatalogToTopMenuItemsWithFlat()
{
$observer = $this->_preparationData();
$this->_category->expects($this->once())->method('getChildrenNodes')->will($this->returnValue([$this->_childrenCategory]));
$this->_category->expects($this->once())->method('getUseFlatResource')->will($this->returnValue(true));
$this->_categoryFlatState->expects($this->once())->method('isFlatEnabled')->will($this->returnValue(true));
$this->_observer->execute($observer);
}
示例7: generateForCustom
/**
* @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $url
* @param int $storeId
* @return array
*/
protected function generateForCustom($url, $storeId)
{
$urls = [];
$targetPath = !$url->getRedirectType() ? $url->getTargetPath() : $this->categoryUrlPathGenerator->getUrlPathWithSuffix($this->category, $storeId);
if ($url->getRequestPath() !== $targetPath) {
$urls[$url->getRequestPath() . '_' . $storeId] = $this->urlRewriteFactory->create()->setEntityType(CategoryUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($this->category->getId())->setRequestPath($url->getRequestPath())->setTargetPath($targetPath)->setRedirectType($url->getRedirectType())->setStoreId($storeId)->setDescription($url->getDescription())->setIsAutogenerated(0)->setMetadata($url->getMetadata());
}
return $urls;
}
示例8: getNode
/**
* @param \Magento\Catalog\Model\Category $category
* @return Node
*/
protected function getNode(\Magento\Catalog\Model\Category $category)
{
$nodeId = $category->getId();
$node = $this->categoryTree->loadNode($nodeId);
$node->loadChildren();
$this->prepareCollection();
$this->categoryTree->addCollectionData($this->categoryCollection);
return $node;
}
示例9: afterSave
/**
* @param \Magento\Catalog\Model\Category $subject
* @param \Magento\Catalog\Model\Category $result
* @return \Magento\Catalog\Model\Category
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterSave(\Magento\Catalog\Model\Category $subject, \Magento\Catalog\Model\Category $result)
{
/** @var \Magento\Catalog\Model\Category $result */
$productIds = $result->getAffectedProductIds();
if ($productIds) {
$this->productRuleProcessor->reindexList($productIds);
}
return $result;
}
示例10: getSelectedAuthors
/**
* @access public
* @param \Magento\Catalog\Model\Category $category
* @return mixed
*/
public function getSelectedAuthors(CategoryModel $category)
{
if (!$category->hasSelectedAuthors()) {
$authors = [];
foreach ($this->getSelectedAuthorsCollection($category) as $author) {
$authors[] = $author;
}
$category->setSelectedAuthors($authors);
}
return $category->getData('selected_authors');
}
示例11: getSelectedArticles
/**
* @access public
* @param \Magento\Catalog\Model\Category $category
* @return mixed
*/
public function getSelectedArticles(CategoryModel $category)
{
if (!$category->hasSelectedArticles()) {
$articles = [];
foreach ($this->getSelectedArticlesCollection($category) as $article) {
$articles[] = $article;
}
$category->setSelectedArticles($articles);
}
return $category->getData('selected_articles');
}
示例12: generateForGlobalScope
/**
* Generate list of urls for global scope
*
* @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
*/
protected function generateForGlobalScope()
{
$urls = [];
$categoryId = $this->category->getId();
foreach ($this->category->getStoreIds() as $id) {
if (!$this->isGlobalScope($id) && !$this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore($id, $categoryId, Category::ENTITY)) {
$urls = array_merge($urls, $this->generateForSpecificStoreView($id));
}
}
return $urls;
}
示例13: aroundReindex
/**
* Reindex category's data after into search engine after reindexing the category
*
* @param \Magento\Catalog\Model\Category $subject The category being reindexed
* @param callable $proceed The parent function we are plugged on
* : Magento\Catalog\Model\Category::reindex()
*
* @return \Magento\Catalog\Model\Category
*/
public function aroundReindex(\Magento\Catalog\Model\Category $subject, callable $proceed)
{
$proceed();
if ($subject->getLevel() > 1) {
$categoryIndexer = $this->indexerRegistry->get(\Smile\ElasticsuiteCatalog\Model\Category\Indexer\Fulltext::INDEXER_ID);
if (!$categoryIndexer->isScheduled()) {
$categoryIndexer->reindexRow($subject->getId());
}
}
return;
}
示例14: buildPath
/**
* @param Category $category
* @return string
*/
protected function buildPath(Category $category)
{
$data = [];
$path = $category->getPath();
foreach (explode('/', $path) as $categoryId) {
$category = $this->_categoryRepository->get($categoryId);
if ($category && $category->getLevel() > 1) {
$data[] = $category->getName();
}
}
return count($data) ? '/' . implode('/', $data) : '';
}
示例15: _getCategory
/**
* Get Category from request
*
* @return Category
*/
protected function _getCategory()
{
if (!$this->_category) {
$this->_category = $this->_objectManager->create('Magento\\Catalog\\Model\\Category');
$categoryId = (int) $this->getRequest()->getParam('category', 0);
if (!$categoryId && $this->_getUrlRewrite()->getId()) {
$categoryId = $this->_getUrlRewrite()->getCategoryId();
}
if ($categoryId) {
$this->_category->load($categoryId);
}
}
return $this->_category;
}