Inheritance: extends BaseCategoryDescription
 public function actionCreate()
 {
     $model = new Category();
     $description = new CategoryDescription();
     $image = new XUploadForm();
     $this->performAjaxValidation($model, 'category-form');
     $userImages = array();
     if (!isset($_POST[$this->modelName])) {
         Yii::app()->user->setState('images', NULL);
     }
     if (isset($_POST[$this->modelName])) {
         $model->setAttributes($_POST[$this->modelName]);
         $description->setAttributes($_POST[$this->modelName . 'Description']);
         $suc = Yii::t('info', 'The record was successfully created');
         $err = Yii::t('info', 'The record could not be created');
         $userImages = Yii::app()->user->getState('images');
         if (Yii::app()->user->hasState('images')) {
             $description->category_id = 0;
             $description->locale_code = Yii::app()->getLanguage();
             //$description->link = str_replace(' ','-',trim(strtolower(str_replace('_','-',preg_replace('/(?<![A-Z])[A-Z]/', '\0', $description->name)))));
             $description->link = strtolower(str_replace(' ', '-', preg_replace('!\\s+!', ' ', trim(preg_replace("/[^A-Za-z ]/", ' ', $description->name)))));
             if ($model->validate() && $description->validate()) {
                 if ($model->save()) {
                     $description->category_id = $model->id;
                     $description->save();
                     $this->addImages($model->id, 'Image', 'images', 'Category');
                     Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc);
                     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                         $this->renderPartial('_view', array('model' => $model), false, true);
                         Yii::app()->end();
                     } else {
                         $this->redirect(array('view', 'id' => $model->id));
                     }
                 } else {
                     Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err);
                 }
             } else {
                 $description->validate();
             }
         } else {
             Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, Yii::t('info', 'Please upload an image'));
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form', array('model' => $model, 'description' => $description, 'image' => $image, 'userImages' => $userImages), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'description' => $description, 'image' => $image, 'userImages' => $userImages));
 }
 public function actionAutocomplete($query)
 {
     $json = array();
     // TODO: add locale
     $language_id = 1;
     $descriptions = CategoryDescription::model()->findAll("name LIKE '%{$query}%' AND language_id={$language_id}");
     foreach ($descriptions as $description) {
         $json[] = array('id' => $description->category_id, 'value' => $description->category->getFullname());
     }
     echo CJSON::encode($json);
 }
