本文整理汇总了PHP中ProductCategory::getByName方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductCategory::getByName方法的具体用法?PHP ProductCategory::getByName怎么用?PHP ProductCategory::getByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductCategory
的用法示例。
在下文中一共展示了ProductCategory::getByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testChildProductCategories
public function testChildProductCategories()
{
$childProductCategory = new ProductCategory();
$childProductCategory->name = "My Test Category Child";
$existingCats = ProductCategory::getByName('My Test Category');
$childProductCategory->productCategory = $existingCats[0];
$this->assertTrue($childProductCategory->save());
$id = $childProductCategory->id;
unset($childProductCategory);
$childProductCategory = ProductCategory::getById($id);
$this->assertEquals("My Test Category Child", $childProductCategory->name);
$this->assertEquals("My Test Category", $existingCats[0]->name);
}
示例2: testSuperUserCreateAction
public function testSuperUserCreateAction()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
Yii::app()->user->userModel = $super;
$this->resetGetArray();
$superCategoryId = self::getModelIdByModelNameAndName('ProductCategory', 'My Category 1');
$productCategory = array();
$productCategory['name'] = 'Red Widget';
$productCategoryParent = array('id' => $superCategoryId);
$productCategory['productCategory'] = $productCategoryParent;
$this->setPostArray(array('ProductCategory' => $productCategory));
$redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/category/create');
$productCategories = ProductCategory::getByName('Red Widget');
$this->assertEquals(1, count($productCategories));
$this->assertTrue($productCategories[0]->id > 0);
$this->assertEquals($superCategoryId, $productCategories[0]->productCategory->id);
$compareRedirectUrl = Yii::app()->createUrl('productTemplates/category/details', array('id' => $productCategories[0]->id));
$this->assertEquals($compareRedirectUrl, $redirectUrl);
}