예제 #1
0
 public function testSaveDeleteItem()
 {
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager(\TestHelper::getContext());
     $node = $catalogManager->getTree(null, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE);
     $params = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('catalog.lists.type.domain' => 'product')))), 'start' => 0, 'limit' => 1);
     $catalogListTypeManager = \Aimeos\Controller\ExtJS\Catalog\Lists\Type\Factory::createController(\TestHelper::getContext());
     $resultType = $catalogListTypeManager->searchItems($params);
     $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('catalog.lists.parentid' => $node->getId(), 'catalog.lists.typeid' => $resultType['items'][0]->{'catalog.lists.type.id'}, 'catalog.lists.domain' => 'product', 'catalog.lists.refid' => -1, 'catalog.lists.datestart' => '2000-01-01 00:00:00', 'catalog.lists.dateend' => '2000-01-01 00:00:00', 'catalog.lists.config' => array('test' => 'unit'), 'catalog.lists.position' => 1, 'catalog.lists.status' => 1));
     $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('catalog.lists.refid' => -1)))));
     $saved = $this->object->saveItems($saveParams);
     $searched = $this->object->searchItems($searchParams);
     $deleteParams = (object) array('site' => 'unittest', 'items' => $saved['items']->{'catalog.lists.id'});
     $this->object->deleteItems($deleteParams);
     $result = $this->object->searchItems($searchParams);
     $this->assertInternalType('object', $saved['items']);
     $this->assertNotNull($saved['items']->{'catalog.lists.id'});
     $this->assertEquals($saved['items']->{'catalog.lists.id'}, $searched['items'][0]->{'catalog.lists.id'});
     $this->assertEquals($saved['items']->{'catalog.lists.parentid'}, $searched['items'][0]->{'catalog.lists.parentid'});
     $this->assertEquals($saved['items']->{'catalog.lists.typeid'}, $searched['items'][0]->{'catalog.lists.typeid'});
     $this->assertEquals($saved['items']->{'catalog.lists.domain'}, $searched['items'][0]->{'catalog.lists.domain'});
     $this->assertEquals($saved['items']->{'catalog.lists.refid'}, $searched['items'][0]->{'catalog.lists.refid'});
     $this->assertEquals($saved['items']->{'catalog.lists.datestart'}, $searched['items'][0]->{'catalog.lists.datestart'});
     $this->assertEquals($saved['items']->{'catalog.lists.dateend'}, $searched['items'][0]->{'catalog.lists.dateend'});
     $this->assertEquals($saved['items']->{'catalog.lists.config'}, $searched['items'][0]->{'catalog.lists.config'});
     $this->assertEquals($saved['items']->{'catalog.lists.position'}, $searched['items'][0]->{'catalog.lists.position'});
     $this->assertEquals($saved['items']->{'catalog.lists.status'}, $searched['items'][0]->{'catalog.lists.status'});
     $this->assertEquals(1, count($searched['items']));
     $this->assertEquals(0, count($result['items']));
 }
예제 #2
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->editor = \TestHelperMShop::getContext()->getEditor();
     $attributeManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager(\TestHelperMShop::getContext());
     $attributeListManager = $attributeManager->getSubManager('lists');
     $this->object = $attributeListManager->getSubManager('type');
 }
예제 #3
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = \TestHelperHtml::getContext();
     $config = $context->getConfig();
     $config->set('client/html/catalog/lists/basket-add', true);
     $paths = \TestHelperHtml::getHtmlTemplatePaths();
     $this->object = new \Aimeos\Client\Html\Catalog\Lists\Items\Standard($context, $paths);
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'cafe'));
     $catItems = $catalogManager->searchItems($search);
     if (($catItem = reset($catItems)) === false) {
         throw new \RuntimeException('No catalog item found');
     }
     $domains = array('media', 'price', 'text', 'attribute', 'product');
     $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($context);
     $search = $productManager->createSearch();
     $search->setConditions($search->compare('==', 'product.code', array('CNE', 'U:TEST', 'U:BUNDLE')));
     $total = 0;
     $view = \TestHelperHtml::getView('unittest', $config);
     $view->listProductItems = $productManager->searchItems($search, $domains, $total);
     $view->listProductTotal = $total;
     $view->listPageSize = 100;
     $view->listPageCurr = 1;
     $view->listParams = array();
     $view->listCatPath = array($catalogManager->createItem(), $catItem);
     $this->object->setView($view);
 }
