Shopware 5 - 循环遍历所有属性
您好,我需要一些关于商店用品的帮助。 我的问题可能很基本,但我无法完成。我想打印出一篇文章的属性。在商店软件文档中,他们将它们称为 {$sArticle.attr1} 到 {$sArticle.attr20},但它们也可以有不同的名称,因此我无法直接引用该名称,而是只希望打印一些属性。
到目前为止,我知道所有属性都存储在 s_articles_attributes 数据库表中,我只想在列名包含='artikelattribut_' 时打印出这些列。
代码将在 frontend/detail/tabs 的表中实现 - > description.tpl
实际表已经使用了 $sArticle.sProperties,代码如下所示:
{if $sArticle.sProperties}
<div class="product--properties panel has--border">
<table class="product--properties-table">
{foreach $sArticle.sProperties as $sProperty}
<tr class="product--properties-row">
{* Property label *}
{block name='frontend_detail_description_properties_label'}
<td class="product--properties-label is--bold">{$sProperty.name|escape}:</td>
{/block}
{* Property content *}
{block name='frontend_detail_description_properties_content'}
<td class="product--properties-value">{$sProperty.value|escape}</td>
{/block}
</tr>
{/foreach}
</table>
</div>
{/if}
问题是 $sArticle.sProperties 和 {$sArticle.attr1} 直到 {$sArticle.attr20} 是不同的。我想要的只是第二个 {foreach} ,它循环抛出所有文章属性,也许这个想法已经很清楚了:
{foreach $sArticle.attr FROM s_articles_attributes WHERE name contains='artikelattribut_'}
我希望有人理解我的问题。感谢您的任何建议。 谢谢
Hello i need some help with shopware.
My question is probably pretty basic but i cannot get it done. I want to print out attributes from an article. In shopware documentation they call them {$sArticle.attr1} till {$sArticle.attr20} but they can also have different names so i cannot refer directly to the name and instead i want only a few attributes to be printed.
so far i know that all attributes are stored in the s_articles_attributes database table and i only want to print out those columns when the column name containes='artikelattribut_'
The code is going to be implemented in a table from frontend/detail/tabs --> description.tpl
the actual table already uses the $sArticle.sProperties and the code looks the following:
{if $sArticle.sProperties}
<div class="product--properties panel has--border">
<table class="product--properties-table">
{foreach $sArticle.sProperties as $sProperty}
<tr class="product--properties-row">
{* Property label *}
{block name='frontend_detail_description_properties_label'}
<td class="product--properties-label is--bold">{$sProperty.name|escape}:</td>
{/block}
{* Property content *}
{block name='frontend_detail_description_properties_content'}
<td class="product--properties-value">{$sProperty.value|escape}</td>
{/block}
</tr>
{/foreach}
</table>
</div>
{/if}
The thing is that $sArticle.sProperties and {$sArticle.attr1} till {$sArticle.attr20} are different. All i want is a second {foreach} that loops threw all article attributes maybe the idea is getting clear with that:
{foreach $sArticle.attr FROM s_articles_attributes WHERE name contains='artikelattribut_'}
I hope somebody understands my problem. Thankfull for any advice.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,请记住,“属性”和“属性”在 Shopware 中的含义有所不同,正如您可能从其他商店系统中了解到的那样。
“特性”用于产品的特性,例如产品的味道或颜色。
Shopware 中的“属性”与通常含义中的属性没有任何关系。您可以找到几乎每个实体的这些
*_attributes
表,它们的使用更像是自定义字段或列,您可以将它们添加到实体中以使用自定义数据扩展它们。现在回到你的问题。试试这个:
有两种方法可以访问产品的属性。
$sArticle
变量,您可以使用它们,正如您在文本中所描述的那样。$sArticle.attributes
中,您可以在其中找到不同类型的属性。默认情况下,这些是详细信息页面上产品的核心
和营销
。请注意,这些键的值是Shopware\Bundle\StoreFrontBundle\Struct\Attribute
类型的对象。这就是为什么我们需要调用 toArray 方法来获取可以迭代的数组。First, keep in mind, that "properties" and "attributes" mean something different in Shopware as you might know it from other shop systems.
"Properties" are used for characteristics of a product, like the taste or colour of product.
"Attributes" in Shopware do not have anything to do with attributes in the usual meaning. You can find those
*_attributes
tables for almost every entity and they are used more like custom fields or columns which you could add to the entities to extend them with custom data.Now back to your problem. Try this:
There are two ways to access the attributes of a product.
$sArticle
variable and you can use them, as you already described in your text.$sArticle.attributes
where you can find different types of attributes. By default those arecore
andmarketing
for products on the detail page. Be aware that the values of those keys are objects of typeShopware\Bundle\StoreFrontBundle\Struct\Attribute
. That's why we need to call thetoArray
method, to get an array which we can iterate.