@@ -34,19 +34,27 @@ class UpdateUrlKeyForProducts implements DataPatchInterface, PatchVersionInterfa
34
34
*/
35
35
private $ urlProduct ;
36
36
37
+ /**
38
+ * @var \Magento\Framework\EntityManager\MetadataPool
39
+ */
40
+ private $ metadataPool ;
41
+
37
42
/**
38
43
* @param ModuleDataSetupInterface $moduleDataSetup
39
44
* @param EavSetupFactory $eavSetupFactory
40
45
* @param Url $urlProduct
46
+ * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
41
47
*/
42
48
public function __construct (
43
49
ModuleDataSetupInterface $ moduleDataSetup ,
44
50
EavSetupFactory $ eavSetupFactory ,
45
- Url $ urlProduct
51
+ Url $ urlProduct ,
52
+ \Magento \Framework \EntityManager \MetadataPool $ metadataPool
46
53
) {
47
54
$ this ->moduleDataSetup = $ moduleDataSetup ;
48
55
$ this ->eavSetup = $ eavSetupFactory ->create (['setup ' => $ moduleDataSetup ]);
49
56
$ this ->urlProduct = $ urlProduct ;
57
+ $ this ->metadataPool = $ metadataPool ;
50
58
}
51
59
52
60
/**
@@ -58,7 +66,7 @@ public function apply()
58
66
$ table = $ this ->moduleDataSetup ->getTable ('catalog_product_entity_varchar ' );
59
67
$ select = $ this ->moduleDataSetup ->getConnection ()->select ()->from (
60
68
$ table ,
61
- ['value_id ' , 'value ' ]
69
+ [$ this -> getProductLinkField (), ' attribute_id ' , ' store_id ' , 'value_id ' , 'value ' ]
62
70
)->where (
63
71
'attribute_id = ? ' ,
64
72
$ this ->eavSetup ->getAttributeId ($ productTypeId , 'url_key ' )
@@ -99,4 +107,17 @@ public function getAliases()
99
107
{
100
108
return [];
101
109
}
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
+ }
102
123
}
0 commit comments