/** * Display list of product added to cart */ public function actionIndex() { // Recount // ShopModule::registerAssets(); $this->pageName = Yii::t('app', 'CART'); $this->pageTitle = $this->pageName; $this->breadcrumbs = array(Yii::t('app', 'PRODUCTION') => array('/shop'), $this->pageName); 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()) { $this->form->registerGuest(); $order = $this->createOrder(); Yii::app()->cart->clear(); Yii::app()->user->setFlash('success', Yii::t('CartModule.default', 'SUCCESS_ORDER')); Yii::app()->request->redirect($this->createUrl('view', array('secret_key' => $order->secret_key))); } } } $deliveryMethods = ShopDeliveryMethod::model()->applyTranslateCriteria()->active()->orderByName()->findAll(); if (count($deliveryMethods) < 1) { throw new CHttpException(404, Yii::t('CartModule.default', 'ERROR_DELIVERY')); } $paymenyMethods = ShopPaymentMethod::model()->findAll(); if (count($paymenyMethods) < 1) { throw new CHttpException(404, Yii::t('CartModule.default', 'ERROR_PAYMENTS')); } $this->render('index', array('items' => Yii::app()->cart->getDataWithModels(), 'totalPrice' => Yii::app()->currency->convert(Yii::app()->cart->getTotalPrice()), 'deliveryMethods' => $deliveryMethods, 'paymenyMethods' => $paymenyMethods)); }
public function afterUninstall() { Yii::app()->settings->clear($this->id); //Yii::app()->unintallComponent('cart'); $db = Yii::app()->db; $tablesArray = array(Order::model()->tableName(), OrderHistory::model()->tableName(), OrderProduct::model()->tableName(), OrderStatus::model()->tableName(), OrderProductHistroy::model()->tableName(), ShopPaymentMethod::model()->tableName(), ShopPaymentMethodTranslate::model()->tableName(), ShopDeliveryMethod::model()->tableName(), ShopDeliveryMethodTranslate::model()->tableName(), ShopDeliveryPayment::model()->tableName(), ProductNotifications::model()->tableName()); foreach ($tablesArray as $table) { $db->createCommand()->dropTable($table); } return parent::afterInstall(); }
/** * Delete method * @param array $id */ public function actionDelete($id = array()) { if (Yii::app()->request->isPostRequest) { $model = ShopDeliveryMethod::model()->findAllByPk($_REQUEST['id']); if (!empty($model)) { foreach ($model as $m) { if ($m->countOrders() == 0) { $m->delete(); } else { throw new CHttpException(409, Yii::t('CartModule.admin', 'ERR_DEL_DELIVERY')); } } } if (!Yii::app()->request->isAjaxRequest) { $this->redirect('index'); } } }
/** * Update order * @param bool $new * @throws CHttpException */ public function actionUpdate($new = false) { Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/admin/orders.update.js', CClientScript::POS_END); if ($new === true) { $model = new Order(); $model->unsetAttributes(); } else { $model = $this->_loadModel($_GET['id']); } if (!$model->isNewRecord) { $update = Yii::t('CartModule.admin', 'UPDATE_ORDER', array('{order_id}' => CHtml::encode($model->id))); } $this->pageName = $model->isNewRecord ? Yii::t('CartModule.admin', 'Создание заказа') : Yii::t('CartModule.admin', 'ORDER', 0); $this->breadcrumbs = array(Yii::t('CartModule.admin', 'ORDER', 0) => $this->createUrl('index'), $model->isNewRecord ? Yii::t('CartModule.admin', 'Создание заказа') : $update); 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(); if ($model->isNewRecord === false) { $template[] = 'delete'; } // register all delivery methods to recalculate prices Yii::app()->clientScript->registerScript('deliveryMetohds', strtr('var deliveryMethods = {data};', array('{data}' => CJavaScript::jsonEncode($deliveryMethods))), CClientScript::POS_END); /// if ($new) { // $this->setFlashMessage(Yii::t('core', 'Теперь Вы можете добавить товары.')); //} $this->redirect(array('update', 'id' => $model->id)); } } $this->render('update', array('deliveryMethods' => ShopDeliveryMethod::model()->applyTranslateCriteria()->orderByName()->findAll(), 'paymentMethods' => ShopPaymentMethod::model()->findAll(), 'statuses' => OrderStatus::model()->orderByPosition()->findAll(), 'model' => $model)); }
<div class="row"> <div class="col-md-3"> <?php $this->renderPartial('_nav'); ?> </div> <div class="col-md-9"> <h1><?php echo $this->pageName; ?> </h1> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'ordersListGrid', 'itemsCssClass' => 'table table-striped table-condensed', 'dataProvider' => $orders->search(), 'template' => '{items}', 'columns' => array(array('name' => 'user_name', 'type' => 'raw', 'value' => 'Html::link(Html::encode($data->user_name), array("/cart/default/view", "secret_key"=>$data->secret_key))'), 'user_email', 'user_phone', array('name' => 'status_id', 'filter' => Html::listData(OrderStatus::model()->orderByPosition()->findAll(), 'id', 'name'), 'value' => '$data->status_name'), array('name' => 'delivery_id', 'filter' => Html::listData(ShopDeliveryMethod::model()->orderByPosition()->findAll(), 'id', 'name'), 'value' => '$data->delivery_name'), array('type' => 'raw', 'name' => 'full_price', 'value' => 'ShopProduct::formatPrice($data->full_price)')))); ?> </div> </div>
public function validateDelivery() { if (ShopDeliveryMethod::model()->countByAttributes(array('id' => $this->delivery_id)) == 0) { $this->addError('delivery_id', $this->t('VALID_DELIVERY')); } }
/** * @param $key * @param $id * @return string */ public function idToText($key, $id) { $val = $id; if ('delivery_id' === $key) { $model = ShopDeliveryMethod::model()->findByPk($id); if ($model) { $val = $model->name; } } elseif ('status_id' === $key) { $model = OrderStatus::model()->findByPk($id); if ($model) { $val = $model->name; } } return $val; }
/** * @return mixed */ public function getDelivery_name() { $model = ShopDeliveryMethod::model()->findByPk($this->delivery_id); if ($model) { return $model->name; } }