#attributes #custom-attributes #magento-1.9
#атрибуты #пользовательские атрибуты #magento-1.9
Вопрос:
Как я могу получить список атрибутов набора атрибутов, которых нет в наборе атрибутов по умолчанию?
Я попробовал следующие коды:
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
->load($_product->getAttributeSetId())->getId();
$attributes = Mage::getModel('catalog/product_attribute_api')
->items($attributeSetId);
echo '<pre>';
print_r($attributes);
die();
Но это вернуло массив со всеми атрибутами, включая атрибуты набора атрибутов по умолчанию, тогда как мне просто нужны были атрибуты, которые принадлежали только моему пользовательскому набору атрибутов.
Ответ №1:
Это решение, которое я придумал
public function getSpecificAttributes($product) {
//get ids of all the attributes in the default attribute set
$entityTypeId = Mage::getModel('eav/entity')
->setType('catalog_product')
->getTypeId();
$attributeSetName = 'Default';
$defaultAttributeSetId = Mage::getModel('eav/entity_attribute_set')
->getCollection()
->setEntityTypeFilter($entityTypeId)
->addFieldToFilter('attribute_set_name', $attributeSetName)
->getFirstItem()
->getAttributeSetId();
$defaultAttributes = Mage::getModel('catalog/product_attribute_api')->items($defaultAttributeSetId);
$defaultAttributeCodes = array();
foreach ($defaultAttributes as $attributes) {
$defaultAttributeCodes[] = $attributes['code'];
}
//get ids of all the attributes in the attribute set specific to the current product
$attributeSetId = $product->getAttributeSetId();
$specificAttributes = Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);
$attributeCodes = array();
foreach ($specificAttributes as $attributes) {
$attributeCodes[] = $attributes['code'];
}
$currentAttributes = array_diff($attributeCodes, $defaultAttributeCodes);
return $currentAttributes;
}