OSDN Git Service

Eコマース機能更新。
authornaoki hirata <naoki@magic3.org>
Mon, 30 Oct 2017 22:49:04 +0000 (07:49 +0900)
committernaoki hirata <naoki@magic3.org>
Mon, 30 Oct 2017 22:49:04 +0000 (07:49 +0900)
include/wp/contentApi.php
include/wp/wp-includes/class-wp-query.php

index 3555f6e..b8ea5c6 100644 (file)
@@ -1094,6 +1094,59 @@ class ContentApi extends BaseApi
                return $url;
        }
        /**
+        * EC画面のURLを取得
+        *
+        * @param string $pageType                              ページ種別(shop,cart,myaccount,checkout,terms等)
+        * @return string                                               URL
+        */
+       function getCommerceUrl($pageType)
+       {
+               $baseUrl = '';
+               $urlParams = '';
+               
+               // Eコマース用ページID取得
+               $subId = $this->gPage->getPageSubIdByContentType(M3_VIEW_TYPE_COMMERCE, $this->gEnv->getCurrentPageId());
+               
+               // デフォルトページの場合はページIDは付加しない
+//             $subId = $this->gEnv->getCurrentPageSubId();
+               if ($subId != $this->gEnv->getDefaultPageSubId()) $urlParams = M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subId;
+               
+               // ベースURLを取得
+               switch ($this->accessPoint){
+               case '':                        // PC用
+               default:
+                       $baseUrl = $this->gEnv->getDefaultUrl();
+                       break;
+               case 'm':                       // 携帯用
+                       $baseUrl = $this->gEnv->getDefaultMobileUrl();
+                       break;
+               case 's':                       // スマートフォン用
+                       $baseUrl = $this->gEnv->getDefaultSmartphoneUrl();
+                       break;
+               }
+               
+               $baseUrl .= '?';
+               if (!empty($urlParams)){
+                       $baseUrl .= $urlParams . '&';
+               }
+               // ページ種別を付加
+               $task = '';
+               switch ($pageType){
+               case 'cart':
+                       $task = 'cart';
+                       break;
+               case 'shop':
+               case 'myaccount':
+               case 'checkout':
+               case 'terms':
+                       break;
+               }
+               if (!empty($task)) $baseUrl .= M3_REQUEST_PARAM_OPERATION_TASK . '=' . $task;
+               
+               $url = $this->getUrl($baseUrl);
+               return $url;
+       }
+       /**
         * コンテンツ表示制御(サムネールを表示するかどうか)を取得
         *
         * @return bool                         true=表示、false=表示しない
@@ -1103,7 +1156,7 @@ class ContentApi extends BaseApi
                return $this->showThumb;
        }
        /**
-        * WordPressã\82³ã\83³ã\83\9dã\83¼ã\83\8dã\83³ã\83\88ã\81«コンテンツを更新
+        * WordPressã\82³ã\83³ã\83\9dã\83¼ã\83\8dã\83³ã\83\88ã\81®コンテンツを更新
         *
         * @param string $content                               コンテンツテキスト
         * @return                                                              なし
@@ -1168,5 +1221,59 @@ class ContentApi extends BaseApi
        {
                return $this->postTitle;
        }
+       /**
+        * WordPress専用描画ページかどうかを取得
+        *
+        * @return bool                                         WordPress専用描画ページかどうか
+        */
+       function isWordPressSpecificPage()
+       {
+               // 現在のページがcommerce等の特定のページコンテンツ属性の場合は画面はWordPress側のみで作成する
+               $contentType = $this->gPage->getContentType();
+               if ($contentType == M3_VIEW_TYPE_COMMERCE){
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+       /**
+        * WordPress専用描画ページのパラメータを取得
+        *
+        * @return array                        パラメータの連想配列。取得できない場合はnullが返る。
+        */
+       function getWordPressSpecificPageParam()
+       {
+               global $woocommerce;
+               
+               // WooCommerceがインストールされていない場合は終了
+               if (!isset($woocommerce)) return array();
+               
+               $pages = array(
+                                       'shop' => array(
+                                               'name'    => _x( 'shop', 'Page slug', 'woocommerce' ),
+                                               'title'   => _x( 'Shop', 'Page title', 'woocommerce' ),
+                                               'content' => '',
+                                       ),
+                                       'cart' => array(
+                                               'name'    => _x( 'cart', 'Page slug', 'woocommerce' ),
+                                               'title'   => _x( 'Cart', 'Page title', 'woocommerce' ),
+                                               'content' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']',
+                                       ),
+                                       'checkout' => array(
+                                               'name'    => _x( 'checkout', 'Page slug', 'woocommerce' ),
+                                               'title'   => _x( 'Checkout', 'Page title', 'woocommerce' ),
+                                               'content' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']',
+                                       ),
+                                       'myaccount' => array(
+                                               'name'    => _x( 'my-account', 'Page slug', 'woocommerce' ),
+                                               'title'   => _x( 'My account', 'Page title', 'woocommerce' ),
+                                               'content' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']',
+                                       ),
+                               );
+               // EC機能用のページタイプを取得
+               $pageType = $this->gRequest->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
+               
+               return $pages[$pageType];
+       }
 }
 ?>
index 4413430..694b867 100644 (file)
@@ -1675,6 +1675,7 @@ class WP_Query {
                global $gPageManager;
                global $paged;
 
+               // ########## このメソッドは画面出力前に実行される ##########
                // ##### URLパラメータを解析 #####
                $this->query_vars = array();
                // ページ番号
@@ -1687,6 +1688,12 @@ class WP_Query {
                // コンテンツタイプが設定されていない場合はダミーのWP_Postデータを作成
                $contentType = $gContentApi->getContentType();
                if (empty($contentType)){
+                       // WordPress専用描画ページの場合はWP_Postオブジェクト用のパラメータを取得
+                       $pageParams = array();
+                       if ($gContentApi->isWordPressSpecificPage()){
+                               $pageParams = $gContentApi->getWordPressSpecificPageParam();
+                       }
+                       
                        // コンテンツタイプないページの場合はWordPressの「page」で画面を生成
                        // WP_Postオブジェクトに変換して格納
                        $post = new stdClass;
@@ -1712,6 +1719,13 @@ class WP_Query {
                        $post->filter = 'raw';
                        // Magic3用パラメータ
                        $post->thumb_src = $thumbSrc;*/
+                       
+                       // ### WordPress専用描画ページのパラメータ ###
+                       if (!empty($pageParams)){
+                               $post->post_name = $pageParams['name'];
+                               $post->post_title = $pageParams['title'];
+                               $post->post_content = $pageParams['content'];
+                       }
                
                        $wpPostObj = new WP_Post($post);
                        $this->posts = array($wpPostObj);