forked from Smile-SA/elasticsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Smile-SA#82 from Elastic-Suite/fix-esp170-visual-s…
…earch Fix esp170 visual search
- Loading branch information
Showing
17 changed files
with
477 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteVisualSearch | ||
* @author Pierre Gauthier <[email protected]> | ||
* @copyright 2021 Smile | ||
* @license Licensed to Smile-SA. All rights reserved. No warranty, explicit or implicit, provided. | ||
* Unauthorized copying of this file, via any medium, is strictly prohibited. | ||
*/ | ||
namespace Smile\ElasticsuiteVisualSearch\Block; | ||
|
||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Smile\ElasticsuiteVisualSearch\Model\SearchByImageManager; | ||
|
||
/** | ||
* Product visual search image preview block | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteVisualSearch | ||
* @author Pierre Gauthier <[email protected]> | ||
*/ | ||
class Image extends Template | ||
{ | ||
/** | ||
* @var SearchByImageManager | ||
*/ | ||
protected $searchByImageManager; | ||
|
||
/** | ||
* Result constructor. | ||
* @param Context $context Context. | ||
* @param SearchByImageManager $searchByImageManager Search by image manager. | ||
* @param array $data Data. | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
SearchByImageManager $searchByImageManager, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->searchByImageManager = $searchByImageManager; | ||
} | ||
|
||
/** | ||
* Get search image url. | ||
* | ||
* @return string | ||
* @throws NoSuchEntityException | ||
*/ | ||
public function getSearchImageUrl(): string | ||
{ | ||
return $this->searchByImageManager->getImageUrl(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/module-elasticsuite-visual-search/Controller/Search/UploadImage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteVisualSearch | ||
* @author Pierre Gauthier <[email protected]> | ||
* @copyright 2021 Smile | ||
* @license Licensed to Smile-SA. All rights reserved. No warranty, explicit or implicit, provided. | ||
* Unauthorized copying of this file, via any medium, is strictly prohibited. | ||
*/ | ||
namespace Smile\ElasticsuiteVisualSearch\Controller\Search; | ||
|
||
use Magento\Catalog\Model\Session; | ||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\App\Action\Context; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Controller\ResultInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Smile\ElasticsuiteVisualSearch\Model\ImageUploader; | ||
|
||
/** | ||
* Upload image. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteVisualSearch | ||
* @author Pierre Gauthier <[email protected]> | ||
* @see https://qastack.fr/magento/211985/how-to-recreate-magento-2-backend-image-upload-in-frontend | ||
*/ | ||
class UploadImage extends Action | ||
{ | ||
/** | ||
* @var ImageUploader | ||
*/ | ||
protected $imageFileUploader; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
protected $storeManager; | ||
|
||
/** | ||
* @param Context $context Contexte. | ||
* @param StoreManagerInterface $storeManager Store Manger. | ||
* @param ImageUploader $imageFileUploader Image File Uploader. | ||
* @param Session $session Session. | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
StoreManagerInterface $storeManager, | ||
ImageUploader $imageFileUploader, | ||
Session $session | ||
) { | ||
parent::__construct($context); | ||
$this->storeManager = $storeManager; | ||
$this->imageFileUploader = $imageFileUploader; | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* Image upload action | ||
* | ||
* @return ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
$result = $this->imageFileUploader->saveImageToMediaFolder('search-image'); | ||
$this->session->setData('visual_search_image_path', $result['file']); | ||
|
||
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.