搜索
开启辅助访问 切换到宽版

QQ登录

只需一步,快速开始

扫一扫,访问微社区

注册 找回密码
查看: 5215|回复: 1
打印 上一主题 下一主题

使用产品属性attribute作为附加信息显示

[复制链接]
跳转到指定楼层
楼主
发表于 2013-9-2 22:38:40 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
使用属性attribute作为产品额外的字段予以显示相关附加信息,其目的是一方面弥补产品字段本身数量的局限性,另一方面也是为了尽快显示产品相关信息,这样让顾客能够尽快注意到这些信息。

为何使用属性attribute?
1. 无需创建额外的数据库表或字段;
2. 只修改product.tpl和compare.tpl就可以了;
3. 你可以增加多语言版的更多的额外“字段”


本案例如上图所示为一本书添加产品额外信息。按照如下操作步骤进行:
1. 修改产品

网站后台
创建如下两个属性组 (Catalog > Attribute > Attribute Groups)
Product Info
Product Details
创建属于某属性组的以下属性(Catalog > Attribute > Attributes)
Product Info 属性组: ISBN, Pages, Author and Publisher
Product Details 属性组: Reading Level, Pages, Author, Publisher, ISBN-10, ISBN-13, Book Dimension
创建产品 (例如 Harry Potter)
转到 Attribute 标签页
选择添加所有上述属性
至于填写什么内容,你来决定吧。


修改产品模板 ( yourtheme/template/product/product.tpl )
将如下代码加载31行下面 (标记着 start-end 处)

<div class="description">
              ....
              <span><?php echo $text_stock; ?></span> <?php echo $stock; ?>
              <br/><br/>
              <!-- Start Additional Info -->
              <?php if ($attribute_groups) { ?>
                <?php foreach ($attribute_groups as $attribute_group) { ?>
                  <?php if ($attribute_group['name'] == 'Product Info') { ?>
                    <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
                      <span><?php echo $attribute['name']; ?></span> <?php echo html_entity_decode($attribute['text']); ?><br />
                    <?php } ?>
                  <?php } ?>
                <?php } ?>
              <?php } ?>
              <!-- End Additional Info -->
            </div>

2. 修改比较页面Compare Page

打开比较页面模板Compare Template ( yourtheme/template/product/compare.tpl )
加入如下代码:
<?php if ($attribute_group['name'] != 'Product Info') { ?> <!-- line 88 -->

        <?php } ?>  <!-- line 108 -->



3.
你可以修改属性组名称 "Product Info" 为任何文字,只要它与 $attribute_group['name'] 过滤器.
并不仅仅指一个属性组,你可以过滤两个或三个属性组。
如果你在属性内容中加入链接<a href=".."></a> 或其他html代码内容,不要忘记使用html的编码函数。
<?php echo html_entity_decode($attribute['text']); ?>

通过一些调整,你可以在分类页面显示特定产品的属性,作为产品信息或产品标签用。
另外,你也可以将产品属性作为一个条件值进行判断,如下所示:

<?php if ( $attribute['name'] == 'prodLabel' && $attribute['text'] == 'Free Shipping') {
            echo '<span class="freeShipping">'.$attribute['text'].'</span>';
        } ?>



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 分享分享 支持支持 反对反对
回复

使用道具 举报

沙发
发表于 2014-10-19 09:40:03 | 只看该作者
感谢,正是我需要的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

QQ|手机版|OpenCart - 中文官方网站 ( 蜀ICP备09033774号|人工智能

GMT+8, 2024-5-4 05:02 , Processed in 0.082802 second(s), 29 queries , Gzip On.

快速回复 返回顶部 返回列表