Magento Coding Solutions

Retrieve attribute code in configurable product in magento

echo $_attribute->getProductAttribute()->getAttributeCode();
Mage::getModel('eav/entity_attribute')->load($_attribute->getAttributeId())->getAttributeCode();


/**
 * get attribute collection
 */
$attribute = $_product->getResource()->getAttribute('my_attribute');
/**
 * get attribute type
 */
$attribute->getAttributeType();
/**
 * get attribute Label
 */
$attribute->getFrontendLabel();
/**
 * get attribute default value
 */
$attribute->getDefaultValue();
/**
 * check if the attribute is visible
 */
$attribute->getIsVisible();
/**
 * check if the attribute is required
 */
$attribute->getIsRequired();
/**
 * get attribute value
 */
$attributeValue = Mage::getModel('catalog/product')->load($_product->getId())->getMyAttribute();

get all product in cart item magento

$cart = Mage::getSingleton('checkout/cart');
$productIds = array();
foreach($cart->getQuote()->getAllVisibleItems() as $item) {
$productIds[] = $item->getProduct()->getId();
}

echo "<pre>";
print_r($productIds);
echo "</pre>";

pdo_mysql extension is not installed


i am writing below code
    require_once("../../app/Mage.php");

Mage::app();

to occur error  



Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The PDO extension is required for this adapter but the extension is not loaded' in /home/mp345/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php:342 Stack trace: #0 /home/mp345/public_html/lib/Zend/Db/Adapter/Abstract.php(247): Zend_Db_Adapter_Pdo_Abstract->setFetchMode(2) #1 /home/mp345/public_html/app/code/core/Mage/Core/Model/Resource.php(165): Zend_Db_Adapter_Abstract->__construct(Array) #2 /home/mp345/public_html/app/code/core/Mage/Core/Model/Resource.php(110): Mage_Core_Model_Resource->_newConnection('pdo_mysql', Object(Mage_Core_Model_Config_Element)) #3 /home/mp345/public_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(320): Mage_Core_Model_Resource->getConnection('core_write') #4 /home/mp345/public_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(350): Mage_Core_Model_Resource_Db_Abstract->_getConnection('write') #5 /home/mp345/public_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(335): Mage_Core_Model_Res in /home/mp345/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php on line 342


solution

create a file php.ini in rootpath with code



extension=pdo.so;
extension=pdo_sqlite.so;
extension=sqlite.so;

extension=pdo_mysql.so;



Get product attribute label & value in Magento


$_product->getData('attribute_code')
AND 
if you need label of the product attribute
$_product->getAttributeText('attribute_code')
or 
$_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product);

magento admin login information

$user = Mage::getSingleton('admin/session');
echo $userId = $user->getUser()->getUserId();
echo "</br>";
echo $userEmail = $user->getUser()->getEmail();
echo "</br>";
$userFirstname = $user->getUser()->getFirstname();
$userLastname = $user->getUser()->getLastname();
$userUsername = $user->getUser()->getUsername();
$userPassword = $user->getUser()->getPassword();

file upload in magento programaticaly

include("../app/Mage.php");
Mage::app();
$path = Mage::getBaseDir('media') . DS . 'clipart' . DS .'clipart'.DS;
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg','png','gif','jpeg','eps'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path.$_FILES['image']['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);