Пример #1
0
 protected function _prepareCollection()
 {
     $coreSlider = $this->_bannersliderHelper->getCoreSlider();
     $collection = $this->_collectionFactory->create();
     foreach ($coreSlider as $slider) {
         $collection->addItem($this->_objectFactory->create(['data' => ['id' => $slider['value'], 'title' => $slider['label']]]));
     }
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Пример #2
0
 /**
  * Prepare collection for grid
  *
  * @return $this
  */
 protected function _prepareCollection()
 {
     $collection = $this->_collectionFactory->create();
     foreach ($this->getTransactionAdditionalInfo() as $key => $value) {
         $data = new \Magento\Framework\DataObject(['key' => $key, 'value' => $value]);
         $collection->addItem($data);
     }
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Пример #3
0
 /**
  * Prepare the cart collection.
  *
  * @return $this
  */
 protected function _prepareCollection()
 {
     $quote = $this->getQuote();
     if ($quote) {
         $collection = $quote->getItemsCollection(false);
     } else {
         $collection = $this->_dataCollectionFactory->create();
     }
     $collection->addFieldToFilter('parent_item_id', ['null' => true]);
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Пример #4
0
 /**
  * Reformat base collection into collection without sub-collection in items
  *
  * @param \Magento\Framework\Data\Collection $baseCollection
  * @return \Magento\Framework\Data\Collection
  */
 protected function _getRowCollection(\Magento\Framework\Data\Collection $baseCollection = null)
 {
     if (null === $baseCollection) {
         $baseCollection = $this->getParentBlock()->getPreparedCollection();
     }
     $collection = $this->_collectionFactory->create();
     /** @var $item \Magento\Framework\Object */
     foreach ($baseCollection as $item) {
         if ($item->getIsEmpty()) {
             continue;
         }
         if ($item->hasChildren() && count($item->getChildren()) > 0) {
             /** @var $subItem \Magento\Framework\Object */
             foreach ($item->getChildren() as $subItem) {
                 $tmpItem = clone $item;
                 $tmpItem->unsChildren();
                 $tmpItem->addData($subItem->getData());
                 $collection->addItem($tmpItem);
             }
         } else {
             $collection->addItem($item);
         }
     }
     return $collection;
 }
Пример #5
0
 /**
  * Retrieve current store categories
  *
  * @param bool|string $sorted
  * @param bool $asCollection
  * @param bool $toLoad
  * @return \Magento\Framework\Data\Tree\Node\Collection or
  * \Magento\Catalog\Model\ResourceModel\Category\Collection or array
  */
 public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
 {
     $parent = $this->_storeManager->getStore()->getRootCategoryId();
     $cacheKey = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
     if (isset($this->_storeCategories[$cacheKey])) {
         return $this->_storeCategories[$cacheKey];
     }
     /**
      * Check if parent node of the store still exists
      */
     $category = $this->_categoryFactory->create();
     /* @var $category ModelCategory */
     if (!$category->checkId($parent)) {
         if ($asCollection) {
             return $this->_dataCollectionFactory->create();
         }
         return [];
     }
     $recursionLevel = max(0, (int) $this->scopeConfig->getValue('catalog/navigation/max_depth', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
     $storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
     $this->_storeCategories[$cacheKey] = $storeCategories;
     return $storeCategories;
 }
Пример #6
0
 /**
  * Retrieve media gallery images
  *
  * @return \Magento\Framework\Data\Collection
  */
 public function getMediaGalleryImages()
 {
     $directory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
     if (!$this->hasData('media_gallery_images') && is_array($this->getMediaGallery('images'))) {
         $images = $this->_collectionFactory->create();
         foreach ($this->getMediaGallery('images') as $image) {
             if (isset($image['disabled']) && $image['disabled']) {
                 continue;
             }
             $image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
             $image['id'] = !empty($image['value_id']) ? $image['value_id'] : null;
             $image['path'] = $directory->getAbsolutePath($this->getMediaConfig()->getMediaPath($image['file']));
             $images->addItem(new \Magento\Framework\DataObject($image));
         }
         $this->setData('media_gallery_images', $images);
     }
     return $this->getData('media_gallery_images');
 }