Exemplo n.º 1
0
 /**
  * Adds the required text test data for text.
  *
  * @param array $testdata Associative list of key/list pairs
  * @throws MW_Setup_Exception If no type ID is found
  */
 private function _addTextData(array $testdata)
 {
     $textManager = MShop_Text_Manager_Factory::createManager($this->_additional, 'Default');
     $textTypeManager = $textManager->getSubManager('type', 'Default');
     $ttypeIds = array();
     $ttype = $textTypeManager->createItem();
     $this->_conn->begin();
     foreach ($testdata['text/type'] as $key => $dataset) {
         $ttype->setId(null);
         $ttype->setCode($dataset['code']);
         $ttype->setDomain($dataset['domain']);
         $ttype->setLabel($dataset['label']);
         $ttype->setStatus($dataset['status']);
         $textTypeManager->saveItem($ttype);
         $ttypeIds[$key] = $ttype->getId();
     }
     $text = $textManager->createItem();
     foreach ($testdata['text'] as $key => $dataset) {
         if (!isset($ttypeIds[$dataset['typeid']])) {
             throw new MW_Setup_Exception(sprintf('No text type ID found for "%1$s"', $dataset['typeid']));
         }
         $text->setId(null);
         $text->setLanguageId($dataset['langid']);
         $text->setTypeId($ttypeIds[$dataset['typeid']]);
         $text->setDomain($dataset['domain']);
         $text->setLabel($dataset['label']);
         $text->setContent($dataset['content']);
         $text->setStatus($dataset['status']);
         $textManager->saveItem($text, false);
     }
     $this->_conn->commit();
 }
Exemplo n.º 2
0
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('MShop_Exception');
     $target = 'MShop_Common_Manager_Interface';
     $manager = MShop_Text_Manager_Factory::createManager(TestHelper::getContext(), 'test');
     $this->assertInstanceOf($target, $manager);
 }
Exemplo n.º 3
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_editor = TestHelper::getContext()->getEditor();
     $manager = MShop_Text_Manager_Factory::createManager(TestHelper::getContext());
     $listManager = $manager->getSubManager('list');
     $this->_object = $listManager->getSubManager('type');
 }
Exemplo n.º 4
0
 /**
  * Initializes the text list type controller.
  *
  * @param MShop_Context_Item_Interface $context MShop context object
  */
 public function __construct(MShop_Context_Item_Interface $context)
 {
     parent::__construct($context, 'Text_List_Type');
     $manager = MShop_Text_Manager_Factory::createManager($context);
     $listManager = $manager->getSubManager('list');
     $this->_manager = $listManager->getSubManager('type');
 }
 /**
  * Insert catalog nodes and product/catalog relations.
  */
 protected function _process()
 {
     $this->_msg('Adding catalog text performance data', 0);
     $context = $this->_getContext();
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($context);
     $catalogListManager = $catalogManager->getSubManager('list');
     $catalogListTypeManager = $catalogListManager->getSubManager('type');
     $search = $catalogListTypeManager->createSearch();
     $expr = array($search->compare('==', 'catalog.list.type.domain', 'text'), $search->compare('==', 'catalog.list.type.code', 'default'));
     $search->setConditions($search->combine('&&', $expr));
     $types = $catalogListTypeManager->searchItems($search);
     if (($typeItem = reset($types)) === false) {
         throw new Exception('Catalog list type item not found');
     }
     $textManager = MShop_Text_Manager_Factory::createManager($context);
     $textTypeManager = $textManager->getSubManager('type');
     $search = $textTypeManager->createSearch();
     $expr = array($search->compare('==', 'text.type.domain', 'catalog'), $search->compare('==', 'text.type.code', 'name'));
     $search->setConditions($search->combine('&&', $expr));
     $types = $textTypeManager->searchItems($search);
     if (($textTypeItem = reset($types)) === false) {
         throw new Exception('Text type item not found');
     }
     $textItem = $textManager->createItem();
     $textItem->setTypeId($textTypeItem->getId());
     $textItem->setLanguageId('en');
     $textItem->setDomain('catalog');
     $textItem->setStatus(1);
     $listItem = $catalogListManager->createItem();
     $listItem->setTypeId($typeItem->getId());
     $listItem->setDomain('text');
     $this->_txBegin();
     $start = $pos = 0;
     $search = $catalogManager->createSearch();
     $search->setSortations(array($search->sort('+', 'catalog.id')));
     do {
         $result = $catalogManager->searchItems($search);
         foreach ($result as $id => $item) {
             $textItem->setId(null);
             $textItem->setLabel($item->getLabel());
             $textItem->setContent(str_replace('-', ' ', $item->getLabel()));
             $textManager->saveItem($textItem);
             $listItem->setId(null);
             $listItem->setParentId($id);
             $listItem->setRefId($textItem->getId());
             $listItem->setPosition($pos++);
             $catalogListManager->saveItem($listItem, false);
         }
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count == $search->getSliceSize());
     $this->_txCommit();
     $this->_status('done');
 }
