何千ものオプションがある属性があります。オプションは、フィードからすべての製品をインポートするスクリプトによってプログラムで作成されます。サイトの実行速度がかなり遅いので、古いオプションをすべて削除すると思いました。問題は、Magento管理者から編集ページを読み込めないことです。MySQLクエリで属性オプションを特定するにはどうすればよいですか?または、プログラムですべての属性オプションを削除するにはどうすればよいですか?
ありがとう!
何千ものオプションがある属性があります。オプションは、フィードからすべての製品をインポートするスクリプトによってプログラムで作成されます。サイトの実行速度がかなり遅いので、古いオプションをすべて削除すると思いました。問題は、Magento管理者から編集ページを読み込めないことです。MySQLクエリで属性オプションを特定するにはどうすればよいですか?または、プログラムですべての属性オプションを削除するにはどうすればよいですか?
ありがとう!
これにより、すべてのオプションのリストが表示されます
$attribute_code = 'color';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product',$attribute_code);
$options = $attribute->getSource()->getAllOptions();
これにより、属性を更新してオプションを削除できます
$options['delete'][$option_id] = true;
$options['value'][$option_id] = true;
$options['delete'][$another_option_id] = true;
$options['value'][$another_option_id] = true;
// (...)
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttributeOption($options);
ここでは、magentoでプログラムによってすべての属性オプション値を削除する方法を説明します。Magentoの管理パネルから属性オプション値を削除することもできますが、属性オプション値が非常に多い場合は、管理者から削除するのに非常に時間がかかるため、プログラムでMagentoに属性オプション値を追加できます。そのためには、magentoルートフォルダーにdeleteattributeoptions.phpファイルを作成し、その中に以下のコードを追加して、ATTRIBUTE_CODE_HEREを属性コードに置き換える必要があります。
<?php
require_once 'app/Mage.php';$app = Mage::app('admin');umask(0);
$attribute_code = 'ATTRIBUTE_CODE_HERE';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_code);
$options = $attribute->getSource()->getAllOptions();
$optionsDelete = array();
foreach($options as $option) {
if ($option['value'] != "") {
$optionsDelete['delete'][$option['value']] = true;
$optionsDelete['value'][$option['value']] = true;
}
}
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->addAttributeOption($optionsDelete);
?>
お役に立てば幸いです。:)
これは、関係するテーブルとの関係を示すクエリです。これがお役に立てば幸いです。この方法で、ストアビューごとに個別に取得できます。
属性(またはこれらのテーブル内に格納されているその他のもの)のストアビューにラベルをフェッチするには、次を使用します。
SELECT
EA.attribute_id,
EA.entity_type_id,
EA.attribute_code,
EAL.value AS label
FROM `magento_eav_attribute` AS EA
INNER JOIN `magento_eav_attribute_option`
AS EAO ON EAO.attribute_id = EA.attribute_id
INNER JOIN `magento_eav_attribute_label`
AS EAL ON EAL.attribute_id = EA.attribute_id
WHERE
EAL.store_id = 0 AND
EA.attribute_code = 'color' LIMIT 0,1';
処理するオプションに関連するオプション値を取得するには、次のようなものを使用します。
SELECT *
FROM `magento_eav_attribute_option_value`
WHERE store_id = 0
AND option_id = YOUR_OPTION_ID;
または、いくつかの結合を使用して、これらのテーブルを直接接続します
SELECT
EA.attribute_id,
EA.entity_type_id,
EA.attribute_code,
EAOV.option_id,
EAOV.value_id,
EAOV.value,
EAL.value AS label
FROM `magento_eav_attribute` AS EA
INNER JOIN `magento_eav_attribute_option`
AS EAO ON EAO.attribute_id = EA.attribute_id
INNER JOIN `magento_eav_attribute_option_value`
AS EAOV ON EAOV.option_id = EAO.option_id
INNER JOIN `magento_eav_attribute_label`
AS EAL ON EAL.attribute_id = EA.attribute_id
WHERE
EAOV.store_id = 0 AND
EAOV.option_id = YOUR_OPTION_ID AND
EAL.store_id = '0' AND
EA.attribute_code = 'color';
これは値を削除する方法ではないことは知っていますが、必要なデータセットを取得する方法を特定するのに役立つかもしれません。
ではごきげんよう。
これが私がやろうとしている方法です
// Deleting attribute options by GUID
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "position");
//Values have to be deleted one at a time
// Eav Setup.php
$updates = array();
foreach ($attribute->getSource()->getAllOptions() as $option) {
$update['value'] = array();
$update['delete'][$option['value']] = true;
$update['attribute_id'] = $attribute->getId();
$update['value'][$option['value']] = true;
$updates[] = $update;
}
$setup->addAttributeOption($updates);
die();