Browsing articles tagged with "magento Archives - Page 11 of 21 - Kalpesh Mehta"
Jun 15, 2013
kalpesh

Magento get attribute label

To get attribute label for the product in Magento is not that straight-forward as we do for getting attribute value. You will need attribute code and product object to get the attribute label as shown below.

If you have the product object, you can use it to get the attribute’s label..

$label = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getLabel($product);

For the current/selected store view..

$label = $product->getResource()->getAttribute($attribute_code)->getStoreLabel();

This will output you the label of the attribute associated with the attribute code you passed for that product. E.g. Shirt Size, Color, etc..

To get select/dropdown attribute label by value OR to get select/dropdown attribute value by label, please check this post: http://ka.lpe.sh/2012/09/13/magento-get-product-attribute-select-option-idlabelvalue/

Jun 15, 2013
kalpesh

Magento get list of all product attributes

Get list of all the product attributes defined in Magento. This will fetch you an array with all the attribute codes as a key AND all the attribute details including attribute code as a value. You can limit this array by just attribute code and attribute label as per your need. I will show you all the possible attribute information you can fetch defined for the product.

$attrib_data = array(); $allAttributeCodes = array();
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')->getItems();

foreach ($attributes as $attribute){
    $attrib_data[$attribute->getAttributeCode()] = $attribute->getData();
    //$allAttributeCodes[] = $attribute->getAttributeCode();
}

Sample Output: Continue reading »

May 26, 2013
kalpesh

Magento filter products by status

Get all the products with status equal to enabled/disabled.

If you are using Flat Catalog in Magento, you will not get disabled products by this filter as in flat table all the products are only enabled one. You can check if your Magento website uses flat catalog or not by going here:
Admin > System > Configuration > Catalog section > Catalog > Frontend

Check Use Flat Catalog Category and Use Flat Catalog Product, if they are Yes it means you are using flat catalog, if they are No it means you are NOT using flat catalog.

So, if you don’t have flat catalog enabled and you want to filter all the products with status equal to disabled, you can use below code:

$products = Mage::getModel('catalog/category')->load($category_id)
->getProductCollection()
->addAttributeToSelect('*') //whatever attributes you want to get here
->addAttributeToFilter(
    'status',
    array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED) 
        //replace DISABLED to ENABLED for products with status enabled
);
May 26, 2013
kalpesh

Magento disable guest checkout / enable guest checkout

By default the guest checkout in Magento is enabled and visitors can place an order without registering to the website. Some websites require mandatory login for placing orders, and this default feature should be turned off to disallow guest checkout.

To disable guest checkout, navigate to:

System > Configuration > Sales section > Checkout > Checkout Options
Set Allow Guest Checkout to No

This will now disable any guest checkout in your site.
To enable guest checkout, simply set the above dropdown option to Yes.

May 26, 2013
kalpesh

Magento performace optimization, Catalog URL Rewrite Management

If your Magento site is slow, then one of the reason can be because of Catalog URL Rewrites. You can check in the Magento Admin > Catalog > URL Rewrite Management. If you see the catalog rewrites are very large than expected as per total Categories and Products you have, this will create your site to be slow. This generally gets too large if you edit the categories/products and change it’s URL. Generally we keep on changing the product URL to optimize for search engines or to correct some typo in the link. Magento saves all the previous category and product URLs even if it is changed many times, resulting in more number of URL rewrites in database. I have seen in one of the project, where total SKUs were near to 4,00,000 while the URL Rewrites were near to 46,00,000 with just one website and store!

Magento Catalog URL Rewrite Management
Continue reading »

Pages:«1...891011121314...21»

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions