0

I am upgrading a site from 1.6 community to 1.7. A custom module that was working is now breaking with the error:

    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'fulfilled' in 'where clause'";i:1;s:5421:"#0 lib/Varien/Db/Statement/Pdo/Mysql.php

app/code/local/FP/Giftcard/Block/Adminhtml/Rewrite/Sales/Order/Grid.php(102): Varien_Data_Collection_Db->load()

The queries that are running:

SELECT `main_table`.* FROM `magento_sales_order_status` AS `main_table`

SELECT COUNT(*) FROM `magento_sales_flat_order_grid` AS `main_table` WHERE 

(`fulfilled` = '1') GROUP BY `main_table`.`entity_id`

The correct queries which are running before the upgrade:

SELECT COUNT(*) FROM (SELECT `main_table`.*, MIN(if(magento_sales_flat_order_giftcardproduct.type = 'PHYSICAL', ifnull(fulfilled,0), 0)) AS `fulfilled` FROM `magento_sales_flat_order_grid` AS `main_table`
 LEFT JOIN `magento_sales_flat_order_giftcardproduct` ON magento_sales_flat_order_giftcardproduct.order_id = main_table.entity_id AND magento_sales_flat_order_giftcardproduct.type = 'PHYSICAL' WHERE (`fulfilled` = '1') GROUP BY `main_table`.`entity_id`) AS `a`

SELECT `main_table`.*, MIN(if(magento_sales_flat_order_giftcardproduct.type = 'PHYSICAL', ifnull(fulfilled,0), 0)) AS `fulfilled` FROM `magento_sales_flat_order_grid` AS `main_table`
 LEFT JOIN `magento_sales_flat_order_giftcardproduct` ON magento_sales_flat_order_giftcardproduct.order_id = main_table.entity_id AND magento_sales_flat_order_giftcardproduct.type = 'PHYSICAL' WHERE (`fulfilled` = '1') GROUP BY `main_table`.`entity_id` ORDER BY created_at DESC LIMIT 20

The sales order grid rewrite code:

Class FP_Giftcard_Block_Adminhtml_Rewrite_Sales_Order_Grid
//    extends Mage_Adminhtml_Block_Sales_Order_Grid
    extends Mage_Adminhtml_Block_Sales_Order_Grid
{
    /**
     * Prepare the order grid columns by adding the totals including the giftcard amount
     */
    protected function _prepareColumns()
    {
        parent::_prepareColumns();

        /**
         * @todo
         * Waiting on client specs
         */
        #$this->_addGiftcardColumns();
        $this->_addGiftcardproductColumns();

        $this->sortColumnsByOrder();
        return $this;
    } 

    protected function _addGiftcardColumns()
    {

        $_baseTotal = & $this->getColumn("base_grand_total");
        $_baseTotal["index"] = "base_grand_total_incl_gc";

        $_total = & $this->getColumn("grand_total");
        $_total["index"] = "grand_total_incl_gc";         
    }

    protected function _addGiftcardproductColumns()
    {
        $this->addColumnAfter('giftcard_status', array(
            'header' => Mage::helper('sales')->__('Giftcard Fulfillment Status'),
            'index' => 'fulfilled',
            'type'  => 'options',
            'width' => '100px',
            'options' => Mage::helper("fp_giftcard/adminhtml")->getCollectionStatusMap()
        ), 'status');        
    }

    /**
     * Prepare grid collection object
     *
     * @return this
     */
    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $this->setCollection($collection);        
        if ($this->getCollection()) {

            $this->_preparePage();

            $columnId = $this->getParam($this->getVarNameSort(), $this->_defaultSort);
            $dir      = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
            $filter   = $this->getParam($this->getVarNameFilter(), null);

            if (is_null($filter)) {
                $filter = $this->_defaultFilter;
            }
            $_pseudo_filter = false;

            if (is_string($filter)) {

                // this line is broken
                $data = $this->helper('adminhtml')->prepareFilterString($filter);

                if (isset($data['giftcard_status']) && $data['giftcard_status'] == 0)
                {
                    $alias = $this->getCollection()->getTable("fp_giftcard/sales_giftcardproduct");
                    $this->getCollection()->getSelect()->where("{$alias}.type IS NULL OR {$alias}.type = '" . FP_Giftcard_Helper_Product::GCTYPE_VIRTUAL."'");


                    foreach($data as $k=>$v)
                    {
                        $_pseudo_filter[$k] = $v;
                    }

                    unset($data['giftcard_status']);
                }
                $this->_setFilterValues($data);

            }
            else if ($filter && is_array($filter)) {
                $this->_setFilterValues($filter);
            }
            else if(0 !== sizeof($this->_defaultFilter)) {
                $this->_setFilterValues($this->_defaultFilter);
            }

            if (isset($this->_columns[$columnId]) && $this->_columns[$columnId]->getIndex()) {
                $dir = (strtolower($dir)=='desc') ? 'desc' : 'asc';
                $this->_columns[$columnId]->setDir($dir);
                $this->_setCollectionOrder($this->_columns[$columnId]);
            }

            if (!$this->_isExport) {
                $this->getCollection()->load();
                $this->_afterLoadCollection();
            }
            if ($_pseudo_filter)
            {
                $this->_setFilterValues($_pseudo_filter);
            }
        }

        return $this;
    }
} 

Wondering if anyone can help me track down what the issue might be and how to fix it?

2
  • Might be a stupid question, but did you try to run the installers again? With n98-magerun it would be n98-magerun sys:setup:run. Maybe that helps you out. Oct 19, 2016 at 18:51
  • Thanks for the suggestion. That didn't fix it. Oct 20, 2016 at 18:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.