One of the great benefits of Magento is that it allows store owners to run different stores on the same installation. However when looking at Magento product attributes limitations one will notice that: Magento can support only up to 64 product attributes in one attribute set, and that the attribute configuration is applied globally. These can be limiting factor when one considers the differences between markets.
One of the global settings for product attributes is ‘Visible on Product View Page on Front-end’ which automatically determines if the attribute is to be shown in the product specifications section. When running multiple stores on the same Magento one would require to control on which store the product is visible. With Magento functionality this can be handled by defining new product attributes by site in collaboration with attribute sets. However one have to be careful of the Magento limitations of product attributes. What if each store requires different product attribute configuration?
Clounce_VisibilityByStore extends the product attributes ‘Visible on Product View Page on Front-end’ with a list of store groups that can be excluded from the visibility setting. That is, if the ‘Visible on Product View Page on Front-end’ is set to ‘Yes’ and the store group is set as an exclusion from this setting, Clounce_VisibilityByStore, will remove the attribute from the attributes list that the product detail page loads.
Understanding the Module code
The Magento block used to render the product attributes is
Mage_Catalog_Block_Product_View_Attributes and the function used is:
public function getAdditionalData(array $excludeAttr = array())
The method takes a parameter of attributes that will be excluded from the frontend. Therefore what is required is to have a list of attributes that need to be excluded for store. This is achieved by adding a new setting for the product attributes to determine if the ‘Visible on Product View Page on Front-end’ settings applies to the store group.
The module Clounce_VisibilityByStore creates this new setting by hooking into the event
Once the new setting is available it is important to store the selected stores into a table. To avoid modifying the Magento EAV tables a new table called
clounce_visibilitybystore is created with the columns:
|link_id||Primary Key||int(11)||Required for updating attributes|
|attribute_code||Attribute||varchar(255)||Product attribute identified|
|store||List of Stores||varchar(4000)||Stores where the attribute will be excluded|
The updating of the
clounce_visibilitybystore table is handled by hooking into the event
catalog_entity_attribute_save_after. When the
catalog_entity_attribute_save_after method is called the stores list is converted to a comma separated list and stored. However if the option ‘No Exclusions’ is selected the entry in the
clounce_visibilitybystore is deleted.
Finally it is important to update the template
catalog/product/view/attributes.phtml is overridden to call a new helper method
and its return passed to
to ensure that only the attributes applicable to the store frontend are shown.
- Community Edition: 1.8
Notes: The extension makes use of event observers which should allow it to work fine with other Community and Enterprise Editions.
Download the extension and if are happy with it why not Donate 1€ to support this site.
THIS EXTENSION IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THIS SITE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS EXTENSION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NOTE: ALWAYS TAKE A BACKUP OF YOUR SITE AND DATABASE BEFORE INSTALLING ANY MODULE