-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEW] upload media to order #153
base: master
Are you sure you want to change the base?
Changes from all commits
10ef3c2
9a6cc58
ff76dcf
4ae7dba
e20f3a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ client/html/tests/tmp | |
*.junit.xml | ||
*.log | ||
*.ser | ||
|
||
.idea | ||
vendor |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
namespace Aimeos\Client\Html\Basket\Standard; | ||
|
||
|
||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Http\UploadedFile; | ||
|
||
/** | ||
* Default implementation of standard basket HTML client. | ||
* | ||
|
@@ -458,8 +461,18 @@ protected function addCoupon( \Aimeos\MW\View\Iface $view ) | |
*/ | ||
protected function addProducts( \Aimeos\MW\View\Iface $view ) | ||
{ | ||
$attrIds[] = \Aimeos\MShop::create( $this->getContext(), 'attribute' )->find( 'custom', [], 'product', 'upload' )->getId(); | ||
|
||
$attrIds[] = \Aimeos\MShop::create( $this->getContext(), 'attribute' )->find( 'file', [], 'product', 'upload' )->getId(); | ||
|
||
$fs = $this->getContext()->fs( 'fs' ); | ||
|
||
if( !$fs->has('basket-upload' ) ) { | ||
$fs->mkdir( 'basket-upload' ); | ||
} | ||
|
||
$context = $this->getContext(); | ||
$domains = ['attribute', 'media', 'price', 'product', 'text']; | ||
$domains = ['attribute', 'media', 'price', 'product', 'text', 'custom']; | ||
|
||
$basketCntl = \Aimeos\Controller\Frontend::create( $context, 'basket' ); | ||
$productCntl = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $domains ); | ||
|
@@ -482,12 +495,29 @@ protected function addProducts( \Aimeos\MW\View\Iface $view ) | |
$list = []; | ||
$entries = (array) $view->param( 'b_prod', [] ); | ||
|
||
foreach( $entries as $values ) | ||
{ | ||
if( isset( $values['prodid'] ) ) { | ||
$list[] = $values['prodid']; | ||
for($i = 0; $i < count($entries); ++$i) { | ||
$paths = []; | ||
foreach ($attrIds as $attrId) { | ||
if (isset($entries[$i]['attrcustid'][$attrId]) && is_array($entries[$i]['attrcustid'][$attrId])) { | ||
/** @var UploadedFile $file */ | ||
foreach ($entries[$i]['attrcustid'][$attrId] as $file) { | ||
$filepath = 'basket-upload/' . md5($file->getFilename() . microtime(true)) . '.' . $file->extension(); | ||
try { | ||
$stream = fopen($file->getRealPath(), 'r+'); | ||
$fs->writes($filepath, $stream); | ||
fclose($stream); | ||
} catch (\Exception $ex) { | ||
Log::error($ex->getMessage()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
$paths[] = $filepath; | ||
} | ||
$entries[$i]['attrcustid'][$attrId] = $paths; | ||
} | ||
if (isset($entries[$i]['prodid'])) { | ||
$list[] = $entries[$i]['prodid']; | ||
} | ||
} | ||
} | ||
} | ||
|
||
foreach( $entries as $values ) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,36 @@ | |
|
||
|
||
?> | ||
<script type="text/javascript"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inline JS doesn't work with CSP and must be moved to the JS file |
||
function removeFile(event) { | ||
console.log($(event).parents('.upload-file-entry').remove()); | ||
} | ||
function slugName(name) { | ||
return name.toLowerCase().replaceAll(' ', '_').replaceAll('.', '_'); | ||
} | ||
function updateFileList() { | ||
$('input[type=file]').each((i, input) => { | ||
$('.upload-file-list').html(''); | ||
if(input.files && input.files.length > 0) { | ||
$('.upload-view').addClass('bg-success'); | ||
$('.upload-view').attr('data-title', $('.upload-view').attr('data-title').replace('hinzufügen', 'ändern')); | ||
for(let file of input.files) { | ||
const localUrl = URL.createObjectURL(file); | ||
$el = $('<div class="upload-file-entry"></div>'); | ||
$el.attr('id', `file-${slugName(file.name)}`); | ||
$el.append(`<img src="${localUrl}" alt="image">`); | ||
$el.append(`<span class="m-2">${file.name}</span>`); | ||
$('.upload-file-list').append($el); | ||
} | ||
} | ||
}) | ||
} | ||
if (window.fileListInterval) { | ||
clearInterval(window.fileListInterval); | ||
window.fileListInterval = null; | ||
} | ||
|
||
</script> | ||
<ul class="selection"> | ||
|
||
<?php foreach( $this->typemap( $this->productItem->getRefItems( 'attribute', null, 'config' ) ) as $code => $attributes ) : ?> | ||
|
@@ -188,9 +218,10 @@ | |
<ul class="selection"> | ||
|
||
<?php foreach( $this->productItem->getRefItems( 'attribute', null, 'custom' ) as $id => $attribute ) : $key = $attribute->getType() . '-' . $attribute->getCode() ?> | ||
|
||
<li class="select-item <?= $enc->attr( $key ) ?>"> | ||
<label for="select-<?= $enc->attr( $this->productItem->getId() . '-' . $key ) ?>" class="select-name"><?= $enc->html( $this->translate( 'client/code', $attribute->getName() ) ) ?></label> | ||
<?php if ( $attribute->getType() !== 'upload' ) { ?> | ||
<label for="select-<?= $enc->attr( $this->productItem->getId() . '-' . $key ) ?>" class="select-name"><?= $enc->html( $this->translate( 'client/code', $attribute->getName() ) ) ?></label> | ||
<?php } ?> | ||
|
||
<?php if( $hint = $this->translate( 'client/code', $key . '-hint', null, 0, false ) ) : ?> | ||
<div class="select-hint"><?= $enc->html( $hint ) ?></div> | ||
|
@@ -207,10 +238,26 @@ | |
> | ||
<?php break; case 'date': ?> | ||
<input id="select-<?= $enc->attr( $this->productItem->getId() . '-' . $key ) ?>" class="form-control" type="date" name="<?= $enc->attr( $this->formparam( ['b_prod', 0, 'attrcustid', $id] ) ) ?>"> | ||
<?php break;case 'upload': ?> | ||
<div class="upload-wrapper"> | ||
<div class="upload-view" | ||
data-title="<?= $enc->html( $this->translate( 'client/code', $attribute->getName() ) ) ?> Klicken zum hinzufügen." | ||
onclick="document.querySelector('#upload-<?= $enc->attr( $this->productItem->getId() . '-' . $key ) ?>').click()" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No inline JS please because this won't work because of Content Security Policy rules |
||
> | ||
</div> | ||
<input id="upload-<?= $enc->attr( $this->productItem->getId() . '-' . $key ) ?>" | ||
class="form-control hidden" | ||
type="file" | ||
name="<?= $enc->attr( $this->formparam( ['b_prod', 0, 'attrcustid', $id] ) ) ?>[]" | ||
multiple | ||
onchange="updateFileList()" | ||
> | ||
<div class="upload-file-list p-1"> | ||
</div> | ||
</div> | ||
<?php break; default: ?> | ||
<input id="select-<?= $enc->attr( $this->productItem->getId() . '-' . $key ) ?>" class="form-control" type="text" name="<?= $enc->attr( $this->formparam( ['b_prod', 0, 'attrcustid', $id] ) ) ?>"> | ||
<?php endswitch ?> | ||
|
||
</div> | ||
</li> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check return value of
fopen()