2015-10-07 152 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>