public function actionIndex() { header('Content-Type: application/json'); $json = array(); $product = ShopProduct::model()->findByPk(Yii::app()->request->getPost('product_id')); if (!$product) { throw new CHttpException(404); } $record = new ProductNotifications(); if (isset($_POST['ProductNotifications'])) { $record->attributes = array('email' => $_POST['ProductNotifications']['email']); $record->product_id = $product->id; if ($record->validate() && $record->hasEmail() === false) { $record->save(); $json['message'] = 'Мы сообщим вам когда товар появится в наличии'; $json['status'] = 'OK'; } else { $json['message'] = 'Ошибка'; $json['status'] = 'ERROR'; } } $json['data'] = $this->renderPartial('_form', array('model' => $record, 'product' => $product), true); echo CJSON::encode($json); // $this->render('_form', array('model' => $record, 'product' => $product)); }
/** * Add new email to list */ public function actionIndex() { $product = StoreProduct::model()->findByPk(Yii::app()->request->getPost('product_id')); if (!$product) { throw new CHttpException(404); } $record = new ProductNotifications(); $record->attributes = array('email' => $_POST['email']); $record->product_id = $product->id; if ($record->validate() && $record->hasEmail() === false) { $record->save(); } }
/** * Delete requests */ public function actionDelete() { $model = ProductNotifications::model()->findByPk(Yii::app()->request->getParam('id')); if ($model) { ProductNotifications::model()->deleteAllByAttributes(array('product_id' => $model->product_id)); } }
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 actionGetCounters() { Yii::import('mod.cart.models.Order'); Yii::import('mod.cart.models.ProductNotifications'); Yii::import('mod.support.models.TicketMessage'); $json = array(); if (Yii::app()->hasModule('comments')) { $json['comments'] = (int) Comments::model()->waiting()->count(); } $json['orders'] = (int) Order::model()->new()->count(); $json['notify'] = (int) ProductNotifications::model()->count(); $json['support'] = (int) TicketMessage::model()->count(); echo CJSON::encode($json); }
public function actionSend() { $record = ProductNotifications::model()->findAllByAttributes(array('product_id' => $_GET['product_id'])); $tplMail = TplMail::model()->findByAttributes(array('formkey' => 'PRODUCT_NOTIFY')); if (!$tplMail) { throw new CHttpException(404, 'Не могу найти шаблон письма.'); } foreach ($record as $row) { if (!$row->product) { continue; } $tplMail->setEmails($row->email); $tplMail->sendEmail($this->replaceArray($row->product), $this->replaceArray($row->product)); $row->delete(); } Yii::app()->user->setFlash('success', Yii::t('CartModule.admin', 'Сообщения успешно отправлены.')); $this->redirect('index'); }
/** * Check if email exists in list for current product */ public function hasEmail() { return ProductNotifications::model()->countByAttributes(array('email' => $this->email, 'product_id' => $this->product_id)) > 0; }