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 11 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.

Zrzut ekranu 2024-01-29 o 13.20.21.png

Zrzut ekranu 2024-01-29 o 13.34.29.png

Zrzut ekranu 2024-01-29 o 13.21.43.png

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.

Delivery Data:

Enabled: enabled displaying shipping details in structured data.

Business Days: weekdays that will be displayed in the structured data as business days.

Cutoff Time: describes the time after which the store will no longer process orders received on that day. The order placed after this hour will be processed on the next day.

Handling Time: the time needed to process an order (time from order placement to shipment).

Handling Time Unit Code: the unit for handling time.

Transit Time: the time needed to transfer an order from the warehouse to the customer.

Transit Time Unit Code: the unit for transit time.

The handling and transit time are individual matter for every project. The fields in the configuration provide the default values.
If you need a custom handling and/or transit time you need to create a preference for \MageSuite\GoogleStructuredData\Provider\Data\Product\DeliveryData\HandlingTime and/or \MageSuite\GoogleStructuredData\Provider\Data\Product\DeliveryData\TransitTime class in your project and implement dedicated logic.

Only shipping methods with fixed prices are taken into consideration. If you use Table Rate in your project you have to implement the logic to display this shipping method in the structured data.

Grouped Products:

Use Parent Product URL: Yes/No - If enabled children of the grouped products will use the 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)

Product Data Index

Because generating product data consumes a lot of resources these data are indexed. The index is automatically updated when the product is modified.
All customizations which are done via plugins on MageSuite\GoogleStructuredData\Provider\Data\Product\TypeResolvers and MageSuite\GoogleStructuredData\Provider\Data\Product\CompositeAttribute will be indexed.
For introduce customization which shouldn’t be indexed because they for example are related to the URL used for opening a product MageSuite\GoogleStructuredData\Provider\Data\Product\ModifiersPool needs to be used. This modification will be stored only in the Redis cache for 24h.

<type name="MageSuite\GoogleStructuredData\Provider\Data\Product\ModifiersPool">
    <arguments>
        <argument name="modifiers" xsi:type="array">
            <item name="delivery_data" xsi:type="array">
                <item name="modifier" xsi:type="object">MageSuite\GoogleStructuredData\Provider\Data\Product\Modifier\DeliveryData</item>
                <item name="sort_order" xsi:type="number">10</item>
            </item>
        </argument>
    </arguments>
</type>

Frontend

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

  • No labels