JEMBOT MAWOT Bypass Shell
<?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)
*/
namespace PrestaShop\PrestaShop\Adapter\Order\CommandHandler;
use Cart;
use Currency;
use Customer;
use Hook;
use Order;
use OrderDetail;
use OrderInvoice;
use PrestaShop\PrestaShop\Adapter\ContextStateManager;
use PrestaShop\PrestaShop\Adapter\Order\OrderProductQuantityUpdater;
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderException;
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Order\Product\Command\DeleteProductFromOrderCommand;
use PrestaShop\PrestaShop\Core\Domain\Order\Product\CommandHandler\DeleteProductFromOrderHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Order\ValueObject\OrderId;
use Shop;
use Validate;
/**
* @internal
*/
final class DeleteProductFromOrderHandler extends AbstractOrderCommandHandler implements DeleteProductFromOrderHandlerInterface
{
/**
* @var ContextStateManager
*/
private $contextStateManager;
/**
* @var OrderProductQuantityUpdater
*/
private $orderProductQuantityUpdater;
/**
* @param ContextStateManager $contextStateManager
* @param OrderProductQuantityUpdater $orderProductQuantityUpdater
*/
public function __construct(
ContextStateManager $contextStateManager,
OrderProductQuantityUpdater $orderProductQuantityUpdater
) {
$this->contextStateManager = $contextStateManager;
$this->orderProductQuantityUpdater = $orderProductQuantityUpdater;
}
/**
* {@inheritdoc}
*/
public function handle(DeleteProductFromOrderCommand $command)
{
$orderDetail = new OrderDetail($command->getOrderDetailId());
$order = new Order($command->getOrderId()->getValue());
$this->assertProductCanBeDeleted($order, $orderDetail);
$cart = new Cart($order->id_cart);
$this->contextStateManager
->setCart($cart)
->setCurrency(new Currency($order->id_currency))
->setCustomer(new Customer($order->id_customer))
->setShop(new Shop($order->id_shop))
;
try {
$order = $this->orderProductQuantityUpdater->update(
$order,
$orderDetail,
0,
$orderDetail->id_order_invoice != 0 ? new OrderInvoice($orderDetail->id_order_invoice) : null
);
Hook::exec('actionOrderEdited', ['order' => $order]);
} finally {
$this->contextStateManager->restorePreviousContext();
}
}
/**
* @param Order $order
* @param OrderDetail $orderDetail
*/
private function assertProductCanBeDeleted(Order $order, OrderDetail $orderDetail)
{
if (!Validate::isLoadedObject($orderDetail)) {
throw new OrderException('Order detail could not be found.');
}
if (!Validate::isLoadedObject($order)) {
throw new OrderNotFoundException(new OrderId((int) $order->id), 'Order could not be found.');
}
if ($orderDetail->id_order != $order->id) {
throw new OrderException('Order detail does not belong to order.');
}
// We can't edit a delivered order
if ($order->hasBeenDelivered()) {
throw new OrderException('Delivered order cannot be modified.');
}
}
}
xxxxx1.0, XXX xxxx