简体   繁体   English

Magento和可配置的产品属性

[英]Magento and configurable product attributes

I have an issue with displaying product custom attributes. 我在显示产品自定义属性时遇到问题。 I've read every resources through google but still no success. 我通过谷歌阅读了所有资源,但仍然没有成功。 The problem is that I have to show size attribute of configurable product on category grid and list view. 问题是我必须在类别网格和列表视图上显示可配置产品的大小属性。 Every solution on google suggested something like 谷歌的每个解决方案都提出了类似的建议

$_product->getAttributeText('size')

but I ended up at just a single string - "S" or "M" instead of an array. 但我最后只是一个字符串 - “S”或“M”而不是数组。 How can I fetch all possible sizes of all simple products which belongs to particular configurable product without much hassle? 如何在没有太多麻烦的情况下获取属于特定可配置产品的所有可能尺寸的所有简单产品?

UPDATE UPDATE

After using solution proposed by Joseph Mastey I encountered another problem. 在使用Joseph Mastey提出的解决方案后,我遇到了另一个问题。 I managed to show all possible options for given attribute, but now I need to show only these options which are available to buy. 我设法显示给定属性的所有可能选项,但现在我只需要显示可以购买的这些选项。 For example if t-shirt size L is out of stock or is disabled, L option should not be shown. 例如,如果T恤尺码L缺货或被禁用,则不应显示L选项。 How can I solve this issue? 我该如何解决这个问题?

When dealing with configurable products (or any time you're dealing with a concept for only one type of product, as configurable attributes are), you'll probably be working with getTypeInstance . 在处理可配置产品时(或者您只处理一种类型产品的概念,作为可配置属性),您可能正在使用getTypeInstance See below, I grab the configurable attributes for the product, then find the one for size. 请参阅下文,我获取产品的可配置属性,然后找到适合大小的属性。 You could also just run through every configurable attribute if you wanted. 如果需要,您还可以运行每个可配置属性。 Or if size is the only configurable attribute, just skip that if() . 或者,如果size是唯一可配置的属性,则跳过if()

$attrs  = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
foreach($attrs as $attr) {
    if(0 == strcmp("size", $attr['attribute_code'])) {
        $options    = $attr['values'];
        foreach($options as $option) {
            print "{$option['store_label']}<br />";
        }
    }
}

Hope that helps! 希望有所帮助! Thanks, 谢谢,

Joe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM