コード例 #1
0
 /**
  * @covers Mage_ImportExport_Model_Resource_CollectionByPagesIterator::iterate
  */
 public function testIterate()
 {
     $pageSize = 2;
     $pageCount = 3;
     /** @var $callbackMock PHPUnit_Framework_MockObject_MockObject */
     $callbackMock = $this->getMock('stdClass', array('callback'));
     /** @var $collectionMock Varien_Data_Collection_Db|PHPUnit_Framework_MockObject_MockObject */
     $collectionMock = $this->getMock('Varien_Data_Collection_Db', array('clear', 'setPageSize', 'setCurPage', 'count', 'getLastPageNumber'), array(), '', false, false);
     $adapter = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', array(), '', false, true, true, array('fetchAll'));
     $collectionMock->setConnection($adapter);
     $collectionMock->expects($this->exactly($pageCount + 1))->method('clear')->will($this->returnSelf());
     $collectionMock->expects($this->exactly($pageCount))->method('setPageSize')->will($this->returnSelf());
     $collectionMock->expects($this->exactly($pageCount))->method('setCurPage')->will($this->returnSelf());
     $collectionMock->expects($this->exactly($pageCount))->method('count')->will($this->returnValue($pageSize));
     $collectionMock->expects($this->exactly($pageCount))->method('getLastPageNumber')->will($this->returnValue($pageCount));
     for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
         for ($rowNumber = 1; $rowNumber <= $pageSize; $rowNumber++) {
             $itemId = ($pageNumber - 1) * $pageSize + $rowNumber;
             $item = new Varien_Object(array('id' => $itemId));
             $collectionMock->addItem($item);
             $callbackMock->expects($this->at($itemId - 1))->method('callback')->with($item);
         }
     }
     $this->_resourceModel->iterate($collectionMock, $pageSize, array(array($callbackMock, 'callback')));
 }
コード例 #2
0
 /**
  * Load needed data from customer collection
  */
 public function load()
 {
     if ($this->_isCollectionLoaded == false) {
         $collection = clone $this->_customerCollection;
         $collection->removeAttributeToSelect();
         $tableName = $collection->getResource()->getEntityTable();
         $collection->getSelect()->from($tableName, array('entity_id', 'website_id', 'email'));
         $this->_byPagesIterator->iterate($this->_customerCollection, $this->_pageSize, array(array($this, 'addCustomer')));
         $this->_isCollectionLoaded = true;
     }
 }
コード例 #3
0
ファイル: EntityAbstract.php プロジェクト: nemphys/magento2
 /**
  * Iterate through given collection page by page and export items
  *
  * @param Varien_Data_Collection_Db $collection
  */
 protected function _exportCollectionByPages(Varien_Data_Collection_Db $collection)
 {
     $this->_byPagesIterator->iterate($collection, $this->_pageSize, array(array($this, 'exportItem')));
 }
コード例 #4
0
ファイル: Option.php プロジェクト: nemphys/magento2
 /**
  * Load exiting custom options data
  *
  * @return Mage_ImportExport_Model_Import_Entity_Product_Option
  */
 protected function _initOldCustomOptions()
 {
     if (!$this->_oldCustomOptions) {
         $oldCustomOptions = array();
         $optionTitleTable = $this->_tables['catalog_product_option_title'];
         $productIds = array_values($this->_productsSkuToId);
         foreach ($this->_storeCodeToId as $storeId) {
             $addCustomOptions = function (Mage_Catalog_Model_Product_Option $customOption) use(&$oldCustomOptions, $storeId) {
                 $productId = $customOption->getProductId();
                 if (!isset($oldCustomOptions[$productId])) {
                     $oldCustomOptions[$productId] = array();
                 }
                 if (isset($oldCustomOptions[$productId][$customOption->getId()])) {
                     $oldCustomOptions[$productId][$customOption->getId()]['titles'][$storeId] = $customOption->getTitle();
                 } else {
                     $oldCustomOptions[$productId][$customOption->getId()] = array('titles' => array($storeId => $customOption->getTitle()), 'type' => $customOption->getType());
                 }
             };
             /** @var $collection Mage_Catalog_Model_Resource_Product_Option_Collection */
             $this->_optionCollection->reset();
             $this->_optionCollection->addProductToFilter($productIds);
             $this->_optionCollection->getSelect()->join(array('option_title' => $optionTitleTable), 'option_title.option_id = main_table.option_id', array('title' => 'title', 'store_id' => 'store_id'))->where('option_title.store_id = ?', $storeId);
             $this->_byPagesIterator->iterate($this->_optionCollection, $this->_pageSize, array($addCustomOptions));
         }
         $this->_oldCustomOptions = $oldCustomOptions;
     }
     return $this;
 }