예제 #4
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = \TestHelper::getContext();
     $paths = \TestHelper::getHtmlTemplatePaths();
     $this->object = new \Aimeos\Client\Html\Catalog\Lists\Items\Standard($context, $paths);
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'cafe'));
     $catItems = $catalogManager->searchItems($search);
     if (($catItem = reset($catItems)) === false) {
         throw new \Exception('No catalog item found');
     }
     $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($context);
     $search = $productManager->createSearch();
     $search->setConditions($search->compare('==', 'product.code', array('CNC', 'CNE')));
     $total = 0;
     $view = \TestHelper::getView();
     $view->listProductItems = $productManager->searchItems($search, array('media', 'price', 'text'), $total);
     $view->listProductTotal = $total;
     $view->listPageSize = 100;
     $view->listPageCurr = 1;
     $view->listParams = array();
     $view->listCatPath = array($catalogManager->createItem(), $catItem);
     $this->object->setView($view);
 }
예제 #5
0
 public function testTreeWithId()
 {
     $start = microtime(true);
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
     $catalogManager->getTree($this->root->getId(), array('text', 'media'));
     $stop = microtime(true);
     echo "\n    catalog tree with ID: " . ($stop - $start) * 1000 . " msec\n";
 }
예제 #6
0
 /**
  * Insert catalog nodes and product/catalog relations.
  */
 public function migrate()
 {
     $this->msg('Adding catalog text performance data', 0);
     $context = $this->getContext();
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
     $catalogListManager = $catalogManager->getSubManager('lists');
     $catalogListTypeManager = $catalogListManager->getSubManager('type');
     $search = $catalogListTypeManager->createSearch();
     $expr = array($search->compare('==', 'catalog.lists.type.domain', 'text'), $search->compare('==', 'catalog.lists.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 = \Aimeos\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');
 }
예제 #7
0
 public function testRun()
 {
     $context = \TestHelperJobs::getContext();
     $aimeos = \TestHelperJobs::getAimeos();
     $name = 'ControllerJobsCatalogIndexOptimizeDefaultRun';
     $context->getConfig()->set('mshop/index/manager/name', $name);
     $indexManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Index\\Manager\\Standard')->setMethods(array('optimize'))->setConstructorArgs(array($context))->getMock();
     \Aimeos\MShop\Catalog\Manager\Factory::injectManager('\\Aimeos\\MShop\\Index\\Manager\\' . $name, $indexManagerStub);
     $indexManagerStub->expects($this->once())->method('optimize');
     $object = new \Aimeos\Controller\Jobs\Index\Optimize\Standard($context, $aimeos);
     $object->run();
 }
 /**
  * Insert catalog nodes and product/catalog relations.
  */
 public function migrate()
 {
     $this->msg('Adding product categories performance data', 0);
     $context = $this->getContext();
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
     $catalogListManager = $catalogManager->getSubManager('lists');
     $catalogListTypeManager = $catalogListManager->getSubManager('type');
     $search = $catalogListTypeManager->createSearch();
     $expr = array($search->compare('==', 'catalog.lists.type.domain', 'product'), $search->compare('==', 'catalog.lists.type.code', 'default'));
     $search->setConditions($search->combine('&&', $expr));
     $types = $catalogListTypeManager->searchItems($search);
     if (($typeItem = reset($types)) === false) {
         throw new \RuntimeException('Catalog list type item not found');
     }
     $search = $catalogManager->createSearch();
     $search->setSortations(array($search->sort('+', 'catalog.level'), $search->sort('+', 'catalog.left')));
     $search->setSlice(0, 0x7fffffff);
     $catIds = array_keys($catalogManager->searchItems($search));
     $listItem = $catalogListManager->createItem();
     $listItem->setTypeId($typeItem->getId());
     $listItem->setDomain('product');
     $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($context);
     $search = $productManager->createSearch();
     $search->setSortations(array($search->sort('+', 'product.id')));
     $search->setSlice(0, 1000);
     $start = $pos = 0;
     do {
         $catId = current($catIds);
         if (($catId2 = next($catIds)) === false) {
             $catId2 = reset($catIds);
         }
         $result = $productManager->searchItems($search);
         $this->txBegin();
         foreach ($result as $id => $item) {
             $listItem->setId(null);
             $listItem->setParentId($catId);
             $listItem->setRefId($id);
             $listItem->setPosition($pos++);
             $catalogListManager->saveItem($listItem, false);
             $listItem->setId(null);
             $listItem->setParentId($catId2);
             $listItem->setRefId($id);
             $listItem->setPosition($pos++);
             $catalogListManager->saveItem($listItem, false);
         }
         $this->txCommit();
         $count = count($result);
         $start += $count;
         $search->setSlice($start, 1000);
     } while ($count == $search->getSliceSize());
     $this->status('done');
 }
예제 #9
0
 /**
  * Adds the catalog test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @throws \Aimeos\MW\Setup\Exception If a required ID is not available
  */
 private function addCatalogData(array $testdata)
 {
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->additional, 'Standard');
     $parentIds = array('init' => null);
     $catalog = $catalogManager->createItem();
     foreach ($testdata['catalog'] as $key => $dataset) {
         $catalog->setId(null);
         $catalog->setCode($dataset['code']);
         $catalog->setLabel($dataset['label']);
         $catalog->setConfig($dataset['config']);
         $catalog->setStatus($dataset['status']);
         $catalogManager->insertItem($catalog, $parentIds[$dataset['parent']]);
         $parentIds[$key] = $catalog->getId();
     }
 }
