Question

I have CMS block in magento admin and it included the following code:

<div id="featured-products" class="tab">{{block type="featuredproducts/listing" template="featured/featuredproducts/list_home.phtml"}}</div>
<div id="newproducts" class="tab">{{block type="newproducts/newproductslist" template="newproducts/list_home.phtml"}}</div>
<div id="bestseller" class="tab">{{block type="bestseller/bestsellerlist" template="bestseller/list_home.phtml"}}</div>

and i am trying to getting this block on a template as follows:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product-tabs-image')->toHtml(); ?>

but its showing error instead of showing the actual contents as follows:

There has been an error processing your request

SELECT SUM(order_items.qty_ordered) AS `ordered_qty`, `order_items`.`name` AS `order_items_name`, `order_items`.`product_id` AS `entity_id`, `e`.`entity_type_id`, `e`.`attribute_set_id`, `e`.`type_id`, `e`.`sku`, `e`.`has_options`, `e`.`required_options`, `e`.`created_at`, `e`.`updated_at`, `e`.`name`, `e`.`price`, `e`.`thumbnail`, `e`.`short_description`, `e`.`small_image`, `e`.`url_key`, `cat_index`.`position` AS `cat_index_position` FROM `sales_flat_order_item` AS `order_items`
INNER JOIN `sales_flat_order` AS `order` ON `order`.entity_id = order_items.order_id AND `order`.state <> 'canceled'
LEFT JOIN `catalog_product_entity` AS `e` ON (e.type_id NOT IN ('grouped', 'configurable', 'bundle')) AND e.entity_id = order_items.product_id AND e.entity_type_id = 4
INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='1' AND cat_index.visibility IN(2, 4) AND cat_index.category_id = '2' WHERE (parent_item_id IS NULL) GROUP BY `order_items`.`product_id` HAVING (SUM(order_items.qty_ordered) > 0) ORDER BY `ordered_qty` desc



 Trace:
  #0 /var/www/html/magento/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
  #1 /var/www/html/magento/app/code/core/Zend/Db/Statement.php(291):       Varien_Db_Statement_Pdo_Mysql->_execute(Array)
  #2 /var/www/html/magento/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
  #3 /var/www/html/magento/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT SUM(orde...', Array)
 #4 /var/www/html/magento/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('SELECT SUM(orde...', Array)
 #5 /var/www/html/magento/lib/Zend/Db/Adapter/Abstract.php(737): Varien_Db_Adapter_Pdo_Mysql->query('SELECT SUM(orde...', Array)
 #6 /var/www/html/magento/lib/Varien/Data/Collection/Db.php(734): Zend_Db_Adapter_Abstract->fetchAll('SELECT SUM(orde...', Array)
 #7 /var/www/html/magento/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.ph p(1047): Varien_Data_Collection_Db->_fetchAll('SELECT SUM(orde...')
 #8 /var/www/html/magento/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(871): Mage_Eav_Model_Entity_Collection_Abstract->_loadEntities(false, false)
 #9 /var/www/html/magento/lib/Varien/Data/Collection.php(741): Mage_Eav_Model_Entity_Collection_Abstract->load()
 #10 /var/www/html/magento/app/code/local/Megnor/Bestseller/Block/Bestsellerlist.php(37): Varien_Data_Collection->getIterator()
 #11 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(293): Megnor_Bestseller_Block_Bestsellerlist->_prepareLayout()
 #12 /var/www/html/magento/app/code/core/Mage/Core/Model/Layout.php(456): Mage_Core_Block_Abstract->setLayout(Object(Mage_Core_Model_Layout))
 #13 /var/www/html/magento/app/code/core/Mage/Core/Model/Email/Template/Filter.php(164): Mage_Core_Model_Layout->createBlock('bestseller/best...', NULL, Array)
 #14 [internal function]: Mage_Core_Model_Email_Template_Filter->blockDirective(Array)
