@@ -34,19 +34,27 @@ class UpdateUrlKeyForProducts implements DataPatchInterface, PatchVersionInterfa
3434 */
3535 private $ urlProduct ;
3636
37+ /**
38+ * @var \Magento\Framework\EntityManager\MetadataPool
39+ */
40+ private $ metadataPool ;
41+
3742 /**
3843 * @param ModuleDataSetupInterface $moduleDataSetup
3944 * @param EavSetupFactory $eavSetupFactory
4045 * @param Url $urlProduct
46+ * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
4147 */
4248 public function __construct (
4349 ModuleDataSetupInterface $ moduleDataSetup ,
4450 EavSetupFactory $ eavSetupFactory ,
45- Url $ urlProduct
51+ Url $ urlProduct ,
52+ \Magento \Framework \EntityManager \MetadataPool $ metadataPool
4653 ) {
4754 $ this ->moduleDataSetup = $ moduleDataSetup ;
4855 $ this ->eavSetup = $ eavSetupFactory ->create (['setup ' => $ moduleDataSetup ]);
4956 $ this ->urlProduct = $ urlProduct ;
57+ $ this ->metadataPool = $ metadataPool ;
5058 }
5159
5260 /**
@@ -58,7 +66,7 @@ public function apply()
5866 $ table = $ this ->moduleDataSetup ->getTable ('catalog_product_entity_varchar ' );
5967 $ select = $ this ->moduleDataSetup ->getConnection ()->select ()->from (
6068 $ table ,
61- ['value_id ' , 'value ' ]
69+ [$ this -> getProductLinkField (), ' attribute_id ' , ' store_id ' , 'value_id ' , 'value ' ]
6270 )->where (
6371 'attribute_id = ? ' ,
6472 $ this ->eavSetup ->getAttributeId ($ productTypeId , 'url_key ' )
@@ -99,4 +107,17 @@ public function getAliases()
99107 {
100108 return [];
101109 }
110+
111+ /**
112+ * Return product id field name - entity_id|row_id
113+ *
114+ * @return string
115+ * @throws \Exception
116+ */
117+ private function getProductLinkField ()
118+ {
119+ return $ this ->metadataPool
120+ ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class)
121+ ->getLinkField ();
122+ }
102123}
0 commit comments