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;
use Cart;
use Combination;
use Configuration;
use Currency;
use Customer;
use Group;
use Order;
use PrestaShop\PrestaShop\Adapter\Number\RoundModeConverter;
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderException;
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Order\ValueObject\OrderId;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\ProductId;
use PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision;
use PrestaShopException;
use Product;
use Validate;
/**
* Reusable methods for Order subdomain command/query handlers.
*/
abstract class AbstractOrderHandler
{
/**
* @param OrderId $orderId
*
* @return Order
*/
protected function getOrder(OrderId $orderId)
{
try {
$order = new Order($orderId->getValue());
} catch (PrestaShopException $e) {
throw new OrderException(
sprintf(
'Error occured when trying to get order object #%s',
$orderId->getValue()
),
0,
$e
);
}
if ($order->id !== $orderId->getValue()) {
throw new OrderNotFoundException($orderId, sprintf('Order with id "%d" was not found.', $orderId->getValue()));
}
return $order;
}
/**
* @param Order $order
*
* @return bool
*/
protected function isTaxIncludedInOrder(Order $order): bool
{
return $this->getOrderTaxCalculationMethod($order) === PS_TAX_INC;
}
/**
* @param Order $order
*
* @return int
*/
protected function getOrderTaxCalculationMethod(Order $order): int
{
$customer = new Customer($order->id_customer);
return Group::getPriceDisplayMethod((int) $customer->id_default_group);
}
/**
* @param Cart $cart
*
* @return int
*/
protected function getPrecisionFromCart(Cart $cart): int
{
$computingPrecision = new ComputingPrecision();
$currency = new Currency((int) $cart->id_currency);
return $computingPrecision->getPrecision($currency->precision);
}
/**
* @param int $combinationId
*
* @return Combination|null
*/
protected function getCombination(int $combinationId)
{
$combination = null;
if (0 !== $combinationId) {
$combination = new Combination($combinationId);
if (!Validate::isLoadedObject($combination)) {
throw new OrderException('Product combination not found.');
}
}
return $combination;
}
/**
* @param ProductId $productId
* @param int $langId
*
* @return Product
*/
protected function getProduct(ProductId $productId, $langId)
{
$product = new Product($productId->getValue(), false, $langId);
if ($product->id !== $productId->getValue()) {
throw new OrderException(sprintf('Product with id "%d" is invalid.', $productId->getValue()));
}
return $product;
}
/**
* @return string
*/
protected function getNumberRoundMode(): string
{
return RoundModeConverter::getNumberRoundMode((int) Configuration::get('PS_PRICE_ROUND_MODE'));
}
/**
* Delivery option consists of deliveryAddress and carrierId.
*
* Legacy multishipping feature used comma separated carriers in delivery option (e.g. {'1':'6,7'}
* Now that multishipping is gone - delivery option should consist of one carrier and one address.
*
* However the structure of deliveryOptions is still used with comma in legacy, so
* this method provides assurance for deliveryOption structure until major refactoring
*
* @param int $carrierId
*
* @return string
*/
protected function formatLegacyDeliveryOptionFromCarrierId(int $carrierId): string
{
return sprintf('%d,', $carrierId);
}
}
xxxxx1.0, XXX xxxx