Skip to main content

Posts

Showing posts from June, 2023

"Asymmetric transaction rollback" in DataPatch

I was working on one of the needs in which I needed to add some new data to the catalog_eav_attribute table. And for that, I've created an update query that will be executed from DataPatch, and the query will be executed to update data in the database when the code is deployed to the server. So I have added below code: public function apply() { $this->moduleDataSetup->getConnection()->startSetup(); $connection = $this->resourceConnection->getConnection(); try { if ($connection->tableColumnExists('catalog_eav_attribute', 'used_in_feed') === true) { foreach ($this->attributes as $attribute) { $query = "UPDATE catalog_eav_attribute SET used_in_feed = 1 WHERE attribute_id = (SELECT attribute_id FROM eav_attribute WHERE entity_type_id = 4 AND attribute_code = '" . $attribute . "')"; $connection->query($query); ...

How to add new field in attribute form in Magento 2?

Magento provide a feature to manage product attributes from the admin. There we can manage how to use that attributes in frontend and backend. And sometimes based on demand, we need additional information for an individual attribute. For example, include an attribute in the product feed. So let's see how we can add a new field to capture the additional value for each attribute. Please follow the below steps: STEP 1: Create a plugin <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Front"> <plugin name="extension_attribute_edit_form" sortorder="1" type="MageInsight\ProductFeed\Plugin\Block\Adminhtml\Product\Attribute\Edit\Tab\Front"> </plugin></type> </config> STEP 2: Next, we will create the “Front” class ...