PHPackages                             markshust/magento2-module-simpledata - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. markshust/magento2-module-simpledata

ActiveMagento2-module

markshust/magento2-module-simpledata
====================================

The SimpleData module simplifies calling Magento data structures.

2.0.2(3y ago)94179.4k—9.8%7[1 issues](https://github.com/markshust/magento2-module-simpledata/issues)[2 PRs](https://github.com/markshust/magento2-module-simpledata/pulls)2MITPHPPHP &gt;=7.1

Since May 20Pushed 2y ago4 watchersCompare

[ Source](https://github.com/markshust/magento2-module-simpledata)[ Packagist](https://packagist.org/packages/markshust/magento2-module-simpledata)[ GitHub Sponsors](https://github.com/markshust)[ RSS](/packages/markshust-magento2-module-simpledata/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (2)

MarkShust\_SimpleData
=====================

[](#markshust_simpledata)

Simplifies calling Magento data structures.

 [![Supported Magento Versions](https://camo.githubusercontent.com/9c0567b94bb65300bf743da1c2a6df8f5aa9b78a7289924f989b06739e0c8771/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d6167656e746f2d322e322532307c253230322e332d627269676874677265656e2e7376673f6c6f676f3d6d6167656e746f266c6f6e6743616368653d74727565267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9c0567b94bb65300bf743da1c2a6df8f5aa9b78a7289924f989b06739e0c8771/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d6167656e746f2d322e322532307c253230322e332d627269676874677265656e2e7376673f6c6f676f3d6d6167656e746f266c6f6e6743616368653d74727565267374796c653d666c61742d737175617265) [![Latest Stable Version](https://camo.githubusercontent.com/cf62b67426b4d6349a05da551cdf6321f53c9eea0bdcf19cf45a3f6a0ac5bd2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61726b73687573742f6d6167656e746f322d6d6f64756c652d73696d706c65646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/markshust/magento2-module-simpledata) [![Composer Downloads](https://camo.githubusercontent.com/48193ff51e66d932572589cba2fb6bf8c8dca498872fbcd389ab88993246c910/68747470733a2f2f706f7365722e707567782e6f72672f6d61726b73687573742f6d6167656e746f322d6d6f64756c652d73696d706c65646174612f646f776e6c6f616473)](https://packagist.org/packages/markshust/magento2-module-simpledata) [![Maintained - Yes](https://camo.githubusercontent.com/04aba48520e6322ebc6c41b7995626a88ce408bd46ec4eb15ae474936b345276/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65642533462d7965732d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity) [![](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)

Table of contents
-----------------

[](#table-of-contents)

- [Summary](#summary)
- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

Summary
-------

[](#summary)

Calling Magento data structures can be confusing. There are many classes available, and knowing which to call and when can be confusing &amp; overwhelming.

This module aims to simplify calling these data structures. All classes are prefixed with `Simple` so they are easy to lookup within IDEs. They also follow a pretty standard naming convention which aligns with Magento's way of naming modules. It also provides a `SimpleDataPatch` class which greatly simplifies writing data patch scripts.

For example, here is a data patch script to update the content of a CMS page with and without `SimpleData`:

[![Demo](https://raw.githubusercontent.com/markshust/magento2-module-simpledata/master/docs/demo.png)](https://raw.githubusercontent.com/markshust/magento2-module-simpledata/master/docs/demo.png)

Installation
------------

[](#installation)

```
composer require markshust/magento2-module-simpledata
bin/magento module:enable MarkShust_SimpleData
bin/magento setup:upgrade
```

Usage
-----

[](#usage)

Here are the signatures of the simplified data structures classes:

`MarkShust\SimpleData\Api\Data\Cms\SimpleBlock`

```
/**
 * Delete a block from a given identifier and optional store id.
 * @param string $identifier
 * @param int $storeId
 */
public function delete(string $identifier, int $storeId = Store::DEFAULT_STORE_ID): void

/**
 * If the CMS block identifier is found, attempt to update the record.
 * If it is not found, attempt to create a new record.
 * @param array $data
 */
public function save(array $data): void
```

`MarkShust\SimpleData\Api\Data\Cms\SimplePage`

```
/**
 * Delete a page from a given identifier and optional store id.
 * @param string $identifier
 * @param int $storeId
 */
public function delete(string $identifier, int $storeId = Store::DEFAULT_STORE_ID): void

/**
 * If the CMS page identifier is found, attempt to update the record.
 * If it is not found, attempt to create a new record.
 * @param array $data
 */
public function save(array $data): void
```

### Examples using SimpleDataPatch

[](#examples-using-simpledatapatch)

#### Create block

[](#create-block)

```
