Skip to content

Fixed issue where assigning customer group to a category caused an error when trying to duplicate menu#371

Open
Riyaprajapat wants to merge 1 commit intoSnowdogApps:developfrom
Riyaprajapat:duplicate_error
Open

Fixed issue where assigning customer group to a category caused an error when trying to duplicate menu#371
Riyaprajapat wants to merge 1 commit intoSnowdogApps:developfrom
Riyaprajapat:duplicate_error

Conversation

@Riyaprajapat
Copy link
Copy Markdown

@Riyaprajapat Riyaprajapat commented Jul 4, 2025

Issue Description:

When customer groups are assigned to a category in a Menu, attempting to duplicate that menu results an error. As a result, the menu cannot be duplicated successfully.

Screenshot-1:
image

Screenshot-2:
image

Screenshot-3:
image

Steps to Reproduce:

  1. Take a clean shop.
  2. Install snowdog/module-menu in the shop.
  3. Go to Stores → Configuration → SNOWDOG → Menu → General and set Customer Groups Enabled to Yes. (See Screenshot-1)
  4. Create menu, assign customer groups to a category, and save the menu. (See Screenshot-2)
  5. Duplicate that menu and observe result( See Screenshot-3).

Expected Results:

The menu should duplicate successfully, even if customer groups are assigned to categories.

Actual Results:

An error occurs during the duplication process, and the menu cannot be duplicated.

Additional Information:

File path: snowdog/module-menu/Service/Menu/Cloner.php

When cloning the menu, the code at line 119 uses $nodeClone->setData($node->getData()); to copy all data. However, in the original menu, the customer_groups field is saved as a JSON string like ["0", "1", "2", "3"], but after cloning, it becomes a plain array or comma-separated values like 0,1,2,3. This difference in format causes the error “Unable to unserialize value. Error: Syntax error” when saving the cloned menu. To fix this, the customer_groups value should be converted back to a JSON string before saving the cloned node.

image

Comment thread Service/Menu/Cloner.php

$nodeClone->setData($node->getData());
if (isset($data['customer_groups'])) {
$data['customer_groups'] = json_encode((array)$data['customer_groups']);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In code where customerGroups is serialized, unserialized we are using Magento\Framework\Serialize\SerializerInterface

Let's keep this uniform across this module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants