作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在模块的安装脚本中为一个类别创建了自定义属性,如下所示:
$attrib = array(
'type' => 'varchar',
'group' => 'My Data',
'backend' => '',
'frontend' => '',
'label' => 'My Custom Field',
'input' => 'text',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => true,
);
$installer->addAttribute(3, 'custom_field', $attrib);
$p_category = Mage::getModel('catalog/category')
->setStoreId(0)
->load(2);
$category = Mage::getModel('catalog/category');
$category->setStoreId(0)
->setName('Test Category')
->setCustomField('abcd')
->setDisplayMode('PRODUCTS')
->setAttributeSetId($category->getDefaultAttributeSetId())
->setIsActive(1)
->setIsAnchor(1)
->setPath(implode('/',$p_category->getPathIds()))
->setInitialSetupFlag(true)
->save();
<?php
$category = Mage::getModel('catalog/category')->loadByAttribute('custom_field', 'abcd');
print_r($category);
?>
catalog_category_entity_varchar
表并注意到“name”属性有一个 store_id = 0 和 store_id = 1 的条目,而“custom_field”属性只有一个 store_id = 1 的条目。
catalog_category_entity_varchar
中为“custom_field”添加了一个 store_id = 0 条目并将值设置为“abcd”时表,loadByAttribute 得到了预期的结果。
catalog_category_entity_varchar
中获得 store_id = 0 条目?而我的自定义字段不是?
最佳答案
如果您将以下键更改为 global 那么它应该为两个商店添加它
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
关于Magento loadByAttribute 用于自定义类别属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2886123/
我在模块的安装脚本中为一个类别创建了自定义属性,如下所示: $attrib = array( 'type' => 'varchar', 'group'
今天我再次与 Magento 战斗:)并且我发现了 $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $prod
我是一名优秀的程序员,十分优秀!