Exemplo n.º 6
0
 public function testSaveItemLabelContent()
 {
     $context = TestHelper::getContext();
     $methods = array('createItem', 'saveItem');
     $managerStub = $this->getMock('MShop_Text_Manager_Default', $methods, array($context));
     $itemStub = $this->getMock('MShop_Text_Item_Default');
     $managerStub->expects($this->once())->method('createItem')->will($this->returnValue($itemStub));
     $managerStub->expects($this->once())->method('saveItem');
     $itemStub->expects($this->once())->method('getContent')->will($this->returnValue("<br>\ntest<br>\n<br>\ncontent"));
     $itemStub->expects($this->once())->method('setContent')->with($this->equalTo("<br>\ntest<br>\n<br>\ncontent"));
     $itemStub->expects($this->once())->method('setLabel')->with($this->equalTo('test content'));
     MShop_Text_Manager_Factory::injectManager('MShop_Text_Manager_Default', $managerStub);
     $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('text.content' => "<br>\ntest<br>\n<br>\ncontent<br>\n<br>\r\n"));
     $cntl = new Controller_ExtJS_Text_Default($context);
     $cntl->saveItems($saveParams);
     MShop_Text_Manager_Factory::injectManager('MShop_Text_Manager_Default', null);
 }
 /**
  * Gets required text item ids.
  *
  * @param array $keys List of keys for search
  * @throws MW_Setup_Exception If no type ID is found
  */
 private function _getTextData(array $keys)
 {
     $textManager = MShop_Text_Manager_Factory::createManager($this->_additional, 'Default');
     $labels = array();
     foreach ($keys as $dataset) {
         if (($pos = strpos($dataset, '/')) === false || ($str = substr($dataset, $pos + 1)) === false) {
             throw new MW_Setup_Exception(sprintf('Some keys for ref text are set wrong "%1$s"', $dataset));
         }
         $labels[] = $str;
     }
     $search = $textManager->createSearch();
     $search->setConditions($search->compare('==', 'text.label', $labels));
     $refIds = array();
     foreach ($textManager->searchItems($search) as $item) {
         $refIds['text/' . $item->getLabel()] = $item->getId();
     }
     return $refIds;
 }
