Skip to content
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

Migrate "Orders > Shopping Carts" page #35007

Merged
1 change: 1 addition & 0 deletions admin-dev/themes/new-theme/.webpack/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ module.exports = {
country_form: './js/pages/country/form',
create_product: './js/pages/product/create/create-product',
create_product_default_theme: './scss/pages/product/create_product_default_theme.scss',
cart: './js/pages/cart',
},
output: {
publicPath: '',
Expand Down
51 changes: 51 additions & 0 deletions admin-dev/themes/new-theme/js/pages/cart/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* 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 license@prestashop.com 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 <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*
*/

import Grid from '@components/grid/grid';
import FiltersResetExtension from '@components/grid/extension/filters-reset-extension';
import SortingExtension from '@components/grid/extension/sorting-extension';
import BulkActionCheckboxExtension from '@components/grid/extension/bulk-action-checkbox-extension';
import SubmitBulkExtension from '@components/grid/extension/submit-bulk-action-extension';
import SubmitRowActionExtension from '@components/grid/extension/action/row/submit-row-action-extension';
import LinkRowActionExtension from '@components/grid/extension/link-row-action-extension';
import FiltersSubmitButtonEnablerExtension from '@components/grid/extension/filters-submit-button-enabler-extension';
import ExportToSqlManagerExtension from '@components/grid/extension/export-to-sql-manager-extension';
import ReloadListActionExtension from '@components/grid/extension/reload-list-extension';

const {$} = window;

$(() => {
const grid = new Grid('cart');
grid.addExtension(new ExportToSqlManagerExtension());
grid.addExtension(new ReloadListActionExtension());
grid.addExtension(new FiltersResetExtension());
grid.addExtension(new SortingExtension());
grid.addExtension(new BulkActionCheckboxExtension());
grid.addExtension(new SubmitBulkExtension());
grid.addExtension(new SubmitRowActionExtension());
grid.addExtension(new LinkRowActionExtension());
grid.addExtension(new FiltersSubmitButtonEnablerExtension());
});
7 changes: 7 additions & 0 deletions admin-dev/themes/new-theme/scss/components/layout/_kpi.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
}
}

&.-color4 {
.value,
> .material-icons {
color: #9e5ba1;
}
}

