0

Prestashop 1.5に到着したばかりで、非常に単純なモジュールを作成しています。そのすぐ隣に表示する必要のある複数の製品に関連する今週のビデオです。

私はバックオフィスから始めることにしました。現在、すべてのビデオエントリを表示、追加、編集、および削除できますが、ビデオとその関連製品の間のNNアソシエーションをマッピングする方法に少し迷っています...ドキュメントの欠如も役に立ちません。

これをやってのける方法はありますか?

これが私のコードの一部です。Videoクラスは次のように定義されています。

class Video extends ObjectModel {

    public $id_video;
    public $title;
    public $url;
    public $active;

    public static $definition = array(
        'table'     => 'video',
        'primary'   => 'id_video',
        'multilang' => false,
        'fields' => array(
            'id_video' => array(
                'type' => ObjectModel :: TYPE_INT
            ),
            'title' => array(
                'type' => ObjectModel :: TYPE_STRING, 
                'required' => true
            ),
            'url' => array(
                'type' => ObjectModel :: TYPE_STRING, 
                'required' => true
            ), 
            'active' => array(
                'type'      => ObjectModel :: TYPE_BOOL, 
                'required'  => true
            )
        ),
    );

(...)

AdminVideoクラスはここにあります:

class AdminVideoController extends ModuleAdminController {

    public function __construct()
    {
        $this->table = 'video';
        $this->className = 'Video';
        $this->lang = false;

        $this->fields_list['id_video'] = array(
            'title' => $this->l('ID'),
            'align' => 'center',
        );

        $this->fields_list['title'] = array(
            'title' => $this->l('Title'),
            'width' => 'auto'
        );

        $this->fields_list['url'] = array(
            'title' => $this->l('URL'),
            'width' => 'auto'
        );

        $this->fields_list['active'] = array(
            'title' => $this->l('Active'),
            'width' => '70',
            'align' => 'center',
            'active' => 'status',
            'type' => 'bool',
            'orderby' => false
        );

        parent::__construct();
    }

    public function postProcess()
    {
         parent::postProcess();
    }

    public function renderList()
    {
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        $this->addRowAction('details');

        return parent::renderList();
    }

    public function renderForm()
    {
        if (!($obj = $this->loadObject(true)))
            return;

        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('This weeks video'),
                'image' => '../img/admin/world.gif'
            ),
            'input' => array(
                array(
                    'type' => 'text',
                    'label' => $this->l('Nome'),
                    'name' => 'title',
                    'size' => 33,
                    'required' => true,
                    'desc' => $this->l('Title')
                ),
                array(
                      'type' => 'text',
                      'label' => $this->l('URL'),
                      'name' => 'url',
                      'size' => 33,
                      'required' => true,
                      'desc' => $this->l('Video URL')
                ),
                array(
                    'type' => 'radio',
                    'label' => $this->l('Active:'),
                    'name' => 'active',
                    'required' => false,
                    'class' => 't',
                    'is_bool' => true,
                    'values' => array(
                        array(
                            'id' => 'active_on',
                            'value' => 1,
                            'label' => $this->l('Enabled')
                        ),
                        array(
                            'id' => 'active_off',
                            'value' => 0,
                            'label' => $this->l('Disabled')
                        )
                    ),
                    'desc' => $this->l('Only one video can be active at any given time')
                ),
            )
        );

        if (Shop::isFeatureActive())
        {
            $this->fields_form['input'][] = array(
                'type' => 'shop',
                'label' => $this->l('Shop association:'),
                'name' => 'checkBoxShopAsso',
            );
        }

        $this->fields_form['submit'] = array(
            'title' => $this->l('   Save   '),
            'class' => 'button'
        );

        if (!($obj = $this->loadObject(true)))
            return;

        return parent::renderForm();
    }
  }

もう1つ、バックオフィス内にビデオのプレビューを追加することは可能でしょうか?YouTubeの埋め込みコードをエコーし​​ようとしましたが、ヘッダーの前に挿入されます。これを行うためのクリーンな方法はありますか、それともjQueryのトリックを使用する必要がありますか?私は基本的に、postProcess()が終了する直前にYTの埋め込みコードのエコーを実行していました。

前もって感謝します!

4

1 に答える 1

2

ビデオを製品に関連付ける最も簡単な方法は、「ビデオ」テーブルに「製品」テキストフィールドを追加して、関連する製品のIDのコンマ区切りリストを保存することです(例:1,10,27)。少し初歩的なものでも、機能するはずです。
または、次のようなテーブルを使用することもできます。

create table video_product (
  id_association int not null auto_increment,
  id_video int,
  id_product int,
  primary key (id_association)
);

このソリューションの問題は、PrestaShop ObjectModelコアが、関連するテーブルを自動的に更新または削除するメソッドを提供しないことです(少なくとも私が知る限り)。そのため、「video_product」テーブルを管理するコードを挿入する必要があります。 「ビデオ」クラス。
これを行う方法の例が必要な場合はclasses/Product.php、製品テーブルとそれに関連するすべてのテーブル(カテゴリ、タグ、機能、添付ファイルなど)を管理するスクリプトを確認する必要があります。
Prestashopデータベースがどのように構成されているかを知るにはdocs/dbmodel.mwb、データベースのスキーマを含むファイルを見てください。このファイルは、MySQLWorkbenchアプリケーションを使用して表示できます。

于 2012-11-11T20:52:08.720 に答える