当前位置: 首页>>代码示例>>PHP>>正文


PHP Category::setData方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Category::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::setData方法的具体用法?PHP Category::setData怎么用?PHP Category::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Category的用法示例。


在下文中一共展示了Category::setData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testGetCustomAttributes

 public function testGetCustomAttributes()
 {
     $nameAttributeCode = 'name';
     $descriptionAttributeCode = 'description';
     $interfaceAttribute = $this->getMock('\\Magento\\Framework\\Api\\MetadataObjectInterface');
     $interfaceAttribute->expects($this->once())->method('getAttributeCode')->willReturn($nameAttributeCode);
     $descriptionAttribute = $this->getMock('\\Magento\\Framework\\Api\\MetadataObjectInterface');
     $descriptionAttribute->expects($this->once())->method('getAttributeCode')->willReturn($descriptionAttributeCode);
     $customAttributesMetadata = [$interfaceAttribute, $descriptionAttribute];
     $this->metadataServiceMock->expects($this->once())->method('getCustomAttributesMetadata')->willReturn($customAttributesMetadata);
     $this->category->setData($nameAttributeCode, "sub");
     //The color attribute is not set, expect empty custom attribute array
     $this->assertEquals([], $this->category->getCustomAttributes());
     //Set the color attribute;
     $this->category->setData($descriptionAttributeCode, "description");
     $attributeValue = new \Magento\Framework\Api\AttributeValue();
     $attributeValue2 = new \Magento\Framework\Api\AttributeValue();
     $this->attributeValueFactory->expects($this->exactly(2))->method('create')->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2);
     $this->assertEquals(1, count($this->category->getCustomAttributes()));
     $this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode));
     $this->assertEquals("description", $this->category->getCustomAttribute($descriptionAttributeCode)->getValue());
     //Change the attribute value, should reflect in getCustomAttribute
     $this->category->setData($descriptionAttributeCode, "new description");
     $this->assertEquals(1, count($this->category->getCustomAttributes()));
     $this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode));
     $this->assertEquals("new description", $this->category->getCustomAttribute($descriptionAttributeCode)->getValue());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:27,代码来源:CategoryTest.php

示例2: 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;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Navigation.php

示例3: testReindexFlatDisabled

 /**
  * @param $productScheduled
  * @param $expectedProductReindexCall
  *
  * @dataProvider reindexFlatDisabledTestDataProvider
  */
 public function testReindexFlatDisabled($productScheduled, $expectedProductReindexCall)
 {
     $affectedProductIds = ["1", "2"];
     $this->category->setAffectedProductIds($affectedProductIds);
     $pathIds = ['path/1/2', 'path/2/3'];
     $this->category->setData('path_ids', $pathIds);
     $this->category->setId('123');
     $this->flatState->expects($this->any())->method('isFlatEnabled')->will($this->returnValue(false));
     $this->productIndexer->expects($this->exactly(1))->method('isScheduled')->will($this->returnValue($productScheduled));
     $this->productIndexer->expects($this->exactly($expectedProductReindexCall))->method('reindexList')->with($pathIds);
     $this->indexerRegistry->expects($this->at(0))->method('get')->with(Indexer\Category\Product::INDEXER_ID)->will($this->returnValue($this->productIndexer));
     $this->category->reindex();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:CategoryTest.php

示例4: 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');
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:29,代码来源:CategoryRepository.php

示例5: testGetLevel

 public function testGetLevel()
 {
     $this->assertEquals(0, $this->_model->getLevel());
     $this->_model->setData('level', 1);
     $this->assertEquals(1, $this->_model->getLevel());
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:6,代码来源:CategoryTreeTest.php

示例6: testGetAvailableSortBy

 public function testGetAvailableSortBy()
 {
     $this->assertEquals([], $this->_model->getAvailableSortBy());
     $this->_model->setData('available_sort_by', 'test,and,test');
     $this->assertEquals(['test', 'and', 'test'], $this->_model->getAvailableSortBy());
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:6,代码来源:CategoryTest.php

示例7: setData

 /**
  * {@inheritdoc}
  */
 public function setData($key, $value = null)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'setData');
     if (!$pluginInfo) {
         return parent::setData($key, $value);
     } else {
         return $this->___callPlugins('setData', func_get_args(), $pluginInfo);
     }
 }
开发者ID:HaonanXu,项目名称:der-snack-backup,代码行数:12,代码来源:Interceptor.php

示例8: _addCategoryUrlPath

 /**
  * Adds url_path property for non-root category - to ensure that url path is not empty.
  *
  * Sometimes attribute 'url_path' can be empty, because url_path hasn't been generated yet,
  * in this case category is loaded with empty url_path and we should generate it manually.
  *
  * @param \Magento\Framework\Object $category
  * @return void
  */
 protected function _addCategoryUrlPath($category)
 {
     if (!$category instanceof \Magento\Framework\Object || $category->getUrlPath()) {
         return;
     }
     // This routine is not intended to be used with root categories,
     // but handle 'em gracefully - ensure them to have empty path.
     if ($category->getLevel() <= 1) {
         $category->setUrlPath('');
         return;
     }
     if (self::$_categoryForUrlPath === null) {
         self::$_categoryForUrlPath = $this->_categoryFactory->create();
     }
     // Generate url_path
     $urlPath = self::$_categoryForUrlPath->setData($category->getData())->getUrlPath();
     $category->setUrlPath($urlPath);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:27,代码来源:Url.php


注:本文中的Magento\Catalog\Model\Category::setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。