Jump to content
pskeeda

Enable PDF upload in Product Customization

Recommended Posts

I am using PS 1.6, i want to enable PDF file upload in Product Customization. Currently i am able to upload only jpg, gif and png files.

 

Please know, how to enable the same.

Share this post


Link to post
Share on other sites

To allow PDF upload, I override the ProductController::pictureUpload method in override/controllers/front.

 

In the following class:

  • has been tested with PS 1.6.0.5 and 1.6.0.6,
  • images are still handled by PrestaShop core,
  • files are uploaded in uploads/customizations/{cart_id}. You can remove this feature by editing lines 3, 33 and 36,
  • files that are not handled by PrestaShop core are prefixed with a "P".
  • some modules are editing the admin/displayImage.php file, but as I couldn't find any usage, I didn't. If you want to do this, you'll have to test the first letter of the file to send correct mime-type to the browser.
  • In your theme, in the product.tpl file, you can detect if the file is an image or a PDF with the folliwng code.  


if isset($pictures.$key)}
	<div class="customizationUploadBrowse">
		{if substr(basename($pictures.$key), 0, 1) == 'P'}
			<a href="{$pic_dir}{$pictures.$key}" target="_blank">{l s='View the file'}</a>
		{else}
			<img src="{$pic_dir}{$pictures.$key}_small" alt="" />
		{/if}
		<a href="{$link->getProductDeletePictureLink($product, $field.id_customization_field)|escape:'html':'UTF-8'}" title="{l s='Delete'}" >
			<img src="{$img_dir}icon/delete.gif" alt="{l s='Delete'}" class="customization_delete_icon" width="11" height="13" />
		</a>
	</div>
{/if}

I hope this will help you.

 

Regards.

ProductController.php

Edited by Esoterick (see edit history)

Share this post


Link to post
Share on other sites

Dear Esoterick,
Thanks for your reply. Since i am not a technical person, can you please elaborate that which files i need to edit to enable pdf upload.

Your reply will be highly appreciated.

Share this post


Link to post
Share on other sites

Esoterick fix works very well! (PS 1.6.0.5)

- Download his ProductController.php and upload it in /override/controllers/front/;

 

- Clear Prestashop cache;

 

- Now you have to fix the file preview in frontend, in product.tpl you can use the code portion Esoterick suggest:

{if isset($pictures.$key)}
	<div class="customizationUploadBrowse">
		{if substr(basename($pictures.$key), 0, 1) == 'P'}
			<a href="{$pic_dir}{$pictures.$key}" target="_blank">{l s='View the file'}</a>
		{else}
			<img src="{$pic_dir}{$pictures.$key}_small" alt="" />
		{/if}
		<a href="{$link->getProductDeletePictureLink($product, $field.id_customization_field)|escape:'html':'UTF-8'}" title="{l s='Delete'}" >
			<img src="{$img_dir}icon/delete.gif" alt="{l s='Delete'}" class="customization_delete_icon" width="11" height="13" />
		</a>
	</div>
{/if}

- Open "order-payment.tpl", "order-detail.tpl", "order-return.tpl" and search for "customizationUploaded", comment the div and paste this code above it:

{foreach from=$datas item='data'}
{if substr(basename($data.value), 0, 1) == 'P'}
<a href="{$pic_dir}{$data.value}" target="_blank">Open attached file</a>
{else}
<img src="{$pic_dir}{$data.value}_small" alt="" />
{/if}
<a href="{$link->getProductDeletePictureLink($product, $field.id_customization_field)|escape:'html':'UTF-8'}" title="{l s='Delete'}" >
<img src="{$img_dir}icon/delete.gif" alt="{l s='Delete'}" class="customization_delete_icon" width="11" height="13" />
</a>
{/foreach}

Now open "shopping-cart.tpl", again search for search for "customizationUploaded" comment the div and paste this code above it:

{foreach $custom_data as $picture}
{if substr(basename($picture.value), 0, 1) == 'P'}
<a href="{$pic_dir}{$picture.value}" target="_blank">Open attached file</a>
{else}
<img src="{$pic_dir}{$picture.value}_small" alt="" />
{/if}
<a href="{$link->getProductDeletePictureLink($product, $field.id_customization_field)|escape:'html':'UTF-8'}" title="{l s='Delete'}" >
<img src="{$img_dir}icon/delete.gif" alt="{l s='Delete'}" class="customization_delete_icon" width="11" height="13" />
</a>
{/foreach}

- Now last step: open "/ps-admin/themes/default/template/controllers/orders/_customized_data.tpl", search for "Product::CUSTOMIZE_FILE", comment the first foreach and paste this code above:

		{foreach from=$datas item=data}
			<div class="form-group">
				<span class="col-lg-4 control-label"><strong>{if $data['name']}{$data['name']}{else}{l s='Picture #'}{$data@iteration}{/if}</strong></span>
				<div class="col-lg-8">
					{if substr(basename($data.value), 0, 1) == 'P'}
						<a href="{$pic_dir}{$data.value}" target="_blank">Open attached file</a>
					{else}
						<a href="displayImage.php?img={$data['value']}&name={$order->id|intval}-file{$data@iteration}" class="_blank">
							<img class="img-thumbnail" src="{$smarty.const._THEME_PROD_PIC_DIR_}{$data['value']}_small" alt=""/>
						</a>
					{/if}
				</div>
			</div>
		{/foreach}

That's it ;-) 

ProductController.php

Edited by fatum (see edit history)

Share this post


Link to post
Share on other sites

Thanks fatum for taking the time to explain my reply :)

;-) you save me! thank you!

Edited by fatum (see edit history)

Share this post


Link to post
Share on other sites

This doesn't appear to be working on 1.6.1.7

:(

 

Bummer, because I really needed it to!

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More