Exemplo n.º 8
0
 protected function _cleanupText()
 {
     $manager = MShop_Text_Manager_Factory::createManager($this->_context);
     $search = $manager->createSearch();
     $expr = array($search->compare('==', 'text.domain', 'product'), $search->compare('==', 'text.label', 'import-%'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', 'text.id')));
     $start = 0;
     do {
         $result = $manager->searchItems($search);
         $manager->deleteItems(array_keys($result));
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count == $search->getSliceSize());
 }
 /**
  * Adds the text-list test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @param array $refIds Associative list of domains and the keys/IDs of the inserted items
  * @throws MW_Setup_Exception If a required ID is not available
  */
 private function _addTextData(array $testdata, array $refIds)
 {
     $textManager = MShop_Text_Manager_Factory::createManager($this->_additional, 'Default');
     $textListManager = $textManager->getSubManager('list', 'Default');
     $textListTypeManager = $textListManager->getSubmanager('type', 'Default');
     $labels = array();
     foreach ($testdata['text/list'] as $dataset) {
         if (($pos = strpos($dataset['parentid'], '/')) === false || ($str = substr($dataset['parentid'], $pos + 1)) == false) {
             throw new MW_Setup_Exception(sprintf('Some keys for parentid are set wrong "%1$s"', $dataset['parentid']));
         }
         $labels[] = $str;
     }
     $search = $textManager->createSearch();
     $search->setConditions($search->compare('==', 'text.label', $labels));
     $parentIds = array();
     foreach ($textManager->searchItems($search) as $item) {
         $parentIds['text/' . $item->getLabel()] = $item->getId();
     }
     $tListTypeIds = array();
     $tListType = $textListTypeManager->createItem();
     $this->_conn->begin();
     foreach ($testdata['text/list/type'] as $key => $dataset) {
         $tListType->setId(null);
         $tListType->setCode($dataset['code']);
         $tListType->setDomain($dataset['domain']);
         $tListType->setLabel($dataset['label']);
         $tListType->setStatus($dataset['status']);
         $textListTypeManager->saveItem($tListType);
         $tListTypeIds[$key] = $tListType->getId();
     }
     $tList = $textListManager->createItem();
     foreach ($testdata['text/list'] as $dataset) {
         if (!isset($parentIds[$dataset['parentid']])) {
             throw new MW_Setup_Exception(sprintf('No text ID found for "%1$s"', $dataset['parentid']));
         }
         if (!isset($tListTypeIds[$dataset['typeid']])) {
             throw new MW_Setup_Exception(sprintf('No text list type ID found for "%1$s"', $dataset['typeid']));
         }
         if (!isset($refIds[$dataset['domain']][$dataset['refid']])) {
             throw new MW_Setup_Exception(sprintf('No "%1$s" ref ID found for "%2$s"', $dataset['refid'], $dataset['domain']));
         }
         $tList->setId(null);
         $tList->setParentId($parentIds[$dataset['parentid']]);
         $tList->setTypeId($tListTypeIds[$dataset['typeid']]);
         $tList->setRefId($refIds[$dataset['domain']][$dataset['refid']]);
         $tList->setDomain($dataset['domain']);
         $tList->setDateStart($dataset['start']);
         $tList->setDateEnd($dataset['end']);
         $tList->setConfig($dataset['config']);
         $tList->setPosition($dataset['pos']);
         $tList->setStatus($dataset['status']);
         $textListManager->saveItem($tList, false);
     }
     $this->_conn->commit();
 }
Exemplo n.º 10
0
 public function testImportFromXLSFile()
 {
     $this->_object = new Controller_ExtJS_Catalog_Import_Text_Default($this->_context);
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $node = $catalogManager->getTree(null, array(), MW_Tree_Manager_Abstract::LEVEL_ONE);
     $params = new stdClass();
     $params->lang = array('en');
     $params->items = $node->getId();
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $exporter = new Controller_ExtJS_Catalog_Export_Text_Default($this->_context);
     $result = $exporter->exportFile($params);
     $this->assertTrue(array_key_exists('file', $result));
     $filename = substr($result['file'], 9, -14);
     $this->assertTrue(file_exists($filename));
     $filename2 = 'catalog-import.xls';
     $phpExcel = PHPExcel_IOFactory::load($filename);
     if (unlink($filename) !== true) {
         throw new Exception(sprintf('Deleting file "%1$s" failed', $filename));
     }
     $sheet = $phpExcel->getSheet(0);
     $sheet->setCellValueByColumnAndRow(6, 2, 'Root: delivery info');
     $sheet->setCellValueByColumnAndRow(6, 3, 'Root: long');
     $sheet->setCellValueByColumnAndRow(6, 4, 'Root: name');
     $sheet->setCellValueByColumnAndRow(6, 5, 'Root: payment info');
     $sheet->setCellValueByColumnAndRow(6, 6, 'Root: short');
     $objWriter = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel5');
     $objWriter->save($filename2);
     $params = new stdClass();
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $params->items = $filename2;
     $this->_object->importFile($params);
     if (file_exists($filename2) !== false) {
         throw new Exception('Import file was not removed');
     }
     $textManager = MShop_Text_Manager_Factory::createManager($this->_context);
     $criteria = $textManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'text.domain', 'catalog');
     $expr[] = $criteria->compare('==', 'text.languageid', 'en');
     $expr[] = $criteria->compare('==', 'text.status', 1);
     $expr[] = $criteria->compare('~=', 'text.content', 'Root:');
     $criteria->setConditions($criteria->combine('&&', $expr));
     $textItems = $textManager->searchItems($criteria);
     $textIds = array();
     foreach ($textItems as $item) {
         $textManager->deleteItem($item->getId());
         $textIds[] = $item->getId();
     }
     $listManager = $catalogManager->getSubManager('list');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'catalog.list.domain', 'text');
     $expr[] = $criteria->compare('==', 'catalog.list.refid', $textIds);
     $criteria->setConditions($criteria->combine('&&', $expr));
     $listItems = $listManager->searchItems($criteria);
     foreach ($listItems as $item) {
         $listManager->deleteItem($item->getId());
     }
     $this->assertEquals(5, count($textItems));
     $this->assertEquals(5, count($listItems));
     foreach ($textItems as $item) {
         $this->assertEquals('Root:', substr($item->getContent(), 0, 5));
     }
 }
