/**
  * Adds the attribute 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 addAttributeData(array $testdata)
 {
     $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->additional, 'Standard');
     $attributeTypeManager = $attributeManager->getSubManager('type', 'Standard');
     $atypeIds = array();
     $atype = $attributeTypeManager->createItem();
     $this->conn->begin();
     foreach ($testdata['attribute/type'] as $key => $dataset) {
         $atype->setId(null);
         $atype->setCode($dataset['code']);
         $atype->setDomain($dataset['domain']);
         $atype->setLabel($dataset['label']);
         $atype->setStatus($dataset['status']);
         $attributeTypeManager->saveItem($atype);
         $atypeIds[$key] = $atype->getId();
     }
     $attribute = $attributeManager->createItem();
     foreach ($testdata['attribute'] as $key => $dataset) {
         if (!isset($atypeIds[$dataset['typeid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No attribute type ID found for "%1$s"', $dataset['typeid']));
         }
         $attribute->setId(null);
         $attribute->setDomain($dataset['domain']);
         $attribute->setTypeId($atypeIds[$dataset['typeid']]);
         $attribute->setCode($dataset['code']);
         $attribute->setLabel($dataset['label']);
         $attribute->setStatus($dataset['status']);
         $attribute->setPosition($dataset['pos']);
         $attributeManager->saveItem($attribute, false);
     }
     $this->conn->commit();
 }
Beispiel #2
0
 public function testExportXLSFile()
 {
     $this->object = new \Aimeos\Controller\ExtJS\Attribute\Export\Text\Standard($this->context);
     $manager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context);
     $ids = array();
     foreach ($manager->searchItems($manager->createSearch()) as $item) {
         $ids[] = $item->getId();
     }
     $params = new \stdClass();
     $params->lang = array('de');
     $params->items = $ids;
     $params->site = 'unittest';
     $result = $this->object->exportFile($params);
     $this->assertTrue(array_key_exists('file', $result));
     $file = substr($result['file'], 9, -14);
     $this->assertTrue(file_exists($file));
     $phpExcel = \PHPExcel_IOFactory::load($file);
     if (unlink($file) === false) {
         throw new \RuntimeException('Unable to remove export file');
     }
     $phpExcel->setActiveSheetIndex(0);
     $sheet = $phpExcel->getActiveSheet();
     $this->assertEquals('Language ID', $sheet->getCell('A1')->getValue());
     $this->assertEquals('Text', $sheet->getCell('G1')->getValue());
     $this->assertEquals('de', $sheet->getCell('A9')->getValue());
     $this->assertEquals('color', $sheet->getCell('B9')->getValue());
     $this->assertEquals('red', $sheet->getCell('C9')->getValue());
     $this->assertEquals('default', $sheet->getCell('D9')->getValue());
     $this->assertEquals('name', $sheet->getCell('E9')->getValue());
     $this->assertEquals('', $sheet->getCell('G9')->getValue());
 }
 /**
  * Returns required attribute item ids.
  *
  * @param array $keys List of keys for search
  * @return array $refIds List with referenced Ids
  * @throws \Aimeos\MW\Setup\Exception If no type ID is found
  */
 protected function getAttributeData(array $keys)
 {
     $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->additional, 'Standard');
     $attributeTypeManager = $attributeManager->getSubManager('type', 'Standard');
     $codes = $typeCodes = $domains = array();
     foreach ($keys as $dataset) {
         $exp = explode('/', $dataset);
         if (count($exp) != 4) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('Some keys for ref attribute are set wrong "%1$s"', $dataset));
         }
         $domains[] = $exp[1];
         $typeCodes[] = $exp[2];
         $codes[] = $exp[3];
     }
     $search = $attributeTypeManager->createSearch();
     $expr = array($search->compare('==', 'attribute.type.domain', $domains), $search->compare('==', 'attribute.type.code', $typeCodes));
     $search->setConditions($search->combine('&&', $expr));
     $typeids = array();
     foreach ($attributeTypeManager->searchItems($search) as $item) {
         $typeids[] = $item->getId();
     }
     $search = $attributeManager->createSearch();
     $expr = array($search->compare('==', 'attribute.code', $codes), $search->compare('==', 'attribute.typeid', $typeids));
     $search->setConditions($search->combine('&&', $expr));
     $refIds = array();
     foreach ($attributeManager->searchItems($search) as $item) {
         $refIds['attribute/' . $item->getDomain() . '/' . $item->getType() . '/' . $item->getCode()] = $item->getId();
     }
     return $refIds;
 }
