Magento的 - 单定制产品属性与值数组 [英] Magento - Single Custom Product Attribute with Array of Values

查看:87
本文介绍了Magento的 - 单定制产品属性与值数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Magento需要提供输出其所有值作为列表项的数组的定制产品属性.的基本前提是产品的成分的列表...上我们需要进入(例如)水,盐,着色剂每一个产品的基础 - 并为那些被呈现为在前端的列表

I have a need in Magento to provide an array custom product attribute that outputs all of its values as list items. The basic premise is a list of product ingredients... on a per product basis we need to enter (for example) water, salt, colourings - and for those to be rendered as a list on the front end.

我的逻辑至今一直使用标准的文本字段属性,输入逗号在后端分隔值,然后尝试使用该字符串作为数组从我可以使用的foreach创建无序列表.

My logic so far has been to use the standard text field attribute, entering comma separated values in the back-end and then to try and use that string as an array from which I can use foreach to create the unordered list.

到目前为止,我可以重复整个字符串仅作为一个列表项,但渲染字符串作为它的个体值的数组至今难倒我!见下文...

So far I can echo the entire string as just one list item, but rendering the string as an array of its individual values has so far stumped me! See below...

的成分文本字段属性具有水",盐",着色剂"的值. -加上引号和逗号只是在这样的前提下:它将对列表进行预格式化,使其准备好成为数组.

The Ingredients text field attribute has a value of "water", "salt", "colourings". - the addition of quote marks and commas is only the assumption that this would pre-format the list ready to be an array.

<?php
$ingredientsArrayContent = $this->getProduct()->getSpa_productingredients();
$ingredientsArray = array($ingredientsArrayContent);
?>
<ul>
    <?php
    reset($ingredientsArray);
    foreach ($ingredientsArray as $ingredientsValue) {
        echo "<li>$ingredientsValue</li>\n";
    }
    ?>
</ul>

所以在前端,这是输出:

So on the front end this is outputting:

<ul>
    <li>"water", "salt", "colourings"</li>
</ul>

当然,我希望获得的是什么:

What of course I am looking to achieve is:

<ul>
    <li>water</li>
    <li>salt</li>
    <li>colourings</li>
</ul>

我是否使这个问题复杂化了,甚至在Magento中也缺少一些明显的东西?任何指针不胜感激!!

Am I over complicating this and missing something really obvious even in Magento? Any pointers greatly appreciated!!

推荐答案

也许代替:

$ ingredientsArray =阵列($ ingredientsArrayContent);

$ingredientsArray = array($ingredientsArrayContent);

尝试使用:

$ ingredientsArray =阵列(爆炸( ",$ ingredientsArrayContent));

$ingredientsArray = array(explode(",",$ingredientsArrayContent));

根据您的属性是否被设置为:水,盐,色素"或水,盐,色素"定界符可能需要更改或您设置的属性值可能需要改变.

Depending on whether your attribute is set as: "water,salt,colourings" or "water, salt, colourings" your delimiter might need to change or how you set your attribute values might need to change.

这篇关于Magento的 - 单定制产品属性与值数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