小编Jam*_*mie的帖子

是否有更简单的方法来获取属性的前端值?

我有一组属性代码,我需要获取以下值:

$attributes = array(
    'Category'           => 'type',
    'Manufacturer'       => 'brand',
    'Title'              => 'meta_title',
    'Description'        => 'description',
    'Product Link'       => 'url_path',
    'Price'              => 'price',
    'Product-image link' => 'image',
    'SKU'                => 'sku',
    'Stock'              => 'qty',
    'Condition'          => 'condition',
    'Shipping cost'      => 'delivery_cost');
Run Code Online (Sandbox Code Playgroud)

在遍历产品集合后,我得到属性的前端值,如下所示:

$attributeId = Mage::getResourceModel('eav/entity_attribute')
    ->getIdByCode('catalog_product', $attribute_code);
$attribute = Mage::getModel('catalog/resource_eav_attribute')
    ->load($attributeId);
$value = $attribute->getFrontend()->getValue($product);
Run Code Online (Sandbox Code Playgroud)

简单地使用$product->getDate($attribute)将无法使用下拉列表和多项选择,它只返回它们的id而不是它们的前端值.

虽然上面的代码可行,但是获取值似乎还有很长的路要走,但更重要的是它运行速度很慢.是否有更快/更明智的方法来获取产品属性的前端值?

编辑
我现在有以下(在处理像image和之类的特殊情况之后qty),这对眼睛来说更容易,并且似乎运行得更快(虽然我不知道为什么):

$inputType = $product->getResource()
                     ->getAttribute($attribute_code)
                     ->getFrontend()
                     ->getInputType();

switch ($inputType) {
case 'multiselect':
case 'select':
case 'dropdown':
    $value = …
Run Code Online (Sandbox Code Playgroud)

attributes magento magento-1.5

8
推荐指数
1
解决办法
1万
查看次数

在PostgreSQL中使用行值作为列

我有以下brands表格,其中包含以前查询的total每个销售额month:

 id  |   date   | total
-----+----------+------
 123 | Apr-2012 | 100
 123 | Mar-2012 | 150
 123 | Jan-2012 | 500
 987 | Apr-2012 | 5
 987 | Mar-2012 | 0.10
 987 | Feb-2012 | 8
Run Code Online (Sandbox Code Playgroud)

我期待实现以下目标:

 id  | Apr-2012 | Mar-2012 | Feb-2012 | Jan-2012
 123 | 100      | 150      | 0        | 500
 987 | 5        | 0.10     | 8        | 0
Run Code Online (Sandbox Code Playgroud)

如何将date值用作列,并能够用0总计填写缺少的日期?

sql postgresql pivot crosstab

5
推荐指数
1
解决办法
7201
查看次数

标签 统计

attributes ×1

crosstab ×1

magento ×1

magento-1.5 ×1

pivot ×1

postgresql ×1

sql ×1