magento get Configurable attributes in attribute set - magento

How can I get all configurable attributes in attribute set?
I was looping all the attribute set then I want to display only its configurable attribute.

You should be able to get an attribute collection and filter it (based on the attribute set) - this would return you all attributes in the specified set that are configurable.
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeSetFilter($attributeSetId)
->addFieldToFilter("is_configurable", array("eq", "1"))
->getItems();

I assume that by configurable attributes, you actually mean attributes that can be used to create a configurable product. Douglas Radburn's answer is the right way to do this, it's only missing two more filters. As you can see in the picture above, there are three conditions for using an attribute to create a configurable product. Using the image's message as reference, we can construct the following collection.
$attributes = Mage::getResourceModel("catalog/product_attribute_collection")
->setAttributeSetFilter($attributeSetId)
->addFieldToFilter("frontend_input", "select")
->addFieldToFilter("is_configurable", "1")
->addFieldToFilter("is_global", "1");

This will work:
$objAttributes = Mage::getResourceModel('catalog/product_attribute_collection')
->addFieldToFilter("is_configurable", array("1"))
->getItems();

Related

value of specific group attributes of product

in manage attributes set say default i created a group say "my custom group" now i want to get value of all attributes under this group for current product how can i do this?..
$attributeValue = Mage::getModel('catalog/product')
->load($this->getProduct()->getId());
echo "<pre>";
print_r($attributeValue);
echo "</pre>";
show all attributes for product
Hello You can not fetch the Attributes values as per group.
Magento Follow the EAV Model.
So if you want to access the value form any Custom attribute value for that product then you have to follow the Magento Standard Way as below.
Syntax
$product=Mage::getModel('catalog/product')->load($Id);
Once you write above line the it will fetch all data for that product. Now you want to fetch the value of any attributes like name, color or any other attributes then use below code.
$product->getData('Attribute Code');
Or
$product->getName();
This way you can access the details of any attributes.
First thing:
$_prod = Mage::getModel('catalog/product')->load($id);
There are 2 kinds of attributes:
The ones in 'General' where you can use:
$_prod->getAttributeText('some_attribute_code')
The ones in a custom group where you use:
$_prod->getData('some_attribute_code')
The difference is the function you call getAttributeText or getData

How to find associated products from grouped product is they are disabled?

I am trying to get the associated products from a grouped product.I can do that, but not for the products that they are disabled. I tried a solution which mention to set : Use Flat Catalog Product to "NO" but i still can't. Any other ideas? I tried load a collection and use filters like IS_ENABLED OR DISABLED and by loading Models like
$product = Mage::getModel('catalog/product')->load($id);
$associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
Any other ideas?
So lets look at the getAssociatedProducts() method of Mage_Catalog_Model_Product_Type_Grouped class. Here's the interesting part of it:
if (!Mage::app()->getStore()->isAdmin()) {
$this->setSaleableStatus($product);
}
$collection = $this->getAssociatedProductCollection($product)
->addAttributeToSelect('*')
->addFilterByRequiredOptions()
->setPositionOrder()
->addStoreFilter($this->getStoreFilter($product))
->addAttributeToFilter('status', array('in' => $this->getStatusFilters($product)));
As you can see Magento adds status to collection filter. Method getStatusFilters() returns product statuses to apply on filter. If you would look at the body of this method you would see that it returns basically $product->getData($this->_keyStatusFitlers).
This method needs to return 2 values (2 statuses). But it doesn't. Responsible for that is if statement before the collection set up:
if (!Mage::app()->getStore()->isAdmin()) {
$this->setSaleableStatus($product);
}
This parts will set only ENABLED status on the product status filters.
If you want to get disabled products from grouped product you have rewrite Mage_Catalog_Model_Product_Type_Grouped class and remove the if statement and/or set proper filters.
Let me know if you don't know how to rewrite a Magento class, then I will extend this answer.

