在 list.phtml 中显示产品属性 - Magento

Show product attributes in list.phtml - Magento(在 list.phtml 中显示产品属性 - Magento)
本文介绍了在 list.phtml 中显示产品属性 - Magento的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

你好,我已经阅读了很多关于这个的帖子,虽然它有效但并不完整.

Hello I have read many posts about this, and while it works its not complete.

例如;属性 1 = 鞋码,属性 2 = 鞋色.两者都在下拉列表中,我想在类别页面中列出每个产品的所有可能的属性颜色.

For example; Attribute 1= shoesize and attribute 2 = shoe color. Both are in a dropdown and I would like to list all of the possible attribute colors per product within the category pages.

问题:当我测试代码时,它只会显示第一个鞋子颜色,而不是所有可能性.我在这里做错了什么?

Problem: When I test the code it will only display the first shoe color, instead of all posibilites. What am I doing wrong here?

以下是我所拥有的 3 个示例.所有代码都有效,但只显示第一个属性颜色.示例 1:

Here are 3 examples of what I have. All code work, but only shows the first attribute color. Example 1:

<!-- Find the following loop -->
<?php foreach ($_productCollection as $_product): ?>
<!-- Inside it insert one of the following codes as needed -->
<!-- Use this for regular text attributes -->
<?php echo $_product->getMyAttribute() ?>
<?php echo $_product->getAnotherCustomAttribute() ?>

<!-- Use this for dropdown attributes -->
<?php echo $_product->getAttributeText('shoecolor') ?>
<?php endforeach?>
<!-- ... --> 

示例 2

<?php echo $_product->getResource()->getAttribute('shoecolor')->getFrontend()->getValue($_product) ?>

示例 3

<?php $type = "simple"; $p = "0" ?> 
<?php foreach ($_productCollection as $_product): ?> 
<?php $custom = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); ?> 
<?php $col = $custom->getUsedProductCollection()->addAttributeToSelect('shoecolor')->addFilterByRequiredOptions(); ?> 
<?php foreach($col as $simple_product) { $p=$simple_product->getId(); $type="configurable"; } ?> 

<?php if($type == "configurable"): ?> 
<h5><?php echo $_product->load($p)->getAttributeText('shoecolor'); ?><?php $type="simple" ?></h5> 
 <?php endif; ?> 

推荐答案

你可以在属性编辑页面进行配置

you can just config it in attribute edit page

用于产品列表 -> 是

Used in Product Listing -> Yes

这篇关于在 list.phtml 中显示产品属性 - Magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)