Exemplo n.º 11
0
 public function testImportFromCSVFile()
 {
     $catalogManager = MShop_Catalog_Manager_Factory::createManager($this->_context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'root'));
     $items = $catalogManager->searchItems($search);
     if (($root = reset($items)) === false) {
         throw new Controller_ExtJS_Exception('No item found for catalog code "root"');
     }
     $id = $root->getId();
     $data = array();
     $data[] = '"Language ID","Catalog code","Catalog ID","List type","Text type","Text ID","Text"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: long"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: meta desc"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: meta keywords"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: meta title"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: name"' . "\n";
     $data[] = '"en","Root","' . $id . '","default","name","","Root: short"' . "\n";
     $data[] = ' ';
     $ds = DIRECTORY_SEPARATOR;
     $csv = 'en-catalog-test.csv';
     $filename = PATH_TESTS . $ds . 'tmp' . $ds . 'catalog-import.zip';
     if (file_put_contents(PATH_TESTS . $ds . 'tmp' . $ds . $csv, implode('', $data)) === false) {
         throw new Exception(sprintf('Unable to write test file "%1$s"', $csv));
     }
     $zip = new ZipArchive();
     $zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
     $zip->addFile(PATH_TESTS . $ds . 'tmp' . $ds . $csv, $csv);
     $zip->close();
     if (unlink(PATH_TESTS . $ds . 'tmp' . $ds . $csv) === false) {
         throw new Exception('Unable to remove export file');
     }
     $params = new stdClass();
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $params->items = $filename;
     $this->_object->importFile($params);
     $textManager = MShop_Text_Manager_Factory::createManager($this->_context);
     $criteria = $textManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'text.domain', 'catalog');
     $expr[] = $criteria->compare('==', 'text.languageid', 'en');
     $expr[] = $criteria->compare('==', 'text.status', 1);
     $expr[] = $criteria->compare('~=', 'text.content', 'Root:');
     $criteria->setConditions($criteria->combine('&&', $expr));
     $textItems = $textManager->searchItems($criteria);
     $textIds = array();
     foreach ($textItems as $item) {
         $textManager->deleteItem($item->getId());
         $textIds[] = $item->getId();
     }
     $listManager = $catalogManager->getSubManager('list');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'catalog.list.domain', 'text');
     $expr[] = $criteria->compare('==', 'catalog.list.refid', $textIds);
     $criteria->setConditions($criteria->combine('&&', $expr));
     $listItems = $listManager->searchItems($criteria);
     foreach ($listItems as $item) {
         $listManager->deleteItem($item->getId());
     }
     foreach ($textItems as $item) {
         $this->assertEquals('Root:', substr($item->getContent(), 0, 5));
     }
     $this->assertEquals(6, count($textItems));
     $this->assertEquals(6, count($listItems));
     if (file_exists($filename) !== false) {
         throw new Exception('Import file was not removed');
     }
 }
