【问题标题】:attribute select magento query属性选择magento查询
【发布时间】:2010-11-06 13:03:39
【问题描述】:

我正在尝试在 magento 中获取此查询。

从目录中选择merk,option_id .......按option_id分组

到目前为止,我有这个,但不幸的是它没有显示 option_id 值,而且我不知道如何按它们分组...

我希望有人愿意帮助我 [代码]

<?php 
function getMenuWatches(){
    $collection = Mage::getModel("catalog/product")->getCollection();
    $collection->addAttributeToFilter("attribute_set_id", 26); 
    $collection->addAttributeToSelect("option_id , merk"); 


    return $collection;
}
$collection=getMenuWatches();
//print_r($collection);
foreach ($collection as $product){
    echo $product->getOptionId();
    $product->getMerk();
    echo   $product->getId('merk');
    echo   $product->getAttributeText('merk')."<br/>";

}
?>
[/code]

【问题讨论】:

    标签: magento


    【解决方案1】:
    $collection->addAttributeToSelect(array('option_id', 'merk'));
    $collection->groupByAttribute('option_id');
    

    【讨论】:

    • txs 但不知何故他没有给我 option_id。 Merk 是一个具有多种选择的属性。每个选项都有一个没有。 option_id 也许我必须做一些技巧才能获得这个值。?
    【解决方案2】:

    具有多个选择的属性存储为逗号分隔值。 所以你只需要在选择对象中添加“merk”属性:

    $collection->addAttributeToSelect('merk');
    

    当您迭代集合时,您可以通过调用属性值来检索选项 id:

    // List of option_id values
    $values = explode(',', $product->getMerk()); 
    

    检索值后,您需要检索每个选项 id 的选项标签

    $attribute = $product->getResource()->getAttribute('merk');
    $optionLabel = $attribute->getSource()->getOptionText($optionId);
    

    按您可能使用的多个值之一进行过滤:

    // Creates FIND_IN_SET statement for comma-separated attribute values
    $collection->addAttributeToFilter('merk', array('finset' => $optionId)); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-31
      • 2017-09-23
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      相关资源
      最近更新 更多