Magento 2: How to Update Stores Configuration Settings Programmatically

Introduction A few moments earlier I posted two articles: Magento 2: How to Change Category Attribute Value Programmatically Magento 2: How to Update Product Attribute Settings Programmatically where described why we should use Data Patch to update something in the admin panel. In this article I will show the method of how to update 'Stores > Configuration' settings in the Magento 2. Solution <?php declare(strict_types=1); namespace Vendor\ModuleName\Setup\Patch\Data; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\App\Config\Storage\WriterInterface; class UpdateLayeredNavigationSettings implements DataPatchInterface { /** @var ModuleDataSetupInterface */ private ModuleDataSetupInterface $moduleDataSetup; /** * @var WriterInterface */ private WriterInterface $configWriter; /** * Constructor * * @param ModuleDataSetupInterface $moduleDataSetup * @apram WriterInterface $configWriter */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, WriterInterface $configWriter ) { $this->moduleDataSetup = $moduleDataSetup; $this->configWriter = $configWriter; } /** * {@inheritdoc} */ public function apply() { $this->moduleDataSetup->startSetup(); $this->configWriter->save('catalog/layered_navigation/display_category', '0'); $this->configWriter->save('catalog/layered_navigation/display_product_count', '0'); $this->moduleDataSetup->endSetup(); } /** * {@inheritdoc} */ public static function getDependencies() { return []; } /** * {@inheritdoc} */ public function getAliases() { return []; } } Explanation If read my previous articles you remember that we used something like EavSetup model for the product attribute and Category Repository for the category attribute....

May 13, 2023 · 2 min

Magento 2: How to Update Product Attribute Settings Programmatically

Introduction Imagine similar situation as I described in the previous article Magento 2: How to Change Category Attribute Value Programmatically But now we need to change product attribute setting. And, as in previuos example, we can do it via admin panel. Buuut… would be better… Solution To use Data Patch. <?php declare(strict_types=1); namespace Vendor\ModuleName\Setup\Patch\Data; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Catalog\Model\Product; class UpdateColorAttribute implements DataPatchInterface { /** @var ModuleDataSetupInterface */ private ModuleDataSetupInterface $moduleDataSetup; /** * @var EavSetupFactory */ private EavSetupFactory $eavSetupFactory; /** * Constructor * * @param ModuleDataSetupInterface $moduleDataSetup * @param EavSetupFactory $eavSetupFactory */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, EavSetupFactory $eavSetupFactory ) { $this->moduleDataSetup = $moduleDataSetup; $this->eavSetupFactory = $eavSetupFactory; } /** * {@inheritdoc} */ public function apply() { /** @var EavSetup $eavSetup */ $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $eavSetup->updateAttribute(Product::ENTITY, 'color', ['used_in_product_listing' => 1]); } /** * {@inheritdoc} */ public static function getDependencies() { return []; } /** * {@inheritdoc} */ public function getAliases() { return []; } } Explanation We use updateAttribute method of the EavSetup model to update color product attribute....

May 13, 2023 · 2 min

Magento 2: How to Change Category Attribute Value Programmatically

Introduction Imagine we are working on the client’s project. It serves on staging and production servers, of course. But we are working locally. And we need to change a category attribute value. It’s easy! Just navigate to the admin panel and select the necessary value. But this is a bad practice. Because now we should remember about this attribute and after ticket will be deployed to staging we should change attribute value here also....

May 13, 2023 · 2 min

Magento 2: How to Show All Layout Xml for Certain Page

Introduction Imagine you should fix something in Magento 2 on the product listing page, for example. You added an data (like new block with arguments, for example) to the catalog_category_view.xml layout but your changes doesn’t respond on front-end. Solution To check if your data exists in the catalog_category_view.xml layout you should print all layout on the product listing page. Navigate to the following class and method: \Magento\Framework\View\Layout\Builder::generateLayoutXml After this line $this->layout->generateXml(); add the following...

April 30, 2023 · 1 min

Upload Code to ESP32-Cam via Arduino Uno (or Pro, or etc...)

Introduction In this post we will program ESP32-Cam using Arduino Uno. But you can use Arduino Pro or Mega, or another one version of course. We will upload the default sketch from the official espressif/arduino-esp32 github page to the ESP32-Cam. Everything in this post is done on Ubuntu 22.04.1 LTS. Wiring Diagram Red - Arduino:5V -> ESP32-Cam:5V Black - Arduino:GND -> ESP32-Cam:GND Green - Arduino:TX -> ESP32-Cam:UOT Yellow - Arduino:RX -> ESP32-Cam:UOR Purple - ESP32-Cam:GPIO0 -> ESP32-Cam:GND This wire is used to set the ESP32-Cam to the FLASH Mode....

February 21, 2023 · 5 min