Guest User

Untitled

a guest
Feb 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. -----------------------
  2. GET PRODUCT INFO
  3. -----------------------
  4.  
  5. SET @productId = 206;
  6. SELECT e.entity_id AS 'id',
  7. v1.value AS 'name',
  8. e.sku,
  9. d1.value AS 'price',
  10. v2.value AS 'image',
  11. v3.value AS 'thumbnail',
  12. mg.value AS 'media_gallery',
  13. cids.category_ids AS 'category_ids',
  14. cids.category_names AS 'category_names'
  15. FROM catalog_product_entity e
  16. LEFT JOIN catalog_product_entity_varchar v1 ON e.entity_id = v1.entity_id
  17. AND v1.store_id = 0
  18. AND v1.attribute_id =
  19. (SELECT attribute_id
  20. FROM eav_attribute
  21. WHERE attribute_code = 'name'
  22. AND entity_type_id =
  23. (SELECT entity_type_id
  24. FROM eav_entity_type
  25. WHERE entity_type_code = 'catalog_product'))
  26. LEFT JOIN catalog_product_entity_text t1 ON e.entity_id = t1.entity_id
  27. AND t1.store_id = 0
  28. AND t1.attribute_id =
  29. (SELECT attribute_id
  30. FROM eav_attribute
  31. WHERE attribute_code = 'short_description'
  32. AND entity_type_id =
  33. (SELECT entity_type_id
  34. FROM eav_entity_type
  35. WHERE entity_type_code = 'catalog_product'))
  36. LEFT JOIN catalog_product_entity_text t2 ON e.entity_id = t2.entity_id
  37. AND t2.store_id = 0
  38. AND t2.attribute_id =
  39. (SELECT attribute_id
  40. FROM eav_attribute
  41. WHERE attribute_code = 'description'
  42. AND entity_type_id =
  43. (SELECT entity_type_id
  44. FROM eav_entity_type
  45. WHERE entity_type_code = 'catalog_product'))
  46. LEFT JOIN catalog_product_entity_varchar v2 ON e.entity_id = v2.entity_id
  47. AND v2.store_id = 0
  48. AND v2.attribute_id =
  49. (SELECT attribute_id
  50. FROM eav_attribute
  51. WHERE attribute_code = 'image'
  52. AND entity_type_id =
  53. (SELECT entity_type_id
  54. FROM eav_entity_type
  55. WHERE entity_type_code = 'catalog_product'))
  56. LEFT JOIN catalog_product_entity_varchar v3 ON e.entity_id = v3.entity_id
  57. AND v3.store_id = 0
  58. AND v3.attribute_id =
  59. (SELECT attribute_id
  60. FROM eav_attribute
  61. WHERE attribute_code = 'thumbnail'
  62. AND entity_type_id =
  63. (SELECT entity_type_id
  64. FROM eav_entity_type
  65. WHERE entity_type_code = 'catalog_product'))
  66. LEFT JOIN catalog_product_entity_decimal d1 ON e.entity_id = d1.entity_id
  67. AND d1.store_id = 0
  68. AND d1.attribute_id =
  69. (SELECT attribute_id
  70. FROM eav_attribute
  71. WHERE attribute_code = 'price'
  72. AND entity_type_id =
  73. (SELECT entity_type_id
  74. FROM eav_entity_type
  75. WHERE entity_type_code = 'catalog_product'))
  76. LEFT JOIN
  77. (SELECT m1.entity_id,
  78. GROUP_CONCAT(m2.value) AS value
  79. FROM catalog_product_entity_media_gallery_value_to_entity m1
  80. INNER JOIN catalog_product_entity_media_gallery m2 ON m2.value_id = m1.value_id
  81. AND m2.attribute_id =
  82. (SELECT attribute_id
  83. FROM eav_attribute
  84. WHERE attribute_code = 'media_gallery'
  85. AND entity_type_id =
  86. (SELECT entity_type_id
  87. FROM eav_entity_type
  88. WHERE entity_type_code = 'catalog_product'))
  89. GROUP BY m1.entity_id) mg ON e.entity_id = mg.entity_id
  90. LEFT JOIN
  91. (SELECT product_id,
  92. GROUP_CONCAT(c.category_id SEPARATOR ',') AS category_ids,
  93. GROUP_CONCAT(cv.value SEPARATOR ',') AS category_names
  94. FROM catalog_category_product c
  95. INNER JOIN catalog_category_entity_varchar cv ON c.category_id = cv.entity_id
  96. AND cv.store_id = 0
  97. AND cv.attribute_id =
  98. (SELECT attribute_id
  99. FROM eav_attribute
  100. WHERE attribute_code = 'name'
  101. AND entity_type_id =
  102. (SELECT entity_type_id
  103. FROM eav_entity_type
  104. WHERE entity_type_code = 'catalog_category'))
  105. GROUP BY product_id) cids ON e.entity_id = cids.product_id
  106. WHERE e.entity_id = @productId\G
  107.  
  108.  
  109. -----------------------
  110. RESULTS
  111. -----------------------
  112.  
  113. *************************** 1. row ***************************
  114. id: 206
  115. name: Branderoo Testeroo 1
  116. sku: Branderoo Testeroo 1
  117. price: 19.9900
  118. image: /3/7/375248_3.jpg
  119. thumbnail: /3/7/375248_3.jpg
  120. media_gallery: /3/7/375248_3.jpg,/s/c/screen_shot_2017-12-17_at_7.04.04_pm_1.png,/s/c/screen_shot_2017-12-17_at_9.04.55_pm_1.png,/2/9/29_86.png,/2/9/29_b_83.png,/2/9/29_c_83.png,/2/9/29_87.png,/2/9/29_b_84.png,/2/9/29_c_84.png,/k/j/kjaicon-128.png
  121. category_ids: NULL
  122. category_names: NULL
Add Comment
Please, Sign In to add comment