1

Customer.php ファイル ( import/export ) を変更して、CSV ファイルから顧客をインポートするときに新しいアカウントの詳細を自動的に送信できるようにしようとしています。

新しい行ごとに呼び出された (メールを受信した) 単純な mail() 呼び出しを削除したので、適切な領域で作業しています。問題は、新しいランダム パスワードを生成して新しいアカウントの詳細を送信しようとしたときに発生します。メールはまったく送信されず、理由もわかりません。コードは次のとおりです( app/code/local/Mage/ImportExport/Model/Import/Entity/Customer.php から編集)

 /**
 * Update and insert data in entity table.
 *
 * @param array $entityRowsIn Row for insert
 * @param array $entityRowsUp Row for update
 * @return Mage_ImportExport_Model_Import_Entity_Customer
 */
protected function _saveCustomerEntity(array $entityRowsIn, array $entityRowsUp)
{
    if ($entityRowsIn) {
        $this->_connection->insertMultiple($this->_entityTable, $entityRowsIn);

          // BEGIN: Send New Account Email          
          $cust = Mage::getModel('customer/customer');
          $cust->setWebsiteId(Mage::app()->getWebsite()->getId());              
          foreach($entityRowsIn as $idx => $u){
            // Failed
            $cust->loadByEmail($u['email']);
            $cust->setConfirmation(NULL);
            $cust->setPassword($cust->generatePassword(8));
            $cust->save();
            $cust->sendNewAccountEmail();
            //$cust->sendPasswordReminderEmail(); // this call doesnt work either
          }
          // END: Send New Account Email

    }
    if ($entityRowsUp) {
        $this->_connection->insertOnDuplicate(
            $this->_entityTable,
            $entityRowsUp,
            array('group_id', 'store_id', 'updated_at', 'created_at')
        );
    }
    return $this;
}
4

2 に答える 2

2

パフォーマンスを改善するには、magento の「キャッシュ」オブジェクトを使用するため、ループ内でオブジェクトをロードしようとするときは、新しいインスタンスをロードするか、reset() メソッドを呼び出す必要があります。

$website_id = Mage::app()->getWebsite()->getId();       
foreach($entityRowsIn as $idx => $u){
    $cust = Mage::getModel('customer/customer');
    $cust->setWebsiteId($website_id);
    $cust->loadByEmail($u['email']);
    $cust->setPassword($cust->generatePassword(8));
    $cust->save();
    $cust->sendNewAccountEmail();  // if you are getting 2 email then remove this line
}

多数の顧客をロードしている場合、メモリの問題が発生する可能性があり、使用する他の手法を探す必要がありますreset()

このコードが Magento の管理セクションから実行されている場合は、正しい Web サイト ID を設定していることを確認する必要があります ( Mage::app()->getWebsite()->getId()は間違った ID を返します)。

フロント エンドからこのコードは正常に動作しますが、管理エリアで getId() メソッドが '0' を返していたため、管理作業には '1' またはフロント エンドの Web サイト ID を使用する必要があります。ちょっとした問題ですが、何時間も行きました!

于 2012-11-27T11:34:17.127 に答える
0

既存の顧客のパスワードを自動生成する方法についてこのスクリプトを見つけました

$passwordLength = 10;
$customers = Mage::getModel('customer/customer')->getCollection();
foreach ($customers as $customer){
    $customer->setPassword($customer->generatePassword($passwordLength))->save();
    $customer->sendNewAccountEmail();
}
于 2013-01-21T10:02:30.637 に答える