EC-CUBE2のシーケンス一覧

前回のブログ「EC-CUBE2の規格登録でエラー」でシーケンスの更新を書きました。
他のシーケンスの重複でエラーが出たと報告があったのでシーケンスの値を全てチェックして更新しました。

EC-CUBE2で使われているシーケンスは下記になります。

dtb_api_account_api_account_id_seq
dtb_api_config_api_config_id_seq
dtb_best_products_best_id_seq
dtb_bloc_bloc_id_seq
dtb_category_category_id_seq
dtb_class_class_id_seq
dtb_classcategory_classcategory_id_seq
dtb_coupon_coupon_id_seq
dtb_coupon_products_coupon_products_id_seq
dtb_coupon_used_coupon_used_id_seq
dtb_csv_no_seq
dtb_csv_sql_sql_id_seq
dtb_customer_customer_id_seq
dtb_deliv_deliv_id_seq
dtb_holiday_holiday_id_seq
dtb_kiyaku_kiyaku_id_seq
dtb_mail_history_send_id_seq
dtb_mailmaga_template_template_id_seq
dtb_maker_maker_id_seq
dtb_member_member_id_seq
dtb_module_update_logs_log_id_seq
dtb_news_news_id_seq
dtb_order_detail_order_detail_id_seq
dtb_order_order_id_seq
dtb_other_deliv_other_deliv_id_seq
dtb_pagelayout_page_id_seq
dtb_payment_payment_id_seq
dtb_plugin_hookpoint_plugin_hookpoint_id_seq
dtb_plugin_plugin_id_seq
dtb_products_class_product_class_id_seq
dtb_products_product_id_seq
dtb_review_review_id_seq
dtb_send_history_send_id_seq
dtb_tax_rule_tax_rule_id_seq

上記の値をチェック

select * from dtb_category_category_id_seq;

修正が必要なら値を更新

select setval('dtb_category_category_id_seq',100);

EC-CUBE2の規格登録でエラー

EC-CUBEの規格登録をしようとしたら下記のエラーが出た件

*—————————————————————*
SQL: [INSERT INTO dtb_classcategory(name,class_id,creator_id,rank,create_date,update_date,classcategory_id)
SELECT $1,$2,$3,$4,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$5]
PlaceHolder: [array (
0 => ‘テストデータ’,
1 => ’92’,
2 => ‘2’,
3 => 3,
4 => 96,
)]
MDB2 Error: unknown error
_doQuery: [Error message: Could not execute statement]
[Last executed query: EXECUTE mdb2_statement_pgsql_2977d07f3499f15f5f700e51693c3dfbbe8b622f1d (‘テストデータ’, ’92’, ‘2’, 3, 96)]
[Native message: ERROR: 重複キーが一意性制約”dtb_classcategory_pkey”に違反しています
DETAIL: キー (classcategory_id)=(96) はすでに存在します]
*—————————————————————*

EC-CUBE 2.x
PostgreSQL

classcategory_idがかぶっているよというエラーです。

PostgreSQLで状況を確認します。(phpPgAdmin)

まずはシーケンスの状況を確認します。

select * from dtb_classcategory_classcategory_id_seq;

last_valueの値がclasscategory_idの最後の値です。
これが96になっています。

classcategory_idのMAXの値を調べます。

SELECT MAX(classcategory_id) FROM dtb_classcategory;

240と値が返ってきました。

last_valueの値を変える必要があります。

select setval('dtb_classcategory_classcategory_id_seq',241);

下記のエラーが出ました。

「リードオンリーのトランザクションでは setval() を実行できません」

phpPgAdminでは実行ができないようなので、SSHでサーバーに繋げて直接PostgreSQLから実行します。

# select setval('dtb_classcategory_classcategory_id_seq',241);

最後に規格登録の動作確認をして登録できればOKです。

[EC-CUBE2]複数配送設定を無効にする

EC-CUBE2で「お届け先ごと送料無料プラグイン」と「送料無料対象商品設定」の両方を入れると思った動作をしないパターンがある。

どちらを優先するか悩んだ末、複数配送を使う人が少数ということもあり、複数配送設定をOFFにできるか調査した。

