Пример #1
0
 public function render()
 {
     if (!$this->wp->isUserLoggedIn()) {
         return Render::get('user/login', array());
     }
     $customer = $this->customerService->getCurrent();
     return Render::get('user/account/change_password', array('messages' => $this->messages, 'customer' => $customer, 'myAccountUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::ACCOUNT))));
 }
Пример #2
0
 public function render()
 {
     if (!$this->wp->isUserLoggedIn()) {
         return Render::get('user/login', array());
     }
     $content = $this->wp->getPostField('post_content', $this->options->getPageId(Pages::ACCOUNT));
     $content = do_shortcode($content);
     $customer = $this->customerService->getCurrent();
     $query = new \WP_Query(array('post_type' => Types::ORDER, 'post_status' => array(Status::PENDING, Status::ON_HOLD), 'posts_per_page' => $this->options->get('shopping.unpaid_orders_number'), 'meta_query' => array(array('key' => 'customer_id', 'value' => $this->wp->getCurrentUserId(), 'compare' => '='))));
     $orders = $this->orderService->findByQuery($query);
     $permalink = get_permalink();
     return Render::get('user/account', array('content' => $content, 'messages' => $this->messages, 'customer' => $customer, 'unpaidOrders' => $orders, 'editBillingAddressUrl' => Api::getEndpointUrl('edit-address', 'billing', $permalink), 'editShippingAddressUrl' => Api::getEndpointUrl('edit-address', 'shipping', $permalink), 'changePasswordUrl' => Api::getEndpointUrl('change-password', '', $permalink), 'myOrdersUrl' => Api::getEndpointUrl('orders', '', $permalink)));
 }
Пример #3
0
 private function getStateFromSession($id)
 {
     $state = array();
     $session = $this->session->getField(self::CART);
     if (isset($session[$id])) {
         $state = $session[$id];
         $state['customer'] = $this->customerService->getCurrent();
         if (isset($state['items'])) {
             $productService = $this->productService;
             $this->wp->addFilter('jigoshop\\internal\\order\\item', function ($value, $data) use($productService) {
                 return $productService->findForState($data);
             }, 10, 2);
             $state['items'] = unserialize($state['items']);
         }
         if (isset($state['shipping'])) {
             $shipping = $state['shipping'];
             if (!empty($shipping['method'])) {
                 $state['shipping'] = array('method' => $this->shippingService->findForState($shipping['method']), 'price' => $shipping['price'], 'rate' => isset($shipping['rate']) ? $shipping['rate'] : null);
             }
         }
         if (isset($state['payment']) && !empty($state['payment'])) {
             $state['payment'] = $this->paymentService->get($state['payment']);
         }
     }
     return $state;
 }
Пример #4
0
 public function render()
 {
     if (!$this->wp->isUserLoggedIn()) {
         return Render::get('user/login', array());
     }
     $order = $this->wp->getQueryParameter('orders');
     $accountUrl = $this->wp->getPermalink($this->options->getPageId(Pages::ACCOUNT));
     if (!empty($order) && is_numeric($order)) {
         $order = $this->orderService->find($order);
         /** @var Entity $order */
         return Render::get('user/account/orders/single', array('messages' => $this->messages, 'order' => $order, 'myAccountUrl' => $accountUrl, 'listUrl' => Api::getEndpointUrl('orders', '', $accountUrl), 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'getTaxLabel' => function ($taxClass) use($order) {
             return Tax::getLabel($taxClass, $order);
         }));
     }
     $customer = $this->customerService->getCurrent();
     $orders = $this->orderService->findForUser($customer->getId());
     return Render::get('user/account/orders', array('messages' => $this->messages, 'customer' => $customer, 'orders' => $orders, 'myAccountUrl' => $accountUrl));
 }
Пример #5
0
 public function render()
 {
     $cart = $this->cartService->getCurrent();
     $content = $this->wp->getPostField('post_content', $this->options->getPageId(Pages::CART));
     $content = do_shortcode($content);
     $termsUrl = '';
     $termsPage = $this->options->get('advanced.pages.terms');
     if ($termsPage > 0) {
         $termsUrl = $this->wp->getPermalink($termsPage);
     }
     return Render::get('shop/cart', array('content' => $content, 'cart' => $cart, 'messages' => $this->messages, 'productService' => $this->productService, 'customer' => $this->customerService->getCurrent(), 'shippingMethods' => $this->shippingService->getEnabled(), 'shopUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::SHOP)), 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'showShippingCalculator' => $this->options->get('shipping.calculator'), 'termsUrl' => $termsUrl));
 }
Пример #6
0
 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));
 }
Пример #7
0
 public function render()
 {
     if (!$this->wp->isUserLoggedIn()) {
         return Render::get('user/login', array());
     }
     $customer = $this->customerService->getCurrent();
     switch ($this->wp->getQueryParameter('edit-address')) {
         case 'shipping':
             $address = $customer->getShippingAddress();
             break;
         case 'billing':
         default:
             $address = $customer->getBillingAddress();
             break;
     }
     return Render::get('user/account/edit_address', array('messages' => $this->messages, 'customer' => $customer, 'address' => $address, 'myAccountUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::ACCOUNT))));
 }
Пример #8
0
 private function createUserAccount()
 {
     // Check if user agreed to account creation
     if (isset($_POST['jigoshop_account']) && $_POST['jigoshop_account']['create'] != 'on') {
         return;
     }
     $email = $_POST['jigoshop_order']['billing_address']['email'];
     $errors = new \WP_Error();
     $this->wp->doAction('register_post', $email, $email, $errors);
     if ($errors->get_error_code()) {
         throw new Exception($errors->get_error_message());
     }
     $login = $_POST['jigoshop_account']['login'];
     $password = $_POST['jigoshop_account']['password'];
     if (empty($login) || empty($password)) {
         throw new Exception(__('You need to fill username and password fields.', 'jigoshop'));
     }
     if ($password != $_POST['jigoshop_account']['password2']) {
         throw new Exception(__('Passwords do not match.', 'jigoshop'));
     }
     $id = $this->wp->wpCreateUser($login, $password, $email);
     if (!$id) {
         throw new Exception(sprintf(__("<strong>Error</strong> Couldn't register an account for you. Please contact the <a href=\"mailto:%s\">administrator</a>.", 'jigoshop'), $this->options->get('general.email')));
     }
     if (is_wp_error($id)) {
         throw new Exception(sprintf(__("<strong>Error</strong> Account creation failed: %s", 'jigoshop'), $id->get_error_message($id->get_error_code())));
     }
     $this->wp->wpUpdateUser(array('ID' => $id, 'role' => 'customer', 'first_name' => $_POST['jigoshop_order']['billing_address']['first_name'], 'last_name' => $_POST['jigoshop_order']['billing_address']['last_name']));
     $this->wp->doAction('jigoshop\\checkout\\created_account', $id);
     // send the user a confirmation and their login details
     if ($this->wp->applyFilters('jigoshop\\checkout\\new_user_notification', true, $id)) {
         $this->wp->wpNewUserNotification($id);
     }
     $this->wp->wpSetAuthCookie($id, true, $this->wp->isSsl());
     $cart = $this->cartService->getCurrent();
     $customer = $this->customerService->find($id);
     $customer->restoreState($cart->getCustomer()->getStateToSave());
     $cart->setCustomer($customer);
 }
Пример #9
0
 /**
  * Checks whether provided customer needs to be taxed.
  *
  * @param Customer $customer Customer to check.
  * @return boolean Whether customer needs to be taxed.
  */
 public function isTaxable(Customer $customer)
 {
     return $this->service->isTaxable($customer);
 }
Пример #10
0
 public function fill(OrderInterface $order, array $data)
 {
     if (!empty($data['customer']) && is_numeric($data['customer'])) {
         $data['customer'] = $this->customerService->find($data['customer']);
     }
     if (isset($data['customer'])) {
         if (!empty($data['customer'])) {
             $data['customer'] = $this->wp->getHelpers()->maybeUnserialize($data['customer']);
         } else {
             $data['customer'] = new CustomerEntity\Guest();
         }
         if (isset($data['billing_address'])) {
             $data['billing_address'] = array_merge(array_flip(array_keys(ProductHelper::getBasicBillingFields())), $data['billing_address']);
             /** @var CustomerEntity $customer */
             $customer = $data['customer'];
             $customer->setBillingAddress($this->createAddress($data['billing_address']));
         }
         if (isset($data['shipping_address'])) {
             $data['shipping_address'] = array_merge(array_flip(array_keys(ProductHelper::getBasicShippingFields())), $data['shipping_address']);
             /** @var CustomerEntity $customer */
             $customer = $data['customer'];
             $customer->setShippingAddress($this->createAddress($data['shipping_address']));
         }
         $order->setCustomer($data['customer']);
         unset($data['customer']);
     }
     /** @var OrderInterface $order */
     $order = $this->wp->applyFilters('jigoshop\\factory\\order\\fetch\\after_customer', $order);
     if (isset($data['items'])) {
         $order->removeItems();
     }
     //We do not want to add coupons and from directly, without validation.
     $coupons = null;
     if (isset($data['coupons'])) {
         $coupons = $data['coupons'];
         unset($data['coupons']);
     }
     if (isset($data['discount'])) {
         unset($data['discount']);
     }
     $order->restoreState($data);
     if ($coupons) {
         $coupons = $this->wp->getHelpers()->maybeUnserialize($coupons);
         if (isset($coupons[0]) && is_array($coupons[0])) {
             $codes = array_map(function ($coupon) {
                 return $coupon['code'];
             }, $coupons);
         } else {
             $codes = $coupons;
         }
         $coupons = $this->couponService->getByCodes($codes);
         foreach ($coupons as $coupon) {
             /** @var Coupon $coupon */
             try {
                 $order->addCoupon($coupon);
             } catch (Exception $e) {
                 $this->messages->addWarning($e->getMessage(), false);
             }
         }
     }
     return $this->wp->applyFilters('jigoshop\\factory\\order\\fill', $order);
 }