2015-10-07 153 views
4

以下代码已在Akeneo文档中给出: Use REST API 。在代码的执行,它给人造成像获取Akeneo中的类别列表

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

我想目前在Akeneo以类似的方式的类别。上面的代码使用WebserviceBundle中的ProductController。我应该如何继续以类似的方式获得类别。

回答

3

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

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

product controller是一个很好的模板,开始

您也可以看看我们的internal API category controller,看看如何正确规范类

+1

感谢@julien,我会考虑它。 :) –

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)); 
} 

及相关枝条模板:

<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>