안녕하세요, 저는 몇 가지 SQL 쿼리를 실행하기 위해 PHP 문을 작성하는 방법을 알고 싶습니다.magento 최소한의 가격으로 가장 많이 본 제품을 나열하는 방법
예를 들어 : (목록 최소한의 가격으로 모든 제품)
$collection1 = Mage::getModel('catalog/product')->getCollection();
$collection1
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addAttributeToFilter('attribute_set_id', 4)
->setOrder('created_at', 'desc')
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents();
SQL 쿼리는이 방법 :
SELECT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`,
IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`,
`price_index`.`tier_price` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_product_index_price` AS
`price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND
price_index.customer_group_id = 0 WHERE (`e`.`attribute_set_id` = '4') ORDER BY `e`.`created_at` desc
하지만 난 다음 PHP 문이 가장 많이 본 제품을 나열 할 수 있습니다 알고 :
$collection2 = Mage::getResourceModel('reports/product_collection');
$collection2->addViewsCount();
그러면 SQL 쿼리는 다음과 같습니다.
SELECT COUNT(report_table_views.event_id) AS `views`, `e`.* FROM `report_event` AS `report_table_views`
INNER JOIN `catalog_product_entity` AS `e` ON e.entity_id = report_table_views.object_id AND e.entity_type_id = 4
WHERE (report_table_views.event_type_id = 1) GROUP BY `e`.`entity_id` HAVING
(COUNT(report_table_views.event_id) > 0) ORDER BY `views` DESC
나는 위의 두 SQL 쿼리를 결합하는 PHP 구문을 작성하는 방법을 생각하고 있는데, 나는 다음 SQL 쿼리의 결과를 보여주고 싶다.
SELECT COUNT(report_table_views.event_id) AS `views`, `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`,
`price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price,
price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`,
`price_index`.`max_price`, `price_index`.`tier_price` FROM `report_event` AS `report_table_views` INNER JOIN
`catalog_product_entity` AS `e` ON e.entity_id = report_table_views.object_id AND e.entity_type_id = 4 INNER JOIN
`catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id =
'1' AND price_index.customer_group_id = 0 WHERE (report_table_views.event_type_id = 1 AND `e`.`attribute_set_id` =
'4') GROUP BY `e`.`entity_id` HAVING (COUNT(report_table_views.event_id) > 0) ORDER BY `views` DESC
나는 내가 다음과 같은 PHP 문을 쓸 수 있다고 생각하지만, (가) 전체 SQL 문을 무시 어쩌면, addViewsCount을 작동하지 않습니다. 내가 세트 ID가 모든 제품 엔티티 4해야합니다 속성 트러블 요구 사항이 이제
$collection3 = Mage::getResourceModel('reports/product_collection');
$collection3
->addAttributeToSelect('*')
->addAttributeToFilter('attribute_set_id', 4)
->addOrderedQty()
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addViewsCount();
, 최소한의 가격으로 가장 많이 본 제품을 나열하는 PHP 문을 작성하는 방법을 알 수있는 사람, 그리고 용서해주십시오. 나는 구글에서 그러한 정보를 검색 할 생각이 없으므로이 질문이 매우 어려운 일이라는 것을 알고있다. 모두가 문제를 살펴 보도록하십시오. 모든 노력에 감사드립니다.
이 PHP 구문이 효과가 있다고 생각합니다. \t $ storeId = Mage :: app() -> getStore() -> getId(); \t $ collection3 = Mage :: getResourceModel ('reports/product_collection') -> setStoreId ($ storeId); \t $ collection3-> addViewsCount(); \t $ collection3-> addAttributeToFilter ('attribute_set_id', 4); \t $ collection3-> addAttributeToSelect ('*'); \t $ collection3-> addStoreFilter ($ storeId); \t $ collection3-> addMinimalPrice(); \t $ collection3-> addFinalPrice(); \t $ collection3-> addTaxPercents(); – Jun