I attempted to implement this, but it didn't work as expected.
P.S. I have already made these changes via the admin configuration, but we need to implement them in code to ensure they apply across different instances.
declare(strict_types=1);
namespace Scandiweb\AmastyConfig\Setup\Patch\Data;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class UpdateProductLabelConfig implements DataPatchInterface
{
/**
* @var WriterInterface
*/
protected $configWriter;
/**
* Constructor
*
* @param WriterInterface $configWriter
*/
public function __construct(
WriterInterface $configWriter
) {
$this->configWriter = $configWriter;
}
/**
* Apply the patch to update Amasty product label config values
*
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function apply(): void
{
// Set label position to Top Left
$this->configWriter->save(
'amasty_labels/general/position', // Config path for label position
'top_left', // Value
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0 // Scope ID (0 means global)
);
// Set label margin to 8px
$this->configWriter->save(
'amasty_labels/general/label_margin', // Config path for label margin
'8', // Value in px
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0 // Scope ID (0 means global)
);
}
/**
* Get patch dependencies
*
* @return array
*/
public static function getDependencies(): array
{
return [];
}
/**
* Get patch aliases
*
* @return array
*/
public function getAliases(): array
{
return [];
}
}