Skip to content

Commit

Permalink
Merge pull request #17000 from matks/merge2develop
Browse files Browse the repository at this point in the history
Merge 1.7.6.x into develop - 01/01/2020
  • Loading branch information
matks committed Jan 2, 2020
2 parents dbe5762 + e9dfe70 commit 66dfde9
Show file tree
Hide file tree
Showing 19 changed files with 235 additions and 106 deletions.
38 changes: 9 additions & 29 deletions classes/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision;
use PrestaShop\PrestaShop\Core\Localization\Locale;
use PrestaShopBundle\Translation\Loader\SqlTranslationLoader;
use PrestaShopBundle\Translation\TranslatorComponent as Translator;
use PrestaShopBundle\Translation\TranslatorLanguageLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Translation\Loader\XliffFileLoader;

/**
* Class ContextCore.
Expand Down Expand Up @@ -410,9 +409,7 @@ public function getTranslatorFromLocale($locale)

// In case we have at least 1 translated message, we return the current translator.
// If some translations are missing, clear cache
if ($locale === '' || count($translator->getCatalogue($locale)->all())) {
$this->translator = $translator;

if ($locale === '' || null === $locale || count($translator->getCatalogue($locale)->all())) {
return $translator;
}

Expand All @@ -427,31 +424,14 @@ public function getTranslatorFromLocale($locale)
(new Filesystem())->remove($cache_file);
}

$adminContext = defined('_PS_ADMIN_DIR_');
$translator->addLoader('xlf', new XliffFileLoader());

$sqlTranslationLoader = new SqlTranslationLoader();
if (null !== $this->shop) {
$sqlTranslationLoader->setTheme($this->shop->theme);
}

$translator->addLoader('db', $sqlTranslationLoader);
$notName = $adminContext ? '^Shop*' : '^Admin*';
$translator->clearLanguage($locale);

$finder = Finder::create()
->files()
->name('*.' . $locale . '.xlf')
->notName($notName)
->in($this->getTranslationResourcesDirectories());

foreach ($finder as $file) {
list($domain, $locale, $format) = explode('.', $file->getBasename(), 3);

$translator->addResource($format, $file, $locale, $domain);
if (!$this->language instanceof PrestashopBundle\Install\Language) {
$translator->addResource('db', $domain . '.' . $locale . '.db', $locale, $domain);
}
}
$adminContext = defined('_PS_ADMIN_DIR_');
// Do not load DB translations when $this->language is PrestashopBundle\Install\Language
// because it means that we're looking for the installer translations, so we're not yet connected to the DB
$withDB = !$this->language instanceof PrestashopBundle\Install\Language;
$theme = $this->shop !== null ? $this->shop->theme : null;
(new TranslatorLanguageLoader($adminContext))->loadLanguage($translator, $locale, $withDB, $theme);

return $translator;
}
Expand Down
9 changes: 7 additions & 2 deletions classes/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use PrestaShop\PrestaShop\Core\Domain\MailTemplate\Command\GenerateThemeMailTemplatesCommand;
use PrestaShop\PrestaShop\Core\CommandBus\CommandBusInterface;
use PrestaShop\PrestaShop\Core\Language\LanguageInterface;
use PrestaShopBundle\Translation\TranslatorLanguageLoader;

class LanguageCore extends ObjectModel implements LanguageInterface
{
Expand Down Expand Up @@ -1461,7 +1462,11 @@ private static function updateMultilangFromClassForShop($tableName, $classObject
{
$shopDefaultLangId = Configuration::get('PS_LANG_DEFAULT', null, $shop->id_shop_group, $shop->id);
$shopDefaultLanguage = new Language($shopDefaultLangId);
$translatorDefaultShopLanguage = Context::getContext()->getTranslatorFromLocale($shopDefaultLanguage->locale);

$translator = SymfonyContainer::getInstance()->get('translator');
if (!$translator->isLanguageLoaded($shopDefaultLanguage->locale)) {
(new TranslatorLanguageLoader(true))->loadLanguage($translator, $shopDefaultLanguage->locale);
}

$shopFieldExists = $primary_key_exists = false;
$columns = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . $tableName . '`');
Expand Down Expand Up @@ -1500,7 +1505,7 @@ private static function updateMultilangFromClassForShop($tableName, $classObject
continue;
}

$untranslated = $translatorDefaultShopLanguage->getSourceString($data[$toUpdate], $classObject->getDomain());
$untranslated = $translator->getSourceString($data[$toUpdate], $classObject->getDomain());
$translatedField = $classObject->getFieldValue($toUpdate, $untranslated);

if (!empty($translatedField) && $translatedField != $data[$toUpdate]) {
Expand Down
4 changes: 2 additions & 2 deletions classes/ObjectModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1446,9 +1446,9 @@ public function validateFieldsRequiredDatabase($htmlentities = true)
throw new PrestaShopException('Validation function not found. ' . $data['validate']);
}

$value = Tools::getValue($field);
$value = Tools::getValue($field, null);

if (empty($value)) {
if ($value === null) {
$errors[$field] = $this->trans('The field %s is required.', array(self::displayFieldName($field, get_class($this), $htmlentities)), 'Admin.Notifications.Error');
}
}
Expand Down
13 changes: 10 additions & 3 deletions classes/controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,20 @@ public function __construct($forceControllerName = '', $default_theme_name = 'de
}

$this->bo_theme = $default_theme_name;

if (!@filemtime(_PS_BO_ALL_THEMES_DIR_ . $this->bo_theme . DIRECTORY_SEPARATOR . 'template')) {
$this->bo_theme = 'default';
}

$this->bo_css = ((Validate::isLoadedObject($this->context->employee)
&& $this->context->employee->bo_css) ? $this->context->employee->bo_css : 'theme.css');
$this->context->employee->bo_theme = (
Validate::isLoadedObject($this->context->employee)
&& $this->context->employee->bo_theme
) ? $this->context->employee->bo_theme : $this->bo_theme;

$this->bo_css = (
Validate::isLoadedObject($this->context->employee)
&& $this->context->employee->bo_css
) ? $this->context->employee->bo_css : 'theme.css';
$this->context->employee->bo_css = $this->bo_css;

$adminThemeCSSFile = _PS_BO_ALL_THEMES_DIR_ . $this->bo_theme . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . $this->bo_css;

Expand Down
30 changes: 7 additions & 23 deletions classes/lang/DataLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShopBundle\Translation\TranslatorComponent as Translator;
use PrestaShopBundle\Translation\TranslatorLanguageLoader;

/**
* DataLang classes are used by Language
Expand Down Expand Up @@ -53,30 +55,12 @@ public function __construct($locale)
{
$this->locale = $locale;

$legacyTranslator = Context::getContext()->getTranslator();
$legacyLocale = $legacyTranslator->getLocale();
$this->translator = SymfonyContainer::getInstance()->get('translator');
$isAdminContext = defined('_PS_ADMIN_DIR_');

if ($legacyLocale === $this->locale) {
$this->translator = $legacyTranslator;
} else {
$this->translator = new Translator(
$this->locale,
null,
_PS_CACHE_DIR_ . '/translations/' . $this->locale,
false
);

$this->translator->addLoader('xlf', new \Symfony\Component\Translation\Loader\XliffFileLoader());

$finder = \Symfony\Component\Finder\Finder::create()
->files()
->name('*.' . $this->locale . '.xlf')
->in((_PS_ROOT_DIR_ . '/app/Resources/translations'));

foreach ($finder as $file) {
list($domain, $locale, $format) = explode('.', $file->getBasename(), 3);
$this->translator->addResource($format, $file, $locale, $domain);
}
if (!$this->translator->isLanguageLoaded($this->locale)) {
(new TranslatorLanguageLoader($isAdminContext))->loadLanguage($this->translator, $this->locale);
$this->translator->getCatalogue($this->locale);
}
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@
"@php ./tests-legacy/create-test-db.php"
],
"test-all": [
"composer phpunit-admin",
"composer phpunit-legacy",
"composer unit-tests",
"composer phpunit-admin",
"composer phpunit-sf",
"composer integration-tests",
"composer phpunit-controllers",
Expand Down
4 changes: 2 additions & 2 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

// Bootstrap an application with parameters.yml, which has been installed before PHP parameters file support
if (!file_exists($phpParametersFilepath) && file_exists($yamlParametersFilepath)) {
$parameters = Yaml::parse($yamlParametersFilepath);
$parameters = Yaml::parseFile($yamlParametersFilepath);
if ($exportPhpConfigFile($parameters, $phpParametersFilepath)) {
$filesystem->dumpFile($yamlParametersFilepath, 'parameters:' . "\n");
}
Expand All @@ -79,7 +79,7 @@
$config = require $phpParametersFilepath;
$exportPhpConfigFile($config, $cachedParameters);
} elseif (file_exists($yamlParametersFilepath)) {
$config = Yaml::parse($yamlParametersFilepath);
$config = Yaml::parseFile($yamlParametersFilepath);
$exportPhpConfigFile($config, $cachedParameters);
}
}
Expand Down
20 changes: 7 additions & 13 deletions controllers/admin/AdminProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2545,21 +2545,15 @@ public function processSuppliers($id_product = null)
$product_supplier->update();
}

if ($product->id_supplier == $supplier->id_supplier) {
if ((int) $attribute['id_product_attribute'] > 0) {
$data = array(
'supplier_reference' => pSQL($reference),
'wholesale_price' => (float) Tools::convertPrice($price, $id_currency),
);
$where = '
if ($product->id_supplier == $supplier->id_supplier && (int) $attribute['id_product_attribute'] > 0) {
$data = array(
'supplier_reference' => pSQL($reference),
'wholesale_price' => (float) Tools::convertPrice($price, $id_currency),
);
$where = '
a.id_product = ' . (int) $product->id . '
AND a.id_product_attribute = ' . (int) $attribute['id_product_attribute'];
ObjectModel::updateMultishopTable('Combination', $data, $where);
} else {
$product->wholesale_price = (float) Tools::convertPrice($price, $id_currency); //converted in the default currency
$product->supplier_reference = pSQL($reference);
$product->update();
}
ObjectModel::updateMultishopTable('Combination', $data, $where);
}
} elseif (Tools::isSubmit('supplier_reference_' . $product->id . '_' . $attribute['id_product_attribute'] . '_' . $supplier->id_supplier)) {
//int attribute with default values if possible
Expand Down
7 changes: 4 additions & 3 deletions install-dev/controllers/console/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,17 @@ public function process()
if (!$this->processInstallDatabase()) {
$this->printErrors();
}

// Deferred Kernel Init
$this->initKernel();

if (!$this->processInstallDefaultData()) {
$this->printErrors();
}
if (!$this->processPopulateDatabase()) {
$this->printErrors();
}

// Deferred Kernel Init
$this->initKernel();

if (!$this->processConfigureShop()) {
$this->printErrors();
}
Expand Down
2 changes: 1 addition & 1 deletion mails/themes/modern/core/order_customer_comment.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-family:Open sans, arial, sans-serif;font-size:14px;line-height:25px;text-align:left;color:#363A41;">
<span style=" font-size:16px" class="label">{{ 'Customer:'|trans({}, 'Emails.Body', locale)|raw }}</span> {firstrname} {lastname} ({email}) </div>
<span style=" font-size:16px" class="label">{{ 'Customer:'|trans({}, 'Emails.Body', locale)|raw }}</span> {firstname} {lastname} ({email}) </div>
</td>
</tr>
</table>
Expand Down
15 changes: 14 additions & 1 deletion src/Adapter/Customer/CommandHandler/EditCustomerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,20 @@ public function handle(EditCustomerCommand $command)

// validateFieldsRequiredDatabase() below is using $_POST
// to check if required fields are set
$_POST[RequiredField::PARTNER_OFFERS] = $command->isPartnerOffersSubscribed();
if ($command->isPartnerOffersSubscribed() !== null) {
$_POST[RequiredField::PARTNER_OFFERS] = $command->isPartnerOffersSubscribed();
} elseif ($command->isNewsletterSubscribed() !== null) {
$_POST[RequiredField::NEWSLETTER] = $command->isNewsletterSubscribed();
}

// before validation, we need to get the list of customer mandatory fields from the database
// and set their current values (only if it is not being modified: if it is not in $_POST)
$requiredFields = $customer->getFieldsRequiredDatabase();
foreach ($requiredFields as $field) {
if (!array_key_exists($field['field_name'], $_POST)) {
$_POST[$field['field_name']] = $customer->{$field['field_name']};
}
}

$this->assertRequiredFieldsAreNotMissing($customer);

Expand Down
6 changes: 6 additions & 0 deletions src/Core/Domain/Customer/ValueObject/RequiredField.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ class RequiredField
*/
const PARTNER_OFFERS = 'optin';

