@@ -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