All Projects → markshust → magento2-module-simpledata

markshust / magento2-module-simpledata

Licence: MIT license
The SimpleData module simplifies calling Magento data structures.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to magento2-module-simpledata

Slider-M2
Slider extension for Magento 2.x
Stars: ✭ 17 (-79.27%)
Mutual labels:  magento, magento2, magento2-module
Brazilian-Solutions
Este repositório permite a discussão da comunidade brasileira Magento sobre módulos e soluções para o mercado brasileiro.
Stars: ✭ 19 (-76.83%)
Mutual labels:  magento, magento2, magento2-module
magento2-module-ordergrid
The Order Grid module adds more details to the order grid in the admin.
Stars: ✭ 54 (-34.15%)
Mutual labels:  magento, magento2, magento2-module
module-notifications
Notify the Magento 2 admin user about disabled caches or new customer reviews.
Stars: ✭ 20 (-75.61%)
Mutual labels:  magento, magento2, magento2-module
magento2-allegro
Magento 2 Allegro Integration module
Stars: ✭ 25 (-69.51%)
Mutual labels:  magento, magento2, magento2-module
Magento-Quickorder
Magento Quickorder module, enables bulk order creation by inputting SKUs & quantities.
Stars: ✭ 30 (-63.41%)
Mutual labels:  magento, magento2, magento2-module
magento2-language-tr tr
Magento2 Turkish Translation / Magento2 Türkçe Çevirisi
Stars: ✭ 28 (-65.85%)
Mutual labels:  magento, magento2, magento2-module
rebuild-urlrewrite
Rebuild Url Rewrite for magento 2
Stars: ✭ 26 (-68.29%)
Mutual labels:  magento, magento2, magento2-module
magento2-edit-order-email
Magento2 - Edit Order Email from Admin
Stars: ✭ 30 (-63.41%)
Mutual labels:  magento, magento2, magento2-module
magento2
For any issues or questions please get in touch with us via [email protected]
Stars: ✭ 15 (-81.71%)
Mutual labels:  magento, magento2, magento2-module
module-login-as-customer
Allows admin to login as a customer (enter to customer account).
Stars: ✭ 104 (+26.83%)
Mutual labels:  magento, magento2, magento2-module
magento2-db-log-cleaner
Magento2 Cron Log Cleaning
Stars: ✭ 23 (-71.95%)
Mutual labels:  magento, magento2, magento2-module
magento2-customer-account-links-manager
Customer Account Links Manager allows you to quickly and easily remove customer account links from Magento 2 customer dashboard.
Stars: ✭ 40 (-51.22%)
Mutual labels:  magento, magento2, magento2-module
MultipleLayeredNavigation-M2
Magento 2 Multiple Layered Navigation extension.
Stars: ✭ 20 (-75.61%)
Mutual labels:  magento, magento2, magento2-module
blog
MageVision Blog
Stars: ✭ 23 (-71.95%)
Mutual labels:  magento, magento2, magento2-module
magento2-guest-to-customer
Guest to Customer for Magento2 - Quickly and easily convert existing guest checkout customers to registered customers.
Stars: ✭ 66 (-19.51%)
Mutual labels:  magento, magento2, magento2-module
magento2-showoutofstockprice
This Magento2 Module adds prices and the add-to-cart button to out-of-stock configurable products.
Stars: ✭ 22 (-73.17%)
Mutual labels:  magento, magento2, magento2-module
LargeConfigProducts
Large Configurable Products workaround for Magento 2
Stars: ✭ 83 (+1.22%)
Mutual labels:  magento, magento2, magento2-module
module-blog-m22
Fixes for Blog on Magento 2.2.x
Stars: ✭ 21 (-74.39%)
Mutual labels:  magento, magento2, magento2-module
module-dsu-client
No description or website provided.
Stars: ✭ 17 (-79.27%)
Mutual labels:  magento, magento2, magento2-module

MarkShust_SimpleData

Simplifies calling Magento data structures.

Supported Magento Versions Latest Stable Version Composer Downloads Maintained - Yes

Table of contents

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

Installation

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

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

Create block

<?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
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
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
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
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
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

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

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

<?php
declare(strict_types = 1);

namespace MarkShust\SimpleData;

use MarkShust\SimpleData\Api\Cms\SimpleBlock;

class MyClass
{
    /** @var SimpleBlock */
    protected $block;

    /**
     * SimpleDataPatch constructor.
     * @param SimpleBlock $simpleBlock
     */
    public function __construct(
        SimpleBlock $simpleBlock
    ) {
        $this->block = $simpleBlock;
    }

    /**
     * {@inheritdoc}
     */
    public function execute(): void
    {
        $this->block->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar',
            'content' => <<<CONTENT
<div class="foo-bar">
    Foo bar
</div>
CONTENT,
        ]);

        // Carry out other actions...
    }
}

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].