Doctrine-like fixtures integration for Shopware 6.

Overview

Shopware 6 Fixtures

Did you ever want to create and load Doctrine-like fixtures in your Shopware 6 plugin?

Look no further!

This plugin provides an ultra-lightweight approach to fixture loading in your Shopware 6 plugin.

Usage requirements

shopware

Development requirements

git cmake docker

Usage

Install and activate the plugin in your Shopware instance.

composer require family-office/fixtures
bin/console plugin:refresh && bin/console plugin:install FamilyOfficeFixtures --activate

We start by creating a fixture class which is implementing the FixtureInterface.

In this example, we're creating demo data for fictional entity named Elephant.

<?php // <plugin root>/src/Fixtures/ElephantFixtures.php

namespace PluginThatNeedsFixtures\Fixtures;

use FamilyOffice\Fixtures\Component\FixtureInterface;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\Uuid\Uuid;

class ElephantFixtures implements FixtureInterface
{
    private EntityRepositoryInterface $elephantRepository;

    public function __construct(EntityRepositoryInterface $elephantRepository)
    {
        $this->elephantRepository = $elephantRepository;
    }
    
    public function getDependencies(): array
    {
        return [];
    }

    public function load(): void
    {
        $this->elephantRepository->create([
            'id' => Uuid::randomHex(),
            'name' => 'PHP Elephant',
            'color' => 'blue'
        ], Context::createDefaultContext());
    }
}

After creating our fixture class, we will have to register it as a service.

It's automatically tagged as a fixture (fo.entity.fixture) if you use auto configuration.

<!-- <plugin root>/src/Resources/services.xml -->
<service id="PluginThatNeedsFixtures\Fixtures\ElephantFixtures"/>

Sometimes, a fixture depends on another fixture.

Maybe our ElephantFixtures entity require the BigEarsFixtures to be loaded before them.

If both fixtures are defined within the same services.xml file, the loading order can be changed by arranging the service definitions accordingly.

<!-- <plugin root>/src/Resources/services.xml -->

<!-- first loaded -->
<service id="PluginThatNeedsFixtures\Fixture\BigEarsFixtures"/>

<!-- second loaded -->
<service id="PluginThatNeedsFixtures\Fixture\ElephantFixture"/>

A perhaps easier way to depend on another fixture, which also works if the dependet on fixture is defined in a different services.xml file, is to return all fixtures classes the current fixture depends on in the getDependencies method.

<?php // <plugin root>/src/Fixture/ElephantFixtures.php

namespace PluginThatNeedsFixtures\Fixtures;

// ...

class ElephantFixtures implements FixtureInterface
{
    private EntityRepositoryInterface $elephantRepository;

    public function __construct(EntityRepositoryInterface $elephantRepository)
    {
        $this->elephantRepository = $elephantRepository;
    }
    
    public function getDependencies(): array
    {
        return [
            BigEarsFixtures::class
        ];
    }

    public function load(): void
    {
        // ...
    }
}

Circular dependencies and loading a fixture more than once are prohibited by default.

Finally, make sure the plugin you are trying to load the fixtures for is installed and activated.

If that is the case, go ahead and load the fixtures.

bin/console fo:fixtures:load

The command loads all fixtures from all installed and activated plugins.

Development

Clone the project into your Shopware installation

git clone [email protected]:Family-Office-Company/FamilyOfficeFixtures.git
cd FamilyOfficeFixtures

Install the development dependencies

make install

..and start developing! 🥳

Acknowledgements

Thanks to Freepik from www.flaticon.com for providing the plugin icon.

License

This project is licensed under the MIT license.
Feel free to do whatever you want with the code!

You might also like...
A RESTful and extendable Backend as a Service that provides instant backend to develop sites and apps faster, with dead-simple integration for JavaScript, iOS, Android and more.

