Skip to content

Instantly share code, notes, and snippets.

@shebin512
Last active September 19, 2020 18:17
Show Gist options
  • Save shebin512/9062b657e1e1a55fd3b5 to your computer and use it in GitHub Desktop.
Save shebin512/9062b657e1e1a55fd3b5 to your computer and use it in GitHub Desktop.
My Magento1 Snippets
<?php
//Get Attribute sets
$attribute_sets = Mage::getModel('catalog/product_attribute_set_api')->items();
print_r($attribute_sets);
//get Attributes for a an attibute set
$attributes = Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);
print_r($attributes);
/**
* Get attribute Id by Attibute Code
*/
function getAttributeSetId($attributeSetName){
$entityTypeId = Mage::getModel('eav/entity')
->setType('catalog_product')
->getTypeId();
//$attributeSetName = 'Default';
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
->getCollection()
->setEntityTypeFilter($entityTypeId)
->addFieldToFilter('attribute_set_name', $attributeSetName)
->getFirstItem()
->getAttributeSetId();
//echo $attributeSetId;
return $attributeSetId;
}
/**
* Get Attribute set list in CSV format function
*/
function getAttributesCodesByAttributeSetName($attributeSetName){
$attributeSetId = getAttributeSetId($attributeSetName);
$attributes = Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);
$attributesTofetch = array();
foreach($attributes as $_attribute){
//print_r($_attribute);
$attributesTofetch [] = $_attribute['code'];
}
//echo implode(',', $attributesTofetch);
return implode(',', $attributesTofetch);
}
/**
* Camel caseing of attribute code to get function.
* fucntion + usage
*/
$getValue = camelCase("get_".$attribute);
$attributeValue = $product->$getValue();
function camelCase($str, array $noStrip = [])
{
// non-alpha and non-numeric characters become spaces
$str = preg_replace('/[^a-z0-9' . implode("", $noStrip) . ']+/i', ' ', $str);
$str = trim($str);
// uppercase the first character of each word
$str = ucwords($str);
$str = str_replace(" ", "", $str);
$str = lcfirst($str);
return $str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment