コード例 #1
0
ファイル: Order.php プロジェクト: jigoshop/Jigoshop2
 /**
  * Creates new order properly based on POST variable data.
  *
  * @param $id int Post ID to create object for.
  *
  * @return Entity
  */
 public function create($id)
 {
     $post = $this->wp->getPost($id);
     // Support for our own post types and "Publish" button.
     if (isset($_POST['original_post_status'])) {
         $post->post_status = $_POST['original_post_status'];
     }
     $order = $this->fetch($post);
     $data = array('updated_at' => time());
     if (isset($_POST['jigoshop_order']['status'])) {
         $order->setStatus($_POST['jigoshop_order']['status']);
     }
     if (isset($_POST['post_excerpt'])) {
         $data['customer_note'] = trim($_POST['post_excerpt']);
     }
     if (isset($_POST['jigoshop_order'])) {
         $data = array_merge($data, $_POST['jigoshop_order']);
     }
     $data['items'] = $this->getItems($id);
     if (isset($_POST['order']['shipping'])) {
         $data['shipping'] = array('method' => null, 'rate' => null, 'price' => -1);
         $method = $this->shippingService->get($_POST['order']['shipping']);
         if ($method instanceof MultipleMethod && isset($_POST['order']['shipping_rate'])) {
             $method->setShippingRate($_POST['order']['shipping_rate']);
             $data['shipping']['rate'] = $method->getShippingRate();
         }
         $data['shipping']['method'] = $method;
     }
     return $order = $this->wp->applyFilters('jigoshop\\factory\\order\\create', $this->fill($order, $data));
 }
コード例 #2
0
ファイル: CouponService.php プロジェクト: jigoshop/Jigoshop2
 /**
  * Finds item specified by ID.
  *
  * @param $id int The ID.
  *
  * @return EntityInterface
  */
 public function find($id)
 {
     $post = null;
     if ($id !== null) {
         $post = $this->wp->getPost($id);
     }
     return $this->factory->fetch($post);
 }
コード例 #3
0
ファイル: ProductService.php プロジェクト: jigoshop/Jigoshop2
 /**
  * Finds item specified by state.
  *
  * @param array $state State of the product to be found.
  *
  * @return \Jigoshop\Entity\Product Item found.
  */
 public function findForState(array $state)
 {
     $post = $this->wp->getPost($state['id']);
     $product = $this->factory->fetch($post);
     $product->restoreState($state);
     return $this->wp->applyFilters('jigoshop\\service\\product\\find_for_state', $product, $state);
 }
コード例 #4
0
ファイル: Permalinks.php プロジェクト: jigoshop/Jigoshop2
 /**
  * Save the settings
  */
 private function save()
 {
     // We need to save the options ourselves; settings api does not trigger save for the permalinks page
     if (isset($_POST['permalink_structure']) || isset($_POST['category_base']) && isset($_POST['product_permalink'])) {
         // Cat and tag bases
         $categorySlug = trim(strip_tags($_POST['jigoshop_product_category_slug']));
         $tagSlug = trim(strip_tags($_POST['jigoshop_product_tag_slug']));
         $permalinks = $this->options->get('permalinks');
         $helpers = $this->wp->getHelpers();
         $permalinks['category'] = $helpers->untrailingslashit($categorySlug);
         $permalinks['tag'] = $helpers->untrailingslashit($tagSlug);
         // Product base
         $product_permalink = trim(strip_tags($_POST['product_permalink']));
         if ($product_permalink == 'custom') {
             // Get permalink without slashes
             $product_permalink = trim(strip_tags($_POST['product_permalink_structure']), '/');
             // This is an invalid base structure and breaks pages
             if ('%' . Types::PRODUCT_CATEGORY . '%' == $product_permalink) {
                 $product_permalink = _x('product', 'slug', 'jigoshop') . '/' . $product_permalink;
             }
         } elseif (empty($product_permalink)) {
             $product_permalink = false;
         }
         $permalinks['product'] = $helpers->untrailingslashit($product_permalink);
         // Shop base may require verbose page rules if nesting pages
         $shopPageId = $this->options->getPageId(FrontendPages::SHOP);
         $shop_permalink = urldecode($shopPageId > 0 && $this->wp->getPost($shopPageId) ? $this->wp->getPageUri($shopPageId) : _x('shop', 'default-slug', 'jigoshop'));
         if ($shopPageId && trim($permalinks['product'], '/') === $shop_permalink) {
             $permalinks['verbose'] = true;
         }
         $this->options->update('permalinks', $permalinks);
         $this->options->saveOptions();
         $this->wp->getRewrite()->flush_rules();
     }
 }
