Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. SELECT e.entity_id, e.sku, eav.value AS 'description'
  2. FROM catalog_product_entity e
  3. JOIN catalog_product_entity_text eav
  4. ON e.entity_id = eav.entity_id
  5. JOIN eav_attribute ea
  6. ON eav.attribute_id = ea.attribute_id
  7. WHERE ea.attribute_code = 'description'
  8.  
  9. SELECT
  10. `e`.`sku`,
  11. IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`,
  12. IF(at_description.value_id > 0, at_description.value, at_description_default.value) AS `description`
  13.  
  14. FROM
  15. `catalog_product_entity` AS `e`
  16. INNER JOIN
  17. `catalog_product_entity_varchar` AS `at_name_default`
  18. ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND
  19. (`at_name_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
  20. `at_name_default`.`store_id` = 0
  21. LEFT JOIN
  22. `catalog_product_entity_varchar` AS `at_name`
  23. ON (`at_name`.`entity_id` = `e`.`entity_id`) AND
  24. (`at_name`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND
  25. (`at_name`.`store_id` = 1)
  26. INNER JOIN
  27. `catalog_product_entity_text` AS `at_description_default`
  28. ON (`at_description_default`.`entity_id` = `e`.`entity_id`) AND
  29. (`at_description_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
  30. `at_description_default`.`store_id` = 0
  31. LEFT JOIN
  32. `catalog_product_entity_text` AS `at_description`
  33. ON (`at_description`.`entity_id` = `e`.`entity_id`) AND
  34. (`at_description`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND
  35. (`at_description`.`store_id` = 1)
  36.  
  37. (`at_name`.`store_id` = 1)
  38.  
  39. (`at_description`.`store_id` = 1)
  40.  
  41. $collection = Mage::getResourceModel('catalog/product_collection')
  42. ->addAttributeToSelect(array('sku', 'name', 'description'));
  43. foreach ($collection as $item) {
  44. $sku = $item->getSku();
  45. $name = $item->getName();
  46. $description = $item->getDescription();
  47. //do something with $sku, $name & $description
  48. }
  49.  
  50. SELECT
  51. catalog_product_entity_varchar.entity_id,
  52. catalog_product_entity_varchar.`value` AS product_name,
  53. catalog_product_entity.sku
  54. FROM
  55. catalog_product_entity_varchar
  56. INNER JOIN catalog_product_entity ON catalog_product_entity_varchar.entity_id = catalog_product_entity.entity_id
  57. WHERE
  58. catalog_product_entity_varchar.entity_type_id = (
  59. SELECT
  60. entity_type_id
  61. FROM
  62. eav_entity_type
  63. WHERE
  64. entity_type_code = 'catalog_product'
  65. )
  66. AND attribute_id = (
  67. SELECT
  68. attribute_id
  69. FROM
  70. eav_attribute
  71. WHERE
  72. attribute_code = 'name'
  73. AND entity_type_id = (
  74. SELECT
  75. entity_type_id
  76. FROM
  77. eav_entity_type
  78. WHERE
  79. entity_type_code = 'catalog_product'
  80. )
  81. )
  82.  
  83. $sql = "SELECT `value`
  84. FROM catalog_product_entity_varchar
  85. WHERE entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product')
  86. AND attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product'))";
  87.  
  88. $results = $readConnection->fetchAll($sql);
  89.  
  90. SET @etype = (SELECT
  91. entity_type_id
  92. FROM
  93. eav_entity_type
  94. WHERE
  95. entity_type_code = 'catalog_product');
  96.  
  97. SET @name = (SELECT
  98. attribute_id
  99. FROM
  100. eav_attribute
  101. WHERE
  102. attribute_code = 'name'
  103. AND entity_type_id = @etype);
  104.  
  105. SET @image = (SELECT
  106. attribute_id
  107. FROM
  108. eav_attribute
  109. WHERE
  110. attribute_code = 'image'
  111. AND entity_type_id = @etype);
  112.  
  113. SET @smallimage = (SELECT
  114. attribute_id
  115. FROM
  116. eav_attribute
  117. WHERE
  118. attribute_code = 'small_image'
  119. AND entity_type_id = @etype);
  120.  
  121. SET @price = (SELECT
  122. attribute_id
  123. FROM
  124. eav_attribute
  125. WHERE
  126. attribute_code = 'price'
  127. AND entity_type_id = @etype);
  128.  
  129. SET @description = (SELECT
  130. attribute_id
  131. FROM
  132. eav_attribute
  133. WHERE
  134. attribute_code = 'description'
  135. AND entity_type_id = @etype);
  136.  
  137. SELECT
  138. e.entity_id AS 'id',
  139. e.sku,
  140. v1.value AS 'name',
  141. v2.value AS 'image',
  142. s2.value AS 'small_image',
  143. si.qty AS 'stock qty',
  144. d1.value AS 'price',
  145. s1.value AS 'description'
  146. FROM
  147. catalog_product_entity e
  148. LEFT JOIN
  149. cataloginventory_stock_item si ON e.entity_id = si.product_id
  150. LEFT JOIN
  151. catalog_product_entity_varchar v1 ON e.entity_id = v1.entity_id
  152. AND v1.store_id IN (0,1,2)
  153. AND v1.attribute_id = @name
  154. LEFT JOIN
  155. catalog_product_entity_varchar v2 ON e.entity_id = v2.entity_id
  156. AND v2.store_id IN (0,1,2)
  157. AND v2.attribute_id = @image
  158. LEFT JOIN
  159. catalog_product_entity_varchar s2 ON e.`entity_id` = s2.entity_id
  160. AND s2.store_id IN (0,1,2)
  161. AND s2.`attribute_id` = @smallimage
  162. LEFT JOIN
  163. catalog_product_entity_decimal d1 ON e.entity_id = d1.entity_id
  164. AND d1.store_id IN (0,1,2)
  165. AND d1.attribute_id = @price
  166. LEFT JOIN
  167. catalog_product_entity_text s1 ON e.entity_id = s1.entity_id
  168. AND s1.store_id IN (0,1,2)
  169. AND s1.attribute_id = @description ;
  170.  
  171. select
  172. sku.entity_id, sku.sku, #get sku and entity
  173. productName.value, #get name
  174. description.value #get description
  175. from
  176. catalog_product_entity as sku,
  177. catalog_product_entity_varchar as productName,
  178. catalog_product_entity_text as description
  179. where
  180. productName.attribute_id = 73
  181. and
  182. sku.entity_id = productName.entity_id
  183. and
  184. description.attribute_id = 75
  185. and
  186. sku.entity_id = description.entity_id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement