バージョン選択

フォーラム

メニュー

オンライン状況

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

サイト内検索

プラグイン > 開発について > 商品登録ページの拡張フォームで product_id を取得したい

開発について

新規スレッドを追加する

フラット表示 前のトピック | 次のトピック
投稿者 スレッド
h_tanaka
投稿日時: 2017/6/5 15:30
対応状況: 解決済
登録日: 2016/7/22
居住地: 愛媛県
投稿: 1657
Re: 商品登録ページの拡張フォームで product_id を取得したい
最終的に次のようなコードになりました。


class ProductTypeExtension extends AbstractTypeExtension
{
    public $app;

    public function __construct($app)
    {
        $this->app = $app;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $app = $this->app;
        if (!$app->isGranted('ROLE_ADMIN')) {
            return;
        }

        $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($app) {
            $Product = $event->getData();
            if (!$Product) {
                return;
            }
            $product_id = $Product->getId();
            if (!$product_id) {
                return;
            }

            $default = null;
            $TestProduct = $app['eccube.plugin.test.repository.test_product']->findOneBy(array('product_id' => $product_id));
            if ($TestProduct) {
                $default = $TestProduct->getId();
            }

            $Tests = $app['eccube.repository.xxxxx']->findBy(array(), array('rank' => 'DESC'));
            if (empty($Tests) || !is_array($Tests)) {
                return;
            }
            $selTests = array();
            foreach ($Tests as $Test) {
                $selTests[$Test->getId()] = $Test;
            }

            $form = $event->getForm();

            $form->add('plg_test_id', 'choice', array(
                'mapped' => false,
                'required' => true,
                'choices' => array('__unselected' => '選択してください') + $seTests,
                'data' => $TestProduct->getId(),
                'constraints' => array(
                    new Assert\NotBlank(),
                    new Assert\NotEqualTo(array(
                        'value' => '__unselected',
                        'message' => 'form.type.select.notselect'
                    )),
                ),
            ))
        });
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
    }

    public function getExtendedType()
    {
        return 'admin_product';
    }
}


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

フラット表示 前のトピック | 次のトピック


題名 投稿者 日時
   商品登録ページの拡張フォームで product_id を取得したい h_tanaka 2017/6/5 11:47
     Re: 商品登録ページの拡張フォームで product_id を取得したい nyorai 2017/6/5 14:20
       Re: 商品登録ページの拡張フォームで product_id を取得したい h_tanaka 2017/6/5 14:39
         Re: 商品登録ページの拡張フォームで product_id を取得したい nyorai 2017/6/5 14:58
           Re: 商品登録ページの拡張フォームで product_id を取得したい h_tanaka 2017/6/5 15:09
             Re: 商品登録ページの拡張フォームで product_id を取得したい h_tanaka 2017/6/5 15:25
             » Re: 商品登録ページの拡張フォームで product_id を取得したい h_tanaka 2017/6/5 15:30

 



ログイン


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

統計情報

総メンバー数は89,651名です
総投稿数は110,158件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2314
5
umebius
2085
6
yuh
1819
7
h_tanaka
1657
8
red
1570
9
mcontact
1323
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
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.