From b1d48dbeef19b36cdc4792e17cfcf75f57c1ecae Mon Sep 17 00:00:00 2001 From: cquintini Date: Thu, 2 Mar 2023 18:33:35 -0400 Subject: [PATCH 0001/1030] Enable Order Creation in BO with a virtual product and a customer address that is from a Country that is not served by any carrier. --- .../js/pages/order/create/create-order-page.ts | 4 ++++ .../GetCartForOrderCreationHandler.php | 8 ++++++-- .../CartForOrderCreation/CartShipping.php | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/admin-dev/themes/new-theme/js/pages/order/create/create-order-page.ts b/admin-dev/themes/new-theme/js/pages/order/create/create-order-page.ts index 0ad971c7d73d4..f3d75cba88d3f 100644 --- a/admin-dev/themes/new-theme/js/pages/order/create/create-order-page.ts +++ b/admin-dev/themes/new-theme/js/pages/order/create/create-order-page.ts @@ -84,6 +84,7 @@ export interface CartShipping { giftMessage: string; recycledPackaging: boolean; selectedCarrierId: number | null | string; + virtual: boolean; } export interface CartSummary { @@ -732,6 +733,9 @@ export default class CreateOrderPage { $(createOrderMap.cartBlock).removeClass('d-none'); $(createOrderMap.cartBlock).data('cartId', cartInfo.cartId); + if(cartInfo.shipping.virtual){ + $(createOrderMap.shippingBlock).addClass('d-none'); + } } /** diff --git a/src/Adapter/Cart/QueryHandler/GetCartForOrderCreationHandler.php b/src/Adapter/Cart/QueryHandler/GetCartForOrderCreationHandler.php index dc04995c0bdb6..4f28c95c77ac5 100644 --- a/src/Adapter/Cart/QueryHandler/GetCartForOrderCreationHandler.php +++ b/src/Adapter/Cart/QueryHandler/GetCartForOrderCreationHandler.php @@ -359,7 +359,7 @@ private function extractShippingFromLegacySummary(Cart $cart, array $legacySumma $deliveryAddress = (int) $cart->id_address_delivery; //Check if there is any delivery options available for cart delivery address - if (!array_key_exists($deliveryAddress, $deliveryOptionsByAddress)) { + if (!array_key_exists($deliveryAddress, $deliveryOptionsByAddress) && !$cart->isVirtualCart()) { return null; } @@ -374,7 +374,8 @@ private function extractShippingFromLegacySummary(Cart $cart, array $legacySumma (int) $carrier->id ?: $this->defaultCarrierId ?: null, (bool) $cart->gift, (bool) $cart->recyclable, - $cart->gift_message + $cart->gift_message, + $cart->isVirtualCart() ); } @@ -389,6 +390,9 @@ private function extractShippingFromLegacySummary(Cart $cart, array $legacySumma private function fetchCartDeliveryOptions(array $deliveryOptionsByAddress, int $deliveryAddressId) { $deliveryOptions = []; + if(empty($deliveryOptionsByAddress)){ + return $deliveryOptions; + } // legacy multishipping feature allowed to split cart shipping to multiple addresses. // now when the multishipping feature is removed // the list of carriers should be shared across whole cart for single delivery address diff --git a/src/Core/Domain/Cart/QueryResult/CartForOrderCreation/CartShipping.php b/src/Core/Domain/Cart/QueryResult/CartForOrderCreation/CartShipping.php index 44df023d8a544..e482c8820e44f 100644 --- a/src/Core/Domain/Cart/QueryResult/CartForOrderCreation/CartShipping.php +++ b/src/Core/Domain/Cart/QueryResult/CartForOrderCreation/CartShipping.php @@ -66,6 +66,11 @@ class CartShipping */ private $giftMessage; + /** + * @var bool + */ + private $isVirtual; + /** * @param string $shippingPrice * @param bool $freeShipping @@ -74,6 +79,7 @@ class CartShipping * @param bool $isGift * @param bool $isRecycledPackaging * @param string $giftMessage + * @param bool $isVirtual */ public function __construct( string $shippingPrice, @@ -82,7 +88,8 @@ public function __construct( ?int $selectedCarrierId, bool $isGift, bool $isRecycledPackaging, - string $giftMessage + string $giftMessage, + bool $isVirtual ) { $this->shippingPrice = $shippingPrice; $this->freeShipping = $freeShipping; @@ -91,6 +98,7 @@ public function __construct( $this->isGift = $isGift; $this->isRecycledPackaging = $isRecycledPackaging; $this->giftMessage = $giftMessage; + $this->isVirtual = $isVirtual; } /** @@ -148,4 +156,12 @@ public function getGiftMessage(): string { return $this->giftMessage; } + + /** + * @return bool + */ + public function isVirtual(): bool + { + return $this->isVirtual; + } } From fd2e013595dee454ef018a91b4817b6dc24787c7 Mon Sep 17 00:00:00 2001 From: Cesar Quintini Date: Thu, 2 Mar 2023 19:13:03 -0400 Subject: [PATCH 0002/1030] Update create-order-page.ts fix format --- .../themes/new-theme/js/pages/order/create/create-order-page.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin-dev/themes/new-theme/js/pages/order/create/create-order-page.ts b/admin-dev/themes/new-theme/js/pages/order/create/create-order-page.ts index f3d75cba88d3f..6ef97e81beae4 100644 --- a/admin-dev/themes/new-theme/js/pages/order/create/create-order-page.ts +++ b/admin-dev/themes/new-theme/js/pages/order/create/create-order-page.ts @@ -733,7 +733,7 @@ export default class CreateOrderPage { $(createOrderMap.cartBlock).removeClass('d-none'); $(createOrderMap.cartBlock).data('cartId', cartInfo.cartId); - if(cartInfo.shipping.virtual){ + if (cartInfo.shipping.virtual) { $(createOrderMap.shippingBlock).addClass('d-none'); } } From f04accd03c1008452101c1b5664b1ef717fc229e Mon Sep 17 00:00:00 2001 From: Hlavtox Date: Fri, 3 Mar 2023 14:51:45 +0100 Subject: [PATCH 0003/1030] Do not interfere with PDF files --- classes/Tools.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/classes/Tools.php b/classes/Tools.php index 16e2f1ee2a6a9..303352a6a3fcb 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -2516,11 +2516,6 @@ public static function generateHtaccess($path = null, $rewrite_settings = null, Header set Access-Control-Allow-Origin \"*\" - - - Header set Content-Disposition \"Attachment\" - Header set X-Content-Type-Options \"nosniff\" - \n\n"); fwrite($write_fd, ' # Apache 2.2 From be75079bd132b40ec9749b46c0fe2069dda35eca Mon Sep 17 00:00:00 2001 From: Antonin 0x346e3730 CLAUZIER Date: Mon, 3 Oct 2022 19:18:40 +0400 Subject: [PATCH 0004/1030] Skip own profile when bulk delete --- .../CommandHandler/BulkDeleteProfileHandler.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Adapter/Profile/CommandHandler/BulkDeleteProfileHandler.php b/src/Adapter/Profile/CommandHandler/BulkDeleteProfileHandler.php index 7d569204ab0e9..cb3dfbcc0d39c 100644 --- a/src/Adapter/Profile/CommandHandler/BulkDeleteProfileHandler.php +++ b/src/Adapter/Profile/CommandHandler/BulkDeleteProfileHandler.php @@ -69,6 +69,7 @@ public function __construct($superAdminProfileId, ContextEmployeeProviderInterfa public function handle(BulkDeleteProfileCommand $command) { $entityIds = $command->getProfileIds(); + $exceptionToThrowLater = null; foreach ($entityIds as $entityId) { $entityIdValue = $entityId->getValue(); @@ -95,7 +96,17 @@ public function handle(BulkDeleteProfileCommand $command) } } catch (PrestaShopException $e) { throw new ProfileException(sprintf('Unexpected error occurred when deleting Profile with id %s', var_export($entityIdValue, true)), 0, $e); + } catch (FailedToDeleteProfileException $e) { + if ($e->getCode() === FailedToDeleteProfileException::PROFILE_IS_ASSIGNED_TO_CONTEXT_EMPLOYEE) { + $exceptionToThrowLater = $e; + continue; + } + throw $e; } } + + if ($exceptionToThrowLater) { + throw $exceptionToThrowLater; + } } } From ee646894c666a02de0a241f074c38b6553cd7bda Mon Sep 17 00:00:00 2001 From: Antonin 0x346e3730 CLAUZIER Date: Tue, 4 Oct 2022 13:19:05 +0400 Subject: [PATCH 0005/1030] Hide the checkbox for bulk actions for the current user's profile --- .../ProfileGridDataFactoryDecorator.php | 95 +++++++++++++++++++ .../services/core/grid/grid_data_factory.yml | 6 ++ .../services/core/grid/grid_factory.yml | 2 +- .../Columns/Content/bulk_action.html.twig | 2 +- 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/Core/Grid/Data/Factory/ProfileGridDataFactoryDecorator.php diff --git a/src/Core/Grid/Data/Factory/ProfileGridDataFactoryDecorator.php b/src/Core/Grid/Data/Factory/ProfileGridDataFactoryDecorator.php new file mode 100644 index 0000000000000..1d651d2039cde --- /dev/null +++ b/src/Core/Grid/Data/Factory/ProfileGridDataFactoryDecorator.php @@ -0,0 +1,95 @@ + + * @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\Core\Grid\Data\GridData; +use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection; +use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollectionInterface; +use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface; +use Symfony\Component\Security\Core\Security; + +/** + * Class ProfileGridDataFactory decorates data from profile doctrine data factory. + */ +final class ProfileGridDataFactoryDecorator implements GridDataFactoryInterface +{ + /** + * @var GridDataFactoryInterface + */ + private $profileGridDataFactory; + + /** + * @var Security + */ + private $security; + + public function __construct( + GridDataFactoryInterface $profileGridDataFactory, + Security $security + + ) { + $this->profileGridDataFactory = $profileGridDataFactory; + $this->security = $security; + } + + /** + * {@inheritdoc} + */ + public function getData(SearchCriteriaInterface $searchCriteria) + { + $profileData = $this->profileGridDataFactory->getData($searchCriteria); + + $profileRecords = $this->applyModifications($profileData->getRecords()); + + return new GridData( + $profileRecords, + $profileData->getRecordsTotal(), + $profileData->getQuery() + ); + } + + /** + * @param RecordCollectionInterface $profiles + * + * @return RecordCollection + */ + private function applyModifications(RecordCollectionInterface $profiles) + { + $modifiedProfiles = []; + + $currentUserIdProfile = $this->security->getUser()->getData()->id_profile; + foreach ($profiles as $profile) { + if ($profile['id_profile'] === $currentUserIdProfile) { + $profile['disableBulkCheckbox'] = true; + } + + $modifiedProfiles[] = $profile; + } + + return new RecordCollection($modifiedProfiles); + } +} diff --git a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_data_factory.yml b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_data_factory.yml index 1b92f519c89fe..63923eb3c06c5 100644 --- a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_data_factory.yml +++ b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_data_factory.yml @@ -186,6 +186,12 @@ services: - '@prestashop.core.grid.query.doctrine_query_parser' - 'profile' + prestashop.core.grid.data_factory.profiles_decorator: + class: 'PrestaShop\PrestaShop\Core\Grid\Data\Factory\ProfileGridDataFactoryDecorator' + arguments: + - '@prestashop.core.grid.data_factory.profiles' + - '@security.helper' + prestashop.core.grid.data_provider.cms_page_category: class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%' arguments: diff --git a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_factory.yml b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_factory.yml index c1aef65e774d5..ad4b02e03d81b 100644 --- a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_factory.yml +++ b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_factory.yml @@ -148,7 +148,7 @@ services: class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory' arguments: - '@prestashop.core.grid.definition.factory.profile' - - '@prestashop.core.grid.data_factory.profiles' + - '@prestashop.core.grid.data_factory.profiles_decorator' - '@prestashop.core.grid.filter.form_factory' - '@prestashop.core.hook.dispatcher' diff --git a/src/PrestaShopBundle/Resources/views/Admin/Common/Grid/Columns/Content/bulk_action.html.twig b/src/PrestaShopBundle/Resources/views/Admin/Common/Grid/Columns/Content/bulk_action.html.twig index b4f43a30aefb3..ca82eb08a67b2 100644 --- a/src/PrestaShopBundle/Resources/views/Admin/Common/Grid/Columns/Content/bulk_action.html.twig +++ b/src/PrestaShopBundle/Resources/views/Admin/Common/Grid/Columns/Content/bulk_action.html.twig @@ -23,7 +23,7 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) *#} -{% if column.options.disabled_field is empty or not record[column.options.disabled_field] %} +{% if (column.options.disabled_field is empty or not record[column.options.disabled_field]) and (record.disableBulkCheckbox is not defined or not record.disableBulkCheckbox) %}