#15 /var/www/html/magento/lib/Varien/Filter/Template.php(134): call_user_func(Array, Array)
#16 /var/www/html/magento/app/code/core/Mage/Core/Model/Email/Template/Filter.php(504): Varien_Filter_Template->filter('<div class="bot...')
#17 /var/www/html/magento/app/code/core/Mage/Cms/Block/Block.php(54): Mage_Core_Model_Email_Template_Filter->filter('<div class="bot...')
#18 /var/www/html/magento/app/code/local/Mirasvit/SeoAutolink/Block/Cms/Block.php(36): Mage_Cms_Block_Block->_toHtml()
#19 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(919): Mirasvit_SeoAutolink_Block_Cms_Block->_toHtml()
#20 /var/www/html/magento/app/design/frontend/default/MAG090199/template/catalog/product/view.phtml(252): Mage_Core_Block_Abstract->toHtml()
#21 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(241): include('/var/www/html/m...')
#22 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/defaul...')
#23 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#24 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Template->_toHtml()
#25 /var/www/html/magento/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml()
#26 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Text_List->_toHtml()
#27 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(637): Mage_Core_Block_Abstract->toHtml()
#28 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(581): Mage_Core_Block_Abstract->_getChildHtml('content', true)
#29 /var/www/html/magento/app/design/frontend/default/MAG090199/template/page/1column.phtml(54): Mage_Core_Block_Abstract->getChildHtml('content')
#30 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(241): include('/var/www/html/m...')
#31 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/defaul...')
#32 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#33 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Template->_toHtml()
#34 /var/www/html/magento/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#35 /var/www/html/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()
#36 /var/www/html/magento/app/code/core/Mage/Catalog/Helper/Product/View.php(147): Mage_Core_Controller_Varien_Action->renderLayout()
#37 /var/www/html/magento/app/code/core/Mage/Catalog/controllers/ProductController.php(132): Mage_Catalog_Helper_Product_View->prepareAndRender(484, Object(Mage_Catalog_ProductController), Object(Varien_Object))
#38 /var/www/html/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Catalog_ProductController->viewAction()
#39 /var/www/html/magento/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('view')
#40 /var/www/html/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#41 /var/www/html/magento/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#42 /var/www/html/magento/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#43 /var/www/html/magento/index.php(87): Mage::run('', 'store')
#44 {main}

Error log record number: 1280154555476

Was it helpful?

Solution

After trying to execute the given SQL query in phpmyadmin for a default Magento database, I got the following error:

#1054 - Unknown column 'e.name' in 'field list'

What this means is that the column name does not exist in the table e which is an alias for the table catalog_product_entity.

After taking another look at the SQl query, I can see that you are trying to get columns that aren't in that table. The columns `e`.`name`, `e`.`price`, `e`.`thumbnail`, `e`.`short_description`, `e`.`small_image`, `e`.`url_key` are not present in the catalog_product_entity table.

So, after the removing those columns, the final SQL should look like:

SELECT SUM(order_items.qty_ordered) AS `ordered_qty`, `order_items`.`name` AS `order_items_name`, `order_items`.`product_id` AS `entity_id`, `e`.`entity_type_id`, `e`.`attribute_set_id`, `e`.`type_id`, `e`.`sku`, `e`.`has_options`, `e`.`required_options`, `e`.`created_at`, `e`.`updated_at`, `cat_index`.`position` AS `cat_index_position` FROM `sales_flat_order_item` AS `order_items`
INNER JOIN `sales_flat_order` AS `order` ON `order`.entity_id = order_items.order_id AND `order`.state <> 'canceled'
LEFT JOIN `catalog_product_entity` AS `e` ON (e.type_id NOT IN ('grouped', 'configurable', 'bundle')) AND e.entity_id = order_items.product_id AND e.entity_type_id = 4
INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='1' AND cat_index.visibility IN(2, 4) AND cat_index.category_id = '2' WHERE (parent_item_id IS NULL) GROUP BY `order_items`.`product_id` HAVING (SUM(order_items.qty_ordered) > 0) ORDER BY `ordered_qty` desc

Edit

Doing this may not be possible if you are using product collections. So, please post the code for the _prepareLayout function (specially the one which is using the product collection)

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top