Call-back icon  Sales: Call 877.832.5289 (N America)|310.295.4144 (International)

Magento

eCommerce Software for Online Growth

Magento Forum

   
Page 2 of 5
Problem with attributes
 
finch8243
Member
 
Total Posts:  51
Joined:  2007-08-31
 

Moshe just updated the wiki entry for this, but I’m still unable to get it to work as he delineates.  Moshe—what up yo?

D

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1771
Joined:  2007-08-07
Los Angeles
 

@capple_: if it is a plain text attribute, use:

$_product->getData('part_no')
// or
$_product->getPartNo();
If it is a dropdown, use:
$_product->getAttributeText('part_no')

 Signature 

- I would love to change the world, but they won’t give me the source code -

 
Magento Community Magento Community
Magento Community
Magento Community
 
tobillo
Jr. Member
 
Total Posts:  30
Joined:  2008-04-07
Germany
 

Hi,

this does not work Moshe.... here is my code:

catalog.xml

<reference name="content">
            <
block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
                   <
block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                   <!-- 
edit oliver attribute on list -->
                      <
action method="addAttribute"><code>my_weight</code></action>
                  <!-- 
edit oliver attribute on list -->
                   </
block>
            </
block>
</
reference>

<
reference name="content">
            <
block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
                   <
block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                   <!-- 
edit oliver attribute on list -->
                      <
action method="addAttribute"><code>my_weight</code></action>
                  <!-- 
edit oliver attribute on list -->
                   </
block>
            </
block>
  </
reference>

list.phtml

<? $_product->getAttributeText('my_weight'?>

What’s the matter???!?!?

G
O

 
Magento Community Magento Community
Magento Community
Magento Community
 
miazad1
Jr. Member
 
Total Posts:  9
Joined:  2008-03-13
 

Hi,

Try placing the attribute within

<attribute>

like so:

<action method="addAttribute"><attribute>my_weight</attribute></action>

 
Magento Community Magento Community
Magento Community
Magento Community
 
miazad1
Jr. Member
 
Total Posts:  9
Joined:  2008-03-13
 

Oliver,

Ignore my previous post, it was just a shot in the dark plus I’m a newbie, so forgive me. Back to the issue at hand, is there a function called addAttribute in the file called List.php in the core?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1771
Joined:  2007-08-07
Los Angeles
 

Looks like it was changed. Please try this:

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

 Signature 

- I would love to change the world, but they won’t give me the source code -

 
Magento Community Magento Community
Magento Community
Magento Community
 
nafnaf1000
Sr. Member
 
Total Posts:  119
Joined:  2008-02-21
 

Anyone get this working yet????

if you did can you please help with code,.,,,

Thank you,

 
Magento Community Magento Community
Magento Community
Magento Community
 
nafnaf1000
Sr. Member
 
Total Posts:  119
Joined:  2008-02-21
 

Any one get this working yet???

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stefan Pantiru
Jr. Member
 
Total Posts:  8
Joined:  2008-05-08
 

A possible solution is to add your attribute to layer model file ( app/code/core/Mage/Catalog/Model/Layer.php )
to the function prepareProductColletion($collection) at line 56

->addAttributeToSelect('my_attribute')

Only after that, you can do

$_product->getData('my_attribute')
in the template.

Note: This is not elegant. Elegant would have been to be able to do

$_productCollection $this->addAttribute('my_attribute')->getLoadedProductCollection()
at the beginning of the template (in theory you are able to do that, but that doesn’t work either for me)

 
Magento Community Magento Community
Magento Community
Magento Community
 
jonahcoyote
Jr. Member
 
Total Posts:  12
Joined:  2008-02-16
Madison, WI
 

Hi all,

I’m wondering if the modifications for this would be the same to get an attribute to display on the shopping cart page?

I’ve tried editing checkout.xml with this on line 54:

<action method="addAttribute"><attribute>course_number</attribute></action>

And cart.phtml with this on line 79:

<?php echo $this->getData('course_number')?>

But nothing shows up. Any ideas?

Thanks,
Jonah

 
Magento Community Magento Community
Magento Community
Magento Community
 
InDaMixXx
Sr. Member
 
Avatar
Total Posts:  77
Joined:  2008-04-29
 

Any one get this working yet ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzflorida
Sr. Member
 
Total Posts:  84
Joined:  2008-03-07
Clearwater
 

This is how it is done:

insert the following wherever you want your custom attribute value to appear:

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

The code “author” was used as an example above.
You will have to insert the desired attribute code (found under ‘Manage Attributes’ in Magento Admin).
Please pay attention to capitalization.

Only the attribute value is pulled with this function and not the label of the attribute (in this case “Author"), as opposed to the product pages which list both. So in the case of the example above, you would want to ad “Author:” or the like, in front of it, if desired, for example like this:

<div>Author<?php echo $_product->getResource()->getAttribute('author')->getFrontend()->getValue($_product?></div>

Then you also need to add the following code in the layout/catalog.xml file:

<action method="addAttribute"><attribute>author</attribute></action>

Insert it immediately after:

<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">

In both:

<catalog_category_default>

and

<catalog_category_layered>

That should do it.

Let me know if you have any trouble.

 
Magento Community Magento Community
Magento Community
Magento Community
 
InDaMixXx
Sr. Member
 
Avatar
Total Posts:  77
Joined:  2008-04-29
 

Omg it works.

Thx you very much.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gabriel Queiroz
Member
 
Avatar
Total Posts:  73
Joined:  2008-05-28
Brazil
 

@tzflorida: Thanks, man. Works like a charm here (inside the category pages).

I still can’t get it to work on the home page, though… I’m inserting a block like:

{{block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml" category_id="4"}}

Anyone knows where the <action method="addAttribute"> tag should be added?

Thanks in advance.

 Signature 

Gabriel Queiroz Silva

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzflorida
Sr. Member
 
Total Posts:  84
Joined:  2008-03-07
Clearwater
 

Hi Gabriel,

Try this:

Put the action tag within the block tag you specified… like this:

{{block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml" category_id="4"}} 
{{action method
="addAttribute"}}{{attribute}}author{{/attribute}}{{/action}} 
{{
/block}}

You are trying to use this within the CMS of Magento?

This is something I will also need… however, I have not yet had the time to test it out.

Let me know if that works.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 2 of 5
 
Sales: Call 877.832.5289 (North America) 310.295.4144 (International)
© Copyright 2008 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
52172 users|1008 users currently online|105399 forum posts