奇妙な「1103誤ったテーブル名」エラー
-
16-10-2019 - |
質問
コード:
public function testAction(){
$Collection = Mage::getModel('catalog/product')->getCollection();
$Collection->getSelect()->join(array('t2' => 'SELECT product_id FROM sales_flat_quote_item GROUP BY product_id ORDER BY SUM(qty) DESC;'), 'e.entity_id = t2.product_id', 't2.product_id');
foreach($Collection as $c){
var_dump($c);
}
}
これが次のとおりです エラートレース.
誤ったテーブル名 sales_flat_quote_item
?
ここでの問題は何ですか?私はクエリ全体を手動で作成し、それで完了したいと思っています.. :)
ありがとう。
解決
グループ化の部分については知りませんが、このような販売アイテムコレクションで製品コレクションに参加できます。
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->joinTable(
array('t2'=>'sales/quote_item'),
'product_id = entity_id',
array('product_id')
);
これを続けることができると思います。
編集] - 質問とは無関係ですが、問題に対する可能な解決策
このようなベストセラーを入手できます。
$collection = Mage::getResourceModel('sales/report_bestsellers_collection')
->setModel('catalog/product')
->addStoreFilter(Mage::app()->getStore()->getId())//if you want the bestsellers for a specific store view. if you want global values remove this
->setPageSize(5)//set here the number of products you want returned - skip this and the next line if you want all the products but this may lead to performance issues.
->setCurPage(1);
2度目の編集
コレクションを印刷した場合、ケースで選択 $collection->getSelect()
あなたはこのようなものを見るでしょう:
SELECT
1 AS `status`,
`e`.`entity_id`,
`e`.`type_id`,
`e`.`attribute_set_id`,
`t2`.`product_id`
FROM
`catalog_product_flat_1` AS `e`
INNER JOIN
`(SELECT product_id FROM sales_flat_quote_item GROUP BY product_id ORDER BY SUM(qty) DESC)` AS `t2`
ON e.entity_id = t2.product_id
後の引用マーク( `)に注意してください INNER JOIN
. 。そこにはテーブル名があるはずです。代わりに、完全な選択があります。これは構文的に正しいものではありません...したがって、エラー。
所属していません magento.stackexchange