Magento Code Snippets
Get all the product attributes which are searchable
select a.attribute_code from eav_attribute a inner join catalog_eav_attribute b on a.attribute_id = b.attribute_id where b.is_searchable = 1; |
Get product type from product SKU or ID
$product = Mage::getModel('catalog/product')->load($product_id); | |
//$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$product_sku); | |
$productType = $product->getTypeId(); //gives simple, configurable, bundled, grouped, etc.. |
Check whether request is coming from frontend or backend
if(Mage::app()->getStore()->isAdmin() && Mage::getDesign()->getArea() == 'adminhtml'){ | |
//request is from backend/admin | |
} else { | |
//request is NOT from backend/admin | |
} |
Check if there are any items in cart or not
$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount(); |
Check if Module is installed or not
$moduleExists = Mage::getConfig()->getNode('modules/Namespace_Module'); //returns YES or NO |
Get current package and frontend theme name
$currentPackage = Mage::getSingleton('core/design_package')->getPackageName(); | |
$currentTheme = Mage::getSingleton('core/design_package')->getTheme('frontend'); |
Get store contact telephone
$storePhone = Mage::getStoreConfig('general/store_information/phone'); |
Get store timezone
$storeTimezone = Mage::getStoreConfig('general/locale/timezone'); |
Get the title of CMS static block
$block = Mage::getModel('cms/block')->load($blockID); | |
echo $block->getTitle(); |
Get all the children of a block in PHTML
$children = $this->getChild(); | |
Mage::log($children->getData()); |
Check if this is category page or product page
$req = Mage::app()->getFrontController()->getRequest()->getControllerName(); | |
if($req == 'category') { | |
$cat = Mage::registry('current_category'); | |
} elseif($req == 'product') { | |
$prod = Mage::registry('current_product'); | |
} |
Get first and/or last item from collection
$firstItem = $collection->getFirstItem(); Mage::log($firstItem->getData()); | |
$lastItem = $collection->getLastItem(); Mage::log($lastItem->getData()); |
Check if there are any cross-sell products attached to a product
$crosssell = $product->getCrossSellProducts(); | |
if(count($crosssell)) { | |
//product have cross-sell products... | |
} |
Get all active payment methods
$activePayMethods = Mage::getModel('payment/config')->getActiveMethods(); |
Get all active shipping carriers
$activeCarriers = Mage::getSingleton('shipping/config')->getActiveCarriers(); |
Error: Index process is working now. Please try run this process later
This error generally comes when Magento was re-indexing one of the indexes and it failed in between. The solution is to remove the relevant index lock at: magento/var/locks/index_process*.lock
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)