예제 #10
0
 public function testGetBodyLevelsOnly()
 {
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager(\TestHelperHtml::getContext());
     $node = $catalogManager->getTree(null, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE);
     $this->context->getConfig()->set('client/html/catalog/filter/tree/levels-only', 1);
     $view = $this->object->getView();
     $helper = new \Aimeos\MW\View\Helper\Param\Standard($view, array('f_catid' => $node->getChild(0)->getId()));
     $view->addHelper('param', $helper);
     $tags = array();
     $expire = null;
     $output = $this->object->getBody(1, $tags, $expire);
     $this->assertNotContains('level-2', $output);
     $this->assertEquals('2022-01-01 00:00:00', $expire);
     $this->assertEquals(1, count($tags));
 }
예제 #11
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = \TestHelper::getContext();
     $paths = \TestHelper::getHtmlTemplatePaths();
     $this->object = new \Aimeos\Client\Html\Catalog\Stage\Breadcrumb\Standard($context, $paths);
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'cafe'));
     $catItems = $catalogManager->searchItems($search);
     if (($catItem = reset($catItems)) === false) {
         throw new \Exception('No catalog item found');
     }
     $view = \TestHelper::getView();
     $view->stageCatPath = $catalogManager->getPath($catItem->getId());
     $this->object->setView($view);
 }
예제 #12
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->context = \TestHelperHtml::getContext();
     $paths = \TestHelperHtml::getHtmlTemplatePaths();
     $this->object = new \Aimeos\Client\Html\Catalog\Lists\Promo\Standard($this->context, $paths);
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'cafe'));
     $catItems = $catalogManager->searchItems($search, array('product'));
     if (($this->catItem = reset($catItems)) === false) {
         throw new \RuntimeException('No catalog item found');
     }
     $this->view = \TestHelperHtml::getView();
     $this->view->listParams = array();
     $this->view->listCurrentCatItem = $this->catItem;
     $this->object->setView($this->view);
 }
예제 #13
0
 /**
  * Inserts catalog promotion products.
  */
 protected function process()
 {
     $this->msg('Adding catalog promotion performance data', 0);
     $context = $this->getContext();
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
     $catalogListManager = $catalogManager->getSubManager('lists');
     $catalogListTypeManager = $catalogListManager->getSubManager('type');
     $search = $catalogListTypeManager->createSearch();
     $expr = array($search->compare('==', 'catalog.lists.type.domain', 'product'), $search->compare('==', 'catalog.lists.type.code', 'promotion'));
     $search->setConditions($search->combine('&&', $expr));
     $types = $catalogListTypeManager->searchItems($search);
     if (($typeItem = reset($types)) === false) {
         throw new \Exception('Catalog list type item not found');
     }
     $search = $catalogManager->createSearch();
     $search->setSortations(array($search->sort('+', 'catalog.level'), $search->sort('+', 'catalog.left')));
     $listItem = $catalogListManager->createItem();
     $listItem->setTypeId($typeItem->getId());
     $listItem->setDomain('product');
     $start = 0;
     do {
         $this->txBegin();
         $result = $catalogManager->searchItems($search);
         foreach ($result as $catId => $catItem) {
             $pos = 0;
             $search = $catalogListManager->createSearch();
             $expr = array($search->compare('==', 'catalog.lists.parentid', $catId), $search->compare('==', 'catalog.lists.position', array(20, 40, 60, 80)), $search->compare('==', 'catalog.lists.domain', 'product'), $search->compare('==', 'catalog.lists.type.code', 'default'));
             $search->setConditions($search->combine('&&', $expr));
             foreach ($catalogListManager->searchItems($search) as $item) {
                 $listItem->setId(null);
                 $listItem->setParentId($item->getParentId());
                 $listItem->setRefId($item->getRefId());
                 $listItem->setPosition($pos++);
                 $catalogListManager->saveItem($listItem, false);
             }
         }
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
         $this->txCommit();
     } while ($count == $search->getSliceSize());
     $this->status('done');
 }
