public function displayRules() { $classes = array(); foreach ($this->options['classes'] as $class) { $classes[$class['class']] = $class['label']; } $countries = array_merge(array('' => __('All countries', 'jigoshop')), Country::getAll()); Render::output('admin/settings/tax/rules', array('rules' => $this->taxService->getRules(), 'classes' => $classes, 'countries' => $countries)); }
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)); } } }
/** * Validate and sanitize input values. * * @param array $settings Input fields. * * @return array Sanitized and validated output. * @throws ValidationException When some items are not valid. */ public function validate($settings) { $settings['show_message'] = $settings['show_message'] == 'on'; $settings['demo_store'] = $settings['demo_store'] == 'on'; if (!in_array($settings['country'], array_keys(Country::getAll()))) { $this->messages->addError(__('Invalid shop location (country), please select again.', 'jigoshop')); $settings['country'] = ''; } return $settings; }
/** * Validate and sanitize input values. * * @param array $settings Input fields. * * @return array Sanitized and validated output. * @throws ValidationException When some items are not valid. */ public function validate($settings) { $settings['catalog_per_page'] = (int) $settings['catalog_per_page']; if ($settings['catalog_per_page'] <= 0) { $this->messages->addWarning(sprintf(__('Invalid products per page value: "%d". Value set to 12.', 'jigoshop'), $settings['catalog_per_page'])); $settings['catalog_per_page'] = 12; } if (!in_array($settings['catalog_order_by'], array_keys($this->catalogOrderBy))) { $this->messages->addWarning(sprintf(__('Invalid products sorting: "%s". Value set to %s.', 'jigoshop'), $settings['catalog_order_by'], $this->catalogOrderBy['post_date'])); $settings['catalog_order_by'] = 'post_date'; } if (!in_array($settings['catalog_order'], array_keys($this->catalogOrder))) { $this->messages->addWarning(sprintf(__('Invalid products sorting orientation: "%s". Value set to %s.', 'jigoshop'), $settings['catalog_order'], $this->catalogOrder['DESC'])); $settings['catalog_order'] = 'DESC'; } $settings['hide_out_of_stock'] = $settings['hide_out_of_stock'] == 'on'; $settings['enable_verification_message'] = $settings['enable_verification_message'] == 'on'; $settings['guest_purchases'] = $settings['guest_purchases'] == 'on'; $settings['show_login_form'] = $settings['show_login_form'] == 'on'; $settings['allow_registration'] = $settings['allow_registration'] == 'on'; $settings['login_for_downloads'] = $settings['login_for_downloads'] == 'on'; $settings['force_ssl'] = $settings['force_ssl'] == 'on'; $settings['validate_zip'] = $settings['validate_zip'] == 'on'; $settings['restrict_selling_locations'] = $settings['restrict_selling_locations'] == 'on'; if (!$settings['restrict_selling_locations']) { $settings['selling_locations'] = array(); } else { $settings['selling_locations'] = array_intersect($settings['selling_locations'], array_keys(Country::getAll())); } if (!in_array($settings['redirect_add_to_cart'], array_keys($this->addToCartRedirectionOptions))) { $this->messages->addWarning(sprintf(__('Invalid add to cart redirection: "%s". Value set to %s.', 'jigoshop'), $settings['redirect_add_to_cart'], $this->addToCartRedirectionOptions['same_page'])); $settings['redirect_add_to_cart'] = 'same_page'; } if (!in_array($settings['redirect_continue_shopping'], array_keys($this->backToShopRedirectionOptions))) { $this->messages->addWarning(sprintf(__('Invalid continue shopping redirection: "%s". Value set to %s.', 'jigoshop'), $settings['redirect_continue_shopping'], $this->backToShopRedirectionOptions['product_list'])); $settings['redirect_continue_shopping'] = 'product_list'; } return $settings; }
/** * @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[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'); ?> </a> <button class="btn btn-success pull-right" name="action" value="save_address"><?php
/** * 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; }
/** * @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); }
?> </dd> <dt><?php echo __('State/province', 'jigoshop'); ?> </dt> <dd><?php echo Country::getStateName($address->getCountry(), $address->getState()); ?> </dd> <dt><?php echo __('Country', 'jigoshop'); ?> </dt> <dd><?php echo Country::getName($address->getCountry()); ?> </dd> <?php if ($address->getPhone()) { ?> <dt><?php echo __('Phone', 'jigoshop'); ?> </dt> <dd><?php echo $address->getPhone(); ?> </dd> <?php }
?> "><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'))); ?> </div> </div>
/** * Checks whether provided customer needs to be taxed. * * @param Entity $customer Customer to check. * * @return boolean Whether customer needs to be taxed. */ public function isTaxable(Entity $customer) { $country = $this->options->get('general.country'); $customerCountry = $customer->getTaxAddress()->getCountry(); if (Country::isEU($country)) { return Country::isEU($customerCountry); } return $country == $customerCountry; }
/** * 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)); }
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); } }