Use this helper to manage core_config_data entries inside patches.
Import it as follows:
public function __construct(
Migration\Context $context,
private Migration\Facade\AdminConfig $adminConfig
) {
parent::__construct($context);
}Retrieve existing config for a given path:
$username = $this->adminConfig->get('my/module/user');Override an existing entry, or create a new one if needed. You can also pass an array of paths, and each item may override scope and scope_id:
$this->adminConfig->set('payment/creditcard/identifier', 'My Store');
$this->adminConfig->set([
'catalog/frontend/flat_catalog_category' => '1',
'web/secure/use_in_frontend' => [
'value' => '1',
'scope' => 'stores',
'scope_id' => 2,
],
]);Equivalent to checking the "restore" checkbox in admin. Force the setting to fallback to its default value defined in some config.xml. This method accepts either a single path or an array of paths:
$this->adminConfig->restore('shipping/carrier/show_foo_in_checkout');
$this->adminConfig->restore([
'web/secure/use_in_frontend',
'design/head/includes',
]);Append a value to a given setting. Useful for managing the HTML scripts theme field and similar ones.
$this->adminConfig->append('design/head/includes', <<<HTML
<script src="https://another.slow.chat/script.js" async></script>
HTML);appendOption($path, $option, $separator = ',', $scope = ScopeConfig::SCOPE_TYPE_DEFAULT, $scopeId = null)
Append one or multiple options to list-like config values, avoiding duplicates:
$this->adminConfig->appendOption(
'catalog/frontend/flat_catalog_category',
'new_option'
);Use these helpers to create, read, update, and delete CMS pages or blocks.
To import them:
public function __construct(
Migration\Context $context,
private Migration\Facade\CmsBlock $cmsBlock,
private Migration\Facade\CmsPage $cmsPage,
) {
parent::__construct($context);
}Both CmsPage and CmsBlock share the same methods below. Methods that read or write store assignments accept $storeId = null to use the default/global scope.
Load a page or block by its identifier:
$footerBlock = $this->cmsBlock->get('footer');Create a new entry on the database for the given content:
$this->cmsPage->create('my-new-page', [
'title' => 'Lorem Ipsum',
'content' => <<<HTML
<span>Hello World!</span>
HTML,
]);Similar to create(), but if the content already exists it leaves it unchanged and returns that existing page or block instance.
Update the content of the existing CMS content:
$this->cmsBlock->update('footer', [
'title' => 'Lorem Ipsum',
'content' => <<<HTML
<ul><!-- page builder generated stuff --></ul>
HTML,
]);Similar to update(), but only applies changes when the content already exists. Returns the updated page or block instance, or null when nothing matches.
If content with the given identifier already exists, update it with the provided data. Otherwise, create it:
$this->cmsPage->createOrUpdate('my-page', [
'title' => 'Lorem Ipsum',
'content' => <<<HTML
<span>Hello World!</span>
HTML,
]);Delete the respective CMS entity:
$this->cmsBlock->delete('seasonal-offers');Similar to delete(), but skips deletion when the CMS entity already doesn't exists.
Check if a page or block with the given identifier already exists on the database:
if (!$this->cmsBlock->exists('seasonal-offers')) {
$this->cmsBlock->create('seasonal-offers', [
'title' => 'Seasonal Offers',
'content' => '<p>Seasonal offers</p>',
]);
}Tip
Use Page Builder normally and copy the content field directly from your database to fill the HTML content.
These methods are shared by CategoryAttribute, CustomerAttribute, and ProductAttribute facades.
Create a new EAV attribute:
$attribute = $this->productAttribute->create('brand_badge', [
'label' => 'Brand Badge',
'input' => 'text',
'type' => 'varchar',
]);Similar to create(), but if the attribute already exists it leaves it unchanged and returns that existing attribute instance.
Update an existing attribute definition:
$this->productAttribute->update('brand_badge', [
'label' => 'Brand Highlight',
]);Similar to update(), but skips the update when the attribute does not exist.
Delete an existing attribute definition.
Similar to delete(), but skips deletion when the attribute does not exist.
Check whether an attribute already exists:
if (!$this->productAttribute->exists('brand_badge')) {
$this->productAttribute->create('brand_badge', [
'label' => 'Brand Badge',
'input' => 'text',
'type' => 'varchar',
]);
}Use this helper to manage category attributes and mass update category attribute values.
Import it as follows:
public function __construct(
Migration\Context $context,
private Migration\Facade\CategoryAttribute $categoryAttribute
) {
parent::__construct($context);
}Mass update given categories. This changes entity attribute values, not the attribute definition itself:
$categoryIds = [4, 5];
$this->categoryAttribute->massUpdate($categoryIds, [
'description' => 'Clothes',
]);Use this helper to manage customer attributes.
Use it as follows:
public function __construct(
Migration\Context $context,
private Migration\Facade\CustomerAttribute $customerAttribute
) {
parent::__construct($context);
}Use this helper to manage product attributes, assign them to attribute sets, and mass update product attribute values.
Import it as follows:
public function __construct(
Migration\Context $context,
private Migration\Facade\ProductAttribute $productAttribute
) {
parent::__construct($context);
}Create a new dropdown attribute:
$attribute = $this->productAttribute->createDropdown('sizes', 'Clothes Size', ['P', 'M', 'G']);Similar to createDropdown(), but returns the existing attribute when it already exists.
Simulates the process of navigating to Stores -> Attribute Set and assigning an attribute there:
$this->productAttribute->assignToAttributeSet(
'size',
'Clothes',
'Tech Specs',
'gender'
);Remove an attribute from the given attribute set. When $attributeSetId is omitted, the default product attribute set is used:
$this->productAttribute->unassignFromAttributeSet(
'size',
12
);Mass update given products without changing the attribute definition itself:
$productIds = [1, 2, 3];
$this->productAttribute->massUpdate($productIds, [
'brand_badge' => 'Featured',
]);