Beispiel #1
0
 public function render()
 {
     $id_product = $this->getPresenter()->getParam('id');
     $this->template->setFile(dirname(__FILE__) . '/pictogram.phtml');
     $this->template->all_files = PictogramModel::getAllFiles();
     $this->template->files = PictogramModel::get($id_product);
     $this->template->id_product = $id_product;
     $this->template->render();
 }
 function add_old(NFORM $form)
 {
     $values = $form->getValues();
     $arr = Tools::getValuesForTable('product', $values);
     if (isset($values['id_product_supplier'])) {
         $arr['id_product_supplier'] = $values['id_product_supplier'];
     }
     $id_product = ProductModel::add($arr);
     $product_lang_row = Tools::getCollum('product_lang');
     $langs = Setting::getLangs();
     foreach ($langs as $l) {
         $lang_val = array();
         foreach ($values as $k => $v) {
             if (strpos($k, CategoryFormControl::$_separator . $l['iso'])) {
                 list($name) = explode(CategoryFormControl::$_separator . $l['iso'], $k);
                 //overi ci je z danej tabulky
                 if (in_array($name, $product_lang_row)) {
                     $lang_val[$name] = $v;
                     //pridanie linky rewrite
                     if ($name == 'link_rewrite' and $v == '') {
                         $lang_val[$name] = NStrings::webalize($values['name' . CategoryFormControl::$_separator . $l['iso']]);
                     }
                 }
             }
         }
         $lang_val += array('id_product' => $id_product, 'id_lang' => $l['id_lang']);
         ProductModel::addProductLang($lang_val);
     }
     //pridaj param
     /*
      * Iba ak je product bez parametrov
      */
     $values['id_product'] = $id_product;
     //		$val_product_param = Tools::getValuesForTable('product_param', $values);
     //		ProductModel::addProductParamValue($val_product_param);
     ProductModel::addProductToCategory($values['id_categories'], $id_product);
     // prepisanie file_node na novy id_category
     dibi::query("UPDATE [file_node] SET id_module = %i", $id_product, "WHERE id_module = 999998 AND type_module = 'product'");
     //prepisanie pictogram
     PictogramModel::addNullToProduct($id_product);
     ProductModel::saveProductAlternative($id_product, $values['product_alternative']);
     //prepisanie product param
     if ($id_product != $this->getId()) {
         dibi::query("UPDATE [product_param] SET id_product = %i", $id_product, "WHERE id_product IS NULL");
     }
     $this->flashMessage(_('Produkt bol prodaný'));
     $s = NEnvironment::getSession("Admin_Eshop");
     $back_url = $s['back_url'];
     if ($back_url != '') {
         $this->redirectUrl($back_url);
     } else {
         $this->redirect('Eshop:default');
     }
 }
