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()));
 }
 /**
  * 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
0
 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;
     }
 }
 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'));
     }
 }
 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;
 }
 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;
 }
 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
0
 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);
 }
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
0
 /**
  * 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');
 }
 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))));
 }
 /**
  * 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);
         }
     }
 }
 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();
         }
     }
 }
 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
0
    $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();
 public function saveCategory($id, $name)
 {
     $db = $this->db;
     $newCategory = new ProductCategory();
     $newCategory->setName($name);
     if (0 != $id) {
         $newCategory->setID($id);
         $newCategory->update($db);
     } else {
         $newCategory->save($db);
     }
 }
示例#17
0
 protected function saveProductCategory($productId)
 {
     if (empty($_REQUEST['cat_id']) || empty($productId)) {
         return false;
     }
     $info = Category::model()->findByPk($_REQUEST['cat_id']);
     if (empty($info)) {
         throw new exception('该商品分类不存在!');
     }
     if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) {
         $model = ProductCategory::model()->findByAttributes(array('product_id' => $_REQUEST['id']));
         if (empty($info)) {
             $model = new ProductCategory();
         }
     } else {
         $model = new ProductCategory();
     }
     if ($info['level'] == 1) {
         $one_id = $info['id'];
         $two_id = 0;
     } else {
         $one_id = $info['parent_id'];
         $two_id = $info['id'];
     }
     $model->product_id = $productId;
     $model->one_id = $one_id;
     $model->two_id = $two_id;
     $model->add_time = time();
     $flag = $model->save();
     if (empty($flag)) {
         throw new exception('商品分类信息添加失败!');
     }
     return true;
 }
示例#18
0
<?php

require_once '../productCategory.php';
//from root/model/
$function = $_POST['function'];
$textIn = $_POST['textIn'];
$lvl = $_POST['lvl'];
$lvl1 = $lvl2 = $lvl3 = '';
$lvl1 = @$_POST['lvl1'];
$lvl2 = @$_POST['lvl2'];
$lvl3 = @$_POST['lvl3'];
if ($lvl == 1) {
    $lvl1 = $_POST['textIn'];
}
if ($lvl == 2) {
    $lvl2 = $_POST['textIn'];
}
if ($lvl == 3) {
    $lvl3 = $_POST['textIn'];
}
if ($function == "insert") {
    $newCateg = new ProductCategory($lvl1, $lvl2, $lvl3);
    $newCateg->save();
    echo "the level is =={$lvl1}:{$lvl2}:{$lvl3}== {$newCateg->lvl}";
}
//echo "$function successfully data returned, and the posted value is $textIn, lvl3 is $lvl3";
示例#19
0
文件: Ajax.php 项目: msigley/shopp
 /**
  * Handles Product/Category slug editor
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function edit_slug()
 {
     check_admin_referer('wp_ajax_shopp_edit_slug');
     $defaults = array('slug' => false, 'type' => false, 'id' => false, 'title' => false);
     $p = array_merge($defaults, $_POST);
     extract($p);
     if (false === $slug || false === $id) {
         die('-1');
     }
     switch ($type) {
         case 'category':
             $Category = new ProductCategory($_POST['id']);
             if ($slug == $Category->slug) {
                 die('-1');
             }
             $term = get_term($Category->id, $Category->taxonomy);
             $Category->slug = wp_unique_term_slug(sanitize_title_with_dashes($slug), $term);
             $Category->save();
             echo apply_filters('editable_slug', $Category->slug);
             break;
         case 'product':
             $Product = new ShoppProduct($_POST['id']);
             if ($slug == $Product->slug) {
                 die('-1');
             }
             // Same as before? Nothing to do so bail
             // Regardless of the true post status, we'll pass 'publish' here to ensure we get a unique slug back
             $Product->slug = wp_unique_post_slug(sanitize_title_with_dashes($slug), $Product->id, 'publish', ShoppProduct::posttype(), 0);
             $Product->save();
             echo apply_filters('editable_slug', $Product->slug);
             break;
     }
     exit;
 }