public function addGroup($websiteId, $name, $rootCategoryId) { if (!Mage::helper('M2ePro/Magento_Store_Website')->isExists($websiteId)) { $error = Mage::helper('M2ePro')->__('Website with id %value% does not exist.', (int) $websiteId); throw new Exception($error); } $group = new Mage_Core_Model_Store_Group(); $group->setId(null); $group->setName($name); $group->setWebsiteId($websiteId); $group->setWebsite(Mage::app()->getWebsite($websiteId)); if (isset($rootCategoryId)) { $category = Mage::getModel('catalog/category')->load($rootCategoryId); if (!$category->hasEntityId()) { $error = Mage::helper('M2ePro')->__('Category with %category_id% doen\'t exist', $rootCategoryId); throw new Exception($error); } if ((int) $category->getLevel() !== 1) { $error = Mage::helper('M2ePro')->__('Category of level 1 must be provided.'); throw new Exception($error); } $group->setRootCategoryId($rootCategoryId); } $group->save(); return $group; }
/** * @covers Mage_Core_Model_Website::setGroups * @covers Mage_Core_Model_Website::setStores * @covers Mage_Core_Model_Website::getStores */ public function testSetGroupsAndStores() { /* Groups */ $expectedGroup = new Mage_Core_Model_Store_Group(); $expectedGroup->setId(123); $this->_model->setDefaultGroupId($expectedGroup->getId()); $this->_model->setGroups(array($expectedGroup)); $groups = $this->_model->getGroups(); $this->assertSame($expectedGroup, reset($groups)); /* Stores */ $expectedStore = new Mage_Core_Model_Store(); $expectedStore->setId(456); $expectedGroup->setDefaultStoreId($expectedStore->getId()); $this->_model->setStores(array($expectedStore)); $stores = $this->_model->getStores(); $this->assertSame($expectedStore, reset($stores)); }