設定は簡単で、管理画面から「システム設定」→「パラメータ設定」の中にある「USE_MULTIPLE_SHIPPING」をfalseに設定する。

これで複数配送の設定が無効になります。

[EC-CUBE2]商品についての問合せ

商品についてのお問合せで本文にどの商品についての問合せなのかを記載する。

商品詳細ページ
問合せフォーム

上記2種類のテンプレートを編集します。

▼商品詳細ページ
/data/Smarty/templates/default/products/detail.tpl

<a href="<!--{$smarty.const.HTTPS_URL}-->contact/?product_id=<!--{$tpl_product_id}-->">このアイテムについて問い合わせる</a>

▼問合せフォーム
/data/Smarty/templates/default/contact/index.tpl

textareaタグの間に下記を追加。

<!--{if $smarty.get.product_id != ''}-->
商品番号:<!--{$smarty.get.product_id|escape}-->についての問合せ
<!--{/if}-->

[EC-CUBE2]隠し商品

隠し商品リンクの依頼がありました。
前回はカテゴリーごとでしたが、今回は商品単体です。

今回のサーバーはjsonが使えるので、jsonで対応します。

■検索処理の修正
修正ファイル
/data/config/config.php
/data/class/pages/products/LC_Page_Products_List.php

修正ファイルはカテゴリーのやつと同じ

▼config.php

ここに非表示の商品IDの値を設定する。
配列をjson_encodeした値を設定する。

define("Special_Item_ids", json_encode(array(14)));

▼LC_Page_Products_List.php

375行目あたりのlfGetSearchConditionメソッドに処理を追加します。
下記の処理に追加します。
・$searchCondition[‘where’] = SC_Product_Ex::getProductDispConditions(‘alldtl’);の位置を移動させます。
・}else{の処理を追加します。

        // ▼対象商品IDの抽出
        // 商品検索条件の作成(未削除、表示)
        $searchCondition['where'] = SC_Product_Ex::getProductDispConditions('alldtl');

        // カテゴリからのWHERE文字列取得
        if ($arrSearchData['category_id'] != 0) {
            list($searchCondition['where_category'], $searchCondition['arrvalCategory']) = SC_Helper_DB_Ex::sfGetCatWhere($arrSearchData['category_id']);

		// 商品一覧で検索の場合対象product_idは検索にかからないようにする Yuiworks.Maeda 2018-05-30
		} else {
			$searchCondition['where'] .= " AND product_id NOT IN (?)";
			$searchCondition['arrval'][] = implode(",", json_decode(Special_Item_ids));
		}

【EC-CUBE2】非公開カテゴリーの作成

一部カテゴリーを非表示としたい(特別会員専用ページのようなもの)

要件は下記のような感じ
・カテゴリーID指定であれば一覧を表示
・全商品一覧には表示しない
・キーワード検索では表示しない
・対象カテゴリーの一覧、商品にはmetaタグで検索エンジンにindexされないようにする。
・カテゴリー一覧に表示されないようにする

■検索処理の修正
修正ファイル
/data/config/config.php
/data/class/pages/products/LC_Page_Products_List.php

▼config.php

ここに会員専用カテゴリーの値を設定する。
配列をsirialize化した値を設定する。

# 非公開カテゴリ(sirializeで指定)
define("Special_Category_ids", 'a:1:{i:0;i:37;}');

カテゴリーIDが10の場合は下記の配列になる。
array(0=>10);
これをsirialize化すると上記のような値になります。

▼LC_Page_Products_List.php

404行目のlfGetSearchConditionメソッドに処理を追加します。
下記の処理に追加します。

list($searchCondition['where_category'], $searchCondition['arrvalCategory']) = SC_Helper_DB_Ex::sfGetCatWhere($arrSearchData['category_id']);


// カテゴリからのWHERE文字列取得
if ($arrSearchData['category_id'] != 0) {
	list($searchCondition['where_category'], $searchCondition['arrvalCategory']) = SC_Helper_DB_Ex::sfGetCatWhere($arrSearchData['category_id']);
// 全商品一覧の場合、特定カテゴリーを表示しない
} else {
	$searchCondition['where_category'] = "category_id NOT IN (?)";
	$searchCondition['arrvalCategory'] = unserialize(Special_Category_ids);
}

これで全商品一覧、キーワード検索で対象商品が出てこなくなります。

■カテゴリー一覧の修正
カテゴリが自動生成されるので生成されないように処理を追加
/data/Smarty/templates/default/frontparts/bloc/category.tpl
/data/Smarty/templates/sphone/frontparts/bloc/category.tpl

必要あればガラケーのテンプレートも修正
/data/Smarty/templates/mobile/frontparts/bloc/category.tpl

まずはconfig.phpに設定したカテゴリーIDの値をテンプレートに渡します。
* 29行目付近の</script>の後に追記

<!--{php}--> 
	$this->assign("Special_Category_ids", unserialize(Special_Category_ids)); 
<!--{/php}-->

指定カテゴリーでなければ表示という処理を追加

<!--{if $arrTree[cnt].display == 1}-->の後ろにifを追加

<!--{if !in_array($arrTree[cnt].category_id, $Special_Category_ids)}-->
<!--{/if}-->の後ろに<!--{/if}-->で閉じる

下記のような感じ

<!--{* 表示フラグがTRUEなら表示 *}-->
<!--{if $arrTree[cnt].display == 1}-->
	<!--{*非表示カテゴリ以外であれば表示*}-->
	<!--{if !in_array($arrTree[cnt].category_id, $Special_Category_ids)}-->
		<!--{assign var=level value=`$arrTree[cnt].level`}-->
		<!--{assign var=levdiff value=`$level-$preLev`}-->
			<!--{if $levdiff > 0}-->
				<ul>
			<!--{elseif $levdiff == 0 && $firstdone == 1}-->
				</li>
			<!--{elseif $levdiff < 0}-->
				<!--{section name=d loop=`$levdiff*-1`}-->
						</li>
					</ul>
				<!--{/section}-->
				</li>
			<!--{/if}-->
		<li class="level<!--{$level}--><!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> onmark<!--{/if}-->">
			<p>
				<a href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$arrTree[cnt].category_id}-->"<!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> class="onlink"<!--{/if}-->><!--{$arrTree[cnt].category_name|h}-->(<!--{$arrTree[cnt].product_count|default:0}-->)</a>
			</p>
		<!--{if $firstdone == 0}--><!--{assign var=firstdone value=1}--><!--{/if}-->
		<!--{assign var=preLev value=`$level`}-->
	<!--{/if}-->