Example #3
0
 public function actionIndex()
 {
     if (isset($_POST['deleteVariationID'])) {
         $session = new CHttpSession();
         $session->open();
         $aOrderVariations = $session['orderVariations'];
         unset($aOrderVariations[$_POST['deleteVariationID']]);
         $session['orderVariations'] = $aOrderVariations;
         echo 'success';
         exit;
     }
     /** @var $cs CClientScript */
     $cs = Yii::app()->clientScript;
     $cs->registerCssFile(Yii::app()->baseUrl . '/js/plugins/maximage/jquery.maximage.min.css');
     Yii::app()->clientScript->registerCoreScript('jquery.ui');
     Yii::app()->clientScript->registerCssFile(Yii::app()->clientScript->getCoreScriptUrl() . '/jui/css/base/jquery-ui.css');
     $cs->registerScriptFile(Yii::app()->baseUrl . '/js/plugins/maximage/jquery.maximage.min.js');
     $cs->registerScriptFile(Yii::app()->baseUrl . '/js/plugins/maximage/jquery.cycle.all.js');
     $cs->registerScriptFile(Yii::app()->baseUrl . '/js/plugins/jquery.easing.1.3.js');
     $cs->registerScriptFile(Yii::app()->baseUrl . '/js/catalog.min.js');
     $cs->registerScriptFile(Yii::app()->baseUrl . '/js/custom.js');
     $cs->registerCssFile(Yii::app()->baseUrl . '/js/plugins/to_ui_slider/css/ui.slider.extras.css');
     $cs->registerScriptFile(Yii::app()->baseUrl . '/js/plugins/to_ui_slider/js/selectToUISlider.jQuery.js');
     $session = new CHttpSession();
     $session->open();
     if (isset($session['orderVariations']) && is_array($session['orderVariations']) && count($session['orderVariations']) > 0) {
         $aOrderVariations = $session['orderVariations'];
         $aReadyVariations = array();
         foreach ($aOrderVariations as $variation_id) {
             $Product2variation = Product2variation::model()->find('variation_id=' . $variation_id);
             if (isset($Product2variation)) {
                 $product = ProductDescription::model()->find('product_id=' . $Product2variation['product_id'] . ' AND language_id=' . $this->language_id);
                 $category2product = Category2product::model()->find('product_id=' . $Product2variation['product_id']);
                 $category = CategoryDescription::model()->find('category_id=' . $category2product['category_id'] . ' AND language_id=' . $this->language_id);
                 $Variation = Variation::model()->find('variation_id=' . $variation_id);
                 $VariationDescription = VariationDescription::model()->find('variation_id=' . $variation_id . ' AND language_id=' . $this->language_id);
                 $aReadyVariations[$variation_id]['variation_image'] = $Variation['variation_image'];
                 $aReadyVariations[$variation_id]['variation_description'] = $VariationDescription['variation_description'];
                 $aReadyVariations[$variation_id]['product_name'] = $product['product_name'];
                 $aReadyVariations[$variation_id]['variation_name'] = $VariationDescription['variation_name'];
                 $aReadyVariations[$variation_id]['category_name'] = $category['category_name'];
             } else {
                 $aReadyVariations[$variation_id]['variation_image'] = 'no_image.jpg';
                 $aReadyVariations[$variation_id]['product_name'] = '';
                 $aReadyVariations[$variation_id]['variation_name'] = Yii::t('strings', "No longer exist");
             }
         }
     }
     $this->render('cart', array('aReadyVariations' => $aReadyVariations));
 }
Example #4
0
 public function get_index($cat = '', $alias = '')
 {
     //Filtering the Attribute groups for product specific
     if (empty($alias)) {
     }
     $prod = Product::with(array('getCategory', 'getCategory.getDescriptions'))->where('alias', '=', $cat)->first();
     $cat = $prod->getCategory[0]->getDescriptions->alias;
     $alias = $prod->alias;
     $category_id = CategoryDescription::with('getCategory')->where('alias', '=', $cat)->only('id');
     $result = Category::with(array("getDescriptions", "getTopCat", "getTopCat.getDescriptions", "getProducts" => function ($query) use($alias) {
         $query->where('alias', '=', $alias);
     }, "getProducts.getBrand", "getProducts.getImages", "getProducts.getDetail", "getProducts.getTax", "getProducts.getDiscount", "getProducts.getAttributes", "getProducts.getShipment", "getAttributeListing", "getAttributeListing.getTopGroup"))->where('id', '=', $category_id)->first();
     Title::put($result->getProducts[0]->getDetail->name);
     /*Get attributes*/
     $topGroups = array();
     foreach ($result->getAttributeListing as $item) {
         array_push($topGroups, $item->getTopGroup->id);
     }
     $topGroups = array_unique($topGroups);
     $groups = array();
     foreach ($result->getAttributeListing as $item) {
         array_push($groups, $item->id);
     }
     $groups = array_unique($groups);
     $belongedGroups = array();
     foreach ($result->getProducts[0]->getAttributes as $item) {
         array_push($belongedGroups, $item->id);
     }
     $attrs = AttributeGroup::with(array('getParentGroup' => function ($query) use($groups) {
         $query->order_by('sort_order', 'desc');
         $query->where_in('id', $groups);
     }, 'getParentGroup.getAttributes' => function ($query) use($belongedGroups) {
         $query->where_in('id', $belongedGroups);
     }))->where_in('id', $topGroups)->get();
     return View::make('products.index')->with('product', $result)->with('attrs', $attrs);
 }