예제 #14
0
 public function testExportXLSFile()
 {
     $this->object = new \Aimeos\Controller\ExtJS\Catalog\Export\Text\Standard($this->context);
     $manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
     $node = $manager->getTree(null, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE);
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.label', array('Root', 'Tee')));
     $ids = array();
     foreach ($manager->searchItems($search) as $item) {
         $ids[$item->getLabel()] = $item->getId();
     }
     $params = new \stdClass();
     $params->lang = array('de', 'fr');
     $params->items = array($node->getId());
     $params->site = $this->context->getLocale()->getSite()->getCode();
     $result = $this->object->exportFile($params);
     $this->assertTrue(array_key_exists('file', $result));
     $file = substr($result['file'], 9, -14);
     $this->assertTrue(file_exists($file));
     $inputFileType = \PHPExcel_IOFactory::identify($file);
     $objReader = \PHPExcel_IOFactory::createReader($inputFileType);
     $objPHPExcel = $objReader->load($file);
     $objPHPExcel->setActiveSheetIndex(0);
     if (unlink($file) === false) {
         throw new \RuntimeException('Unable to remove export file');
     }
     $sheet = $objPHPExcel->getActiveSheet();
     $this->assertEquals('Language ID', $sheet->getCell('A1')->getValue());
     $this->assertEquals('Text', $sheet->getCell('G1')->getValue());
     $this->assertEquals('de', $sheet->getCell('A4')->getValue());
     $this->assertEquals('Root', $sheet->getCell('B4')->getValue());
     $this->assertEquals($ids['Root'], $sheet->getCell('C4')->getValue());
     $this->assertEquals('default', $sheet->getCell('D4')->getValue());
     $this->assertEquals('name', $sheet->getCell('E4')->getValue());
     $this->assertEquals('', $sheet->getCell('G4')->getValue());
     $this->assertEquals('de', $sheet->getCell('A24')->getValue());
     $this->assertEquals('Tee', $sheet->getCell('B24')->getValue());
     $this->assertEquals($ids['Tee'], $sheet->getCell('C24')->getValue());
     $this->assertEquals('unittype8', $sheet->getCell('D24')->getValue());
     $this->assertEquals('long', $sheet->getCell('E24')->getValue());
     $this->assertEquals('Dies würde die lange Beschreibung der Teekategorie sein. Auch hier machen Bilder einen Sinn.', $sheet->getCell('G24')->getValue());
 }
예제 #15
0
 protected function setUp()
 {
     $this->paths = \TestHelperHtml::getHtmlTemplatePaths();
     $this->context = \TestHelperHtml::getContext('unitperf');
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'home'));
     $items = $catalogManager->searchItems($search);
     if (($catalogItem = reset($items)) === false) {
         throw new \RuntimeException('No catalog item with code "home" found');
     }
     $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context);
     $search = $productManager->createSearch();
     $search->setConditions($search->compare('==', 'product.code', 'perf-00000'));
     $items = $productManager->searchItems($search);
     if (($productItem = reset($items)) === false) {
         throw new \RuntimeException('No product item with code "perf-00000" found');
     }
     $this->view = \TestHelperHtml::getView('unitperf');
     $param = array('f_catid' => $catalogItem->getId(), 'd_prodid' => $productItem->getId());
     $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $param);
     $this->view->addHelper('param', $helper);
 }
예제 #16
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = \TestHelper::getContext();
     $this->object = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
 }
