コード例 #1
0
 protected function _toOptionArray()
 {
     if (is_null($this->options)) {
         // Create options
         $this->options = array();
         $categories = $this->categoryCollection->getItems();
         foreach ($categories as $category) {
             $pathIds = $category->getPathIds();
             // skip root and default categories
             if (count($pathIds) < 3) {
                 continue;
             }
             // remove root and default from path
             $pathIds = array_slice($pathIds, 2);
             $path = [];
             foreach ($pathIds as $pathId) {
                 if (isset($categories[$pathId])) {
                     $path[] = $categories[$pathId]->getName();
                 }
             }
             $fullName = implode('/', $path);
             $this->options[] = ['value' => $category->getId(), 'label' => $fullName];
         }
         // Sort options
         usort($this->options, function ($option1, $option2) {
             return strcmp($option1['label'], $option2['label']);
         });
     }
     return $this->options;
 }