Exemplo n.º 12
0
 protected function _delete(MShop_Product_Item_Interface $product)
 {
     $textManager = MShop_Text_Manager_Factory::createManager($this->_context);
     $manager = MShop_Product_Manager_Factory::createManager($this->_context);
     $listManager = $manager->getSubManager('list');
     foreach ($product->getListItems('text') as $listItem) {
         $textManager->deleteItem($listItem->getRefItem()->getId());
         $listManager->deleteItem($listItem->getId());
     }
     $manager->deleteItem($product->getId());
 }
Exemplo n.º 13
0
 public function testImportFromCSVFile()
 {
     $data = array();
     $data[] = '"Language ID","Type","Code","List type","Text type","Text ID","Text"' . "\n";
     $data[] = '"en","color","white","default","name","","unittest: white"' . "\n";
     $data[] = '"en","color","blue","default","name","","unittest: blue"' . "\n";
     $data[] = '"en","color","red","default","name","","unittest: red"' . "\n";
     $data[] = '"en","size","l","default","name","","unittest: l"' . "\n";
     $data[] = '"en","size","xl","default","name","","unittest: xl"' . "\n";
     $data[] = '"en","size","xxl","default","name","","unittest: xxl"' . "\n";
     $data[] = ' ';
     $ds = DIRECTORY_SEPARATOR;
     $csv = 'en-attribute-test.csv';
     $filename = PATH_TESTS . $ds . 'tmp' . $ds . 'attribute-import.zip';
     if (file_put_contents(PATH_TESTS . $ds . 'tmp' . $ds . $csv, implode('', $data)) === false) {
         throw new Exception(sprintf('Unable to write test file "%1$s"', $csv));
     }
     $zip = new ZipArchive();
     $zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
     $zip->addFile(PATH_TESTS . $ds . 'tmp' . $ds . $csv, $csv);
     $zip->close();
     if (unlink(PATH_TESTS . $ds . 'tmp' . $ds . $csv) === false) {
         throw new Exception('Unable to remove export file');
     }
     $params = new stdClass();
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $params->items = $filename;
     $this->_object->importFile($params);
     $textManager = MShop_Text_Manager_Factory::createManager($this->_context);
     $criteria = $textManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'text.domain', 'attribute');
     $expr[] = $criteria->compare('==', 'text.languageid', 'en');
     $expr[] = $criteria->compare('==', 'text.status', 1);
     $expr[] = $criteria->compare('~=', 'text.content', 'unittest:');
     $criteria->setConditions($criteria->combine('&&', $expr));
     $textItems = $textManager->searchItems($criteria);
     $textIds = array();
     foreach ($textItems as $item) {
         $textManager->deleteItem($item->getId());
         $textIds[] = $item->getId();
     }
     $attributeManager = MShop_Attribute_Manager_Factory::createManager($this->_context);
     $listManager = $attributeManager->getSubManager('list');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'attribute.list.domain', 'text');
     $expr[] = $criteria->compare('==', 'attribute.list.refid', $textIds);
     $criteria->setConditions($criteria->combine('&&', $expr));
     $listItems = $listManager->searchItems($criteria);
     foreach ($listItems as $item) {
         $listManager->deleteItem($item->getId());
     }
     foreach ($textItems as $item) {
         $this->assertEquals('unittest:', substr($item->getContent(), 0, 9));
     }
     $this->assertEquals(6, count($textItems));
     $this->assertEquals(6, count($listItems));
     if (file_exists($filename) !== false) {
         throw new Exception('Import file was not removed');
     }
 }
