本文整理匯總了PHP中app\modules\shop\models\Category::createEmptyCategory方法的典型用法代碼示例。如果您正苦於以下問題:PHP Category::createEmptyCategory方法的具體用法?PHP Category::createEmptyCategory怎麽用?PHP Category::createEmptyCategory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\modules\shop\models\Category
的用法示例。
在下文中一共展示了Category::createEmptyCategory方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createCategory
/**
* @param array $item
* @param int $parentId
* @return int
*/
protected function createCategory($item, $parentId)
{
if (empty($item) || empty($item[static::ELEMENT_ID]) || empty($item[static::ELEMENT_NAIMENOVANIE])) {
return $parentId;
}
$result = $parentId;
if (isset($this->categoryCache[$item[static::ELEMENT_ID]])) {
$result = $this->categoryCache[$item[static::ELEMENT_ID]];
} else {
$guid = CommercemlGuid::findOne(['guid' => $item[static::ELEMENT_ID]]);
if (empty($guid)) {
$guid = new CommercemlGuid();
$guid->guid = $item[static::ELEMENT_ID];
$guid->name = $item[static::ELEMENT_NAIMENOVANIE];
$guid->type = 'CATEGORY';
$guid->model_id = 1;
$category = Category::findOne(['slug' => Helper::createSlug($item[static::ELEMENT_NAIMENOVANIE]), 'parent_id' => $parentId]);
if (empty($category)) {
if (null !== ($category = Category::createEmptyCategory($parentId, null, $item[static::ELEMENT_NAIMENOVANIE]))) {
$guid->model_id = $category->id;
}
} else {
$guid->model_id = $category->id;
}
$guid->save();
$guid->refresh();
$result = $this->categoryCache[$item[static::ELEMENT_ID]] = $guid->model_id;
} else {
$result = $this->categoryCache[$item[static::ELEMENT_ID]] = $guid->model_id;
}
}
return $result;
}