質問

顧客属性だけをロードし、その値を変更してそれを保存するための最も効率的な方法(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()の節約機能を扱う、

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top