public function actionActivateTheme() { $themes = Theme::model()->findAll(); $suc = Yii::t('info', 'Theme has been Activated'); $err = Yii::t('info', 'Theme was not Activated'); if (isset($_POST['Theme']['name'])) { $valid = Theme::model()->findByAttributes(array('name' => $_POST['Theme']['name'])); if (!empty($valid)) { file_put_contents(UtilityHelper::yiiparam('frontPath') . "/config/main-theme.php", $this->getConfigTemplate($_POST['Theme']['name'])); Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc); } else { Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err); } } else { //Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR,$err); } $this->render('activate', array('models' => $themes)); }
public function actionContactUs() { $model = new ContactUsForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'contactus-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['ContactUsForm'])) { $model->attributes = $_POST['ContactUsForm']; // validate user input and redirect to the previous page if valid if ($model->validate()) { UtilityHelper::sendMail($model->email, UtilityHelper::yiiparam('salesEmail'), 'Contact Us Request - ' . $model->subject, $model->comment); $this->render('thankyou', array('model' => $model)); } } // display the login form $this->render('contactus', array('model' => $model)); }
public function actionIndex() { $settings = Yii::app()->settings; $config = (require Yii::getPathOfAlias('backend.views.settings.settingsForm') . '.php'); //echo UtilityHelper::getSettings('messages','accountactivatedsubject'); //echo UtilityHelper::getSettings('messages','accountactivated'); if (isset($_POST['SettingsForm'])) { //print_r($_POST['SettingsForm']); //$model->setAttributes($_POST['SettingsForm']); $settings->deleteCache(); foreach ($_POST['SettingsForm'] as $category => $values) { $settings->set($category, $values); } file_put_contents(UtilityHelper::yiiparam('frontPath') . "/config/main-settings.php", $this->getConfigTemplate($settings->get('site', 'name'), $settings->get('site', 'siteRedirectUrl'), $settings->get('site', 'noreplyEmail'), $settings->get('site', 'salesEmail'), $settings->get('site', 'sitePhone'), $settings->get('site', 'currency'))); user()->setFlash('success', 'Site settings were updated.'); $this->refresh(); } foreach ($config['elements'] as $category => &$attributes) { foreach ($attributes['elements'] as &$attribute) { $attribute['value'] = $settings->get($category, $attribute['name']); } } $this->render('index', array('config' => $config)); }
echo $order->email; ?> </h5> <h5>Phone: <?php echo $order->telephone; ?> </h5> <br/> <span>Please take note of your transaction id, you may be required to present it in future.</span> <?php echo CHtml::hiddenField('merch_txnref', $ref); echo CHtml::hiddenField('merchantid', "174"); echo CHtml::hiddenField('names', $order->firstname . ' ' . $order->lastname); //$orderID); echo CHtml::hiddenField('email_address', $order->email); echo CHtml::hiddenField('amount', "{$total}"); //echo CHtml::hiddenField('site_redirect_url', UtilityHelper::yiiparam('site_redirect_url')); echo CHtml::hiddenField('phone_number', $order->telephone); echo CHtml::hiddenField('currency', UtilityHelper::yiiparam('currencyText')); ?> <?php } ?> </div> </div> <div class="section_foot_general"> <input type="submit" class="f_right_checkout" value="" /> <div class="clear"></div> </div> <?php echo CHtml::endForm();
/** * Registration user */ public function actionRegistration() { Profile::$regMode = true; $model = new RegistrationForm(); $profile = new Profile(); // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); if ($model->validate() && $profile->validate()) { //$soucePassword = $model->password; //$realp = PasswordHelper::generateStrongPassword(); //$model->password = $realp; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = PasswordHelper::hashPassword($model->password); $model->verifyPassword = $model->password; $model->superuser = 0; $model->type = 1; $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE; if ($model->save()) { $profile->user_id = $model->id; $profile->save(); if (Yii::app()->controller->module->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); $name = $_POST['Profile']['first_name'] . ' ' . $_POST['Profile']['last_name']; UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("<div style='border: 1px solid #FCC32A;border-radius:5px;box-shadow:1px 5px 5px;background-color:#FFFFEE;'><div style='background-color:#333;border-radius:5px;padding:10px;'><img src='http://yorshop.com/img/main_logo.png' style='float:left'/><h2 style='color: #FFF;width:70%;margin-left:15%;'>Successful Registration</h2><hr/></div><div style='padding:10px;'><p><strong>Dear {name},</strong></p><p>Thank you for registering at <a href='{site_url}' target='blank'>{site_name}</a>.</p><p>Please activate your account by clicking: <a href='{activation_url}' target='blank'>{activation_url}</a> or copy and paste it in your browser.</p><p><a href='{site_url}' target='blank' ><img src='http://yorshop.com/img/form_submit.png'/></a></p></div><div style='padding:0px 10px 0px;'><p>If you need any assistance or have any inquiry or suggestion, feel free to contact our customer service team at <a href='mailto:info@yorshop.com'>info@yorshop.com</a> or call us at <strong>0700 967 7467</strong> between 8am and 10pm on weekdays and 9am to 6pm on weekends, we would be happy to guide you.</p> <address>Thank You!<br/>Your Yorshop Team</address></div></div>", array('{activation_url}' => $activation_url, '{name}' => $name, '{site_name}' => Yii::app()->name, '{site_url}' => UtilityHelper::yiiparam('site_name')))); } if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) { $identity = new UserIdentity($model->username, $soucePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); $this->redirect(Yii::app()->controller->module->returnUrl); } else { if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } else { $profile->validate(); } } if (isset($this->location)) { $this->render('frontend.views.user.registration', array('model' => $model, 'profile' => $profile)); } else { $this->render('/user/registration', array('model' => $model, 'profile' => $profile)); } } }
public static function callInterswitch($ref, &$json) { //$ref = $_POST['txnref']; $order = Order::model()->findByAttributes(array('payment_code' => $ref)); $pay = PaymentTransaction::model()->findByAttributes(array('reference_number' => $ref)); $url = UtilityHelper::yiiparam('interswitchGet') . '?productid=' . UtilityHelper::yiiparam('interswitchProductID') . '&transactionreference=' . $ref . '&amount=' . $order->total * 100; //self::sendToLog($url); try { $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $url); curl_setopt($cURL, CURLOPT_HTTPGET, true); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Hash: ' . hash('sha512', UtilityHelper::yiiparam('interswitchProductID') . $ref . UtilityHelper::yiiparam('MAC_key')))); $result = curl_exec($cURL); if (FALSE === $result) { throw new Exception(curl_error($cURL), curl_errno($cURL)); } //self::sendToLog($result,"Json things!!!"); curl_close($cURL); } catch (Exception $e) { self::sendToLog(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), "CURL Interswitch Error"); return false; } $json = json_decode($result, true); //$pay->transaction_date = $json['TransactionDate']; //$pay->reference_number = $ref; $pay->payment_reference = $json['PaymentReference']; $pay->response_description = $json['ResponseDescription']; $pay->response_code = $json['ResponseCode']; $pay->approved_amount = $json['Amount'] / 100; //$pay->customer_name = ; $pay->save(); $json['CustomerName'] = $pay->customer_name; $total = UtilityHelper::formatPrice($order->total); $siteurl = UtilityHelper::yiiparam('siteUrl'); if (empty($order->check)) { $messg = "Dear {$order->firstname} {$order->lastname},<br/><br/>You have just attempted making payment for order #{$order->id} on {$order->store_url}. Find the details below.<br/><br/>Amount: {$total}<br/><br/>Response Description: {$json['ResponseDescription']}<br/><br/>Response Code: {$json['ResponseCode']}<br/><br/>Transaction Ref No: {$ref}<br/><br/>Payment Reference: {$json['PaymentReference']}<br/><br/>Transaction Date: {$json['TransactionDate']}<br/>"; if ($json['ResponseCode'] == '09') { } else { if ($json['ResponseCode'] == '00') { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Successful Payment Notification', $messg); //UtilityHelper::changeOrderStatus($order->id); $order->order_status_id = 2; $order->check = 1; $order->save(); UtilityHelper::subtractOrder($order->id); } else { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Failed Payment Notification', $messg); //UtilityHelper::changeOrderStatus($order->id,10); $order->order_status_id = 10; $order->check = 1; $order->save(); } } } //return $order; }
<?php $this->pageTitle = UtilityHelper::yiiparam('site_name'); ?> <h1>Welcome to <i><?php echo UtilityHelper::yiiparam('site_name'); ?> Admin Panel</i></h1> <?php Yii::app()->user->setFlash('success', '<strong> You may login by clicking login on the top right corner.</strong>'); $this->widget('bootstrap.widgets.TbAlert'); ?> <img style='margin-left:20%;' src='<?php echo Yii::app()->request->baseUrl . '/images/admin_icon.png'; ?> ' title='Admin' alt='Admin'/>
public function actionPayment($id) { $cart = $this->getCart(); $add = CheckoutAddress::model()->findByPk($id); $link; $onlinePaymentMethodName; $extrapObj = array(); $orderArray = array(); $classArray = array(); if (!empty($add) && !empty($cart['items'])) { if (isset($_POST['Payment']['payment_method'])) { $pay_method = $_POST['Payment']['payment_method']; $cart['payment'] = $pay_method == 4 ? 2 : $pay_method; $paymentType = is_numeric($pay_method) ? 'others' : 'online'; $order = new Order(); $order->order_status_id = 1; $order->total = $this->getCartTotal(); $order->ip = Yii::app()->request->userHostAddress; $order->user_agent = Yii::app()->request->userAgent; $order->firstname = $add->firstname; $order->lastname = $add->lastname; $order->email = $add->email; $order->telephone = $add->telephone; $order->payment_firstname = $add->firstname; $order->payment_lastname = $add->lastname; $order->payment_company = ''; $order->payment_tax_id = 0; $order->payment_address_1 = $add->address_1; $order->payment_address_2 = $add->address_2; $order->payment_city = $add->city; $order->payment_postcode = $add->postal_code; $order->payment_country_id = $add->country_id; $order->payment_zone_id = $add->zone_id; $order->payment_method = $cart['payment']; $order->payment_code = uniqid() . rand(1, 9); $order->shipping_firstname = $add->firstname; $order->shipping_lastname = $add->lastname; $order->shipping_company = ''; $order->shipping_address_1 = $add->address_1; $order->shipping_address_2 = $add->address_2; $order->shipping_city = $add->city; $order->shipping_postcode = $add->postal_code; $order->shipping_country_id = $add->country_id; $order->shipping_zone_id = $add->zone_id; $order->shipping_method = 2; if ($add->zone_id == 2412) { $order->shipping_method = 1; } $storeid = UtilityHelper::yiiparam('storeID'); $store = Store::model()->findByPk($storeid); $order->store_id = $storeid; $order->store_name = $store->name; $order->store_url = $store->url; $order->payment_country = Country::model()->findByPk($order->payment_country_id)->name; $order->payment_zone = Zone::model()->findByPk($order->payment_zone_id)->name; $order->shipping_country = $order->payment_country; $order->shipping_zone = $order->payment_zone; if ($order->save()) { foreach ($cart['items'] as $product) { $orderproduct = new OrderProduct(); $orderproduct->order_id = $order->id; $orderproduct->product_id = $product['product_id']; $orderproduct->name = $product['name']; $orderproduct->model = $product['model']; $orderproduct->quantity = $product['quantity']; $orderproduct->price = $product['price']; $orderproduct->total = $product['total']; $orderproduct->tax = 0; if ($orderproduct->save()) { if (!empty($product['option'])) { foreach ($product['option'] as $orderoption) { $orderoption->order_id = $order->id; $orderoption->order_product_id = $orderproduct->id; $orderoption->save(); } } } else { Yii::log("CartPaymentOrderProductErrors: " . CVarDumper::dumpAsString($orderproduct->getErrors()), CLogger::LEVEL_ERROR, "cart.actions.payment"); } } //Yii::app()->user->setState('user_cart', NULL); $extrap = array(); // switch ($paymentType) { case 'others': // Will need to loop through the ids for non online payment to do this properly if ($pay_method == 1) { $link = '_cash'; $extrap = array('orderID' => $order->id, 'total' => $order->total); UtilityHelper::changeOrderStatus($order->id); } else { if ($pay_method == 3) { $link = '_bank'; $extrap = array('orderID' => $order->id, 'total' => $order->total); } } break; case 'online': $subClasses = new PaymentGatewayHelper(); $subClassesArray = $subClasses->getSubClasses(); foreach ($subClassesArray as $class => $payOption) { ${$class} = new $class(); $onlinePaymentMethodName = ${$class}->getPaymentName(); if ($pay_method == $onlinePaymentMethodName) { $link = ${$class}->getViewLink(); ${$class}->setOrderObj($order); $extrapObj = ${$class}->getOrderObj(); foreach ($extrapObj as $field => $value) { $orderArray[$field] = $value; } $link = ${$class}->getViewLink(); $extrap = array('orderID' => $orderArray['id'], 'total' => $orderArray['total']); ${$class}->regPaymentTransaction($order); $classArray['pay_method'] = $pay_method; } else { continue; } } break; default: break; } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial($link, array_merge(array('ref' => $order->payment_code), $extrap, $classArray), false, true); Yii::app()->end(); } $this->render($link, array_merge(array('ref' => $order->payment_code), $extrap, $classArray)); Yii::app()->end(); } else { Yii::log("CartPaymentErrors: " . CVarDumper::dumpAsString($order->getErrors()), CLogger::LEVEL_ERROR, "cart.actions.payment"); } } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_payment', array('app' => $add), false, true); Yii::app()->end(); } $this->render('payment', array('app' => $add)); Yii::app()->end(); } $this->redirect(array('cart')); }
public static function getPublishPath($path) { $rpath = realpath(UtilityHelper::yiiparam('frontPath') . '/www' . $path); if (!empty($rpath)) { $url = Yii::app()->assetManager->publish($rpath); return $url; } return null; }
public static function callGlobalPay($txnref, &$trans) { //$txnref = $_GET["txnref"]; $client = new SoapClient('https://www.globalpay.com.ng/globalpaywebservice/service.asmx?wsdl', array('exceptions' => 0, 'encoding' => 'UTF-8')); $soapaction = "https://www.eazypaynigeria.com/globalpay/getTransactions"; $namespace = "https://www.eazypaynigeria.com/globalpay/"; $order = Order::model()->findByAttributes(array('payment_code' => $txnref)); $pay = PaymentTransaction::model()->findByAttributes(array('reference_number' => $txnref)); $merch_txnref = $txnref; $channel = ""; //change the merchantid to the one sent to you $merchantID = "174"; $start_date = ""; $end_date = ""; //change the uid and pwd to the one sent to you $uid = "yl_ws_user"; $pwd = "yl_ws_password"; $payment_status = ""; /* $err = $client->getError(); if ($err) { $this->render('view2',array('response'=>$err, 'error'=>1)); }*/ // Doc/lit parameters get wrapped $MethodToCall = "getTransactions"; //$MethodToCall= "Checkcenter"; $param = array('merch_txnref' => $merch_txnref, 'channel' => $channel, 'merchantID' => $merchantID, 'start_date' => $start_date, 'end_date' => $end_date, 'uid' => $uid, 'pwd' => $pwd, 'payment_status' => $payment_status); $result = $client->__soapCall($MethodToCall, array('parameters' => $param), array('uri' => $namespace, 'soapaction' => $soapaction)); // Check for a fault if (is_soap_fault($result)) { //"SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})"; return false; } else { //This gives getTransactionsResult $WebResult = $MethodToCall . "Result"; // Pass the result into XML if (is_object($result)) { $xresult = $result->{$WebResult}; } else { $xresult = $result[$WebResult]; } $xml = simplexml_load_string($xresult); //self::sendToLog($xml); //$trans = array(); $trans['amount'] = $xml->record->amount; $trans['txn_date'] = $xml->record->payment_date; $trans['pmt_method'] = $xml->record->channel; $trans['pmt_status'] = $xml->record->payment_status; $trans['pmt_txnref'] = $xml->record->txnref; $trans['currency'] = $xml->record->field_values->field_values->field[2]->currency; // $pnr = 'PNR'; $trans['trans_status'] = $xml->record->payment_status_description; $trans['merch_name'] = $pay->customer_name; $trans['merch_phoneno'] = $order->telephone; $trans['merch_amt'] = $pay->transaction_amount; //$pay = new PaymentTransaction; $pay->transaction_date = $trans['txn_date']; //$pay->reference_number = ; $pay->payment_reference = $trans['pmt_txnref']; if ($trans['amount'] != $trans['merch_amt']) { $trans['pmt_status'] .= " ( Amount does not match and no service will be rendered)"; $pay->response_code = $trans['pmt_status']; } else { $pay->response_code = $trans['pmt_status']; } $pay->response_description = $trans['trans_status']; $pay->approved_amount = $trans['amount']; //$pay->transaction_amount = $trans['merch_amt']; $pay->transaction_currency = $trans['currency']; //$pay->customer_name = $trans['merch_name']; $pay->save(); if (empty($order->check)) { $message = "Dear {$order->firstname} {$order->lastname},<br/><br/>You have just attempted making payment for order #{$order->id} on {$order->store_url}. Find the details below.<br/><br/>Name : {$order->firstname} {$order->lastname} <br/><br/>Phone number : {$order->telephone} <br/><br/>Amount : " . UtilityHelper::formatPrice($trans['amount']) . " <br/><br/>Transaction Date : {$trans['txn_date']} <br/><br/>Payment Method : {$trans['pmt_method']} <br/><br/>Payment Status : {$pay->response_code} <br/><br/>Transaction Reference Number : {$trans['pmt_txnref']} <br/><br/>Currency : {$trans['currency']} <br/><br/>Transaction Status : {$trans['trans_status']} <br/><br/>"; if ($trans['pmt_status'] == 'successful' && $trans['amount'] == $trans['merch_amt']) { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Successful Payment Notification', $message); //UtilityHelper::changeOrderStatus($order->id); $order->order_status_id = 2; $order->check = 1; $order->save(); UtilityHelper::subtractOrder($order->id); } else { if ($trans['pmt_status'] == 'pending') { } else { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Failed Payment Notification', $message); //UtilityHelper::changeOrderStatus($order->id,10); $order->order_status_id = 10; $order->check = 1; $order->save(); } } } return $order; } return false; }
?> </div> <div id="column3"> <div class="container-fluid"> <div class="inner-column3"> <div class="row-fluid"> <div class="span4"> <div class="row-fluid"> <img src="<?php echo Yii::app()->request->baseUrl; ?> /img/phone_icon.png" class="call_icon span2"/> <div class="call_order span10"> <span class="call_text">Call to order</span><br/> <span class="call_phone"><?php echo UtilityHelper::yiiparam('sitePhone'); ?> </span> </div> </div> </div> <div class="span6 offset2"> <a href="<?php echo $this->createUrl('/user/profile'); ?> " class="account_link">Account</a> <a href="<?php echo $this->createUrl('/cart/cart'); ?> "><div class="s_cart"><span><?php echo $this->getCartCount();
protected function completePaymentTransaction($response) { $order = Order::model()->findByAttributes(array('payment_code' => $response['invoice'])); $pay = PaymentTransaction::model()->findByAttributes(array('reference_number' => $response['invoice'])); $pay->query_code = $response['process_code']; $pay->response_description = $response['message']; $pay->response_code = $response['status']; $pay->approved_amount = $response['total']; $pay->save(); $total = UtilityHelper::formatPrice($order->total); $siteurl = UtilityHelper::yiiparam('siteUrl'); if (empty($order->check)) { $messg = "Dear {$order->firstname} {$order->lastname},<br/><br/>You have just attempted making payment for order #{$order->id} on {$order->store_url}. Find the details below.<br/><br/>Amount: {$total}<br/><br/>Response Description: {$response['message']}<br/><br/>Response Code: {$response['process_code']}<br/><br/>Transaction Ref No: {$response['invoice']}<br/><br/>Payment Reference: {$response['transaction_id']}<br/><br/>Transaction Date: " . date("D/M/Y") . "<br/>"; } else { if ($response['status'] == 'SUCCESS') { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Successful Payment Notification', $messg); $order->order_status_id = 2; $order->check = 1; $order->save(); UtilityHelper::subtractOrder($order->id); } else { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Failed Payment Notification', $messg); $order->order_status_id = 10; $order->check = 1; $order->save(); } } $this->logResults($response['status']); }
public function actionUpdate($id) { $model = $this->loadModel($id, $this->modelName); $description = $model->productDescriptions[0]; $image = new XUploadForm(); if (!isset($_POST[$this->modelName])) { $this->loadImages($model, 'product_images'); $this->loadImages($model, 'thumbs', 'thumbs'); } $this->loadProductOption($model->id); $this->loadProductAttribute($model->id); $this->loadProductDiscount($model->id); $this->loadProductSpecial($model->id); $this->performAjaxValidation(array($model, $description), 'product-form'); $userImages = Yii::app()->user->getState('product_images'); $thumbs = Yii::app()->user->getState('thumbs'); if (isset($_POST[$this->modelName])) { $model->setAttributes($_POST[$this->modelName]); $description->setAttributes($_POST[$this->modelName . 'Description']); $suc = Yii::t('info', 'Product was successfully updated'); $err = Yii::t('info', 'Could not update Product'); if (Yii::app()->user->hasState('thumbs')) { if ($this->validateProduct($model, $description)) { if ($model->save()) { $description->product_id = $model->id; $description->link = strtolower(str_replace(' ', '-', preg_replace('!\\s+!', ' ', trim(preg_replace("/[^A-Za-z ]/", ' ', $description->name))))); $description->save(); $this->deleteImages($model, 'thumbs'); $this->addImages($model->id, 'Image', 'thumbs', 'Product'); $tpath = realpath(UtilityHelper::yiiparam('frontPath') . '/www' . $model->thumbs[0]->source); $timage = Yii::app()->image->load($tpath); $timage->resize(200, 200); $timage->save(); $this->productUpdate($model); Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc); if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_view', array('model' => $model, 'description' => $description, 'option' => $this->_productoption, 'attribute' => $this->_productattribute), false, true); Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->id)); } } else { Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err); } } } } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_form_product', array('model' => $model, 'description' => $description, 'option' => $this->_productoption, 'attribute' => $this->_productattribute, 'thumbs' => $thumbs, 'image' => $image, 'userImages' => $userImages, 'discount' => $this->_productdiscount, 'special' => $this->_productspecial), false, true); Yii::app()->end(); } $this->render('update', array('model' => $model, 'description' => $description, 'option' => $this->_productoption, 'attribute' => $this->_productattribute, 'thumbs' => $thumbs, 'image' => $image, 'userImages' => $userImages, 'discount' => $this->_productdiscount, 'special' => $this->_productspecial)); }
<?php $this->widget('bootstrap.widgets.TbAlert'); ?> <?php $this->widget('bootstrap.widgets.TbDetailView', array('data' => $model, 'attributes' => array(array('name' => 'name', 'header' => 'Name', 'value' => $model->getName()), 'id', 'model', 'sku', 'upc', 'ean', 'jan', 'isbn', 'mpn', 'location', 'quantity', 'stock_status_id', array('name' => 'image', 'type' => 'raw', 'value' => !empty($model->thumbs) ? TbHtml::image(TbHtml::encode(UtilityHelper::yiiparam('frontPath') . '/www' . $model->thumbs[0]->source), Yii::t('label', 'Image')) : null, 'cssClass' => 'gridimage'), 'manufacturer_id', 'shipping', 'price', 'points', 'tax_class_id', 'date_available', 'weight', 'weight_class_id', 'length', 'width', 'height', 'length_class_id', 'subtract', 'minimum', 'sort_order', 'status', 'date_added', 'date_modified', 'viewed'))); ?> <div class="hlinks hide"> <div class="uid"><?php echo $model->id; ?> </div> </div>
public function addImages($id, $imageClass, $svar = 'images', $model_name) { //If we have pending images $class = $imageClass; if (Yii::app()->user->hasState($svar)) { $userImages = Yii::app()->user->getState($svar); //Resolve the final path for our images $path = UtilityHelper::yiiparam('frontPath') . "/www/uploads/{$id}/"; //Create the folder and give permissions if it doesnt exists if (!is_dir($path)) { mkdir($path); chmod($path, 0777); } //Now lets create the corresponding models and move the files //$image = $userImages[0]; foreach ($userImages as $image) { if (is_file($image["path"])) { if (rename($image["path"], $path . $image["filename"])) { chmod($path . $image["filename"], 0777); $img = new $imageClass(); $img->size = $image["size"]; $img->mime = $image["mime"]; $img->name = $image["name"]; $img->source = "/uploads/{$id}/" . $image["filename"]; if (isset($image["sort_order"])) { $img->sort_order = $image["sort_order"]; } if ($class == 'ProductImage') { $img->product_id = $id; } else { $img->model_name = $model_name; $img->model_id = $id; } if (!$img->save()) { //Its always good to log something Yii::log("Could not save Image:\n" . CVarDumper::dumpAsString($img->getErrors()), CLogger::LEVEL_ERROR); //this exception will rollback the transaction //print_r($img->getErrors()); throw new Exception('Could not save Image'); } } } else { //You can also throw an execption here to rollback the transaction //echo $image["path"]." is not a file"; Yii::log($image["path"] . " is not a file:\n" . CVarDumper::dumpAsString($userImages), CLogger::LEVEL_WARNING); } } //Clear the user's session Yii::app()->user->setState($svar, NULL); } }