Offer file upload for customer - Possible

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Innonic
Posts: 43
Joined: 24 Nov 2015, 21:03

Offer file upload for customer - Possible

Post by Innonic » 10 Aug 2017, 09:50

I tried to search the forum with several terms, but the search always answers like this:
The following words in your search query were ignored because they are too common words: upload customer file.
I don't know, how to search differently so I decided to quickly ask here:

So if I would like to offer my customers an upload, let's say for images to create individual products.
I would like to embed it in the product description to make the customer to be able to say "I want that product with my uploaded picture on it.".
Is that possible? How?

Thank you very much!

User avatar
aimeos
Administrator
Posts: 7835
Joined: 01 Jan 1970, 00:00

Re: Offer file upload for customer - Possible

Post by aimeos » 10 Aug 2017, 22:43

Not out of the box but this could be implemented in a very similar way to custom text using attributes.
If you are able to implement that, we would love to integrate it into the Aimeos core. Otherwise, you can ask the Aimeos company.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Innonic
Posts: 43
Joined: 24 Nov 2015, 21:03

Re: Offer file upload for customer - Possible

Post by Innonic » 11 Aug 2017, 10:42

Thank you for your quick response.

If I find enough time to do that, I'll let you know first.

bozo
Posts: 6
Joined: 08 Dec 2020, 07:13

Re: Offer file upload for customer - Possible

Post by bozo » 08 Dec 2020, 07:34

This is an old post, but this is the function I'm looking for.

I could set "upload" using admin page similar way to custom text using attributes. I found where to extended attribute-standard.php.

File upload only visible, but not working. I don't know how to set parameters properly.

How to make uploadform work, and where to get filename for hidden input element?

Aimeos version: 2020.x
PHP version: 7.4
environment: Linux and Win

User avatar
aimeos
Administrator
Posts: 7835
Joined: 01 Jan 1970, 00:00

Re: Offer file upload for customer - Possible

Post by aimeos » 09 Dec 2020, 08:41

In the admin interface there are already file uploads available (media and download tab), so you can upload all files you need. The original topic was about uploading files by customers in the frontend I think.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

bozo
Posts: 6
Joined: 08 Dec 2020, 07:13

Re: Offer file upload for customer - Possible

Post by bozo » 09 Dec 2020, 09:58

Sorry for the misleading information.

I mentioned admin page as I was using it for configuration. I created and added new custom attribute with it. Afterwards I planned to customize this.

I added it in order to implement customer image upload. To provide image upload possibility for t-shirts or mugs for example.

User avatar
aimeos
Administrator
Posts: 7835
Joined: 01 Jan 1970, 00:00

Re: Offer file upload for customer - Possible

Post by aimeos » 09 Dec 2020, 10:41

Add a new attribute type "upload" here:
https://github.com/aimeos/aimeos-core/b ... hp#L18-L20
and a new attribute "custom" for the type "upload" here:
https://github.com/aimeos/aimeos-core/b ... php#L7-L16

Then, you need to add a new case for "upload" here including the input field for uploads:
https://github.com/aimeos/ai-client-htm ... #L168-L179

Afterwards, extend the basket/standard component to store the uploaded file:
https://github.com/aimeos/ai-client-htm ... #L463-L514

Use the PSR-7 request and the filesystem object for that, i.e. something like this:

Code: Select all

$attrId = \Aimeos\MShop::create( $this->getContext(), 'attribute' )->find( 'custom', [], 'product', 'upload' )->getId();
$files = $view->request()->getUploadedFiles();
$fs = $this->getContext()->fs( 'fs-secure' );

if( !$fs->has('basket' ) ) {
	$fs->mkdir( 'basket' );
}

foreach( $files as $file )
{
	$filepath = 'basket/' . md5( $file->getClientFilename() . mypid() . microtime(true) );
	$fs->writes( $filepath, $file->getStream() );
	$values['attrcustid'][$attrId] = $filepath;
}
See https://www.php-fig.org/psr/psr-7/ and https://github.com/aimeos/aimeos-core/b ... /Iface.php

After implementing the code, the file should be stored and the custom upload attribute is saved as order base product attribute. Finally, you have to think about how to retrieve that data for fulfillment.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

bozo
Posts: 6
Joined: 08 Dec 2020, 07:13

Re: Offer file upload for customer - Possible

Post by bozo » 09 Dec 2020, 12:36

Thank you for Your time and the detailed explanation!

I tried to do similar way, the given steps helps me to see how the whole flow works!

I was able to visualize the file upload input form element, I could browse files.
After submit(checkout) the file data not included in the post.

Code: Select all

	<?php break; case 'upload': ?>
               <input id="select-<?= $enc->attr( $key ) ?>" 
		      class="form-control" 
                       type="file" 
		     name="<?= $enc->attr( $this->formparam( ['b_prod', 0, 'attrcustid', $id] ) ); ?>" 
               />
               
		<input type="hidden" 
		         name="<?= $enc->attr( $this->formparam( ['b_prod', 0, 'attrcustid', $id] ) ); ?>" 
               />		
I have also added a hidden element, which is appearing in the POST, but this is always empty. Actually this is understandable.
I wonder if an on-change function is missing? or something similar?

I only can think of using some javascript code, but I would prefer the aimeos way of implementation.

So the main problem now, how to include the file data into the post?

User avatar
aimeos
Administrator
Posts: 7835
Joined: 01 Jan 1970, 00:00

Re: Offer file upload for customer - Possible

Post by aimeos » 11 Dec 2020, 11:56

Remove the hidden field. The uploaded file should be available in this structure returned by getUploadedFiles():

Code: Select all

[
	'b_prod' => [
		0 => [
			'attrcustid' => [
				'<id>' => <UploadedFile Object>
			]
		]
	]
]
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

bozo
Posts: 6
Joined: 08 Dec 2020, 07:13

Re: Offer file upload for customer - Possible

Post by bozo » 11 Dec 2020, 16:15

I tried many ways... it doesn't show up. :roll:

I assume getUploadedFiles() is the controller end, so first should appear in the POST.

This is what I can see now in the POST: (after removing hidden field)

Code: Select all

{
	"_token": "KKMavkREgf4HMCdOqdKYHSfeoGLN3F28zg5sHIGZ",
	"b_action": "add",
	"b_prod[0][prodid]": "8",
	"b_prod[0][quantity]": "1"
}
if I print the form attribute name in attribute-standard.php to see what should I expect:

Code: Select all

<?= $enc->attr( $this->formparam( ['b_prod', 0, 'attrcustid', $id] ) ); ?>
I get this:

Code: Select all

b_prod[0][attrcustid][20]
I can POST any data but file. I was thinking whether the root cause of my problem is that the post is not multipart.

So I edited body-standard.php and added enctype="multipart/form-data" to form tag. No change.

Code: Select all

<form method="POST" enctype="multipart/form-data" action="<?= $enc->attr( $this->url( $basketTarget, $basketController, $basketAction, ( $basketSite ? ['site' => $basketSite] : [] ), [], $basketConfig ) ); ?>">

Post Reply