Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

https://github.com/magesuite/google-structured-data

This module provided a centralized way to add and manage Google Structured Data in the shop. It’s developed in an elastic way and it’s easy to customize and extend. Also, native Magento structured data was disabled because it was rendered in a decentralized way and was hard to customize.

Installation

This module is optional

composer require "creativestyle/magesuite-google-structured-data" ^2.0.0

Admin settings

Stores > Configuration > MageSuite > Google Structured Data

Breadcrumbs

Is Enabled: Yes/No - Enable/disable adding breadcrumbs to structured data.

Organization

Is Enabled: Yes/No - Enable/disable adding organization information to structured data.

Address:

This section contains the address data of organization.

Contact:

This section contains information about available ways of contacting the organization.

Is Enabled: Yes/No - Enable/disable adding search data on the search result page to structured data.

Social Media

Is Enabled: Yes/No - Enable/disable adding social media information to structured data.

Profiles:

This section contains links to social media profiles which should be displayed in structured data. If the field is empty it will be skipped.

Category

Include products: Yes/No - Enable/disable adding products data on category pages structured data.

Product

Is Enabled: Yes/No - Enable/disable adding product information to structured data.

Show Rating: Yes/No - Enable/disable adding reviews to the structured data of products.

Attributes:

Description: (list of available product attributes) - Select for attribute used in the field description in structured data.

Brand: (list of available product attributes) - Select for attribute used in the field brand in structured data.

Manufacturer: (list of available product attributes) - Select for attribute used in the field manufacturer in structured data.

If the select is empty field won’t be added.

Grouped Products:

Use Parent Product URL: Yes/No - If enabled children of the grouped products will use grouped product URL as their own. It’s useful when assigned products are “Not visible individually”, and then they don’t have the correct product URL.

Use Parent Product Images: Yes/No - If enabled children of the grouped products will use grouped product images as their own.

Use Parent Product Reviews: Yes/No - If enabled children of the grouped products will load reviews from the grouped product.

Backend

Customization of structured data

The most of methods responsible for providing structured data are public, so they can be easily customized by plugins.

Class responsible for providing the data:

  • MageSuite\GoogleStructuredData\Provider\Data\Breadcrumbs

  • MageSuite\GoogleStructuredData\Provider\Data\Organization

  • MageSuite\GoogleStructuredData\Provider\Data\Product

  • MageSuite\GoogleStructuredData\Provider\Data\SearchBox

  • MageSuite\GoogleStructuredData\Provider\Data\Social

For Product, the logic is more complex and it’s stored in MageSuite\GoogleStructuredData\Provider\Data\Product namespace.
Each product type has its own resolver which can be replaced, resolvers are defined in etc/di.xml

 <type name="MageSuite\GoogleStructuredData\Provider\Data\Product\TypeResolverPool">
    <arguments>
        <argument name="productTypeResolvers" xsi:type="array">
            <item name="configurable" xsi:type="object">MageSuite\GoogleStructuredData\Provider\Data\Product\TypeResolver\Configurable</item>
            <item name="grouped" xsi:type="object">MageSuite\GoogleStructuredData\Provider\Data\Product\TypeResolver\Grouped</item>
        </argument>
    </arguments>
</type>

Product Attributes

By default, only 3 product attributes are added to structured data, they are defined in etc/di.xml

<type name="MageSuite\GoogleStructuredData\Provider\Data\Product\CompositeAttribute">
    <arguments>
        <argument name="attributeDataProviders" xsi:type="array">
            <item name="description" xsi:type="array">
                <item name="attribute_name" xsi:type="string">description</item>
                <item name="class" xsi:type="object">MageSuite\GoogleStructuredData\Provider\Data\Product\Attribute\Eav</item>
                <item name="type" xsi:type="string">configured_eav</item>
                <item name="disabled" xsi:type="boolean">false</item>
            </item>
            <item name="brand" xsi:type="array">
                <item name="attribute_name" xsi:type="string">brand</item>
                <item name="class" xsi:type="object">MageSuite\GoogleStructuredData\Provider\Data\Product\Attribute\Brand</item>
                <item name="type" xsi:type="string">configured_eav</item>
                <item name="disabled" xsi:type="boolean">false</item>
            </item>
            <item name="manufacturer" xsi:type="array">
                <item name="attribute_name" xsi:type="string">manufacturer</item>
                <item name="class" xsi:type="object">MageSuite\GoogleStructuredData\Provider\Data\Product\Attribute\Eav</item>
                <item name="type" xsi:type="string">configured_eav</item>
                <item name="disabled" xsi:type="boolean">false</item>
            </item>
        </argument>
    </arguments>
</type>

<item name="description" xsi:type="array"> - property name will be used in structured data as a key for value

Each entry has its own configuration:

  • attribute_name - It is used as attribute code for type eav or config path for type configured_eav

  • class - PHP class responsible for returning attribute value, by default, there is only Eav and Brand.

  • type - We have 3 available types:

    • eav - It will load an attribute from the product with the attribute code configured in the entry attribute_name.

    • configured_eav - It will load attribute code which is configured under structured_data/product_page/attributes/{attribute_name} in core_config_data database table.

    • custom - It will only execute logic prepared in provided entry class, this class might execute custom calculations or even return a static value.

  • disabled - (false/true) Simple switch which allows disabling specific attributes to be processed.

Example of adding a new attribute

etc/di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MageSuite\GoogleStructuredData\Provider\Data\Product\CompositeAttribute">
        <arguments>
            <argument name="attributeDataProviders" xsi:type="array">
                <item name="gtin" xsi:type="array">
                    <item name="attribute_name" xsi:type="string">gtin13</item>
                    <item name="class" xsi:type="object">MageSuite\GoogleStructuredData\Provider\Data\Product\Attribute\Eav</item>
                    <item name="type" xsi:type="string">configured_eav</item>
                    <item name="disable" xsi:type="boolean">false</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

etc/adminhtml/system.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="structured_data">
            <group id="product_page">
                <group id="attributes">
                    <field id="gtin13" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                        <label>GTIN13</label>
                        <source_model>MageSuite\GoogleStructuredData\Model\Config\Attributes</source_model>
                        <comment>Defines which attribute will be used to describe product GTIN13.</comment>
                    </field>
                </group>
            </group>
        </section>
    </system>
</config>

The result will be the addition of the key gtin to structured data with the content from the product attribute configured in the Stores > Configuration > MageSuite > Google structured data > Product > Attributes
(database path: structured_data/product_page/attributes/gtin13)

Frontend

structured data are visible in the page source code and also they can be checked using https://validator.schema.org/

  • No labels