Example #5
0
 public function get_index($alias)
 {
     //We need Category ID for grabbing products
     $category_id = CategoryDescription::with('getCategory')->where('alias', '=', $alias)->only('id');
     if ($category_id == null) {
         return \Laravel\Redirect::to('/');
     }
     //getting the products which belongs to this category!
     $data = Input::all();
     //Category attrs for filters.
     $catAttr = Category::with(array("getAttributeListing", "getAttributeListing.getAttributes"))->where('id', '=', $category_id)->first();
     $filter = array();
     if (isset($data['Filter'])) {
         foreach ($data['Filter'] as $cLine) {
             $kvp = explode('[-]', $cLine);
             // [0] = Enerji Sınıfı , [1] = A++
             $groupID = 0;
             $attrID = 0;
             foreach ($catAttr->getAttributeListing as $item) {
                 if ($kvp[0] === $item->name) {
                     $groupID = $item->id;
                     foreach ($item->getAttributes as $item2) {
                         if ($kvp[1] === $item2->value) {
                             $attrID = $item2->id;
                             $filter[$kvp[0]] = array("val" => $kvp[1], "id" => $attrID, 'GID' => $groupID);
                         }
                     }
                 }
             }
         }
     }
     $price_range = array();
     if (isset($data['Price_Range'])) {
         $price_range = explode(' - ', $data['Price_Range']);
         if ($price_range[0] == "2500TL ve üzeri") {
             $price_range[0] = 2500;
             $price_range[1] = 999999;
         }
     }
     $countforCache = Category::with('getProducts')->where('id', '=', $category_id)->first()->getProducts()->count();
     if (Cache::has('category.products.' . $category_id)) {
         $a = Cache::get('category.products.' . $category_id);
         $a = count($a->getProducts);
         if ($a !== $countforCache) {
             Cache::forget('category.products.' . $category_id);
         }
     }
     if (!Cache::has('category.products.' . $category_id)) {
         $result = Category::with(array("getProducts", "getProducts.getDetail", "getProducts.getBrand", "getProducts.getImages", "getProducts.getTax", "getProducts.getDiscount", "getProducts.getAttributes", "getChildren", "getChildren.getDescriptions", "getChildren.getProducts", "getSlideshow", "getSlideshow.getItems", "getAttributeListing", "getAttributeListing.getAttributes", "getAttributeListing.getAttributes.productSpecific"))->where('id', '=', $category_id)->first();
         Cache::forever('category.products.' . $category_id, $result, 3);
     }
     $result = Cache::get('category.products.' . $category_id);
     $products = array();
     $attributes = array();
     $brands = array();
     $price = array();
     $range = array();
     if (isset($filter)) {
         foreach ($result->getProducts as $product) {
             $mami = array();
             $prodPrice = getItemPrice($product)->tax_raw;
             foreach ($product->getAttributes as $mam) {
                 $mami[] = $mam->id;
             }
             $invalid = FALSE;
             foreach ($filter as $filtresingle) {
                 if (array_search($filtresingle['id'], $mami) === FALSE) {
                     $invalid = TRUE;
                     break;
                 }
             }
             if ($invalid == FALSE) {
                 //check for price range!
                 if (!empty($price_range)) {
                     if ($prodPrice > $price_range[0] && $prodPrice <= $price_range[1]) {
                         $brands[] = $product->getBrand->name;
                         $price[] = getItemPrice($product)->tax_raw;
                         foreach ($product->getAttributes as $attribute) {
                             array_push($attributes, $attribute->id);
                         }
                         array_push($products, $product);
                     }
                 } else {
                     $brands[] = $product->getBrand->name;
                     $price[] = getItemPrice($product)->tax_raw;
                     foreach ($product->getAttributes as $attribute) {
                         array_push($attributes, $attribute->id);
                     }
                     array_push($products, $product);
                 }
             } else {
             }
         }
     }
     if ($price != null) {
         $price = PriceRange::create($price);
     }
     if ($brands != null) {
         $brands = array_unique($brands);
     }
     $attributes = array_count_values($attributes);
     $attrgroup = array();
     foreach ($result->getAttributeListing as $groups) {
         foreach ($groups->getAttributes as $attr) {
             if (array_key_exists($attr->id, $attributes)) {
                 array_push($attrgroup, $groups->id);
             }
         }
     }
     Title::put($result->getDescriptions->name . ' Kategorisi');
     return View::make('category.index')->with('result', $result)->with('brands', $brands)->with('products', $products)->with('filters', $filter)->with('attribute_filter', $attributes)->with('ranges', $price)->with('selected_ranges', $price_range);
 }