예제 #17
0
 public function testSearchByCategoriesPriceText()
 {
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
     $search = $catalogManager->createSearch(true);
     $search->setConditions($search->compare('==', 'catalog.label', 'cat-1'));
     $result = $catalogManager->searchItems($search);
     if (($catItem = reset($result)) === false) {
         throw new \RuntimeException('No catalog item found');
     }
     $catIds = array((int) $this->catItem->getId(), (int) $catItem->getId());
     $start = microtime(true);
     $indexManager = \Aimeos\MShop\Index\Manager\Factory::createManager($this->context);
     $search = $indexManager->createSearch(true);
     $search->setSlice(0, $this->slizeSize);
     $expr = array($search->getConditions(), $search->compare('==', 'index.catalog.id', (int) $this->catItem->getId()), $search->compare('>=', $search->createFunction('index.catalogcount', array('default', $catIds)), 2), $search->compare('>', $search->createFunction('index.text.relevance', array('default', 'en', 'plain')), 0), $search->compare('>=', $search->createFunction('index.price.value', array('default', 'EUR', 'default')), 0));
     $search->setConditions($search->combine('&&', $expr));
     $sort = array($search->sort('-', $search->createFunction('sort:index.text.relevance', array('default', 'en', 'plain'))));
     $search->setSortations($sort);
     $total = 0;
     $result = $indexManager->searchItems($search, array('text', 'price', 'media'), $total);
     $stop = microtime(true);
     printf("\n    index search by category count/text/price, sort by relevance (%1\$d/%2\$d): %3\$f msec\n", count($result), $total, ($stop - $start) * 1000);
 }
예제 #18
0
 public function testImportFromXLSFile()
 {
     $this->object = new \Aimeos\Controller\ExtJS\Catalog\Import\Text\Standard($this->context);
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
     $node = $catalogManager->getTree(null, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE);
     $params = new \stdClass();
     $params->lang = array('en');
     $params->items = $node->getId();
     $params->site = $this->context->getLocale()->getSite()->getCode();
     $exporter = new \Aimeos\Controller\ExtJS\Catalog\Export\Text\Standard($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 = PATH_TESTS . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'catalog-import.xls';
     $phpExcel = \PHPExcel_IOFactory::load($filename);
     if (unlink($filename) !== true) {
         throw new \RuntimeException(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 = basename($filename2);
     $this->object->importFile($params);
     if (file_exists($filename2) !== false) {
         throw new \RuntimeException('Import file was not removed');
     }
     $textManager = \Aimeos\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('lists');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'catalog.lists.domain', 'text');
     $expr[] = $criteria->compare('==', 'catalog.lists.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));
     }
 }
예제 #19
0
 public function testSearchItemsCatalog()
 {
     $context = $this->context;
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
     $catSearch = $catalogManager->createSearch();
     $conditions = array($catSearch->compare('==', 'catalog.label', 'Kaffee'), $catSearch->compare('==', 'catalog.editor', $this->editor));
     $catSearch->setConditions($catSearch->combine('&&', $conditions));
     $result = $catalogManager->searchItems($catSearch);
     if (($catItem = reset($result)) === false) {
         throw new \Exception('No catalog item found');
     }
     $conditions = array($catSearch->compare('==', 'catalog.label', 'Neu'), $catSearch->compare('==', 'catalog.editor', $this->editor));
     $catSearch->setConditions($catSearch->combine('&&', $conditions));
     $result = $catalogManager->searchItems($catSearch);
     if (($catNewItem = reset($result)) === false) {
         throw new \Exception('No catalog item found');
     }
     $search = $this->object->createSearch();
     $search->setConditions($search->compare('==', 'product.editor', $this->editor));
     $sortfunc = $search->createFunction('sort:index.catalog.position', array('promotion', $catItem->getId()));
     $search->setSortations(array($search->sort('+', $sortfunc)));
     $search->setSlice(0, 1);
     $this->assertEquals(1, count($this->object->searchItems($search)));
     $total = 0;
     $search = $this->object->createSearch();
     $search->setSlice(0, 1);
     $conditions = array($search->compare('==', 'index.catalog.id', $catItem->getId()), $search->compare('==', 'product.editor', $this->editor));
     $search->setConditions($search->combine('&&', $conditions));
     $result = $this->object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(2, $total);
     $conditions = array($search->compare('!=', 'index.catalog.id', null), $search->compare('==', 'product.editor', $this->editor));
     $search->setConditions($search->combine('&&', $conditions));
     $result = $this->object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(7, $total);
     $func = $search->createFunction('index.catalog.position', array('promotion', $catItem->getId()));
     $conditions = array($search->compare('>=', $func, 0), $search->compare('==', 'product.editor', $this->editor));
     $search->setConditions($search->combine('&&', $conditions));
     $sortfunc = $search->createFunction('sort:index.catalog.position', array('promotion', $catItem->getId()));
     $search->setSortations(array($search->sort('+', $sortfunc)));
     $result = $this->object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(2, $total);
     $catIds = array((int) $catItem->getId(), (int) $catNewItem->getId());
     $func = $search->createFunction('index.catalogcount', array('default', $catIds));
     $conditions = array($search->compare('==', $func, 2), $search->compare('==', 'product.editor', $this->editor));
     $search->setConditions($search->combine('&&', $conditions));
     $result = $this->object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(1, $total);
 }
예제 #20
0
 protected function getCatalogItem()
 {
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'cafe'));
     $items = $catalogManager->searchItems($search);
     if (($item = reset($items)) === false) {
         throw new \Exception('No catalog item with code "cafe" found');
     }
     return $item;
 }
