Skip to content

Commit

Permalink
Merge branch '8.2.x' into merge-82x-90x-131124
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Nov 13, 2024
2 parents c360b00 + fc2922f commit c366945
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: COMPOSER_PROCESS_TIMEOUT=600 composer install --ansi --prefer-dist --no-interaction --no-progress

- name: Run PHPCSFixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --path-mode=intersection

- name: Run ergebnis/composer-normalize
run: composer normalize --dry-run --no-check-lock
Expand Down
4 changes: 2 additions & 2 deletions classes/CartRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -1408,9 +1408,9 @@ public function getContextualValue($use_tax, ?Context $context = null, $filter =
if ((in_array($product['id_product'] . '-' . $product['id_product_attribute'], $selected_products)
|| in_array($product['id_product'] . '-0', $selected_products))
&& (($this->reduction_exclude_special && !$product['reduction_applies']) || !$this->reduction_exclude_special)) {
$price = $product['price'];
$price = $product['price_with_reduction_without_tax'];
if ($use_tax) {
$price = $product['price_without_reduction'];
$price = $product['price_with_reduction'];
}

$selected_products_reduction += $price * $product['cart_quantity'];
Expand Down
4 changes: 2 additions & 2 deletions classes/Guest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function getBrowser($userAgent)
FROM `' . _DB_PREFIX_ . 'web_browser` wb
WHERE wb.`name` = \'' . pSQL($k) . '\'');

return $result['id_web_browser'];
return $result['id_web_browser'] ?? null;
}
}

Expand Down Expand Up @@ -180,7 +180,7 @@ protected function getOs($userAgent)
FROM `' . _DB_PREFIX_ . 'operating_system` os
WHERE os.`name` = \'' . pSQL($k) . '\'');

return $result['id_operating_system'];
return $result['id_operating_system'] ?? null;
}
}

Expand Down
9 changes: 9 additions & 0 deletions classes/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,15 @@ public function deleteImage($forceDelete = false)
}
}

// We need to delete old thumbnails (if exists) from variant images as well
$old_thumbnails = glob(_PS_TMP_IMG_DIR_ . 'product_mini_' . $this->id_product . '_*.' . $this->image_format);
if (!empty($old_thumbnails)) {
foreach ($old_thumbnails as $file) {
// we don't care, if it exists, because glob will handle this
@unlink($file);
}
}

// Can we delete the image folder?
if (is_dir($this->image_dir . $this->getImgFolder())) {
$deleteFolder = true;
Expand Down
29 changes: 21 additions & 8 deletions classes/order/OrderInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,37 @@ public function getProductsDetail()
' . ($this->id && $this->number ? ' AND od.`id_order_invoice` = ' . (int) $this->id : '') . ' ORDER BY od.`product_name`');
}

