Skip to content

Commit

Permalink
Fixed comments from @jolelievre
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Oct 22, 2019
1 parent f9927f9 commit 6691ede
Show file tree
Hide file tree
Showing 33 changed files with 97 additions and 117 deletions.
Expand Up @@ -221,7 +221,7 @@
<input onchange="checkPartialRefundProductAmount(this)" type="text" name="partialRefundProduct[{$product['id_order_detail']|intval}]" />
{if !$currencySymbolBeforeAmount}<div class="input-group-addon">{$currency->sign}</div>{/if}
</div>
<p class="help-block"><i class="icon-warning-sign"></i> {l s='(Max %amount_refundable% %tax_method%)' sprintf=[ '%amount_refundable%' => Context::getContext()->getCurrentLocale()->formatPrice($amount_refundable, Currency::getCurrencyInstance($currency->id)->iso_code), '%tax_method%' => $smarty.capture.TaxMethod] d='Admin.Orderscustomers.Help'}</p>
<p class="help-block"><i class="icon-warning-sign"></i> {l s='(Max %amount_refundable% %tax_method%)' sprintf=[ '%amount_refundable%' => Context::getContext()->getCurrentLocale()->formatPrice($amount_refundable, Currency::getIsoCodeById((int)$currency->id)), '%tax_method%' => $smarty.capture.TaxMethod] d='Admin.Orderscustomers.Help'}</p>
</div>
</div>
{/if}
Expand Down
Expand Up @@ -189,10 +189,10 @@
<input onchange="checkPartialRefundProductAmount(this)" type="text" name="partialRefundProduct[{$product['id_order_detail']}]" />
{if !$currencySymbolBeforeAmount}<div class="input-group-addon">{$currency->sign}</div>{/if}
</div>
<p class="help-block"><i class="icon-warning-sign"></i> {l
<p class="help-block"><i class="icon-warning-sign"></i> {if !is_null($amount_refundable)}{l
s='(Max %amount_refundable% %tax_method%)'
sprintf=['%amount_refundable%' => Context::getContext()->getCurrentLocale()->formatPrice(Tools::ps_round($amount_refundable, 2), Currency::getCurrencyInstance($currency->id)->iso_code), '%tax_method%' => $smarty.capture.TaxMethod]
d='Admin.Orderscustomers.Help'}</p>
sprintf=['%amount_refundable%' => Context::getContext()->getCurrentLocale()->formatPrice($amount_refundable, Currency::getIsoCodeById((int) $currency->id)), '%tax_method%' => $smarty.capture.TaxMethod]
d='Admin.Orderscustomers.Help'}{/if}</p>
</div>
</div>
{/if}
Expand Down
Expand Up @@ -1111,7 +1111,7 @@
</div>
<p class="help-block"><i class="icon-warning-sign"></i> {l
s='(Max %s %s)'
sprintf=[Context::getContext()->getCurrentLocale()->formatPrice(Tools::ps_round($shipping_refundable, 2), Currency::getCurrencyInstance($currency->id)->iso_code) , $smarty.capture.TaxMethod]
sprintf=[Context::getContext()->getCurrentLocale()->formatPrice($shipping_refundable, Currency::getIsoCodeById((int) $currency->id)) , $smarty.capture.TaxMethod]
d='Admin.Orderscustomers.Feature'
}
</p>
Expand Down
2 changes: 1 addition & 1 deletion classes/Cart.php
Expand Up @@ -1849,7 +1849,7 @@ public static function getTotalCart($id_cart, $use_tax_display = false, $type =

$with_taxes = $use_tax_display ? $cart->_taxCalculationMethod != PS_TAX_EXC : true;

return Context::getContext()->getCurrentLocale()->formatPrice($cart->getOrderTotal($with_taxes, $type), Currency::getCurrencyInstance((int) $cart->id_currency)->iso_code, false);
return Context::getContext()->getCurrentLocale()->formatPrice($cart->getOrderTotal($with_taxes, $type), Currency::getIsoCodeById((int) $cart->id_currency), false);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions classes/Currency.php
Expand Up @@ -612,6 +612,27 @@ public static function getIdByIsoCode($isoCode, $idShop = 0, $forceRefreshCache
return Cache::retrieve($cacheId);
}

/**
* Get Currency ISO Code by ID
*
* @param int $id
* @param bool $forceRefreshCache
*
* @return string
*/
public static function getIsoCodeById(int $id, bool $forceRefreshCache = false)
{
$cacheId = 'Currency::getIsoCodeById' . pSQL($id);
if ($forceRefreshCache || !Cache::isStored($cacheId)) {
$result = Currency::getCurrencyInstance($id);
Cache::store($cacheId, $result->iso_code);

return $result->iso_code;
}

return Cache::retrieve($cacheId);
}

/**
* Get Currency ID query.
*
Expand Down
2 changes: 1 addition & 1 deletion classes/Notification.php
Expand Up @@ -130,7 +130,7 @@ public static function getLastElementsIdsByType($type, $idLastElement)
'id_customer' => ((!empty($value['id_customer'])) ? (int) $value['id_customer'] : 0),
'id_customer_message' => ((!empty($value['id_customer_message'])) ? (int) $value['id_customer_message'] : 0),
'id_customer_thread' => ((!empty($value['id_customer_thread'])) ? (int) $value['id_customer_thread'] : 0),
'total_paid' => ((!empty($value['total_paid'])) ? Tools::getContextLocale(Context::getContext())->formatPrice((float) $value['total_paid'], Currency::getCurrencyInstance((int) $value['id_currency'])->iso_code) : 0),
'total_paid' => ((!empty($value['total_paid'])) ? Tools::getContextLocale(Context::getContext())->formatPrice((float) $value['total_paid'], Currency::getIsoCodeById((int) $value['id_currency'])) : 0),
'carrier' => ((!empty($value['name'])) ? Tools::safeOutput($value['name']) : ''),
'iso_code' => ((!empty($value['iso_code'])) ? Tools::safeOutput($value['iso_code']) : ''),
'company' => ((!empty($value['company'])) ? Tools::safeOutput($value['company']) : ''),
Expand Down
4 changes: 2 additions & 2 deletions classes/Product.php
Expand Up @@ -3674,7 +3674,7 @@ public static function convertPrice($params, &$smarty)
public static function convertPriceWithCurrency($params, &$smarty)
{
$currency = $params['currency'];
$currency = is_object($currency) ? $currency->iso_code : Currency::getCurrencyInstance($currency)->iso_code;
$currency = is_object($currency) ? $currency->iso_code : Currency::getIsoCodeById((int) $currency);

return Context::getContext()->getCurrentLocale()->formatPrice($params['price'], $currency);
}
Expand All @@ -3695,7 +3695,7 @@ public static function displayWtPrice($params, &$smarty)
public static function displayWtPriceWithCurrency($params, &$smarty)
{
$currency = $params['currency'];
$currency = is_object($currency) ? $currency->iso_code : Currency::getCurrencyInstance($currency)->iso_code;
$currency = is_object($currency) ? $currency->iso_code : Currency::getIsoCodeById((int) $currency);

return Context::getContext()->getCurrentLocale()->formatPrice($params['price'], $currency);
}
Expand Down
3 changes: 0 additions & 3 deletions classes/controller/AdminController.php
Expand Up @@ -416,9 +416,6 @@ public function __construct($forceControllerName = '', $default_theme_name = 'de
if (strpos($this->controller_name, 'ControllerOverride')) {
$this->controller_name = substr($this->controller_name, 0, -18);
}
if (strpos($this->controller_name, 'ControllerCore')) {
$this->controller_name = substr($this->controller_name, 0, -14);
}
if (strpos($this->controller_name, 'Controller')) {
$this->controller_name = substr($this->controller_name, 0, -10);
}
Expand Down
2 changes: 1 addition & 1 deletion classes/order/OrderHistory.php
Expand Up @@ -520,7 +520,7 @@ public function sendEmail($order, $template_vars = false)
}

$context = Context::getContext();
$data['{total_paid}'] = Tools::getContextLocale($context)->formatPrice((float) $order->total_paid, (new Currency((int) $order->id_currency))->iso_code);
$data['{total_paid}'] = Tools::getContextLocale($context)->formatPrice((float) $order->total_paid, Currency::getIsoCodeById((int) $order->id_currency));

if (Validate::isLoadedObject($order)) {
// Attach invoice and / or delivery-slip if they exists and status is set to attach them
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminCustomerThreadsController.php
Expand Up @@ -718,7 +718,7 @@ public function renderView()
$total_ok += $order['total_paid_real'] / $order['conversion_rate'];
}
$orders[$key]['date_add'] = Tools::displayDate($order['date_add']);
$orders[$key]['total_paid_real'] = $this->context->getCurrentLocale()->formatPrice($order['total_paid_real'], (new Currency((int) $order['id_currency']))->iso_code);
$orders[$key]['total_paid_real'] = $this->context->getCurrentLocale()->formatPrice($order['total_paid_real'], Currency::getIsoCodeById((int) $order['id_currency']));
}
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminOrdersController.php
Expand Up @@ -194,7 +194,7 @@ public static function setOrderCurrency($echo, $tr)
$idCurrency = (int) $order->id_currency;
}

return (new self())->context->getCurrentLocale()->formatPrice($echo, Currency::getCurrencyInstance($idCurrency)->iso_code);
return Context::getContext()->getCurrentLocale()->formatPrice($echo, Currency::getIsoCodeById((int) $idCurrency));
}

public function initPageHeaderToolbar()
Expand Down
4 changes: 2 additions & 2 deletions controllers/admin/AdminSuppliersController.php
Expand Up @@ -380,7 +380,7 @@ public function renderView()
$combination['id_product_attribute']
);
$comb_array[$combination['id_product_attribute']]['product_supplier_reference'] = $comb_infos['product_supplier_reference'];
$comb_array[$combination['id_product_attribute']]['product_supplier_price_te'] = $this->context->getCurrentLocale()->formatPrice($comb_infos['product_supplier_price_te'], (new Currency($comb_infos['id_currency']))->iso_code);
$comb_array[$combination['id_product_attribute']]['product_supplier_price_te'] = $this->context->getCurrentLocale()->formatPrice($comb_infos['product_supplier_price_te'], Currency::getIsoCodeById((int) $comb_infos['id_currency']));
$comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference'];
$comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13'];
$comb_array[$combination['id_product_attribute']]['upc'] = $combination['upc'];
Expand Down Expand Up @@ -411,7 +411,7 @@ public function renderView()
);
$products[$i]->product_supplier_reference = $product_infos['product_supplier_reference'];
$currencyId = $product_infos['id_currency'] ?: Currency::getDefaultCurrency()->id;
$products[$i]->product_supplier_price_te = $this->context->getCurrentLocale()->formatPrice($product_infos['product_supplier_price_te'], (new Currency($currencyId))->iso_code);
$products[$i]->product_supplier_price_te = $this->context->getCurrentLocale()->formatPrice($product_infos['product_supplier_price_te'], Currency::getIsoCodeById((int) $currencyId));
}
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/front/DiscountController.php
Expand Up @@ -125,7 +125,7 @@ protected function formatReductionAmount($hasTaxIncluded, $amount, $currencyId)

return sprintf(
'%s ' . $taxTranslation,
$this->context->getCurrentLocale()->formatPrice($amount, Currency::getCurrencyInstance((int) $currencyId)->iso_code)
$this->context->getCurrentLocale()->formatPrice($amount, Currency::getIsoCodeById((int) $currencyId))
);
}

Expand Down Expand Up @@ -188,7 +188,7 @@ protected function buildCartRuleFromVoucher(array $voucher): array
} else {
$voucher['voucher_minimal'] = $this->context->getCurrentLocale()->formatPrice(
$voucher['minimum_amount'],
Currency::getCurrencyInstance((int) $voucher['minimum_amount_currency'])->iso_code
Currency::getIsoCodeById((int) $voucher['minimum_amount_currency'])
);
}

Expand Down
8 changes: 3 additions & 5 deletions src/Adapter/Cart/QueryHandler/GetCartForViewingHandler.php
Expand Up @@ -40,7 +40,6 @@
use PrestaShop\PrestaShop\Core\Domain\Cart\QueryHandler\GetCartForViewingHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Cart\QueryResult\CartView;
use PrestaShop\PrestaShop\Core\Localization\Locale;
use PrestaShop\PrestaShop\Core\Localization\Locale\Repository as LocaleRepository;
use Product;
use StockAvailable;
use Validate;
Expand All @@ -62,13 +61,12 @@ final class GetCartForViewingHandler implements GetCartForViewingHandlerInterfac

/**
* @param ImageManager $imageManager
* @param LocaleRepository $localeRepository
* @param string $localeCode
* @param Locale $locale
*/
public function __construct(ImageManager $imageManager, LocaleRepository $localeRepository, string $localeCode)
public function __construct(ImageManager $imageManager, Locale $locale)
{
$this->imageManager = $imageManager;
$this->locale = $localeRepository->getLocale($localeCode);
$this->locale = $locale;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/Adapter/Cart/QueryHandler/GetCartInformationHandler.php
Expand Up @@ -45,7 +45,7 @@
use PrestaShop\PrestaShop\Core\Domain\Cart\QueryResult\CartInformation\CartShipping;
use PrestaShop\PrestaShop\Core\Localization\CLDR\LocaleInterface;
use PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException;
use PrestaShop\PrestaShop\Core\Localization\Locale\RepositoryInterface;
use PrestaShop\PrestaShop\Core\Localization\Locale;
use PrestaShopException;

/**
Expand All @@ -64,16 +64,14 @@ final class GetCartInformationHandler extends AbstractCartHandler implements Get
private $contextLangId;

/**
* @param RepositoryInterface $localeRepository
* @param string $locale
* @param Locale $locale
* @param int $contextLangId
*/
public function __construct(
RepositoryInterface $localeRepository,
string $locale,
Locale $locale,
int $contextLangId
) {
$this->locale = $localeRepository->getLocale($locale);
$this->locale = $locale;
$this->contextLangId = $contextLangId;
}

Expand Down
13 changes: 5 additions & 8 deletions src/Adapter/Customer/QueryHandler/GetCustomerCartsHandler.php
Expand Up @@ -33,29 +33,26 @@
use PrestaShop\PrestaShop\Core\Domain\Customer\Query\GetCustomerCarts;
use PrestaShop\PrestaShop\Core\Domain\Customer\QueryHandler\GetCustomerCartsHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Customer\QueryResult\CartSummary;
use PrestaShop\PrestaShop\Core\Localization\CLDR\LocaleInterface;
use PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException;
use PrestaShop\PrestaShop\Core\Localization\Locale\RepositoryInterface;
use PrestaShop\PrestaShop\Core\Localization\Locale;

/**
* Handles GetCustomerCartsQuery using legacy object models
*/
final class GetCustomerCartsHandler extends AbstractCustomerHandler implements GetCustomerCartsHandlerInterface
{
/**
* @var LocaleInterface
* @var Locale
*/
private $locale;

/**
* @param RepositoryInterface $localeRepository
* @param string $locale
* @param Locale $locale
*/
public function __construct(
RepositoryInterface $localeRepository,
string $locale
Locale $locale
) {
$this->locale = $localeRepository->getLocale($locale);
$this->locale = $locale;
}

/**
Expand Down
Expand Up @@ -63,7 +63,6 @@
use PrestaShop\PrestaShop\Core\Domain\Customer\QueryHandler\GetCustomerForViewingHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId;
use PrestaShop\PrestaShop\Core\Localization\Locale;
use PrestaShop\PrestaShop\Core\Localization\Locale\Repository as LocaleRepository;
use Product;
use Referrer;
use Shop;
Expand Down Expand Up @@ -107,21 +106,19 @@ final class GetCustomerForViewingHandler implements GetCustomerForViewingHandler
* @param TranslatorInterface $translator
* @param int $contextLangId
* @param Link $link
* @param LocaleRepository $localeRepository
* @param string $localeCode
* @param Locale $locale
*/
public function __construct(
TranslatorInterface $translator,
$contextLangId,
Link $link,
LocaleRepository $localeRepository,
string $localeCode
Locale $locale
) {
$this->context = new LegacyContext();
$this->contextLangId = $contextLangId;
$this->translator = $translator;
$this->link = $link;
$this->locale = $localeRepository->getLocale($localeCode);
$this->locale = $locale;
}

/**
Expand Down Expand Up @@ -263,7 +260,7 @@ private function getCustomerOrders(Customer $customer)
$order['total_paid_real_not_formated'] = $order['total_paid_real'];
$order['total_paid_real'] = $this->locale->formatPrice(
$order['total_paid_real'],
(new Currency((int) $order['id_currency']))->iso_code
Currency::getIsoCodeById((int) $order['id_currency'])
);

if (!isset($order['order_state'])) {
Expand Down
13 changes: 5 additions & 8 deletions src/Adapter/Customer/QueryHandler/GetCustomerOrdersHandler.php
Expand Up @@ -34,29 +34,26 @@
use PrestaShop\PrestaShop\Core\Domain\Customer\Query\GetCustomerOrders;
use PrestaShop\PrestaShop\Core\Domain\Customer\QueryHandler\GetCustomerOrdersHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\Customer\QueryResult\OrderSummary;
use PrestaShop\PrestaShop\Core\Localization\CLDR\LocaleInterface;
use PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException;
use PrestaShop\PrestaShop\Core\Localization\Locale\RepositoryInterface;
use PrestaShop\PrestaShop\Core\Localization\Locale;

/**
* Handles GetCustomerOrders query using legacy object models
*/
final class GetCustomerOrdersHandler extends AbstractCustomerHandler implements GetCustomerOrdersHandlerInterface
{
/**
* @var LocaleInterface
* @var Locale
*/
private $locale;

/**
* @param RepositoryInterface $localeRepository
* @param string $locale
* @param Locale $locale
*/
public function __construct(
RepositoryInterface $localeRepository,
string $locale
Locale $locale
) {
$this->locale = $localeRepository->getLocale($locale);
$this->locale = $locale;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/Adapter/Kpi/ShoppingCartTotalKpi.php
Expand Up @@ -33,7 +33,6 @@
use Order;
use PrestaShop\PrestaShop\Core\Kpi\KpiInterface;
use PrestaShop\PrestaShop\Core\Localization\Locale;
use PrestaShop\PrestaShop\Core\Localization\Locale\Repository as LocaleRepository;
use Validate;

/**
Expand All @@ -52,12 +51,11 @@ final class ShoppingCartTotalKpi implements KpiInterface
private $options;

/**
* @param LocaleRepository $localeRepository
* @param string $localeCode
* @param Locale $locale
*/
public function __construct(LocaleRepository $localeRepository, string $localeCode)
public function __construct(Locale $locale)
{
$this->locale = $localeRepository->getLocale($localeCode);
$this->locale = $locale;
}

/**
Expand All @@ -76,7 +74,7 @@ public function render()
$helper->subtitle = $translator->trans('Cart #%ID%', ['%ID%' => $cart->id], 'Admin.Orderscustomers.Feature');
$helper->value = $this->locale->formatPrice(
$this->getCartTotalPrice($cart),
\Currency::getCurrencyInstance((int) $cart->id_currency)->iso_code
\Currency::getIsoCodeById((int) $cart->id_currency)
);

return $helper->generate();
Expand Down

0 comments on commit 6691ede

Please sign in to comment.