Setting Product Attribute Visibility per Shop in Magento
As an experienced e-commerce developer, I often encounter requests to customize product attribute visibility across multiple stores or websites within the same Magento installation. In this post, we’ll tackle a common scenario: setting the visibility of a specific product attribute like “size” for the frontend on a per-shop basis.
The Challenge: Global Attribute Visibility Settings
By default, Magento allows you to configure global settings for each product attribute in the admin panel under Catalog > Attributes > Manage Attributes. Here, you can set whether an attribute is visible on the product view page on the front-end, search results, layered navigation, etc.âbut these settings apply universally across all your stores.
In your case, if you’ve set “Visible on Product View Page on Front-end” to no for the “size” attribute in the admin panel, this setting currently applies to both Shop A and Shop B. You want to display this information only on Shop A’s product detail pages while keeping it hidden on Shop B.
The Solution: Attribute Visibility per Store View
To achieve this level of granular control over your product attributes’ visibility, we’ll need to leverage Magento’s advanced store view functionality combined with a bit of custom code. Here’s a step-by-step approach:
-
Create a new attribute set: First, create a new attribute set specifically for Shop A (or whichever shop you want the “size” attribute to appear on). This will allow us to configure unique attribute settings for each store view.
-
Assign attributes to the new set: In the admin panel, navigate to Catalog > Attributes Sets and duplicate an existing one (like “Default”). Rename it something like “Shop A Product Set”. Then, under Catalog > Attributes, find your size attribute and assign it to this new set.
-
Configure store-specific visibility settings: Now, for each of your stores (e.g., Shop A), go to Stores > Configuration > Catalog > Product Attributes. Here, you can configure the visibility settings for your “size” attribute specifically for that store view.
For Shop A, set “Visible on Product View Page on Front-end” to yes. Leave this setting as no for all other stores (like Shop B).
-
Assign the new attribute set to products: Finally, for each product you want to display with the size attribute in Shop A, go to Catalog > Products and edit its settings under the “Attributes Set” dropdown menu. Assign it to your newly created “Shop A Product Set”.
Code Example: Extending Magento’s Attribute Visibility Functionality
If you’re an advanced developer looking for a programmatic solution, you can create a custom module that extends Magento’s attribute visibility functionality. This involves creating a new plugin or observer to modify the visibility behavior based on the current store view.
Here’s a simplified example of how this might look:
class CustomizeAttributeVisibility
{
public function aroundGetIsVisibleOnFront(
\Magento\Eav\Model\Entity\Attribute $subject,
callable $proceed,
\Magento\Framework\DataObject $object
) {
if ($subject->getId() === 123 && $this->storeManager->getStore()->getCode() === 'shop_a') { // Assume 123 is the size attribute ID
return true;
}
return $proceed($subject, $object);
}
}
In this example, we’re using a plugin to override the getIsVisibleOnFront method for our “size” attribute (ID 123). The method checks if the current store is Shop A; if so, it forces the visibility setting to true regardless of the global admin configuration.
Conclusion: Customizing Attribute Visibility per Store View
As we’ve seen, Magento provides robust flexibility in managing product attributes across multiple stores through its attribute sets and store view-specific configurations. By following the approach outlined above, you can easily customize the visibility of any attribute for the frontend on a per-shop basis without resorting to complex hacks or core modifications.
Remember, this level of customization requires an understanding of Magento’s architecture and may necessitate some advanced development skills if implementing it programmatically. But with careful planning and execution, you can create highly tailored shopping experiences across your e-commerce empire.
To learn more about extending Magento’s core functionality for unique business requirements, check out our comprehensive guide on Magento module development at Laravel Company. Happy customizing!