Ejemplo n.º 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))));
 }
Ejemplo n.º 2
0
 /**
  * Executes actions associated with selected page.
  */
 public function action()
 {
     if (isset($_POST['action']) && $_POST['action'] == 'add-to-cart') {
         /** @var \Jigoshop\Entity\Product $product */
         $product = $this->productService->find($_POST['item']);
         try {
             /** @var Item $item */
             $item = $this->wp->applyFilters('jigoshop\\cart\\add', null, $product);
             if ($item === null) {
                 throw new Exception(__('Unable to add product to the cart.', 'jigoshop'));
             }
             if (isset($_POST['quantity'])) {
                 $item->setQuantity($_POST['quantity']);
             }
             /** @var Cart $cart */
             $cart = $this->cartService->get($this->cartService->getCartIdForCurrentUser());
             $cart->addItem($item);
             $this->cartService->save($cart);
             $url = false;
             $button = '';
             switch ($this->options->get('shopping.redirect_add_to_cart')) {
                 case 'cart':
                     $url = $this->wp->getPermalink($this->options->getPageId(Pages::CART));
                     break;
                 case 'checkout':
                     $url = $this->wp->getPermalink($this->options->getPageId(Pages::CHECKOUT));
                     break;
                     /** @noinspection PhpMissingBreakStatementInspection */
                 /** @noinspection PhpMissingBreakStatementInspection */
                 case 'product_list':
                     $url = $this->wp->getPermalink($this->options->getPageId(Pages::SHOP));
                 case 'product':
                 case 'same_page':
                 default:
                     $button = sprintf('<a href="%s" class="btn btn-warning pull-right">%s</a>', $this->wp->getPermalink($this->options->getPageId(Pages::CART)), __('View cart', 'jigoshop'));
             }
             $this->messages->addNotice(sprintf(__('%s successfully added to your cart. %s', 'jigoshop'), $product->getName(), $button));
             if ($url !== false) {
                 $this->messages->preserveMessages();
                 $this->wp->wpRedirect($url);
             }
         } catch (NotEnoughStockException $e) {
             if ($e->getStock() == 0) {
                 $message = sprintf(__('Sorry, we do not have "%s" in stock.', 'jigoshop'), $product->getName());
             } else {
                 if ($this->options->get('products.show_stock')) {
                     $message = sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. We only have %d available at this time. Please edit your cart and try again. We apologize for any inconvenience caused.', 'jigoshop'), $product->getName(), $e->getStock());
                 } else {
                     $message = sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. Please edit your cart and try again. We apologize for any inconvenience caused.', 'jigoshop'), $product->getName());
                 }
             }
             $this->messages->addError($message);
         } catch (Exception $e) {
             $this->messages->addError(sprintf(__('A problem ocurred when adding to cart: %s', 'jigoshop'), $e->getMessage()));
         }
     }
 }
Ejemplo n.º 3
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));
 }
Ejemplo n.º 4
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));
 }
Ejemplo n.º 5
0
 public function render()
 {
     $content = $this->wp->getPostField('post_content', $this->options->getPageId(Pages::THANK_YOU));
     /** @var Order $order */
     $order = $this->orderService->find((int) $_REQUEST['order']);
     if ($order->getKey() != $_REQUEST['key']) {
         $this->messages->addError(__('Invalid security key. The order was processed.', 'jigoshop'));
         $this->wp->redirectTo($this->options->getPageId(Pages::SHOP));
     }
     return Render::get('shop/checkout/thanks', array('content' => $content, 'messages' => $this->messages, 'order' => $order, 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'shopUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::SHOP)), 'cancelUrl' => \Jigoshop\Helper\Order::getCancelLink($order), 'getTaxLabel' => function ($taxClass) use($order) {
         return Tax::getLabel($taxClass, $order);
     }));
 }
Ejemplo n.º 6
0
 /**
  * Renders page template.
  *
  * @return string Page template.
  */
 public function render()
 {
     $content = $this->wp->getPostField('post_content', $this->options->getPageId(Pages::CHECKOUT));
     $content = do_shortcode($content);
     $cart = $this->cartService->getCurrent();
     $billingFields = $this->getBillingFields($cart->getCustomer()->getBillingAddress());
     $shippingFields = $this->getShippingFields($cart->getCustomer()->getShippingAddress());
     $termsUrl = '';
     $termsPage = $this->options->get('advanced.pages.terms');
     if ($termsPage > 0) {
         $termsUrl = $this->wp->getPageLink($termsPage);
     }
     $verificationMessage = $this->options->get('shopping.enable_verification_message') ? $this->options->get('shopping.verification_message') : '';
     return Render::get('shop/checkout', array('cartUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::CART)), 'content' => $content, 'cart' => $cart, 'messages' => $this->messages, 'shippingMethods' => $this->shippingService->getEnabled(), 'paymentMethods' => $this->paymentService->getEnabled(), 'billingFields' => $billingFields, 'shippingFields' => $shippingFields, 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'showLoginForm' => $this->options->get('shopping.show_login_form') && !$this->wp->isUserLoggedIn(), 'allowRegistration' => $this->options->get('shopping.allow_registration') && !$this->wp->isUserLoggedIn(), 'showRegistrationForm' => $this->options->get('shopping.allow_registration') && !$this->options->get('shopping.guest_purchases') && !$this->wp->isUserLoggedIn(), 'alwaysShowShipping' => $this->options->get('shipping.always_show_shipping'), 'verificationMessage' => $verificationMessage, 'differentShipping' => isset($_POST['jigoshop_order']) ? $_POST['jigoshop_order']['different_shipping_address'] == 'on' : false, 'termsUrl' => $termsUrl, 'defaultGateway' => $this->options->get('payment.default_gateway')));
 }
Ejemplo n.º 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))));
 }
Ejemplo n.º 8
0
 public function render()
 {
     /** @var Order $order */
     $order = $this->orderService->find((int) $this->wp->getQueryParameter('pay'));
     $render = $this->wp->applyFilters('jigoshop\\pay\\render', '', $order);
     if (!empty($render)) {
         return Render::get('shop/checkout/payment', array('messages' => $this->messages, 'content' => $render, 'order' => $order));
     }
     $termsUrl = '';
     $termsPage = $this->options->get('advanced.pages.terms');
     if ($termsPage > 0) {
         $termsUrl = $this->wp->getPageLink($termsPage);
     }
     $accountUrl = $this->wp->getPermalink($this->options->getPageId(Pages::ACCOUNT));
     return Render::get('shop/checkout/pay', array('messages' => $this->messages, 'order' => $order, 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'termsUrl' => $termsUrl, 'myAccountUrl' => $accountUrl, 'myOrdersUrl' => Api::getEndpointUrl('orders', '', $accountUrl), 'paymentMethods' => $this->paymentService->getEnabled(), 'getTaxLabel' => function ($taxClass) use($order) {
         return Tax::getLabel($taxClass, $order);
     }));
 }