顧客のウェブサイトIDをプログラムで設定する
-
13-12-2019 - |
質問
外部のスクリプトを介して顧客を追加するときには、Webサイトとストアの値が無視され、顧客が常に「管理者」に割り当てられ、「メインウェブサイト」に割り当てられている理由を教えてください。
私のMagentoインスタンス内に1つのウェブサイトと1店舗のみがあり、それぞれ1
のIDがあります。私のコードは以下のとおりです。
$customer = Mage::getModel("customer/customer");
$customer ->setWebsiteId(1)
->setStore(1)
->setFirstname('John')
->setLastname('Smith')
->setEmail('john@smith.com')
->setPassword('password')
->setGroupId('1');
try{
$customer->save();
}
catch (Exception $e) {
Zend_Debug::dump($e->getMessage());
}
. 解決
setStore()
を使用する代わりにsetStoreId()
$customer = Mage::getModel('customer/customer');
$email = 'john@smith.com';
$storeId = 1;
$website_id = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
$customer->setWebsiteId($website_id);
$customer->setStoreId($storeId);
...
. 他のヒント
あなたのコードにエラーが発生しました、
->setStore()
.
上記はストアIDに整数値をとらず、現在のストアのインスタンスを取ります。
->setStore(Mage::app()->getStore())
.
あなたの場合、私はそれが想像だと思います、
->setStore(Mage::getModel('core/store')->load(2));
. 所属していません magento.stackexchange