Exemplo n.º 14
0
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('MShop_Exception');
     MShop_Text_Manager_Factory::createManager(TestHelper::getContext(), 'unknown');
 }
Exemplo n.º 15
0
 public function testImportFromXLSFile()
 {
     $this->_object = new Controller_ExtJS_Product_Import_Text_Default($this->_context);
     $filename = 'product-import-test.xlsx';
     $phpExcel = new PHPExcel();
     $phpExcel->setActiveSheetIndex(0);
     $sheet = $phpExcel->getActiveSheet();
     $sheet->setCellValueByColumnAndRow(0, 2, 'en');
     $sheet->setCellValueByColumnAndRow(0, 3, 'en');
     $sheet->setCellValueByColumnAndRow(0, 4, 'en');
     $sheet->setCellValueByColumnAndRow(0, 5, 'en');
     $sheet->setCellValueByColumnAndRow(0, 6, 'en');
     $sheet->setCellValueByColumnAndRow(0, 7, 'en');
     $sheet->setCellValueByColumnAndRow(1, 2, 'product');
     $sheet->setCellValueByColumnAndRow(1, 3, 'product');
     $sheet->setCellValueByColumnAndRow(1, 4, 'product');
     $sheet->setCellValueByColumnAndRow(1, 5, 'product');
     $sheet->setCellValueByColumnAndRow(1, 6, 'product');
     $sheet->setCellValueByColumnAndRow(1, 7, 'product');
     $sheet->setCellValueByColumnAndRow(2, 2, 'ABCD');
     $sheet->setCellValueByColumnAndRow(2, 3, 'ABCD');
     $sheet->setCellValueByColumnAndRow(2, 4, 'ABCD');
     $sheet->setCellValueByColumnAndRow(2, 5, 'ABCD');
     $sheet->setCellValueByColumnAndRow(2, 6, 'ABCD');
     $sheet->setCellValueByColumnAndRow(2, 7, 'ABCD');
     $sheet->setCellValueByColumnAndRow(3, 2, 'default');
     $sheet->setCellValueByColumnAndRow(3, 3, 'default');
     $sheet->setCellValueByColumnAndRow(3, 4, 'default');
     $sheet->setCellValueByColumnAndRow(3, 5, 'default');
     $sheet->setCellValueByColumnAndRow(3, 6, 'default');
     $sheet->setCellValueByColumnAndRow(3, 7, 'default');
     $sheet->setCellValueByColumnAndRow(4, 2, 'long');
     $sheet->setCellValueByColumnAndRow(4, 3, 'metadescription');
     $sheet->setCellValueByColumnAndRow(4, 4, 'metakeywords');
     $sheet->setCellValueByColumnAndRow(4, 5, 'metatitle');
     $sheet->setCellValueByColumnAndRow(4, 6, 'name');
     $sheet->setCellValueByColumnAndRow(4, 7, 'short');
     $sheet->setCellValueByColumnAndRow(6, 2, 'ABCD: long');
     $sheet->setCellValueByColumnAndRow(6, 3, 'ABCD: meta desc');
     $sheet->setCellValueByColumnAndRow(6, 4, 'ABCD: meta keywords');
     $sheet->setCellValueByColumnAndRow(6, 5, 'ABCD: meta title');
     $sheet->setCellValueByColumnAndRow(6, 6, 'ABCD: name');
     $sheet->setCellValueByColumnAndRow(6, 7, 'ABCD: short');
     $objWriter = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
     $objWriter->save($filename);
     $params = new stdClass();
     $params->site = $this->_context->getLocale()->getSite()->getCode();
     $params->items = $filename;
     $this->_object->importFile($params);
     $textManager = MShop_Text_Manager_Factory::createManager($this->_context);
     $criteria = $textManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'text.domain', 'product');
     $expr[] = $criteria->compare('==', 'text.languageid', 'en');
     $expr[] = $criteria->compare('==', 'text.status', 1);
     $expr[] = $criteria->compare('~=', 'text.content', 'ABCD:');
     $criteria->setConditions($criteria->combine('&&', $expr));
     $textItems = $textManager->searchItems($criteria);
     $textIds = array();
     foreach ($textItems as $item) {
         $textManager->deleteItem($item->getId());
         $textIds[] = $item->getId();
     }
     $productManager = MShop_Product_Manager_Factory::createManager($this->_context);
     $listManager = $productManager->getSubManager('list');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'product.list.domain', 'text');
     $expr[] = $criteria->compare('==', 'product.list.refid', $textIds);
     $criteria->setConditions($criteria->combine('&&', $expr));
     $listItems = $listManager->searchItems($criteria);
     foreach ($listItems as $item) {
         $listManager->deleteItem($item->getId());
     }
     foreach ($textItems as $item) {
         $this->assertEquals('ABCD:', substr($item->getContent(), 0, 5));
     }
     $this->assertEquals(6, count($textItems));
     $this->assertEquals(6, count($listItems));
     if (file_exists($filename) !== false) {
         throw new Exception('Import file was not removed');
     }
 }
