【问题标题】:Traverse ez-multioption attribute options in EZ Publish PHP-side在 EZ Publish PHP 端遍历 ez-multioption 属性选项
【发布时间】:2011-03-16 12:08:25
【问题描述】:

我需要帮助来遍历多选项中的所有选项。

我使用带有一个名为“product_properties”的新多选项属性的产品类。我需要一个函数来检查用户在前端选择的 optionID 是否与列表中的选项匹配,如果找到匹配项则返回 true。

这样我可以检查例如用户选择“红色”作为产品的“颜色”。

在伪代码中这是我需要的:

参数:postedOptionID、currentObjectID

  1. 获取对象上的属性“product_properties”(多选项)。

  2. 对于“product_properties”中“颜色”的每个选项

    2.1 如果张贴OptionID == optionID

    2.1.1 返回真

谢谢

【问题讨论】:

    标签: php ezpublish


    【解决方案1】:

    我终于找到了方法:)

    • $product_properties_name 是“ezmultioption”数据类型的类属性的名称。在我的例子中,它被称为“product_properties”,是“产品”类的一个属性。

    首先获取对象的所有属性: $contentObjectAttributes = $contentObject->version($contentObject->attribute('current_version'))->contentObjectAttributes();

    然后循环每个并找到'product_properties':

    // Loop all attributes of the object's class         
    foreach(array_keys($contentObjectAttributes) as $key)        
    {
        $contentObjectAttribute = $contentObjectAttributes[$key];
        $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();           
        $attributeIdentifier = $contentClassAttribute->attribute("identifier");     
    
        // Get 'product_properties'-attribute
        if ($attributeIdentifier == $product_properties_name)
        {               
            // Get the multioption
            $multioption_list = $contentObjectAttribute->content();
    
            // Loop all multioption lists (Color, Make, Brand etc.)
            foreach($multioption_list->attribute('multioption_list') as $index => $option)
            {       
                // Loop through this multioption and get all options (if 'Color', get 'Blue', 'Red', 'Green' etc.)
                foreach($option['optionlist'] as $option)
                {
                    $optionValue = trim($option['value']);
    
                    // if there's a match on $optionValue, do something interesting...  
                }                                               
            }           
        }       
    }   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 2018-05-15
      • 2016-05-19
      • 2018-03-02
      相关资源
      最近更新 更多