Populate custom attributes from database Magento - 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

Related

Get Meta Keyword By ID in 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(); ?>

Magento - Unable to display custom options

I'm using a module for displaying grouped configurable products and all options are showing except custom options. They are displaying on the configurable product page but that's it. I'm trying to use the code in app\design\frontend\blank\blank\template\catalog\product\view\options.phtml in my custom configurable.phtml but $_options is showing up null. Here is the code used to retrieve $_options
<?php $_options = Mage::helper('core')->decorateArray($this->getOptions()) ?>
<?php if (count($_options)):?>
and after the javascript
<?php foreach($_options as $_option): ?>
<?php echo $this->getOptionHtml($_option) ?>
<?php endforeach; ?>
</dl>
<?php else: echo dlkghflghf;?>
<?php endif; ?>
The dlkghflghf is displaying so i know $_options is not showing up. Any suggestions?
Your custom configurable.phtml is a template of what block? You can use a block that extends Mage_Catalog_Block_Product_View_Options or you can set your own method for options like the method from Mage_Catalog_Block_Product_View_Options, you also need to have a method getProduct():
public function getOptions()
{
return $this->getProduct()->getOptions();
}

Add custom category attribute to the frontend.

Pages of different category should display different footers and is the idea behind.
I know there are lot of similar questions and I tried them all, but they didn't work.
I have added custom category attribute to category page, and I want to see it in the footer.
I tried to use:
<?php if($_customAttribute = $this->getCurrentCategory()->getCustomAttribute()): ?>
<?php echo $_helper->categoryAttribute($_category, $_customAttribute, 'footer_text') ?>
But I have not got any results for this.
You can try it like this.
$category = Mage::registry('current_category');
<?php if ($category->getFooterText()) : ?>
<?php echo Mage::helper('catalog/output')->categoryAttribute($category, $category->getFooterText(), 'footer_text');?>
<?php endif;?>
But keep in mind...if you add this in footer.phtml it won't work with the block cache on. The footer is cached, so once you load a page the code above will have no effect on the next pages.
[EDIT]
If you want to have a different footer on some pages you need to modify the cache key for the footer block. There is an explanation on how to do that in here but it's for a simple page not a category. The concept is the same.
What you need to do is to change only the getCacheKeyInfo method to depend on the category. Something like this:
public function getCacheKeyInfo()
{
$info = parent::getCacheKeyInfo();
$category = Mage::registry('current_category');
if ($category) {
$info[] = $category->getId();
}
return $info;
}

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.

Magento - Filter Category list by category attribute

I have a list of store categories, and everything is working well except for one thing. I would like the list of categories to omit any that are set as 'Include in Navivation Menu = No'.
I can tell at this point that this attribute is not being loaded, but I'm having a difficult time figuring out where to place the filter. Currently, I am getting my category list via:
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
Followed by:
<?php foreach ($_categories as $_category) : ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
...
...
At this point, I have my category objects how I want them. But if I run a debug on these objects, the 'include_in_menu' attribute is not listed.
So for some reason:
<?php $_subCategory->getIncludeInMenu() ?>
Was not working for me after I ran:
<?php foreach($_parentCategory->getChildrenCategories() as $_subCategory) : ?>
The object was still the same model, but ['include_in_menu'] was no longer part of the object. I don't like this solution, but I just reconverted the object back:
<?php $_subCategory = Mage::getModel('catalog/category')->load($_subCategory->getId()) ?>
And then it worked fine. Not sure why getting the children would strip down the object, but it does.

Resources