我有这个查询,它不是我写的,我不擅长PHP和Magento。我有这个客户在一些产品中有几个图像,比方说,一个产品有14个图像,但其中一半被排除在外,他们不想显示它们。所以我的查询返回每个产品的所有图片。您可以看到以下代码:
$_mediaGalleryData = $_read->fetchAll('SELECT
main.entity_id, `main`.`value_id`, `main`.`value` AS `file`,
`value`.`label`, `value`.`position`, `value`.`disabled`, `default_value`.`label` AS `label_default`,
`default_value`.`position` AS `position_default`,
`default_value`.`disabled` AS `disabled_default`
FROM `catalog_product_entity_media_gallery` AS `main`
LEFT JOIN `catalog_product_entity_media_gallery_value` AS `value`
ON main.value_id=value.value_id AND value.store_id=' . $store_id . '
LEFT JOIN `catalog_product_entity_media_gallery_value` AS `default_value`
ON main.value_id=default_value.value_id AND default_value.store_id=0
WHERE (
AND main.attribute_id = ' . $_read->quote($_mediaGalleryAttributeId) . ')
AND (main.entity_id IN (' . $_read->quote($collection->getAllIds()) . '))
ORDER BY IF(value.position IS NULL, default_value.position, value.position) ASC
');
我添加了value.disabled = 0,如下所示:
WHERE (
value.disabled = 0
AND main.attribute_id = ' . $_read->quote($_mediaGalleryAttributeId) . ')
AND (main.entity_id IN (' . $_read->quote($collection->getAllIds()) . '))
但它也没有用。关于我该如何解决的任何想法?
编辑:所以我将代码更改为以下但仍然得到相同的结果;
$_mediaGalleryData = $_read->fetchAll('SELECT
main.entity_id, `main`.`value_id`, `main`.`value` AS `file`,
`value`.`label`, `value`.`position`, `value`.`disabled`, `value`.`label` AS `label_default`,
`value`.`position` AS `position_default`,
`value`.`disabled` AS `disabled_default`
FROM `catalog_product_entity_media_gallery` AS `main`
INNER JOIN `catalog_product_entity_media_gallery_value` AS `value`
ON main.value_id=value.value_id AND value.store_id=' . $store_id . '
WHERE (
value.disabled = 0
AND main.attribute_id = ' . $_read->quote($_mediaGalleryAttributeId) . ')
AND (main.entity_id IN (' . $_read->quote($collection->getAllIds()) . '))
ORDER BY IF(value.position IS NULL, value.position, value.position) ASC
');