本文整理汇总了PHP中ProductCategory::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductCategory::getById方法的具体用法?PHP ProductCategory::getById怎么用?PHP ProductCategory::getById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductCategory
的用法示例。
在下文中一共展示了ProductCategory::getById方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateModelData
/**
* Populate Product Template Model with data
* @param Product Template object $model
* @param int $counter
*/
public function populateModelData(&$model, $counter)
{
assert('$model instanceof ProductTemplate');
parent::populateModel($model);
$productTemplateRandomData = self::getProductTemplatesRandomData();
$name = $productTemplateRandomData['names'][$counter];
$productCategoryName = self::getProductCategoryForTemplate($name);
$allCats = ProductCategory::getAll();
foreach ($allCats as $category) {
if ($category->name == $productCategoryName) {
$categoryId = $category->id;
}
}
$productCategory = ProductCategory::getById($categoryId);
$model->name = $name;
$model->productCategories->add($productCategory);
$model->priceFrequency = 2;
$model->cost->value = 200;
$model->listPrice->value = 200;
$model->sellPrice->value = 200;
$model->status = ProductTemplate::STATUS_ACTIVE;
$model->type = ProductTemplate::TYPE_PRODUCT;
$sellPriceFormula = new SellPriceFormula();
$sellPriceFormula->type = SellPriceFormula::TYPE_EDITABLE;
$model->sellPriceFormula = $sellPriceFormula;
}
示例2: resolveProductTemplateHasManyProductCategoriesFromPost
/**
* Resolve the product categories from prost
* @param ProductTemplate $productTemplate
* @param array $postData
* @return array
*/
public static function resolveProductTemplateHasManyProductCategoriesFromPost(ProductTemplate $productTemplate, $postData)
{
$newCategory = array();
if (isset($postData['categoryIds']) && strlen($postData['categoryIds']) > 0) {
$categoryIds = explode(",", $postData['categoryIds']);
// Not Coding Standard
foreach ($categoryIds as $categoryId) {
$newCategory[$categoryId] = ProductCategory::getById((int) $categoryId);
}
if ($productTemplate->productCategories->count() > 0) {
$categoriesToRemove = array();
foreach ($productTemplate->productCategories as $index => $existingCategory) {
$categoriesToRemove[] = $existingCategory;
}
foreach ($categoriesToRemove as $categoryToRemove) {
$productTemplate->productCategories->remove($categoryToRemove);
}
}
//Now add missing categories
foreach ($newCategory as $category) {
$productTemplate->productCategories->add($category);
}
} else {
//remove all categories
$productTemplate->productCategories->removeAll();
}
return $newCategory;
}
示例3: actionEdit
public function actionEdit($id, $redirectUrl = null)
{
$productCategory = ProductCategory::getById(intval($id));
$breadcrumbLinks = static::getDetailsAndEditBreadcrumbLinks();
$breadcrumbLinks[] = StringUtil::getChoppedStringContent(strval($productCategory), 25);
$view = new ProductCategoriesPageView(ProductDefaultViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $this->makeEditAndDetailsView($this->attemptToSaveModelFromPost($productCategory, $redirectUrl), 'Edit'), $breadcrumbLinks, 'ProductBreadCrumbView'));
echo $view->render();
}
示例4: 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);
}
示例5: testSuperUserDeleteAction
public function testSuperUserDeleteAction()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
Yii::app()->user->userModel = $super;
$productCategory = ProductCategoryTestHelper::createProductCategoryByName("My New Category");
//Delete a product template
$this->setGetArray(array('id' => $productCategory->id));
$this->resetPostArray();
$productCategories = ProductCategory::getAll();
$this->assertEquals(14, count($productCategories));
$this->runControllerWithRedirectExceptionAndGetContent('productTemplates/category/delete');
$productCategories = ProductCategory::getAll();
$this->assertEquals(13, count($productCategories));
try {
ProductCategory::getById($productCategory->id);
$this->fail();
} catch (NotFoundException $e) {
//success
}
}