Amasty Resolution Center

Assistance with Creating a Data Patch for Product Label Adjustments

Dear Amasty Support and Community,

I need help creating a data patch for my Magento store to:

  1. Set the margin between product labels to 8px.

  2. Position all product labels at the top left.

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.

Could you guide me on how to achieve this via a data patch?

Thank you for your help!

Best regards,


I tried the following data patch, but it didn't update the admin panel values
```php
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 [];
    }
}
```