コード例 #1
0
ファイル: EditAddress.php プロジェクト: jigoshop/Jigoshop2
 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));
         }
     }
 }
コード例 #2
0
ファイル: CartService.php プロジェクト: jigoshop/Jigoshop2
 /**
  * @param $address Address
  *
  * @return array
  */
 private function validateAddress($address)
 {
     $errors = array();
     if ($address->isValid()) {
         if ($address->getFirstName() == null) {
             $errors[] = __('First name is empty.', 'jigoshop');
         }
         if ($address->getLastName() == null) {
             $errors[] = __('Last name is empty.', 'jigoshop');
         }
         if ($address->getAddress() == null) {
             $errors[] = __('Address is empty.', 'jigoshop');
         }
         if ($address->getCountry() == null) {
             $errors[] = __('Country is not selected.', 'jigoshop');
         }
         if ($address->getState() == null) {
             $errors[] = __('State or province is not selected.', 'jigoshop');
         }
         if ($address->getCity() == null) {
             $errors[] = __('City is empty.', 'jigoshop');
         }
         if ($address->getPostcode() == null) {
             $errors[] = __('Postcode is empty.', 'jigoshop');
         }
         if ($this->options->get('shopping.validate_zip') && !Validation::isPostcode($address->getPostcode(), $address->getCountry())) {
             $errors[] = __('Invalid postcode.', 'jigoshop');
         }
     }
     if (!Country::exists($address->getCountry())) {
         $errors[] = sprintf(__('Country "%s" does not exist.', 'jigoshop'), $address->getCountry());
     }
     if (Country::hasStates($address->getCountry()) && !Country::hasState($address->getCountry(), $address->getState())) {
         $errors[] = sprintf(__('Country "%s" does not have state "%s".', 'jigoshop'), $address->getCountry(), $address->getState());
     }
     return $errors;
 }
コード例 #3
0
ファイル: FlatRate.php プロジェクト: jigoshop/Jigoshop2
 /**
  * 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['is_taxable'] = $settings['is_taxable'] == 'on';
     if (!in_array($settings['type'], array_keys($this->types))) {
         $settings['type'] = $this->options['type'];
         $this->messages->addWarning(__('Type is invalid - value is left unchanged.', 'jigoshop'));
     }
     if (!is_numeric($settings['cost'])) {
         $settings['cost'] = $this->options['cost'];
         $this->messages->addWarning(__('Cost was invalid - value is left unchanged.', 'jigoshop'));
     }
     if ($settings['cost'] >= 0) {
         $settings['cost'] = (double) $settings['cost'];
     } else {
         $settings['cost'] = $this->options['cost'];
         $this->messages->addWarning(__('Cost was below 0 - value is left unchanged.', 'jigoshop'));
     }
     if (!is_numeric($settings['fee'])) {
         $settings['fee'] = $this->options['fee'];
         $this->messages->addWarning(__('Fee was invalid - value is left unchanged.', 'jigoshop'));
     }
     if ($settings['fee'] >= 0) {
         $settings['fee'] = (double) $settings['fee'];
     } else {
         $settings['fee'] = $this->options['fee'];
         $this->messages->addWarning(__('Fee was below 0 - value is left unchanged.', 'jigoshop'));
     }
     if (!in_array($settings['available_for'], array_keys($this->availability))) {
         $settings['available_for'] = $this->options['available_for'];
         $this->messages->addWarning(__('Availability is invalid - value is left unchanged.', 'jigoshop'));
     }
     if ($settings['available_for'] === 'specific') {
         $settings['countries'] = array_filter($settings['countries'], function ($item) {
             return Country::exists($item);
         });
     } else {
         $settings['countries'] = array();
     }
     return $settings;
 }
コード例 #4
0
ファイル: CustomerList.php プロジェクト: jigoshop/Jigoshop2
 private function getRow($user, $columnKey)
 {
     switch ($columnKey) {
         case 'customer_name':
             return $user->last_name && $user->first_name ? $user->last_name . ', ' . $user->first_name : '-';
         case 'username':
             return $user->user_login;
         case 'location':
             $stateCode = $this->wp->getUserMeta($user->ID, 'billing_state', true);
             $countryCode = $this->wp->getUserMeta($user->ID, 'billing_country', true);
             $state = Country::hasState($countryCode, $stateCode) ? Country::getStateName($countryCode, $stateCode) : $stateCode;
             $country = Country::exists($countryCode) ? Country::getName($countryCode) : $countryCode;
             $value = '';
             if ($state) {
                 $value .= $state . ', ';
             }
             $value .= $country;
             if ($value) {
                 return $value;
             } else {
                 return '-';
             }
         case 'email':
             return '<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>';
         case 'spent':
             return Product::formatPrice($this->getCustomerTotalSpent($user->ID));
         case 'orders':
             return $this->getCustomerOrderCount($user->ID);
         case 'last_order':
             $lastOrder = $this->getCustomerLastOrder($user->ID);
             if ($lastOrder) {
                 /** @var \Jigoshop\Entity\Order $order */
                 $order = $this->orderService->find($lastOrder->order_id);
                 return '<a href="' . admin_url('post.php?post=' . $lastOrder->order_id . '&action=edit') . '">#' . $order->getNumber() . '</a> &ndash; ' . date_i18n(get_option('date_format'), strtotime($lastOrder->order_date));
             }
             return '-';
         case 'user_actions':
             $actions = array();
             $actions['edit'] = array('url' => admin_url('user-edit.php?user_id=' . $user->ID), 'name' => __('Edit', 'jigoshop'), 'action' => 'edit');
             $actions = $this->wp->applyFilters('jigoshop\\admin\\reports\\table\\customer_list\\user_actions', $actions, $user);
             return $actions;
         default:
             return $this->wp->applyFilters('jigoshop\\admin\\reports\\table\\customer_list\\row', '', $user, $columnKey);
     }
 }