Пример #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));
         }
     }
 }
Пример #2
0
 /**
  * Ajax action for changing country.
  */
 public function ajaxChangeCountry()
 {
     $customer = $this->customerService->getCurrent();
     if (!Country::isAllowed($_POST['value'])) {
         $locations = array_map(function ($location) {
             return Country::getName($location);
         }, $this->options->get('shopping.selling_locations'));
         echo json_encode(array('success' => false, 'error' => sprintf(__('This location is not supported, we sell only to %s.'), join(', ', $locations))));
         exit;
     }
     if ($customer->hasMatchingAddresses()) {
         $customer->getBillingAddress()->setCountry($_POST['value']);
     }
     $customer->getShippingAddress()->setCountry($_POST['value']);
     $this->customerService->save($customer);
     $cart = $this->cartService->getCurrent();
     $cart->setCustomer($customer);
     $this->cartService->save($cart);
     $response = $this->getAjaxLocationResponse($customer, $cart);
     echo json_encode($response);
     exit;
 }
Пример #3
0
 /**
  * Executes actions associated with selected page.
  */
 public function action()
 {
     $cart = $this->cartService->getCurrent();
     if ($cart->isEmpty()) {
         $this->messages->addWarning(__('Your cart is empty, please add products before proceeding.', 'jigoshop'));
         $this->wp->redirectTo($this->options->getPageId(Pages::SHOP));
     }
     if (!$this->isAllowedToEnterCheckout()) {
         $this->messages->addError(__('You need to log in before processing to checkout.', 'jigoshop'));
         $this->wp->redirectTo($this->options->getPageId(Pages::CART));
     }
     if (isset($_POST['action']) && $_POST['action'] == 'purchase') {
         try {
             $allowRegistration = $this->options->get('shopping.allow_registration');
             if ($allowRegistration && !$this->wp->isUserLoggedIn()) {
                 $this->createUserAccount();
             }
             if (!$this->isAllowedToCheckout($cart)) {
                 if ($allowRegistration) {
                     throw new Exception(__('You need either to log in or create account to purchase.', 'jigoshop'));
                 }
                 throw new Exception(__('You need to log in before purchasing.', 'jigoshop'));
             }
             if ($this->options->get('advanced.pages.terms') > 0 && (!isset($_POST['terms']) || $_POST['terms'] != 'on')) {
                 throw new Exception(__('You need to accept terms &amp; conditions!', 'jigoshop'));
             }
             $this->cartService->validate($cart);
             $this->customerService->save($cart->getCustomer());
             if (!Country::isAllowed($cart->getCustomer()->getBillingAddress()->getCountry())) {
                 $locations = array_map(function ($location) {
                     return Country::getName($location);
                 }, $this->options->get('shopping.selling_locations'));
                 throw new Exception(sprintf(__('This location is not supported, we sell only to %s.'), join(', ', $locations)));
             }
             $shipping = $cart->getShippingMethod();
             if ($this->isShippingRequired($cart) && (!$shipping || !$shipping->isEnabled())) {
                 throw new Exception(__('Shipping is required for this order. Please select shipping method.', 'jigoshop'));
             }
             $payment = $cart->getPaymentMethod();
             $isPaymentRequired = $this->isPaymentRequired($cart);
             $this->wp->doAction('jigoshop\\checkout\\payment', $payment);
             if ($isPaymentRequired && (!$payment || !$payment->isEnabled())) {
                 throw new Exception(__('Payment is required for this order. Please select payment method.', 'jigoshop'));
             }
             $order = $this->orderService->createFromCart($cart);
             /** @var Order $order */
             $order = $this->wp->applyFilters('jigoshop\\checkout\\order', $order);
             $this->orderService->save($order);
             $this->cartService->remove($cart);
             $url = '';
             if ($isPaymentRequired) {
                 $url = $payment->process($order);
             } else {
                 $order->setStatus(\Jigoshop\Helper\Order::getStatusAfterCompletePayment($order));
                 $this->orderService->save($order);
             }
             // Redirect to thank you page
             if (empty($url)) {
                 $url = $this->wp->getPermalink($this->wp->applyFilters('jigoshop\\checkout\\redirect_page_id', $this->options->getPageId(Pages::THANK_YOU)));
                 $url = $this->wp->getHelpers()->addQueryArg(array('order' => $order->getId(), 'key' => $order->getKey()), $url);
             }
             $this->wp->wpRedirect($url);
             exit;
         } catch (Exception $e) {
             $this->messages->addError($e->getMessage());
         }
     }
 }
Пример #4
0
 /**
  * @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);
 }
Пример #5
0
?>
&nbsp;</dd>
	<dt><?php 
echo __('State/province', 'jigoshop');
?>
</dt>
	<dd><?php 
echo Country::getStateName($address->getCountry(), $address->getState());
?>
&nbsp;</dd>
	<dt><?php 
echo __('Country', 'jigoshop');
?>
</dt>
	<dd><?php 
echo Country::getName($address->getCountry());
?>
&nbsp;</dd>
	<?php 
if ($address->getPhone()) {
    ?>
		<dt><?php 
    echo __('Phone', 'jigoshop');
    ?>
</dt>
		<dd><?php 
    echo $address->getPhone();
    ?>
&nbsp;</dd>
	<?php 
}
Пример #6
0
 /**
  * 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()), ' ,');
 }
Пример #7
0
 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);
     }
 }