public function actionPayment() { if (isset($_POST)) { $this->form = ShopPaymentMethod::model()->cache($this->cacheTime)->findAll(); $this->render('_payment', array('model' => $this->form)); } }
/** * Update payment method * @param bool $new * @throws CHttpException */ public function actionUpdate($new = false) { Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/admin/payment.js', CClientScript::POS_END); if ($new === true) { $model = new ShopPaymentMethod(); $model->unsetAttributes(); } else { $model = ShopPaymentMethod::model()->language(Yii::app()->language->active)->findByPk($_GET['id']); } if (!$model) { throw new CHttpException(404, Yii::t('CartModule.admin', 'NO_FOUND_PAYMENT')); } Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/admin/paymentMethod.update.js'); $this->pageName = $model->isNewRecord ? $model->t('IS_CREATE', 0) : $model->t('IS_CREATE', 1); $this->breadcrumbs = array(Yii::t('CartModule.default', 'MODULE_NAME') => array('/admin/shop'), Yii::t('CartModule.admin', 'PAYMENTS') => $this->createUrl('index'), $this->pageName); // $form = new CMSForm($model->config, $model); if (Yii::app()->request->isPostRequest) { $model->attributes = $_POST['ShopPaymentMethod']; if ($model->validate()) { $model->save(); if ($model->payment_system) { $manager = new PaymentSystemManager(); $system = $manager->getSystemClass($model->payment_system); $system->saveAdminSettings($model->id, $_POST); } $this->redirect('index'); } } $this->render('update', array('model' => $model)); }
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(); }
public function actionProcess() { if (Yii::app()->request->getParam('Shp_pmId')) { $_GET['payment_id'] = $_GET['Shp_pmId']; } $payment_id = (int) Yii::app()->request->getParam('payment_id'); $model = ShopPaymentMethod::model()->findByPk($payment_id); if (!$model) { throw new CHttpException(404, 'Ошибка'); } $system = $model->getPaymentSystemClass(); if ($system instanceof BasePaymentSystem) { $response = $system->processPaymentRequest($model); if ($response instanceof Order) { $this->redirect($this->createUrl('/cart', array('view' => $response->secret_key))); } else { throw new CHttpException(404, Yii::t('CartModule.default', 'Возникла ошибка при обработке запроса. <br> {err}', array('{err}' => $response))); } } }
/** * 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)); }
/** * Validate payment method exists * @param $attr * @return mixed */ public function validatePaymentMethods($attr) { if (!is_array($this->{$attr})) { return; } foreach ($this->{$attr} as $id) { if (ShopPaymentMethod::model()->countByAttributes(array('id' => $id)) == 0) { $this->addError($attr, $this->t('ERROR_PAYMENT')); } } }
public function validatePayment() { if (ShopPaymentMethod::model()->countByAttributes(array('id' => $this->payment_id)) == 0) { $this->addError('payment_id', $this->t('VALID_PAYMENT')); } }
public function getPayment_name() { $model = ShopPaymentMethod::model()->findByPk($this->payment_id); if ($model) { return $model->name; } }