- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
寻找一种方法将描述字段添加到 Magento 中的单个属性值。请注意,我指的是属性值选项,而不是实际的属性本身。
举个例子:
属性=颜色
属性值:红、绿、蓝
我想为 3 种颜色中的每一种添加一个描述字段(1 表示红色,1 表示绿色,1 表示蓝色)。这样做的目的是在前端显示工具提示,以提供有关每个颜色选项的更多信息。
有人知道该怎么做吗?有很多解决方案适用于属性本身(颜色),但不适用于单个选项(红色、绿色、蓝色)。
描述应该可以在管理面板中编辑。我不想要依赖于使用 phpMyAdmin 等直接在数据库中编辑这些内容的解决方案。
据我了解,这些值存储在“eav_attribute_option_value”表中,并且可能需要进一步的列来存储说明。不知道如何在管理面板中进行所有设置。有想法吗?
编辑:我添加了需要添加描述文本的屏幕截图。因此,在每种颜色旁边(在屏幕截图上:黑色、蓝色、绿色、灰色、红色、白色等)-每种颜色旁边都需要有一个描述。
最佳答案
这可能已经过时了 11 个月,但对于遇到此问题的其他人来说,也许这可以帮助您。我希望它能让你免于像我和我的同事那样头撞墙。出于我的目的,我尝试为 Magento 1.9 版创建一个图像 URL 字段,以支持从旧平台的产品迁移。
这个答案已经在这里得到了部分回答 - Creating new options for Magento attributes但还有一些额外的事情我必须弄清楚:
1.) 这个答案假设您已经创建了自己的模块(如果您不知道如何创建,请从这里开始:http://www.smashingmagazine.com/2012/03/01/basics-creating-magento-module/)
2.) 您还可以自己在 catalog/product/attribute/options.phtml 中创建额外的字段。但为了节省您的时间,我做了一些修改,让它出现在管理员中。在第 88 行创建一个新的表头选项:
<th><?php echo Mage::helper('catalog')->__('YOUR_ATTRIBUTE_NAME_HERE') ?></th>
接下来在第101行创建一个新的td:
<td class="a-left"><input class="input-text" type="text" name="option[YOUR_ATTRIBUTE_NAME_HERE][{{id}}]" value="{{TABLE_COLUMN_NAME_HERE}}" <?php if ($this->getReadOnly()):?> disabled="disabled"<?php endif;?>/></td>
而且,大部分逻辑都是在 Javascript 中完成的,因此我们需要在 126 行复制该字段:
'<td><input class="input-text" type="text" name="option[YOUR_ATTRIBUTE_NAME_HERE][{{id}}]" value="{{TABLE_COLUMN_NAME_HERE}}" <?php if ($this->getReadOnly()):?> disabled="disabled"<?php endif;?>/><\/td>'+
3.) 对我来说最长的部分是为 _saveOption 方法创建自定义逻辑。我重写了父类,但为了省去你的麻烦,这是我的逻辑:
protected function _saveOption(Mage_Core_Model_Abstract $object)
{
$option = $object->getOption();
if (is_array($option)) {
$adapter = $this->_getWriteAdapter();
$optionTable = $this->getTable('eav/attribute_option');
$optionValueTable = $this->getTable('eav/attribute_option_value');
$stores = Mage::app()->getStores(true);
if (isset($option['value'])) {
$attributeDefaultValue = array();
if (!is_array($object->getDefault())) {
$object->setDefault(array());
}
foreach ($option['value'] as $optionId => $values) {
$intOptionId = (int) $optionId;
if (!empty($option['delete'][$optionId])) {
if ($intOptionId) {
$adapter->delete($optionTable, array('option_id = ?' => $intOptionId));
}
continue;
}
$sortOrder = !empty($option['order'][$optionId]) ? $option['order'][$optionId] : 0;
$imgUrl = !empty($option['image_url'][$optionId]) ? $option['image_url'][$optionId] : 0;
if (!$intOptionId) {
$data = array(
'attribute_id' => $object->getId(),
'sort_order' => $sortOrder,
'image_url' => $imgUrl
);
$adapter->insert($optionTable, $data);
$intOptionId = $adapter->lastInsertId($optionTable);
} else {
$data = array('sort_order' => $sortOrder, 'image_url' => $imgUrl);
$where = array('option_id =?' => $intOptionId);
$adapter->update($optionTable, $data, $where);
}
if (in_array($optionId, $object->getDefault())) {
if ($object->getFrontendInput() == 'multiselect') {
$attributeDefaultValue[] = $intOptionId;
} elseif ($object->getFrontendInput() == 'select') {
$attributeDefaultValue = array($intOptionId);
}
}
// Default value
if (!isset($values[0])) {
Mage::throwException(Mage::helper('eav')->__('Default option value is not defined'));
}
$adapter->delete($optionValueTable, array('option_id =?' => $intOptionId));
foreach ($stores as $store) {
if (isset($values[$store->getId()])
&& (!empty($values[$store->getId()])
|| $values[$store->getId()] == "0")
) {
$data = array(
'option_id' => $intOptionId,
'store_id' => $store->getId(),
'value' => $values[$store->getId()]
);
$adapter->insert($optionValueTable, $data);
}
}
}
$bind = array('default_value' => implode(',', $attributeDefaultValue));
$where = array('attribute_id =?' => $object->getId());
$adapter->update($this->getMainTable(), $bind, $where);
}
}
return $this;
}
我的自定义字段名为 image_url,因此我将其添加到要插入的 $data 变量中。这会将值插入到 eav_attribute_option 表的“image_url”列中,但您可以使用相同的方法将其存储在 eav_attribute_option_value 中。
4.) 由于某种原因,堆栈溢出帖子指出此 _saveOption 方法将在保存时触发,但我的方法没有,因此我还覆盖了 _afterSave 方法同一个类,如下所示:
protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$this->_clearUselessAttributeValues($object);
$this->_saveStoreLabels($object)
->_saveAdditionalAttributeData($object)
->saveInSetIncluding($object)
->_saveOption($object);
return $this;
}
5.) 现在它将尝试保存您的新值。但这会导致错误,因为您的自定义表列很可能还不存在。如果适合您,欢迎您手动创建。不幸的是,我需要根据我的情况以编程方式创建这个,所以对于那些在同一条船上的人(这是一个有点不干净的方法),但为了速度,我重新路由了 app/code/core/Mage/Core/Model/Resource/Setup.php 通过在此处创建本地修订版: app/code/local/Mage/Core/Model/Resource/Setup.php 并将其添加到第 154 行在构造函数类中:
$installer = $this;
$installer->getConnection()->addColumn($installer->getTable('eav/attribute_option'), 'YOUR_COLUMN_NAME_HERE', 'VARCHAR(256) NULL');
$installer->endSetup();
6.) 好的,现在所有内容都应该保存到数据库中,但我们仍然需要将值读入 - 这让我困惑了一段时间,但我发现Javascript 负责替换 230 行 HTML 中的 {{id}} 和 {{sort_order}} 标记。因此,我们需要将新列添加到此 getOptionsValues() 方法中。我在catalog/product/attribute/options.phtml的第70行添加了以下代码:
<?php foreach ($this->getOptionValues() as &$val) {
$imgUrl = $this->getImageUrl($val->id);
if ($imgUrl != "0") {
$val->_data["YOUR_TABLE_COLUMN_NAME_HERE"] = $imgUrl;
}
} ?>
然后,在您的 YOUR_MODULE_Block_Adminhtml_Options 类中添加上面调用的方法 getImageUrl():
/**
* Retrieve results from custom column
*
* @return Mage_Core_Model_Mysql4_Store_Collection
*/
public function getImageUrl($option_id)
{
//Get the resource model
$resource = Mage::getSingleton('core/resource');
//Retrieve the read connection
$readConnection = $resource->getConnection('core_read');
//Retrieve our table name
$table = $resource->getTableName('eav/attribute_option');
$query = 'SELECT ' . $this->custom_col . ' FROM ' . $table . ' WHERE option_id = '
. (int)$option_id . ' LIMIT 1';
//Execute the query and store the result
$imgUrl = $readConnection->fetchOne($query);
return $imgUrl;
}
这就是你想要的。我真的希望这对遇到类似情况的人有所帮助。
关于Magento 属性值 - 添加描述字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23652358/
Magento 主题和 Magento 皮肤有什么区别?它们和 Magento 模块之间有什么关系? 最佳答案 主题是创建视觉体验的布局、模板、区域设置和/或外观文件的任意组合... 主题由以下任意或
我想在 Magento 之外获得购物车 Block。这是我的代码。 getLocale()->getLocaleCode(); //Solution Mage::getSingleto
我是 Magento 新手,使用 CE 1.7.0.2 开发了一个网站。现在可以上线了,但我遇到了页面加载缓慢的问题。 我的网站产品主页、列表和详细信息页面最初需要 10-13 秒的时间来加载页面,但
我在 magento 网站上工作。我有 4 个类别,其中两个使用其他主题(不是我的特定 magento 主题)。我如何配置我的主题以从我的默认主题而不是基本主题中获取丢失的文件。 谢谢 最佳答案 通常
我遇到了我的 magento 项目的要求,因此我需要为特定客户群的购买提供特别折扣。此折扣必须显示在客户帐户中,如果他们属于该特定组,并且当用户要使用该特定折扣时,必须根据该折扣优惠对该商品的价格进行
我在 Magento 主题开发中找到的大量教程建议从使用空白作为制作您自己的自定义主题的指南开始。很多这些文章已经很旧了,截至当前版本(1.7),情况仍然如此吗? 附言- 除了 Magento 的 o
似乎这应该是一个可以找到的问题,但我找不到它。 magento 数据库中存储的类别 NAME 在哪里?我可以看到 catalog_category_entity有 key ID,然后还有其他 EAV
我知道 magento 会根据需要调整原始产品图像的大小并以不同的大小对其进行多次缓存。 这些 chached 图像存储在哪里(路径)? 当您从缓存管理中刷新图像缓存时,它们会被删除吗? 如果我要手动
我在我的 magento 网上商店中使用这个扩展 http://www.manadev.com/seo-layered-navigation-plus (分层导航) 此扩展适用于简单的产品。 但就我而
我在 Magento 的一家商店下拥有某些产品的批发属性。我想设置它,以便这些特定属性仅出现在产品页面上,如果客户已登录并且他们在批发客户组中。 这可能吗? 最佳答案 像这样的事情应该可以工作,尽管我
和有什么区别和 在 Magento 中? 我将创建一个新模块,我必须决定在这两个事件中的哪一个事件中挂起我的观察者。 最佳答案 类别(和所有其他对象)保存在事务中。事件catalog_categor
好吧,这是一个似乎很容易解决的问题,但它让我望而却步...... 我的 Magento Web 上有一些类别,每个类别都有一些产品。我希望它们显示为 4 列计数,但它始终显示为 3 列计数,如下所示:
我已经在我的网站上添加了一些成员(member)跟踪代码。为了使跟踪工作正常进行,我需要向关联公司提供确认付款的网址。 我正在使用Magento,我不确定该版本,但几年内未对其进行更新。我需要知道订单
我们的网站遇到了问题。 系统 > 配置屏幕仅显示菜单、侧面菜单和页脚。当我们点击侧边菜单选项时,屏幕仍然黑屏,相关信息也没有出现。请看 this link .这就是出现的情况。当我们点击任何侧面菜单选
我想只使用一个 csv 文件来翻译前端 Magento 商店。所以我这样做了: 我创建了一个名为 Translator 的自定义模块。在其 config.xml 中,我放置了以下几行: ....
我添加了自定义订单状态选项。 有谁知道我如何通过API将其设置为自定义值? 最佳答案 感谢Diglin为我指出的正确位置。只是为了正确地给出答案: 您可以使用addComment方法来执行此操作,该方
目前,Magento 处理大规模操作的方式存在问题。无论分页如何,它都会返回一些 JS,其中包含当前集合和过滤器的每个 db id。这是为了支持网格标题中的“全选”与“全选可见”选项。当您的记录数量较
如何收集具有此角色的所有角色(系统->权限->角色)和用户? 谢谢。 最佳答案 获得所有角色 $roles = Mage::getModel('admin/roles')->getCol
如果能在我网站的各种应用程序之间进行通用登录,那将是一种巨大的用户体验。现在,我有一个 Magento 店面和一个 IPS 板社区。我正在尝试将它们集成到我的用户的一个通用登录中。 IPS 板提供多种
我正在为 Magento 社区 1.4.2 版中的时尚客户开发一个网站,作为该项目的一部分,我需要一些定制的主页促销块来展示特定产品或产品类别。为此,我想我会编写自己的小部件,并且除了如何处理图像外,
我是一名优秀的程序员,十分优秀!