Miscellaneous script services reference
Shopware\Core\Framework\Script\Facade\ArrayFacade
The ArrayFacade acts as a wrapper around an array and allows easier manipulation of arrays inside scripts. An array facade can also be accessed like a "normal" array inside twig. Examples:
{% do array.push('test') %}
{% do array.foo = 'bar' }
{% do array.has('foo') }
{% if array.foo === 'bar' %}
{% foreach array as key => value %}
set()
set()
adds a new element to the array using the given key.Arguments:
string|int
key: The array key.mixed
value: The value that should be added.
Examples:
Add a new element with key
test
and value 1.twig{% set product = services.cart.products.get(hook.ids.get('p1')) %} {% do product.payload.set('test', 1) %}
push()
push()
adds a new value to the end of the array.Arguments:
mixed
value: The value that should be added.
removeBy()
removeBy()
removes the value at the given index from the array.Arguments:
string|int
index: The index that should be removed.
remove()
remove()
removes the given value from the array. It does nothing if the provided value does not exist in the array.Arguments:
mixed
value: The value that should be removed.
reset()
reset()
removes all entries from the array.
merge()
merge()
recursively merges the array with the given array.Arguments:
array<string|int,mixed>|\ArrayFacade
array: The array that should be merged with this array. Either a plainarray
or anotherArrayFacade
.
Examples:
Merge two arrays.
twig{% set my_array = array({'bar': 'foo', 'baz': true}) %} {% do product.payload.merge(my_array) %}
replace()
replace()
recursively replaces elements from the given array into this array.Arguments:
array<string|int,mixed>|\ArrayFacade
array: The array from which the elements should be replaced into this array. Either a plainarray
or anotherArrayFacade
.
Examples:
Replace elements in the product payload array.
twig{% set second = array({'bar': 'baz'}) %} {% do product.payload.replace(second) %}
count()
count()
returns the count of elements inside this array.Returns
int
Returns the count of elements.
all()
all()
function returns all elements of this array.Returns
array
Returns all elements of this array.
services.config (Shopware\Core\System\SystemConfig\Facade\SystemConfigFacade
)
The config
service allows you to access the shop's and your app's configuration values.
get()
The
get()
method allows you to access all config values of the store.Notice that your app needs the
system_config:read
privilege to use this method.Returns
array|bool|float|int|string|null
Arguments:
string
key: The key of the configuration value e.g.core.listing.defaultSorting
.string
|null
salesChannelId: The SalesChannelId if you need the config value for a specific SalesChannel, if you don't provide a SalesChannelId, the one of the current Context is used as default.Default:
null
Examples:
Read an arbitrary system_config value.
twig{% set systemConfig = services.config.get('core.listing.productsPerPage') %}
app()
The
app()
method allows you to access the config values your app's configuration.Notice that your app does not need any additional privileges to use this method, as you can only access your own app's configuration.
Returns
array|bool|float|int|string|null
Arguments:
string
key: The name of the configuration value specified in the config.xml e.g.exampleTextField
.string
|null
salesChannelId: The SalesChannelId if you need the config value for a specific SalesChannel, if you don't provide a SalesChannelId, the one of the current Context is used as default.Default:
null
Examples:
Read your app's config value.
twig{% set appConfig = services.config.app('app_config') %}