Magentoの属性は、モデル 'eav/entity_attribute'で表されます。次のコードは、それらにアクセスする方法を示しています。あなたが探していたことを願っています。
/*
* Initialize Magento. This assumes that we're running the script from the root
* directory of a magento installation. Obviously if you're writing an extension
* you don't need this.
*/
require_once 'app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::getSingleton("core/session")->setUser(Mage::getModel("admin/user")->load(0));
umask(0);
/*
* Attributes are represented by the eav/entity_attribute model
*/
$model = Mage::getModel("eav/entity_attribute");
foreach($model->getCollection() as $attr){
//$attr is a Mage_Eav_Model_Entity_Attribute (see Mage_Eav_Model_Entity_Attribute_Abstract for
//most of the action).
//Replace with your attribute processing code
echo "id={$attr->getId()}, code={$attr->getAttributeCode()},label={$attr->getFrontendLabel()}\n";
//Check to see if the attribute has options
if($attr->usesSource()){
echo " attribute options";
//process the options.
foreach($attr->getSource()->getAllOptions() as $option){
//Replace with your option processing code.
$label = $option['label'];
$value = $option['value'];
//Normally label is a string and value is an int. However,
//some options have sub options. In this case value is like
//array(array('label'=>'Label', 'value'=>'...'), ...)
if(is_array($value)){
$value = print_r($value, true);
}
echo " $label => $value\n";
}
}
}
あなたは属性で行うことができますいくつかの他のきちんとしたもの:
//Load an attribute by code/name
Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'price');
//Get the attribute set for an attribute
$setId = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'price')->getAttributeSetId();
$set = Mage::getModel('eav/entity_attribute_set')->load($setId);
アプリ/コード/コア/メイジ、アプリ/コード/コア/メイジ/ EAV /モデル/エンティティ/ Attribute.phpを参照してください。 /Eav/Model/Entity/Attribute/Abstract.php
出典
2011-12-23 12:35:31
jjm
ありがとうございました!大文字を使用してください。ほんの数分しかかかりません。 –
データベースに照会せずにデータベース値を取得することはできません。 –
Magento APIメソッド(データベース自体を照会する)を使用してカスタムクエリメソッドを使用するのではなく、 –