Skip to content

Commit f5a3d04

Browse files
authored
Merge pull request #253 from PrestaSafe/fix-order-paste-blocks
Fix order paste blocks
2 parents 5fae0d3 + 98d7ac2 commit f5a3d04

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

_dev/yarn.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.24.8.tgz"
1313
integrity sha512-WzfbgXOkGzZiXXCqk43kKwZjzwx4oulxZi3nq2TYL9mOjQv6kYwul9mz6ID36njuL7Xkp6nJEfok848Zj10j/w==
1414

15-
"@esbuild/darwin-arm64@0.21.5":
15+
"@esbuild/linux-x64@0.21.5":
1616
version "0.21.5"
17-
resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz"
18-
integrity sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==
17+
resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz"
18+
integrity sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ==
1919

2020
"@headlessui/vue@^1.7.19":
2121
version "1.7.22"
@@ -107,10 +107,15 @@
107107
resolved "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz"
108108
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==
109109

110-
"@rollup/rollup-darwin-arm64@4.19.0":
110+
"@rollup/rollup-linux-x64-gnu@4.19.0":
111111
version "4.19.0"
112-
resolved "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.19.0.tgz"
113-
integrity sha512-emvKHL4B15x6nlNTBMtIaC9tLPRpeA5jMvRLXVbl/W9Ie7HhkrE7KQjvgS9uxgatL1HmHWDXk5TTS4IaNJxbAA==
112+
resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.19.0.tgz"
113+
integrity sha512-HBndjQLP8OsdJNSxpNIN0einbDmRFg9+UQeZV1eiYupIRuZsDEoeGU43NQsS34Pp166DtwQOnpcbV/zQxM+rWA==
114+
115+
"@rollup/rollup-linux-x64-musl@4.19.0":
116+
version "4.19.0"
117+
resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.19.0.tgz"
118+
integrity sha512-HxfbvfCKJe/RMYJJn0a12eiOI9OOtAUF4G6ozrFUK95BNyoJaSiBjIOHjZskTUffUrB84IPKkFG9H9nEvJGW6A==
114119

115120
"@swc/helpers@^0.2.13":
116121
version "0.2.14"
@@ -698,11 +703,6 @@ fs.realpath@^1.0.0:
698703
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
699704
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
700705

701-
fsevents@~2.3.2, fsevents@~2.3.3:
702-
version "2.3.3"
703-
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
704-
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
705-
706706
function-bind@^1.1.2:
707707
version "1.1.2"
708708
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"

classes/PrettyBlocksModel.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,10 @@ public static function copyZone($zone_name, $zone_name_to_paste, $id_lang, $id_s
970970
$query->where('zone_name = \'' . $zone_name . '\'');
971971
$query->where('id_lang = ' . (int) $id_lang);
972972
$query->where('id_shop = ' . (int) $id_shop);
973+
$query->orderBy('position ASC');
973974
$results = $db->executeS($query);
974975
$result = true;
976+
$lastPosition = self::getLastPosition($zone_name, $id_lang, $id_shop);
975977

976978
foreach ($results as $row) {
977979
$model = new PrettyBlocksModel(null, $id_lang, $id_shop);
@@ -985,6 +987,8 @@ public static function copyZone($zone_name, $zone_name_to_paste, $id_lang, $id_s
985987
$model->instance_id = $row['instance_id'];
986988
$model->id_shop = (int) $id_shop;
987989
$model->id_lang = (int) $id_lang;
990+
$model->position = $row['position'] + $lastPosition;
991+
++$lastPosition;
988992
if (!$model->save()) {
989993
$errors[] = $model;
990994
}
@@ -993,6 +997,19 @@ public static function copyZone($zone_name, $zone_name_to_paste, $id_lang, $id_s
993997
return $errors;
994998
}
995999

1000+
public static function getLastPosition($zone_name, $id_lang, $id_shop)
1001+
{
1002+
$db = Db::getInstance();
1003+
$query = new DbQuery();
1004+
$query->select('MAX(position)')
1005+
->from('prettyblocks')
1006+
->where('zone_name = \'' . $zone_name . '\'')
1007+
->where('id_lang = ' . (int) $id_lang)
1008+
->where('id_shop = ' . (int) $id_shop);
1009+
1010+
return (int) $db->getValue($query);
1011+
}
1012+
9961013
/**
9971014
* deleteBlocksFromZone
9981015
* delete all blocks from a zone

0 commit comments

Comments
 (0)