Beispiel #3
0
 public function render($id_product = NULL, $show = true, $sale = false)
 {
     $params = NEnvironment::getApplication()->getPresenter()->getParam();
     //NDebug::bardump($params);
     if (isset($params['material'])) {
         $this->material = $params['material'];
     }
     if (isset($params['size'])) {
         $this->size = $params['size'];
     }
     if (isset($params['color'])) {
         $this->color = $params['color'];
     }
     if (isset($params['id_product'])) {
         $this->id_product = $params['id_product'];
     }
     if (isset($params['count'])) {
         $this->count = (int) $params['count'];
     }
     if ($id_product != NULL) {
         $this->id_product = $id_product;
     }
     $id_lang = $this->getPresenter()->id_lang;
     $template = $this->template;
     $template->setFile(dirname(__FILE__) . '/Product.phtml');
     $template->l = ProductModel::get($this->id_product, $id_lang);
     $lowest_price_product_param = dibi::fetchSingle("SELECT id_product_param FROM [product_param] WHERE id_product = %i", $this->id_product, "ORDER BY price LIMIT 1");
     $template->l['price_array'] = ProductModel::getPrice($lowest_price_product_param);
     if ($show) {
         $template->images = ProductModel::getImages($this->id_product);
         $template->files = ProductModel::getFiles($this->id_product);
         $template->product_alternative = ProductModel::getProductAlternative($this->id_product);
         // prepocitavanie
         $this->template->id_product = $this->id_product;
         $product_params = ProductModel::getProductParamFluent($this->id_product)->orderBy('price')->fetchAll();
         //		print_r($this->template->product_params);exit;
         //zisti ktore sltpce su vyplnene
         $this->template->param = array();
         //zisti pre moznosti pre material ak neni zisti pre velkost ak neni zisti pre farbu
         foreach ($product_params as $k => $p) {
             if ($p['material'] != '') {
                 $this->template->param['material'][$p['material']] = $p['material'];
             }
             if ($p['size'] != '') {
                 $this->template->param['size'][$p['size']] = $p['size'];
             }
             if ($p['color'] != '') {
                 $this->template->param['color'][$p['color']] = $p['color'];
             }
         }
         if (isset($this->template->param['material'])) {
             reset($this->template->param['material']);
             if ($this->material == NULL or !isset($this->template->param['material'][$this->material])) {
                 $this->material = key($this->template->param['material']);
             }
         }
         if (isset($this->template->param['size'])) {
             reset($this->template->param['size']);
             $this->template->param['size'] = dibi::query("SELECT size FROM [product_param] WHERE %if", $this->material != NULL, "material = %s", $this->material, "AND %end id_product = %i", $this->id_product, "AND size != ''")->fetchPairs('size', 'size');
             if ($this->size == NULL or !isset($this->template->param['size'][$this->size])) {
                 $this->size = key($this->template->param['size']);
             }
             usort($this->template->param['size'], 'EshopProductControl::cmp');
             //				print_r($this->template->param['size']);
         }
         if (isset($this->template->param['color'])) {
             reset($this->template->param['color']);
             $this->template->param['color'] = dibi::query("SELECT color FROM [product_param] WHERE %if", $this->material != NULL, "material = %s", $this->material, "AND %end %if", $this->size != NULL, "size = %s", $this->size, "AND %end id_product = %i", $this->id_product, "AND color!=''")->fetchPairs('color', 'color');
             if ($this->color == NULL or !isset($this->template->param['color'][$this->color])) {
                 $this->color = key($this->template->param['color']);
             }
         }
         //			zisti id_product_param
         $product = dibi::fetch("\n\t\t\t\tSELECT\n\t\t\t\t\t*, COUNT(*) as c\n\t\t\t\tFROM\n\t\t\t\t\t[product_param]\n\t\t\t\tWHERE 1=1 %if", $this->material != NULL, "AND material = %s", $this->material, "%end\n\t\t\t\t\t%if", $this->size != NULL, "AND size = %s", $this->size, "%end\n\t\t\t\t\t%if", $this->color != NULL, "AND color = %s", $this->color, "%end\n\t\t\t\t\tAND id_product = %i", $this->id_product, "LIMIT 1");
         $this->template->id_product_param = $product['id_product_param'];
         $this->template->price = ProductModel::getPrice($product['id_product_param']);
         $this->template->sql = dibi::$sql;
         $this->template->pictograms = PictogramModel::get($this->id_product);
         //FEATURES - zobrazenie pre sekciu MATRACE link na potahove latky
         $categories = ProductModel::getProductCategories($this->id_product);
         $pom = array();
         foreach ($categories as $c) {
             $pom[] = $c['id_category'];
         }
         if (in_array('2', $pom) or in_array('3', $pom)) {
             $this->template->show_link_potahove_latky = 1;
         }
         //FEATURES - zobrazenie pre sekciu POSTELE
         $pom = array();
         foreach ($categories as $c) {
             $pom[] = $c['id_category'];
         }
         if (in_array('45', $pom)) {
             $this->template->show_different_name_for_postele = 1;
         }
     } else {
         $template->setFile(dirname(__FILE__) . '/ProductAnnotation.phtml');
         $template->image = self::getImage($this->id_product);
         //			$categories = $this->getPresenter()->getParam('categories');
         //
         //			if($categories=='' OR $categories=='novinky'){
         //
         //				$pom = ProductModel::getProductCategories($id_product);
         //				$pom = current($pom);
         //				$categories = CategoryModel::getUrl($pom['id_category']);
         //			}
         $pom = ProductModel::getProductCategories($id_product);
         //			print_r($pom);
         $pom = end($pom);
         $categories = CategoryModel::getUrl($pom['id_category']);
         $template->l['url'] = $this->getPresenter()->link('Eshop:current', array('categories' => $categories, 'url_identifier' => $template->l['link_rewrite']));
     }
     //		var_dump();
     if ($sale) {
         $params = dibi::fetch("SELECT *  FROM [product_param] WHERE id_product = %i", $this->id_product);
         $template->l['size'] = $params->size;
         $template->l['material'] = $params->material;
         $template->l['color'] = $params->color;
         $template->l['stock'] = $params->stock;
     }
     $template->render();
 }