예제 #21
0
 public function testImportFromCSVFile()
 {
     $catalogManager = \Aimeos\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 \Aimeos\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 = \Aimeos\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('lists');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'catalog.lists.domain', 'text');
     $expr[] = $criteria->compare('==', 'catalog.lists.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');
     }
 }
예제 #22
0
 protected function get($code)
 {
     $manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', $code));
     $result = $manager->searchItems($search, array('product'));
     if (($item = reset($result)) === false) {
         throw new \Exception(sprintf('No catalog item for code "%1$s"', $code));
     }
     return $item;
 }
예제 #23
0
 public function testSearchItems()
 {
     $context = \TestHelper::getContext();
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
     $catSearch = $catalogManager->createSearch();
     $catSearch->setConditions($catSearch->compare('==', 'catalog.label', 'Kaffee'));
     $result = $catalogManager->searchItems($catSearch);
     if (($catItem = reset($result)) === false) {
         throw new \Exception('No catalog item found');
     }
     $catSearch->setConditions($catSearch->compare('==', 'catalog.label', 'Neu'));
     $result = $catalogManager->searchItems($catSearch);
     if (($catNewItem = reset($result)) === false) {
         throw new \Exception('No catalog item found');
     }
     $search = $this->object->createSearch();
     $search->setConditions($search->compare('==', 'index.catalog.id', $catItem->getId()));
     // catalog ID
     $result = $this->object->searchItems($search, array());
     $this->assertEquals(2, count($result));
     $search->setConditions($search->compare('!=', 'index.catalog.id', null));
     // catalog ID
     $result = $this->object->searchItems($search, array());
     $this->assertEquals(8, count($result));
     $func = $search->createFunction('index.catalog.position', array('promotion', $catItem->getId()));
     $search->setConditions($search->compare('>=', $func, 0));
     // position
     $sortfunc = $search->createFunction('sort:index.catalog.position', array('promotion', $catItem->getId()));
     $search->setSortations(array($search->sort('+', $sortfunc)));
     $result = $this->object->searchItems($search, array());
     $this->assertEquals(2, count($result));
     $catIds = array((int) $catItem->getId(), (int) $catNewItem->getId());
     $func = $search->createFunction('index.catalogcount', array('default', $catIds));
     $search->setConditions($search->compare('==', $func, 2));
     // count categories
     $result = $this->object->searchItems($search, array());
     $this->assertEquals(1, count($result));
 }
