Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Inconsistant Attribute availability within Quote
 
John
Sr. Member
 
Avatar
Total Posts:  129
Joined:  2007-12-20
Sheffield, United Kingdom
 

Hi, I seem to be able to show inconsistent behaviour in the retrieval of attributes from a Quote object and want to know if anyone has seen this or has a better way round the problem.

First I am updating a shipping methods that seems to have broken from 1.0 to 1.1.  I have setup a custom attribute to represent the tiers for my shipping and each product has a tier.  So the idea is that when the product is put into the basket/shipping quote is requested then the tier for that product and the corresponding cost is returned.  Worked fine up to 1.1 - now the code below returns NULL for $product_tier_level.  (there is an attribute that I created called ‘postage_level’.

$items $quote->getAllItems();
foreach ( 
$items as $item {
  $product_tier_level 
$item->getProduct()->getpostage_level(); //Broke in 1.1.x - ho hum
}

Now to get round this I took the code from the Catalog/Block/Product/View/Attributes.php which I have pased below to help with the understanding.

function getProduct()
    
{
        
if (!$this->_product{
            $this
->_product Mage::registry('product');
        
}
        
return $this->_product;
    
}

public function getAdditionalData()
    
{
        $data 
= array();
        
$product $this->getProduct();
        
$attributes $product->getAttributes();
        foreach (
$attributes as $attribute{
            
if ($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined()) {

                $value 
$attribute->getFrontend()->getValue($product);
                if (
strlen($value) && $product->hasData($attribute->getAttributeCode())) {
                    $data[$attribute
->getAttributeCode()= array(
                       
'label' => $attribute->getFrontend()->getLabel(),
                       
'value' => $value//$product->getData($attribute->getAttributeCode())
                    
);
                
}
            }
        }
        
return $data;
    
}

Now my code uses this and looks like this

$quote Mage::getSingleton('checkout/session')->getQuote();
$items $quote->getAllItems();
foreach ( 
$items as $item {
    $product 
$item->getProduct();  
    
$attributes $product->getAttributes();
     foreach (
$attributes as $attribute{
           $key 
$attribute->getAttributeCode();  // Backend Label
           
$label $attribute->getFrontend()->getLabel();      // Frontend Label
           
$value $attribute->getFrontend()->getValue($product);  // value of attribute for product
      
}
}

So my issue I have - finally - is that $key and $label always return there correct values but $value is dependent on the product (item) I am looking at.  I have narrowed the issue down and it seems to be related to the those products that I have edited in the admin menus directly and not via initial import or via a mass update.  This is very strange that there is a difference.  It looks like if I go and edit the product then I am stripping down the data that I have associated with the product when I use a quote.  So Product A and B are the same - I edit product A in the admin and just save it - no changes and I now cannot see most of the attributes in the code above.  Where product B is unaffected.

attribute.php code above still works fine and I get the custom attributes in my “additional info” tab in the product detail view in the front end for both A and B.

Any advise?  I have my caches off and I have cleared them + I have removed all my sessions and re-started the web server.

Hope you can help - point me in the correct direction as I don’t understand why the quote object should behave and store different values for different products.

Thanks
John

 
Magento Community Magento Community
Magento Community
Magento Community
 
joff
Jr. Member
 
Total Posts:  27
Joined:  2008-06-27
 

John this is a very helpful post. Did you ever discover why the attribute value was returning inconsistently?

 
Magento Community Magento Community
Magento Community
Magento Community
 
John
Sr. Member
 
Avatar
Total Posts:  129
Joined:  2007-12-20
Sheffield, United Kingdom
 

Hi - no I did not - very strange - I just worked round the issue and tried a different approch

What problem are you having?

Regards
John

 
Magento Community Magento Community
Magento Community
Magento Community
 
till
Member
 
Total Posts:  58
Joined:  2007-12-17
 

Having the same issue.

1) in app/design/frontend/default/<TEMPLATE>/template/catalog/product/view/addtocart.phtml

$_product $this->getProduct();
$attribs $_product->getData();

It returns attributes from all groups - not just default.

2) in app/design/frontend/default/<TEMPLATE>/template/checkout/cart/item/default.phtml

$_product $this->getProduct();
$attribs $_product->getData();

It only returns attributes from default.

Still debugging myself though Magento to figure out how to get the attributes without a straight SQL query. wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
quanza
Sr. Member
 
Avatar
Total Posts:  97
Joined:  2008-12-02
Tokyo, Japan
 

any progress update on this?  I seem to be having a similar issue ...

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top