4

次のコードは、Akeneo のドキュメントに記載されています: Use REST API 。コードを実行すると、次のような結果が得られます

RESULT:{"resource":"http:\/\/akeneo-pim.local\/api\/rest\/products\/OROMUG_DBO","family":"mugs","groups":OMUG_OB","OROMUG_ODB"]}}.....

同様の方法で、Akeneo に存在するカテゴリを取得したいと考えています。上記のコードは、WebserviceBundle の ProductController を使用しています。同様の方法でカテゴリを取得するには、どうすればよいですか。

4

2 に答える 2

3

実際、Akeneo PIM は現在、外部目的の製品 REST コントローラーのみを提供しています。

唯一の解決策は、独自のカテゴリ コントローラを作成して、PIM からカテゴリ データを抽出することです。

製品コントローラーは、開始するのに適したテンプレートです

カテゴリを適切に正規化する方法については、内部 API カテゴリ コントローラを参照することもできます。

于 2015-10-07T12:31:25.570 に答える
0

これは、「印刷」チャネルのすべての既存のカテゴリから選択できるフォームを表示するコントローラのサンプル コードです。

public function indexAction()
{

    $channels = $this->channelRepository->getFullChannels(); 
    $selected_channel = null;

    /*
    * default channels are: 'print', 'mobile' 'ecommerce'
    */
    foreach($channels as $channel) {
        if('print' == $channel->getCode() ) {
            $selected_channel = $channel;
            break;
        }
    }
    $categories = [];

    /*
    * fill-in the array with the values we're interested in
    */
    if($selected_channel) {
        $category = $selected_channel->getCategory();
        $categories_ids = array_merge([$category->getId()], $this->categoryRepository->getAllChildrenIds($category));

        foreach($categories_ids as $category_id) {
            $category = $this->categoryRepository->find($category_id);
            $categories[] = array('id' =>$category->getId(), 'label' => $category->getLabel());
        }
    }

    return $this->templating->renderResponse('CfXmlBundle:Form:index.html.twig', array('categories' => $categories, 'locale' => 'en_US', 'scope' => null));
}

関連する Twig テンプレート:

<form>
    <div style="clear: both; width: 100%;">
        <label>Choose a catalog:</label>
        <select name="category_id" style="width: 100%;">
        {% for category in categories %}
        <option value="{{ category.id }}">{{ category.label }}</option>
        {% endfor %}
        </select>
    </div>
    <div style="clear: both; width: 100%">
        <label>Catalog title</label>
        <input type="text" name="title" value="" style="width: 100%;" placeholder="default is choosen catalog name" />
    </div>
    <div style="clear: both; width: 100%;">
        <label>Catalog description</label>
        <textarea name="description" style="width: 100%;"></textarea>
    </div>
    <div style="clear: both;">
        <input style="float: left;" type="checkbox" name="prices" value="0" />
        <label style="float: left;">&nbsp;Show prices ?</label>
    </div>
    <div style="clear: both; text-align:right;">
        <input type="submit" value="Generate" />
    </div>    
</form>
于 2016-07-02T09:20:39.447 に答える