インストールスクリプトを介してウィジェットを作成および配置します

magento.stackexchange https://magento.stackexchange.com/questions/11904

質問

ウィジェットインスタンスを作成して、特定のページに割り当ててインストールスクリプトを介して表示できますか?サンプルの内容と同様の機能をいくつか持ちたいのですが、ウィジェットを使用します。より具体的には、私の質問は、ウィジェットのインスタンスを作成し、インストールスクリプトを介してプログラムで特定のページに配置することを目的としています。

役に立ちましたか?

解決

きれいではありませんが、もちろん、セットアップスクリプトなど、プログラムでウィジェットインスタンスを作成できます。

$widgetParameters = array(
    'param1' => 'This is some value from the widget form,
    'param2' => 'Some/other/value',
    'param2_2' => 'Rly?',
    'template' => 'this/is/the/template.phtml'
);

$instance = Mage::getModel('widget/widget_instance')->setData(array(
    'type' => 'your_module/your_widget',
    'package_theme' => 'default/theme', // has to match the concrete theme containing the template
    'title' => 'This is the Widget title',
    'store_ids' => '0', // or comma separated list of ids
    'widget_parameters' => serialize($widgetParameters),
    'page_groups' => array(array(
        'page_group' => 'all_pages',
        'all_pages' => array(
            'page_id' => null,
            'group' => 'all_pages',
            'layout_handle' => 'default',
            'block' => 'left',
            'for' => 'all',
            'template' => $widgetParameters['template],
        )
    ))
))->save();

この例では、左列のすべてのページに表示するウィジェットインスタンスを設定します。
異なるページまたはターゲットブロックを指定する場合は、それに応じて値を更新する必要があります。何が設定されているかを見ることをお勧めします Mage_Widget_Adminhtml_Widget_InstanceController::saveAction() それに応じて上記のコードを調整します。

他のヒント

スクリプトではなくカスタムモジュールを作成できます。このMagentoの公式リンクを参照してMagentoウィジェットを作成できます

http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-magento-widget-part-1

http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-magento-widget-part-2

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top