Пример #1
0
 /**
  * Update order
  * @param bool $new
  * @throws CHttpException
  */
 public function actionUpdate($new = false)
 {
     if (SLicenseChecker::check() === false && SLicenseChecker::isOnLocalhost() === false) {
         throw new CHttpException(404, 'В ознакомительной версии редактирование заказов недоступно.');
     }
     if ($new === true) {
         $model = new Order();
         $model->unsetAttributes();
     } else {
         $model = $this->_loadModel($_GET['id']);
     }
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = $_POST['Order'];
         if ($model->validate()) {
             $model->save();
             // Update quantities
             if (sizeof(Yii::app()->request->getPost('quantity', array()))) {
                 $model->setProductQuantities(Yii::app()->request->getPost('quantity'));
             }
             $model->updateDeliveryPrice();
             $model->updateTotalPrice();
             $this->setFlashMessage(Yii::t('OrdersModule.admin', 'Изменения успешно сохранены'));
             if (isset($_POST['REDIRECT'])) {
                 $this->smartRedirect($model);
             } else {
                 $this->redirect(array('index'));
             }
         }
     }
     $this->render('update', array('deliveryMethods' => StoreDeliveryMethod::model()->applyTranslateCriteria()->orderByName()->findAll(), 'statuses' => OrderStatus::model()->orderByPosition()->findAll(), 'model' => $model));
 }
Пример #2
0
 /**
  * Delete method
  * @param array $id
  */
 public function actionDelete($id = array())
 {
     if (Yii::app()->request->isPostRequest) {
         $model = StoreDeliveryMethod::model()->findAllByPk($_REQUEST['id']);
         if (!empty($model)) {
             foreach ($model as $m) {
                 if ($m->countOrders() == 0) {
                     $m->delete();
                 } else {
                     throw new CHttpException(409, Yii::t('OrdersModule.admin', 'Ошибка удаления способа доставки. Он используется заказами.'));
                 }
             }
         }
         if (!Yii::app()->request->isAjaxRequest) {
             $this->redirect('index');
         }
     }
 }
Пример #3
0
 /**
  * Display list of product added to cart
  */
 public function actionIndex()
 {
     // Recount
     if (Yii::app()->request->isPostRequest && Yii::app()->request->getPost('recount') && !empty($_POST['quantities'])) {
         $this->processRecount();
     }
     $this->form = new OrderCreateForm();
     // Make order
     if (Yii::app()->request->isPostRequest && Yii::app()->request->getPost('create')) {
         if (isset($_POST['OrderCreateForm'])) {
             $this->form->attributes = $_POST['OrderCreateForm'];
             if ($this->form->validate()) {
                 $order = $this->createOrder();
                 Yii::app()->cart->clear();
                 $this->addFlashMessage(Yii::t('OrdersModule.core', 'Спасибо. Ваш заказ принят.'));
                 Yii::app()->request->redirect($this->createUrl('view', array('secret_key' => $order->secret_key)));
             }
         }
     }
     $deliveryMethods = StoreDeliveryMethod::model()->applyTranslateCriteria()->active()->orderByName()->findAll();
     $this->render('index', array('items' => Yii::app()->cart->getDataWithModels(), 'totalPrice' => Yii::app()->currency->convert(Yii::app()->cart->getTotalPrice()), 'deliveryMethods' => $deliveryMethods));
 }
Пример #4
0
 /**
  * Check if delivery method exists
  */
 public function validateDelivery()
 {
     if (StoreDeliveryMethod::model()->countByAttributes(array('id' => $this->delivery_id)) == 0) {
         $this->addError('delivery_id', Yii::t('OrdersModule.core', 'Необходимо выбрать способ доставки.'));
     }
 }
Пример #5
0
 /**
  * Before save event
  */
 public function beforeSave()
 {
     if ($this->position == '') {
         $max = StoreDeliveryMethod::model()->orderByPositionDesc()->find();
         if ($max) {
             $this->position = (int) $max->position + 1;
         } else {
             $this->position = 0;
         }
     }
     return parent::beforeSave();
 }
