モデルから属性だけをロードして保存する
-
12-12-2019 - |
質問
顧客属性だけをロードし、その値を変更してそれを保存するための最も効率的な方法(Magentoメソッドを使用)とは何ですか。
解決
既に顧客モデル(少なくとも部分的にロードされている)をお持ちの場合は、この行を使用して単一の属性を保存できます。
$customer->getResource()->saveAttribute($customer, 'attribute_code_goes_here');
.
実際には、これが機能するためには、$customer
インスタンスに存在している必要がある唯一の属性は、entity_id
と保存する属性です。このような選択されたeav属性のみで顧客にロードできます。
$customer = Mage::getModel('customer/customer')
->load($customerId, array('attribute_code_goes_here'));
. 他のヒント
$customer = Mage::getModel('customer/customer')->loadByEmail('customer@email.com');
//or if you know the customer ID
$customer = Mage::getModel('customer/customer')->load($id, array('attribute_code'));
// attribute_code
$customer->setAttributeCode('new value here')->save();
.
これは値の変更のみを保存します。Magentoは変更されていないすべての要素をすべて取り除き、データから変更されたものだけを保存します。
これを行います.Mage_Eav_Model_Entity_Abstract::_collectSaveData()
の節約機能を扱う、
所属していません magento.stackexchange