Beispiel #4
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\Attribute\Manager\Factory::createManager(\TestHelperMShop::getContext());
     $attributeListManager = $attributeManager->getSubManager('lists');
     $this->object = $attributeListManager->getSubManager('type');
 }
Beispiel #5
0
 public function testSaveDeleteItem()
 {
     $manager = \Aimeos\MShop\Attribute\Manager\Factory::createManager(\TestHelperExtjs::getContext());
     $typeManager = $manager->getSubManager('type');
     $criteria = $typeManager->createSearch();
     $criteria->setSlice(0, 1);
     $result = $typeManager->searchItems($criteria);
     if (($type = reset($result)) === false) {
         throw new \Exception('No type item found');
     }
     $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('attribute.typeid' => $type->getId(), 'attribute.domain' => 'product', 'attribute.code' => 'test', 'attribute.label' => 'test label', 'attribute.position' => 1, 'attribute.status' => 0));
     $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => array('==' => (object) array('attribute.code' => 'test')))));
     $saved = $this->object->saveItems($saveParams);
     $searched = $this->object->searchItems($searchParams);
     $deleteParams = (object) array('site' => 'unittest', 'items' => array($saved['items']->{'attribute.id'}));
     $this->object->deleteItems($deleteParams);
     $result = $this->object->searchItems($searchParams);
     $this->assertInternalType('object', $saved['items']);
     $this->assertNotNull($saved['items']->{'attribute.id'});
     $this->assertEquals($saved['items']->{'attribute.id'}, $searched['items'][0]->{'attribute.id'});
     $this->assertEquals($saved['items']->{'attribute.typeid'}, $searched['items'][0]->{'attribute.typeid'});
     $this->assertEquals($saved['items']->{'attribute.domain'}, $searched['items'][0]->{'attribute.domain'});
     $this->assertEquals($saved['items']->{'attribute.code'}, $searched['items'][0]->{'attribute.code'});
     $this->assertEquals($saved['items']->{'attribute.label'}, $searched['items'][0]->{'attribute.label'});
     $this->assertEquals($saved['items']->{'attribute.position'}, $searched['items'][0]->{'attribute.position'});
     $this->assertEquals($saved['items']->{'attribute.status'}, $searched['items'][0]->{'attribute.status'});
     $this->assertEquals(1, count($searched['items']));
     $this->assertEquals(0, count($result['items']));
 }