.title,
.subtitle,
.value {
Expand Down
4 changes: 4 additions & 0 deletions classes/lang/KeysReference/FeatureFlagLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@

trans('New front container', 'Admin.Advparameters.Feature');
trans('Enable / Disable the new front container.', 'Admin.Advparameters.Help');

// Carts index feature flag
trans('Carts', 'Admin.Advaparameters.Feature');
trans('Enable or Disable the migrated carts page.', 'Admin.Advparameters.Help');
1 change: 1 addition & 0 deletions install-dev/data/xml/feature_flag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
<feature_flag id="customer_threads" name="customer_threads" type="env,dotenv,db" label_wording="Customer threads" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the migrated customer threads page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="symfony_layout" name="symfony_layout" type="env,query,dotenv,db" label_wording="Symfony layout" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable symfony layout (in opposition to legacy layout)." description_domain="Admin.Advparameters.Help" state="1" stability="beta" />
<feature_flag id="front_container_v2" name="front_container_v2" type="env,dotenv,db" label_wording="New front container" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the new front container." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="carts" name="carts" type="env,dotenv,db" label_wording="Carts" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the migrated carts page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
</entities>
</entity_feature_flag>
97 changes: 97 additions & 0 deletions src/Adapter/Cart/CommandHandler/BulkDeleteCartHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?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 license@prestashop.com 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 <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Adapter\Cart\CommandHandler;

use PrestaShop\PrestaShop\Adapter\Cart\Repository\CartRepository;
use PrestaShop\PrestaShop\Adapter\Order\Repository\OrderRepository;
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsCommandHandler;
use PrestaShop\PrestaShop\Core\Domain\AbstractBulkCommandHandler;
use PrestaShop\PrestaShop\Core\Domain\Cart\Command\BulkDeleteCartCommand;
use PrestaShop\PrestaShop\Core\Domain\Cart\CommandHandler\BulkDeleteCartHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\BulkCartException;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CannotDeleteOrderedCartException;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CartException;
use PrestaShop\PrestaShop\Core\Domain\Cart\ValueObject\CartId;
use PrestaShop\PrestaShop\Core\Domain\Exception\BulkCommandExceptionInterface;
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException;
use PrestaShop\PrestaShop\Core\Exception\CoreException;

/**
* Deletes cart in bulk action using legacy object model
*/
#[AsCommandHandler]
class BulkDeleteCartHandler extends AbstractBulkCommandHandler implements BulkDeleteCartHandlerInterface
{
public function __construct(
protected readonly CartRepository $cartRepository,
protected readonly OrderRepository $orderRepository
) {
}

/**
* {@inheritdoc}
*
* @throws CartException
* @throws CoreException
*/
public function handle(BulkDeleteCartCommand $command): void
{
$this->handleBulkAction($command->getCartIds(), CartException::class);
}

protected function buildBulkException(array $caughtExceptions): BulkCommandExceptionInterface
{
return new BulkCartException(
$caughtExceptions,
'Errors occurred during Alias bulk delete action',
);
}

/**
* @param CartId $id
* @param mixed $command
*
* @return void
*/
protected function handleSingleAction(mixed $id, mixed $command): void
{
try {
$this->orderRepository->getByCartId($id);
throw new CannotDeleteOrderedCartException(sprintf('Cart "%s" with order cannot be deleted.', $id->getValue()));
} catch (OrderNotFoundException $e) {
// Cart is not linked to any order, we can safely delete it
$this->cartRepository->delete($id);
}
}

protected function supports($id): bool
{
return $id instanceof CartId;
}
}
73 changes: 73 additions & 0 deletions src/Adapter/Cart/CommandHandler/DeleteCartHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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 license@prestashop.com 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 <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Adapter\Cart\CommandHandler;

use PrestaShop\PrestaShop\Adapter\Cart\AbstractCartHandler;
use PrestaShop\PrestaShop\Adapter\Cart\Repository\CartRepository;
use PrestaShop\PrestaShop\Adapter\Order\Repository\OrderRepository;
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsCommandHandler;
use PrestaShop\PrestaShop\Core\Domain\Cart\Command\DeleteCartCommand;
use PrestaShop\PrestaShop\Core\Domain\Cart\CommandHandler\DeleteCartHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CannotDeleteCartException;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CannotDeleteOrderedCartException;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CartException;
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException;
use PrestaShop\PrestaShop\Core\Exception\CoreException;

/**
* Handles deletion of cart using legacy object model
*/
#[AsCommandHandler]
class DeleteCartHandler extends AbstractCartHandler implements DeleteCartHandlerInterface
{
public function __construct(
protected readonly CartRepository $cartRepository,
protected readonly OrderRepository $orderRepository
) {
}

/**
* {@inheritdoc}
*
* @throws CannotDeleteCartException
* @throws CannotDeleteOrderedCartException
* @throws CartException
* @throws CoreException
*/
public function handle(DeleteCartCommand $command): void
{
try {
$this->orderRepository->getByCartId($command->getCartId());
throw new CannotDeleteOrderedCartException(sprintf('Cart "%s" with order cannot be deleted.', $command->getCartId()->getValue()));
} catch (OrderNotFoundException $e) {
// Cart is not linked to any order, we can safely delete it
$this->cartRepository->delete($command->getCartId());
}
}
}
77 changes: 77 additions & 0 deletions src/Adapter/Cart/Repository/CartRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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 license@prestashop.com 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 <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Adapter\Cart\Repository;

use Cart;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CannotDeleteCartException;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CartException;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CartNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Cart\ValueObject\CartId;
use PrestaShop\PrestaShop\Core\Exception\CoreException;
use PrestaShop\PrestaShop\Core\Repository\AbstractObjectModelRepository;

class CartRepository extends AbstractObjectModelRepository
{
/**
* Retrieve Cart by CartId.
*
* @param CartId $cartId
*
* @return Cart
*
* @throws CartException
* @throws CoreException
*/
public function get(CartId $cartId): Cart
{
/** @var Cart $cart */
$cart = $this->getObjectModel(
$cartId->getValue(),
Cart::class,
CartNotFoundException::class
);

return $cart;
}

/**
* Delete Cart by CartId.
*
* @param CartId $cartId
*
* @return void
*
* @throws CartException
* @throws CoreException
*/
public function delete(CartId $cartId): void
{
$this->deleteObjectModel($this->get($cartId), CannotDeleteCartException::class);
}
}