Jump to content

add image upload to customer


fred04

Recommended Posts

Hi,
 
I would like to add an additional field for the customer in order to upload an image in the back office side.
in the controllers/admin/AdminCustomerController.php, I had :

        $this->fieldImageSettings = array(
            'name' => 'image',
            'dir' => 'cust'
        );

in the renderForm() function I had :

        $image = _PS_IMG_DIR_ . 'cust/' . $obj->id . '.jpg';
        $image_url = ImageManager::thumbnail($image, (int)$obj->id.'.jpg', 80, 'jpg', true, true);
        $image_size = file_exists($image) ? filesize($image) / 1000 : false;

and at the end of the file I had this function :

    protected function afterImageUpload()
    {
        $return = true;
        /* Generate image with differents size */
        if (($id_customer = (int)Tools::getValue('id_customer')) && isset($_FILES) && count($_FILES) && file_exists(_PS_IMG_DIR_ . 'cust/' . $id_customer . '.jpg'))
        {
            $file = _PS_IMG_DIR_ . 'cust/' . $id_customer . '.jpg';
            if ( !ImageManager::resize($file,_PS_IMG_DIR_ . 'cust/' . $id_customer . '-' . '20x80' . '.jpg',20,80))
                $return = false;

            $current_logo_file = _PS_IMG_DIR_ . 'cust/' . 'cust_mini_' . $id_customer . '_' . $this->context->shop->id . '.jpg';

            if (file_exists($current_logo_file))
                unlink($current_logo_file);
        }
        return $return;
    }

in the admin/themes.../.tpl I had :

        
        <div class="form-group ">
            <label for="logo" class="control-label col-lg-3 ">
                <span data-original-title="{l s='Upload a customer logo from your computer'}" class="label-tooltip" data-toggle="tooltip" data-html="true" title="">{l s="Logo:"}</span>
            </label>
            <div class="col-lg-9 ">
		{if ($image_size)}
			<div class="form-group">
				<div class="col-lg-6" id="logo-images-thumbnails">
					<div class="img-thumbnail text-center">
						<p>{$image_url}</p>
						<p>{l s="File size"}{$image_size}{l s="Kb"}</p>
					</div>
				</div>
			</div>
                {/if}
                <div class="form-group">
                    <div class="col-lg-6">
                        <input id="logo" name="logo" class="hide" type="file"/>
                        <div class="dummyfile input-group">
                            <span class="input-group-addon"><i class="icon-file"></i></span>
                            <input id="logo-name" name="filename" readonly="" type="text"/>
                            <span class="input-group-btn">
                                <button id="logo-selectbutton" type="button" name="submitAddAttachments" class="btn btn-default"><i class="icon-folder-open"></i>{l s="Ajouter un fichier"}</button>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

So I see in the back "Office >> customer >> updatecustomer " the image field, I grab it on the disk but when I save ... the file is not uploaded on the my server ... did I miss something ?

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...