EC-CUBE3のテーブル構造(商品情報テーブルなど)
データベースに関する資料
EC-CUBE3のデータベースは複数のテーブルで構成されている。 データベースの構造については
- https://github.com/EC-CUBE/eccube3-doc/blob/master/ER-D_Physical.pdf
- https://github.com/EC-CUBE/eccube3-doc/blob/master/ER-D_Logical.pdf
- https://github.com/EC-CUBE/eccube3-doc/blob/master/%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E5%AE%9A%E7%BE%A9%E6%9B%B8(EC-CUBE2.13dev).xlsx
にある。(ただし、バージョン2.13用である) (なお、「EC-CUBE 3 開発ドキュメント」は https://github.com/EC-CUBE/ec-cube.github.io にある。)
例えば、店舗情報はdtb_base_infoテーブルに格納されている。
商品情報は、dtb_productテーブルなどにある。
テーブル情報の確認
eccube3=# \dt (結果は省略) eccube3=# \d dtb_base_info Table "public.dtb_base_info" Column | Type | Modifiers ------------------------------------+--------------------------------+----------------------- id | integer | not null country_id | smallint | pref | smallint | company_name | text | company_kana | text | zip01 | text | zip02 | text | zipcode | text | (以下省略) eccube3=# select * from dtb_base_info; id | country_id | pref | company_name | company_kana | zip01 | zip02 | zipcode | addr01 | addr02 | tel01 | tel02 | tel03 | fax01 | fax02 | fax03 | business_hour | email01 | email02 | email03 | email04 | shop_name | shop_kana | shop_name_eng | update_date | good_traded | message | latitude | longitude | delivery_free_amount | delivery_free_quantity | option_multiple_shipping | option_mypage_order_status_display | nostock_hidden | option_favorite_product | option_product_delivery_fee | option_product_tax_rule | option_customer_activate | option_remember_me | authentication_key ----+------------+------+--------------------+----------------------------------+-------+-------+---------+--------------------------------+------------------+-------+-------+-------+-------+-------+-------+---------------+-------------------+-------------------+-------------------+-------------------+--------------+------------------+---------------+---------------------+-------------+--------------------------------+----------+------------+----------------------+------------------------+--------------------------+------------------------------------+----------------+-------------------------+-----------------------------+-------------------------+--------------------------+--------------------+-------------------- 1 | | 13 | 株式会社sample書店 | カブシキガイシャサンプルショテン | 101 | 0051 | | 千代田区神田神保町99-999 | 神保町999ビル | 03 | 9999 | 9876 | 03 | 999 | 9999 | 10時~20時 | admin@example.com | admin@example.com | admin@example.com | admin@example.com | EC-CUBE SHOP | サンプルショテン | | 2017-01-24 17:11:43 | 古書籍 | テストです。中身はありませ ん。 | 35.70204 | 139.768027 | | | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | (1 row)
商品データは複数テーブルに分割
商品データは、EC-CUBE3では複数のテーブルに分割されている。product_id が外部キーになっている。
例
- dtb_product
- dtb_product_category
- dtb_product_tag
- dtb_product_class
- dtb_product_image
- dtb_product_stock
dtb_product
eccube3=# \d dtb_product Table "public.dtb_product" Column | Type | Modifiers --------------------+--------------------------------+-------------------- product_id | integer | not null creator_id | integer | not null status | smallint | name | text | not null note | text | description_list | text | description_detail | text | search_word | text | free_area | text | del_flg | smallint | not null default 0 create_date | timestamp(0) without time zone | not null update_date | timestamp(0) without time zone | not null Indexes: "dtb_product_pkey" PRIMARY KEY, btree (product_id) "idx_c49de22f61220ea6" btree (creator_id) "idx_c49de22f7b00651c" btree (status) Foreign-key constraints: "fk_c49de22f61220ea6" FOREIGN KEY (creator_id) REFERENCES dtb_member(member_id) "fk_c49de22f7b00651c" FOREIGN KEY (status) REFERENCES mtb_disp(id) Referenced by: TABLE "dtb_product_class" CONSTRAINT "fk_1a11d1ba4584665a" FOREIGN KEY (product_id) REFERENCES dtb_product(product_id) TABLE "dtb_product_image" CONSTRAINT "fk_3267cc7a4584665a" FOREIGN KEY (product_id) REFERENCES dtb_product(product_id) TABLE "dtb_product_tag" CONSTRAINT "fk_4433e7214584665a" FOREIGN KEY (product_id) REFERENCES dtb_product(product_id) TABLE "dtb_shipment_item" CONSTRAINT "fk_57c3c0394584665a" FOREIGN KEY (product_id) REFERENCES dtb_product(product_id) TABLE "dtb_order_detail" CONSTRAINT "fk_58fe35734584665a" FOREIGN KEY (product_id) REFERENCES dtb_product(product_id) : eccube3=# select * from dtb_product; product_id | creator_id | status | name | note | description_list | description_detail | search_word | free_area | del_flg | create_date | update_date ------------+------------+--------+------------------+------+------------------+------------------------------------------------------------------------------------------------------------------------------------+-------------+-----------+---------+---------------------+--------------------- 1 | 1 | 1 | ディナーフォーク | | | セットで揃えたいディナー用のカトラリー。 +| | | 0 | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | | | | | | 定番の銀製は、シルバー特有の美しい輝きと柔らかな曲線が特徴です。適度な重みと日本人の手に合いやすいサイズ感で長く愛用いただけます。+| | | | | | | | | | | 最高級プラチナフォークは、贈り物としても人気です。 | | | | | 2 | 1 | 1 | パーコレーター | | | +| | | 0 | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | | | | | | パーコレーターはコーヒーの粉をセットして直火にかけて抽出する器具です。 +| | | | | | | | | | | アウトドアでも淹れたてのコーヒーをお楽しみいただけます。 +| | | | | | | | | | | いまだけ、おいしい淹れ方の冊子つきです。 | | | | | (2 rows)
dtb_product_class
Table "public.dtb_product_class" Column | Type | Modifiers --------------------+--------------------------------+----------------------- product_class_id | integer | not null product_id | integer | not null product_type_id | smallint | not null class_category_id1 | integer | class_category_id2 | integer | delivery_date_id | integer | creator_id | integer | not null product_code | text | stock | numeric(10,0) | default NULL::numeric stock_unlimited | smallint | not null sale_limit | numeric(10,0) | default NULL::numeric price01 | numeric(10,0) | default NULL::numeric price02 | numeric(10,0) | not null delivery_fee | numeric(10,0) | default NULL::numeric create_date | timestamp(0) without time zone | not null update_date | timestamp(0) without time zone | not null del_flg | smallint | not null default 0 (以下省略) eccube3=# select * from dtb_product_class; product_class_id | product_id | product_type_id | class_category_id1 | class_category_id2 | delivery_date_id | creator_id | product_code | stock | stock_unlimited | sale_limit | price01 | price02 | delivery_fee | create_date | update_date | del_flg ------------------+------------+-----------------+--------------------+--------------------+------------------+------------+--------------+-------+-----------------+------------+---------+---------+--------------+---------------------+---------------------+--------- 0 | 1 | 1 | | | | 1 | fork-01 | | 1 | | 115000 | 110000 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 1 1 | 1 | 1 | 3 | 6 | | 1 | fork-01 | | 1 | | 115000 | 110000 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 2 | 1 | 1 | 3 | 5 | | 1 | fork-02 | | 1 | | 95000 | 93000 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 3 | 1 | 1 | 3 | 4 | | 1 | fork-03 | | 1 | | 75000 | 74000 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 4 | 1 | 1 | 2 | 6 | | 1 | fork-04 | | 1 | | 95000 | 93000 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 5 | 1 | 1 | 2 | 5 | | 1 | fork-05 | | 1 | | 50000 | 49000 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 6 | 1 | 1 | 2 | 4 | | 1 | fork-06 | | 1 | | 35000 | 34500 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 7 | 1 | 1 | 1 | 6 | | 1 | fork-07 | | 1 | | | 18000 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 8 | 1 | 1 | 1 | 5 | | 1 | fork-08 | | 1 | | | 13000 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 9 | 1 | 1 | 1 | 4 | | 1 | fork-09 | | 1 | | | 5000 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 10 | 2 | 1 | | | | 1 | cafe-01 | 100 | 0 | 5 | 3000 | 2800 | | 2017-01-19 14:27:02 | 2017-01-19 14:27:02 | 0 (11 rows)
dtb_product_image
eccube3=# \d dtb_product_image Table "public.dtb_product_image" Column | Type | Modifiers ------------------+--------------------------------+----------- product_image_id | integer | not null product_id | integer | not null creator_id | integer | not null file_name | text | not null rank | integer | not null create_date | timestamp(0) without time zone | not null Indexes: "dtb_product_image_pkey" PRIMARY KEY, btree (product_image_id) "idx_3267cc7a4584665a" btree (product_id) "idx_3267cc7a61220ea6" btree (creator_id) Foreign-key constraints: "fk_3267cc7a4584665a" FOREIGN KEY (product_id) REFERENCES dtb_product(product_id) "fk_3267cc7a61220ea6" FOREIGN KEY (creator_id) REFERENCES dtb_member(member_id) eccube3=# select * from dtb_product_image; product_image_id | product_id | creator_id | file_name | rank | create_date ------------------+------------+------------+------------+------+--------------------- 1 | 1 | 1 | fork-1.jpg | 1 | 2017-01-19 14:27:02 2 | 1 | 1 | fork-2.jpg | 2 | 2017-01-19 14:27:02 3 | 1 | 1 | fork-3.jpg | 3 | 2017-01-19 14:27:02 4 | 2 | 1 | cafe-1.jpg | 3 | 2017-01-19 14:27:02 5 | 2 | 1 | cafe-2.jpg | 3 | 2017-01-19 14:27:02 6 | 2 | 1 | cafe-3.jpg | 3 | 2017-01-19 14:27:02 (6 rows)
カスタマイズに向けて
既存のEC-CUBE3を古書店用にカスタマイズするためには、どうしたらいいのだろうか。
- 商品データのテーブルの列を拡張するには別途テーブルを作成してproduct_idで結合する、ということでよいのだろうか。
- 「日本の古本屋」の商品データは、どの列がEC-CUBEのどの列に対応しているのだろうか。(そもそも「日本の古本屋」はEC-CUBE2であると思われるが。)
- 「日本の古本屋」は商品テーブルのほかに書誌テーブルがあるが、後者をどのように実装するか。