質問

外部のスクリプトを介して顧客を追加するときには、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));
.

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