Skip to content

Fixture Helper

Often in fixtures, you need to access specific entities in the database, delete old records, or create new ones. Writing all these database queries multiple times can become quite cumbersome. To simplify this, we have integrated a handy helper class: FixtureHelper.

The FixtureHelper provides numerous small methods to fetch data from the database or write records.

WARNING

The fixture helpers are designed to be most convenient for local development and fixtures. They are not intended for use in production code!

How to use

The FixtureHelper is already included in any fixture (since version 3). You can simply access the fixture helper:

php
<?php

namespace MyName\MyPlugin\Fixtures;

use Basecom\FixturePlugin\Fixture;

class CustomerFixture extends Fixture {
    public function load(): void {
        $this->helper->SalesChannel()->getStorefrontSalesChannel(); 
    }
}

If you are using version 2 or want to use the FixtureHelper in other cases (like tests), you can use dependency injection like any other Symfony service:

php
<?php

class MyExampleService {
    public function __construct(
        private readonly FixtureHelper $helper 
    ) {}

    public function doSomething() {
        $this->helper->SalesChannel()->getStorefrontSalesChannel(); 
    }
}

Available helpers

Below is a list of all available helper categories. Please refer to the documentation for each category to see all the available methods:

HelperDescriptionDocumentation
Utility MethodsSome general methods to help writing fixturesUtility Methods
MediaMethods to interact with the media entitiesMedia Helpers
CategoryMethods to interact with the categoriy entitiesCategory Helpers
Sales ChannelMethods to interact with the sales channel entitiesSales Channel Helpers
SalutationMethods to interact with the salutation entitiesSalutation Helpers
CMSMethods to interact with the cms page entitiesCMS Helpers
Payment MethodMethods to interact with the payment method entitiesPayment Method Helpers
Shipping MethodMethods to interact with the shipping method entitiesShipping Method Helpers
Language & LocaleMethods to interact with the language & locale entitiesLanguage & Locale Helpers
CurrencyMethods to interact with the currency entitiesCurrency Helpers
TaxMethods to interact with the tax entitiesTax Helpers
DatabaseMethods to interact with the database itselfDatabase Helpers

Each helper category provides specialized methods to make working with different aspects of your Shopware setup easier and more efficient.

Released under the MIT License.