バージョン選択

フォーラム

メニュー

オンライン状況

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

サイト内検索

質問 > 管理機能 > 商品、会員の追加項目を受注にも反映させる

管理機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
kumaan
投稿日時: 2023/9/14 16:49
対応状況: 解決済
新米
登録日: 2023/9/11
居住地:
投稿: 9
商品、会員の追加項目を受注にも反映させる
お世話になっております。
見様見真似でEC-CUBEをカスタムして、BtoBサイトを構築中なのですがどうにも行き詰まってしまったので教えてください。

商品登録と会員登録の項目に、独自の項目を追加しました。
それらの情報を、受注時にも引き継ぎたいのです。

受注登録画面に項目を表示するために、

dtb_oder

に追加項目のテーブルを作成した後、

OderTypeExtension.php

を作成しました。


namespace Customize\Form\Extension\Admin;
use Eccube\Form\Type\Admin\OrderType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;



class OrderTypeExtension extends AbstractTypeExtension
{

    public static function getExtendedTypes(): iterable
    {
        yield OrderType::class;
    }
    

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            //請求先コード
            ->add('demandcode',TextType::class,[
                'required' => true
            ])
            //得意先コード
            ->add('customercode',TextType::class,[
                'required' => true
            ])
            //得意先名1
            ->add('customername1',TextType::class,[
                'required' => true
            ])
            //得意先名2
            ->add('customername2',TextType::class,[
                'required' => false
            ])
            //得意先FAX番号
            ->add('customerfaxno',TextType::class,[
                'required' => false
            ])
            //担当者コード
            ->add('chargecode',TextType::class,[
                'required' => true
            ])
            //倉庫コード
            ->add('warehousecode',TextType::class,[
                'required' => true
            ])
            //代引きなしフラグ
            ->add('codnotflgch',TextType::class,[
                'required' => true,
                'data' => '0',
            ]) ;


    }

}



その後で、Resource>template>Oderよりedit.twigをCustomize>template>admin>Oderにコピーして、該当箇所に下記のようにフォームを追記しました。

<div class="row mb-2">
         <div class="col-3">
           <span>{{ 'admin.common.customercode'|trans }}</span>
           <span class="badge bg-primary ms-1">{{ 'admin.common.required'|trans }}</span>
          </div>
                 <div class="col">
                    <div class="row">
                       <div class="col">
                           {{ form_widget(form.customercode) }}
                          </div>
                     </div>
                  <div class="row">
                     <div class="col">
                    {{ form_errors(form.customercode) }}
                       </div>
                       </div>
                  </div>
             </div>


ですが、管理画面側でシステムエラーが発生してうまくいきません。
エラーログは下記のとおりです。