<!--{/if}-->

■metaタグの埋め込み
/data/Smarty/templates/default/site_frame.tpl

以下のコードを埋め込み

<!--{*非表示カテゴリの配列を取得&設定 *}-->
<!--{php}--> 
	$this->assign("Special_Category_ids", unserialize(Special_Category_ids)); 
<!--{/php}-->

<!--{if $arrSearchData}-->
	<!--{if in_array($arrSearchData.category_id, $Special_Category_ids)}-->

		<meta name="robots" content="noindex,nofollow">

	<!--{/if}-->
<!--{/if}-->

<!--{if $arrRelativeCat}-->
	<!--{section name=r loop=$arrRelativeCat}-->
		<!--{section name=s loop=$arrRelativeCat[r]}-->
			<!--{if in_array($arrRelativeCat[r][s].category_id, $Special_Category_ids)}-->

				<meta name="robots" content="noindex,nofollow">

			<!--{/if}-->
		<!--{/section}-->
	<!--{/section}-->
<!--{/if}-->

以上です。

[EC-CUBE3]プラグインインストール時のエラー

プラグインをインストールしようとしたときに下記のエラーが発生

config.yml not found or syntax error

プラグイン内のconfig.ymlが読み込めないというエラーです。

プラグインを解凍して再圧縮した場合ディレクトリ構造が変わるので、それが原因の場合があります。
心当たりがあればそこを修正してください。

例えば..
TestPluginという名前のプラグインを解凍

ファイル階層
TestPlugin
 config.yml

TestPluginフォルダを圧縮するとファイル階層が1個増えてしまいます。

TestPlugin/config.yml

TestPluginフォルダは必要なしです。

下記になるのが正解です。

/config.yml