-
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 4 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 |
---|---|---|
|
@@ -188,7 +188,6 @@ | |
<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> | ||
|
||
|
@@ -207,6 +206,19 @@ | |
> | ||
<?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() ) ) ?>" | ||
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> | ||
</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 ?> | ||
|
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()