Magento 1: Configuration Dropdown Bug – Magento Enterprise and Amasty Shipping Restrictions

I came across this issue, which admittedly may have a small affect for Magento installations, but it’s something that was reported by a team member and bugged me that I couldn’t find the answer.  Well at first – I figured it out.

Conflicts with the Enterprise Customer Segment module prevents all of the intended options from displaying in the configuration dropdown.
Conflicts with the Enterprise Customer Segment module prevents all of the intended options from displaying in the configuration dropdown.

The Issue

The conditions dropdown for rules in the Amasty Shipping Restrictions configuration does not show all of the options – it’s missing the Customer Attributes sub-menu.

This bug affects the Amasty Shipping Restrictions extension in Magento Enterprise Edition.
This bug affects the Amasty Shipping Restrictions extension in Magento Enterprise Edition.

Identifying the Issue

I was patching the Amasty Shipping Restrictions module for the SUPEE-6788 patch on a development server.  A coworker was testing setting up a shipping restriction rule and when choosing an option from the dropdown the page would redirect to the dashboard page.  The issue here was that I had a bad reference in the module that needed to be updated yet.

Though that was an un-related issue, it made me compare the functionality between the development and production servers and noticed that while I corrected the redirection issue, there were items missing from the menu.

Versions

  • Magento Enterprise Edition version 1.14.2.0
    • This bug only exists on Magento Enterprise
  • Amasty Shipping Restrictions version 1.1.2
    • I do have a copy of the most recent version of the Amasty Shipping Restrictions extension, version 1.1.8, and have verified this bug exists in that codbase as well.  For various business reasons I have chosen to manually patch the extension as oppose to upgrade to the most recent version.

Configuration

  • Configuration -> Customers -> Customer Configuration -> Customer Segments -> Enable Customer Segment Functionality
    • Yes
"Enabling

What’s Happening

By enabling the configuration setting above, the Customer Segments option is added to the dropdown.

Customer Segments is an option for the shipping restriction rule configuration
Customer Segments is an option for the shipping restriction rule configuration

The Shipping Restrictions module then attempts to add the Customer Attributes category with it’s sub-options to the dropdown.

The customer attributes section should be added to this dropdown as well, however because of this bug it is not displaying like it should.
The customer attributes section should be added to this dropdown as well, however because of this bug it is not displaying like it should.

I say attempts because the bug in the Amasty Shipping Restrictions module prevents this from actually happening.

The getNewChildSelectOptions() method in:

Will combine the already defined dropdown options with the Customer Attribute submenu options that are available to the Amasty Shipping Restrictions module.  This is an overridden method originally defined in:

On line 32

will trigger an observer than will actually do the work of combining the dropdown options.  This is TRYING to call an observer defined in:

And this is where we finally get to the flaw.  The observer, salesrule_rule_condition_combine, is already defined by the Enterprise Customer Segment module.

Because there are two observers with the same name, only one can get used and the Enterprise module wins.  So because the configuration is set to add Customer Segments the Shipping Restrictions module doesn’t correctly combine it’s options into the dropdown.  However, if you had the Customer Segments option set to no, then the Customer Attributes would show in the dropdown.

The Fix for the Bug

The solution to this bug is simple really – the name of the observer for the Amasty Shipping Restrictions extension needs to be changed to not conflict with the Enterprise module.

This solution will call two observers – one for the Amasty Shipping Restrictions module to add the Customer Attributes submenu and then to the Enterprise Customer Segment module which will add the Customer Segments options.

Change the Observer Name

File:

Change This:

To This:

Call the New Observer Name

File:

Add this line on line 33:

For clarity sake, this should be added after this line:

Clear the Cache

Because we made a modification to the XML you’ll need to choose System -> Cache Managmeent and clear the following caches:

  • Configuration
  • Layotus
  • Blocks HTML Output

Now, refresh the Amasty Shipping Restrictions rules page and you’ll see all of the desired options in the dropdown.