Beispiel #6
0
 public function testInjectManagerReset()
 {
     $manager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context, 'Standard');
     \Aimeos\MShop\Attribute\Manager\Factory::injectManager('\\Aimeos\\MShop\\Attribute\\Manager\\StandardMock', $manager);
     \Aimeos\MShop\Attribute\Manager\Factory::injectManager('\\Aimeos\\MShop\\Attribute\\Manager\\StandardMock', null);
     $this->setExpectedException('\\Aimeos\\MShop\\Exception');
     \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context, 'StandardMock');
 }
 public function testExportCSVFile()
 {
     $manager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context);
     $ids = array();
     foreach ($manager->searchItems($manager->createSearch()) as $item) {
         $ids[] = $item->getId();
     }
     $params = new \stdClass();
     $params->lang = array('de');
     $params->items = $ids;
     $params->site = 'unittest';
     $result = $this->object->exportFile($params);
     $this->assertTrue(array_key_exists('file', $result));
     $file = substr($result['file'], 9, -14);
     $this->assertTrue(file_exists($file));
     $zip = new \ZipArchive();
     $zip->open($file);
     $testdir = 'tmp' . DIRECTORY_SEPARATOR . 'csvexport';
     if (!is_dir($testdir) && mkdir($testdir, 0755, true) === false) {
         throw new \Aimeos\Controller\ExtJS\Exception(sprintf('Couldn\'t create directory "csvexport"'));
     }
     $zip->extractTo($testdir);
     $zip->close();
     if (unlink($file) === false) {
         throw new \Exception('Unable to remove export file');
     }
     $deCSV = $testdir . DIRECTORY_SEPARATOR . 'de.csv';
     $this->assertTrue(file_exists($deCSV));
     $fh = fopen($deCSV, 'r');
     $lines = array();
     while (($data = fgetcsv($fh)) != false) {
         $lines[] = $data;
     }
     fclose($fh);
     if (unlink($deCSV) === false) {
         throw new \Exception('Unable to remove export file');
     }
     if (rmdir($testdir) === false) {
         throw new \Exception('Unable to remove test export directory');
     }
     $this->assertEquals('Language ID', $lines[0][0]);
     $this->assertEquals('Text', $lines[0][6]);
     $this->assertEquals('de', $lines[8][0]);
     $this->assertEquals('color', $lines[8][1]);
     $this->assertEquals('red', $lines[8][2]);
     $this->assertEquals('default', $lines[8][3]);
     $this->assertEquals('name', $lines[8][4]);
     $this->assertEquals('', $lines[8][6]);
     $this->assertEquals('', $lines[163][0]);
     $this->assertEquals('width', $lines[163][1]);
     $this->assertEquals('29', $lines[163][2]);
     $this->assertEquals('default', $lines[163][3]);
     $this->assertEquals('name', $lines[163][4]);
     $this->assertEquals('29', $lines[163][6]);
 }
 public function testAddProductVariant()
 {
     $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager(\TestHelperFrontend::getContext());
     $search = $attributeManager->createSearch();
     $search->setConditions($search->compare('==', 'attribute.code', array('xs', 'white')));
     $attributes = $attributeManager->searchItems($search);
     if (count($attributes) === 0) {
         throw new \RuntimeException('Attributes not found');
     }
     $item = \Aimeos\MShop\Factory::createManager($this->context, 'product')->findItem('CNC');
     $this->object->addProduct($item->getId(), 1, array(), array_keys($attributes), array(), array(), array(), 'default');
     $this->assertEquals(1, count($this->object->get()->getProducts()));
     $this->assertEquals('CNC', $this->object->get()->getProduct(0)->getProductCode());
 }
 /**
  * Insert attribute items and product/attribute relations.
  */
 protected function process()
 {
     $this->msg('Adding product variant attribute performance data', 0);
     $context = $this->getContext();
     $attrManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($context);
     $attrTypeManager = $attrManager->getSubManager('type');
     $search = $attrTypeManager->createSearch();
     $search->setConditions($search->compare('==', 'attribute.type.code', 'width'));
     $result = $attrTypeManager->searchItems($search);
     if (($attrTypeItem = reset($result)) === false) {
         throw new \Exception('No attribute type "size" found');
     }
     $this->txBegin();
     $attrItem = $attrManager->createItem();
     $attrItem->setTypeId($attrTypeItem->getId());
     $attrItem->setDomain('product');
     $attrItem->setStatus(1);
     $pos = 0;
     $attrListWidth = array();
     foreach (array('tight', 'normal', 'wide') as $size) {
         $attrItem->setId(null);
         $attrItem->setCode($size);
         $attrItem->setLabel($size);
         $attrItem->setPosition($pos++);
         $attrManager->saveItem($attrItem);
         $attrListWidth[$attrItem->getId()] = clone $attrItem;
     }
     $search = $attrTypeManager->createSearch();
     $search->setConditions($search->compare('==', 'attribute.type.code', 'length'));
     $result = $attrTypeManager->searchItems($search);
     if (($attrTypeItem = reset($result)) === false) {
         throw new \Exception('No attribute type "size" found');
     }
     $attrItem = $attrManager->createItem();
     $attrItem->setTypeId($attrTypeItem->getId());
     $attrItem->setDomain('product');
     $attrItem->setStatus(1);
     $pos = 0;
     $attrListLength = array();
     foreach (array('short', 'normal', 'long') as $size) {
         $attrItem->setId(null);
         $attrItem->setCode($size);
         $attrItem->setLabel($size);
         $attrItem->setPosition($pos++);
         $attrManager->saveItem($attrItem);
         $attrListLength[$attrItem->getId()] = clone $attrItem;
     }
     $this->txCommit();
     $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager($context);
     $productListManager = $productManager->getSubManager('lists');
     $productListTypeManager = $productListManager->getSubManager('type');
     $expr = array();
     $search = $productListTypeManager->createSearch();
     $expr[] = $search->compare('==', 'product.lists.type.domain', 'attribute');
     $expr[] = $search->compare('==', 'product.lists.type.code', 'variant');
     $search->setConditions($search->combine('&&', $expr));
     $types = $productListTypeManager->searchItems($search);
     if (($productListTypeItem = reset($types)) === false) {
         throw new \Exception('Product list type item not found');
     }
     $search = $productManager->createSearch();
     $search->setSortations(array($search->sort('+', 'product.id')));
     $listItem = $productListManager->createItem();
     $listItem->setTypeId($productListTypeItem->getId());
     $listItem->setDomain('attribute');
     $this->txBegin();
     $start = 0;
     do {
         $result = $productManager->searchItems($search);
         foreach ($result as $id => $item) {
             $listItem->setId(null);
             $listItem->setParentId($id);
             $listItem->setRefId(key($attrListLength));
             $listItem->setPosition(0);
             $productListManager->saveItem($listItem, false);
             $listItem->setId(null);
             $listItem->setParentId($id);
             $listItem->setRefId(key($attrListWidth));
             $listItem->setPosition(1);
             $productListManager->saveItem($listItem, false);
             if (next($attrListLength) === false) {
                 reset($attrListLength);
                 next($attrListWidth);
                 if (current($attrListWidth) === false) {
                     reset($attrListWidth);
                 }
             }
         }
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count == $search->getSliceSize());
     $this->txCommit();
     $this->status('done');
 }
