本文整理汇总了PHP中Magento\Catalog\Model\Category::getData方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::getData方法的具体用法?PHP Category::getData怎么用?PHP Category::getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Category
的用法示例。
在下文中一共展示了Category::getData方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateForAutogenerated
/**
* @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $url
* @param int $storeId
* @return array
*/
protected function generateForAutogenerated($url, $storeId)
{
$urls = [];
if ($this->category->getData('save_rewrites_history')) {
$targetPath = $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(OptionProvider::PERMANENT)->setStoreId($storeId)->setIsAutogenerated(0);
}
}
return $urls;
}
示例2: 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'));
}
示例3: generateRewritesBasedOnCurrentRewrites
/**
* Generate permanent rewrites based on current rewrites
*
* @param int $storeId
* @return array
*/
protected function generateRewritesBasedOnCurrentRewrites($storeId)
{
$urls = [];
foreach ($this->urlMatcher->findAllByFilter($this->createCurrentUrlRewritesFilter($storeId)) as $url) {
$targetPath = null;
if ($url->getRedirectType()) {
$targetPath = str_replace($this->category->getOrigData('url_key'), $this->category->getData('url_key'), $url->getTargetPath());
$redirectType = $url->getRedirectType();
} elseif ($this->category->getData('save_rewrites_history')) {
$targetPath = str_replace($this->category->getOrigData('url_key'), $this->category->getData('url_key'), $url->getRequestPath());
$redirectType = OptionProvider::PERMANENT;
}
if ($targetPath && $url->getRequestPath() != $targetPath) {
$urls[] = $this->createUrlRewrite($storeId, $url->getRequestPath(), $targetPath, $redirectType);
}
}
return $urls;
}
示例4: generateProductUrlRewrites
/**
* Generate url rewrites for products assigned to category
*
* @param Category $category
* @return array
*/
public function generateProductUrlRewrites(Category $category)
{
$this->isSkippedProduct = [];
$saveRewriteHistory = $category->getData('save_rewrites_history');
$storeId = $category->getStoreId();
$productUrls = [];
if ($category->getAffectedProductIds()) {
$this->isSkippedProduct = $category->getAffectedProductIds();
$collection = $this->productCollectionFactory->create()->setStoreId($storeId)->addIdFilter($category->getAffectedProductIds())->addAttributeToSelect('name')->addAttributeToSelect('url_key')->addAttributeToSelect('url_path');
foreach ($collection as $product) {
$product->setStoreId($storeId);
$product->setData('save_rewrites_history', $saveRewriteHistory);
$productUrls = array_merge($productUrls, $this->productUrlRewriteGenerator->generate($product));
}
} else {
$productUrls = array_merge($productUrls, $this->getCategoryProductsUrlRewrites($category, $storeId, $saveRewriteHistory));
}
foreach ($this->childrenCategoriesProvider->getChildren($category, true) as $childCategory) {
$productUrls = array_merge($productUrls, $this->getCategoryProductsUrlRewrites($childCategory, $storeId, $saveRewriteHistory));
}
return $productUrls;
}
示例5: getCategoryUrl
/**
* Retrieve category url
*
* @param ModelCategory $category
* @return string
*/
public function getCategoryUrl($category)
{
if ($category instanceof ModelCategory) {
return $category->getUrl();
}
return $this->_categoryFactory->create()->setData($category->getData())->getUrl();
}
示例6: validateCategory
/**
* Validate category process
*
* @param Category $category
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function validateCategory(Category $category)
{
$useConfigFields = [];
foreach ($this->useConfigFields as $field) {
if (!$category->getData($field)) {
$useConfigFields[] = $field;
}
}
$category->setData('use_post_data_config', $useConfigFields);
$validate = $category->validate();
if ($validate !== true) {
foreach ($validate as $code => $error) {
if ($error === true) {
$attribute = $this->categoryResource->getAttribute($code)->getFrontend()->getLabel();
throw new \Magento\Framework\Exception\LocalizedException(__('Attribute "%1" is required.', $attribute));
} else {
throw new \Magento\Framework\Exception\LocalizedException(__($error));
}
}
}
$category->unsetData('use_post_data_config');
}
示例7: getObject
public function getObject(Category $category)
{
/** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
$productCollection = $category->getProductCollection();
$productCollection = $productCollection->addMinimalPrice();
$category->setProductCount($productCollection->getSize());
$transport = new DataObject();
$this->eventManager->dispatch('algolia_category_index_before', ['category' => $category, 'custom_data' => $transport]);
$customData = $transport->getData();
$storeId = $category->getStoreId();
$category->getUrlInstance()->setStore($storeId);
$path = '';
foreach ($category->getPathIds() as $categoryId) {
if ($path != '') {
$path .= ' / ';
}
$path .= $this->getCategoryName($categoryId, $storeId);
}
$image_url = null;
try {
$image_url = $category->getImageUrl();
} catch (\Exception $e) {
/* no image, no default: not fatal */
}
$data = ['objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => $category->getUrl(), 'include_in_menu' => $category->getIncludeInMenu(), '_tags' => ['category'], 'popularity' => 1, 'product_count' => $category->getProductCount()];
if (!empty($image_url)) {
$data['image_url'] = $image_url;
}
foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) {
$value = $category->getData($attribute['attribute']);
$attribute_resource = $category->getResource()->getAttribute($attribute['attribute']);
if ($attribute_resource) {
$value = $attribute_resource->getFrontend()->getValue($category);
}
if (isset($data[$attribute['attribute']])) {
$value = $data[$attribute['attribute']];
}
if ($value) {
$data[$attribute['attribute']] = $value;
}
}
$data = array_merge($data, $customData);
foreach ($data as &$data0) {
$data0 = $this->try_cast($data0);
}
return $data;
}
示例8: getCategoryUrl
/**
* Get url for category data
*
* @param Category $category
* @return string
*/
public function getCategoryUrl($category)
{
if ($category instanceof Category) {
$url = $category->getUrl();
} else {
$url = $this->_categoryInstance->setData($category->getData())->getUrl();
}
return $url;
}
示例9: checkCategoryData
/**
* Check EAV and flat data
*
* @param \Magento\Catalog\Model\Category $category
*/
protected function checkCategoryData(\Magento\Catalog\Model\Category $category)
{
foreach (self::$attributeCodes as $attributeCode) {
$this->assertEquals(self::$attributeValues[$category->getId()][$attributeCode], $category->getData($attributeCode), "Data for {$category->getId()} attribute code [{$attributeCode}] is wrong");
}
}
示例10: createDataFromModel
/**
* @param Category $category
* @return Metadata
*/
public function createDataFromModel(Category $category)
{
$builder = $this->builder->populateWithArray($category->getData())->setCategoryId($category->getId())->setActive($category->getIsActive())->setChildren($category->getAllChildren(true));
return $builder->create();
}
示例11: getData
/**
* {@inheritdoc}
*/
public function getData($key = '', $index = null)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getData');
if (!$pluginInfo) {
return parent::getData($key, $index);
} else {
return $this->___callPlugins('getData', func_get_args(), $pluginInfo);
}
}