[EC-CUBE4]商品 項目の追加

未分類

Entityの拡張、ファイルの作成

ターミナル操作が苦手なので FTPよりログインして操作

/app/Customize/Entity に移動し、

ProductTrait.php というファイルを作成

/app/Customize/Entity/ProductTrait.phpの中身

______________________

<?php

// app/Customize/Entity/ProductTrait.php

namespace CustomizeEntity;

use DoctrineORMMapping as ORM;

use EccubeAnnotation as Eccube;

/**

  * @EccubeEntityExtension(“EccubeEntityProduct”)

 */

trait ProductTrait

{

    /**

     * @ORMColumn(type=”string”, nullable=true)

     * @EccubeFormAppend(

     *  auto_render=true,

     *  options={

     *   “required”: false,

     *   “label”:”表地”

     *  }

     * )

     */

    public $front_fabric;

}

______________________

→表地の項目を追加、DB表記はfront_fabric

コマンドラインでProxyクラスを生成

ターミナルよりログイン

$ ssh -i ~/.ssh/秘密鍵ファイル名 -p 10022 ホスト名.xserver.jp -l サーバ名

(config作った方がログイン楽かも)

現在地確認

$ pwd

→返答

/home/サーバ名

ECCUBEインストールしたディレクトリに移動

$ cd ~/ドメイン名/public_html/ec

Proxyクラスを生成

$ bin/console eccube:generate:proxies

→返答

bin/console: 許可がありません

$ chmod u+x bin/console

$ bin/console eccube:generate:proxies

→返答、エラー

PHP Parse error:  syntax error, unexpected ‘class’ (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or ‘{‘ or ‘$’ in /home/サーバ名/ドメイン名/public_html/ec/bin/console on line 15

参考リンク(エラーについて):

https://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=23114&forum=11

PHPのバージョン確認

$ php -v

→返答

PHP 5.4.16 (cli) (built: Nov  1 2019 16:04:20) 

(php5って何事よ)

vi で編集

$ vi .bash_profile

PATH=$PATH:$HOME/bin → PATH=$HOME/bin:$PATH に変更

(xキーで削除、iキーで入力、escキーで抜けて:wqキーで保存して終了)

参考リンク(phpバージョン):

https://pgmemo.tokyo/data/archives/1350.html

参考リンク(vi操作):

https://eng-entrance.com/linux-command-vi

PHP7.3に向ける

$ mkdir $HOME/bin

$ ln  -s  /usr/bin/php7.3 $HOME/bin/php

ログアウトしてバージョン確認

$ php -v

→返答

PHP 7.3.25 (cli) (built: Dec  6 2020 21:04:53) ( NTS )

再度ECCUBEディレクトリに移動してproxyコマンド入力

$ cd ~/ドメイン名/public_html/ec

$ bin/console eccube:generate:proxies

→返答

gen ->/home/サーバ名/ドメイン名/public_html/ec/app/proxy/entity/src/Eccube/Entity/Product.php

キャッシュをクリア

$ bin/console cache:clear --no-warmup

→返答

 [OK] Cache for the "prod" environment (debug=false) was successfully cleared.

実行する SQL を確認

$ bin/console doctrine:schema:update --dump-sql

→返答

The following SQL statements will be executed:

ALTER TABLE dtb_product ADD front_fabric VARCHAR(255) DEFAULT NULL;

(front_fabricがない(null))

SQL を実行

$ bin/console doctrine:schema:update --dump-sql --force

→返答
 [OK] Database schema updated successfully!     

phpMyAdminにログインして
dtb_productに項目が追加されているのを確認。
(ログインIDとパスはサーバ登録時のメールに記載されている)

商品登録画面にも表示されていることを確認。

商品ページに項目を表示

●表品詳細のページのフリーエリアに下記タグ入れれば表示される
表地:{{ include(template_from_string(Product.front_fabric))}}

●if文を使って記入されているときだけ表示させる
{% if Product.front_fabric %}
  表地:{{ include(template_from_string(Product.front_fabric))}}
{% endif %}

以上で全工程完了。項目を複数追加するのには{}を繋げてけばいいのかな。

参考リンク:

https://www.creatorlab.jp/2019/04/17/ec-cube-4商品情報の項目を追加する/

参考リンク:

https://sorovider.com/2019/03/20/ec-cube4で商品項目等の追加/

コメント

タイトルとURLをコピーしました