# markshust/magento2-module-simpledata

> The SimpleData module simplifies calling Magento data structures.

`composer require markshust/magento2-module-simpledata`

Canonical URL: https://packagento.com/markshust/magento2-module-simpledata

## At a glance

- **Vendor**: markshust (https://packagento.com/markshust.md)
- **Latest version**: 2.0.2 — released 2022-06-29
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/markshust/magento2-module-simpledata and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require markshust/magento2-module-simpledata:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

The SimpleData module simplifies calling Magento data structures.

## README

<h1 align="center">MarkShust_SimpleData</h1> 

<div align="center">
  <p>Simplifies calling Magento data structures.</p>
  <img src="https://img.shields.io/badge/magento-2.2%20|%202.3-brightgreen.svg?logo=magento&longCache=true&style=flat-square" alt="Supported Magento Versions" />
  <a href="https://packagist.org/packages/markshust/magento2-module-simpledata" target="_blank"><img src="https://img.shields.io/packagist/v/markshust/magento2-module-simpledata.svg?style=flat-square" alt="Latest Stable Version" /></a>
  <a href="https://packagist.org/packages/markshust/magento2-module-simpledata" target="_blank"><img src="https://poser.pugx.org/markshust/magento2-module-simpledata/downloads" alt="Composer Downloads" /></a>
  <a href="https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity" target="_blank"><img src="https://img.shields.io/badge/maintained%3F-yes-brightgreen.svg?style=flat-square" alt="Maintained - Yes" /></a>
  <a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/license-MIT-blue.svg" /></a>
</div>

### Table of contents

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

### Summary

Calling Magento data structures can be confusing. There are many classes available, and knowing which to call and when can be confusing & 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)

### Installation

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

### Usage

Here are the signatures of the simplified data structures classes:

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

```php
/**
 * 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`

```php
/**
 * 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

##### Create block

```php
<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class BlockFooBarCreate extends SimpleDataPatch
{
    public function apply(): void
    {
        $this->block->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar',
            'content' => <<<CONTENT
<div class="foo-bar">
    Foo bar
</div>
CONTENT,
        ]);
    }
}
```

##### Delete block

```php
<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class BlockFooBarDelete extends SimpleDataPatch
{
    public function apply()
    {
        $this->block->delete('foo_bar');
    }
}
```

##### Update block

```php
<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class BlockFooBarUpdate extends SimpleDataPatch
{
    public function apply()
    {
        $this->block->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar 1',
        ]);
    }
}
```

##### Create page

```php
<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class PageFooBarCreate extends SimpleDataPatch
{
    public function apply()
    {
        $this->page->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar',
            'content' => <<<CONTENT
<div class="foo-bar">
    Foo bar
</div>
CONTENT,
        ]);
    }
}
```

##### Update page

```php
<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class MyDataPatch extends SimpleDataPatch
{
    public function apply()
    {
        $this->page->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar 1',
        ]);
    }
}
```

##### Delete page

```php
<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class PageFooBarDelete extends SimpleDataPatch
{
    public function apply()
    {
        $this->page->delete('foo_bar');
    }
}
```

##### Create or update config

```php
<?php

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class ConfigFooBarCreate extends SimpleDataPatch
{
    public function apply()
    {
        $this->config->save('foo/bar', 'baz');
    }
}

```

##### Delete config

```php
<?php

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class ConfigFooBarDelete extends SimpleDataPatch
{
    public function apply()
    {
        $this->config->delete('foo/bar');
    }
}
```

#### Example using dependency injection

_(README truncated for .md surface. Full README on https://packagento.com/markshust/magento2-module-simpledata.)_

## Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

### [2.0.2] - 2022-06-28

#### Fixed
- Change return type to match PatchInterface.

### [2.0.1] - 2020-01-13

#### Fixed
- Removed typed properties for PHP 7.3 support.

### [2.0.0] - 2020-01-12

#### Added
- Added type declarations to class properties.

#### Removed
- Removed `SimpleConfig` class_alias as it caused issues in production mode ([#4](https://github.com/markshust/magento2-module-simpledata/issues/4)). 

### [1.0.0] - 2020-05-20

#### Added
- Initial release.

## Recent Versions

| Version | Released |
|---|---|
| 2.0.2 | 2022-06-29 |
| 2.0.1 | 2021-01-13 |
| 2.0.0 | 2021-01-12 |
| 1.0.0 | 2020-05-20 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| magento/framework | >=101 |
| php | >=7.1 |

## Quality

Latest release (2.0.2) passes the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Pass | Pass | – | – |
| 2.4.8 | – | Pass | Pass | – |
| 2.4.9 | – | – | Pass | Pass |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — a phpcs finding can't make a module incompatible.

#### Static Analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Warning | 4 | 4 warnings (ruleset: Magento2) — 4 auto-fixable with phpcbf |
| PHPMD | Pass | 0 |  |
| Cpd | Pass | 0 |  |
| Composer validate | Info | 2 | valid; 2 advisory notes (composer validate --strict) |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Pass | Pass | – | – |
| 2.4.8 | – | Pass | Pass | – |
| 2.4.9 | – | – | Pass | Pass |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |

#### Integration Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Security

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["markshust/magento2-module-simpledata"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

markshust is a Magento 2 vendor on Packagento. See https://packagento.com/markshust.md for their full catalogue.