[2023-09-14T16:47:21.465313+09:00] admin.ERROR [c64241ec] [0fccf3b] [1] [Eccube\Log\Logger:log:64] - システムエラーが発生しました。 ["Can't get a way to read the property \"demandcode\" in class \"Eccube\\Entity\\Order\".","/home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/property-access/PropertyAccessor.php",511,"#0 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/property-access/PropertyAccessor.php(154): Symfony\\Component\\PropertyAccess\\PropertyAccessor->readProperty(Array, 'demandcode', false)\n#1 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/form/Extension/Core/DataAccessor/PropertyPathAccessor.php(92): Symfony\\Component\\PropertyAccess\\PropertyAccessor->getValue(Object(Eccube\\Entity\\Order), Object(Symfony\\Component\\PropertyAccess\\PropertyPath))\n#2 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/form/Extension/Core/DataAccessor/PropertyPathAccessor.php(48): Symfony\\Component\\Form\\Extension\\Core\\DataAccessor\\PropertyPathAccessor->getPropertyValue(Object(Eccube\\Entity\\Order), Object(Symfony\\Component\\PropertyAccess\\PropertyPath))\n#3 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/form/Extension/Core/DataAccessor/ChainAccessor.php(40): Symfony\\Component\\Form\\Extension\\Core\\DataAccessor\\PropertyPathAccessor->getValue(Object(Eccube\\Entity\\Order), Object(Symfony\\Component\\Form\\Form))\n#4 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/form/Extension/Core/DataMapper/DataMapper.php(57): Symfony\\Component\\Form\\Extension\\Core\\DataAccessor\\ChainAccessor->getValue(Object(Eccube\\Entity\\Order), Object(Symfony\\Component\\Form\\Form))\n#5 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/form/Form.php(388): Symfony\\Component\\Form\\Extension\\Core\\DataMapper\\DataMapper->mapDataToForms(Object(Eccube\\Entity\\Order), Object(RecursiveIteratorIterator))\n#6 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/form/Form.php(492): Symfony\\Component\\Form\\Form->setData(Object(Eccube\\Entity\\Order))\n#7 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/form/FormBuilder.php(210): Symfony\\Component\\Form\\Form->initialize()\n#8 /home/redheart/ドメイン/public_html/ec-cube/src/Eccube/Controller/Admin/Order/EditController.php(220): Symfony\\Component\\Form\\FormBuilder->getForm()\n#9 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/http-kernel/HttpKernel.php(163): Eccube\\Controller\\Admin\\Order\\EditController->index(Object(Symfony\\Component\\HttpFoundation\\Request), Object(Symfony\\Bundle\\FrameworkBundle\\Routing\\Router), NULL)\n#10 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/http-kernel/HttpKernel.php(75): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#11 /home/redheart/ドメイン/public_html/ec-cube/vendor/symfony/http-kernel/Kernel.php(202): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#12 /home/redheart/ドメイン/public_html/ec-cube/index.php(83): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#13 {main}"] [GET, /ec-cube/administrator/order/new, 61.194.59.26, https://ドメイン/ec-cube/administrator/order, Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36]


そもそものお作法が間違っているのか、作法はあっているけどコードの表記がまずいのか、ご教授ください。
よろしくお願いいたします。
h_tanaka
投稿日時: 2023/9/14 16:56
対応状況: −−−
登録日: 2016/7/22
居住地: 愛媛県
投稿: 1423
Re: 商品、会員の追加項目を受注にも反映させる
FormType が参照している Entity に追加されたフィールドがないためです。
こちら参考にしてください。
https://doc4.ec-cube.net/customize_entity


----------------
EC-CUBE 《プラチナ》ランクパートナー
トエビス株式会社 田中 宏典
EC-CUBEの機能やデザインのカスタマイズ承ります。

kumaan
投稿日時: 2023/9/15 11:38
対応状況: −−−
新米
登録日: 2023/9/11
居住地:
投稿: 9
Re: 商品、会員の追加項目を受注にも反映させる
回答ありがとうございます。
Entityを見るとスペルミスやOrderをCustomerのままだったり色々なミスがありました。
それらを一通り尚下にも関わらず、同じエラーが出ております。


請求先コードのdemandcodeを削除しても

"Can't get a way to read the property \"demandcode\" in class \"Eccube\\Entity\\Order\".",

と出るので書き方が間違っているのだと思いますが、引用したProductTraitは全く問題なく動作しているので違いがわかりません。
お手数ですが再度ご教授いただけないでしょうか。

<?php

namespace Customize\Entity;

use Doctrine\ORM\Mapping as ORM;
use Eccube\Annotation\EntityExtension;

/**
 * @EntityExtension("Eccube\Entity\Order")
 */
trait OrderTrait
{
    /*請求先コード*/
    /**
      * @var string
      *
      * @ORM\Column(name="demandcode", type="string", length=7, nullable=true)
      */
      private $demandcode = null;
      /**
       * 
       * @param string $demandcode|null
       * 
       * @return Order
       */
      public function setDemandCode($demandcode = null)
      {
        $this->demandcode = $demandcode;
        return $this;
      }
      /**
       * 
       * @return string|null
       */
      public function getDemandCode()
      {
        return $this->demandcode;
      }
h_tanaka
投稿日時: 2023/9/15 11:43
対応状況: −−−
登録日: 2016/7/22
居住地: 愛媛県
投稿: 1423
Re: 商品、会員の追加項目を受注にも反映させる
Proxy 生成やスキーマ更新などのコマンドは実行していますか?

EC-CUBEバージョンの記載がないので最新版 4.2.2 の場合でしたら、
app/proxy/entity 配下に Proxy ファイルが生成されるはずなので、指定された Entity やフィールドの定義があるか確認してみてください。


----------------
EC-CUBE 《プラチナ》ランクパートナー
トエビス株式会社 田中 宏典
EC-CUBEの機能やデザインのカスタマイズ承ります。

h_tanaka
投稿日時: 2023/9/15 11:49
対応状況: −−−
登録日: 2016/7/22
居住地: 愛媛県
投稿: 1423
Re: 商品、会員の追加項目を受注にも反映させる
エラーは FormType で発生していませんか?
FormType で定義している demandcode と Entity で定義している demandcode が合致しないのだと思います。


----------------
EC-CUBE 《プラチナ》ランクパートナー
トエビス株式会社 田中 宏典
EC-CUBEの機能やデザインのカスタマイズ承ります。

kumaan
投稿日時: 2023/9/15 14:41
対応状況: −−−
新米
登録日: 2023/9/11
居住地:
投稿: 9
Re: 商品、会員の追加項目を受注にも反映させる
ご指摘の通りProxyにOderTriatが反映されていなかったので更新し、ProductTraitの表記と一部分違うところがあったのでそれらを調整しました。

public function setProductionArea($production_area = null)
{
$this->production_area = $production_area;
return $this;
}


production_areaに合わせて、damand_codeと変更して、
SetDemandCode($demand_code = null)で表記を合わせて更新したところ、下記のエラーになりました。

<会員登録>

2023-09-15T14:34:33.644642+09:00] admin.ERROR [aaeb55eb] [ffa337c] [1] [Eccube\Log\Logger:log:64] - システムエラーが発生しました。 ["Can't get a way to read the property \"_\" in class \"Eccube\\Entity\\Customer\".",



<受注登録>
[2023-09-15T14:35:02.960112+09:00] admin.ERROR [aaeb55eb] [dd5abc3] [1] [Eccube\Log\Logger:log:64] - システムエラーが発生しました。 ["Neither the property \"customer_code\" nor one of the methods \"customer_code()\", \"getcustomer_code()\"/\"iscustomer_code()\"/\"hascustomer_code()\" or \"__call()\" exist and have public access in class \"Symfony\\Component\\Form\\FormView\"


今度は別のところにエラーが出てしまいました。
customer_codeのtwingファイルやTrait、CustomerTypeEctensionすべて眺めたのですが記載ミスが見つかりません。


namespace Customize\Form\Extension\Admin;
use Eccube\Form\Type\Admin\CustomerType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

class CustomerTypeExtension extends AbstractTypeExtension
{

    public static function getExtendedTypes(): iterable
    {
        yield CustomerType::class;
    }
    

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            //請求先コード
            ->add('demand_code',TextType::class,[
                'required' => true
            ])
            //得意先コード
            ->add('customer_code',TextType::class,[
                'required' => true
            ])
            //得意先名1
            ->add('customer_name1',TextType::class,[
                'required' => true
            ])
            //得意先名2
            ->add('_',TextType::class,[
                'required' => false
            ])
            //得意先FAX番号
            ->add('customer_faxno',TextType::class,[
                'required' => false
            ])
            //担当者コード
            ->add('charge_code',TextType::class,[
                'required' => true
            ])
            //倉庫コード
            ->add('warehouse_code',TextType::class,[
                'required' => true
            ])
            //代引きなしフラグ
            ->add('codnot_flgch',TextType::class,[
                'required' => true,
                'data' => '0',
            ]) ;
    }

}


namespace Customize\Entity;

use Doctrine\ORM\Mapping as ORM;
use Eccube\Annotation\EntityExtension;

/**
 * @EntityExtension("Eccube\Entity\Customer")
 */
trait CustomerTrait
{
    /*請求先コード*/
    /**
      * @var string|null
      *
      * @ORM\Column(name="demand_code", type="string", length=7, nullable=true)
      */
      private $demand_code = null;
      /**
       * 
       * @param string $demand_code|null
       * 
       * @return Customer
       */
      public function setDemandCode($demand_code = null)
      {
        $this->demand_code = $demand_code;
        return $this;
      }
      /**
       * 
       * @return string|null
       */
      public function getDemandCode()
      {
        return $this->demand_code;
      }


    /*得意先コード*/
    /**
      * @var string|null
      *
      * @ORM\Column(name="customer_code", type="string", length=7, nullable=true)
      */
      private $customer_code = null;
      /**
       * 
       * @param string $customer_code|null
       * 
       * @return Customer
       */
      public function setCustomerCode($customer_code = null)
      {
        $this->customer_code = $customer_code;
        return $this;
      }
      /**
       * 
       * @return string|null
       */
      public function getCustomerCode()
      {
        return $this->customer_code;
      }


<div class="row mb-2">
                                    <div class="col-3">
                                        <span>{{ 'admin.common.customer_code'|trans }}</span>
                                        <span class="badge bg-primary ms-1">{{ 'admin.common.required'|trans }}</span>
                                    </div>
                                    <div class="col">
                                        <div class="row">
                                            <div class="col">
                                                {{ form_widget(form.customer_code) }}
                                                {{ form_errors(form.customer_code) }}
                                            </div>
                                        </div>
                                    </div>
                                </div>



引き続きお手数をおかけしますがよろしくお願いいたします。
h_tanaka
投稿日時: 2023/9/15 14:57
対応状況: −−−
登録日: 2016/7/22
居住地: 愛媛県
投稿: 1423
Re: 商品、会員の追加項目を受注にも反映させる
エラーが発生した場合は、エラーログに出力されている情報をよく見て理解してください。
エラーログにはエラーが発生したファイルと行番号も出ているはずなので、その箇所を確認してください。

おそらくですが、会員登録のエラーは CustomerTypeExtension に定義されている 得意先名2 の '_' というフィールドが CustomerTrait に未定義なのではないかと思われます。

受注登録のエラーは customer_code というフォームが OrderTrait に未定義なのではないかと思われます。


----------------
EC-CUBE 《プラチナ》ランクパートナー
トエビス株式会社 田中 宏典
EC-CUBEの機能やデザインのカスタマイズ承ります。

kumaan
投稿日時: 2023/9/15 15:56
対応状況: −−−
新米
登録日: 2023/9/11
居住地:
投稿: 9
Re: 商品、会員の追加項目を受注にも反映させる
ありがとうございます。
ログ→システムのエラーでは読んでもわからず、デバッグモードにもならないので頭を悩ませていたのですが、デバッグモードの設定を間違っていました。

デバッグモードが動いたら何が間違ってるかわかりました。

Oderのedit.twigにShipping.がついていたので追加項目にもそれを入れていたのですがそれが間違いでした。

初歩的なミスにお時間頂戴して、ご指摘いただきありがとうございました。
スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


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

統計情報

総メンバー数は83,340名です
総投稿数は107,767件です

投稿数ランキング

1
seasoft
7342
2
468
3217
3
AMUAMU
2712
4
nanasess
2288
5
umebius
2085
6
yuh
1789
7
red
1560
8
h_tanaka
1423
9
tsuji
957
10
fukap
907
11
mcontact
897
12
shutta
835
13
tao_s
794
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.