How to get attribute codes of super product attributes of a configurable product

For example, a configurable product with attributes Size and Color, I need to get the attribute codes of the above attributes.
or to be more specific, I need to know whether an attribute is used to configure a configurable product. I need this to check at product list page
try using this code
$config_product = Mage::getModel('catalog/product')->load($config_product_id);
$productAttributeOptions = $config_product->getTypeInstance(true)->getConfigurableAttributesAsArray($config_product);
Create an array as shown below:
$attributeValues['additional_options'][$count]['label'] = $aAttr['name'];
$attributeValues['additional_options'][$count]['value'] = $aAttr['value'];
Then pass the array while adding items to the order:
if (!empty($product['product_options'])) {
$orderItem->setProductOptions($product['product_options']);
}
Here $product['product_options'] is the array that we have created in the first step.

Default attribute value for all product in magento

I want to set a default value of an attribute for all product.
I had same problem before,when i added 11096 product(downloadable products) in my store then client told me to add new attributes in product so i create 1 attribute (Type is Yes/No) and set to attribute set.
Now my problem is how can i edit all product and set that attribute yes or not.if i not set then value is null so i wrote few line code.
Please check this code may be it'll helpful to you.
$ProductId = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE)
->getAllIds();
//Now create an array of attribute_code => values
$attributeData = array("my_attribute_code" =>"my_attribute_value");
//Set the store to affect. I used admin to change all default values
$storeId = 0;
//Now Update the attribute for the given products.
Mage::getSingleton('catalog/product_action')
->updateAttributes($ProductId, $attributeData, $storeId);
As stated here:- http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-attributes-custom-fields
Default Value: You can enter a value that will automatically populate
for new products.
So, I think it only applies for New products that you create after you create that attribute. Hence, the attribute's default value setting might not be applied to those products which were created before creating the attribute.
I had the similar issue and to solve it, I wrote the following code in the file where I want to display the attribute's default value:-
$attributeCode = 'YOUR_ATTRIBUTE_CODE';
$attribute = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter($attributeCode)
->getFirstItem();
echo $attribute->getDefaultValue();
You can also solve the problem by doing a massupdate for all products. Go to the Manage Products paga and Select All followed by Update attributes.
You can do it in Attribute management
Admin panel - Catalog - Attributes - Manage Attributes
Select attribute - Properties - Attribute Properties - Default value

default attribute value for all existing product in magento product in magento [duplicate]

I want to set a default value of an attribute for all product.
I had same problem before,when i added 11096 product(downloadable products) in my store then client told me to add new attributes in product so i create 1 attribute (Type is Yes/No) and set to attribute set.
Now my problem is how can i edit all product and set that attribute yes or not.if i not set then value is null so i wrote few line code.
Please check this code may be it'll helpful to you.
$ProductId = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE)
->getAllIds();
//Now create an array of attribute_code => values
$attributeData = array("my_attribute_code" =>"my_attribute_value");
//Set the store to affect. I used admin to change all default values
$storeId = 0;
//Now Update the attribute for the given products.
Mage::getSingleton('catalog/product_action')
->updateAttributes($ProductId, $attributeData, $storeId);
As stated here:- http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-attributes-custom-fields
Default Value: You can enter a value that will automatically populate
for new products.
So, I think it only applies for New products that you create after you create that attribute. Hence, the attribute's default value setting might not be applied to those products which were created before creating the attribute.
I had the similar issue and to solve it, I wrote the following code in the file where I want to display the attribute's default value:-
$attributeCode = 'YOUR_ATTRIBUTE_CODE';
$attribute = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter($attributeCode)
->getFirstItem();
echo $attribute->getDefaultValue();
You can also solve the problem by doing a massupdate for all products. Go to the Manage Products paga and Select All followed by Update attributes.
You can do it in Attribute management
Admin panel - Catalog - Attributes - Manage Attributes
Select attribute - Properties - Attribute Properties - Default value

Resources