-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add texture in attribute color #36068
Merged
tleon
merged 3 commits into
PrestaShop:develop
from
tleon:Issue-35591-bug-6-cant-add-texture
May 29, 2024
+353
−10
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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,52 @@ | ||||||||||
<?php | ||||||||||
/** | ||||||||||
* Copyright since 2007 PrestaShop SA and Contributors | ||||||||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||||||||||
* | ||||||||||
* NOTICE OF LICENSE | ||||||||||
* | ||||||||||
* This source file is subject to the Open Software License (OSL 3.0) | ||||||||||
* that is bundled with this package in the file LICENSE.md. | ||||||||||
* It is also available through the world-wide-web at this URL: | ||||||||||
* https://opensource.org/licenses/OSL-3.0 | ||||||||||
* If you did not receive a copy of the license and are unable to | ||||||||||
* obtain it through the world-wide-web, please send an email | ||||||||||
* to [email protected] so we can send you a copy immediately. | ||||||||||
* | ||||||||||
* DISCLAIMER | ||||||||||
* | ||||||||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||||||||||
* versions in the future. If you wish to customize PrestaShop for your | ||||||||||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||||||||||
* | ||||||||||
* @author PrestaShop SA and Contributors <[email protected]> | ||||||||||
* @copyright Since 2007 PrestaShop SA and Contributors | ||||||||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||||||||||
*/ | ||||||||||
|
||||||||||
namespace PrestaShop\PrestaShop\Adapter\File\Uploader; | ||||||||||
|
||||||||||
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\AttributeFileUploaderInterface; | ||||||||||
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Exception\AttributeUploadFailedException; | ||||||||||
use PrestaShop\PrestaShop\Core\File\Exception\FileException; | ||||||||||
|
||||||||||
class AttributeFileUploader implements AttributeFileUploaderInterface | ||||||||||
{ | ||||||||||
public function upload(string $filePath, int $id): void | ||||||||||
{ | ||||||||||
try { | ||||||||||
if (file_exists($filePath)) { | ||||||||||
move_uploaded_file($filePath, _PS_IMG_DIR_ . 'co/' . $id . '.jpg'); | ||||||||||
} | ||||||||||
} catch (FileException $e) { | ||||||||||
throw new AttributeUploadFailedException(sprintf('Failed to copy the file %s.', $filePath)); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
public function deleteOldFile(int $id): void | ||||||||||
{ | ||||||||||
if (file_exists(_PS_IMG_DIR_ . 'co/' . $id . '.jpg')) { | ||||||||||
unlink(_PS_IMG_DIR_ . 'co/' . $id . '.jpg'); | ||||||||||
Comment on lines
+48
to
+49
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.
Suggested change
|
||||||||||
} | ||||||||||
} | ||||||||||
} |
36 changes: 36 additions & 0 deletions
36
src/Core/Domain/AttributeGroup/Attribute/AttributeFileUploaderInterface.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,36 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute; | ||
|
||
interface AttributeFileUploaderInterface | ||
{ | ||
/** | ||
* @param string $filePath | ||
* @param int $id | ||
*/ | ||
public function upload(string $filePath, int $id): void; | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/Core/Domain/AttributeGroup/Attribute/Exception/AttributeUploadFailedException.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,31 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Exception; | ||
|
||
class AttributeUploadFailedException extends AttributeException | ||
{ | ||
} |
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,78 @@ | ||||||
<?php | ||||||
/** | ||||||
* Copyright since 2007 PrestaShop SA and Contributors | ||||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||||||
* | ||||||
* NOTICE OF LICENSE | ||||||
* | ||||||
* This source file is subject to the Open Software License (OSL 3.0) | ||||||
* that is bundled with this package in the file LICENSE.md. | ||||||
* It is also available through the world-wide-web at this URL: | ||||||
* https://opensource.org/licenses/OSL-3.0 | ||||||
* If you did not receive a copy of the license and are unable to | ||||||
* obtain it through the world-wide-web, please send an email | ||||||
* to [email protected] so we can send you a copy immediately. | ||||||
* | ||||||
* DISCLAIMER | ||||||
* | ||||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||||||
* versions in the future. If you wish to customize PrestaShop for your | ||||||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||||||
* | ||||||
* @author PrestaShop SA and Contributors <[email protected]> | ||||||
* @copyright Since 2007 PrestaShop SA and Contributors | ||||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||||||
*/ | ||||||
|
||||||
namespace PrestaShop\PrestaShop\Core\Grid\Data\Factory; | ||||||
|
||||||
use PrestaShop\PrestaShop\Adapter\Shop\Url\ImageFolderProvider; | ||||||
use PrestaShop\PrestaShop\Core\Grid\Data\GridData; | ||||||
use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection; | ||||||
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface; | ||||||
|
||||||
/** | ||||||
* Decorates database records for grid presentation | ||||||
*/ | ||||||
final class AttributeGridDataFactory implements GridDataFactoryInterface | ||||||
{ | ||||||
/** | ||||||
* @param GridDataFactoryInterface $attributeDataFactory | ||||||
*/ | ||||||
public function __construct( | ||||||
private readonly GridDataFactoryInterface $attributeDataFactory, | ||||||
private readonly ImageFolderProvider $imageFolderProvider | ||||||
) { | ||||||
} | ||||||
|
||||||
/** | ||||||
* {@inheritdoc} | ||||||
*/ | ||||||
public function getData(SearchCriteriaInterface $searchCriteria) | ||||||
{ | ||||||
$records = $this->attributeDataFactory->getData($searchCriteria); | ||||||
$modifiedRecords = $this->modifyRecords($records->getRecords()->all()); | ||||||
|
||||||
return new GridData( | ||||||
new RecordCollection($modifiedRecords), | ||||||
$records->getRecordsTotal(), | ||||||
$records->getQuery() | ||||||
); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param array $records | ||||||
* | ||||||
* @return array | ||||||
*/ | ||||||
private function modifyRecords(array $records): array | ||||||
{ | ||||||
foreach ($records as &$record) { | ||||||
if (file_exists(_PS_IMG_DIR_ . 'co/' . (int) $record['id_attribute'] . '.jpg')) { | ||||||
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.
Suggested change
|
||||||
$record['texture'] = $this->imageFolderProvider->getUrl() . '/' . (int) $record['id_attribute'] . '.jpg'; | ||||||
} | ||||||
} | ||||||
|
||||||
return $records; | ||||||
} | ||||||
} |
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 |
---|---|---|
|
@@ -15,3 +15,5 @@ services: | |
PrestaShop\PrestaShop\Adapter\Attribute\CommandHandler\EditAttributeHandler: ~ | ||
PrestaShop\PrestaShop\Adapter\Attribute\QueryHandler\GetAttributeForEditingHandler: ~ | ||
PrestaShop\PrestaShop\Adapter\Attribute\Validate\AttributeValidator: ~ | ||
PrestaShop\PrestaShop\Adapter\File\Uploader\AttributeFileUploader: ~ | ||
PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\AttributeFileUploaderInterface: ~ | ||
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. I think this isn't necessary, no? |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.