Exemplo n.º 16
0
 /**
  * Initializes the text controller.
  *
  * @param MShop_Context_Item_Interface $context MShop context object
  */
 public function __construct(MShop_Context_Item_Interface $context)
 {
     parent::__construct($context, 'Text');
     $this->_manager = MShop_Text_Manager_Factory::createManager($context);
 }
Exemplo n.º 17
0
 /**
  * Imports the text content using the given text types.
  *
  * @param MW_Container_Content_Interface $contentItem Content item containing texts and associated data
  * @param array $textTypeMap Associative list of text type IDs as keys and text type codes as values
  * @param string $domain Name of the domain this text belongs to, e.g. product, catalog, attribute
  * @return void
  */
 protected function _importTextsFromContent(MW_Container_Content_Interface $contentItem, array $textTypeMap, $domain)
 {
     $count = 0;
     $codeIdMap = array();
     $context = $this->_getContext();
     $textManager = MShop_Text_Manager_Factory::createManager($context);
     $manager = MShop_Factory::createManager($context, $domain);
     $contentItem->next();
     // skip description row
     while (($row = $contentItem->current()) !== null) {
         $codeIdMap = $this->_importTextRow($textManager, $row, $textTypeMap, $codeIdMap, $domain);
         if (++$count == 1000) {
             $this->_importReferences($manager, $codeIdMap, $domain);
             $codeIdMap = array();
             $count = 0;
         }
         $contentItem->next();
     }
     if (!empty($codeIdMap)) {
         $this->_importReferences($manager, $codeIdMap, $domain);
     }
 }
Exemplo n.º 18
0
 protected function _getListItems()
 {
     $manager = MShop_Text_Manager_Factory::createManager($this->_context, 'Default');
     $search = $manager->createSearch();
     $expr = array($search->compare('==', 'text.label', 'cafe_long_desc'), $search->compare('==', 'text.domain', 'catalog'), $search->compare('==', 'text.type.code', 'long'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSlice(0, 1);
     $results = $manager->searchItems($search);
     if (($item = reset($results)) === false) {
         throw new Exception('No text item found');
     }
     $search = $this->_object->createSearch();
     $expr = array($search->compare('==', 'text.list.parentid', $item->getId()), $search->compare('==', 'text.list.domain', 'media'), $search->compare('==', 'text.list.editor', $this->_editor), $search->compare('==', 'text.list.type.code', 'align-left'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', 'text.list.position')));
     return $this->_object->searchItems($search);
 }