public static function getInvoiceByNumber($id_invoice)
/**
* Returns OrderInvoice for a specific invoice number and order ID.
* It's highly recommended to also provide an order ID, because you
* may end up with a different invoice than you wanted.
*
* DO NOT CONFUSE the number with id_order_invoice, that's a different,
* unique identifier of the invoice.
*
* @param string|int $invoiceNumber
* @param int $orderId
*
* @return OrderInvoice|false
*/
public static function getInvoiceByNumber($invoiceNumber, $orderId = null)
{
if (is_numeric($id_invoice)) {
$id_invoice = (int) $id_invoice;
} elseif (is_string($id_invoice)) {
if (is_numeric($invoiceNumber)) {
$invoiceNumber = (int) $invoiceNumber;
} elseif (is_string($invoiceNumber)) {
$matches = [];
if (preg_match('/^(?:' . Configuration::get('PS_INVOICE_PREFIX', Context::getContext()->language->id) . ')\s*([0-9]+)$/i', $id_invoice, $matches)) {
$id_invoice = $matches[1];
if (preg_match('/^(?:' . Configuration::get('PS_INVOICE_PREFIX', Context::getContext()->language->id) . ')\s*([0-9]+)$/i', $invoiceNumber, $matches)) {
$invoiceNumber = $matches[1];
}
}
if (!$id_invoice) {
if (!$invoiceNumber) {
return false;
}

$id_order_invoice = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
'SELECT `id_order_invoice`
FROM `' . _DB_PREFIX_ . 'order_invoice`
WHERE number = ' . (int) $id_invoice
WHERE `number` = ' . (int) $invoiceNumber . (!empty($orderId) ? ' AND `id_order` = ' . (int) $orderId : '')
);

return $id_order_invoice ? new OrderInvoice((int) $id_order_invoice) : false;
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminShopGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function renderForm()
];

$this->fields_value = [
'active' => true,
'active' => $obj->id ? (bool) $obj->active : true,
];

return parent::renderForm();
Expand Down
46 changes: 46 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,52 @@ Changelog for PrestaShop 9
- Refactoring:
- #36882: Comment search process (by @Hlavtox)

####################################
# v8.2.0 - (2024-09-23)
####################################
- Back Office:
- Improvement:
- #36171: Remove email "Preview" from BO section "Statutes" (by @ShaiMagal)
- #36386: Fix typo in pack wording that doesn't make sense (by @Hlavtox)
- #36172: Input type "number" is not styled properly (by @ShaiMagal)
- #36714: Order modules on translation page alphabetically (by @Hlavtox)
- #36936: Remove redirection on cms exception (by @Hlavtox)
- Bug fix:
- #36457: Fix: Pass correct language ID to getAttributesName instead of hardcoded 1 (by @mouleeg)
- #36454: Prevent creating duplicate customers in some scenarios (by @Hlavtox)
- #36287: Fix issue with Product Customizations (by @Codencode)
- #36802: Fix: Error occurs when navigating new admin controllers with empty quick access links (by @Codencode)
- #36639: Check override conflicts at module install (by @ludoviccardinale & @matthieu-rolland)
- #36895: Update AdminCartsController.php (by @Codencode)
- #36914: Added management of the 'addedByModule' field in the "CustomizationField" object (by @Codencode)
- Front Office:
- Improvement:
- #36359: Match URLs with a trailing slash (by @Hlavtox)
- #36451: Enhance TemplateVarShop Function with Shop Group ID for Improved Multi-Shop Support (by @ChronoBrake)
- Bug fix:
- #36454: Prevent creating duplicate customers in some scenarios (by @Hlavtox)
- #36521: Handle hook prefix to allow dashboard module to be saved (by @PrestaEdit)
- #36664: Use attribute public name instead of private name in URL anchors (by @maxldn5)
- #36834: Fix: problems with product customizations issue 1 (by @Codencode)
- #36905: Fix: Cart.php class method _deleteCustomization not deleting all image files from same customization but only first (by @Codencode)
- Core:
- Improvement:
- #36398: Updated PrestaShop Packages (by @github-actions)
- #36417: Updated PrestaShop Packages (by @github-actions)
- #36576: Mail - Reply-To can be the same as the To address (spam indicator - negative points) (by @ShaiMagal)
- #36764: Version number 8.2.0 (by @matks)
- #36657: Add hook for assigning general purpose variables before the core does it (by @matthieu-rolland)
- #36575: Migrate lazy array improvements and cart presenter decoupling from develop to 8.2.x (by @matthieu-rolland)
- #36955: Use basename on user given filename in legacy uploadcontroller (by @matthieu-rolland)
- #36972: Update default catalog 8.2.x (by @ps-jarvis)
- Bug fix:
- #36662: Cast OrderProductForViewing - location to string for Memcached (by @ShaiMagal)
- #36840: Use PHP constants for doctrine config (by @matks)
- #36875: Add attr_stringify_fetches to PDO init config to avoid BC Break (by @fox-john)
- #36689: Can't transformToCustomer while password max length is shorter than default 16 length (by @ShaiMagal)
- Refactoring:
- #36882: Comment search process (by @Hlavtox)

####################################
# v8.1.7 - (2024-06-14)
####################################
Expand Down
4 changes: 0 additions & 4 deletions src/Adapter/Presenter/Product/ProductLazyArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,6 @@ public function getCombinationSpecificData()
#[LazyArrayAttribute(arrayAccess: true)]
public function getSpecificReferences()
{
if (isset($this->product['cart_quantity'])) {
return null;
}

$specificReferences = null;

// Get data of this combination, it contains other stuff, we will extract only what we need
Expand Down
76 changes: 40 additions & 36 deletions src/Core/Translation/Export/TranslationCatalogueExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
*/
class TranslationCatalogueExporter
{
private const EXPORT_ZIP_FILENAME = '%s/translations_export_%s.zip';

/**
* @var TranslationCatalogueBuilder
*/
Expand Down Expand Up @@ -117,22 +115,25 @@ public function export(array $selections, string $locale): string
{
$this->validateParameters($selections);

// Create directory, where we will do our exports, if it doesn't exist
// This is var/cache/<env>/export
if (!$this->filesystem->exists($this->exportDir)) {
$this->filesystem->mkdir($this->exportDir);
}

$zipFilename = sprintf(self::EXPORT_ZIP_FILENAME, $this->exportDir, $locale);
$path = dirname($zipFilename);
// Prepare unique export identifier so we don't interfere with other exports
$exportIdentifier = uniqid();

// Create our working folder, this is a temporary folder inside var/cache/<env>/export
$workingFolder = $this->exportDir . '/' . $exportIdentifier;
if (!$this->filesystem->exists($workingFolder)) {
$this->filesystem->mkdir($workingFolder);
}

// Clean export folder
$this->filesystem->remove($path);
$this->filesystem->mkdir($path);
$dumpOptions = [
'path' => $path,
'default_locale' => $locale,
'root_dir' => _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR,
];
// Prepare the name of the final zip file we will return
$zipFilename = sprintf('%s/translations_export_%s.zip', $this->exportDir, $locale);

// Dump all XLF files into var/cache/<env>/export/<exportIdentifier>/<locale>
foreach ($selections as $selection) {
$providerDefinition = $this->providerDefinitionFactory->build($selection['type'], $selection['selected']);

Expand All @@ -142,14 +143,25 @@ public function export(array $selections, string $locale): string
// Transform into messageCatalogue object
$messageCatalogue = $this->transformCatalogueMapToMessageCatalogue($catalogue, $locale);

// Dump catalogue into XLF files
$this->dumper->dump($messageCatalogue, $dumpOptions);
// Dump catalogue into XLF files into our temporary folder
$this->dumper->dump(
$messageCatalogue,
[
'path' => $workingFolder,
'default_locale' => $locale,
'root_dir' => _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR,
]
);
}

// Rename files to add locale in it
$this->renameCatalogues($locale, $path);
// Now, we append the locale to the names of the catalogues
$this->renameCatalogues($locale, $workingFolder);

// Zip them
$this->zipManager->createArchive($zipFilename, $workingFolder);

$this->zipManager->createArchive($zipFilename, $path);
// And clean after ourselves
$this->filesystem->remove($workingFolder);

return $zipFilename;
}
Expand Down Expand Up @@ -191,29 +203,21 @@ private function transformCatalogueMapToMessageCatalogue(Catalogue $catalogue, s
return $messageCatalogue;
}

/**
* After export, our files are named with their domain only, FullDomainName.xlf for example.
* This method will append the locale name to the end of the file, so the result is something like
* FullDomainName.ab-AB.xlf
*
* @param string $locale Locale to append to filenames
* @param string $path Folder to work in
*/
protected function renameCatalogues(string $locale, string $path): void
{
$finder = Finder::create();

foreach ($finder->in($path . DIRECTORY_SEPARATOR . $locale)->files() as $file) {
$filenameParts = explode('.', $file->getFilename());
unset($filenameParts[count($filenameParts) - 1]); // Remove the extension
/*
* The destination file name will have the format
* DIRECTORY/ab-AB/FullDomainName.ab-AB.xlf
*/
$destinationFilename = sprintf(
'%s' . DIRECTORY_SEPARATOR . '%s' . DIRECTORY_SEPARATOR . '%s.%s.%s',
$path,
$locale,
implode('.', $filenameParts),
$locale,
$file->getExtension()
);
if ($this->filesystem->exists($destinationFilename)) {
$this->filesystem->remove($destinationFilename);
}
$this->filesystem->rename($file->getPathname(), $destinationFilename);
$currentName = $file->getPathname();
$newName = rtrim($currentName, '.xlf') . '.' . $locale . '.xlf';
$this->filesystem->rename($currentName, $newName);
}
}
}
13 changes: 12 additions & 1 deletion tests/Resources/modules_tests/override/classes/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class Cart extends CartCore
{
public const BOTH = 999;

/*
* module: pscsx32412
* date: 2018-12-26 14:14:05
Expand All @@ -21,6 +23,15 @@ public function updateAddressId($id_address, $id_address_new)
if ($to_update) {
$this->update();
}
$sql = 'UPDATE `' . _DB_PREFIX_ . 'cart_product`
SET `id_address_delivery` = ' . (int) $id_address_new . '
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_address_delivery` = ' . (int) $id_address;
Db::getInstance()->execute($sql);
$sql = 'UPDATE `' . _DB_PREFIX_ . 'customization`
SET `id_address_delivery` = ' . (int) $id_address_new . '
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_address_delivery` = ' . (int) $id_address;
Db::getInstance()->execute($sql);
}

Expand All @@ -31,7 +42,7 @@ public function updateAddressId($id_address, $id_address_new)
*/
public function delete()
{
if ($this->OrderExists()) { // NOT delete a cart which is associated with an order
if ($this->OrderExists()) { //NOT delete a cart which is associated with an order
return false;
}
$uploaded_files = Db::getInstance()->executeS(
Expand Down
34 changes: 15 additions & 19 deletions translations/default/ModulesBlockreassuranceAdmin.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,6 @@ Comment: Confirm uninstall</note>
</trans-unit>
</body>
</file>
<file original="modules/blockreassurance/views/templates/admin/tabs/content/config_elements/cms.tpl" source-language="en-US" target-language="en" datatype="plaintext">
<body>
<trans-unit id="87d49200bfc48e0bcfd3bae27d5616f3">
<source>CMS Page</source>
<target>CMS Page</target>
<note>Line: 24</note>
</trans-unit>
</body>
</file>
<file original="modules/blockreassurance/views/templates/admin/tabs/content/config_elements/description.tpl" source-language="en-US" target-language="en" datatype="plaintext">
<body>
<trans-unit id="0ba3309bf076bf416d0bb498fdfcb77f">
Expand Down Expand Up @@ -245,6 +236,11 @@ Comment: Confirm uninstall</note>
</file>
<file original="modules/blockreassurance/views/templates/admin/tabs/content/listing.tpl" source-language="en-US" target-language="en" datatype="plaintext">
<body>
<trans-unit id="87d49200bfc48e0bcfd3bae27d5616f3">
<source>CMS Page</source>
<target>CMS Page</target>
<note>Line: 81</note>
</trans-unit>
<trans-unit id="2fbc962c5748d8e3fb7ada6598049a67">
<source>Block Content</source>
<target>Block Content</target>
Expand All @@ -270,6 +266,16 @@ Comment: Confirm uninstall</note>
<target>We recommend 3 blocks at maximum.</target>
<note>Line: 118</note>
</trans-unit>
<trans-unit id="6adf97f83acf6453d4a6a4b1070f3754">
<source>None</source>
<target>None</target>
<note>Line: 77</note>
</trans-unit>
<trans-unit id="334c4a4c42fdb79d7ebc3e73b517e6f8">
<source>none</source>
<target>none</target>
<note>Line: 57</note>
</trans-unit>
</body>
</file>
<file original="modules/blockreassurance/views/templates/admin/tabs/display.tpl" source-language="en-US" target-language="en" datatype="plaintext">
Expand Down Expand Up @@ -302,11 +308,6 @@ Comment: Confirm uninstall</note>
</file>
<file original="modules/blockreassurance/views/templates/admin/tabs/display/global.tpl" source-language="en-US" target-language="en" datatype="plaintext">
<body>
<trans-unit id="6adf97f83acf6453d4a6a4b1070f3754">
<source>None</source>
<target>None</target>
<note>Line: 93</note>
</trans-unit>
<trans-unit id="23b5440c1d192315a80d4c47a0a6a777">
<source>Header position on all pages</source>
<target>Header position on all pages</target>
Expand Down Expand Up @@ -341,11 +342,6 @@ Comment: Confirm uninstall</note>
</file>
<file original="modules/blockreassurance/views/templates/admin/tabs/display/product.tpl" source-language="en-US" target-language="en" datatype="plaintext">
<body>
<trans-unit id="334c4a4c42fdb79d7ebc3e73b517e6f8">
<source>none</source>
<target>none</target>
<note>Line: 41</note>
</trans-unit>
<trans-unit id="3f01481a13daed04a03caaa1a28ab49f">
<source>Main column</source>
<target>Main column</target>
Expand Down
Loading

0 comments on commit c366945

Please sign in to comment.