- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在网上做了一些搜索,但还没有找到这个问题的任何答案。我遇到一种情况,我需要一个十进制值的产品属性,它必须支持负数和正数,并且还必须可排序。由于某种原因,Magento 没有“十进制”属性类型。唯一使用小数值的类型是 Price,但不支持负数。如果我使用“文本”作为类型,它支持我想要的任何内容,但它无法正确排序,因为它将值视为字符串而不是 float 。我已经能够解决这个问题,正如其他人在我发现的帖子中所做的那样,通过手动编辑 eav_attribute 表并将“frontend_input”从“price”更改为“text”,但将“backend_type”保留为“decimal” 。这非常有效...直到有人在管理面板中编辑该属性。保存属性后,Magento 会注意到 frontend_input 是“text”,并将“backend_type”更改为“varchar”。我能想到的解决此问题的唯一方法是创建自定义属性类型,但我不确定从哪里开始,也无法在网上找到任何详细信息。
还有其他人遇到过这个问题吗?如果是这样,您采取了什么措施来纠正它?如果我需要创建自定义属性类型,您有任何提示吗?或者您能给我指出执行此操作的任何教程吗?
谢谢!
最佳答案
您想要做的是创建自定义属性类型。
这可以通过首先创建安装程序脚本来完成(这会更新数据库)。
startSetup();
$installer->addAttribute('catalog_product', 'product_type', array(
'group' => 'Product Options',
'label' => 'Product Type',
'note' => '',
'type' => 'dec', //backend_type
'input' => 'select', //frontend_input
'frontend_class' => '',
'source' => 'sourcetype/attribute_source_type',
'backend' => '',
'frontend' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
'required' => true,
'visible_on_front' => false,
'apply_to' => 'simple',
'is_configurable' => false,
'used_in_product_listing' => false,
'sort_order' => 5,
));
$installer->endSetup();
之后,您需要创建一个名为:的自定义 php 类:
Whatever_Sourcetype_Model_Attribute_Source_Type
然后将其粘贴到:
class Whatever_Sourcetype_Model_Attribute_Source_Type extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
const MAIN = 1;
const OTHER = 2;
public function getAllOptions()
{
if (is_null($this->_options)) {
$this->_options = array(
array(
'label' => Mage::helper('sourcetype')->__('Main Product'),
'value' => self::MAIN
),
array(
'label' => Mage::helper('sourcetype')->__('Other Product'),
'value' => self::OTHER
),
);
}
return $this->_options;
}
public function toOptionArray()
{
return $this->getAllOptions();
}
public function addValueSortToCollection($collection, $dir = 'asc')
{
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
$valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1';
$valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2';
$collection->getSelect()->joinLeft(
array($valueTable1 => $this->getAttribute()->getBackend()->getTable()),
"`e`.`entity_id`=`{$valueTable1}`.`entity_id`"
. " AND `{$valueTable1}`.`attribute_id`='{$this->getAttribute()->getId()}'"
. " AND `{$valueTable1}`.`store_id`='{$adminStore}'",
array()
);
if ($collection->getStoreId() != $adminStore) {
$collection->getSelect()->joinLeft(
array($valueTable2 => $this->getAttribute()->getBackend()->getTable()),
"`e`.`entity_id`=`{$valueTable2}`.`entity_id`"
. " AND `{$valueTable2}`.`attribute_id`='{$this->getAttribute()->getId()}'"
. " AND `{$valueTable2}`.`store_id`='{$collection->getStoreId()}'",
array()
);
$valueExpr = new Zend_Db_Expr("IF(`{$valueTable2}`.`value_id`>0, `{$valueTable2}`.`value`, `{$valueTable1}`.`value`)");
} else {
$valueExpr = new Zend_Db_Expr("`{$valueTable1}`.`value`");
}
$collection->getSelect()
->order($valueExpr, $dir);
return $this;
}
public function getFlatColums()
{
$columns = array(
$this->getAttribute()->getAttributeCode() => array(
'type' => 'int',
'unsigned' => false,
'is_null' => true,
'default' => null,
'extra' => null
)
);
return $columns;
}
public function getFlatUpdateSelect($store)
{
return Mage::getResourceModel('eav/entity_attribute')
->getFlatUpdateSelect($this->getAttribute(), $store);
}
}
希望这有帮助。
有关更多信息,请参阅 here.
关于Magento - 如何创建 "decimal"属性类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12043457/
我是 Python 编程的新手,最近我一直在学习数据类型的某些方面。正如我所读,decimal.Decimal() 方法创建了一个小数对象; decimal.Decimal.from_float()
这是我今天在 filmmaster.com: 遇到的错误 PicklingError: Can't pickle : it's not the same object as decimal.Decim
简单的问题 - 为什么 Decimal 类型定义这些常量?何必呢? 我正在寻找一个原因,为什么这是由语言定义的,而不是可能的用途或对编译器的影响。为什么首先把它放在那里?编译器可以像 Decimal.
我在用 Python 编码为 JSON 时遇到问题,特别是 decimal.Decimal 值。我正在使用它为 Google App Engine 应用程序输出 JSON。 为了避免 Python 中
我在 Django 项目中有一些 python 代码曾经可以正常工作。托管该项目的服务器丢失了,我不得不将代码复制到新服务器上。现在,我收到一个似乎毫无意义的错误。 我的一个 python 文件中包含
我发现生成具有特定数量 的 decimal.Decimal 数字的最佳方法 significant figures 是用来初始化下面的变量 kluge 的: import decimal THIS_I
我在应用空合并运算符时遇到以下错误。 private decimal _currentImpulseId; // ... later on used in public property getter
我想使用 decimal.Decimal 对转换后的数字字符串进行算术运算。无论转换后的数字字符串有多少小数,我都希望返回有两位小数。 在这种特殊情况下,为什么两位小数精度返回一位小数,为什么三位小数
我想使用 decimal.Decimal 对转换后的数字字符串进行算术运算。无论转换后的数字字符串有多少小数,我都希望返回有两位小数。 在这种特殊情况下,为什么两位小数精度返回一位小数,为什么三位小数
是什么导致 sum 始终为 null? object[] data = new object[] { 2.2M, 3m, 1, "string", true,
我似乎失去了很多 float 的精度。 例如我需要求解一个矩阵: 4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0
这个问题在这里已经有了答案: Why python decimal.Decimal precision differs with equable args? (2 个答案) 关闭 5 年前。 我知道
当我尝试转换 Task 时出现此错误至 decimal : Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Cul
我听到有人说在 C# 中,大写十进制比小写十进制使用更多的内存,因为小写十进制被解析为小写十进制并且需要内存。 这是真的吗? 最佳答案 没有。 decimal 只是 System.Decimal 的别
我有一个对象,它是 dict、list、常规数据类型和 decimal.Decimal 的嵌套组合。我想用 PyMongo 将这个对象插入到 MongoDB 中。 PyMongo 拒绝插入 Decim
sdr 是我的 sqldatareader,我想检查小数类型的 curPrice 值是否为空。 inrec.curPrice = sdr.IsDBNull(7) ? (十进制?)空:sdr.GetDe
变量 'a' 的类型可以是 - int/float/decimal.Decimal(但不是字符串) 我想检查它是否是 decimal.Decimal 类型。 以下作品: import decimal
我正在使用一个在函数调用中使用一些十进制类型参数的库。但是我有 numpy.int32 类型变量。当我将它传递给函数调用时,出现以下错误: TypeError: conversion from num
考虑以下代码: public class DecimalWrapper { public static implicit operator DecimalWrapper
考虑以下代码: public class DecimalWrapper { public static implicit operator DecimalWrapper
我是一名优秀的程序员,十分优秀!