Esempio n. 1
0
 public function action()
 {
     if (isset($_POST['action']) && $_POST['action'] == 'save_address') {
         $customer = $this->customerService->getCurrent();
         switch ($this->wp->getQueryParameter('edit-address')) {
             case 'shipping':
                 $address = $customer->getShippingAddress();
                 break;
             case 'billing':
             default:
                 $address = $customer->getBillingAddress();
                 break;
         }
         $errors = array();
         if ($address instanceof CompanyAddress) {
             $address->setCompany(trim(htmlspecialchars(strip_tags($_POST['address']['company']))));
             $address->setVatNumber(trim(htmlspecialchars(strip_tags($_POST['address']['euvatno']))));
         }
         $address->setPhone(trim(htmlspecialchars(strip_tags($_POST['address']['phone']))));
         $address->setFirstName(trim(htmlspecialchars(strip_tags($_POST['address']['first_name']))));
         $address->setLastName(trim(htmlspecialchars(strip_tags($_POST['address']['last_name']))));
         $address->setAddress(trim(htmlspecialchars(strip_tags($_POST['address']['address']))));
         $address->setCity(trim(htmlspecialchars(strip_tags($_POST['address']['city']))));
         $postcode = trim(htmlspecialchars(strip_tags($_POST['address']['postcode'])));
         if ($this->options->get('shopping.validate_zip') && !Validation::isPostcode($postcode, $address->getCountry())) {
             $errors[] = __('Postcode is not valid!', 'jigoshop');
         } else {
             $address->setPostcode($postcode);
         }
         $country = trim(htmlspecialchars(strip_tags($_POST['address']['country'])));
         if (!Country::exists($country)) {
             $errors[] = sprintf(__('Country "%s" does not exists.', 'jigoshop'), $country);
         } else {
             $address->setCountry($country);
         }
         $state = trim(htmlspecialchars(strip_tags($_POST['address']['state'])));
         if (Country::hasStates($address->getCountry()) && !Country::hasState($address->getCountry(), $state)) {
             $errors[] = sprintf(__('Country "%s" does not have state "%s".', 'jigoshop'), Country::getName($address->getCountry()), $state);
         } else {
             $address->setState($state);
         }
         $email = trim(htmlspecialchars(strip_tags($_POST['address']['email'])));
         if (!Validation::isEmail($email)) {
             $errors[] = __('Invalid email address', 'jigoshop');
         } else {
             $address->setEmail($email);
         }
         if (!empty($errors)) {
             $this->messages->addError(join('<br/>', $errors), false);
         } else {
             $this->customerService->save($customer);
             $this->messages->addNotice(__('Address saved.', 'jigoshop'));
             $this->wp->redirectTo($this->options->getPageId(Pages::ACCOUNT));
         }
     }
 }
Esempio n. 2
0
 /**
  * Validates whether
  *
  * @param OrderInterface $cart
  */
 public function validate(OrderInterface $cart)
 {
     $customer = $cart->getCustomer();
     $billingErrors = $this->validateAddress($customer->getBillingAddress());
     if ($customer->getBillingAddress()->getEmail() == null) {
         $billingErrors[] = __('Email address is empty.', 'jigoshop');
     }
     if ($customer->getBillingAddress()->getPhone() == null) {
         $billingErrors[] = __('Phone is empty.', 'jigoshop');
     }
     if (!Validation::isEmail($customer->getBillingAddress()->getEmail())) {
         $billingErrors[] = __('Email address is invalid.', 'jigoshop');
     }
     $shippingErrors = $this->validateAddress($customer->getShippingAddress());
     $billingErrors = $this->wp->applyFilters('jigoshop\\service\\cart\\billing_address_validation', $billingErrors, $customer->getBillingAddress());
     $shippingErrors = $this->wp->applyFilters('jigoshop\\service\\cart\\shipping_address_validation', $shippingErrors, $customer->getShippingAddress());
     $error = '';
     if (!empty($billingErrors)) {
         $error .= $this->prepareAddressError(__('Billing address is not valid.', 'jigoshop'), $billingErrors);
     }
     if (!empty($shippingErrors)) {
         $error .= $this->prepareAddressError(__('Shipping address is not valid.', 'jigoshop'), $shippingErrors);
     }
     if (!empty($error)) {
         throw new Exception($error);
     }
 }
Esempio n. 3
0
 /**
  * Validates and returns properly sanitized options.
  *
  * @param $settings array Input options.
  *
  * @return array Sanitized result.
  */
 public function validateOptions($settings)
 {
     $settings['enabled'] = $settings['enabled'] == 'on';
     $settings['title'] = trim(htmlspecialchars(strip_tags($settings['title'])));
     $settings['description'] = trim(htmlspecialchars(strip_tags($settings['description'], '<p><a><strong><em><b><i>')));
     if (!Validation::isEmail($settings['email'])) {
         $settings['email'] = '';
         if ($settings['enabled']) {
             $this->messages->addWarning(__('Email address is not valid.', 'jigoshop'));
         }
     }
     $settings['send_shipping'] = $settings['send_shipping'] == 'on';
     $settings['force_payment'] = $settings['force_payment'] == 'on';
     $settings['test_mode'] = $settings['test_mode'] == 'on';
     if (!Validation::isEmail($settings['test_email'])) {
         $settings['test_email'] = '';
         if ($settings['enabled']) {
             $this->messages->addWarning(__('Test email address is not valid.', 'jigoshop'));
         }
     }
     return $settings;
 }