etailer / Etailer_Backorders

A Magento extension to allow negative values in a product's 'Qty for Item's Status to Become Out of Stock'
MIT License
5 stars 6 forks source link

"Ambigious select statement" error resulting from join #7

Open gebrial opened 8 years ago

gebrial commented 8 years ago

In the admin panel, when opening the page at reports->products->"low stock", we get an error page. The report says (among other things):

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'qty' in where clause is ambiguous

A quick fix for this is to go to the class Etailer_Backorders_Model_Observer_Adminhtml and comment out the lines in the function joinFieldsToCollection. I've seen other solutions to this problem where they define a 'filter_index' when joining, but I'm not sure how to implement that here.

rjocoleman commented 8 years ago

@gebrial I'm happy to take a PR for this, but I don't use this report myself so I won't get to it soon due to other pressing commitments.

gebrial commented 8 years ago

@rjocoleman no problem. I'll try to find a better solution but I thought it was important to make a note of this in case others came across the same problem.

captainyoung commented 8 years ago

Problem is in /app/code/core/Mage/Reports/Model/Resource/Product/Lowstock/Collection.php Line 239 $this->getSelect()->where('qty < ?', $notifyStockExpr);

Should be: $where = $this->_inventoryItemTableAlias . '.qty < ?'; $this->getSelect()->where($where, $notifyStockExpr);

So you have to extend Mage_Reports_Model_Resource_Product_Lowstock_Collection and override: public function useNotifyStockQtyFilter

I will put in a pull request.