/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Productcategory;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['Productcategory']))
{
$model->attributes=$_POST['Productcategory'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}

$this->render('create',array(
'model'=>$model,
));
}
 public function saveAddCategory()
 {
     $catsArray = json_decode(Input::get('category'));
     $brand_id = Input::get('brand_id');
     $cat_type = Input::get('cat_type');
     if (!empty($catsArray)) {
         //We fetch the name of categories under that brand
         $brandModel = Brand::find($brand_id);
         $brandCat = $brandModel->categories->lists('name');
         $brandName = $brandModel->name;
         $tempStoreCatsForLog['cats'] = array();
         foreach ($catsArray as $category) {
             //We check if the new category existed in the list of categories under the brand
             if (in_array($category, $brandCat)) {
                 $data['status'] = 'error';
                 $data['message'] = $category . ' already exist';
             } else {
                 $cat = new Productcategory();
                 $cat->name = strtolower(trim(extract_char($category, array('text', 'int'))));
                 $cat->brand_id = $brand_id;
                 $cat->type = $cat_type;
                 $tempStoreCatsForLog['cats'][] = $cat->name;
                 if (!$cat->save()) {
                     $data = $cat->validatorStatus;
                 } elseif (empty($data)) {
                     $data['status'] = 'success';
                     $data['message'] = 'Created successfully';
                 }
             }
         }
         if (!empty($tempStoreCatsForLog['cats'])) {
             //Log area
             $log['products'] = "[ {$brandName} ] = " . implode(' | ', $tempStoreCatsForLog['cats']);
             $log['stocktype'] = 'create';
             $this->_saveActivityLog($log);
         }
     } else {
         $data['status'] = 'error';
         $data['message'] = 'Field can not be empty';
     }
     return Response::json($data);
 }
 function __construct()
 {
     adminGateKeeper();
     $short_name = getInput("short_name");
     $label = getInput("label");
     $description = getInput("description");
     $hidden = getInput("hidden");
     if ($hidden == 0) {
         $hidden = false;
     } else {
         $hidden = true;
     }
     $product_category = new Productcategory();
     $product_category->short_name = $short_name;
     $product_category->label = $label;
     $product_category->description = $description;
     $product_category->hidden = $hidden;
     $product_category->save();
     new SystemMessage("Your product category has been saved.");
     forward("store");
 }
Ejemplo n.º 4
0
    public function saveOrUpdatePrdprcCat($model, $extcatid = null, $newcatid)
    {
        $product_id = $model->product_id;
        $productprice_id = $model->id;
        $result = array();
        if(!empty($extcatid))
        {
            $condition = 'product_id=' . $product_id;
            $condition .= ' AND productprice_id = ' . $productprice_id;
            $condition .= ' AND category_id = ' . $extcatid;

            $criteria = new CDbCriteria;
            $criteria->select = array( 'id' );
            $criteria->condition = $condition;
            $result = Productcategory::model()->findAll( $criteria );   
        }
        if(count($result) > 0)
        {
            $prdcat = Productcategory::model()->findByPk( $result[0]->id );
        }
        else
        {
            $prdcat = new Productcategory;
        }
        $prdcat->product_id = $product_id;
        $prdcat->productprice_id = $productprice_id;
        $prdcat->category_id = $newcatid;
        $rtn = $prdcat->save();
        if(!$rtn)
        {
            $this->msg = $prdcat->getErrors();
        }
        return $rtn;
    }
Ejemplo n.º 5
0
 public static function syncCat($categories)
 {
     e($categories);
     foreach ($categories as $category) {
         $cat = Productcategory::model()->findByPk($category->id);
         if (!$cat) {
             $cat = new Productcategory();
             $cat->id = $category->id;
         }
         $cat->name = $category->name;
         $cat->desc = $category->cat_descp;
         $cat->type = $category->pid;
         if ($cat->save()) {
             DynamicCall::syncProd($cat->id, $category->pid);
         }
     }
 }
Ejemplo n.º 6
0
 public static function syncSubCat($catid, $oid)
 {
     $url = 'http://mccreative.jaspersonline.co.uk/api/products/getSubMenus/' . $catid . '/' . $oid;
     $results = self::getData($url);
     //        e($results);
     if (!$results->count) {
         return false;
     }
     $ii = 1;
     //        e($results->data);
     foreach ($results->data as $result) {
         $subcat = Productcategory::model()->findByPk($oid . $result->id);
         if (!$subcat) {
             $subcat = new Productcategory();
             $subcat->id = $oid . $result->id;
         }
         $subcat->jaspers_id = $result->id;
         $subcat->name = $result->name;
         if (!$subcat->image) {
             $subcat->image = "http://bmsdev.jaspersonline.co.uk/store/products/order_images/{$result->id}.jpg";
         }
         $subcat->desc = $result->description;
         $subcat->type = 0;
         $subcat->sub = $catid;
         $subcat->oid = $oid;
         if ($subcat->save()) {
             //                e($result->id, 0);
             self::syncProd($oid, $result, $subcat);
         }
         //            if ($subcat->save())
         //                self::syncProd($oid, $result, $subcat);
         //            else
         //                e('not saved');
         $ii++;
     }
     //        e('end');
 }