Example #6
0
    public function actionDelete($id)
    {
        $this->loadModel($id)->delete();
        CategoryDescription::model()->deleteAll('category_id=' . $id);

        // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
        if (!isset($_GET['ajax']))
            $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
    }
Example #7
0
 public function afterDelete()
 {
     // delete children
     $children = Category::model()->findAll("parent_id={$this->cacheId}");
     foreach ($children as $child) {
         $child->delete();
     }
     // delete dependencies
     CategoryPath::model()->deleteAll("category_id={$this->cacheId}");
     CategoryDescription::model()->deleteAll("category_id={$this->cacheId}");
     CategoryFilter::model()->deleteAll("category_id={$this->cacheId}");
     CategoryToStore::model()->deleteAll("category_id={$this->cacheId}");
     CategoryToLayout::model()->deleteAll("category_id={$this->cacheId}");
     ProductToCategory::model()->deleteAll("category_id={$this->cacheId}");
     UrlAlias::model()->deleteAll("query='category_id={$this->cacheId}'");
     parent::afterDelete();
 }
Example #8
0
 public function save()
 {
     $category = Category::model()->findByPk($this->id);
     if (is_null($category)) {
         // insert
         // Category
         $category = new Category();
         $category->date_added = date('Y-m-d');
         $category->date_modified = date('Y-m-d');
         $category->image = $this->image;
         $category->top = $this->top;
         $category->column = $this->columns;
         $category->sort_order = $this->sortOrder;
         $category->status = $this->status;
         $category->parent_id = $this->parent;
         $category->save();
         // Description
         $description = new CategoryDescription();
         $description->category_id = $category->category_id;
         $description->language_id = 1;
         // TODO: language must be dynamic
         $description->name = $this->name;
         $description->meta_description = $this->metaTagDescription;
         $description->meta_keyword = $this->metaTagKeywords;
         $description->description = $this->description;
         $description->save();
     } else {
         // update
         // Category
         $category->date_modified = date('Y-m-d');
         $category->image = $this->image;
         $category->top = $this->top;
         $category->column = $this->columns;
         $category->sort_order = $this->sortOrder;
         $category->status = $this->status;
         $category->parent_id = $this->parent;
         $category->save();
         // Description
         $category->description->name = $this->name;
         $category->description->meta_description = $this->metaTagDescription;
         $category->description->meta_keyword = $this->metaTagKeywords;
         $category->description->description = $this->description;
         $category->description->save();
     }
     // SEO keyword
     $category->updateSEOKeyword($this->seoKeyword);
     // Stores
     $category->clearAllStoresRelations();
     if (isset($this->stores) && count($this->stores)) {
         foreach ($this->stores as $storeId) {
             $category->addToStore($storeId);
         }
     }
     // Filters
     $category->clearAllFiltersRelations();
     if (isset($this->filters) && count($this->filters) > 0) {
         foreach ($this->filters as $filterId) {
             $category->addFilter($filterId);
         }
     }
 }