Esempio n. 1
0
 /**
  * Returns currently logged in customer.
  *
  * @return \Jigoshop\Entity\Customer Current customer entity.
  */
 public function getCurrent()
 {
     if ($this->current === null) {
         $this->current = $this->service->getCurrent();
     }
     return $this->current;
 }
Esempio n. 2
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))));
 }
Esempio n. 3
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)));
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 /**
  * Ajax action for changing postcode.
  */
 public function ajaxChangePostcode()
 {
     $customer = $this->customerService->getCurrent();
     switch ($_POST['field']) {
         case 'shipping_address':
             if ($this->options->get('shopping.validate_zip') && !Validation::isPostcode($_POST['value'], $customer->getShippingAddress()->getCountry())) {
                 echo json_encode(array('success' => false, 'error' => __('Shipping postcode is not valid!', 'jigoshop')));
                 exit;
             }
             $customer->getShippingAddress()->setPostcode($_POST['value']);
             if ($customer->getBillingAddress()->getPostcode() == null) {
                 $customer->getBillingAddress()->setPostcode($_POST['value']);
             }
             break;
         case 'billing_address':
             if ($this->options->get('shopping.validate_zip') && !Validation::isPostcode($_POST['value'], $customer->getBillingAddress()->getCountry())) {
                 echo json_encode(array('success' => false, 'error' => __('Billing postcode is not valid!', 'jigoshop')));
                 exit;
             }
             $customer->getBillingAddress()->setPostcode($_POST['value']);
             if ($_POST['differentShipping'] === 'false') {
                 $customer->getShippingAddress()->setPostcode($_POST['value']);
             }
             break;
     }
     $this->customerService->save($customer);
     $cart = $this->cartService->getCurrent();
     $cart->setCustomer($customer);
     $response = $this->getAjaxLocationResponse($customer, $cart);
     echo json_encode($response);
     exit;
 }
Esempio n. 6
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));
 }
Esempio n. 7
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));
 }
Esempio n. 8
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))));
 }