WHage子句中的未知列,使用Magento Collection中的addExpressionFieldToSelect

时间:2014-06-05 01:12:34

标签: sql magento

我有一个magento网格。我正在以这种方式准备这个系列:

protected function _prepareCollection()
{
    $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');

    // Get collection products in listing
    //--------------------------------
    $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
    $collection->addExpressionFieldToSelect(
            'hello',
            'sum({{prod_id}})',
            array('prod_id' => '`main_table`.`product_id`')
        );

    $collection->getSelect()->distinct();
    $collection->getSelect()->where("`main_table`.`listing_id` = ?",(int)$listingData['id']);
    //--------------------------------

结果选择是:

SELECT DISTINCT `main_table`.*, `second_table`.*, sum(`main_table`.`product_id`) AS     `hello`, `cpe`.`sku` AS `magento_sku`, `cisi`.`is_in_stock`, `cpev`.`value` FROM `sm_m2epro_listing_product` AS `main_table` INNER JOIN `sm_m2epro_amazon_listing_product` AS `second_table` ON `second_table`.`listing_product_id` = `main_table`.`id` INNER JOIN `sm_catalog_product_entity` AS `cpe` ON (cpe.entity_id = `main_table`.product_id) INNER JOIN `sm_cataloginventory_stock_item` AS `cisi` ON (cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1) INNER JOIN `sm_catalog_product_entity_varchar` AS `cpev` ON ( `cpev`.`entity_id` = `main_table`.product_id ) INNER JOIN `sm_eav_attribute` AS `ea` ON (`cpev`.`attribute_id` = `ea`.`attribute_id` AND `ea`.`attribute_code` = 'name') WHERE (`main_table`.`component_mode` = 'amazon') AND (`main_table`.`listing_id` = 3) AND (cpev.store_id = (SELECT MAX(`store_id`) FROM `sm_catalog_product_entity_varchar` WHERE (`entity_id` = `main_table`.`product_id`) AND (`attribute_id` = `ea`.`attribute_id`) AND (`store_id` = 0 OR `store_id` = 7)))

但程序失败了:

        $this->addColumn('ASIN_duplicate', array(
        'header' => Mage::helper('M2ePro')->__('Duplicated'),
        'width' => '20px',
        'index' =>  'hello',

    ));

在WHERE子句中使用“未知列'hello'”。 无法弄清楚问题出在哪里。

0 个答案:

没有答案