Skip to content

Commit

Permalink
Merge pull request #33 from ihormandzyuk/patch-3
Browse files Browse the repository at this point in the history
Update ConvertConfigToJsonPatch.php
  • Loading branch information
magefan authored Jun 16, 2023
2 parents 29f8a73 + 4ac4143 commit e2112bb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Setup/Patch/Data/ConvertConfigToJsonPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,30 @@ public function apply()
$this->moduleDataSetup->endSetup();
}

/**
* @param $block
* @return string
*/
protected function getNumberHashForBlock ($block): string {
$numberHashFromString = sprintf('%u', crc32($block));
$numberHashFromStringSuffix = substr($numberHashFromString, -3);

return '_' . $numberHashFromString . $numberHashFromStringSuffix . '_' . $numberHashFromStringSuffix;
}

/**
* @param $blocks
* @return bool|string
*/
protected function getJsonForBlocks($blocks)
{
$arrayBlocks = [];
$counter = 1;
foreach ($blocks as $block) {
$arrayBlocks[(string)$counter] =
$arrayBlocks[$this->getNumberHashForBlock($block)] =
[
'block_identifier' => $block,
'first_images_to_skip' => ($block == 'category.products.list') ? '2' : '0'
];

$counter++;
}

return $this->serializer->serialize($arrayBlocks);
Expand Down

0 comments on commit e2112bb

Please sign in to comment.