Пример #6
0
 /**
  * @param $key
  * @param $id
  * @return string
  */
 public function idToText($key, $id)
 {
     $val = $id;
     if ('delivery_id' === $key) {
         $model = StoreDeliveryMethod::model()->findByPk($id);
         if ($model) {
             $val = $model->name;
         }
     } elseif ('status_id' === $key) {
         $model = OrderStatus::model()->findByPk($id);
         if ($model) {
             $val = $model->name;
         }
     }
     return $val;
 }
Пример #7
0
 /**
  * @return mixed
  */
 public function getDelivery_name()
 {
     Yii::import('store.StoreModule');
     Yii::import('store.models.StoreDeliveryMethod');
     $model = StoreDeliveryMethod::model()->findByPk($this->delivery_id);
     if ($model) {
         return $model->name;
     }
 }
Пример #8
0
<?php

Yii::import('orders.components.SProductsPreviewColumn');
/**
 * Display orders list
 **/
$this->pageHeader = Yii::t('OrdersModule.admin', 'Заказы');
$this->breadcrumbs = array('Home' => $this->createUrl('/admin'), Yii::t('OrdersModule.admin', 'Заказы'));
$this->topButtons = $this->widget('admin.widgets.SAdminTopButtons', array('template' => array('create'), 'elements' => array('create' => array('link' => $this->createUrl('create'), 'title' => Yii::t('OrdersModule.admin', 'Создать заказ'), 'options' => array('icons' => array('primary' => 'ui-icon-cart'))))));
$this->widget('ext.sgridview.SGridView', array('dataProvider' => $dataProvider, 'id' => 'ordersListGrid', 'filter' => $model, 'columns' => array(array('class' => 'CCheckBoxColumn'), array('class' => 'SGridIdColumn', 'name' => 'id'), array('name' => 'user_name', 'type' => 'raw', 'value' => 'CHtml::link(CHtml::encode($data->user_name), array("/orders/admin/orders/update", "id"=>$data->id))'), 'user_email', 'user_phone', array('name' => 'status_id', 'filter' => CHtml::listData(OrderStatus::model()->orderByPosition()->findAll(), 'id', 'name'), 'value' => '$data->status_name'), array('name' => 'delivery_id', 'filter' => CHtml::listData(StoreDeliveryMethod::model()->orderByPosition()->findAll(), 'id', 'name'), 'value' => '$data->delivery_name'), array('class' => 'SProductsPreviewColumn'), array('type' => 'raw', 'name' => 'full_price', 'value' => 'StoreProduct::formatPrice($data->full_price)'), 'created', array('class' => 'CButtonColumn', 'template' => '{update}{delete}'))));
Пример #9
0
<?php

/**
 * View user orders
 * @var $orders
 */
$this->pageTitle = Yii::t('UsersModule.core', 'Мои заказы');
?>
<h1 class="has_background"><?php 
echo Yii::t('UsersModule.core', 'Мои заказы');
?>
</h1>

<?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'ordersListGrid', 'dataProvider' => $orders->search(), 'template' => '{items}', 'columns' => array(array('name' => 'user_name', 'type' => 'raw', 'value' => 'CHtml::link(CHtml::encode($data->user_name), array("/orders/cart/view", "secret_key"=>$data->secret_key))'), 'user_email', 'user_phone', array('name' => 'status_id', 'filter' => CHtml::listData(OrderStatus::model()->orderByPosition()->findAll(), 'id', 'name'), 'value' => '$data->status_name'), array('name' => 'delivery_id', 'filter' => CHtml::listData(StoreDeliveryMethod::model()->orderByPosition()->findAll(), 'id', 'name'), 'value' => '$data->delivery_name'), array('type' => 'raw', 'name' => 'full_price', 'value' => 'StoreProduct::formatPrice($data->full_price)'))));