Welcome to hook ![Gitter](https://badges.gitter.im/Join Chat.svg) hook is a RESTful, extendable Backend as a Service that provides instant backend to

Judge0 API integration for running/judging code with different languages

Laravel Judge0 Judge0 API integration for running/judging code with different languages use Mouadbnl\Judge0\Models\Submission; $submission = Submissi

PHP library for Qvapay API integration.

Php library for Qvapay API This PHP library facilitates the integration of the Qvapay API. Sign up on QvaPay Create your account to process payments t

Paynow SDK Laravel integration

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

WordPress integration for globalis/chargebee-php-sdk
WordPress integration for globalis/chargebee-php-sdk

chargebee-php-sdk-wp Overview WordPress integration for globalis/chargebee-php-sdk Features Convert PSR-14 events into WordPress hooks Add query-monit

Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project

AmiAirbrakeBundle Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project. Prerequisites Th

Shopware 5 Repository - For Shopware 6 visit https://github.com/shopware/platform
Shopware 5 Repository - For Shopware 6 visit https://github.com/shopware/platform

Shopware 5 License: Dual license AGPL v3 / Proprietary Github Repository: https://github.com/shopware/shopware Issue Tracker: https://issues.shopware.

Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs
Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs

Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps to access the API in an object-oriented way.

Expressive fixtures generator
Expressive fixtures generator

Alice - Expressive fixtures generator Relying on FakerPHP/Faker, Alice allows you to create a ton of fixtures/fake data for use while developing or te

Shopware 6 is an open source ecommerce platform based on a quite modern technology stack that is powered by Symfony and Vue.js.
Shopware 6 is an open source ecommerce platform based on a quite modern technology stack that is powered by Symfony and Vue.js.

Shopware 6 Realize your ideas - fast and without friction. Shopware 6 is an open source ecommerce platform based on a quite modern technology stack th

A Laravel package to help integrate Shopware PHP SDK much more easier

Shopware 6 Laravel SDK A Laravel package to help integrate Shopware PHP SDK much more easier Installation Install with Composer composer require sas/s

Shopware 6 app boilerplate + Symfony backend + Dockware docker dev environment 💙

Shopware 6 app boilerplate with Symfony backend This boilerplate template can be used to get up and running with a docker-based dev setup for Shopware

Shopware plugin to show a variant switch on the product listing and within the (checkout) cart.
Shopware plugin to show a variant switch on the product listing and within the (checkout) cart.

Variant switch for Shopware 6 A plugin for Shopware 6 Features Show variant switch on product listing card Variant switch when hovering a variant prop

The fixture plugin is really helpful if you want to create some static demo data for your shopware instance.

Fixture Plugin The fixture plugin is really helpful if you want to create some static demo data for your shopware instance. Installation Just add it t

Provides integration for Doctrine with various Symfony components.

Doctrine Bridge The Doctrine bridge provides integration for Doctrine with various Symfony components. Resources Contributing Report issues and send P

This package provides a set of factories to be used with containers using the PSR-11 standard for an easy Doctrine integration in a project

psr-container-doctrine: Doctrine Factories for PSR-11 Containers Doctrine factories for PSR-11 containers. This package provides a set of factories to

🎲 This project provides an integration for the Doctrine ORM and the Hyperf framework

Hyperf 🤝 Doctrine This project provides an integration for the Doctrine ORM and the Hyperf framework. Install composer require leocavalcante/hyperf-d

Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

Laravel Befriended Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked

🚀WordPress Plugin Boilerplate using modern web techs like TypeScript, SASS, and so on... on top of a local development environment with Docker and predefined GitLab CI for continous integration and deployment!
🚀WordPress Plugin Boilerplate using modern web techs like TypeScript, SASS, and so on... on top of a local development environment with Docker and predefined GitLab CI for continous integration and deployment!

WP React Starter: WordPress React Boilerplate DEPRECATED: WP React Starter was a "research project" of devowl.io for the development of our WordPress

Releases(1.2.0)
Owner
Familiy Office
Familiy Office
Shopware plugin to show a variant switch on the product listing and within the (checkout) cart.

Variant switch for Shopware 6 A plugin for Shopware 6 Features Show variant switch on product listing card Variant switch when hovering a variant prop

Shape & Shift 17 Aug 26, 2022
Quickly and easily expose Doctrine entities as REST resource endpoints with the use of simple configuration with annotations, yaml, json or a PHP array.

Drest Dress up doctrine entities and expose them as REST resources This library allows you to quickly annotate your doctrine entities into restful res

Lee Davis 88 Nov 5, 2022
This project lists all the mandatory steps I recommend to build a Website using Symfony, Twig, Doctrine.

{% raw %} <-- keep this for Jekyll to fully bypass this documents, because of the Twig tags. Symfony Website Checklist ?? Summary~~~~ Elevator pitch P

William Pinaud 6 Aug 31, 2022
This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like.

Simple PHP API v.1.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses a

Edson M. de Souza 14 Nov 18, 2021
PHP 8.1 like legacy enum (Experimental Alpha Version)

flux-legacy-enum PHP 8.1 like legacy enum Experimental Alpha Version Installation COPY --from=docker-registry.fluxpublisher.ch/flux-enum/legacy:latest

fluxlabs 1 Dec 12, 2022
Like FormRequests, but for validating against a json-schema

JSON Schema Request Laravels Form Request Validation for JSON Schema documents Installation composer require wt-health/laravel-json-schema-request Us

Webtools Health 1 Feb 3, 2022
Provides a Middleware to integration Tideways into Symfony Messenger Processing

Tideways Middleware for Symfony Messenger This package is currently under development and might be moved into the Tideways PHP Extension or stay indep

Tideways 6 Jul 5, 2022
Integration with your Symfony app & Vite

ViteBundle : Symfony integration with Vite This bundle helping you render all of the dynamic script and link tags needed. Essentially, he provide two

Hugues Tavernier 84 Dec 21, 2022
Fully unit tested Facebook SDK v5 integration for Laravel & Lumen

Laravel Facebook SDK A fully unit-tested package for easily integrating the Facebook SDK v5 into Laravel and Lumen 5.0, 5.1, 5.2, & 5.3. This is packa

Sammy Kaye Powers 697 Nov 6, 2022
Modern version of pocketmine forms API, ported to PHP 8.0+ with high quality code and phpstan integration

forms Modern version of pocketmine forms API, ported to PHP 8.0+ with high quality code and phpstan integration Code samples ModalForm Using ModalForm

Frago9876543210 23 Nov 18, 2022