Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Commit

Permalink
Fix for transactions grid collection not being reloaded properly
Browse files Browse the repository at this point in the history
The extension relies on the fact that a new collection object is created
during the second call to _prepareCollection(). This doesn't happen with
the transactions grid, because it always first looks to see if there is
a collection already set. It does this because there is a subclass which
also creates a collection, and utilises this class to do most of the
work.

We don't need this for the main transactions grid, so we unset the
collection before calling _prepareCollection() for the 2nd time. This
makes everything work a lot more nicely.
  • Loading branch information
Matthew Gamble committed Aug 3, 2015
1 parent 024e39c commit 6a9d8e1
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/code/community/BL/CustomGrid/Model/Grid/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ protected function _exportTo($format, $config = null)
$typeModel->beforeGridExport($format, null);
/** @var $layout Mage_Core_Model_Layout */
$layout = Mage::getSingleton('core/layout');
/** @var $gridBlock Mage_Adminhtml_Block_Widget_Grid */
$gridBlock = $layout->createBlock($gridModel->getBlockType());

if (is_array($config)) {
$gridBlock->blcg_setExportConfig($config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
abstract class BL_CustomGrid_Model_Grid_Rewriter_Abstract extends BL_CustomGrid_Object
{
const REWRITE_CODE_VERSION = 3; // bump this value when significant changes are made to the rewriting code

/**
* Return the fixed base of the rewriting class names used by the extension
*
Expand Down Expand Up @@ -108,7 +108,14 @@ protected function _getRewriteCode($blcgClassName, $originalClassName, $blockTyp
{
return 'class ' . $blcgClassName . ' extends ' . $originalClassName . '
{
/**
* @var BL_CustomGrid_Model_Grid
*/
private $_blcg_gridModel = null;
/**
* @var BL_CustomGrid_Model_Grid_Type_Abstract
*/
private $_blcg_typeModel = null;
private $_blcg_filterParam = null;
private $_blcg_exportConfig = null;
Expand Down Expand Up @@ -160,6 +167,12 @@ public function setCollection($collection)
return $return;
}
public function blcg_unsetCollection()
{
$this->_collection = null;
return $this;
}
public function getCollection()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category BL
* @package BL_CustomGrid
* @copyright Copyright (c) 2014 Benoît Leulliette <[email protected]>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class BL_CustomGrid_Model_Grid_Type_Sales_Transactions extends BL_CustomGrid_Model_Grid_Type_Abstract
{
/**
* @return string[]|string
*/
protected function _getSupportedBlockTypes()
{
return array('adminhtml/sales_transactions_grid');
}

/**
* Do some actions before grid collection is prepared
*
* @param Mage_Adminhtml_Block_Widget_Grid $gridBlock Grid block
* @param bool $firstTime Whether this is the first (= incomplete) grid collection preparation
* @return BL_CustomGrid_Model_Grid_Type_Sales_Transactions
*/
public function beforeGridPrepareCollection(Mage_Adminhtml_Block_Widget_Grid $gridBlock, $firstTime = true)
{
if (!$firstTime) {
$gridBlock->blcg_addCollectionCallback(
'before_prepare',
array($this, 'removeFirstTimeCollection'),
array(),
true
);
}
return $this;
}

/**
* When calling _prepareCollection(), this grid by default looks to see if one is already set, rather
* than just overriding any existing collection. This is unique in Magento, and causes all sorts of
* problems because the collection has already been loaded.
*
* @param Mage_Adminhtml_Block_Widget_Grid $gridBlock
* @param Varien_Data_Collection_Db $collection
* @param bool $firstTime
*/
public function removeFirstTimeCollection(
Mage_Adminhtml_Block_Widget_Grid $gridBlock,
Varien_Data_Collection_Db $collection,
$firstTime
) {
if (!$firstTime) {
$gridBlock->blcg_unsetCollection();
}
}
}
9 changes: 7 additions & 2 deletions app/code/community/BL/CustomGrid/etc/customgrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,12 @@
<name>Credit Memos</name>
<sort_order>230000</sort_order>
</sales_creditmemo>


<sales_transactions model="customgrid/grid_type_sales_transactions" module="customgrid">
<name>Transactions</name>
<sort_order>240000</sort_order>
</sales_transactions>

<other model="customgrid/grid_type_other" module="customgrid">
<name>Other</name>
<sort_order>1000000000</sort_order>
Expand Down Expand Up @@ -1787,4 +1792,4 @@
</text>
</attribute>
</column_renderers>
</customgrid>
</customgrid>

0 comments on commit 6a9d8e1

Please sign in to comment.