예제 #1
0
 public function action()
 {
     if (isset($_POST['action']) && $_POST['action'] == 'change_password') {
         $errors = array();
         $user = $this->wp->wpGetCurrentUser();
         /** @noinspection PhpUndefinedFieldInspection */
         if (!$this->wp->wpCheckPassword($_POST['password'], $user->user_pass, $user->ID)) {
             $errors[] = __('Current password is invalid.', 'jigoshop');
         }
         if (empty($_POST['new-password'])) {
             $errors[] = __('Please enter new password.', 'jigoshop');
         } else {
             if ($_POST['new-password'] != $_POST['new-password-2']) {
                 $errors[] = __('Passwords do not match.', 'jigoshop');
             }
         }
         if (!empty($errors)) {
             $this->messages->addError(join('<br/>', $errors), false);
         } else {
             $this->wp->wpUpdateUser(array('ID' => $user->ID, 'user_pass' => $_POST['new-password']));
             $this->messages->addNotice(__('Password changed.', 'jigoshop'));
             $this->wp->redirectTo($this->options->getPageId(Pages::ACCOUNT));
         }
     }
 }
예제 #2
0
 public function action()
 {
     if (isset($_POST['action']) && $_POST['action'] == 'add-to-cart') {
         /** @var Entity $product */
         $product = $this->productService->find($_POST['item']);
         try {
             $item = $this->wp->applyFilters('jigoshop\\cart\\add', null, $product);
             if ($item === null) {
                 throw new Exception(__('Unable to add product to the cart.', 'jigoshop'));
             }
             $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;
                 case 'product':
                 default:
                     $url = $this->wp->getPermalink($product->getId());
                 case 'same_page':
                 case 'product_list':
                     $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);
                 exit;
             }
         } 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()), false);
         }
     }
 }
예제 #3
0
 public function action()
 {
     if (!isset($_REQUEST['order']) || !isset($_REQUEST['key'])) {
         $this->messages->addNotice(__('No order to display.', 'jigoshop'));
         $this->wp->redirectTo($this->options->getPageId(Pages::SHOP));
     }
 }
예제 #4
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));
         }
     }
 }
예제 #5
0
 /**
  * Action method to run tools.
  */
 public function action()
 {
     if (!isset($_GET['tool'])) {
         return;
     }
     $id = trim(htmlspecialchars(strip_tags($_GET['tool'])));
     if (isset($this->tools[$id])) {
         /** @var Tool $tool */
         $tool = $this->tools[$id];
         $this->wp->doAction('jigoshop\\migration\\before', $tool);
         $tool->migrate(null);
         $this->messages->addNotice(__('Migration complete', 'jigoshop'));
         $this->wp->wpRedirect($this->wp->adminUrl('admin.php?page=' . self::NAME));
     }
 }
예제 #6
0
파일: Cart.php 프로젝트: jigoshop/Jigoshop2
 public function action()
 {
     if (isset($_REQUEST['action'])) {
         switch ($_REQUEST['action']) {
             case 'cancel_order':
                 if ($this->wp->getHelpers()->verifyNonce($_REQUEST['nonce'], 'cancel_order')) {
                     /** @var Order $order */
                     $order = $this->orderService->find((int) $_REQUEST['id']);
                     if ($order->getKey() != $_REQUEST['key']) {
                         $this->messages->addError(__('Invalid order key.', 'jigoshop'));
                         return;
                     }
                     if ($order->getStatus() != Status::PENDING) {
                         $this->messages->addError(__('Unable to cancel order.', 'jigoshop'));
                         return;
                     }
                     $order->setStatus(Status::CANCELLED);
                     $cart = $this->cartService->createFromOrder($this->cartService->getCartIdForCurrentUser(), $order);
                     $this->orderService->save($order);
                     $this->cartService->save($cart);
                     $this->messages->addNotice(__('The order has been cancelled', 'jigoshop'));
                 }
                 break;
             case 'update-shipping':
                 $customer = $this->customerService->getCurrent();
                 $this->updateCustomer($customer);
                 break;
             case 'checkout':
                 try {
                     $cart = $this->cartService->getCurrent();
                     // Update quantities
                     $this->updateQuantities($cart);
                     // Update customer (if needed)
                     if ($this->options->get('shipping.calculator')) {
                         $customer = $this->customerService->getCurrent();
                         $this->updateCustomer($customer);
                     }
                     if (isset($_POST['jigoshop_order']['shipping_method'])) {
                         // Select shipping method
                         $method = $this->shippingService->get($_POST['jigoshop_order']['shipping_method']);
                         $cart->setShippingMethod($method);
                     }
                     if ($cart->getShippingMethod() && !$cart->getShippingMethod()->isEnabled()) {
                         $cart->removeShippingMethod();
                         $this->messages->addWarning(__('Previous shipping method is unavailable. Please select different one.', 'jigoshop'));
                     }
                     if ($this->options->get('shopping.validate_zip')) {
                         $address = $cart->getCustomer()->getShippingAddress();
                         if ($address->getPostcode() && !Validation::isPostcode($address->getPostcode(), $address->getCountry())) {
                             throw new Exception(__('Postcode is not valid!', 'jigoshop'));
                         }
                     }
                     do_action('jigoshop\\cart\\before_checkout', $cart);
                     $this->cartService->save($cart);
                     $this->messages->preserveMessages();
                     $this->wp->redirectTo($this->options->getPageId(Pages::CHECKOUT));
                 } catch (Exception $e) {
                     $this->messages->addError(sprintf(__('Error occurred while updating cart: %s', 'jigoshop'), $e->getMessage()));
                 }
                 break;
             case 'update-cart':
                 if (isset($_POST['cart']) && is_array($_POST['cart'])) {
                     try {
                         $cart = $this->cartService->getCurrent();
                         $this->updateQuantities($cart);
                         $this->cartService->save($cart);
                         $this->messages->addNotice(__('Successfully updated the cart.', 'jigoshop'));
                     } catch (Exception $e) {
                         $this->messages->addError(sprintf(__('Error occurred while updating cart: %s', 'jigoshop'), $e->getMessage()));
                     }
                 }
         }
     }
     if (isset($_GET['action']) && isset($_GET['item']) && $_GET['action'] === 'remove-item' && is_numeric($_GET['item'])) {
         $cart = $this->cartService->getCurrent();
         $cart->removeItem((int) $_GET['item']);
         $this->cartService->save($cart);
         $this->messages->addNotice(__('Successfully removed item from cart.', 'jigoshop'), false);
     }
 }
