访问Magento自定义属性 [英] Accessing Magento Custom Attribute

查看:76
本文介绍了访问Magento自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个自定义属性,一个称为 amz_prod_description,一个称为 upc。

I have two custom attributes, one called 'amz_prod_description' and one called 'upc'.

根据此>

我应该能够在$ product-> getUpc()和$ product-> getAmzProdDescription()两者中访问它们。在同一交换机中,我同时使用了这两种功能。 upc属性var可以正常工作,其他属性根本不起作用,这确实在困扰着您,您所知道的,因为它们都使用了Magento所要求的方法,并且都在同一PHP函数中使用。因此,它们都处于相同的上下文中,等等。

I should be able to access them both $product->getUpc() and $product->getAmzProdDescription() where $product. In the same switch, I am using both of these. The 'upc' attribute var works fine, the other doesn't work at all which is really bugging the you-know-what out of me as they're both using the methodology that Magento calls for and in the same PHP function. So they're both in the same context, etc.

帮帮我!? :\

这是我实际值的代码>

Here's my actual code for what it's worth >

case "{amazon_description}":
            $description = $product->getAmzProdDescription();
            // I have tested, $description is not being set.  I have changed the bottom return to just $description and it returns nothing.
            if(strlen($description) > 1499) {
                $amz_description = substr($description,0,1500) . "...";
            } else {
                $amz_description = $description;
            }

            return $amz_description;
        break;

case "{upc}":
            $upc = $product->getUpc();
            return $upc;
        break;


推荐答案

Magento管理中的属性管理中有一个标记称为在前端的产品查看页面上可见。确保两个属性均设置为是,否则该属性将不会内置到getData数组中。

There's a flag in the attribute management in the Magento admin called "Visible on Product View Page on Front-end". Make sure that's set to "Yes" for both attributes, otherwise the attribute won't be built into the getData array. This assumes that your code is running in the frontend, although you haven't specified that.

还要确保您重建了索引并刷新了缓存,并确保了您的代码在前端运行。缓存存储。

Also make sure you rebuild indexes and flush the cache & cache storage.

这篇关于访问Magento自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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