本文整理汇总了PHP中Magento\Catalog\Api\CategoryRepositoryInterface类的典型用法代码示例。如果您正苦于以下问题:PHP CategoryRepositoryInterface类的具体用法?PHP CategoryRepositoryInterface怎么用?PHP CategoryRepositoryInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CategoryRepositoryInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getRssData
/**
* {@inheritdoc}
*/
public function getRssData()
{
try {
$category = $this->categoryRepository->get($this->getRequest()->getParam('cid'));
} catch (NoSuchEntityException $e) {
return ['title' => 'Category Not Found', 'description' => 'Category Not Found', 'link' => $this->getUrl(''), 'charset' => 'UTF-8'];
}
$category->setIsAnchor(true);
$newUrl = $category->getUrl();
$title = $category->getName();
$data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'];
/** @var $product \Magento\Catalog\Model\Product */
foreach ($this->rssModel->getProductCollection($category, $this->getStoreId()) as $product) {
$product->setAllowedInRss(true);
$product->setAllowedPriceInRss(true);
$this->_eventManager->dispatch('rss_catalog_category_xml_callback', ['product' => $product]);
if (!$product->getAllowedInRss()) {
continue;
}
$description = '
<table><tr>
<td><a href="%s"><img src="%s" border="0" align="left" height="75" width="75"></a></td>
<td style="text-decoration:none;">%s %s</td>
</tr></table>
';
$description = sprintf($description, $product->getProductUrl(), $this->imageHelper->init($product, 'rss_thumbnail')->getUrl(), $product->getDescription(), $product->getAllowedPriceInRss() ? $this->renderPriceHtml($product) : '');
$data['entries'][] = ['title' => $product->getName(), 'link' => $product->getProductUrl(), 'description' => $description];
}
return $data;
}
开发者ID:tingyeeh,项目名称:magento2,代码行数:33,代码来源:Category.php
示例2: execute
/**
* Send Email Post Action
*
* @return \Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
if (!$this->_formKeyValidator->validate($this->getRequest())) {
$resultRedirect->setPath('sendfriend/product/send', ['_current' => true]);
return $resultRedirect;
}
$product = $this->_initProduct();
$data = $this->getRequest()->getPostValue();
if (!$product || !$data) {
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
$resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
$resultForward->forward('noroute');
return $resultForward;
}
$categoryId = $this->getRequest()->getParam('cat_id', null);
if ($categoryId) {
try {
$category = $this->categoryRepository->get($categoryId);
} catch (NoSuchEntityException $noEntityException) {
$category = null;
}
if ($category) {
$product->setCategory($category);
$this->_coreRegistry->register('current_category', $category);
}
}
$this->sendFriend->setSender($this->getRequest()->getPost('sender'));
$this->sendFriend->setRecipients($this->getRequest()->getPost('recipients'));
$this->sendFriend->setProduct($product);
try {
$validate = $this->sendFriend->validate();
if ($validate === true) {
$this->sendFriend->send();
$this->messageManager->addSuccess(__('The link to a friend was sent.'));
$url = $product->getProductUrl();
$resultRedirect->setUrl($this->_redirect->success($url));
return $resultRedirect;
} else {
if (is_array($validate)) {
foreach ($validate as $errorMessage) {
$this->messageManager->addError($errorMessage);
}
} else {
$this->messageManager->addError(__('We found some problems with the data.'));
}
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Some emails were not sent.'));
}
// save form data
$this->catalogSession->setSendfriendFormData($data);
$url = $this->_url->getUrl('sendfriend/product/send', ['_current' => true]);
$resultRedirect->setUrl($this->_redirect->error($url));
return $resultRedirect;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:65,代码来源:Sendmail.php
示例3: createMageCategory
/**
* Create new Magento category with given $name.
*
* @param string $name
* @return int ID of the created category
*/
public function createMageCategory($name)
{
/** @var $category CategoryInterface */
$category = $this->_manObj->create(CategoryInterface::class);
$category->setName($name);
$category->setIsActive(false);
$saved = $this->_mageRepoCategory->save($category);
$result = $saved->getId();
return $result;
}
开发者ID:praxigento,项目名称:mobi_mod_mage2_odoo,代码行数:16,代码来源:Category.php
示例4: testDelete
public function testDelete()
{
$categoryId = 5;
$parentId = 7;
$this->request->expects($this->any())->method('getParam')->with('id')->willReturn($categoryId);
$category = $this->getMock('Magento\\Catalog\\Model\\Category', ['getParentId', 'getPath'], [], '', false);
$category->expects($this->once())->method('getParentId')->willReturn($parentId);
$category->expects($this->once())->method('getPath')->willReturn('category-path');
$this->categoryRepository->expects($this->once())->method('get')->with($categoryId)->willReturn($category);
$this->authStorage->expects($this->once())->method('setDeletedPath')->with('category-path');
$this->resultRedirect->expects($this->once())->method('setPath')->with('catalog/*/', ['_current' => true, 'id' => $parentId]);
$this->unit->execute();
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:DeleteTest.php
示例5: generate
/**
* Generate list based on categories
*
* @param int $storeId
* @param Product $product
* @param ObjectRegistry $productCategories
* @return UrlRewrite[]
*/
public function generate($storeId, Product $product, ObjectRegistry $productCategories)
{
$urls = [];
foreach ($productCategories->getList() as $category) {
$anchorCategoryIds = $category->getAnchorsAbove();
if ($anchorCategoryIds) {
foreach ($anchorCategoryIds as $anchorCategoryId) {
$anchorCategory = $this->categoryRepository->get($anchorCategoryId);
$urls[] = $this->urlRewriteFactory->create()->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($product->getId())->setRequestPath($this->urlPathGenerator->getUrlPathWithSuffix($product, $storeId, $anchorCategory))->setTargetPath($this->urlPathGenerator->getCanonicalUrlPath($product, $anchorCategory))->setStoreId($storeId)->setMetadata(['category_id' => $anchorCategory->getId()]);
}
}
}
return $urls;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:22,代码来源:AnchorUrlRewriteGenerator.php
示例6: testExecuteWithException
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExecuteWithException()
{
$productId = 11;
$categoryId = 5;
$sender = 'sender';
$recipients = 'recipients';
$formData = ['sender' => $sender, 'recipients' => $recipients];
$redirectUrl = 'redirect_url';
/** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
$redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
$this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])->willReturn($redirectMock);
$this->validatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
$this->requestMock->expects($this->exactly(2))->method('getParam')->willReturnMap([['id', null, $productId], ['cat_id', null, $categoryId]]);
/** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
$productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])->getMockForAbstractClass();
$this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock);
$productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
$this->categoryRepositoryMock->expects($this->once())->method('get')->with($categoryId, null)->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.')));
$productMock->expects($this->never())->method('setCategory');
$this->registryMock->expects($this->once())->method('register')->willReturnMap([['product', $productMock, false, null]]);
$this->requestMock->expects($this->once())->method('getPostValue')->willReturn($formData);
$this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['sender', $sender], ['recipients', $recipients]]);
$this->sendFriendMock->expects($this->once())->method('setSender')->with($sender)->willReturnSelf();
$this->sendFriendMock->expects($this->once())->method('setRecipients')->with($recipients)->willReturnSelf();
$this->sendFriendMock->expects($this->once())->method('setProduct')->with($productMock)->willReturnSelf();
$exception = new \Exception(__('Exception.'));
$this->sendFriendMock->expects($this->once())->method('validate')->willThrowException($exception);
$this->sendFriendMock->expects($this->never())->method('send');
$this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Some emails were not sent.'))->willReturnSelf();
$this->catalogSessionMock->expects($this->once())->method('setSendfriendFormData')->with($formData);
$this->urlBuilderMock->expects($this->once())->method('getUrl')->with('sendfriend/product/send', ['_current' => true])->willReturn($redirectUrl);
$this->redirectMock->expects($this->once())->method('error')->with($redirectUrl)->willReturnArgument(0);
$redirectMock->expects($this->once())->method('setUrl')->with($redirectUrl)->willReturnSelf();
$this->assertEquals($redirectMock, $this->model->execute());
}
开发者ID:tingyeeh,项目名称:magento2,代码行数:38,代码来源:SendmailTest.php
示例7: getTreeArray
/**
* Get categories tree as recursive array
*
* @param int $parentId
* @param bool $asJson
* @param int $recursionLevel
* @return array
*/
public function getTreeArray($parentId = null, $asJson = false, $recursionLevel = 3)
{
$productId = $this->_request->getParam('product');
if ($productId) {
$product = $this->_productFactory->create()->setId($productId);
$this->_allowedCategoryIds = $product->getCategoryIds();
unset($product);
}
$result = [];
if ($parentId) {
try {
$category = $this->categoryRepository->get($parentId);
} catch (NoSuchEntityException $e) {
$category = null;
}
if ($category) {
$tree = $this->_getNodesArray($this->getNode($category, $recursionLevel));
if (!empty($tree) && !empty($tree['children'])) {
$result = $tree['children'];
}
}
} else {
$result = $this->_getNodesArray($this->getRoot(null, $recursionLevel));
}
if ($asJson) {
return $this->_jsonEncoder->encode($result);
}
$this->_allowedCategoryIds = [];
return $result;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:38,代码来源:Tree.php
示例8: testGetRssData
public function testGetRssData()
{
$category = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->setMethods(['__sleep', '__wakeup', 'load', 'getId', 'getUrl', 'getName'])->disableOriginalConstructor()->getMock();
$category->expects($this->once())->method('getName')->will($this->returnValue('Category Name'));
$category->expects($this->once())->method('getUrl')->will($this->returnValue('http://magento.com/category-name.html'));
$this->categoryRepository->expects($this->once())->method('get')->will($this->returnValue($category));
$product = $this->getMockBuilder('\\Magento\\catalog\\Model\\Product')->setMethods(['__sleep', '__wakeup', 'getName', 'getAllowedInRss', 'getProductUrl', 'getDescription', 'getAllowedPriceInRss'])->disableOriginalConstructor()->getMock();
$product->expects($this->once())->method('getName')->will($this->returnValue('Product Name'));
$product->expects($this->once())->method('getAllowedInRss')->will($this->returnValue(true));
$product->expects($this->exactly(2))->method('getProductUrl')->will($this->returnValue('http://magento.com/product.html'));
$product->expects($this->once())->method('getDescription')->will($this->returnValue('Product Description'));
$product->expects($this->once())->method('getAllowedPriceInRss')->will($this->returnValue(true));
$this->rssModel->expects($this->once())->method('getProductCollection')->will($this->returnValue([$product]));
$this->imageHelper->expects($this->once())->method('init')->with($product, 'thumbnail')->will($this->returnSelf());
$this->imageHelper->expects($this->once())->method('resize')->with(75, 75)->will($this->returnValue('image_link'));
$data = $this->block->getRssData();
$this->assertEquals($this->rssFeed['link'], $data['link']);
$this->assertEquals($this->rssFeed['title'], $data['title']);
$this->assertEquals($this->rssFeed['description'], $data['description']);
$this->assertEquals($this->rssFeed['entries'][0]['title'], $data['entries'][0]['title']);
$this->assertEquals($this->rssFeed['entries'][0]['link'], $data['entries'][0]['link']);
$this->assertContains('<a href="http://magento.com/product.html">', $data['entries'][0]['description']);
$this->assertContains('<img src="image_link" border="0" align="left" height="75" width="75">', $data['entries'][0]['description']);
$this->assertContains('<td style="text-decoration:none;">Product Description </td>', $data['entries'][0]['description']);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:25,代码来源:CategoryTest.php
示例9: initProduct
/**
* Initialize and check product
*
* @return \Magento\Catalog\Model\Product|bool
*/
protected function initProduct()
{
$this->_eventManager->dispatch('review_controller_product_init_before', ['controller_action' => $this]);
$categoryId = (int)$this->getRequest()->getParam('category', false);
$productId = (int)$this->getRequest()->getParam('id');
$product = $this->loadProduct($productId);
if (!$product) {
return false;
}
if ($categoryId) {
$category = $this->categoryRepository->get($categoryId);
$this->coreRegistry->register('current_category', $category);
}
try {
$this->_eventManager->dispatch('review_controller_product_init', ['product' => $product]);
$this->_eventManager->dispatch(
'review_controller_product_init_after',
['product' => $product, 'controller_action' => $this]
);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->logger->critical($e);
return false;
}
return $product;
}
开发者ID:nblair,项目名称:magescotch,代码行数:34,代码来源:Product.php
示例10: convertAttribute
/**
* Set current attribute to entry (for specified product)
*
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Framework\Gdata\Gshopping\Entry $entry
* @return \Magento\Framework\Gdata\Gshopping\Entry
*/
public function convertAttribute($product, $entry)
{
$productCategories = $product->getCategoryIds();
// TODO: set Default value for product_type attribute if product isn't assigned for any category
$value = 'Shop';
if (!empty($productCategories)) {
$category = $this->categoryRepository->get(array_shift($productCategories));
$breadcrumbs = [];
foreach ($category->getParentCategories() as $cat) {
$breadcrumbs[] = $cat->getName();
}
$value = implode(' > ', $breadcrumbs);
}
$this->_setAttribute($entry, 'product_type', self::ATTRIBUTE_TYPE_TEXT, $value);
return $entry;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:23,代码来源:ProductType.php
示例11: testGetUrlPathWithParent
/**
* @dataProvider getUrlPathWithParentDataProvider
* @param string $urlKey
* @param bool $isCategoryNew
* @param bool $level
* @param int $parentCategoryParentId
* @param string $parentUrlPath
* @param string $result
*/
public function testGetUrlPathWithParent(
$urlKey,
$isCategoryNew,
$level,
$parentCategoryParentId,
$parentUrlPath,
$result
) {
$urlPath = null;
$parentLevel = CategoryUrlPathGenerator::MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING - 1;
$this->category->expects($this->any())->method('getParentId')
->will($this->returnValue('parent_id'));
$this->category->expects($this->any())->method('getLevel')
->will($this->returnValue($level));
$this->category->expects($this->any())->method('getUrlPath')->will($this->returnValue($urlPath));
$this->category->expects($this->any())->method('getUrlKey')->will($this->returnValue($urlKey));
$this->category->expects($this->any())->method('isObjectNew')->will($this->returnValue($isCategoryNew));
$methods = ['__wakeup', 'getUrlPath', 'getParentId', 'getLevel', 'dataHasChangedFor', 'load'];
$parentCategory = $this->getMock('Magento\Catalog\Model\Category', $methods, [], '', false);
$parentCategory->expects($this->any())->method('getParentId')
->will($this->returnValue($parentCategoryParentId));
$parentCategory->expects($this->any())->method('getLevel')->will($this->returnValue($parentLevel));
$parentCategory->expects($this->any())->method('getUrlPath')->will($this->returnValue($parentUrlPath));
$parentCategory->expects($this->any())->method('dataHasChangedFor')
->will($this->returnValueMap([['url_key', false], ['path_ids', false]]));
$this->categoryRepository->expects($this->any())->method('get')->with('parent_id')
->will($this->returnValue($parentCategory));
$this->assertEquals($result, $this->categoryUrlPathGenerator->getUrlPath($this->category));
}
开发者ID:razbakov,项目名称:magento2,代码行数:41,代码来源:CategoryUrlPathGeneratorTest.php
示例12: getAssignedProducts
/**
* {@inheritdoc}
*/
public function getAssignedProducts($categoryId)
{
$category = $this->categoryRepository->get($categoryId);
$productsPosition = $category->getProductsPosition();
/** @var \Magento\Framework\Data\Collection\Db $products */
$products = $category->getProductCollection();
/** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface[] $links */
$links = [];
/** @var \Magento\Catalog\Model\Product $product */
foreach ($products->getItems() as $productId => $product) {
/** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface $link */
$link = $this->productLinkFactory->create();
$link->setSku($product->getSku())->setPosition($productsPosition[$productId])->setCategoryId($category->getId());
$links[] = $link;
}
return $links;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:20,代码来源:CategoryLinkManagement.php
示例13: getAssignedProducts
/**
* {@inheritdoc}
*/
public function getAssignedProducts($categoryId)
{
$category = $this->categoryRepository->get($categoryId);
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $products */
$products = $category->getProductCollection();
$products->addFieldToSelect('position');
/** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface[] $links */
$links = [];
/** @var \Magento\Catalog\Model\Product $product */
foreach ($products->getItems() as $product) {
/** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface $link */
$link = $this->productLinkFactory->create();
$link->setSku($product->getSku())->setPosition($product->getData('cat_index_position'))->setCategoryId($category->getId());
$links[] = $link;
}
return $links;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:20,代码来源:CategoryLinkManagement.php
示例14: testGenerationForGlobalScope
/**
* Test method
*/
public function testGenerationForGlobalScope()
{
$this->category->expects($this->any())->method('getStoreId')->will($this->returnValue(null));
$this->category->expects($this->any())->method('getStoreIds')->will($this->returnValue([1]));
$this->storeViewService->expects($this->once())->method('doesEntityHaveOverriddenUrlKeyForStore')->will($this->returnValue(false));
$canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite();
$canonical->setTargetPath('category-1')->setStoreId(1);
$this->canonicalUrlRewriteGenerator->expects($this->any())->method('generate')->will($this->returnValue([$canonical]));
$children = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite();
$children->setTargetPath('category-2')->setStoreId(2);
$this->childrenUrlRewriteGenerator->expects($this->any())->method('generate')->will($this->returnValue([$children]));
$current = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite();
$current->setTargetPath('category-3')->setStoreId(3);
$this->currentUrlRewritesRegenerator->expects($this->any())->method('generate')->will($this->returnValue([$current]));
$categoryForSpecificStore = $this->getMock('Magento\\Catalog\\Model\\Category', ['getUrlKey', 'getUrlPath'], [], '', false);
$this->categoryRepository->expects($this->once())->method('get')->willReturn($categoryForSpecificStore);
$this->assertEquals([$canonical, $children, $current], $this->categoryUrlRewriteGenerator->generate($this->category));
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:CategoryUrlRewriteGeneratorTest.php
示例15: setCategoryLandingPage
/**
* @param string $blockId
* @param string $categoryId
* @return void
*/
protected function setCategoryLandingPage($blockId, $categoryId)
{
$categoryCms = ['landing_page' => $blockId, 'display_mode' => 'PRODUCTS_AND_PAGE'];
if (!empty($categoryId)) {
$category = $this->categoryRepository->get($categoryId);
$category->setData($categoryCms);
$this->categoryRepository->save($categoryId);
}
}
开发者ID:chamalC,项目名称:Custom-Static-Blocks,代码行数:14,代码来源:Block.php
示例16: testGetCurrentCategoryIfCurrentCategoryIsNotSet
public function testGetCurrentCategoryIfCurrentCategoryIsNotSet()
{
$rootCategoryId = 333;
$this->currentCategory->getData('current_category', null);
$this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_category'))->willReturn(null);
$this->categoryRepository->expects($this->once())->method('get')->with($rootCategoryId)->willReturn($this->category);
$this->store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId));
$this->assertEquals($this->currentCategory, $this->model->getCurrentCategory());
$this->assertEquals($this->currentCategory, $this->model->getData('current_category'));
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:LayerTest.php
示例17: getUrlPath
/**
* Build category URL path
*
* @param \Magento\Catalog\Api\Data\CategoryInterface|\Magento\Framework\Model\AbstractModel $category
* @return string
*/
public function getUrlPath($category)
{
if ($category->getParentId() == Category::TREE_ROOT_ID) {
return '';
}
$path = $category->getUrlPath();
if ($path !== null && !$category->dataHasChangedFor('url_key') && !$category->dataHasChangedFor('parent_id')) {
return $path;
}
$path = $category->getUrlKey();
if ($path === false) {
return $category->getUrlPath();
}
if ($this->isNeedToGenerateUrlPathForParent($category)) {
$parentPath = $this->getUrlPath($this->categoryRepository->get($category->getParentId()));
$path = $parentPath === '' ? $path : $parentPath . '/' . $path;
}
return $path;
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:25,代码来源:CategoryUrlPathGenerator.php
示例18: testMoveWithCouldNotMoveException
/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage Could not move category
*/
public function testMoveWithCouldNotMoveException()
{
$categoryId = 2;
$parentId = 1;
$afterId = null;
$categoryMock = $this->getMock('\\Magento\\Catalog\\Model\\Category', [], [], 'categoryMock', false);
$parentCategoryMock = $this->getMock('\\Magento\\Catalog\\Model\\Category', [], [], 'parentCategoryMock', false);
$this->categoryRepositoryMock->expects($this->exactly(2))->method('get')->will($this->returnValueMap([[$categoryId, null, $categoryMock], [$parentId, null, $parentCategoryMock]]));
$categoryMock->expects($this->once())->method('move')->with($parentId, $afterId)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
$this->model->move($categoryId, $parentId, $afterId);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:CategoryManagementTest.php
示例19: initProduct
/**
* Inits product to be used for product controller actions and layouts
* $params can have following data:
* 'category_id' - id of category to check and append to product as current.
* If empty (except FALSE) - will be guessed (e.g. from last visited) to load as current.
*
* @param int $productId
* @param \Magento\Framework\App\Action\Action $controller
* @param \Magento\Framework\DataObject $params
*
* @return false|ModelProduct
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function initProduct($productId, $controller, $params = null)
{
// Prepare data for routine
if (!$params) {
$params = new \Magento\Framework\DataObject();
}
// Init and load product
$this->_eventManager->dispatch('catalog_controller_product_init_before', ['controller_action' => $controller, 'params' => $params]);
if (!$productId) {
return false;
}
try {
$product = $this->productRepository->getById($productId, false, $this->_storeManager->getStore()->getId());
} catch (NoSuchEntityException $e) {
return false;
}
if (!$this->canShow($product)) {
return false;
}
if (!in_array($this->_storeManager->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
return false;
}
// Load product current category
$categoryId = $params->getCategoryId();
if (!$categoryId && $categoryId !== false) {
$lastId = $this->_catalogSession->getLastVisitedCategoryId();
if ($product->canBeShowInCategory($lastId)) {
$categoryId = $lastId;
}
} elseif (!$product->canBeShowInCategory($categoryId)) {
$categoryId = null;
}
if ($categoryId) {
try {
$category = $this->categoryRepository->get($categoryId);
} catch (NoSuchEntityException $e) {
$category = null;
}
if ($category) {
$product->setCategory($category);
$this->_coreRegistry->register('current_category', $category);
}
}
// Register current data and dispatch final events
$this->_coreRegistry->register('current_product', $product);
$this->_coreRegistry->register('product', $product);
try {
$this->_eventManager->dispatch('catalog_controller_product_init_after', ['product' => $product, 'controller_action' => $controller]);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->_logger->critical($e);
return false;
}
return $product;
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:68,代码来源:Product.php
示例20: reindex
/**
* Refresh entities index
*
* @param int[] $entityIds
* @param bool $useTempTable
* @return Rows
*/
public function reindex(array $entityIds = [], $useTempTable = false)
{
$stores = $this->storeManager->getStores();
/* @var $store \Magento\Store\Model\Store */
foreach ($stores as $store) {
$tableName = $this->getTableNameByStore($store, $useTempTable);
if (!$this->getWriteAdapter()->isTableExists($tableName)) {
continue;
}
/** @TODO Do something with chunks */
$categoriesIdsChunks = array_chunk($entityIds, 500);
foreach ($categoriesIdsChunks as $categoriesIdsChunk) {
$categoriesIdsChunk = $this->filterIdsByStore($categoriesIdsChunk, $store);
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
$data = [];
foreach ($categoriesIdsChunk as $categoryId) {
if (!isset($attributesData[$categoryId])) {
continue;
}
try {
$category = $this->categoryRepository->get($categoryId);
} catch (NoSuchEntityException $e) {
continue;
}
$data[] = $this->prepareValuesToInsert(array_merge($category->getData(), $attributesData[$categoryId], ['store_id' => $store->getId()]));
}
foreach ($data as $row) {
$updateFields = [];
foreach (array_keys($row) as $key) {
$updateFields[$key] = $key;
}
$this->getWriteAdapter()->insertOnDuplicate($tableName, $row, $updateFields);
}
}
$this->deleteNonStoreCategories($store, $useTempTable);
}
return $this;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:45,代码来源:Rows.php
注:本文中的Magento\Catalog\Api\CategoryRepositoryInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论