Get Meta Keyword By ID in Magento - magento

I want to display Meta Keyword of a Product in view.phtml file.
What function do i need to call upon to display meta keyword of that particular product in Magento.

To return the meta keyword of the rendered product, use following within your view.phtml:
<?php echo $_product->getMetaKeyword(); ?>
You can get meta keyword by product id with:
<?php $_product = Mage::getModel('catalog/product')->load($productId); ?>
<?php echo $_product->getMetaKeyword(); ?>

Related

How to show the value of an attribute in shopping cart?

I added an attribute 'items' having input type textbox in admin.I want to show the value of that attribute in shopping cart.For that i have added this code in template/checkout/cart/sidebar-top.phtml which is below:
<?php
$productId = $_item->getId();
$productInfo = Mage::getModel("catalog/product")->load($productId);
echo $productInfo->getAttributeText('product_type');
?>
but when i am adding this above code showing
Fatal error: Call to a member function getId() on a non-object
if anyone knows this,please help me out.thanks!
Use the below code
$productId = $_item->getProduct()->getId();
$productInfo = Mage::getModel("catalog/product")->load($productId);
echo $productInfo->getAttributeText('product_type');
Are you talking about custom option or simple attribute?
For Simple attribute (text) and if you are on product page try belo code:
<?php $_item = $this->getItem()?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php echo $_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product); ?>
If you are not on the product page then you can use the below code, load the product by sku and get your attribute value
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku());
echo $product->getResource()->getAttribute('attribute_code')->getFrontEnd()->getValue($product);

Populate custom attributes from database Magento

I needed to add a custom attribute to categories on Magento, I have been able to do so using:
http://www.atwix.com/magento/add-category-attribute/
But now, I will like to turn the custom attribute into a select box and load the options from a external database/module. Is there any way to specificy the options available for the custom attribute in order to make them dinamic?
Thanks.
Have you found the solution? I'm doing it in phtml file like this
<?php $categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*'); ?>
<?php foreach ($categories as $category): ?>
<?php $customAtt= $category->getCustom_att(); ?>
<?php print_r ($customAtt); ?>
<?php endforeach; ?>
That way will populate all your custom category attribute values. Change the getCustom_att() with your custom attribute.
To make it a select option list, read this https://magento.stackexchange.com/questions/8674/how-to-get-all-custom-category-attribute-values/8692#8692

Show fatal error when click to product detail page from wishlist page

I am trying to display category name in product detail page. For that I am using
$cat_name=Mage::registry('current_category')->getName();
It shows category name.
But when I went to wishlist page & click to product image then it give error:-
Fatal error: Call to a member function getName() on a non-object in /opt/lampp/htdocs/dominie/app/design/frontend/default/dominie/template/catalog/product/view.phtml.
Please help me how can I solve this issue.
Just tested the code below and it work in v1.7 when added to template/catalog/product/view.phtml.
However Mage::registry('current_category'); is only available if when coming to a product page from a category page (not tested, but may also dependent on if you have seo url that contain the category names within the url)
<?php
$_helper = $this->helper('catalog/output');
$_category_detail=Mage::registry('current_category');
echo $_category_detail->getName(); //gives current category name
echo $_category_detail->getId(); //gives current category id
?>
See http://vinayp.com.np/how-to-get-category-name-and-id-on-product-page-on-magento/
To display all the categories that a product belong to do
<?php $categories = $_product->getCategoryIds(); ?>
<?php foreach($categories as $k => $_category_id): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>
<?php echo $_category->getName() ?>
<?php endforeach; ?>
See http://www.magentocommerce.com/boards/viewthread/27720/
Try to define $cat_name in your wishlist module so that collection from wishlist module will also contain category name from which it was added to wishlist. This will surely reduce your overhead.

add meta keywords to category list html page output

is it somehow possible to echo the category metakeywords on the category list view below the produkt list?
I tried somethink like this in the file template/catalog/catalog/product/list.phtml:
<?php echo $_category->getMetaKeywords(); ?>
but it doesn't output anything. thank you
You don't get any output because $_category variable is not initialized in template/catalog/catalog/product/list.phtml. The following code shall work:
<?php
$_category = Mage::registry('current_category');
echo $_category->getMetaKeywords();
?>

I want to display the product options value in Magento Product Page

I want to display the product options value in a Magento Product Page. I tried this code:
<?php echo $_product->getAttributeText('color'); ?>
but the options are not showing up.
If you are on the actual product view paghe you can use a helper to get what you want:
echo $_helper->productAttribute($_product, $_product->getColor(), 'color');
or
echo $_helper->productAttribute($_product, $_product->getData('attribute_code'), 'attribute_code');
Alternatively you can try this:
$_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product);
you can this one,
<?php $attributeValue = Mage::getModel('catalog/product')->load($_product->getId())->getColor();?>

Resources