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

Export fixes #182

Open
wants to merge 3 commits into
base: 1.0.0-wip
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 25 additions & 3 deletions app/code/community/BL/CustomGrid/Model/Grid/Rewriter/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

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
const REWRITE_CODE_VERSION = 4; // 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 Expand Up @@ -259,9 +272,18 @@ public function _exportIterateCollection($callback, array $args)
$break = false;
$first = false;
$count = null;


if ($originalCollection instanceof Varien_Data_Collection_Db) {
$selectProperty = new ReflectionProperty(get_class($originalCollection), "_select");
$selectProperty->setAccessible(true);
$originalSelect = $originalCollection->getSelect();
}
while ($break !== true) {
$collection = clone $originalCollection;
if ($originalCollection instanceof Varien_Data_Collection_Db) {
$select = clone $originalSelect;
$selectProperty->setValue($collection, $select);
}
$collection->setPageSize($pageSize);
$collection->setCurPage($page);

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();
}
}
}
7 changes: 6 additions & 1 deletion app/code/community/BL/CustomGrid/etc/customgrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,12 @@
</store_code>
</custom_columns>
</system_store>


<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