/** * Save chosen third-party category */ public function actionIntCatSave() { $service = Yii::app()->getRequest()->getQuery('service'); $strSelected = Yii::app()->getRequest()->getQuery('selected'); $arrSelected = explode("|", $strSelected); if (count($arrSelected) > 1) { $objCategory = Category::model()->findByPk($arrSelected[0]); if ($objCategory instanceof Category) { $strTable = "Category" . ucfirst($service); $objIntCategory = $strTable::model()->findByPk($arrSelected[1]); if ($objIntCategory instanceof $strTable) { if (!$objIntCategory->isUsable) { echo json_encode(ucfirst($service) . " does not allow you to pick this category without choosing a further subcategory."); return; } CategoryIntegration::model()->deleteAllByAttributes(array('category_id' => $objCategory->id, 'module' => $service)); $objCI = new CategoryIntegration(); $objCI->category_id = $objCategory->id; $objCI->module = $service; $objCI->foreign_id = $objIntCategory->id; switch (count($arrSelected)) { case 4: $objCI->extra = $arrSelected[2] . "," . $arrSelected[3]; break; case 3: $objCI->extra = $arrSelected[2]; break; case 2: $objCI->extra = null; break; } if (!$objCI->save()) { echo json_encode(_xls_convert_errors($objCI->getErrors())); } else { echo json_encode("success|" . $objIntCategory->name0); } } else { echo json_encode(ucfirst($service) . " category not found"); } } else { echo json_encode("Web Store category not found"); } } else { echo json_encode("Array error"); } }
public function actionNewcountry() { if (isset($_POST['Country'])) { $obj = new Country(); $obj->attributes = $_POST['Country']; $obj->active = 1; $obj->sort_order = 10; if ($obj->validate()) { if ($obj->save()) { echo "success"; } else { echo _xls_convert_errors_display(_xls_convert_errors($obj->getErrors())); } } else { echo _xls_convert_errors_display(_xls_convert_errors($obj->getErrors())); } } }
/** * The new checkout views display errors in a specific way. * * We take the errors that the framework generates, * create an html string for sending to the view. * * @return string - html */ protected function formatErrors() { $flashErrors = array(); foreach (Yii::app()->user->getFlashes(false) as $key => $msg) { if (in_array($key, array('warning', 'error'))) { $flashErrors[$key] = Yii::app()->user->getFlash($key); } } $controllerErrors = $this->checkoutForm->getErrors() + $flashErrors; if (count($controllerErrors) === 0) { return null; } // $arrAllErrors is an array of array of errors. $strErrors = _xls_convert_errors_display(_xls_convert_errors(_xls_make2dimArray($controllerErrors))); if (str_replace("\n", "", $strErrors) === "") { return null; } // Format errors for html display. $strErrors = str_replace("\n", "<br>", $strErrors); // Remove first break from string. $strErrors = preg_replace("/<br>/", "", $strErrors, 1); return sprintf('<div class="form-error"><p>%s</p></div>', $strErrors); }
public function actionEmail() { if (Yii::app()->user->isGuest) { _xls_404(); } $model = new ShareForm(); if (isset($_POST['ShareForm'])) { $model->attributes = $_POST['ShareForm']; if ($model->validate()) { $strCode = $model->code; //Make sure code we've been passed is valid $objWishlist = Wishlist::model()->findByAttributes(array('gift_code' => $strCode)); if (!$objWishlist->Visible) { _xls_404(); } if (!Yii::app()->user->isGuest) { $objCustomer = Customer::model()->findByPk(Yii::app()->user->Id); $model->fromEmail = $objCustomer->email; $model->fromName = $objCustomer->fullname; } $strHtmlBody = $this->renderPartial('/mail/_cart', array('model' => $model), true); $strSubject = _xls_format_email_subject('EMAIL_SUBJECT_WISHLIST', $objWishlist->customer->fullname, null); $objEmail = new EmailQueue(); $objEmail->customer_id = $objWishlist->customer_id; $objEmail->htmlbody = $strHtmlBody; $objEmail->subject = $strSubject; $objEmail->to = $model->toEmail; $objHtml = new HtmlToText(); //If we get back false, it means conversion failed which 99.9% of the time means improper HTML. $strPlain = $objHtml->convert_html_to_text($strHtmlBody); if ($strPlain !== false) { $objEmail->plainbody = $strPlain; } $objEmail->save(); $response_array = array('status' => "success", 'message' => Yii::t('wishlist', 'Your wish list has been sent'), 'url' => CController::createUrl('site/sendemail', array("id" => $objEmail->id)), 'reload' => true); } else { $response_array['status'] = 'error'; $response_array['errormsg'] = _xls_convert_errors($model->getErrors()); } echo json_encode($response_array); } }
/** * Check that the promo code applied to the cart is still valid. * If the promo code is no longer valid, remove it and return an error * message. * * @return array|null Null if the promo code is still valid. If the promo * code is invalid an array with the following keys will be returned: * code => The promo code. * reason => The reason that the promo code is invalid. */ public function revalidatePromoCode() { if ($this->fk_promo_id === null) { // No promo code applied. return null; } $hasInvalidPromoCode = false; $objPromoCode = PromoCode::model()->findByPk($this->fk_promo_id); if ($objPromoCode === null) { // The promo code has been deleted from Web Store. $hasInvalidPromoCode = true; } else { $objPromoCode->validatePromocode('code', null); $arrErrors = $objPromoCode->getErrors(); if (count($arrErrors) > 0) { // After validating the promo code, there were errors. $hasInvalidPromoCode = true; } } if ($hasInvalidPromoCode === false) { return null; } if ($objPromoCode === null) { $promoCodeCode = ''; $reason = 'This Promo Code has been disabled.'; } else { $promoCodeCode = $objPromoCode->code; $reason = _xls_convert_errors_display(_xls_convert_errors($arrErrors)); } return array('code' => $promoCodeCode, 'reason' => $reason); }
/** * Process manual payment on admin panel * * @param $objCart * @param $objCartPayment * @return string 'success' or error messages from the models */ public static function processManualPayment($objCart, $objCartPayment) { $objCart->setScenario('manual'); $objCartPayment->setScenario('manual'); $objCart->attributes = $_POST['Cart']; $objCartPayment->attributes = $_POST['CartPayment']; switch ($objCart->cart_type) { case CartType::order: $objCart->status = OrderStatus::AwaitingProcessing; $objCartPayment->payment_status = OrderStatus::Completed; $objCartPayment->datetime_posted = new CDbExpression('NOW()'); break; case CartType::awaitpayment: $objCart->status = OrderStatus::AwaitingPayment; $objCartPayment->payment_status = NULL; $objCartPayment->datetime_posted = NULL; break; } if ($objCart->validate() && $objCartPayment->validate()) { $objCart->save(); $objCartPayment->save(); $objEvent = new CEventOrder('CartController', 'onCreateOrder', $objCart->id_str); _xls_raise_events('CEventOrder', $objEvent); return "success"; } else { return implode(" ", _xls_convert_errors($objCart->getErrors() + $objCartPayment->getErrors())); } }
/** * Validate a checkout form. * @throws CException with a helpfully translated message if the form does not validate. */ protected static function validateCheckoutForm($checkoutForm) { if ($checkoutForm->validate() === true) { return; } $arrErrors = $checkoutForm->getErrors(); if (count($arrErrors) > 0) { Yii::log("Checkout Errors " . print_r($arrErrors, true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); throw new CException(Yii::t('checkout', 'Oops, cannot calculate shipping quite yet. Please complete shipping address information and click Calculate again.') . "\n" . _xls_convert_errors_display(_xls_convert_errors($arrErrors))); } }