Home

Awesome

Open Source Love

Magento 2 DataPatchCreator

When working with large teams, many times someone forgets to create a data patch for a cms page, block, configuration or a product attribute.
This module allows you to create PHP Data Patch Files in Magento 2 Admin panel and export them to PHP files which you can add to your code repositories.

Important:

<span style="color:red ">This main version of the module does not work with PageBuilder to assure 2.3.x version compatibility.</span>

If you want to make it work with PageBuilder from Magento 2.4.3 it is required to install additional composer package:

enanobots/m2-datapatchcreator-pagebuilder

Details: https://github.com/enanobots/m2-datapatchcreator-pagebuilder-compatibility

Installation

Installation is via composer

composer require enanobots/m2-datapatchcreator

After installing the packages just run:

php bin/magento setup:upgrade

Requirements:

Tested on:

Available Data Types for data patches:

How to create data patches?

You do everything in Magento 2 admin panel. :)

There are 2 ways to create Magento 2 Data Patch files:

Sync images between store copies:

Module allows images synchronization between Magento 2 store copies.
Class used to dump / fetch images needs to implement ImageSyncInterface

Default Image sync: LocalFile

Adding new Image Sync Models:

Image Sync Models are passed into array of ImageSync class via DI.XML

    <type name="Nanobots\DataPatchCreator\Model\ImagesSync\ImageSync">
        <arguments>
            <argument name="syncModels" xsi:type="array">
                <item name="LocalFile" xsi:type="object">Nanobots\DataPatchCreator\Model\ImagesSync\LocalFile</item>
            </argument>
        </arguments>
    </type>

If you want to add a new ImageSync model, just add a new element to syncModels array via di.xml
This key needs to match the store configuration set for sync_model configuration value.

Create a plugin for SyncMethods and make sure the value field matches array key passed in di.xml.

For example:

    <type name="Nanobots\DataPatchCreator\Model\ImagesSync\ImageSync">
        <arguments>
            <argument name="syncModels" xsi:type="array">
                <item name="AmazonS3" xsi:type="object">YourVendor\YourModule\ImagesSync\AmazonS3</item>
            </argument>
        </arguments>
    </type>
        return [
            ['value' => "AmazonS3", 'label' => __('Copy images to designated folder')],
        ];

Setting configuration in the admin panel will make force usage of your module for images sync.

Suggested Packages: