public function testTitle() { Yii::app()->settings->set('core', array('siteName' => microtime())); $this->open('/'); $this->assertEquals(Yii::app()->settings->get('core', 'siteName'), $this->getTitle()); // Find any active product $product = Products::model()->active()->find(); $this->assertTrue($product instanceof Products); // Open product page $this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url))); $this->assertEquals($product->name . ' / ' . Yii::app()->settings->get('core', 'siteName'), $this->getTitle()); }
public static function getPriceTotal() { $price_total = 0; $tax_total = 0; foreach (Shop::getCartContent() as $product) { $model = Products::model()->findByPk($product['product_id']); $price_total += $model->getPrice(@$product['Variations'], @$product['amount']); $tax_total += $model->getTaxRate(@$product['Variations'], @$product['amount']); } if ($shipping_method = Shop::getShippingMethod()) { $price_total += $shipping_method->price; } $price_total = Shop::t('Price total: {total}', array('{total}' => Shop::priceFormat($price_total))); $price_total .= '<br />'; $price_total .= Shop::t('All prices are including VAT: {vat}', array('{vat}' => Shop::priceFormat($tax_total))) . '<br />'; $price_total .= Shop::t('All prices excluding shipping costs') . '<br />'; return $price_total; }
public function actionRefresh() { $department = Department::model()->findAll(); foreach ($department as $val) { $dish = Dishes::model()->findAll('t.department_id = :depId', array(':depId' => $val->department_id)); foreach ($dish as $value) { $this->addDish($value->dish_id, $val->department_id); } $stuff = Halfstaff::model()->findAll('t.department_id = :depId', array(':depId' => $val->department_id)); foreach ($stuff as $value) { $this->addStuff($value->halfstuff_id, $val->department_id); } $prod = Products::model()->findAll('t.department_id = :depId', array(':depId' => $val->department_id)); foreach ($prod as $value) { $this->addProd($value->product_id, $val->department_id); } } $this->redirect(array('site/index')); }
public function run() { if ($this->products === true) { $this->products = Products::model()->findAll('status = 1'); } if (!is_array($this->products)) { $this->products = array($products); } if (!$this->selected) { $this->selected = $this->products[0]->product_id; } $products = array(); foreach ($this->products as $product) { if (is_numeric($product)) { $products[$product] = Products::model()->findByPk($product); } else { $products[$product->product_id] = $product; } } $this->render($this->view, array('selected' => $this->selected, 'ask_for_amount' => $this->ask_for_amount, 'products' => $products)); return parent::run(); }
public function actionUpdateAmount() { $cart = Shop::getCartContent(); foreach ($_GET as $key => $value) { if (substr($key, 0, 7) == 'amount_') { if ($value == '') { return true; } if (!is_numeric($value) || $value <= 0) { throw new CException('Wrong amount'); } $position = explode('_', $key); $position = $position[1]; if (isset($cart[$position]['amount'])) { $cart[$position]['amount'] = $value; } $product = Products::model()->findByPk($cart[$position]['product_id']); echo Shop::priceFormat(@$product->getPrice($cart[$position]['Variations'], $value)); return Shop::setCartContent($cart); } } }
public function actionIndex() { if (isset($_POST['ajax'])) { $slideShows = Slideshow::model()->findAll(); $images = array(); if ($slideShows) { foreach ($slideShows as $slideShow) { $images[] = $slideShow->imageLink; } echo json_encode($images); } } else { $newProducts = NewProducts::model()->findAll(); $hotProducts = HotProducts::model()->findAll(array("limit" => 17)); $amthucs = Amthuc::model()->findAll(array("order" => 'id DESC', "limit" => 4)); if ($newProducts || $hotProducts) { $newProduct = array(); foreach ($newProducts as $newProduct1) { $product = Products::model()->findByPk($newProduct1->product_id); if ($product) { $newProduct[$newProduct1->id] = $product; } } foreach ($hotProducts as $key => $value) { $product = Products::model()->find('id=:product_id', array(':product_id' => $value->product_id)); if ($product) { $products[] = $product; } } if ($newProduct && $products || $amthucs) { $this->render('index', array('newProduct' => $newProduct, 'products' => $products, 'amthucs' => $amthucs)); } else { $this->render('index'); } } } }
public function actionAdmin() { $product = Products::model()->findByPk($_GET['product_id']); $images = $product->images; $this->render('admin', array('images' => $images, 'product' => $product)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. */ public function loadModel() { if ($this->_model === null) { if (isset($_GET['id'])) { $this->_model = Products::model()->findbyPk($_GET['id']); } if (isset($_GET['title'])) { $this->_model = Products::model()->find('title = :title', array(':title' => $_GET['title'])); } if ($this->_model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } } return $this->_model; }
public function getCategoryShops() { if(!empty($this->allmodel)){ foreach($this->allmodel as $c){ $cat[] = $c->id; } $categories = $cat; } else { $categories = $this->model; } $shops = null; if(!Yii::app()->request->getParam('account')) { $cr = new CDbCriteria; $cr->select = 't.user_id, t.name'; $cr->group = 't.user_id'; // $cr->distinct = true; $cr->addCondition('t.user_id IS NOT NULL and t.shop=1'); if(Yii::app()->request->getParam('brand')) { $shops = Products::model() ->active() ->withcity() // ->applyCategories($categories, null) ->applyCategoriesWithSub($categories, null) ->with(array( 'shopmag'=>array( 'with'=>array( 'productsCount'=>array( 'scopes'=>array( 'active', 'withcity', // 'applyCategories'=>array($categories, null), // 'applyCategoriesWithSub'=>array($categories, null), 'applyManufacturers'=>array(Yii::app()->request->getParam('brand')), 'applyAttributes'=>array($this->getOwner()->activeAttributes), 'applyMinPrice'=>array($this->convertCurrency(Yii::app()->request->getQuery('min_price'))), 'applyMaxPrice'=>array($this->convertCurrency(Yii::app()->request->getQuery('max_price'))), ), ) ), ))) ->findAll($cr); } else { $shops = Products::model() ->active() ->withcity() // ->applyCategories($categories, null) ->applyCategoriesWithSub($categories, null) ->with(array( 'shopmag'=>array( 'with'=>array( 'productsCount'=>array( 'scopes'=>array( 'active', 'withcity', // 'applyCategories'=>array($categories, null), // 'applyCategoriesWithSub'=>array($categories, null), // 'applyManufacturers'=>array($this->manufacturers), 'applyAttributes'=>array($this->getOwner()->activeAttributes), 'applyMinPrice'=>array($this->convertCurrency(Yii::app()->request->getQuery('min_price'))), 'applyMaxPrice'=>array($this->convertCurrency(Yii::app()->request->getQuery('max_price'))), )) ), ))) ->findAll($cr); } } $data = array( 'title'=>'Магазин', 'selectMany'=>true, 'filters'=>array() ); if($shops) { foreach($shops as $m) { $m = $m->shopmag; if($m) { $data['filters'][] = array( 'title' => $m->title, 'count' => $m->productsCount, 'queryKey' => 'shop', 'queryParam' => $m->id, // 'url_name'=>$m->url ); } } } return $data; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Products::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function refreshBalance($depId) { $dish = Dishes::model()->findAll('t.department_id = :depId', array(':depId' => $depId)); foreach ($dish as $value) { $this->addDish($value->dish_id, $depId); } $stuff = Halfstaff::model()->findAll('t.department_id = :depId', array(':depId' => $depId)); foreach ($stuff as $value) { $this->addStuff($value->halfstuff_id, $depId); } $prod = Products::model()->findAll('t.department_id = :depId', array(':depId' => $depId)); foreach ($prod as $value) { $this->addProd($value->product_id, $depId); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $products = Products::model()->with('measure')->findAll(array('order' => 't.name')); $curModel = Storage::model()->with('product.measure')->findAll(array('order' => 'product.name')); //if(empty($curModel)){ $model = new Storage(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Storage'])) { if (!empty($curModel)) { $model->deleteAll(); } if ($_POST['Storage']['curDate'] == '') { $_POST['Storage']['curDate'] = date('Y-m-d'); } $transaction = Yii::app()->db->beginTransaction(); try { $messageType = 'warning'; $message = "There are some errors "; foreach ($_POST['product_id'] as $key => $value) { $tempModel = new Storage(); $tempModel->curDate = $_POST['Storage']['curDate']; $tempModel->prod_id = $value; $tempModel->curCount = $this->changeToFloat($_POST['count'][$key]); $tempModel->price = $_POST['price'][$key]; if ($tempModel->save()) { $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully create data "; } } $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); $this->redirect(array('index')); //$model->attributes=$_POST['Storage']; //$uploadFile=CUploadedFile::getInstance($model,'filename'); /*if($model->save()){ $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully create data "; /* $model2 = Storage::model()->findByPk($model->storage_id); if(!empty($uploadFile)) { $extUploadFile = substr($uploadFile, strrpos($uploadFile, '.')+1); if(!empty($uploadFile)) { if($uploadFile->saveAs(Yii::app()->basePath.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.$model2->storage_id.DIRECTORY_SEPARATOR.$model2->storage_id.'.'.$extUploadFile)){ $model2->filename=$model2->storage_id.'.'.$extUploadFile; $model2->save(); $message .= 'and file uploded'; } else{ $messageType = 'warning'; $message .= 'but file not uploded'; } } } $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); $this->redirect(array('view','id'=>$model->storage_id)); } */ } catch (Exception $e) { $transaction->rollBack(); Yii::app()->user->setFlash('error', "{$e->getMessage()}"); //$this->refresh(); } } $this->render('create', array('model' => $model, 'curModel' => $curModel, 'products' => $products)); //} else{ // $this->redirect(array('index')); //} }
/** * This is method for delete Product from list * @param string $id * @return array[] { * 'code':200, * 'message':'SUCCESS' * } */ public function deleteProduct($id) { $result = Products::model()->findByAttributes(array('id' => $id)); $result->status = '0'; if ($result->save()) { $data = array('code' => 200, 'message' => 'SUCCESS'); } return $data; }
public static function getAllComments(CActiveRecord $model) { $users_adv = Products::model() ->active() ->findAllByAttributes(array( 'user_id'=>$model->id )); $ids=array(); foreach($users_adv as $adv): $ids[]=$adv->id; endforeach; // $criteria = new CDbCriteria(); // $criteria->addInCondition("object_pk", $ids); return Comment::model() ->approved() ->orderByCreatedDesc() ->findAllByAttributes(array('object_pk'=>$ids)); }
public function actionCreate() { $products = Products::model()->with('measure')->findAll(); $curModel = DepStorage::model()->with('product.measure')->findAll('t.type = :type', array(':type' => 1)); $model = new DepStorage(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['DepStorage'])) { if (!empty($curModel) && $curModel->department_id == $_POST['DepStorage']['department_id']) { $model->deleteAll(); } if ($_POST['DepStorage']['curDate'] == '') { $_POST['DepStorage']['curDate'] = date('Y-m-d'); } $transaction = Yii::app()->db->beginTransaction(); try { $messageType = 'warning'; $message = "There are some errors"; if (isset($_POST['prod'])) { foreach ($_POST['prod']['product_id'] as $key => $value) { $tempModel = new DepStorage(); $tempModel->curDate = $_POST['DepStorage']['curDate']; $tempModel->prod_id = $value; $tempModel->curCount = $this->changeToFloat($_POST['prod']['count'][$key]); //$tempModel->price = $_POST['price'][$key]; $tempModel->department_id = $_POST['DepStorage']['department_id']; $tempModel->type = 1; if ($tempModel->save()) { $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully create data "; } } } if (isset($_POST['stuff'])) { foreach ($_POST['stuff']['stuff_id'] as $key => $value) { $tempModel = new DepStorage(); $tempModel->curDate = $_POST['DepStorage']['curDate']; $tempModel->prod_id = $value; $tempModel->curCount = $this->changeToFloat($_POST['stuff']['count'][$key]); //$tempModel->price = $_POST['price'][$key]; $tempModel->department_id = $_POST['DepStorage']['department_id']; $tempModel->type = 2; if ($tempModel->save()) { $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully create data "; } } } if (isset($_POST['dish'])) { foreach ($_POST['dish']['dish_id'] as $key => $value) { $tempModel = new DepStorage(); $tempModel->curDate = $_POST['DepStorage']['curDate']; $tempModel->prod_id = $value; $tempModel->curCount = $this->changeToFloat($_POST['dish']['count'][$key]); //$tempModel->price = $_POST['price'][$key]; $tempModel->department_id = $_POST['DepStorage']['department_id']; $tempModel->type = 3; if ($tempModel->save()) { $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully create data "; } } } //$uploadFile=CUploadedFile::getInstance($model,'filename'); $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); //$this->redirect(array('view','id'=>$model->dep_storage_id)); } catch (Exception $e) { $transaction->rollBack(); Yii::app()->user->setFlash('error', "{$e->getMessage()}"); //$this->refresh(); } } $this->render('create', array('model' => $model, 'curModel' => $curModel, 'products' => $products)); }
public function actionPinfo($ID) { $ID = intval($ID); $language = strtoupper(Yii::app()->session->offSetGet("FrontLanguage")); $datas = Products::model()->findByPk($ID); if (empty($datas)) { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } if ($datas['CategoryId']) { $db = Yii::app()->db; $sql = "SELECT * FROM {{category}} WHERE ID={$datas['CategoryId']}"; $Category = $db->createCommand($sql)->queryRow(); //$Categorybs=Category::model()->findByPk($datas['CategoryId']); } $nameCol = $language . 'Name'; $SummaryCol = $language . 'Summary'; $ContentCol = $language . 'Content'; $this->render('pinfo', array('language' => $language, 'datas' => $datas, 'Category' => $Category, 'nameCol' => $nameCol, 'SummaryCol' => $SummaryCol, 'ContentCol' => $ContentCol)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['dish']) or isset($_POST['stuff']) or isset($_POST['product'])) { $transaction = Yii::app()->db->beginTransaction(); try { $messageType = 'warning'; $message = "There are some errors "; foreach ($_POST as $keys => $value) { $message = "<strong>"; if ($keys == 'dish') { foreach ($value['id'] as $key => $val) { $newModel = new Menu(); $newModel->just_id = $val; $newModel->type = 1; $newModel->type_id = $value['type'][$key]; if ($newModel->save()) { $messageType = 'success'; } Dishes::model()->updateByPk($val, array('price' => $value['price'][$key])); $message .= "Блюда"; } } /*if($keys == 'stuff'){ foreach($value['id'] as $key => $val){ echo $value['price'][$key]."<br />"; $newModel = new Menu; $newModel->just_id = $val; $newModel->type = 2; if($newModel->save()) $messageType = 'success'; Halfstaff::model()->updateByPk($val,array('price'=>$value['price'][$key])); $message .= ", Полуфабрикаты"; } }*/ if ($keys == 'product') { foreach ($value['id'] as $key => $val) { $newModel = new Menu(); $newModel->just_id = $val; $newModel->type = 3; $newModel->type_id = $value['type'][$key]; if ($newModel->save()) { $messageType = 'success'; } Products::model()->updateByPk($val, array('price' => $value['price'][$key])); $message .= ", Продукты "; } } } $message .= "Успешно добавлены</strong>"; $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); //$uploadFile=CUploadedFile::getInstance($model,'filename'); /*if($model->save()){ $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully create data "; /* $model2 = Menu::model()->findByPk($model->menu_id); if(!empty($uploadFile)) { $extUploadFile = substr($uploadFile, strrpos($uploadFile, '.')+1); if(!empty($uploadFile)) { if($uploadFile->saveAs(Yii::app()->basePath.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'menu'.DIRECTORY_SEPARATOR.$model2->menu_id.DIRECTORY_SEPARATOR.$model2->menu_id.'.'.$extUploadFile)){ $model2->filename=$model2->menu_id.'.'.$extUploadFile; $model2->save(); $message .= 'and file uploded'; } else{ $messageType = 'warning'; $message .= 'but file not uploded'; } } } $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); $this->redirect(array('view','id'=>$model->menu_id)); } */ } catch (Exception $e) { $transaction->rollBack(); Yii::app()->user->setFlash('error', "{$e->getMessage()}"); //$this->refresh(); } } $this->render('update', array('model' => $model)); }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $products = Products::model()->findAll('category=:category', array(':category' => $id)); $this->render('view', array('model' => $this->loadModel($id), 'products' => $products)); }
public function actionAjaxAllProd() { $halfstuff = new Halfstaff(); $from = $_POST['from']; $to = $_POST['to']; $allOutProd = array(); $products = array(); $prodCount = array(); $prodSumm = array(); $outProdSumm = array(); for ($i = 0; $i <= date('j', strtotime($to)) - date('j', strtotime($from)); $i++) { $dish = new Expense(); $outProduct = array(); $model = Expense::model()->with('order.dish.dishStruct')->findAll('date(t.order_date) = :dates', array(':dates' => date('Y-m-d', strtotime($from) + $i * 3600 * 24))); foreach ($model as $value) { foreach ($value->getRelated('order') as $val) { $curDish[$val->getRelated('dish')->dish_id] = $val->getRelated('dish')->name; $dishCount[$val->getRelated('dish')->dish_id] = $dishCount[$val->getRelated('dish')->dish_id] + $val->count; foreach ($val->getRelated('dish')->getRelated('dishStruct') as $vals) { $products[$vals->prod_id] = $products[$vals->prod_id] + $vals->amount / $val->getRelated('dish')->count * $val->count; } } } $model2 = Expense::model()->with('order.dish.halfstuff')->findAll('date(t.order_date) = :dates', array(':dates' => date('Y-m-d', strtotime($from) + $i * 3600 * 24))); foreach ($model2 as $value) { foreach ($value->getRelated('order') as $val) { $curDish[$val->getRelated('dish')->dish_id] = $val->getRelated('dish')->name; foreach ($val->getRelated('dish')->getRelated('halfstuff') as $vals) { $stuff[$val->getRelated('dish')->dish_id][$vals->halfstuff_id] = $stuff[$val->getRelated('dish')->dish_id][$vals->halfstuff_id] + $vals->amount / $val->getRelated('dish')->count * $val->count; } } } $model3 = Expense::model()->with('order.halfstuff.stuffStruct')->findAll('date(t.order_date) = :dates', array(':dates' => date('Y-m-d', strtotime($from) + $i * 3600 * 24))); foreach ($model3 as $value) { foreach ($value->getRelated('order') as $val) { $curStuff[$val->getRelated('halfstuff')->halfstuff_id] = $val->getRelated('halfstuff')->name; $stuffCount[$val->getRelated('halfstuff')->halfstuff_id] = $dishCount[$val->getRelated('halfstuff')->halfstuff_id] + $val->count; foreach ($val->getRelated('halfstuff')->getRelated('stuffStruct') as $vals) { if ($vals->types == 1) { $products[$vals->prod_id] = $products[$vals->prod_id] + $vals->amount / $val->getRelated('halfstuff')->count * $val->count; } elseif ($vals->types) { $stuff[$val->getRelated('halfstuff')->halfstuff_id][$vals->prod_id] = $stuff[$val->getRelated('halfstuff')->halfstuff_id][$vals->prod_id] + $vals->amount / $val->getRelated('halfstuff')->count * $val->count; } } } } $model6 = Faktura::model()->with('realize')->findAll('date(realize_date) = :dates', array(':dates' => date('Y-m-d', strtotime($from) + $i * 3600 * 24))); foreach ($model6 as $value) { foreach ($value->getRelated('realize') as $val) { $prodCount[$val->prod_id] = $prodCount[$val->prod_id] + $val->count; $prodSumm[$val->prod_id] = $prodSumm[$val->prod_id] + $val->count * $val->price; $outProdSumm[$val->prod_id] = $outProdSumm[$val->prod_id] + $products[$val->prod_id] * $val->price; } } /*foreach (Department::model()->findAll() as $val) { //echo date('Y-m-d',strtotime($from)+($i*3600*24))."<br>"; $outProduct = $halfstuff->sumArray($outProduct,$dish->getDishProd($val->department_id, date('Y-m-d',strtotime($from)+($i*3600*24)))); //$outDishStuff = $dish->getDishStuff($depId,$dates); } $allOutProd = $halfstuff->sumArray($allOutProd,$outProduct);*/ } $prodModel = Products::model()->findAll(array('order' => 'name')); $this->renderPartial('ajaxAllProd', array('prodCount' => $prodCount, 'prodSumm' => $prodSumm, 'prodModel' => $prodModel, 'products' => $products, 'outProdSumm' => $outProdSumm)); }
public function actionGetProdList() { $model = Products::model()->with('measure')->findByPk($_POST['id']); $this->renderPartial('getProdList', array('model' => $model)); }
public function addXLS($file_path) { //$file_path = './upload_dir/test.xls'; $sheet_array = Yii::app()->yexcel->readActiveSheet($file_path); $current_product = null; foreach ($sheet_array as $row) { if ($this->isRowEmpty($row)) { continue; } if ($row['A'] != null && $row['B'] != null) { continue; } if ($row['A'] != null) { $current_product = ProductTypes::model()->findByAttributes(array('name' => $row['A'])); if (!$current_product) { $current_product = new ProductTypes(); } $current_product->name = $row['A']; $properties = '['; foreach ($row as $cell) { if ($cell != null && $cell != $row['A']) { $properties = "{$properties}\"{$cell}\","; } } $properties[strlen($properties) - 1] = ']'; $current_product->properties = $properties; $objValues = json_decode($current_product->values_); if (!$objValues) { $objValues = array(); $propCount = substr_count($current_product->properties, '","') + 1; for ($i = 0; $i < $propCount; $i++) { $objValues[$i] = array(); } } $current_product->values_ = json_encode($objValues); $current_product->save(); continue; } if (!$current_product) { continue; } //$cell = $row['B']; $product = Products::model()->findByAttributes(array('article' => $row['B'])); if (!$product) { $product = new Products(); } $product->type_id = $current_product->id; $product->article = $row['B']; //$cell = next($row); $product->description = $row['C']; //$cell = next($row); $product->prices = "[\"{$row['D']}\";\"{$row['E']}\";\"{$row['F']}\"]"; $values = '['; //$cell = $row['F']; //while ($cell = next($row)) $objValues = json_decode($current_product->values_, true); $i = 'H'; $nProp = 0; $isChanged = false; while ($row[$i]) { $values = "{$values}\"{$row[$i]}\","; if (is_array($objValues[$nProp]) && !in_array(strtolower($row[$i]), array_map('strtolower', $objValues[$nProp])) || !is_array($objValues[$nProp]) && $row[$i] != $objValues[$nProp]) { $objValues[$nProp][] = $row[$i]; $isChanged = true; } $i++; $nProp++; } $values[strlen($values) - 1] = ']'; $product->values_ = $values; if ($isChanged) { $current_product->values_ = json_encode($objValues, JSON_UNESCAPED_UNICODE); $current_product->save(); } $product->save(); } //$this->actionIndex(); }
?> </h3> <table class="table table-hover" > <thead> <tr class="top-table"> <th class="text-left"></th> <th><?php echo ProductsLang::model()->getAttributeLabel('name'); ?> </th> <th><?php echo Products::model()->getAttributeLabel('currency__id'); ?> </th> <th><?php echo Products::model()->getAttributeLabel('price'); ?> </th> <th><?php echo Yii::t('app', 'Операции'); ?> </th> </tr> </thead> <tbody> <?php foreach ($model->products as $i => $product) { ?> <tr data-product-id="<?php echo $product->getPrimaryKey(); ?>
} ?> <h2><?php echo Shop::t('Shopping cart'); ?> </h2> <?php if ($products) { echo '<table cellpadding="0" cellspacing="0" class="shopping_cart">'; printf('<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th style="width:60px;">%s</th><th style="width:60px;">%s</th><th>%s</th></tr>', Shop::t('Image'), Shop::t('Amount'), Shop::t('Product'), Shop::t('Variation'), Shop::t('Price Single'), Shop::t('Sum'), Shop::t('Actions')); //var_dump($products);die(); foreach ($products as $position => $product) { if ($model = Products::model()->findByPk($product['product_id'])) { $variations = ''; if (isset($product['Variations'])) { foreach ($product['Variations'] as $specification => $variation) { if ($specification = ProductSpecification::model()->findByPk($specification)) { if ($specification->input_type == 'textfield') { $variation = $variation[0]; } else { $variation = ProductVariation::model()->findByPk($variation); } if (Shop::module()->allowPositionLiveChange) { if ($specification->input_type == 'select') { $name = sprintf('variation_%s_%s', $position, $specification->id); $variations .= CHtml::radioButtonList($name, $variation->id, ProductVariation::listData($variation->getVariations(), true)); Yii::app()->clientScript->registerScript($name, "\r\n\t\t\t\t\t\t\t\t\t\t\$('[name=\"" . $name . "\"]').click(function(){\r\n\t\t\t\t\t\t\t\t\t\$.ajax({\r\n\t\t\t\t\t\t\t\t\t\t\t'url' : '" . CController::createUrl('//shop/shoppingCart/updateVariation') . "',\r\n\t\t\t\t\t\t\t\t\t\t\t'type' : 'POST',\r\n\t\t\t\t\t\t\t\t\t\t\t'data' : \$(this),\r\n\t\t\t\t\t\t\t\t\t\t\terror: function() {\r\n\t\t\t\t\t\t\t\t\t\t\t\$('#amount_" . $position . "').css('background-color', 'red');\r\n\t\t\t\t\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t\t\t\t\tsuccess: function(result) {\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.amount_" . $position . "').css('background-color', 'lightgreen');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.widget_amount_" . $position . "').css('background-color', 'lightgreen');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.widget_amount_" . $position . "').html(\$('.amount_" . $position . "').val());\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.price_" . $position . "').html(result);\t\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.price_single_" . $position . "').load('" . $this->createUrl('//shop/shoppingCart/getPriceSingle?position=' . $position) . "');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.price_total').load('" . $this->createUrl('//shop/shoppingCart/getPriceTotal') . "');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.shipping_costs').load('" . $this->createUrl('//shop/shoppingCart/getShippingCosts') . "');\r\n\r\n\t\t\t\t\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\t\t\t\t\t\$('input:checked').trigger('click');\r\n\t\t\t\t\t\t\t\t\t\t"); $variations .= '<br />';
public function actionStructSave($id) { $struct = new HalfstuffStructure(); $prod_id = CHtml::listData(HalfstuffStructure::model()->findAll(array("condition" => "halfstuff_id = {$id}")), 'halfstruct_id', 'prod_id'); $this->chosenProduct = CHtml::listData(Products::model()->findAllByPk($prod_id), 'product_id', 'name'); if ($_POST) { $transaction = Yii::app()->db->beginTransaction(); try { if ($_POST['prod']) { foreach ($_POST['prod'] as $key => $val) { $tempStruct = HalfstuffStructure::model()->updateAll(array('amount' => $val), 'halfstuff_id = :halfstuff_id AND prod_id = :prod_id', array(':halfstuff_id' => $id, ':prod_id' => $key)); } } $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); $this->redirect(array('index')); } catch (exception $ex) { } } $this->render('structSave', array()); }
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'faktura-form', 'enableAjaxValidation' => false)); ?> <style> td,th{ text-align: center!important; } </style> <div class="form-group"> <?php echo CHtml::dropDownList('list', '', $List, array('empty' => '--Выберите заявку--')); ?> <?php echo CHtml::dropDownList('products', '', CHtml::listData(Products::model()->findAll(), 'product_id', 'name'), array('empty' => '--Выберите продукт--', 'id' => 'product')); ?> <div id="data"></div> <div class="form-actions"> <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'id' => 'submitBtn', 'type' => 'primary', 'label' => $model->isNewRecord ? 'Добавить' : 'Сохранить', 'disabled' => 'disabled')); ?> </div> <script> $(document).on("click", ".deleteRow", function() { $(this).parent().parent().remove(); }); $("#product").chosen({ no_results_text: "Уупс, Ничего не найдено!"
public function actionOut() { $dates = $_POST['dates']; $outProduct = array(); $dish = new Expense(); $stuff = new Halfstaff(); foreach (Department::model()->findAll() as $val) { $outProduct = $stuff->sumArray($outProduct, $dish->getDishProd($val->department_id, $dates)); $outDishStuff = $dish->getDishStuff($val->department_id, $dates); } $Products = Products::model()->findAll(); $this->renderPartial('out', array('outProduct' => $outProduct, 'product' => $Products, 'dates' => $dates)); }
public function getStuffProdName($depId) { $models = Dishes::model()->with('stuff')->findAll('t.department_id = :depId', array(':depId' => $depId)); $stuff = ''; if (!empty($models)) { foreach ($models as $values) { foreach ($values->getRelated('stuff') as $value) { $stuff .= $this->getProdId($value->halfstuff_id); } } } $model = Halfstaff::model()->findAll('t.department_id = :depId', array(':depId' => $depId)); foreach ($model as $value) { $stuff .= $this->getProdId($value->halfstuff_id); } $temp = explode(':', $stuff); $result = array(); foreach ($temp as $val) { $model = Products::model()->findByPk($val); if (!empty($model)) { $result[$model->product_id] = $model->name; } } return $result; }
public function getProdName($depId) { $dish = new Dishes(); $result = array(); $stuff = new Halfstaff(); $temp2 = explode(":", $stuff->getStuffProd($depId)); foreach ($temp2 as $val) { $model = Products::model()->findByPk($val); if (!empty($model)) { $result[$model->product_id] = $model->name; } } $temp = explode(":", $dish->getDishProd($depId)); foreach ($temp as $val) { $model = Products::model()->findByPk($val); if (!empty($model)) { $result[$model->product_id] = $model->name; } } foreach (Products::model()->findAll('t.department_id = :depId', array(':depId' => $depId)) as $val) { $result[$val->product_id] = $val->name; } return $result; }
<div id="shopping-cart"> <div id="shopping-cart-content"> <?php if ($products) { echo '<h3>' . CHtml::link(Shop::t('Shopping cart'), array('//shop/shoppingCart/view')) . '</h3>'; echo '<table cellpadding="0" cellspacing="0">'; foreach ($products as $num => $position) { $model = Products::model()->findByPk($position['product_id']); printf('<tr> <td class="cart-left widget_amount_' . $num . '">%s</td> <td class="cart-middle">%s</td> <td class="cart-right price_' . $num . '">%s</td></tr>', $position['amount'], $model->title, Shop::priceFormat($position['amount'] * $model->getPrice(@$position['Variations']))); } if ($shippingMethod = Shop::getShippingMethod()) { printf('<tr> <td class="cart-left">1</td> <td class="cart-middle">%s</td> <td class="cart-right">%s</td></tr>', Shop::t('Shipping costs'), Shop::priceFormat($shippingMethod->price)); } printf('<tr> <td colspan="3" class="cart-right cart-sum price_total"><strong>%s</strong></td> </tr>', Shop::getPriceTotal()); echo '</table>'; } ?> </div> <div id="shopping-cart-footer"></div> </div>
/** * 商品规格 */ public function actionSpec() { $goods_id = $this->get('goods_id'); $goods_row = Goods::model()->find('goods_id = :goods_id', array(':goods_id' => $goods_id)); if ($_POST) { $product_attributes = $this->post('Product'); $Product = new Products(); $result = $Product->createProduct($goods_id, $goods_row, $product_attributes); if ($result) { $this->message('success', '编辑成功', $this->createUrl('index')); } else { $this->message('error', '编辑失败', $this->createUrl('index')); } } //商品规格 $GoodsTypeSpec = new GoodsTypeSpec(); $items = $GoodsTypeSpec->TypeSpecValue($goods_row['type_id']); $spec_list_t = $GoodsTypeSpec->ProductSpecList($goods_id); $spec_list = array(); foreach ($spec_list_t as $v) { $spec_list[$v['spec_id']] = $v; } //货品列表 $product_list = Products::model()->findAll('goods_id = :goods_id AND spec_desc <> :spec_desc AND disabled = :disabled', array(':goods_id' => $goods_id, ':spec_desc' => '', ':disabled' => 'false')); echo $this->render('spec', array('items' => $items, 'spec_list' => $spec_list, 'goods_row' => $goods_row, 'product_list' => $product_list)); }