LoginSignup
8
10

More than 5 years have passed since last update.

EC-CUBEで複数DBで会員データを共通化する

Posted at

EC-CUBEで複数の店舗(データベース)を作ったけど、会員データは共通化したい、というケースはよくあるかと思います。

MySQLのみですが、同一のDBサーバに複数のDBがある構成であれば、かんたんに共通化することができます。

店舗Aと店舗Bがあり、店舗Aの会員データを両方の店舗で使いたい、というケースであれば、次のような対応になります。

店舗Bの、doctrineのdcm.ymlファイルを以下のように編集します。

src/Resource/doctrine/Eccube.Entity.Customer.dcm.yml
Eccube\Entity\Customer:
    type: entity
    table: [店舗Aのデータベース名].dtb_customer
    repositoryClass: Eccube\Repository\CustomerRepository
    ...
src/Resource/doctrine/Eccube.Entity.CustomerAddress.dcm.yml
Eccube\Entity\CustomerAddress:
    type: entity
    table: [店舗Aのデータベース名].dtb_customer_address
    repositoryClass: Eccube\Repository\CustomerAddressRepository
    ...
src/Resource/doctrine/Eccube.Entity.CustomerFavoriteProducuct.dcm.yml
Eccube\Entity\CustomerFavoriteProduct:
    type: entity
    table: [店舗Aのデータベース名].dtb_customer_favorite_product
    repositoryClass: Eccube\Repository\CustomerFavoriteProductRepository

次に、app/config/eccube/config.ymlauth_magicを店舗Aと同じ値に設定します。

app/config/eccube/config.yml
auth_magic: xxxxx <- 店舗Aの値を設定
password_hash_algos: sha256
shop_name: 'EC-CUBE SHOP'
...

以上です。

これで会員データは共通化され、どちらのサイトでもログインすることができます。

今回はMySQLの例ですが、PostgreSQLの場合は、同じデータベース内でスキーマを変更すれば同様の対応が可能です。

8
10
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
10