daniel-rose / magento2-gallery

Gallery module for Magento 2
15 stars 5 forks source link

Features and status #1

Closed viktor-zhuromskyy closed 8 years ago

viktor-zhuromskyy commented 8 years ago

Would you be so kind to update your readme.md with features set and status of the extension, please?

letunhatkong commented 8 years ago

I downloaded this extension and try test on my local. This extension created Gallery Module on content section of M2 admin. It includes 2 sections: Galleries, and Images.

This extension is worked on Admin page. All data are stored on DB. But i can't get galleries in front-end. :(

<?php
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$gallery = $_objectManager->get('DR\Gallery\Block\Gallery');

$a = $gallery->getGallery(); // Not work
echo $this->getGallery()->getId(); // Not Work
var_dump(count($a));
?>
letunhatkong commented 8 years ago

I created 2 function. File ../Block/Gallery.php

/**
     * Get Gallery Collection (status = 1)
     * @return mixed Gallery Collection
     */
    public function getGalleryCollection()
    {
        $result = [];
        $galleries = $this->galleryRepository->getAllGallery();
        if (is_null($galleries) || count($galleries) <= 0) return [];
        foreach($galleries as $gallery) {
            $_gal = [
                'id' => $gallery->getId(),
                'name' => $gallery->getName(),
                'status' => $gallery->getStatus(),
                'images' => []
            ];
            $images = $gallery->getImageCollection();
            if (count($images) > 0) {
                $_img = [];
                foreach ($images as $image) {
                    if ($image->getStatus()) {
                        $img = [
                            'id' => $gallery->getId(),
                            'name' => $gallery->getName(),
                            'path' => $image->getPath()
                        ];
                        array_push($_img, $img);
                    }
                }
                $_gal['images'] = $_img;
            }
            array_push($result, $_gal);
        }
        return $result;
    }

and file ../Model/GalleryRepository.php

/**
     * Get All Gallery with status = 1
     * @return mixed
     */
    public function getAllGallery() {
        return $this->galleryCollectionFactory->create()
            ->addFieldToFilter("status", "1")
            ->setOrder('updated_at', 'DESC');
    }

In Front - End

<?php
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$gallery = $_objectManager->get('DR\Gallery\Block\Gallery');
$galleries = $gallery->getGalleryCollection();
?>
daniel-rose commented 8 years ago

Sorry for the delay in getting back to you! @letunhatkong use the widget to display a gallery. @devdesco-ceo I will add the readme.md over the weekend.

letunhatkong commented 8 years ago

Thank Daniel Rose for this extension.