我一直在努力寻找一种方法将照片添加到Magento的客户档案中。 除了这一点,他们拥有一切,我无法在任何地方找到如何做到这一点。 任何帮助表示赞赏。 我正在使用社区版。
答案 0 :(得分:3)
要为magento客户上传个人资料照片,我们需要执行以下几个步骤。
以上链接可帮助您在数据库中添加新的字段,并且您需要手动上传该照片,以下代码将帮助您上传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中保存文件名。
$客户 - > setLogo($了newName);