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; }
/** * Abstraction for location update response. * Prepares and returns array of updated data for location change requests. * * @param Customer $customer The customer (for location). * @param \Jigoshop\Entity\Cart $cart Current cart. * * @return array */ private function getAjaxLocationResponse(Customer $customer, \Jigoshop\Entity\Cart $cart) { $response = $this->getAjaxCartResponse($cart); $address = $customer->getShippingAddress(); // Add some additional fields $response['has_states'] = Country::hasStates($address->getCountry()); $response['states'] = Country::getStates($address->getCountry()); $response['html']['estimation'] = $address->getLocation(); return $response; }
/** * Returns list of default fields for shipping section. * * @param Address $address Address to fill values for. * * @return array Default fields. */ public function getDefaultShippingFields(Address $address) { return ProductHelper::getBasicShippingFields(array('first_name' => array('value' => $address->getFirstName(), 'columnSize' => 6), 'last_name' => array('value' => $address->getLastName(), 'columnSize' => 6), 'company' => array('value' => $address instanceof CompanyAddress ? $address->getCompany() : '', 'columnSize' => 12), 'address' => array('value' => $address->getAddress(), 'columnSize' => 12), 'country' => array('options' => Country::getAllowed(), 'value' => $address->getCountry(), 'columnSize' => 6), 'state' => array('type' => Country::hasStates($address->getCountry()) ? 'select' : 'text', 'options' => Country::getStates($address->getCountry()), 'value' => $address->getState(), 'columnSize' => 6), 'city' => array('value' => $address->getCity(), 'columnSize' => 6), 'postcode' => array('value' => $address->getPostcode(), 'columnSize' => 6))); }
\Jigoshop\Helper\Forms::text(array('name' => 'address[first_name]', 'label' => __('First name', 'jigoshop'), 'value' => $address->getFirstName())); ?> <?php \Jigoshop\Helper\Forms::text(array('name' => 'address[last_name]', 'label' => __('Last name', 'jigoshop'), 'value' => $address->getLastName())); ?> <?php \Jigoshop\Helper\Forms::text(array('name' => 'address[address]', 'label' => __('Address', 'jigoshop'), 'value' => $address->getAddress())); ?> <?php \Jigoshop\Helper\Forms::text(array('name' => 'address[city]', 'label' => __('City', 'jigoshop'), 'value' => $address->getCity())); ?> <?php \Jigoshop\Helper\Forms::text(array('name' => 'address[postcode]', 'label' => __('Postcode', 'jigoshop'), 'value' => $address->getPostcode())); ?> <?php \Jigoshop\Helper\Forms::field(Country::hasStates($address->getCountry()) ? 'select' : 'text', array('name' => 'address[state]', 'label' => __('State/province', 'jigoshop'), 'value' => $address->getState(), 'options' => Country::getStates($address->getCountry()))); ?> <?php \Jigoshop\Helper\Forms::select(array('name' => 'address[country]', 'label' => __('Country', 'jigoshop'), 'value' => $address->getCountry(), 'options' => Country::getAllowed())); ?> <?php \Jigoshop\Helper\Forms::text(array('name' => 'address[phone]', 'label' => __('Phone', 'jigoshop'), 'value' => $address->getPhone())); ?> <?php \Jigoshop\Helper\Forms::text(array('name' => 'address[email]', 'label' => __('Email', 'jigoshop'), 'value' => $address->getEmail())); ?> <a href="<?php echo $myAccountUrl; ?> " class="btn btn-default"><?php _e('Go back to My account', 'jigoshop');
/** * @param $order Order The order. * * @return array Available arguments with proper values. */ private function getOrderEmailArguments($order) { $billingAddress = $order->getCustomer()->getBillingAddress(); $shippingAddress = $order->getCustomer()->getShippingAddress(); return $this->wp->applyFilters('jigoshop\\emails\\order_variables', array('blog_name' => $this->wp->getBloginfo('name'), 'order_number' => $order->getNumber(), 'order_date' => $this->wp->getHelpers()->dateI18n($this->wp->getOption('date_format')), 'shop_name' => $this->options->get('general.company_name'), 'shop_address_1' => $this->options->get('general.company_address_1'), 'shop_address_2' => $this->options->get('general.company_address_2'), 'shop_tax_number' => $this->options->get('general.company_tax_number'), 'shop_phone' => $this->options->get('general.company_phone'), 'shop_email' => $this->options->get('general.company_email'), 'customer_note' => $order->getCustomerNote(), 'order_items' => $this->formatItems($order), 'subtotal' => ProductHelper::formatPrice($order->getSubtotal()), 'shipping' => ProductHelper::formatPrice($order->getShippingPrice()), 'shipping_cost' => ProductHelper::formatPrice($order->getShippingPrice()), 'shipping_cost_raw' => $order->getShippingPrice(), 'shipping_method' => $order->getShippingMethod() ? $order->getShippingMethod()->getName() : '', 'discount' => ProductHelper::formatPrice($order->getDiscount()), 'total_tax' => ProductHelper::formatPrice($order->getTotalTax()), 'total' => ProductHelper::formatPrice($order->getTotal()), 'is_local_pickup' => $order->getShippingMethod() && $order->getShippingMethod()->getId() == LocalPickup::NAME ? true : null, 'checkout_url' => $order->getStatus() == Order\Status::PENDING ? OrderHelper::getPayLink($order) : null, 'payment_method' => $order->getPaymentMethod()->getName(), 'billing_first_name' => $billingAddress->getFirstName(), 'billing_last_name' => $billingAddress->getLastName(), 'billing_company' => $billingAddress instanceof CompanyAddress ? $billingAddress->getCompany() : '', 'billing_address_1' => $billingAddress->getAddress(), 'billing_address_2' => '', 'billing_postcode' => $billingAddress->getPostcode(), 'billing_city' => $billingAddress->getCity(), 'billing_country' => Country::getName($billingAddress->getCountry()), 'billing_country_raw' => $billingAddress->getCountry(), 'billing_state' => Country::hasStates($billingAddress->getCountry()) ? Country::getStateName($billingAddress->getCountry(), $billingAddress->getState()) : $billingAddress->getState(), 'billing_state_raw' => $billingAddress->getState(), 'billing_email' => $billingAddress->getEmail(), 'billing_phone' => $billingAddress->getPhone(), 'shipping_first_name' => $shippingAddress->getFirstName(), 'shipping_last_name' => $shippingAddress->getLastName(), 'shipping_company' => $shippingAddress instanceof CompanyAddress ? $shippingAddress->getCompany() : '', 'shipping_address_1' => $shippingAddress->getAddress(), 'shipping_address_2' => '', 'shipping_postcode' => $shippingAddress->getPostcode(), 'shipping_city' => $shippingAddress->getCity(), 'shipping_country' => Country::getName($shippingAddress->getCountry()), 'shipping_country_raw' => $shippingAddress->getCountry(), 'shipping_state' => Country::hasStates($shippingAddress->getCountry()) ? Country::getStateName($shippingAddress->getCountry(), $shippingAddress->getState()) : $shippingAddress->getState(), 'shipping_state_raw' => $shippingAddress->getState()), $order); }
?> <button class="btn btn-default pull-right close" title="<?php _e('Close', 'jigoshop'); ?> "><span class="glyphicon glyphicon-remove"></span></button> </h3> </div> <div class="panel-body"> <?php \Jigoshop\Helper\Forms::select(array('name' => 'country', 'value' => $customer->getShippingAddress()->getCountry(), 'options' => Country::getAllowed())); ?> <?php \Jigoshop\Helper\Forms::hidden(array('id' => 'state', 'name' => 'state', 'value' => $customer->getShippingAddress()->getState())); ?> <?php if ($customer->getShippingAddress()->getCountry() && Country::hasStates($customer->getShippingAddress()->getCountry())) { ?> <?php \Jigoshop\Helper\Forms::select(array('id' => 'noscript_state', 'name' => 'state', 'value' => $customer->getShippingAddress()->getState(), 'options' => Country::getStates($customer->getShippingAddress()->getCountry()))); ?> <?php } else { ?> <?php \Jigoshop\Helper\Forms::text(array('id' => 'noscript_state', 'name' => 'state', 'value' => $customer->getShippingAddress()->getState())); ?> <?php } ?> <?php \Jigoshop\Helper\Forms::text(array('name' => 'postcode', 'value' => $customer->getShippingAddress()->getPostcode(), 'placeholder' => __('Postcode', 'jigoshop')));
/** * Returns location string based on current translation. * * @return string Location string. */ public function getLocation() { // TODO: Write documentation about changing customer location string return trim(sprintf(_x('%1$s, %2$s', 'customer', 'jigoshop'), Country::getName($this->getCountry()), Country::hasStates($this->getCountry()) ? Country::getStateName($this->getCountry(), $this->getState()) : $this->getState(), $this->getPostcode()), ' ,'); }
public function dataBox() { $post = $this->wp->getGlobalPost(); /** @var \Jigoshop\Entity\Order $order */ $order = $this->orderService->findForPost($post); $billingOnly = $this->options->get('shipping.only_to_billing'); $address = $order->getCustomer()->getBillingAddress(); $billingFields = $this->wp->applyFilters('jigoshop\\admin\\order\\billing_fields', ProductHelper::getBasicBillingFields(array('first_name' => array('value' => $address->getFirstName()), 'last_name' => array('value' => $address->getLastName()), 'company' => array('value' => $address instanceof Customer\CompanyAddress ? $address->getCompany() : ''), 'euvatno' => array('value' => $address instanceof Customer\CompanyAddress ? $address->getVatNumber() : ''), 'address' => array('value' => $address->getAddress()), 'city' => array('value' => $address->getCity()), 'postcode' => array('value' => $address->getPostcode()), 'country' => array('value' => $address->getCountry(), 'options' => Country::getAllowed()), 'state' => array('type' => Country::hasStates($address->getCountry()) ? 'select' : 'text', 'value' => $address->getState(), 'options' => Country::getStates($address->getCountry())), 'phone' => array('value' => $address->getPhone()), 'email' => array('value' => $address->getEmail())), $order)); $address = $order->getCustomer()->getShippingAddress(); $shippingFields = $this->wp->applyFilters('jigoshop\\admin\\order\\shipping_fields', ProductHelper::getBasicShippingFields(array('first_name' => array('value' => $address->getFirstName()), 'last_name' => array('value' => $address->getLastName()), 'company' => array('value' => $address instanceof Customer\CompanyAddress ? $address->getCompany() : ''), 'address' => array('value' => $address->getAddress()), 'city' => array('value' => $address->getCity()), 'postcode' => array('value' => $address->getPostcode()), 'country' => array('value' => $address->getCountry(), 'options' => Country::getAllowed()), 'state' => array('type' => Country::hasStates($address->getCountry()) ? 'select' : 'text', 'value' => $address->getState(), 'options' => Country::getStates($address->getCountry()))), $order)); $customers = $this->customerService->findAll(); Render::output('admin/order/dataBox', array('order' => $order, 'billingFields' => $billingFields, 'shippingFields' => $shippingFields, 'customers' => $customers, 'billingOnly' => $billingOnly)); }