Git Product home page Git Product logo

Comments (4)

letunhatkong avatar letunhatkong commented on June 28, 2024

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.

  • Images: allow user create images with name, url, image, description, status (enable or disable)
  • Gallery: allow user create galleries with name, status (enable or disable), collection (filter all images and user can select images to each galerry).

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));
?>

from magento2-gallery.

letunhatkong avatar letunhatkong commented on June 28, 2024

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();
?>

from magento2-gallery.

daniel-rose avatar daniel-rose commented on June 28, 2024

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.

from magento2-gallery.

letunhatkong avatar letunhatkong commented on June 28, 2024

Thank Daniel Rose for this extension.

from magento2-gallery.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.