/**
* Newsletter field name
*/
const NEWSLETTER = 'newsletter';

/**
* All allowed required fields for customer
*/
const ALLOWED_REQUIRED_FIELDS = [
self::PARTNER_OFFERS,
self::NEWSLETTER,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use PrestaShop\PrestaShop\Core\MailTemplate\MailTemplateGenerator;
use PrestaShop\PrestaShop\Core\MailTemplate\ThemeCatalogInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\ThemeInterface;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\TranslatorInterface;

/**
Expand Down Expand Up @@ -99,34 +98,9 @@ public function handle(GenerateThemeMailTemplatesCommand $command)
/** @var ThemeInterface $theme */
$theme = $this->themeCatalog->getByName($command->getThemeName());

$this->cleanTranslatorLocaleCache($command->getLanguage());

$coreMailsFolder = $command->getCoreMailsFolder() ?: $this->defaultCoreMailsFolder;
$modulesMailFolder = $command->getModulesMailFolder() ?: $this->defaultModulesMailFolder;

$this->generator->generateTemplates($theme, $language, $coreMailsFolder, $modulesMailFolder, $command->overwriteTemplates());
}

/**
* When installing a new Language, if it's a new one the Translator component can't manage it because its cache is
* already filled with the default one as fallback. We force the component to update its cache by adding a fake
* resource for this locale (this is the only way clean its local cache)
*
* @param string $locale
*/
private function cleanTranslatorLocaleCache($locale)
{
if (!method_exists($this->translator, 'addLoader')
|| !method_exists($this->translator, 'addResource')
) {
return;
}

$this->translator->addLoader('array', new ArrayLoader());
$this->translator->addResource(
'array',
['Fake clean cache message' => 'Fake clean cache message'],
$locale
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ public function toggleNewsletterSubscriptionAction($customerId)
$editableCustomer = $this->getQueryBus()->handle(new GetCustomerForEditing((int) $customerId));

$editCustomerCommand = new EditCustomerCommand((int) $customerId);

// toggle newsletter subscription
$editCustomerCommand->setNewsletterSubscribed(!$editableCustomer->isNewsletterSubscribed());

$this->getCommandBus()->handle($editCustomerCommand);
Expand Down
1 change: 1 addition & 0 deletions src/PrestaShopBundle/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class Translator extends BaseTranslator
{
use PrestaShopTranslatorTrait;
use TranslatorLanguageTrait;

/**
* {@inheritdoc}
Expand Down
1 change: 1 addition & 0 deletions src/PrestaShopBundle/Translation/TranslatorComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
class TranslatorComponent extends BaseTranslatorComponent
{
use PrestaShopTranslatorTrait;
use TranslatorLanguageTrait;
}
Loading

0 comments on commit 66dfde9

Please sign in to comment.