Beispiel #10
0
 public function testUpdateListItems()
 {
     $attrManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context);
     $attrId = $attrManager->findItem('s', array(), 'product', 'size')->getId();
     $item = $this->object->findItem('CNC', array('attribute'));
     // create new list item
     $map = array($attrId => array('product.lists.datestart' => '2000-01-01 00:00:00'));
     $this->object->updateListItems($item, $map, 'attribute', 'hidden');
     $item = $this->object->findItem('CNC', array('attribute'));
     $listItems = $item->getListItems('attribute', 'hidden');
     $this->assertEquals(1, count($listItems));
     $this->assertEquals('2000-01-01 00:00:00', reset($listItems)->getDateStart());
     // update existing list item
     $map = array($attrId => array('product.lists.config' => array('key' => 'value')));
     $this->object->updateListItems($item, $map, 'attribute', 'hidden');
     $item = $this->object->findItem('CNC', array('attribute'));
     $listItems = $item->getListItems('attribute', 'hidden');
     $this->assertEquals(1, count($listItems));
     $this->assertEquals('2000-01-01 00:00:00', reset($listItems)->getDateStart());
     $this->assertEquals(array('key' => 'value'), reset($listItems)->getConfig());
     // delete existing list item
     $this->object->updateListItems($item, array(), 'attribute', 'hidden');
     $item = $this->object->findItem('CNC', array('attribute'));
     $this->assertEquals(0, count($item->getListItems('attribute', 'hidden')));
 }
Beispiel #11
0
 /**
  * Adds data for the given language.
  *
  * @param \Aimeos\MW\Container\Content\Iface $contentItem Content item
  * @param string $langid Language id
  * @param array $ids List of of item ids whose texts should be added
  */
 protected function addLanguage(\Aimeos\MW\Container\Content\Iface $contentItem, $langid, array $ids)
 {
     $manager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->getContext());
     $search = $manager->createSearch();
     if (!empty($ids)) {
         $search->setConditions($search->compare('==', 'attribute.id', $ids));
     }
     $sort = array($search->sort('+', 'attribute.siteid'), $search->sort('+', 'attribute.domain'), $search->sort('-', 'attribute.code'), $search->sort('-', 'attribute.typeid'));
     $search->setSortations($sort);
     $start = 0;
     do {
         $result = $manager->searchItems($search, array('text'));
         foreach ($result as $item) {
             $this->addItem($contentItem, $item, $langid);
         }
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count == $search->getSliceSize());
 }
 public function testCopyFrom()
 {
     $attrManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager(\TestHelper::getContext());
     $items = $attrManager->searchItems($attrManager->createSearch());
     if (($item = reset($items)) === false) {
         throw new \Exception('No attribute item found');
     }
     $this->object->copyFrom($item);
     $this->assertEquals($item->getId(), $this->object->getAttributeId());
     $this->assertEquals($item->getLabel(), $this->object->getName());
     $this->assertEquals($item->getType(), $this->object->getCode());
     $this->assertEquals($item->getCode(), $this->object->getValue());
 }
