2
Magentoの顧客プロフィールに写真を追加する方法を見つけようとしています。 彼らはこれ以外のものはすべて持っているので、どこに行ってもそれを見つけることができません。 何か助けていただければ幸いです。 コミュニティ版を使用しています。Magento - 顧客プロフィール写真のアップロード
Magentoの顧客プロフィールに写真を追加する方法を見つけようとしています。 彼らはこれ以外のものはすべて持っているので、どこに行ってもそれを見つけることができません。 何か助けていただければ幸いです。 コミュニティ版を使用しています。Magento - 顧客プロフィール写真のアップロード
お客様のプロフィール写真をマゼンタ色でアップロードするには、以下の手順を実行する必要があります。
上記のリンクは、DBに新しいファイルを追加するのに役立ちます。このファイルを手動でアップロードする必要があります。下のコードは、magentoで写真をアップロードするのに役立ちます。
if(isset($_FILES['logo']['name']) and (file_exists($_FILES['logo']['tmp_name'])))
{
try {
$uploader = new Varien_File_Uploader('logo');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS .'catalog/customer/logo/';
$newName = time() . $_FILES['logo']['name'];
$uploader->save($path, $newName);
$customer->setLogo($newName);
// actual path of image
$imageUrl = $path . $newName;
// path of the resized image to be saved
// here, the resized image is saved in media/resized folder
$imageResized = $path . $newName;
// resize image only if the image file exists and the resized image file doesn't exist
// the image is resized proportionally with the width/height 135px
if (!file_exists($imageResized)&&file_exists($imageUrl)) :
$imageObj = new Varien_Image($imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->resize(150, 150);
$imageObj->save($imageResized);
endif;
}catch(Exception $e) {
}
}
アップロード後、ファイル名をDBに保存する必要があります。
$ customer-> setLogo($ newName);
こんにちはサンカール。ソリューションをありがとう!モジュールのオブザーバにコードを挿入しましたが、 'customer_save_before'または 'customer_save_after'イベントが発生すると(顧客のバックエンド内で)、$ _FILES配列は空です。私は$ _POST配列のファイル名を取得しますが、私は$ _FILESを取得しません。何か案は?多分私はこのコードを置くことができる他の場所を提案することができますか? – Alan
ええ、私はこれを持っています。 "追加情報"フォームにはenctype = "multipart/form-data"属性が必要です。それ以外の場合は、ファイルを送信しません。 – Alan