예제 #24
0
 protected function delete(array $prodcodes, array $delete, array $nondelete)
 {
     $catListManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context)->getSubmanager('lists');
     $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context);
     $listManager = $productManager->getSubManager('lists');
     foreach ($this->get($prodcodes, $delete + $nondelete) as $id => $product) {
         foreach ($delete as $domain) {
             $manager = \Aimeos\MShop\Factory::createManager($this->context, $domain);
             foreach ($product->getListItems($domain) as $listItem) {
                 $manager->deleteItem($listItem->getRefItem()->getId());
                 $listManager->deleteItem($listItem->getId());
             }
         }
         foreach ($nondelete as $domain) {
             $ids = array_keys($product->getListItems($domain));
             $listManager->deleteItems($ids);
         }
         $productManager->deleteItem($product->getId());
         $search = $catListManager->createSearch();
         $search->setConditions($search->compare('==', 'catalog.lists.refid', $id));
         $result = $catListManager->searchItems($search);
         $catListManager->deleteItems(array_keys($result));
     }
     $attrManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context);
     $search = $attrManager->createSearch();
     $search->setConditions($search->compare('==', 'attribute.code', 'import-test'));
     $result = $attrManager->searchItems($search);
     $attrManager->deleteItems(array_keys($result));
 }
예제 #25
0
 /**
  * Adds the catalog 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 \Aimeos\MW\Setup\Exception If a required ID is not available
  */
 private function addCatalogListData(array $testdata, array $refIds)
 {
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->additional, 'Standard');
     $catalogListManager = $catalogManager->getSubManager('lists', 'Standard');
     $catalogListTypeManager = $catalogListManager->getSubManager('type', 'Standard');
     $itemCode = array();
     foreach ($testdata['catalog/lists'] as $dataset) {
         if (($pos = strpos($dataset['parentid'], '/')) === false || ($str = substr($dataset['parentid'], $pos + 1)) === false) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('Some keys for parentid are set wrong "%1$s"', $dataset['parentid']));
         }
         $itemCode[] = $str;
     }
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', $itemCode));
     $parentIds = array();
     foreach ($catalogManager->searchItems($search) as $item) {
         $parentIds['catalog/' . $item->getCode()] = $item->getId();
     }
     $listItemTypeIds = array();
     $listItemType = $catalogListTypeManager->createItem();
     $this->conn->begin();
     foreach ($testdata['catalog/lists/type'] as $key => $dataset) {
         $listItemType->setId(null);
         $listItemType->setCode($dataset['code']);
         $listItemType->setDomain($dataset['domain']);
         $listItemType->setLabel($dataset['label']);
         $listItemType->setStatus($dataset['status']);
         $catalogListTypeManager->saveItem($listItemType);
         $listItemTypeIds[$key] = $listItemType->getId();
     }
     $listItem = $catalogListManager->createItem();
     foreach ($testdata['catalog/lists'] as $dataset) {
         if (!isset($parentIds[$dataset['parentid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No catalog ID found for "%1$s"', $dataset['parentid']));
         }
         if (!isset($refIds[$dataset['domain']][$dataset['refid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No "%1$s" ref ID found for "%2$s"', $dataset['refid'], $dataset['domain']));
         }
         if (!isset($listItemTypeIds[$dataset['typeid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No catalog list type ID found for "%1$s"', $dataset['typeid']));
         }
         $listItem->setId(null);
         $listItem->setParentId($parentIds[$dataset['parentid']]);
         $listItem->setTypeId($listItemTypeIds[$dataset['typeid']]);
         $listItem->setRefId($refIds[$dataset['domain']][$dataset['refid']]);
         $listItem->setDomain($dataset['domain']);
         $listItem->setDateStart($dataset['start']);
         $listItem->setDateEnd($dataset['end']);
         $listItem->setConfig($dataset['config']);
         $listItem->setPosition($dataset['pos']);
         $listItem->setStatus($dataset['status']);
         $catalogListManager->saveItem($listItem, false);
     }
     $this->conn->commit();
 }
예제 #26
0
 protected function getListItems()
 {
     $manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context, 'Standard');
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'cafe'));
     $search->setSlice(0, 1);
     $results = $manager->searchItems($search);
     if (($item = reset($results)) === false) {
         throw new \Exception('No catalog item found');
     }
     $search = $this->object->createSearch();
     $expr = array($search->compare('==', 'catalog.lists.parentid', $item->getId()), $search->compare('==', 'catalog.lists.domain', 'text'), $search->compare('==', 'catalog.lists.editor', $this->editor), $search->compare('==', 'catalog.lists.type.code', 'unittype1'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', 'catalog.lists.position')));
     return $this->object->searchItems($search);
 }
예제 #27
0
 /**
  * Adds data for the given language.
  *
  * @param string $langid Language id
  * @param array $ids List of of item ids whose texts should be added
  * @param \Aimeos\MW\Container\Content\Iface $contentItem Content item
  */
 protected function addLanguage(\Aimeos\MW\Container\Content\Iface $contentItem, $langid, array $ids)
 {
     $manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->getContext());
     foreach ($ids as $id) {
         foreach ($this->getNodeList($manager->getTree($id, array('text'))) as $item) {
             $this->addItem($contentItem, $item, $langid);
         }
     }
 }
