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 6691ede commit d7b0b8e
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 37 deletions.
6 changes: 3 additions & 3 deletions classes/Currency.php
Expand Up @@ -624,10 +624,10 @@ 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);
$resultIsoCode = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `iso_code` FROM ' . _DB_PREFIX_ . 'currency WHERE `id_currency` = ' . (int) $id);
Cache::store($cacheId, $resultIsoCode);

return $result->iso_code;
return $resultIsoCode;
}

return Cache::retrieve($cacheId);
Expand Down
10 changes: 5 additions & 5 deletions src/Adapter/CombinationDataProvider.php
Expand Up @@ -30,7 +30,6 @@
use PrestaShop\Decimal\Number;
use PrestaShop\PrestaShop\Adapter\Product\ProductDataProvider;
use PrestaShop\PrestaShop\Core\Localization\Locale;
use PrestaShop\PrestaShop\Core\Localization\Locale\Repository as LocaleRepository;
use PrestaShopBundle\Form\Admin\Type\CommonAbstractType;
use Product;

Expand All @@ -54,13 +53,14 @@ class CombinationDataProvider
*/
private $locale;

public function __construct(LocaleRepository $repository)
/**
* @param Locale $locale
*/
public function __construct(Locale $locale)
{
$this->context = new LegacyContext();
$this->productAdapter = new ProductDataProvider();
$this->locale = $repository->getLocale(
$this->context->getContext()->language->getLocale()
);
$this->locale = $locale;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Adapter/Kpi/ShoppingCartTotalKpi.php
Expand Up @@ -28,6 +28,7 @@

use Cart;
use Context;
use Currency;
use Group;
use HelperKpi;
use Order;
Expand Down Expand Up @@ -74,7 +75,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::getIsoCodeById((int) $cart->id_currency)
Currency::getIsoCodeById((int) $cart->id_currency)
);

return $helper->generate();
Expand Down
23 changes: 11 additions & 12 deletions src/Adapter/Order/QueryHandler/GetOrderForViewingHandler.php
Expand Up @@ -29,7 +29,6 @@
use Address;
use Carrier;
use Configuration;
use Context;
use Country;
use Currency;
use Customer;
Expand Down Expand Up @@ -105,25 +104,25 @@ final class GetOrderForViewingHandler implements GetOrderForViewingHandlerInterf
private $translator;

/**
* @var Context
* @var int
*/
private $context;
private $contextLanguageId;

/**
* @param ImageTagSourceParserInterface $imageTagSourceParser
* @param TranslatorInterface $translator
* @param Context $context
* @param int $contextLanguageId
* @param Locale $locale
*/
public function __construct(
ImageTagSourceParserInterface $imageTagSourceParser,
TranslatorInterface $translator,
Context $context,
int $contextLanguageId,
Locale $locale
) {
$this->imageTagSourceParser = $imageTagSourceParser;
$this->translator = $translator;
$this->context = $context;
$this->contextLanguageId = $contextLanguageId;
$this->locale = $locale;
}

Expand Down Expand Up @@ -355,7 +354,7 @@ private function getOrderProducts(Order $order): OrderProductsForViewing
$stockLocationIsAvailable = true;
}

