属性选择magento查询

发布于 2024-09-30 13:57:25 字数 725 浏览 3 评论 0原文

我正在尝试在 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]

i am trying to get this query in magento.

Select merk, option_id from catalog ....... group by option_id

Sofar i have this but it aint showing the option_id value unfortunately and also i dont know how to group by them...

i hope someone is willing to help me
[code]

<?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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绻影浮沉 2024-10-07 13:57:25
$collection->addAttributeToSelect(array('option_id', 'merk'));
$collection->groupByAttribute('option_id');
$collection->addAttributeToSelect(array('option_id', 'merk'));
$collection->groupByAttribute('option_id');
傲鸠 2024-10-07 13:57:25

具有多个选择的属性存储为逗号分隔值。
因此,您只需要在 select 对象中添加“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)); 

Attributes with multiple choices are stored as comma separated values.
So you just need add "merk" attribute in select object:

$collection->addAttributeToSelect('merk');

and when you are iterating the collection, you may retrieve options id by calling your attribute value:

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

After retrieving of the values you need to retrieve option label for each option id

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

To filter by one of the multiple values you may use:

// Creates FIND_IN_SET statement for comma-separated attribute values
$collection->addAttributeToFilter('merk', array('finset' => $optionId)); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文