久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Magento - 在分組產品表中顯示自定義屬性

Magento - Show Custom Attributes in Grouped Product table(Magento - 在分組產品表中顯示自定義屬性)
本文介紹了Magento - 在分組產品表中顯示自定義屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要找到一種方法來顯示自定義屬性的值,而不是下圖中顯示的產品名稱".


(來源:magentocommerce.com)

我正在使用/app/design/frontend/default/defaultx/template/catalog/product/view/type/grouped.php

下面的代碼不起作用(自定義屬性是 yearmade):

<?php foreach ($_relatedProducts as $_item): ?><tr><td><?php echo $this->htmlEscape($_item->getYearmade()) ?></td>

任何幫助將不勝感激.

所以答案很簡單.你看我上面沒有提到的是 確實有輸出......但它只是一個數字(例如:52).原來這是該自定義屬性值的 ID(這是自定義屬性的下拉類型).

總結一下
這適用于文本類型的自定義屬性:

echo $this->htmlEscape($_item->getYearmade())

但是對于所有其他類型的自定義屬性(我認為),應該使用以下內容:

echo $this->htmlEscape($_item->getAttributeText('yearmade'))

如果沒有下面 Alan Storm 提供的最出色的答案,我就不會發(fā)現這一點.謝謝樓主.

解決方案

所有 Magento 模型都有一個可用的getData"方法,該方法將返回一個鍵/值對的 php 數組.在 grouped.phtml 文件的頂部嘗試這個(在 $_product 被定義之后)

print('

');print_r($_product->getData());print('

');

您應該會看到類似于以下內容的輸出.

數組([store_id] =>1[entity_id] =>3437[entity_type_id] =>4[attribute_set_id] =>27[type_id] =>分組[sku] =>[category_ids] =>[created_at] =>2009-04-16 03:37:51...

因此,您可以獲取一組屬性,然后將密鑰拉出.您還可以使用 Magento 的方便/神奇的 getX 和 setX 方法.在所有 Magento 模型上,您可以通過調用基于名稱的駝峰大小寫版本的方法來訪問數據數組中的任何屬性,

$created_at = $_product->getCreatedAt();$_product->setCreatedAt($date);

因此,無論您的自定義屬性名稱是什么,您都應該能夠使用上面的方法獲得它,如果您不確定是否只是 print_r 或 var_dump 由 getData() 返回的數組的內容.

最后,如果自定義屬性位于相關產品之一的簡單產品上,您將需要更多類似的東西

$_relatedProducts[0]->getCreatedAt();

I need to find a way to show the value of a custom attribute in place of the "Product Name" shown in the image below.


(source: magentocommerce.com)

I'm working with /app/design/frontend/default/defaultx/template/catalog/product/view/type/grouped.php

The code below doesn't work(the custom attribute is yearmade):

<?php if (count($_associatedProducts)): ?>  
<?php foreach ($_associatedProducts as $_item): ?>  
    <tr>  
        <td><?php echo $this->htmlEscape($_item->getYearmade()) ?></td>

Any help would be appreciated.

EDIT: So the answer turned out to be quite simple. You see what I failed to mention above was that there was indeed output... but that it was just a number (eg: 52). Turns out this was the ID for that custom attribute value (It was a Dropdown type of custom attribute).

So in summary
This works for custom attributes of type text:

echo $this->htmlEscape($_item->getYearmade())

But for all other types of custom attribute (I think), the following should be used:

echo $this->htmlEscape($_item->getAttributeText('yearmade'))

I would not have discovered this without the most excellent answer provided by Alan Storm, below. Thank you sir.

解決方案

All Magento models have a "getData" method available, which will return an php-array of key/value pairs. Try this at the top of your grouped.phtml file (after $_product is defined)

print('<pre>');print_r($_product->getData());print('</pre>');

You should see output that looks something like the following.

Array
(
    [store_id] => 1
    [entity_id] => 3437
    [entity_type_id] => 4
    [attribute_set_id] => 27
    [type_id] => grouped
    [sku] => 
    [category_ids] => 
    [created_at] => 2009-04-16 03:37:51
...     

So, you can grab an array of properties and just pull the key out. You could also use Magento's convenience/magic getX and setX methods. On all Magento models, you can access any property in the data array by calling a method based on the camel case version of the name,

$created_at = $_product->getCreatedAt();
$_product->setCreatedAt($date);

So, whatever your custom attribute name is, you should be able to get at it using the above, and if you're not sure just print_r or var_dump the contents of the array returned by getData().

Finally, if the custom attribute is on one of the related products simple product, you'll wants something more like

$_associatedProducts[0]->getCreatedAt();

這篇關于Magento - 在分組產品表中顯示自定義屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 第四色影音先锋 | 在线小视频| 99精品国产一区二区三区 | 国产成人影院 | 欧美综合国产精品久久丁香 | 亚洲国产一区二区三区 | 久久99精品久久久水蜜桃 | 国产一二三区在线 | 永久免费在线观看 | www.久久艹 | 天堂一区二区三区 | 美女黄频| 精品国产免费人成在线观看 | 久久一区二区视频 | 久久国产传媒 | 亚洲码欧美码一区二区三区 | 在线播放中文字幕 | 欧美久久一级特黄毛片 | 久久久久国产一区二区三区不卡 | 久久在线 | a毛片 | 国产精品一区二区在线观看 | 在线男人天堂 | 一区二区三区四区av | 国产视频一区在线 | 亚洲九九 | 91亚洲精品国偷拍自产在线观看 | 免费网站国产 | 91se在线| 日本涩涩视频 | 精品国产乱码久久久久久影片 | 国产精品久久久久国产a级 欧美日本韩国一区二区 | 日韩精品在线播放 | 欧美日韩久久 | 色婷婷综合久久久久中文一区二区 | 免费在线成人 | 午夜欧美一区二区三区在线播放 | 成人激情视频免费在线观看 | 91精品国产综合久久久久久丝袜 | 一区二区视频在线观看 | 久久久久成人精品 |