Beispiel #13
0
 protected function getListItems()
 {
     $manager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context, 'Standard');
     $search = $manager->createSearch();
     $expr = array($search->compare('==', 'attribute.code', 'xs'), $search->compare('==', 'attribute.domain', 'product'), $search->compare('==', 'attribute.editor', $this->editor), $search->compare('==', 'attribute.type.code', 'size'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSlice(0, 1);
     $results = $manager->searchItems($search);
     if (($item = reset($results)) === false) {
         throw new \Exception('No attribute item found');
     }
     $search = $this->object->createSearch();
     $expr = array($search->compare('==', 'attribute.lists.parentid', $item->getId()), $search->compare('==', 'attribute.lists.domain', 'text'), $search->compare('==', 'attribute.lists.editor', $this->editor), $search->compare('==', 'attribute.lists.type.code', 'default'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', 'attribute.lists.position')));
     return $this->object->searchItems($search);
 }
 public function testUpdateAttributePriceUpdated()
 {
     $context = \TestHelper::getContext();
     $attrManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($context);
     $search = $attrManager->createSearch();
     $expr = array($search->compare('==', 'attribute.code', 'xs'), $search->compare('==', 'attribute.type.code', 'size'));
     $search->setConditions($search->combine('&&', $expr));
     $attributes = $attrManager->searchItems($search, array('price'));
     if (($attribute = reset($attributes)) === false) {
         throw new \Exception('No attribute found');
     }
     $orderProdAttrManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product/attribute');
     $ordAttr = $orderProdAttrManager->createItem();
     $ordAttr->copyFrom($attribute);
     $orderProduct = $this->order->getProduct(0);
     $orderProduct->setAttributes(array($ordAttr));
     $orderProduct->setPrice($this->price);
     $object = new \Aimeos\MShop\Plugin\Provider\Order\ProductPrice($context, $this->plugin);
     try {
         $object->update($this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT);
         $this->fail('Price changes not recognized');
     } catch (\Aimeos\MShop\Plugin\Provider\Exception $mppe) {
         $this->assertEquals('612.95', $this->order->getProduct(0)->getPrice()->getValue());
         $this->assertEquals(array('product' => array('0' => 'price.changed')), $mppe->getErrorCodes());
     }
 }
Beispiel #15
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 = basename($filename);
     $this->object->importFile($params);
     $textManager = \Aimeos\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 = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context);
     $listManager = $attributeManager->getSubManager('lists');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'attribute.lists.domain', 'text');
     $expr[] = $criteria->compare('==', 'attribute.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('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');
     }
 }
Beispiel #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()
 {
     $this->editor = \TestHelperMShop::getContext()->getEditor();
     $this->object = \Aimeos\MShop\Attribute\Manager\Factory::createManager(\TestHelperMShop::getContext());
 }
 public function testGetBodyAddCustomAttribute()
 {
     $attrManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context);
     $search = $attrManager->createSearch();
     $expr = array($search->compare('==', 'attribute.code', 'custom'), $search->compare('==', 'attribute.domain', 'product'), $search->compare('==', 'attribute.type.code', 'date'));
     $search->setConditions($search->combine('&&', $expr));
     $result = $attrManager->searchItems($search, array());
     if (($attribute = reset($result)) === false) {
         throw new \Exception('No attribute');
     }
     $view = $this->object->getView();
     $param = array('b_action' => 'add', 'b_prodid' => $this->getProductItem('U:TESTP')->getId(), 'b_quantity' => 1, 'b_attrcustid' => array($attribute->getId() => '2000-01-01'), 'b_warehouse' => 'default');
     $helper = new \Aimeos\MW\View\Helper\Parameter\Standard($view, $param);
     $view->addHelper('param', $helper);
     $this->object->process();
     $output = $this->object->getBody();
     $this->assertRegExp('#<li class="attr-item">.*<span class="value">2000-01-01</span>.*</li>#smU', $output);
 }
Beispiel #18
0
 public function testImportFromXLSFile()
 {
     $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context);
     $search = $attributeManager->createSearch();
     $search->setConditions($search->compare('==', 'attribute.type.code', 'color'));
     $ids = array();
     foreach ($attributeManager->searchItems($search) as $item) {
         $ids[] = $item->getId();
     }
     if (empty($ids)) {
         throw new \RuntimeException('Empty id list');
     }
     $params = new \stdClass();
     $params->lang = array('en');
     $params->items = $ids;
     $params->site = $this->context->getLocale()->getSite()->getCode();
     $exporter = new \Aimeos\Controller\ExtJS\Attribute\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 . 'attribute-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.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 = $attributeManager->getSubManager('lists');
     $criteria = $listManager->createSearch();
     $expr = array();
     $expr[] = $criteria->compare('==', 'attribute.lists.domain', 'text');
     $expr[] = $criteria->compare('==', 'attribute.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));
     }
 }
 protected function cleanupAttribute()
 {
     $manager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->context);
     $search = $manager->createSearch();
     $expr = array($search->compare('==', 'attribute.domain', 'product'), $search->compare('==', 'attribute.label', 'import-%'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', 'attribute.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());
 }
