Esempio n. 1
0
 public function run()
 {
     $shippingTypesList = ShippingType::find()->orderBy('order DESC')->all();
     $shippingTypes = ['' => yii::t('order', 'Choose shipping type')];
     foreach ($shippingTypesList as $sht) {
         if ($sht->cost > 0) {
             $currency = yii::$app->getModule('order')->currency;
             $name = "{$sht->name} ({$sht->cost}{$currency})";
         } else {
             $name = $sht->name;
         }
         $shippingTypes[$sht->id] = $name;
     }
     $paymentTypes = ['' => yii::t('order', 'Choose payment type')];
     $paymentTypesList = PaymentType::find()->orderBy('order DESC')->all();
     foreach ($paymentTypesList as $pt) {
         $paymentTypes[$pt->id] = $pt->name;
     }
     $fieldFind = Field::find()->orderBy('order DESC');
     $fieldValueModel = new FieldValue();
     $orderModel = new Order();
     if (empty($orderModel->shipping_type_id) && ($orderShippingType = yii::$app->session->get('orderShippingType'))) {
         if ($orderShippingType > 0) {
             $orderModel->shipping_type_id = (int) $orderShippingType;
         }
     }
     $this->getView()->registerJs("pistol88.order.updateShippingType = '" . Url::toRoute(['/order/tools/update-shipping-type']) . "';");
     return $this->render($this->view, ['orderModel' => $orderModel, 'fieldFind' => $fieldFind, 'paymentTypes' => $paymentTypes, 'elements' => $this->elements, 'shippingTypes' => $shippingTypes, 'shippingTypesList' => $shippingTypesList, 'fieldValueModel' => $fieldValueModel]);
 }
 protected function findModel($id)
 {
     if (($model = ShippingType::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 3
0
 public function addShippingCost($event)
 {
     if ($orderShippingType = yii::$app->session->get('orderShippingType')) {
         if ($orderShippingType > 0) {
             $shippingType = ShippingType::findOne($orderShippingType);
             if ($shippingType && $shippingType->cost > 0 && (int) $shippingType->free_cost_from <= 0 | $shippingType->free_cost_from > $event->cost) {
                 $event->cost = $event->cost + $shippingType->cost;
             }
         }
     }
     return $this;
 }
Esempio n. 4
0
 public function search($params)
 {
     $query = ShippingType::find()->orderBy('order DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Esempio n. 5
0
 public function actionView($id)
 {
     $this->layout = '@vendor/pistol88/yii2-order/views/layouts/mini';
     $model = $this->findModel($id);
     if ($model->status == $this->module->defaultStatus) {
         $model->status = $this->module->operatorOpenStatus;
         $model->seller_user_id = yii::$app->user->id;
         $model->save(false);
     }
     $searchModel = new ElementSearch();
     $params = yii::$app->request->queryParams;
     if (!is_array($params)) {
         $params = [];
     }
     $params['ElementSearch']['order_id'] = $model->id;
     $dataProvider = $searchModel->search($params);
     $paymentTypes = ArrayHelper::map(PaymentType::find()->all(), 'id', 'name');
     $shippingTypes = ArrayHelper::map(ShippingType::find()->all(), 'id', 'name');
     $fieldFind = Field::find();
     return $this->render('view', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'shippingTypes' => $shippingTypes, 'fieldFind' => $fieldFind, 'paymentTypes' => $paymentTypes, 'model' => $model]);
 }
Esempio n. 6
0
<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;
use pistol88\order\models\PaymentType;
use pistol88\order\models\ShippingType;
use pistol88\cart\widgets\ElementsList;
use pistol88\cart\widgets\CartInformer;
use pistol88\order\widgets\BuyByCode;
use pistol88\order\widgets\ChooseClient;
use pistol88\order\models\FieldValue;
$paymentTypes = ArrayHelper::map(PaymentType::find()->orderBy('order DESC')->all(), 'id', 'name');
$shippingTypes = ArrayHelper::map(ShippingType::find()->orderBy('order DESC')->all(), 'id', 'name');
pistol88\order\assets\CreateOrderAsset::register($this);
$this->registerJs("pistol88.createorder.updateCartUrl = '" . Url::toRoute(['tools/cart-info']) . "';");
$this->title = Yii::t('order', 'Create order');
$this->params['breadcrumbs'][] = ['label' => Yii::t('order', 'Orders'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="order-create">

<div class="order-form">
    <div class="row">
        <?php 
$form = ActiveForm::begin(['id' => 'orderForm']);
?>
        <div class="col-lg-6">
            <div class=" panel panel-default">
                <div class="panel-heading"><h3>Заказ</h3></div>
Esempio n. 7
0
 public function actionOrder($order_id = false)
 {
     $customServiceModel = new CustomService();
     if ($customServiceModel->load(Yii::$app->request->post()) && $customServiceModel->save()) {
         yii::$app->cart->put($customServiceModel);
         if (yii::$app->request->post('ajax')) {
             die(json_encode(['result' => 'success']));
         } else {
             \Yii::$app->session->setFlash('customServiceBuy', 'В корзине!');
         }
     }
     if ($type = yii::$app->request->get('service-order-type')) {
         if (!in_array($type, ['net', 'table'])) {
             return $this->redirect('404');
         }
         yii::$app->response->cookies->add(new \yii\web\Cookie(['name' => 'service-order-type', 'value' => $type]));
     } else {
         $type = yii::$app->request->cookies->get('service-order-type');
         if (!$type) {
             $type = 'net';
         }
     }
     $organization = false;
     $organizations = [];
     if (yii::$app->has('organization')) {
         $organization = yii::$app->organization->get();
         $organizations = yii::$app->organization->getList();
     }
     if ($organization) {
         $services = Service::find()->where('(calculator = "" OR calculator IS NULL) AND organization_id = :org_id', [':org_id' => $organization->id])->orderBy('sort DESC, id ASC')->all();
         $categories = Category::find()->where(['organization_id' => $organization->id])->orderBy('sort DESC, id ASC')->all();
         $complexes = Complex::find()->where(['organization_id' => $organization->id])->orderBy('sort DESC, id ASC')->all();
     } else {
         $services = Service::find()->orderBy('sort DESC, id ASC')->all();
         $categories = Category::find()->where('parent_id IS NULL OR parent_id = 0')->orderBy('sort DESC, id ASC')->all();
         $complexes = Complex::find()->orderBy('sort DESC, id ASC')->all();
     }
     $calculateServiceModel = Service::find()->where('calculator != ""')->all();
     $priceModel = new Price();
     $orderModel = new Order();
     $paymentTypes = ArrayHelper::map(PaymentType::find()->orderBy('order DESC')->all(), 'id', 'name');
     $shippingTypes = ArrayHelper::map(ShippingType::find()->orderBy('order DESC')->all(), 'id', 'name');
     $prices = [];
     foreach ($priceModel::find()->all() as $price) {
         $prices[$price->service_type][$price->category_id][$price->service_id] = $price;
     }
     $this->getView()->registerJs('pistol88.service.propertyListUrl = "' . Url::toRoute(['/service/property/get-ajax-list']) . '";');
     $this->getView()->registerJs('pistol88.service.searchClientByIdentUrl = "' . Url::toRoute(['/service/property/get-client-by-property']) . '";');
     if ($order_id) {
         $order = Order::findOne($order_id);
     } else {
         $order = false;
     }
     return $this->render('order', ['order' => $order, 'organization' => $organization, 'organizations' => $organizations, 'type' => $type, 'customServiceModel' => $customServiceModel, 'calculateServiceModel' => $calculateServiceModel, 'prices' => $prices, 'services' => $services, 'complexes' => $complexes, 'categories' => $categories, 'orderModel' => $orderModel, 'priceModel' => $priceModel, 'paymentTypes' => $paymentTypes, 'shippingTypes' => $shippingTypes]);
 }
Esempio n. 8
0
 public function getShipping()
 {
     return $this->hasOne(ShippingType::className(), ['id' => 'shipping_type_id']);
 }
Esempio n. 9
0
 public function actionPrint($id)
 {
     $this->layout = 'print';
     $this->enableCsrfValidation = false;
     $model = $this->findModel($id);
     $searchModel = new ElementSearch();
     $params = yii::$app->request->queryParams;
     if (empty($params['ElementSearch'])) {
         $params = ['ElementSearch' => ['order_id' => $model->id]];
     }
     $dataProvider = $searchModel->search($params);
     $paymentTypes = ArrayHelper::map(PaymentType::find()->all(), 'id', 'name');
     $shippingTypes = ArrayHelper::map(ShippingType::find()->all(), 'id', 'name');
     $fieldFind = Field::find();
     return $this->render('print', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'shippingTypes' => $shippingTypes, 'fieldFind' => $fieldFind, 'paymentTypes' => $paymentTypes, 'module' => $this->module, 'model' => $model]);
 }