Closed viktor-zhuromskyy closed 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));
?>
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();
?>
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.
Thank Daniel Rose for this extension.
Would you be so kind to update your readme.md with features set and status of the extension, please?