From 10ef3c2af8ca3cc60ad3b1d4d9b61d5f163b95f7 Mon Sep 17 00:00:00 2001 From: Eike Ahmels Date: Tue, 31 Aug 2021 09:23:17 +0200 Subject: [PATCH 1/4] client side for order media upload --- .gitignore | 3 + .../Client/Html/Basket/Standard/Standard.php | 51 +- .../basket/standard/body-standard.php | 2 +- .../catalog/detail/body-standard.php | 7 +- .../common/partials/attribute-standard.php | 7 +- .../common/partials/products-standard.php | 5 +- .../common/summary/detail-standard.php | 17 + client/html/themes/default/aimeos.css | 17 +- client/html/themes/default/aimeos.js | 27 +- composer.json | 1 + composer.lock | 5431 +++++++++++++++++ 11 files changed, 5556 insertions(+), 12 deletions(-) create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index 16f1349e2..d23cf16a8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ client/html/tests/tmp *.junit.xml *.log *.ser + +.idea +vendor diff --git a/client/html/src/Client/Html/Basket/Standard/Standard.php b/client/html/src/Client/Html/Basket/Standard/Standard.php index 9ab8659fb..69fb1c221 100644 --- a/client/html/src/Client/Html/Basket/Standard/Standard.php +++ b/client/html/src/Client/Html/Basket/Standard/Standard.php @@ -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,16 @@ protected function addCoupon( \Aimeos\MW\View\Iface $view ) */ protected function addProducts( \Aimeos\MW\View\Iface $view ) { + $attrId = \Aimeos\MShop::create( $this->getContext(), 'attribute' )->find( 'custom', [], '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,15 +493,49 @@ protected function addProducts( \Aimeos\MW\View\Iface $view ) $list = []; $entries = (array) $view->param( 'b_prod', [] ); - foreach( $entries as $values ) + for($i = 0; $i < count($entries); ++$i) { + $paths = []; + 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()); + } + $paths[] = $filepath; + } + $entries[$i]['attrcustid'][$attrId] = $paths; + } + if( isset( $entries[$i]['prodid'] ) ) { + $list[] = $entries[$i]['prodid']; + } + } + /*foreach( $entries as $values ) { + if (isset( $values['attrcustid'][$attrId] )) { + $file = $values['attrcustid'][$attrId]; + $filepath = 'basket/' . 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()); + } + $values['attrcustid'][$attrId] = $filepath; + } if( isset( $values['prodid'] ) ) { $list[] = $values['prodid']; } - } + }*/ foreach( $entries as $values ) { + Log::debug(print_r($values, true)); if( ( $values['prodid'] ?? null ) && ( $values['quantity'] ?? 0 ) > 0 ) { $basketCntl->addProduct( $productCntl->get( $values['prodid'] ), diff --git a/client/html/templates/basket/standard/body-standard.php b/client/html/templates/basket/standard/body-standard.php index 06f5eca2a..2269e8d90 100644 --- a/client/html/templates/basket/standard/body-standard.php +++ b/client/html/templates/basket/standard/body-standard.php @@ -40,7 +40,7 @@ standardBasket ) ) : ?>

html( $this->translate( 'client', 'Basket' ), $enc::TRUST ) ?>

-
+ csrf()->formfield() ?> diff --git a/client/html/templates/catalog/detail/body-standard.php b/client/html/templates/catalog/detail/body-standard.php index 179dd012e..30e371da1 100644 --- a/client/html/templates/catalog/detail/body-standard.php +++ b/client/html/templates/catalog/detail/body-standard.php @@ -170,8 +170,11 @@ block()->get( 'catalog/detail/service' ) ?> - - + + csrf()->formfield() ?> diff --git a/client/html/templates/common/partials/attribute-standard.php b/client/html/templates/common/partials/attribute-standard.php index 3d0b6898b..7269ffcc4 100644 --- a/client/html/templates/common/partials/attribute-standard.php +++ b/client/html/templates/common/partials/attribute-standard.php @@ -188,7 +188,6 @@