public function testRemoveAllItems() { $model = new Varien_Data_Collection(); $model->addItem(new Varien_Object()); $model->addItem(new Varien_Object()); $this->assertCount(2, $model->getItems()); $model->removeAllItems(); $this->assertEmpty($model->getItems()); }
protected function _prepareColumns() { try { $collection = $this->_createCollection(); $collection->setPageSize(1); $collection->load(); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($this->__('An error occured rendering the grid: ' . $e->getMessage())); Mage::logException($e); $collection = new Varien_Data_Collection(); } $config = $this->_getReport()->getGridConfig(); $filterable = $config->getFilterable(); $items = $collection->getItems(); if (count($items)) { $item = reset($items); foreach ($item->getData() as $key => $val) { $isFilterable = false; if (isset($filterable[$key])) { $isFilterable = $filterable[$key]; } elseif (in_array($key, $filterable)) { $isFilterable = 'adminhtml/widget_grid_column_filter_text'; } $this->addColumn($key, array('header' => Mage::helper('core')->__($key), 'index' => $key, 'filter' => $isFilterable, 'sortable' => true)); } } return parent::_prepareColumns(); }
/** * Get the skus of all potential configurable products that a simple product * within the collection of products to be cleaned may need to be linked to. * @param Varien_Data_Collection $productCollection * @return array */ protected function _getAllParentConfigurableSkus(Varien_Data_Collection $productCollection) { $helper = $this->_helper; $catalogId = $this->_config->catalogId; return array_map(function ($product) use($helper, $catalogId) { return $helper->normalizeSku($product->getStyleId(), $catalogId); }, array_filter($productCollection->getItems(), array($this, '_filterProductWithConfigParent'))); }