Beispiel #20
0
 /**
  * Adds the order product attribute test data.
  *
  * @param \Aimeos\MShop\Common\Manager\Iface $manager
  * @param array $testdata
  * @param array $ordProds
  * @param \Aimeos\MShop\Product\Item\Iface[] $products
  * @throws \Aimeos\MW\Setup\Exception
  */
 protected function addOrderBaseProductAttributeData(\Aimeos\MShop\Common\Manager\Iface $manager, array $testdata, array $ordProds, array $products)
 {
     $attrCodes = array();
     $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->additional, 'Standard');
     $attributes = $attributeManager->searchItems($attributeManager->createSearch());
     foreach ($attributes as $attrItem) {
         $attrCodes[$attrItem->getType()][] = $attrItem;
     }
     $ordProdAttr = $manager->createItem();
     foreach ($testdata['order/base/product/attr'] as $dataset) {
         if (!isset($ordProds[$dataset['ordprodid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No order product ID found for "%1$s"', $dataset['ordprodid']));
         }
         $ordProdAttr->setId(null);
         $ordProdAttr->setParentId($ordProds[$dataset['ordprodid']]);
         $ordProdAttr->setCode($dataset['code']);
         $ordProdAttr->setValue($dataset['value']);
         $ordProdAttr->setName($dataset['name']);
         if (isset($attrCodes[$dataset['code']])) {
             foreach ((array) $attrCodes[$dataset['code']] as $attrItem) {
                 if ($attrItem->getCode() == $dataset['value']) {
                     $ordProdAttr->setAttributeId($attrItem->getId());
                 }
             }
         }
         if (isset($dataset['type'])) {
             $ordProdAttr->setType($products[$dataset['type']]->getType());
         }
         $manager->saveItem($ordProdAttr, false);
     }
 }
