バージョン選択

フォーラム

メニュー

オンライン状況

58 人のユーザが現在オンラインです。 (47 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 58
もっと...

サイト内検索

質問 > 管理機能 > タグIDで条件分岐

管理機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
nanase
投稿日時: 2021/4/18 7:29
対応状況: 解決済
新米
登録日: 2021/4/18
居住地:
投稿: 3
タグIDで条件分岐
▼テンプレート
[EC-CUBE] EC-CUBE4.0.5 新規インストール
[レンタルサーバ] Xserver
[OS] Linux
[PHP] PHP Version 7.3.25
[データベース] MySQL 5.7.29
[WEBサーバ] Apache
[ブラウザ] Safari ,Chrome
[導入プラグインの有無] 無し
[カスタマイズの有無] 無し
[現象]

初心者です、タグIDを使用して条件分岐を書きたく下記のサイトを参考にさせて頂きsrc/Eccube/Entity/Product.phpの1054行目に以下を追加しました。
(https://umebius.com/eccube/check_if_product_has_tag/)

/**
* 商品にタグが設定されているかどうかをbooleanで返却するメソッド
* @see https://umebius.com/eccube/check_if_product_has_tag/
* @param $Tag \Eccube\Entity\Tag|integer|string
* @return bool
*/
public function hasTag($Tag){
return false === $this->ProductTag->filter(function (ProductTag $T) use ($Tag){
if (is_int($Tag)) {
if ($T->getTagId() === $Tag) {
return true;
}
} else if (is_string($Tag)) {
if ($T->getTag()->getName() === $Tag) {
return true;
}
} else if ($Tag instanceof \Eccube\Entity\Tag) {
if ($T->getTag() === $Tag) {
return true;
}
}
return false;
})->isEmpty();
}

ページ管理の商品詳細にて以下を追加しましたが該当のタグIDがあっても「限定品です」の表記になりませんでした。
記載されている通りに出来ているとは思うのですがどこかやり方が間違っているのでしょうか、教えて頂ければ幸いです。
よろしくお願いいたします。

{% if Product.hasTag(3) %}
限定品です。
{% else %}
限定品ではありません。
{% endif %}
tsuji
投稿日時: 2021/4/19 9:35
対応状況: −−−
仙人
登録日: 2013/11/19
居住地:
投稿: 958
Re: タグIDで条件分岐
nanase 様

「限定品ではありません」が表示されているという理解であっていますか?

限定品・限定品ではありません のどちらも出ていないようでしたら、
EC-CUBE管理画面からキャッシュクリアはされていますか?

もしくはデバッグモードで試して、何かエラーが起きていますか?


----------------
****************************************
株式会社システムフレンド
辻 拓也(takuya tsuji)
改造専門店・EC-CUBE工房
****************************************

nanase
投稿日時: 2021/4/19 23:20
対応状況: −−−
新米
登録日: 2021/4/18
居住地:
投稿: 3
Re: タグIDで条件分岐
tsuji様
ご回答ありがとうございます。
仰る通り「限定品ではありません」が表示されています。
(キャッシュは管理画面からクリアしており、sshでもコマンドでクリアしてあります。)

デバッグモードで開いてみましたが申し訳ありませんが見方が分からないです。
hasTagというプロパティのメソッドが存在しないと書いてあるのは分かるのですがどこを直せば良いのかが分かりません。
内容を記載するのでご助言頂けると大変助かります。
よろしくお願いいたします。

▼RuntimeError(line 389)

389行目 {% if Product.hasTag(3) %}

// line 389
if (twig_get_attribute($this->env, $this->source, (isset($context["Product"]) || array_key_exists("Product", $context) ? $context["Product"] : (function () { throw new RuntimeError('Variable "Product" does not exist.', 389, $this->source); })()), "hasTag", [0 => 3], "method", false, false, false, 389)) {

Twig\Error\RuntimeError:
Neither the property "hasTag" nor one of the methods "hasTag()", "gethasTag()"/"ishasTag()"/"hashasTag()" or "__call()" exist and have public access in class "Eccube\Entity\Product".

▼Logsのページ

INFO
php
User Deprecated: The "base_template_class" option on Twig\Environment is deprecated since Twig 2.7.0.

INFO
php
User Deprecated: Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine ORM 3.0.

INFO
php
User Deprecated: The type "datetime" was implicitly marked as commented due to the configuration. This is deprecated and will be removed in DoctrineBundle 2.0. Either set the "commented" attribute in the configuration to "false" or mark the type as commented in "Eccube\Doctrine\DBAL\Types\UTCDateTimeType::requiresSQLCommentHint()."

INFO
php
User Deprecated: The type "datetimetz" was implicitly marked as commented due to the configuration. This is deprecated and will be removed in DoctrineBundle 2.0. Either set the "commented" attribute in the configuration to "false" or mark the type as commented in "Eccube\Doctrine\DBAL\Types\UTCDateTimeTzType::requiresSQLCommentHint()."
tsuji
投稿日時: 2021/4/21 9:29
対応状況: −−−
仙人
登録日: 2013/11/19
居住地:
投稿: 958
Re: タグIDで条件分岐
nanase 様

↓のエラーが出ているということは、ProductにhasTagという関数がないということです。

キャッシュはクリアされているとのことでしたし、プラグインも入れていないということなので、
後は、Customizeディレクトリ配下にProductのEntityのTraitを作っておられたりしませんか?
もし、そちらに作っておられるなら、そこに入れられたらよいかと思います。

Entityは拡張できる作りになっていますので、そのあたりを確認するという感じでしょうか。

Neither the property "hasTag" nor one of the methods "hasTag()", "gethasTag()"/"ishasTag()"/"hashasTag()" or "__call()" exist and have public access in class "Eccube\Entity\Product".



推測で違うかもしれませんので、ご参考までにしていただけたらと思います。


----------------
****************************************
株式会社システムフレンド
辻 拓也(takuya tsuji)
改造専門店・EC-CUBE工房
****************************************

nanase
投稿日時: 2021/4/21 10:36
対応状況: 解決済
新米
登録日: 2021/4/18
居住地:
投稿: 3
Re: タグIDで条件分岐
tsuji様
再度ご回答頂きありがとうございます。
カスタマイズもしていないので思い当たる節が無かったのですが、
EC-CUBEを再インストールしproduct.phpに記載したところ無事希望した表示が出来ました!
お騒がせして申し訳ございませんでした。

tsuji様にご提示頂いたEntityの拡張について興味があるのでこれから勉強していきたいと思います。
ご回答頂きありがとうございました。
また機会がございましたらご助言のほどよろしくお願いいたします。
スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は88,284名です
総投稿数は109,688件です

投稿数ランキング

1
seasoft
7365
2
468
3217
3
AMUAMU
2712
4
nanasess
2303
5
umebius
2085
6
yuh
1818
7
h_tanaka
1610
8
red
1567
9
mcontact
1240
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
796
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.