首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取Akeneo中的类别列表

获取Akeneo中的类别列表
EN

Stack Overflow用户
提问于 2015-10-07 20:14:11
回答 2查看 1.2K关注 0票数 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。我应该如何处理才能以类似的方式获取类别。

EN

回答 2

Stack Overflow用户

发布于 2015-10-07 20:31:26

事实上,Akeneo PIM目前只为外部目的提供了一个产品REST控制器。

您唯一的解决方案是创建自己的类别控制器,以便从PIM中提取类别数据。

product controller是一个很好的入门模板

您还可以查看我们的internal API category controller,了解如何正确地规范化类别

票数 3
EN

Stack Overflow用户

发布于 2016-07-02 17:20:39

下面是一个控制器的示例代码,该控制器显示一个表单,允许从“打印”通道的所有现有类别中进行选择。

代码语言:javascript
复制
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模板:

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32991915

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档