예제 #7
0
 /**
  * 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)
 {
     // This is required when installin emails this function is used twice,
     // once for advanced settings and once for all jigoshop settings.
     if (isset($settings['general']) && is_array($settings['general'])) {
         return $settings;
     }
     if (isset($settings['install_emails'])) {
         unset($settings['install_emails']);
         // TODO add this to WPAL
         remove_all_actions('save_post_' . Types\Email::NAME);
         $this->di->get('jigoshop.installer')->installEmails();
         $this->messages->addNotice(__('Emails created.', 'jigoshop'));
     }
     $settings['automatic_complete'] = $settings['automatic_complete'] == 'on';
     $settings['automatic_reset'] = $settings['automatic_reset'] == 'on';
     $settings['products_list']['variations_sku_stock'] = $settings['products_list']['variations_sku_stock'] == 'on';
     if (!in_array($settings['cache'], array_keys($this->caches))) {
         $this->messages->addWarning(sprintf(__('Invalid cache mechanism: "%s". Value set to %s.', 'jigoshop'), $settings['cache'], $this->caches['simple']));
         $settings['cache'] = 'simple';
     }
     $settings['ignore_meta_queries'] = $settings['ignore_meta_queries'] == 'on';
     if (isset($settings['api'], $settings['api']['keys'])) {
         $settings['api']['keys'] = array_filter($settings['api']['keys'], function ($item) {
             return !empty($item['key']);
         });
         $settings['api']['keys'] = array_map(function ($item) {
             return array_merge(array('key' => '', 'permissions' => array()), $item);
         }, $settings['api']['keys']);
     }
     $pages = $this->_getPages();
     if (!in_array($settings['pages']['shop'], array_keys($pages))) {
         $this->messages->addError(__('Invalid shop page, please select again.', 'jigoshop'));
     } else {
         $this->options->setPageId(Pages::SHOP, $settings['pages']['shop']);
     }
     if (!in_array($settings['pages']['cart'], array_keys($pages))) {
         $this->messages->addError(__('Invalid cart page, please select again.', 'jigoshop'));
     } else {
         $this->options->setPageId(Pages::CART, $settings['pages']['cart']);
     }
     if (!in_array($settings['pages']['checkout'], array_keys($pages))) {
         $this->messages->addError(__('Invalid checkout page, please select again.', 'jigoshop'));
     } else {
         $this->options->setPageId(Pages::CHECKOUT, $settings['pages']['checkout']);
     }
     if (!in_array($settings['pages']['checkout_thank_you'], array_keys($pages))) {
         $this->messages->addError(__('Invalid thank you page, please select again.', 'jigoshop'));
     } else {
         $this->options->setPageId(Pages::THANK_YOU, $settings['pages']['checkout_thank_you']);
     }
     if (!in_array($settings['pages']['account'], array_keys($pages))) {
         $this->messages->addError(__('Invalid My account page, please select again.', 'jigoshop'));
     } else {
         $this->options->setPageId(Pages::ACCOUNT, $settings['pages']['account']);
     }
     if (!empty($settings['pages']['terms']) && $settings['pages']['terms'] != 0 && !in_array($settings['pages']['terms'], array_keys($pages))) {
         $this->messages->addError(__('Invalid terms page, please select again.', 'jigoshop'));
     }
     return $settings;
 }