【问题标题】:Getting list of categories in Akeneo获取 Akeneo 中的类别列表
【发布时间】:2015-10-07 12:14:11
【问题描述】:

以下代码已在 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。我应该如何进行才能以类似的方式获取类别。

【问题讨论】:

    标签: php symfony akeneo


    【解决方案1】:

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

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

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

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

    【讨论】:

      【解决方案2】:

      这里是控制器的一些示例代码,它显示了一个允许从“打印”通道中选择所有现有类别的表单。

      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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-04
        • 1970-01-01
        • 1970-01-01
        • 2018-07-20
        相关资源
        最近更新 更多