Magento 2 |从mysql查询获取产品型号信息

时间:2020-01-01 22:11:21

标签: mysql join magento2

我正在magento商店工作,该商店已经包括市场扩展。主要目标是为andriod和ios应用程序创建移动api。 可能是我不太擅长在Google上进行搜索,但找不到与我的特定问题相关的任何内容,其他相关搜索也都无法帮助我。

这是我的SQL查询:

`   SELECT e.entity_id AS 'id',
    v1.value AS 'name',
    e.sku,
    d1.value AS 'price',
    distributors.vendor_id as distributor_id,
    d11.value as distributor_name,
    t1.value AS 'short_description',
    t2.value AS 'description',
    v2.value AS 'image',
    v3.value AS 'thumbnail',
    mg.value AS 'media_gallery',
    cids.category_ids AS 'category_ids',
    cids.category_names AS 'category_names',
    cp1.sm_featured as featured,
    e.type_id,
    cp1.special_price as special_price,
    distributors.qty as qty

    FROM catalog_product_entity e
    INNER JOIN `catalog_product_flat_1` AS `cp1` ON e.entity_id=cp1.entity_id
    LEFT JOIN `ced_csmarketplace_vendor_products` AS `distributors` ON 
    e.entity_id=distributors.product_id
    LEFT JOIN `ced_csmarketplace_vendor_varchar` AS `d11` ON (distributors.vendor_id=d11.entity_id) AND 
    (d11.attribute_id=156)
    LEFT JOIN catalog_product_entity_varchar v1 ON e.entity_id = v1.entity_id
    AND v1.store_id = 0
    AND v1.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'))
    LEFT JOIN catalog_product_entity_text t1 ON e.entity_id = t1.entity_id
    AND t1.store_id = 0
    AND t1.attribute_id =
    (SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code = 'short_description'
    AND entity_type_id =
    (SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'))
    LEFT JOIN catalog_product_entity_text t2 ON e.entity_id = t2.entity_id
    AND t2.store_id = 0
    AND t2.attribute_id =
    (SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code = 'description'
    AND entity_type_id =
    (SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'))
    LEFT JOIN catalog_product_entity_varchar v2 ON e.entity_id = v2.entity_id
    AND v2.store_id = 0
    AND v2.attribute_id =
    (SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code = 'image'
    AND entity_type_id =
    (SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'))
    LEFT JOIN catalog_product_entity_varchar v3 ON e.entity_id = v3.entity_id
    AND v3.store_id = 0
    AND v3.attribute_id =
    (SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code = 'thumbnail'
    AND entity_type_id =
    (SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'))
    LEFT JOIN catalog_product_entity_decimal d1 ON e.entity_id = d1.entity_id
    AND d1.store_id = 0
    AND d1.attribute_id =
    (SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code = 'price'
    AND entity_type_id =
    (SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'))
    LEFT JOIN
    (SELECT m1.entity_id,
    GROUP_CONCAT(m2.value) AS value
    FROM catalog_product_entity_media_gallery_value_to_entity m1
    INNER JOIN catalog_product_entity_media_gallery m2 ON m2.value_id = m1.value_id
    AND m2.attribute_id =
    (SELECT attribute_id
    FROM eav_attribute
    WHERE attribute_code = 'media_gallery'
    AND entity_type_id =
    (SELECT entity_type_id
    FROM eav_entity_type
    WHERE entity_type_code = 'catalog_product'))
    GROUP BY m1.entity_id) mg ON e.entity_id = mg.entity_id
    LEFT JOIN
    (SELECT product_id,
    GROUP_CONCAT(c.category_id SEPARATOR ',') AS category_ids,
    GROUP_CONCAT(cv.value SEPARATOR ',') AS category_names
    FROM catalog_category_product c
    INNER JOIN catalog_category_entity_varchar cv ON c.category_id = cv.entity_id
    AND cv.store_id = 0
    AND cv.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_category'))
    GROUP BY product_id) cids ON e.entity_id = cids.product_id WHERE cp1.sm_featured = 1 AND 
    e.entity_id=1;`

在此查询中,我也想要产品变体。我要告诉你。 product variants

我要添加产品配置,单价,小计,数量

有人可以帮我吗?

0 个答案:

没有答案