本文整理汇总了PHP中ProductCategory::save方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductCategory::save方法的具体用法?PHP ProductCategory::save怎么用?PHP ProductCategory::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductCategory
的用法示例。
在下文中一共展示了ProductCategory::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
public function actionCreate()
{
if (Yii::app()->user->checkAccess('createProductCategory') == false) {
throw new CHttpException(403);
}
$category = new ProductCategory('create');
if (isset($_POST['ProductCategory'])) {
$category->attributes = Yii::app()->request->getPost('ProductCategory');
$category->create_time = time();
$category->update_time = time();
$category->sort_order = $category->getMaxSortOrder() + 1;
foreach ($category->brand_id as $key => $value) {
$brandname[] = Brand::model()->findByPk($value)->title;
}
$category->brand_id = implode(',', $category->brand_id);
$category->brand_name = implode(', ', $brandname);
if ($category->validate() && $category->save()) {
$this->setFlashMessage(strtr('<strong>{link}</strong> 产品类型添加成功', array('{link}' => CHtml::link($category->name, array('view', 'id' => $category->primaryKey)))));
$this->redirect($this->getReturnUrl());
}
}
$this->breadcrumbs = array('产品类型' => array('index'), '添加');
$productCategoryOptions = ProductCategory::model()->byBrandOptions(0);
$brandOptions = Brand::model()->getOptions();
$this->render('create', array('category' => $category, 'productCategoryOptions' => $productCategoryOptions, 'brandOptions' => $brandOptions, 'returnUrl' => $this->getReturnUrl()));
}
示例2: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aProductCategoryRelatedByParentId !== null) {
if ($this->aProductCategoryRelatedByParentId->isModified() || $this->aProductCategoryRelatedByParentId->isNew()) {
$affectedRows += $this->aProductCategoryRelatedByParentId->save($con);
}
$this->setProductCategoryRelatedByParentId($this->aProductCategoryRelatedByParentId);
}
if ($this->isNew()) {
$this->modifiedColumns[] = ProductCategoryPeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = ProductCategoryPeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += ProductCategoryPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
if ($this->collProductCategorysRelatedByParentId !== null) {
foreach ($this->collProductCategorysRelatedByParentId as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
if ($this->collProductHasProductCategorys !== null) {
foreach ($this->collProductHasProductCategorys as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例3: executeProductLink
public function executeProductLink(sfWebRequest $request)
{
if ($request->hasParameter("categoryid") && $request->hasParameter("productid")) {
$prodcat = new ProductCategory();
$prodcat->setProductId($request->getParameter("productid"));
$prodcat->setCategoryId($request->getParameter("categoryid"));
$prodcat->save();
cart::update_node($request->getParameter("categoryid"));
return true;
}
}
示例4: actionCreate
public function actionCreate()
{
if (Yii::app()->request->getParam('category', false)) {
$category = new ProductCategory();
$category->attributes = Yii::app()->request->getParam('category', array());
$category->save();
}
if (Yii::app()->request->getParam('backUrl', false)) {
$this->redirect(Yii::app()->createUrl(Yii::app()->request->getParam('backUrl')));
} else {
$this->redirect(Yii::app()->createUrl('/category/index'));
}
}
示例5: createProductCategory
public static function createProductCategory($id = '')
{
$time = mt_rand();
$name = 'SugarProductCategory';
$product = new ProductCategory();
$product->name = $name . $time;
if (!empty($id)) {
$product->new_with_id = true;
$product->id = $id;
}
$product->save();
self::$_createdProductCategories[] = $product;
return $product;
}
示例6: createProductCategoryByName
public static function createProductCategoryByName($name, $parentCategory = null)
{
$productCategory = new ProductCategory();
$productCategory->name = $name;
$productCatalog = new ProductCatalog();
$productCatalog->name = ProductCatalog::DEFAULT_NAME;
$productCatalog->save();
$productCategory->productCatalogs->add($productCatalog);
$saved = $productCategory->save();
if ($parentCategory != null) {
$productCategory->productCategories->add($parentCategory);
}
assert('$saved');
return $productCategory;
}
示例7: actionCreate
public function actionCreate($id = null)
{
$model = new ProductCategory();
if (isset($_POST['ProductCategory'])) {
$model->attributes = $_POST['ProductCategory'];
$model->created = time();
$model->alias = alias($_POST['ProductCategory']['name']);
$model->type = $id;
if ($model->save()) {
Yii::app()->user->setFlash('success', translate('Thêm thành công.'));
$this->redirect(PIUrl::createUrl('/admin/productCategory/index', array('id' => $id)));
}
}
$this->render('create', array('model' => $model));
}
示例8: action_add
public function action_add()
{
$data = array();
if (Request::$method == "POST") {
$cat = new ProductCategory();
$root_id = $_POST['parent_id'];
$post = $cat->validate_create($_POST);
if ($post->check()) {
$post = $post->as_array();
$cat->user_id = Auth::instance()->get_user()->id;
$cat->name = $post['name'];
$cat->slug = $post['slug'];
$cat->meta_keys = $post['meta_keys'];
$cat->meta_desc = $post['meta_desc'];
$cat->save();
//rebuil tree
if ($root_id == 0) {
// if no parent was selected, add/move this node to be a new root in the tree
$categoryTree = ProductCategory::bll()->getTree();
$categoryTree->createRoot($cat);
} else {
$parent = ProductCategory::bll()->findOneBy('id', $root_id);
$cat->getNode()->insertAsLastChildOf($parent);
}
Message::success('Thêm mới danh mục sản phẩm thành công!');
Request::instance()->redirect('/admin/productcategory/index');
} else {
$data['errors'] = $post->errors();
$_POST = $post->as_array();
}
}
$this->template->title = __('Thêm mới danh mục sản phẩm');
$this->template->section_title = __('Thêm mới danh mục sản phẩm');
$q = ProductCategory::bll()->createQuery();
$q->addOrderBy('root_id asc')->addOrderBy('lft asc');
//echo $q->getSqlQuery();
$objects = $q->execute();
///$trees[0] = ' --- ROOT ---';
foreach ($objects as $object) {
$prefix = '|';
if ($object['level'] == 0) {
$prefix = null;
}
$trees[$object['id']] = $prefix . ' ' . str_repeat('- ', $object['level'] * 2) . $object['name'];
}
$data['trees'] = $trees;
$this->template->content = View::factory('admin/product/category/cat_add', $data);
}
示例9: create_category
function create_category($parent_id)
{
global $sugar_demodata;
$last_name_array = $sugar_demodata['last_name_array'];
$last_name_count = count($sugar_demodata['last_name_array']);
$last_name_max = $last_name_count - 1;
$category = new ProductCategory();
$category->name = $last_name_array[mt_rand(0, $last_name_max)] . $sugar_demodata['category_ext_name'];
$category->parent_id = $parent_id;
$key = array_rand($sugar_demodata['users']);
$category->assigned_user_id = $sugar_demodata['users'][$key]['id'];
$category->save();
$cat_id = $category->id;
unset($category);
return $cat_id;
//end function create_category
}
示例10: postNewProduct
/**
* Creates a new product.
*/
public function postNewProduct()
{
// Create the product.
$product = new Product();
$product->name = Input::get('name');
$product->slug = Str::slug(Input::get('name'));
$product->description = Input::get('description');
$product->price = Input::get('price');
$product->save();
// Add the categories.
if (!empty(Input::get('category'))) {
foreach (Input::get('category') as $key => $value) {
$category = new ProductCategory();
$category->product_id = $product->id;
$category->category_id = $key;
$category->save();
}
}
// Redirect to the product media page.
return Redirect::to('/admin/products/' . $product->id . '/media');
}
示例11: actionCreate
public function actionCreate()
{
$this->layout = '/layouts/main_picture';
$pid = Yii::app()->request->getParam('pid', 0);
$model = new ProductCategory();
$model->dpid = $this->companyId;
if ($pid) {
$model->pid = $pid;
}
if (Yii::app()->request->isPostRequest) {
$model->attributes = Yii::app()->request->getPost('ProductCategory');
$category = ProductCategory::model()->find('dpid=:dpid and category_name=:name and delete_flag=0', array(':dpid' => $this->companyId, ':name' => $model->category_name));
if ($category) {
$this->redirect(array('productCategory/index', 'id' => $category->lid, 'companyId' => $this->companyId));
}
$se = new Sequence("product_category");
$model->lid = $se->nextval();
$model->create_at = date('Y-m-d H:i:s', time());
$model->delete_flag = '0';
$model->update_at = date('Y-m-d H:i:s', time());
if ($model->save()) {
//var_dump($model);exit;
$self = ProductCategory::model()->find('lid=:pid and dpid=:dpid', array(':pid' => $model->lid, ':dpid' => $this->companyId));
if ($self->pid != '0') {
$parent = ProductCategory::model()->find('lid=:pid and dpid=:dpid', array(':pid' => $model->pid, ':dpid' => $this->companyId));
$self->tree = $parent->tree . ',' . $self->lid;
} else {
$self->tree = '0,' . $self->lid;
}
//var_dump($model);exit;
$self->update();
Yii::app()->user->setFlash('success', yii::t('app', '添加成功'));
$this->redirect(array('productCategory/index', 'id' => $self->lid, 'companyId' => $this->companyId));
} else {
Yii::app()->user->setFlash('error', yii::t('app', '添加失败'));
$this->redirect(array('productCategory/index', 'companyId' => $this->companyId));
}
}
$this->render('_form1', array('model' => $model, 'action' => $this->createUrl('productCategory/create', array('companyId' => $this->companyId))));
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
if ($this->isAdminRequest()) {
$rules = array('title' => 'required');
$validator = Validator::make(Input::all(), $rules);
// process the login
if ($validator->fails()) {
return Redirect::to('admin/products/create')->withErrors($validator)->with('productcategories', $this->getParents())->withInput(Input::all());
} else {
$productcategory = new ProductCategory();
$productcategory->title = Input::get('title');
$productcategory->short_description = Input::get('short_description');
$productcategory->long_description = Input::get('long_description');
$productcategory->parent_category = Input::get('parent_category');
$productcategory->product_active = Input::get('product_active');
$productcategory->product_features = Input::get('product_features');
$productcategory->save();
// redirect
Session::flash('message', 'Successfully updated ' . Input::get('title'));
return Redirect::to('admin/products');
//return Redirect::route('register.confirm')->with('user', $user->id);
}
}
}
示例13: productSave
protected function productSave($model)
{
$id = $model->id;
if (!empty($model->categories)) {
foreach ($model->categories as $catid) {
$productCategories = new ProductCategory();
$productCategories->product_id = $id;
$productCategories->category_id = $catid;
$productCategories->save();
}
}
if (!empty($model->relatedA)) {
foreach ($model->relatedA as $rid) {
$productRelations = new ProductRelated();
$productRelations->product_id = $id;
$productRelations->related_id = $rid;
$productRelations->save();
}
}
if (!empty($model->stores)) {
foreach ($model->stores as $sid) {
$productStores = new ProductStore();
$productStores->product_id = $id;
$productStores->store_id = $sid;
$productStores->save();
}
}
$productImages = Yii::app()->user->getState('product_images');
if (!empty($productImages)) {
$this->addImages($id, 'ProductImage', 'product_images', 'Product');
}
if (!empty($this->_productoption)) {
foreach ($this->_productoption as $productoption) {
$optionModel = $productoption[0];
$valueModel = $productoption[1];
$optionModel->product_id = $id;
$optionModel->save();
foreach ($valueModel as $value) {
$value->product_option_id = $optionModel->id;
$value->product_id = $id;
$value->option_id = $optionModel->option_id;
$value->save();
}
}
}
if (!empty($this->_productattribute)) {
foreach ($this->_productattribute as $productattribute) {
$productattribute->product_id = $id;
$productattribute->save();
}
}
if (!empty($this->_productdiscount)) {
foreach ($this->_productdiscount as $productdiscount) {
$productdiscount->product_id = $id;
$productdiscount->date_start = date('Y-m-d', strtotime($productdiscount->date_start));
$productdiscount->date_end = date('Y-m-d', strtotime($productdiscount->date_end));
$productdiscount->save();
}
}
if (!empty($this->_productspecial)) {
foreach ($this->_productspecial as $productspecial) {
$productspecial->product_id = $id;
$productspecial->date_start = date('Y-m-d', strtotime($productspecial->date_start));
$productspecial->date_end = date('Y-m-d', strtotime($productspecial->date_end));
$productspecial->save();
}
}
}
示例14: 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);
}
示例15: Shipper
$shipper = new Shipper();
$shipper->name = $v;
$shipper->status = "Active";
$shipper->list_order = $list_order;
$list_order++;
$shipper->save();
$ship_id_arr[] = $shipper->id;
}
echo '.';
foreach ($sugar_demodata['productcategory_seed_data_names'] as $v) {
$category = new ProductCategory();
$category->name = $v;
$category->list_order = "1";
$key = array_rand($sugar_demodata['users']);
$category->assigned_user_id = $sugar_demodata['users'][$key]['id'];
$category->save();
$productcategory_id_arr[] = $category->id;
}
echo '.';
$list_order = 1;
foreach ($sugar_demodata['producttype_seed_data_names'] as $v) {
$type = new ProductType();
$type->name = $v;
$type->list_order = $list_order;
$type->save();
$producttype_id_arr[] = $type->id;
$list_order++;
}
echo '.';
foreach ($sugar_demodata['taxrate_seed_data'] as $v) {
$taxrate = new TaxRate();