I created a custom_stock_status attribute in my module with 'int' backend type and four options in resource.
array(
4 => 'In Stock',
3 => 'Soon',
2 => 'Out Of Stock',
1 => 'Discontinued',
);
The code I use for this attribute creation:
class Jetkharid_Catalog_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
{
public function getDefaultEntities()
{
return array(
'catalog_product' => array(
'entity_model' => 'catalog/product',
'attribute_model' => 'catalog/resource_eav_attribute',
'table' => 'catalog/product',
'additional_attribute_table' => 'catalog/eav_attribute',
'entity_attribute_collection' => 'catalog/product_attribute_collection',
'attributes' => array(
'jetkharid_stock_status' => array(
'type' => 'int',
'label' => 'Stock Status',
'input' => 'select',
'source' => 'jetkharid_catalog/product_attribute_source_stock_status',
'required' => true,
'is_configurable' => false,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'group' => 'General Information',
'searchable' => true,
'used_in_product_listing' => true,
'user_defined' => false,
'default' => 4,
),
),
),
);
}
}
And this is my source for this attribute options:
class Jetkharid_Catalog_Model_Product_Attribute_Source_Stock_Status extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = array(
array(
'value' => 4,
'label' => Mage::helper('jetkharid_catalog')->__('In Stock')
),
array(
'value' => 3,
'label' => Mage::helper('jetkharid_catalog')->__('Soon'),
),
array(
'value' => 2,
'label' => Mage::helper('jetkharid_catalog')->__('Out Of Stock'),
),
array(
'value' => 1,
'label' => Mage::helper('jetkharid_catalog')->__('Discontinued'),
)
);
}
return $this->_options;
}
}
Now I want sort my collection by this attribute, but it seems not working!
How should I do?!
Thanks guys.