Beispiel #21
0
 public function testSearchItems()
 {
     $context = \TestHelperMShop::getContext();
     $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($context);
     $search = $attributeManager->createSearch();
     $expr = array($search->compare('==', 'attribute.code', '30'), $search->compare('==', 'attribute.editor', $context->getEditor()), $search->compare('==', 'attribute.type.domain', 'product'), $search->compare('==', 'attribute.type.code', 'length'));
     $search->setConditions($search->combine('&&', $expr));
     $result = $attributeManager->searchItems($search);
     if (($attrLengthItem = reset($result)) === false) {
         throw new \Exception('No attribute item found');
     }
     $expr = array($search->compare('==', 'attribute.code', '29'), $search->compare('==', 'attribute.editor', $context->getEditor()), $search->compare('==', 'attribute.type.domain', 'product'), $search->compare('==', 'attribute.type.code', 'width'));
     $search->setConditions($search->combine('&&', $expr));
     $result = $attributeManager->searchItems($search);
     if (($attrWidthItem = reset($result)) === false) {
         throw new \Exception('No attribute item found');
     }
     $search = $this->object->createSearch();
     $search->setConditions($search->compare('==', 'index.attribute.id', $attrWidthItem->getId()));
     $result = $this->object->searchItems($search, array());
     $this->assertGreaterThanOrEqual(1, count($result));
     $search = $this->object->createSearch();
     $search->setConditions($search->compare('==', 'index.attribute.id', $attrLengthItem->getId()));
     $result = $this->object->searchItems($search, array());
     $this->assertEquals(3, count($result));
     $search->setConditions($search->compare('!=', 'index.attribute.id', null));
     $result = $this->object->searchItems($search, array());
     $this->assertGreaterThanOrEqual(2, count($result));
     $attrIds = array((int) $attrLengthItem->getId(), (int) $attrWidthItem->getId());
     $func = $search->createFunction('index.attributecount', array('variant', $attrIds));
     $search->setConditions($search->compare('==', $func, 2));
     // count attributes
     $result = $this->object->searchItems($search, array());
     if (($product = reset($result)) === false) {
         throw new \Exception('No product found');
     }
     $this->assertEquals(2, count($result));
     $this->assertEquals('CNE', $product->getCode());
     $func = $search->createFunction('index.attribute.code', array('default', 'size'));
     $search->setConditions($search->compare('~=', $func, 'x'));
     $result = $this->object->searchItems($search, array());
     $this->assertEquals(4, count($result));
 }
 /**
  * Gets the attribute test data and adds attribute-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 \Aimeos\MW\Setup\Exception If a required ID is not available
  */
 private function addAttributeListData(array $testdata, array $refIds)
 {
     $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->additional, 'Standard');
     $attributeTypeManager = $attributeManager->getSubManager('type', 'Standard');
     $attributeListManager = $attributeManager->getSubManager('lists', 'Standard');
     $attributeListTypeManager = $attributeListManager->getSubManager('type', 'Standard');
     $codes = $typeCodes = array();
     foreach ($testdata['attribute/lists'] as $dataset) {
         $exp = explode('/', $dataset['parentid']);
         if (count($exp) != 3) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('Some keys for parentid are set wrong "%1$s"', $dataset['parentid']));
         }
         $typeCodes[] = $exp[1];
         $codes[] = $exp[2];
     }
     $search = $attributeTypeManager->createSearch();
     $expr = array($search->compare('==', 'attribute.type.domain', 'product'), $search->compare('==', 'attribute.type.code', $typeCodes));
     $search->setConditions($search->combine('&&', $expr));
     $typeids = array();
     foreach ($attributeTypeManager->searchItems($search) as $item) {
         $typeids[] = $item->getId();
     }
     $search = $attributeManager->createSearch();
     $expr = array($search->compare('==', 'attribute.code', $codes), $search->compare('==', 'attribute.typeid', $typeids));
     $search->setConditions($search->combine('&&', $expr));
     $parentIds = array();
     foreach ($attributeManager->searchItems($search) as $item) {
         $parentIds['attribute/' . $item->getType() . '/' . $item->getCode()] = $item->getId();
     }
     $listItemTypeIds = array();
     $listItemType = $attributeListTypeManager->createItem();
     $this->conn->begin();
     foreach ($testdata['attribute/lists/type'] as $key => $dataset) {
         $listItemType->setId(null);
         $listItemType->setCode($dataset['code']);
         $listItemType->setDomain($dataset['domain']);
         $listItemType->setLabel($dataset['label']);
         $listItemType->setStatus($dataset['status']);
         $attributeListTypeManager->saveItem($listItemType);
         $listItemTypeIds[$key] = $listItemType->getId();
     }
     $listItem = $attributeListManager->createItem();
     foreach ($testdata['attribute/lists'] as $dataset) {
         if (!isset($parentIds[$dataset['parentid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No attribute ID found for "%1$s"', $dataset['parentid']));
         }
         if (!isset($listItemTypeIds[$dataset['typeid']])) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('No attribute list type ID found for "%1$s"', $dataset['typeid']));
         }
         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']));
         }
         $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']);
         $attributeListManager->saveItem($listItem, false);
     }
     $this->conn->commit();
 }
 public function testEditProductAttributes()
 {
     $productManager = \Aimeos\MShop\Product\Manager\Factory::createManager(\TestHelper::getContext());
     $search = $productManager->createSearch();
     $search->setConditions($search->compare('==', 'product.code', 'U:TESTP'));
     $items = $productManager->searchItems($search);
     if (($item = reset($items)) === false) {
         throw new \Exception('Product not found');
     }
     $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager(\TestHelper::getContext());
     $search = $attributeManager->createSearch();
     $conditions = array($search->compare('==', 'attribute.domain', 'product'), $search->combine('||', array($search->combine('&&', array($search->compare('==', 'attribute.code', 'xs'), $search->compare('==', 'attribute.type.code', 'size'))), $search->combine('&&', array($search->compare('==', 'attribute.code', 'white'), $search->compare('==', 'attribute.type.code', 'color'))))));
     $search->setConditions($search->combine('&&', $conditions));
     $attributes = $attributeManager->searchItems($search);
     if (($attribute = reset($attributes)) === false) {
         throw new \Exception('No attributes available');
     }
     $this->object->addProduct($item->getId(), 1, array(), array(), array_keys($attributes));
     $this->object->editProduct(0, 4);
     $item = $this->object->get()->getProduct(0);
     $this->assertEquals(2, count($item->getAttributes()));
     $this->assertEquals(4, $item->getQuantity());
     $this->object->editProduct(0, 3, array(), array($attribute->getType()));
     $item = $this->object->get()->getProduct(0);
     $this->assertEquals(3, $item->getQuantity());
     $this->assertEquals(1, count($item->getAttributes()));
     $this->assertEquals('U:TESTPSUB01', $item->getProductCode());
 }