コード例 #5
0
ファイル: Order.php プロジェクト: jigoshop/Jigoshop2
 /**
  * Ajax action for changing postcode.
  */
 public function ajaxChangePostcode()
 {
     try {
         $post = $this->wp->getPost((int) $_POST['order']);
         $this->wp->updateGlobalPost($post);
         /** @var \Jigoshop\Entity\Order $order */
         $order = $this->orderService->findForPost($post);
         if ($order->getId() === null) {
             throw new Exception(__('Order not found.', 'jigoshop'));
         }
         switch ($_POST['type']) {
             case 'shipping':
                 $address = $order->getCustomer()->getShippingAddress();
                 break;
             case 'billing':
             default:
                 $address = $order->getCustomer()->getBillingAddress();
         }
         if ($this->options->get('shopping.validate_zip') && !Validation::isPostcode($_POST['value'], $address->getCountry())) {
             throw new Exception(__('Invalid postcode.', 'jigoshop'));
         }
         $address->setPostcode($_POST['value']);
         $order = $this->rebuildOrder($order);
         $this->orderService->save($order);
         $result = $this->getAjaxResponse($order);
     } catch (Exception $e) {
         $result = array('success' => false, 'error' => $e->getMessage());
     }
     echo json_encode($result);
     exit;
 }
コード例 #6
0
ファイル: OrderService.php プロジェクト: jigoshop/Jigoshop2
 /**
  * Finds order specified by ID.
  *
  * @param $id int Order ID.
  *
  * @return Order
  */
 public function find($id)
 {
     $post = null;
     if ($id !== null) {
         $post = $this->wp->getPost($id);
     }
     return $this->wp->applyFilters('jigoshop\\service\\order\\find', $this->factory->fetch($post), $id);
 }
コード例 #7
0
ファイル: Orders.php プロジェクト: jigoshop/Jigoshop2
 protected function _fetchItemData($args)
 {
     $defaults = array('id' => 0, 'variation_id' => 0, 'variation' => array(), 'cost_inc_tax' => 0, 'name' => '', 'qty' => 1, 'cost' => 0, 'taxrate' => 0);
     if ($args['variation_id'] > 0) {
         $post = $this->wp->getPost($args['variation_id']);
         if ($post) {
             /** @var Product\Variable $product */
             $product = $this->productService->find($post->post_parent);
             if ($product->getId() && $product instanceof Product\Variable) {
                 $args['name'] = $product->getVariation($post->ID)->getTitle();
             }
         }
     }
     return $this->_fetchData($defaults, $args);
 }
コード例 #8
0
ファイル: EmailService.php プロジェクト: jigoshop/Jigoshop2
 /**
  * Sends specified email to specified address.
  *
  * @param       $hook string Email to send.
  * @param array $args Arguments to the email.
  * @param       $to   string Receiver address.
  */
 public function send($hook, array $args = array(), $to)
 {
     if ($this->suppress) {
         $this->suppress = false;
         return;
     }
     $templates = $this->getTemplates();
     if (!isset($templates[$hook]) || empty($templates[$hook])) {
         return;
     }
     foreach ($templates[$hook] as $postId) {
         $post = $this->wp->getPost($postId);
         if (!empty($post) && $post->post_status == 'publish') {
             $subject = $this->wp->getPostMeta($postId, 'subject', true);
             $post->post_title = empty($subject) ? $post->post_title : $subject;
             $post = $this->filterPost($post, $args);
             $headers = array('MIME-Version: 1.0', 'Content-Type: text/html; charset=UTF-8', 'From: "' . $this->options->get('general.emails.from') . '" <' . $this->options->get('general.email') . '>');
             $footer = $this->options->get('general.emails.footer');
             $post->post_content = $footer ? $post->post_content . '<br/><br/>' . $footer : $post->post_content;
             $this->wp->wpMail($to, $post->post_title, nl2br($post->post_content), $headers);
         }
     }
 }