ProductTrait.phpの作成
「/ドメイン/public_html/store/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 サーバ名
現在地確認$ pwd
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)
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
現在のPHPに向ける$ mkdir $HOME/bin
$ ln -s /usr/bin/php8.2 $HOME/bin/php
ログアウトしてバージョン確認$ php -v
再度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に項目が追加されているのを確認。
商品ページに項目を表示
▼表品詳細のページのフリーエリアに下記タグ入れれば表示される表地:{{ 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で商品項目等の追加/