Beispiel #24
0
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('\\Aimeos\\MShop\\Exception');
     \Aimeos\MShop\Attribute\Manager\Factory::createManager(\TestHelperMShop::getContext(), 'unknown');
 }
 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));
 }
 /**
  * Returns the attribute list type IDs for the given data sets
  *
  * @param array $data Associative list of identifiers as keys and data sets as values
  * @return array Associative list of identifiers as keys and list type IDs as values
  */
 protected function getAttributeListTypeIds(array $data)
 {
     $manager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($this->additional, 'Standard');
     $listManager = $manager->getSubManager('lists', 'Standard');
     $listTypeManager = $listManager->getSubManager('type', 'Standard');
     $listItemTypeIds = array();
     $listItemType = $listTypeManager->createItem();
     foreach ($data as $key => $dataset) {
         $listItemType->setId(null);
         $listItemType->setCode($dataset['code']);
         $listItemType->setDomain($dataset['domain']);
         $listItemType->setLabel($dataset['label']);
         $listItemType->setStatus($dataset['status']);
         $listTypeManager->saveItem($listItemType);
         $listItemTypeIds[$key] = $listItemType->getId();
     }
     return $listItemTypeIds;
 }
 public function testCopyFrom()
 {
     $attrManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager(\TestHelperMShop::getContext());
     $items = $attrManager->searchItems($attrManager->createSearch());
     if (($item = reset($items)) === false) {
         throw new \Exception('No attribute item found');
     }
     $return = $this->object->copyFrom($item);
     $this->assertInstanceOf('\\Aimeos\\MShop\\Order\\Item\\Base\\Product\\Attribute\\Iface', $return);
     $this->assertEquals($item->getId(), $this->object->getAttributeId());
     $this->assertEquals($item->getLabel(), $this->object->getName());
     $this->assertEquals($item->getType(), $this->object->getCode());
     $this->assertEquals($item->getCode(), $this->object->getValue());
 }
Beispiel #28
0
 public function testSearchItemsAttribute()
 {
     $context = $this->context;
     $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager($context);
     $search = $attributeManager->createSearch();
     $conditions = array($search->compare('==', 'attribute.label', '29'), $search->compare('==', 'attribute.editor', $this->editor), $search->compare('==', 'attribute.type.domain', 'product'), $search->compare('==', 'attribute.type.code', 'width'));
     $search->setConditions($search->combine('&&', $conditions));
     $result = $attributeManager->searchItems($search);
     if (($attrWidthItem = reset($result)) === false) {
         throw new \Exception('No attribute item found');
     }
     $expr = array($search->compare('==', 'attribute.label', '30'), $search->compare('==', 'attribute.editor', $this->editor), $search->compare('==', 'attribute.type.domain', 'product'), $search->compare('==', 'attribute.type.code', 'length'));
     $search->setConditions($search->combine('&&', $expr));
     $result = $attributeManager->searchItems($search);
     if (($attrLenItem = reset($result)) === false) {
         throw new \Exception('No attribute item found');
     }
     $total = 0;
     $search = $this->object->createSearch();
     $search->setSlice(0, 1);
     $conditions = array($search->compare('==', 'index.attribute.id', $attrWidthItem->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(3, $total);
     $expr = array($search->compare('!=', 'index.attribute.id', null), $search->compare('!=', 'index.catalog.id', null), $search->compare('==', 'product.editor', $this->editor));
     $search->setConditions($search->combine('&&', $expr));
     $result = $this->object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(6, $total);
     $attrIds = array((int) $attrWidthItem->getId(), (int) $attrLenItem->getId());
     $func = $search->createFunction('index.attributecount', array('variant', $attrIds));
     $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(2, $total);
     $func = $search->createFunction('index.attribute.code', array('default', 'size'));
     $expr = array($search->compare('!=', 'index.catalog.id', null), $search->compare('~=', $func, 'x'), $search->compare('==', 'product.editor', $this->editor));
     $search->setConditions($search->combine('&&', $expr));
     $result = $this->object->searchItems($search, array(), $total);
     $this->assertEquals(1, count($result));
     $this->assertEquals(3, $total);
 }