예제 #28
0
 public function testGetIndexItemsCategory()
 {
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager(\TestHelper::getContext());
     $search = $catalogManager->createSearch();
     $search->setConditions($search->compare('==', 'catalog.code', 'new'));
     $search->setSlice(0, 1);
     $items = $catalogManager->searchItems($search);
     if (($item = reset($items)) === false) {
         throw new \Exception('Catalog item not found');
     }
     $total = 0;
     $filter = $this->object->createIndexFilterCategory($item->getId(), 'position', '+', 1, 1);
     $results = $this->object->getIndexItems($filter, array(), $total);
     $this->assertEquals(3, $total);
     $this->assertEquals(1, count($results));
 }
예제 #29
-1
 /**
  * Returns the list of categories with their ID.
  *
  * @param array $config Associative array of existing configurations
  * @param \TYPO3\CMS\Backend\Form\FormEngine|\TYPO3\CMS\Backend\Form\DataPreprocessor $tceForms TCE forms object
  * @param string $sitecode Unique code of the site to retrieve the categories for
  * @return array Associative array with existing and new entries
  */
 public function getCategories(array $config, $tceForms = null, $sitecode = 'default')
 {
     if (isset($config['flexParentDatabaseRow']['pid'])) {
         // TYPO3 7+
         $pid = $config['flexParentDatabaseRow']['pid'];
     } elseif (isset($config['row']['pid'])) {
         // TYPO3 6.2
         $pid = $config['row']['pid'];
     }
     $pageTSConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($pid, 'tx_aimeos');
     if (isset($pageTSConfig['properties']['mshop.']['locale.']['site'])) {
         $sitecode = $pageTSConfig['properties']['mshop.']['locale.']['site'];
     }
     try {
         $context = Base::getContext(Base::getConfig());
         $context->setEditor('flexform');
         $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager($context);
         $context->setLocale($localeManager->bootstrap($sitecode, '', '', false));
         $manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
         $item = $manager->getTree(null, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE);
         $config['items'] = array_merge($config['items'], $this->getCategoryList($item, $item->getName()));
     } catch (\Exception $e) {
         error_log($e->getMessage() . PHP_EOL . $e->getTraceAsString());
     }
     return $config;
 }
예제 #30
-1
 /**
  * Insert catalog nodes and product/catalog relations.
  */
 protected function process()
 {
     $this->msg('Adding catalog performance data', 0);
     $context = $this->getContext();
     $catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($context);
     $catalogRootItem = $catalogManager->createItem();
     $catalogRootItem->setCode('home');
     $catalogRootItem->setLabel('Home');
     $catalogRootItem->setStatus(1);
     $catalogManager->insertItem($catalogRootItem);
     for ($i = 1; $i <= 5; $i++) {
         $catalogOneItem = $catalogManager->createItem();
         $catalogOneItem->setCode('cat-' . $i);
         $catalogOneItem->setLabel('cat-' . $i);
         $catalogOneItem->setStatus(1);
         $catalogManager->insertItem($catalogOneItem, $catalogRootItem->getId());
         for ($j = 1; $j <= 10; $j++) {
             $catalogTwoItem = $catalogManager->createItem();
             $catalogTwoItem->setCode('cat-' . $i . ':' . $j);
             $catalogTwoItem->setLabel('cat-' . $i . ':' . $j);
             $catalogTwoItem->setStatus(1);
             $catalogManager->insertItem($catalogTwoItem, $catalogOneItem->getId());
             for ($k = 1; $k <= 10; $k++) {
                 $catalogThreeItem = $catalogManager->createItem();
                 $catalogThreeItem->setCode('cat-' . $i . ':' . $j . ':' . $k);
                 $catalogThreeItem->setLabel('cat-' . $i . ':' . $j . ':' . $k);
                 $catalogThreeItem->setStatus(1);
                 $catalogManager->insertItem($catalogThreeItem, $catalogTwoItem->getId());
             }
         }
     }
     $this->status('done');
 }