我收到以下错误:
a:5:{i:0;s:2328:"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sales_flat_order.web4pro_abandonedcart_flag' in 'where clause', query was: SELECT COUNT(*) FROM (SELECT `main_table`.*, `sales_flat_order`.`web4pro_abandonedcart_flag`, GROUP_CONCAT(order_item_tbl.`name` SEPARATOR '\n') AS `product_names`, GROUP_CONCAT(order_item_tbl.`sku` SEPARATOR '\n') AS `skus`, GROUP_CONCAT(order_item_tbl.`product_id` SEPARATOR '\n') AS `product_ids`, GROUP_CONCAT(order_item_tbl.`product_options` SEPARATOR '^') AS `product_options`, `order_address_billing_tbl`.`company` AS `billing_company`, `order_address_billing_tbl`.`street` AS `billing_street`, `order_address_billing_tbl`.`city` AS `billing_city`, `order_address_billing_tbl`.`region` AS `billing_region`, `order_address_billing_tbl`.`country_id` AS `billing_country_id`, `order_address_billing_tbl`.`postcode` AS `billing_postcode`, `order_address_billing_tbl`.`telephone` AS `billing_telephone`, `order_address_shipping_tbl`.`company` AS `shipping_company`, `order_address_shipping_tbl`.`street` AS `shipping_street`, `order_address_shipping_tbl`.`city` AS `shipping_city`, `order_address_shipping_tbl`.`region` AS `shipping_region`, `order_address_shipping_tbl`.`country_id` AS `shipping_country_id`, `order_address_shipping_tbl`.`postcode` AS `shipping_postcode`, `order_address_shipping_tbl`.`telephone` AS `shipping_telephone`, `order_payment_tbl`.`method` FROM `sales_flat_order_grid` AS `main_table`
INNER JOIN `sales_flat_order` ON main_table.increment_id = sales_flat_order.increment_id
LEFT JOIN `sales_flat_order_item` AS `order_item_tbl` ON `order_item_tbl`.`order_id` = `main_table`.`entity_id` AND `order_item_tbl`.`parent_item_id` IS NULL
LEFT JOIN `sales_flat_order_address` AS `order_address_billing_tbl` ON order_address_billing_tbl.parent_id = main_table.entity_id AND order_address_billing_tbl.`address_type` = "billing"
LEFT JOIN `sales_flat_order_address` AS `order_address_shipping_tbl` ON order_address_shipping_tbl.parent_id = main_table.entity_id AND order_address_shipping_tbl.`address_type` = "shipping"
LEFT JOIN `sales_flat_order_payment` AS `order_payment_tbl` ON order_payment_tbl.parent_id = main_table.entity_id GROUP BY `main_table`.`entity_id`) AS `main_table` WHERE (`sales_flat_order`.`web4pro_abandonedcart_flag` = 1) AND (order_group_id = '0')";i:1;s:5789:"#0 /home/*********/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
如果我说对了,那么web4pro_abandonedcart_flag
表中没有找到sales_flat_order
列吗?
然而,我已经检查过,并且我100%确定该表中有这样的列。
以下是造成此故障的功能:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('sales/order_grid_collection');
$this->setCollection($collection);
$sales_flat_order_table = Mage::getSingleton('core/resource')->getTableName('sales_flat_order');
$collection->getSelect()->join($sales_flat_order_table , 'main_table.increment_id = '.$sales_flat_order_table.'.increment_id', 'web4pro_abandonedcart_flag');
$collection->addFieldToFilter($sales_flat_order_table.'.web4pro_abandonedcart_flag',array('eq' => 1));
return parent::_prepareCollection();
}
请问可以解决问题所在?
答案 0 :(得分:1)
是的,给定的字段可能存在于给定的表中,但是sales_flat_order
表未在外部查询的from
子句中引用,但在where
中您正在引用此表中的字段的标准。
您的查询简化如下:
SELECT COUNT(*)
FROM (...) AS `main_table`
WHERE (`sales_flat_order`.`web4pro_abandonedcart_flag` = 1) AND (order_group_id = '0')
在外部查询中,从字段名称中删除sales_flat_order
,或将其替换为main_table
。但最好的解决方案是完全摆脱子查询。