GoogleStructuredData (optional)
GitHub - 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.
- 1 Installation
- 2 Admin settings
- 2.1 Breadcrumbs
- 2.2 Organization
- 2.3 Search Box
- 2.4 Social Media
- 2.4.1 Profiles
- 2.5 Category
- 2.6 Product
- 2.6.1 Attributes
- 2.6.2 Delivery Data
- 2.6.3 Grouped Products
- 2.7 FAQ Page
- 3 Backend
- 4 Frontend
Installation
This module is optional
composer require "creativestyle/magesuite-google-structured-data" ^3.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 the organization.
Contact
This section contains information about available ways of contacting the organization.
Search Box
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.
Is Indexing Enabled: Yes/No - Enable/disable for storing pregenerated data in the index.
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.
FAQ Page
Is Enabled: Yes/No - Enable/disable adding FAQ data to structured data.
The default provider for this is Accordion Component from Content Constructor.
Backend
Customization of structured data
The most of the 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 typeeav
or config path for typeconfigured_eav
class
- PHP class responsible for returning attribute value, by default, there is onlyEav
andBrand
.type
- We have 3 available types:eav
- It will load an attribute from the product with the attribute code configured in the entryattribute_name
.configured_eav
- It will load attribute code which is configured understructured_data/product_page/attributes/{attribute_name}
incore_config_data
database table.custom
- It will only execute logic prepared in provided entryclass
, 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
:
etc/adminhtml/system.xml
:
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
Generation of product structured data consumes a lot of resources, to improve performance the data are indexed.
The index is automatically updated when the product is modified.
Data generated by plugins on MageSuite\GoogleStructuredData\Provider\Data\Product\TypeResolvers
and MageSuite\GoogleStructuredData\Provider\Data\Product\CompositeAttribute
will be indexed.
To introduce dynamic data on top of data that exists in the index (for example data related to the current URL in the browser or time-sensitive data) MageSuite\GoogleStructuredData\Provider\Data\Product\ModifiersPool
should be used.
All modifiers code will be executed after the data is loaded from the index.
Frontend
structured data are visible in the page source code and they can also be checked using Schema Markup Validator