public function testExportXLSFile() { $this->_object = new Controller_ExtJS_Attribute_Export_Text_Default($this->_context); $manager = 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 Exception('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()); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_editor = TestHelper::getContext()->getEditor(); $attributeManager = MShop_Attribute_Manager_Factory::createManager(TestHelper::getContext()); $attributeListManager = $attributeManager->getSubManager('list'); $this->_object = $attributeListManager->getSubManager('type'); }
/** * Returns required attribute item ids. * * @param array $keys List of keys for search * @return array $refIds List with referenced Ids * @throws MW_Setup_Exception If no type ID is found */ protected function _getAttributeData(array $keys) { $attributeManager = MShop_Attribute_Manager_Factory::createManager($this->_additional, 'Default'); $attributeTypeManager = $attributeManager->getSubManager('type', 'Default'); $codes = $typeCodes = $domains = array(); foreach ($keys as $dataset) { $exp = explode('/', $dataset); if (count($exp) != 4) { throw new 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; }
/** * Initializes the product list type controller. * * @param MShop_Context_Item_Interface $context MShop context object */ public function __construct(MShop_Context_Item_Interface $context) { parent::__construct($context, 'Attribute_List_Type'); $manager = MShop_Attribute_Manager_Factory::createManager($context); $listManager = $manager->getSubManager('list'); $this->_manager = $listManager->getSubManager('type'); }
/** * Adds the attribute test data. * * @param array $testdata Associative list of key/list pairs * @throws MW_Setup_Exception If a required ID is not available */ private function _addAttributeData(array $testdata) { $attributeManager = MShop_Attribute_Manager_Factory::createManager($this->_additional, 'Default'); $attributeTypeManager = $attributeManager->getSubManager('type', 'Default'); $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 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(); }
public function testSaveDeleteItem() { $manager = MShop_Attribute_Manager_Factory::createManager(TestHelper::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'])); }
public function testInjectManagerReset() { $manager = MShop_Attribute_Manager_Factory::createManager($this->_context, 'Default'); MShop_Attribute_Manager_Factory::injectManager('MShop_Attribute_Manager_DefaultMock', $manager); MShop_Attribute_Manager_Factory::injectManager('MShop_Attribute_Manager_DefaultMock', null); $this->setExpectedException('MShop_Exception'); MShop_Attribute_Manager_Factory::createManager($this->_context, 'DefaultMock'); }
public function testExportCSVFile() { $manager = 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 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[158][0]); $this->assertEquals('width', $lines[158][1]); $this->assertEquals('29', $lines[158][2]); $this->assertEquals('default', $lines[158][3]); $this->assertEquals('name', $lines[158][4]); $this->assertEquals('29', $lines[158][6]); }
/** * Adds data for the given language. * * @param MW_Container_Content_Interface $contentItem Content item * @param string $langid Language id * @param array $ids List of of item ids whose texts should be added */ protected function _addLanguage(MW_Container_Content_Interface $contentItem, $langid, array $ids) { $manager = 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()); }
/** * Insert attribute items and product/attribute relations. */ protected function _process() { $this->_msg('Adding product variant attribute performance data', 0); $context = $this->_getContext(); $attrManager = 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 = MShop_Product_Manager_Factory::createManager($context); $productListManager = $productManager->getSubManager('list'); $productListTypeManager = $productListManager->getSubManager('type'); $expr = array(); $search = $productListTypeManager->createSearch(); $expr[] = $search->compare('==', 'product.list.type.domain', 'attribute'); $expr[] = $search->compare('==', 'product.list.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'); }
public function testImportFromXLSFile() { $attributeManager = 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 Exception('Empty id list'); } $params = new stdClass(); $params->lang = array('en'); $params->items = $ids; $params->site = $this->_context->getLocale()->getSite()->getCode(); $exporter = new Controller_ExtJS_Attribute_Export_Text_Default($this->_context); $result = $exporter->exportFile($params); $this->assertTrue(array_key_exists('file', $result)); $filename = substr($result['file'], 9, -14); $this->assertTrue(file_exists($filename)); $filename2 = 'attribute-import.xls'; $phpExcel = PHPExcel_IOFactory::load($filename); if (unlink($filename) !== true) { throw new Exception(sprintf('Deleting file "%1$s" failed', $filename)); } $sheet = $phpExcel->getSheet(0); $sheet->setCellValueByColumnAndRow(6, 2, 'Root: delivery info'); $sheet->setCellValueByColumnAndRow(6, 3, 'Root: long'); $sheet->setCellValueByColumnAndRow(6, 4, 'Root: name'); $sheet->setCellValueByColumnAndRow(6, 5, 'Root: payment info'); $sheet->setCellValueByColumnAndRow(6, 6, 'Root: short'); $objWriter = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel5'); $objWriter->save($filename2); $params = new stdClass(); $params->site = $this->_context->getLocale()->getSite()->getCode(); $params->items = $filename2; $this->_object->importFile($params); if (file_exists($filename2) !== false) { throw new Exception('Import file was not removed'); } $textManager = MShop_Text_Manager_Factory::createManager($this->_context); $criteria = $textManager->createSearch(); $expr = array(); $expr[] = $criteria->compare('==', 'text.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('list'); $criteria = $listManager->createSearch(); $expr = array(); $expr[] = $criteria->compare('==', 'attribute.list.domain', 'text'); $expr[] = $criteria->compare('==', 'attribute.list.refid', $textIds); $criteria->setConditions($criteria->combine('&&', $expr)); $listItems = $listManager->searchItems($criteria); foreach ($listItems as $item) { $listManager->deleteItem($item->getId()); } $this->assertEquals(5, count($textItems)); $this->assertEquals(5, count($listItems)); foreach ($textItems as $item) { $this->assertEquals('Root:', substr($item->getContent(), 0, 5)); } }
public function testCreateManagerNotExisting() { $this->setExpectedException('MShop_Exception'); MShop_Attribute_Manager_Factory::createManager(TestHelper::getContext(), 'unknown'); }
public function testCopyFrom() { $attrManager = 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()); }
/** * Adds the order product attribute test data. * * @param MShop_Common_Manager_Interface $manager * @param array $testdata * @param array $ordProds * @param MShop_Product_Item_Interface[] $products * @throws MW_Setup_Exception */ protected function _addOrderBaseProductAttributeData(MShop_Common_Manager_Interface $manager, array $testdata, array $ordProds, array $products) { $attrCodes = array(); $attributeManager = MShop_Attribute_Manager_Factory::createManager($this->_additional, 'Default'); $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 MW_Setup_Exception(sprintf('No order product ID found for "%1$s"', $dataset['ordprodid'])); } $ordProdAttr->setId(null); $ordProdAttr->setProductId($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); } }
protected function _delete(array $prodcodes, array $delete, array $nondelete) { $catListManager = MShop_Catalog_Manager_Factory::createManager($this->_context)->getSubmanager('list'); $productManager = MShop_Product_Manager_Factory::createManager($this->_context); $listManager = $productManager->getSubManager('list'); foreach ($this->_get($prodcodes, $delete + $nondelete) as $id => $product) { foreach ($delete as $domain) { $manager = 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.list.refid', $id)); $result = $catListManager->searchItems($search); $catListManager->deleteItems(array_keys($result)); } $attrManager = 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)); }
public function testUpdateAttributePriceUpdated() { $context = TestHelper::getContext(); $attrManager = 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 = 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 MShop_Plugin_Provider_Order_ProductPrice($context, $this->_plugin); try { $object->update($this->_order, 'check.after', MShop_Order_Item_Base_Abstract::PARTS_PRODUCT); $this->fail('Price changes not recognized'); } catch (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()); } }
public function testImportFromCSVFile() { $data = array(); $data[] = '"Language ID","Type","Code","List type","Text type","Text ID","Text"' . "\n"; $data[] = '"en","color","white","default","name","","unittest: white"' . "\n"; $data[] = '"en","color","blue","default","name","","unittest: blue"' . "\n"; $data[] = '"en","color","red","default","name","","unittest: red"' . "\n"; $data[] = '"en","size","l","default","name","","unittest: l"' . "\n"; $data[] = '"en","size","xl","default","name","","unittest: xl"' . "\n"; $data[] = '"en","size","xxl","default","name","","unittest: xxl"' . "\n"; $data[] = ' '; $ds = DIRECTORY_SEPARATOR; $csv = 'en-attribute-test.csv'; $filename = PATH_TESTS . $ds . 'tmp' . $ds . 'attribute-import.zip'; if (file_put_contents(PATH_TESTS . $ds . 'tmp' . $ds . $csv, implode('', $data)) === false) { throw new Exception(sprintf('Unable to write test file "%1$s"', $csv)); } $zip = new ZipArchive(); $zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); $zip->addFile(PATH_TESTS . $ds . 'tmp' . $ds . $csv, $csv); $zip->close(); if (unlink(PATH_TESTS . $ds . 'tmp' . $ds . $csv) === false) { throw new Exception('Unable to remove export file'); } $params = new stdClass(); $params->site = $this->_context->getLocale()->getSite()->getCode(); $params->items = $filename; $this->_object->importFile($params); $textManager = MShop_Text_Manager_Factory::createManager($this->_context); $criteria = $textManager->createSearch(); $expr = array(); $expr[] = $criteria->compare('==', 'text.domain', 'attribute'); $expr[] = $criteria->compare('==', 'text.languageid', 'en'); $expr[] = $criteria->compare('==', 'text.status', 1); $expr[] = $criteria->compare('~=', 'text.content', 'unittest:'); $criteria->setConditions($criteria->combine('&&', $expr)); $textItems = $textManager->searchItems($criteria); $textIds = array(); foreach ($textItems as $item) { $textManager->deleteItem($item->getId()); $textIds[] = $item->getId(); } $attributeManager = MShop_Attribute_Manager_Factory::createManager($this->_context); $listManager = $attributeManager->getSubManager('list'); $criteria = $listManager->createSearch(); $expr = array(); $expr[] = $criteria->compare('==', 'attribute.list.domain', 'text'); $expr[] = $criteria->compare('==', 'attribute.list.refid', $textIds); $criteria->setConditions($criteria->combine('&&', $expr)); $listItems = $listManager->searchItems($criteria); foreach ($listItems as $item) { $listManager->deleteItem($item->getId()); } foreach ($textItems as $item) { $this->assertEquals('unittest:', substr($item->getContent(), 0, 9)); } $this->assertEquals(6, count($textItems)); $this->assertEquals(6, count($listItems)); if (file_exists($filename) !== false) { throw new Exception('Import file was not removed'); } }
public function testSearchItemsAttribute() { $context = $this->_context; $attributeManager = 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('==', 'catalog.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('!=', 'catalog.index.attribute.id', null), $search->compare('!=', 'catalog.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('catalog.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('catalog.index.attribute.code', array('default', 'size')); $expr = array($search->compare('!=', 'catalog.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); }
protected function _cleanupAttribute() { $manager = 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()); }
/** * Initializes the attribute controller. * * @param MShop_Context_Item_Interface $context MShop context object */ public function __construct(MShop_Context_Item_Interface $context) { parent::__construct($context, 'Attribute'); $this->_manager = MShop_Attribute_Manager_Factory::createManager($context); }
/** * 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 MW_Setup_Exception If a required ID is not available */ private function _addAttributeListData(array $testdata, array $refIds) { $attributeManager = MShop_Attribute_Manager_Factory::createManager($this->_additional, 'Default'); $attributeTypeManager = $attributeManager->getSubManager('type', 'Default'); $attributeListManager = $attributeManager->getSubManager('list', 'Default'); $attributeListTypeManager = $attributeListManager->getSubManager('type', 'Default'); $codes = $typeCodes = array(); foreach ($testdata['attribute/list'] as $dataset) { $exp = explode('/', $dataset['parentid']); if (count($exp) != 3) { throw new 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/list/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/list'] as $dataset) { if (!isset($parentIds[$dataset['parentid']])) { throw new MW_Setup_Exception(sprintf('No attribute ID found for "%1$s"', $dataset['parentid'])); } if (!isset($listItemTypeIds[$dataset['typeid']])) { throw new MW_Setup_Exception(sprintf('No attribute list type ID found for "%1$s"', $dataset['typeid'])); } if (!isset($refIds[$dataset['domain']][$dataset['refid']])) { throw new MW_Setup_Exception(sprintf('No "%1$s" ref ID found for "%2$s"', $dataset['refid'], $dataset['domain'])); } $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(); }
/** * 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 = TestHelper::getContext()->getEditor(); $this->_object = MShop_Attribute_Manager_Factory::createManager(TestHelper::getContext()); }
public function testSearchItems() { $context = TestHelper::getContext(); $attributeManager = 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('==', 'catalog.index.attribute.id', $attrWidthItem->getId())); $result = $this->_object->searchItems($search, array()); $this->assertGreaterThanOrEqual(1, count($result)); $search = $this->_object->createSearch(); $search->setConditions($search->compare('==', 'catalog.index.attribute.id', $attrLengthItem->getId())); $result = $this->_object->searchItems($search, array()); $this->assertEquals(3, count($result)); $search->setConditions($search->compare('!=', 'catalog.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('catalog.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('catalog.index.attribute.code', array('default', 'size')); $search->setConditions($search->compare('~=', $func, 'x')); $result = $this->_object->searchItems($search, array()); $this->assertEquals(4, count($result)); }
public function testGetBodyAddCustomAttribute() { $attrManager = 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 MW_View_Helper_Parameter_Default($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); }
public function testEditProductAttributes() { $productManager = 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 = 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()); }
protected function _getListItems() { $manager = MShop_Attribute_Manager_Factory::createManager($this->_context, 'Default'); $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.list.parentid', $item->getId()), $search->compare('==', 'attribute.list.domain', 'text'), $search->compare('==', 'attribute.list.editor', $this->_editor), $search->compare('==', 'attribute.list.type.code', 'default')); $search->setConditions($search->combine('&&', $expr)); $search->setSortations(array($search->sort('+', 'attribute.list.position'))); return $this->_object->searchItems($search); }