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); }
/** * 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); }
public function actionEdititem() { if (Yii::app()->user->isGuest) { _xls_404(); } $model = new WishlistEditForm(); error_log(print_r($_POST, true)); // collect user input data if (isset($_POST['WishlistEditForm'])) { $model->attributes = $_POST['WishlistEditForm']; if ($model->validate()) { $strCode = $model->code; $intRow = $model->id; //Make sure code we've been passed is valid $objWishlist = Wishlist::model()->findByAttributes(array('gift_code' => $strCode)); if (!$objWishlist->Visible) { _xls_404(); } $objWishrow = WishlistItem::model()->findByAttributes(array('id' => $intRow, 'registry_id' => $objWishlist->id)); $objWishrow->qty = $model->qty; $objWishrow->qty_received = $model->qty_received; $objWishrow->comment = $model->comment; $objWishrow->priority = $model->priority; if (!$objWishrow->save()) { Yii::log("Error saving wish list item " . print_r($objWishrow->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); $response_array['status'] = 'error'; $response_array['errormsg'] = _xls_convert_errors_display(_xls_convert_errors($objWishrow->getErrors())); } else { $response_array = array('status' => "success", 'code' => $objWishlist->gift_code, 'id' => $objWishrow->id, 'qty' => $objWishrow->qty, 'qty_received' => $objWishrow->qty_received, 'priority' => $objWishrow->priority, 'comment' => $objWishrow->comment, 'reload' => true); } } else { $response_array['status'] = 'error'; $response_array['errormsg'] = _xls_convert_errors_display(_xls_convert_errors($model->getErrors())); } echo json_encode($response_array); } else { $this->getEditForm(); } }
/** * 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))); } }