$pack_items = $product['cache_is_pack'] ? Pack::getItemTable($product['id_product'], $this->context->language->id, true) : array();
$pack_items = $product['cache_is_pack'] ? Pack::getItemTable($product['id_product'], $this->contextLanguageId, true) : array();
foreach ($pack_items as &$pack_item) {
$pack_item['current_stock'] = StockAvailable::getQuantityAvailableByProduct($pack_item['id_product'], $pack_item['id_product_attribute'], $pack_item['id_shop']);
// if the current stock requires a warning
Expand Down Expand Up @@ -456,7 +455,7 @@ private function setProductImageInformation(&$pack_item): void
*/
private function getOrderHistory(Order $order): OrderHistoryForViewing
{
$history = $order->getHistory($this->context->language->id);
$history = $order->getHistory($this->contextLanguageId);

$statuses = [];

Expand Down Expand Up @@ -503,7 +502,7 @@ private function getOrderDocuments(Order $order): OrderDocumentsForViewing

if ('invoice' === $type) {
$number = $document->getInvoiceNumberFormatted(
$this->context->language->id,
$this->contextLanguageId,
$order->id_shop
);

Expand All @@ -513,13 +512,13 @@ private function getOrderDocuments(Order $order): OrderDocumentsForViewing
} elseif ('delivery_slip' === $type) {
$number = sprintf(
'%s%06d',
Configuration::get('PS_DELIVERY_PREFIX', $this->context->language->id, null, $order->id_shop),
Configuration::get('PS_DELIVERY_PREFIX', $this->contextLanguageId, null, $order->id_shop),
$document->delivery_number
);
} elseif ('credit_slip' === $type) {
$number = sprintf(
'%s%06d',
Configuration::get('PS_CREDIT_SLIP_PREFIX', $this->context->language->id),
Configuration::get('PS_CREDIT_SLIP_PREFIX', $this->contextLanguageId),
$document->id
);
}
Expand Down Expand Up @@ -687,7 +686,7 @@ private function getOrderPayments(Order $order): OrderPaymentsForViewing
$currency = new Currency($payment->id_currency);
$invoice = $payment->getOrderInvoice($order->id);
$invoiceNumber = $invoice ?
$invoice->getInvoiceNumberFormatted($this->context->language->id, $order->id_shop) :
$invoice->getInvoiceNumberFormatted($this->contextLanguageId, $order->id_shop) :
null;

$orderPayments[] = new OrderPaymentForViewing(
Expand Down
19 changes: 8 additions & 11 deletions src/Adapter/Product/AdminProductWrapper.php
Expand Up @@ -39,10 +39,8 @@
use Language;
use ObjectModel;
use PrestaShop\PrestaShop\Adapter\Entity\Customization;
use PrestaShop\PrestaShop\Adapter\LegacyContext;
use PrestaShop\PrestaShop\Core\Foundation\Database\EntityNotFoundException;
use PrestaShop\PrestaShop\Core\Localization\Locale;
use PrestaShop\PrestaShop\Core\Localization\Locale\Repository as LocaleRepository;
use PrestaShopBundle\Utils\FloatParser;
use Product;
use ProductDownload;
Expand Down Expand Up @@ -76,23 +74,22 @@ class AdminProductWrapper
private $translator;

/**
* @var Context
* @var array
*/
private $legacyContext;
private $employeeAssociatedShops;

/**
* Constructor : Inject Symfony\Component\Translation Translator.
*
* @param object $translator
* @param LegacyContext $legacyContext
* @param LocaleRepository $localeRepository
* @param string $locale
* @param array $employeeAssociatedShops
* @param Locale $locale
*/
public function __construct($translator, $legacyContext, LocaleRepository $localeRepository, string $locale)
public function __construct($translator, array $employeeAssociatedShops, Locale $locale)
{
$this->translator = $translator;
$this->legacyContext = $legacyContext->getContext();
$this->locale = $localeRepository->getLocale($locale);
$this->employeeAssociatedShops = $employeeAssociatedShops;
$this->locale = $locale;
}

/**
Expand Down Expand Up @@ -482,7 +479,7 @@ public function getSpecificPricesList($product, $defaultCurrency, $shops, $curre
if (!$specific_price['id_shop'] || in_array($specific_price['id_shop'], Shop::getContextListShopID())) {
$can_delete_specific_prices = true;
if (Shop::isFeatureActive()) {
$can_delete_specific_prices = (count($this->legacyContext->employee->getAssociatedShops()) > 1 && !$specific_price['id_shop']) || $specific_price['id_shop'];
$can_delete_specific_prices = (count($this->employeeAssociatedShops) > 1 && !$specific_price['id_shop']) || $specific_price['id_shop'];
}

$price = Tools::ps_round($specific_price['price'], 2);
Expand Down
Expand Up @@ -75,7 +75,8 @@ services:

prestashop.adapter.data_provider.combination:
class: PrestaShop\PrestaShop\Adapter\CombinationDataProvider
arguments: ['@prestashop.core.localization.locale.repository']
arguments:
- "@prestashop.core.localization.locale.context_locale"

prestashop.adapter.data_provider.cms:
class: PrestaShop\PrestaShop\Adapter\CMS\CMSDataProvider
Expand Down
Expand Up @@ -113,7 +113,7 @@ services:
arguments:
- '@prestashop.core.image.parser.image_tag_source_parser'
- '@translator'
- '@=service("prestashop.adapter.legacy.context").getContext()'
- '@=service("prestashop.adapter.legacy.context").getContext().language.id'
- "@prestashop.core.localization.locale.context_locale"
tags:
- name: tactician.handler
Expand Down
Expand Up @@ -23,9 +23,8 @@ services:
class: PrestaShop\PrestaShop\Adapter\Product\AdminProductWrapper
arguments:
- "@translator"
- "@prestashop.adapter.legacy.context"
- "@prestashop.core.localization.locale.repository"
- '@=service("prestashop.adapter.legacy.context").getContext().language.getLocale()'
- "@=service('prestashop.adapter.legacy.context').getContext().employee.getAssociatedShops()"
- "@prestashop.core.localization.locale.context_locale"

prestashop.adapter.admin.controller.attribute_generator:
class: PrestaShop\PrestaShop\Adapter\Attribute\AdminAttributeGeneratorControllerWrapper
Expand Down

0 comments on commit d7b0b8e

Please sign in to comment.