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)); } } }
/** * @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; }
/** * Ajax action for changing state. */ public function ajaxChangeState() { try { $post = $this->wp->getPost((int) $_POST['order']); $this->wp->updateGlobalPost($post); /** @var \Jigoshop\Entity\Order $order */ $order = $this->orderService->findForPost($post); if ($order->getId() === null) { throw new Exception(__('Order not found.', 'jigoshop')); } switch ($_POST['type']) { case 'shipping': $address = $order->getCustomer()->getShippingAddress(); break; case 'billing': default: $address = $order->getCustomer()->getBillingAddress(); } if (Country::hasStates($address->getCountry()) && !Country::hasState($address->getCountry(), $_POST['value'])) { throw new Exception(__('Invalid state.', 'jigoshop')); } $address->setState($_POST['value']); $order = $this->rebuildOrder($order); $this->orderService->save($order); $result = $this->getAjaxResponse($order); } catch (Exception $e) { $result = array('success' => false, 'error' => $e->getMessage()); } echo json_encode($result); exit; }
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> – ' . 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); } }