{"id":15610621,"url":"https://github.com/markshust/magento2-module-simpledata","last_synced_at":"2025-04-07T09:19:52.368Z","repository":{"id":46122770,"uuid":"265627509","full_name":"markshust/magento2-module-simpledata","owner":"markshust","description":"The SimpleData module simplifies calling Magento data structures.","archived":false,"fork":false,"pushed_at":"2023-08-22T15:24:47.000Z","size":1826,"stargazers_count":95,"open_issues_count":5,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T07:07:59.061Z","etag":null,"topics":["magento","magento2","magento2-module"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markshust.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"markshust"}},"created_at":"2020-05-20T16:41:56.000Z","updated_at":"2025-03-03T15:38:57.000Z","dependencies_parsed_at":"2024-06-21T02:16:39.777Z","dependency_job_id":"f6dca389-6ef3-4ae5-9ee3-dbacf4a4f594","html_url":"https://github.com/markshust/magento2-module-simpledata","commit_stats":{"total_commits":14,"total_committers":3,"mean_commits":4.666666666666667,"dds":0.1428571428571429,"last_synced_commit":"75cd52787c59a526e1952d6183350e91470e865c"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markshust%2Fmagento2-module-simpledata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markshust%2Fmagento2-module-simpledata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markshust%2Fmagento2-module-simpledata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markshust%2Fmagento2-module-simpledata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markshust","download_url":"https://codeload.github.com/markshust/magento2-module-simpledata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247622983,"owners_count":20968575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["magento","magento2","magento2-module"],"created_at":"2024-10-03T06:02:02.718Z","updated_at":"2025-04-07T09:19:52.338Z","avatar_url":"https://github.com/markshust.png","language":"PHP","funding_links":["https://github.com/sponsors/markshust"],"categories":["PHP"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eMarkShust_SimpleData\u003c/h1\u003e \n\n\u003cdiv align=\"center\"\u003e\n  \u003cp\u003eSimplifies calling Magento data structures.\u003c/p\u003e\n  \u003cimg src=\"https://img.shields.io/badge/magento-2.2%20|%202.3-brightgreen.svg?logo=magento\u0026longCache=true\u0026style=flat-square\" alt=\"Supported Magento Versions\" /\u003e\n  \u003ca href=\"https://packagist.org/packages/markshust/magento2-module-simpledata\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/markshust/magento2-module-simpledata.svg?style=flat-square\" alt=\"Latest Stable Version\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://packagist.org/packages/markshust/magento2-module-simpledata\" target=\"_blank\"\u003e\u003cimg src=\"https://poser.pugx.org/markshust/magento2-module-simpledata/downloads\" alt=\"Composer Downloads\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/maintained%3F-yes-brightgreen.svg?style=flat-square\" alt=\"Maintained - Yes\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/MIT\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\" /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n## Table of contents\n\n- [Summary](#summary)\n- [Installation](#installation)\n- [Usage](#usage)\n- [License](#license)\n\n## Summary\n\nCalling Magento data structures can be confusing. There are many classes available, and knowing which to call and when can be confusing \u0026 overwhelming.\n\nThis 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.\n\nFor example, here is a data patch script to update the content of a CMS page with and without `SimpleData`:\n\n![Demo](https://raw.githubusercontent.com/markshust/magento2-module-simpledata/master/docs/demo.png)\n\n## Installation\n\n```sh\ncomposer require markshust/magento2-module-simpledata\nbin/magento module:enable MarkShust_SimpleData\nbin/magento setup:upgrade\n```\n\n## Usage\n\nHere are the signatures of the simplified data structures classes:\n\n`MarkShust\\SimpleData\\Api\\Data\\Cms\\SimpleBlock`\n\n```php\n/**\n * Delete a block from a given identifier and optional store id.\n * @param string $identifier\n * @param int $storeId\n */\npublic function delete(string $identifier, int $storeId = Store::DEFAULT_STORE_ID): void\n\n/**\n * If the CMS block identifier is found, attempt to update the record.\n * If it is not found, attempt to create a new record.\n * @param array $data\n */\npublic function save(array $data): void\n```\n\n`MarkShust\\SimpleData\\Api\\Data\\Cms\\SimplePage`\n\n```php\n/**\n * Delete a page from a given identifier and optional store id.\n * @param string $identifier\n * @param int $storeId\n */\npublic function delete(string $identifier, int $storeId = Store::DEFAULT_STORE_ID): void\n\n/**\n * If the CMS page identifier is found, attempt to update the record.\n * If it is not found, attempt to create a new record.\n * @param array $data\n */\npublic function save(array $data): void\n```\n\n### Examples using SimpleDataPatch\n\n#### Create block\n\n```php\n\u003c?php\ndeclare(strict_types = 1);\n\nnamespace MarkShust\\Data\\Setup\\Patch\\Data;\n\nuse MarkShust\\SimpleData\\Setup\\Patch\\SimpleDataPatch;\n\nclass BlockFooBarCreate extends SimpleDataPatch\n{\n    public function apply(): self\n    {\n        $this-\u003eblock-\u003esave([\n            'identifier' =\u003e 'foo_bar',\n            'title' =\u003e 'Foo bar',\n            'content' =\u003e \u003c\u003c\u003cCONTENT\n\u003cdiv class=\"foo-bar\"\u003e\n    Foo bar\n\u003c/div\u003e\nCONTENT,\n        ]);\n    }\n}\n```\n\n#### Delete block\n\n```php\n\u003c?php\ndeclare(strict_types = 1);\n\nnamespace MarkShust\\Data\\Setup\\Patch\\Data;\n\nuse MarkShust\\SimpleData\\Setup\\Patch\\SimpleDataPatch;\n\nclass BlockFooBarDelete extends SimpleDataPatch\n{\n    public function apply()\n    {\n        $this-\u003eblock-\u003edelete('foo_bar');\n    }\n}\n```\n\n#### Update block\n\n```php\n\u003c?php\ndeclare(strict_types = 1);\n\nnamespace MarkShust\\Data\\Setup\\Patch\\Data;\n\nuse MarkShust\\SimpleData\\Setup\\Patch\\SimpleDataPatch;\n\nclass BlockFooBarUpdate extends SimpleDataPatch\n{\n    public function apply()\n    {\n        $this-\u003eblock-\u003esave([\n            'identifier' =\u003e 'foo_bar',\n            'title' =\u003e 'Foo bar 1',\n        ]);\n    }\n}\n```\n\n#### Create page\n\n```php\n\u003c?php\ndeclare(strict_types = 1);\n\nnamespace MarkShust\\Data\\Setup\\Patch\\Data;\n\nuse MarkShust\\SimpleData\\Setup\\Patch\\SimpleDataPatch;\n\nclass PageFooBarCreate extends SimpleDataPatch\n{\n    public function apply()\n    {\n        $this-\u003epage-\u003esave([\n            'identifier' =\u003e 'foo_bar',\n            'title' =\u003e 'Foo bar',\n            'content' =\u003e \u003c\u003c\u003cCONTENT\n\u003cdiv class=\"foo-bar\"\u003e\n    Foo bar\n\u003c/div\u003e\nCONTENT,\n        ]);\n    }\n}\n```\n\n#### Update page\n\n```php\n\u003c?php\ndeclare(strict_types = 1);\n\nnamespace MarkShust\\Data\\Setup\\Patch\\Data;\n\nuse MarkShust\\SimpleData\\Setup\\Patch\\SimpleDataPatch;\n\nclass MyDataPatch extends SimpleDataPatch\n{\n    public function apply()\n    {\n        $this-\u003epage-\u003esave([\n            'identifier' =\u003e 'foo_bar',\n            'title' =\u003e 'Foo bar 1',\n        ]);\n    }\n}\n```\n\n#### Delete page\n\n```php\n\u003c?php\ndeclare(strict_types = 1);\n\nnamespace MarkShust\\Data\\Setup\\Patch\\Data;\n\nuse MarkShust\\SimpleData\\Setup\\Patch\\SimpleDataPatch;\n\nclass PageFooBarDelete extends SimpleDataPatch\n{\n    public function apply()\n    {\n        $this-\u003epage-\u003edelete('foo_bar');\n    }\n}\n```\n\n#### Create or update config\n\n```php\n\u003c?php\n\nnamespace MarkShust\\Data\\Setup\\Patch\\Data;\n\nuse MarkShust\\SimpleData\\Setup\\Patch\\SimpleDataPatch;\n\nclass ConfigFooBarCreate extends SimpleDataPatch\n{\n    public function apply()\n    {\n        $this-\u003econfig-\u003esave('foo/bar', 'baz');\n    }\n}\n\n```\n\n#### Delete config\n\n```php\n\u003c?php\n\nnamespace MarkShust\\Data\\Setup\\Patch\\Data;\n\nuse MarkShust\\SimpleData\\Setup\\Patch\\SimpleDataPatch;\n\nclass ConfigFooBarDelete extends SimpleDataPatch\n{\n    public function apply()\n    {\n        $this-\u003econfig-\u003edelete('foo/bar');\n    }\n}\n```\n\n### Example using dependency injection\n\n```php\n\u003c?php\ndeclare(strict_types = 1);\n\nnamespace MarkShust\\SimpleData;\n\nuse MarkShust\\SimpleData\\Api\\Cms\\SimpleBlock;\n\nclass MyClass\n{\n    /** @var SimpleBlock */\n    protected $block;\n\n    /**\n     * SimpleDataPatch constructor.\n     * @param SimpleBlock $simpleBlock\n     */\n    public function __construct(\n        SimpleBlock $simpleBlock\n    ) {\n        $this-\u003eblock = $simpleBlock;\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function execute(): void\n    {\n        $this-\u003eblock-\u003esave([\n            'identifier' =\u003e 'foo_bar',\n            'title' =\u003e 'Foo bar',\n            'content' =\u003e \u003c\u003c\u003cCONTENT\n\u003cdiv class=\"foo-bar\"\u003e\n    Foo bar\n\u003c/div\u003e\nCONTENT,\n        ]);\n\n        // Carry out other actions...\n    }\n}\n```\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkshust%2Fmagento2-module-simpledata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkshust%2Fmagento2-module-simpledata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkshust%2Fmagento2-module-simpledata/lists"}