0

I am using Magento 2.3.0 and I create custom module for video gallery in admin side module grid mass action change status after not updated in grid but message comes on successfully updated. If any one know how to debug and fix it.

below screenshot share for issue comes

enter image description here

<?php
namespace CustomModule\Videogallery\Block\Adminhtml\Videogallery;

class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
{
    /**
     * @var \Magento\Framework\Module\Manager
     */
    protected $moduleManager;

    /**
     * @var \CustomModule\Videogallery\Model\videogalleryFactory
     */
    protected $_videogalleryFactory;

    /**
     * @var \CustomModule\Videogallery\Model\Status
     */
    protected $_status;

    /**
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Backend\Helper\Data $backendHelper
     * @param \CustomModule\Videogallery\Model\videogalleryFactory $videogalleryFactory
     * @param \CustomModule\Videogallery\Model\Status $status
     * @param \Magento\Framework\Module\Manager $moduleManager
     * @param array $data
     *
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Backend\Helper\Data $backendHelper,
        \CustomModule\Videogallery\Model\VideogalleryFactory $VideogalleryFactory,
        \CustomModule\Videogallery\Model\Status $status,
        \Magento\Framework\Module\Manager $moduleManager,
        array $data = []
    ) {
        $this->_videogalleryFactory = $VideogalleryFactory;
        $this->_status = $status;
        $this->moduleManager = $moduleManager;
        parent::__construct($context, $backendHelper, $data);
    }

    /**
     * @return void
     */
    protected function _construct()
    {
        parent::_construct();
        $this->setId('postGrid');
        $this->setDefaultSort('video_id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(false);
        $this->setVarNameFilter('post_filter');
    }

    /**
     * @return $this
     */
    protected function _prepareCollection()
    {
        $collection = $this->_videogalleryFactory->create()->getCollection();
        $this->setCollection($collection);

        parent::_prepareCollection();

        return $this;
    }

    /**
     * @return $this
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    protected function _prepareColumns()
    {
        $this->addColumn(
            'video_id',
            [
                'header' => __('ID'),
                'type' => 'number',
                'index' => 'video_id',
                'header_css_class' => 'col-id',
                'column_css_class' => 'col-id'
            ]
        );



                $this->addColumn(
                    'video_name',
                    [
                        'header' => __('Video Name'),
                        'index' => 'video_name',
                    ]
                );

                $this->addColumn(
                    'link',
                    [
                        'header' => __('link'),
                        'index' => 'link',
                    ]
                );

                $this->addColumn(
                    'sort',
                    [
                        'header' => __('Sort By'),
                        'index' => 'sort',
                    ]
                );


                        $this->addColumn(
                            'status',
                            [
                                'header' => __('Status'),
                                'index' => 'status',
                                'type' => 'options',
                                'options' => \CustomModule\Videogallery\Block\Adminhtml\Videogallery\Grid::getOptionArray5()
                            ]
                        );





        //$this->addColumn(
            //'edit',
            //[
                //'header' => __('Edit'),
                //'type' => 'action',
                //'getter' => 'getId',
                //'actions' => [
                    //[
                        //'caption' => __('Edit'),
                        //'url' => [
                            //'base' => '*/*/edit'
                        //],
                        //'field' => 'video_id'
                    //]
                //],
                //'filter' => false,
                //'sortable' => false,
                //'index' => 'stores',
                //'header_css_class' => 'col-action',
                //'column_css_class' => 'col-action'
            //]
        //);



           $this->addExportType($this->getUrl('videogallery/*/exportCsv', ['_current' => true]),__('CSV'));
           $this->addExportType($this->getUrl('videogallery/*/exportExcel', ['_current' => true]),__('Excel XML'));

        $block = $this->getLayout()->getBlock('grid.bottom.links');
        if ($block) {
            $this->setChild('grid.bottom.links', $block);
        }

        return parent::_prepareColumns();
    }


    /**
     * @return $this
     */
    protected function _prepareMassaction()
    {

        $this->setMassactionIdField('video_id');
        //$this->getMassactionBlock()->setTemplate('CustomModule_Videogallery::videogallery/grid/massaction_extended.phtml');
        $this->getMassactionBlock()->setFormFieldName('videogallery');

        $this->getMassactionBlock()->addItem(
            'delete',
            [
                'label' => __('Delete'),
                'url' => $this->getUrl('videogallery/*/massDelete'),
                'confirm' => __('Are you sure?')
            ]
        );

        $statuses = $this->_status->getOptionArray();

        $this->getMassactionBlock()->addItem(
            'status',
            [
                'label' => __('Change status'),
                'url' => $this->getUrl('videogallery/*/massStatus', ['_current' => true]),
                'additional' => [
                    'visibility' => [
                        'name' => 'status',
                        'type' => 'select',
                        'class' => 'required-entry',
                        'label' => __('Status'),
                        'values' => $statuses
                    ]
                ]
            ]
        );


        return $this;
    }


    /**
     * @return string
     */
    public function getGridUrl()
    {
        return $this->getUrl('videogallery/*/index', ['_current' => true]);
    }

    /**
     * @param \CustomModule\Videogallery\Model\videogallery|\Magento\Framework\Object $row
     * @return string
     */
    public function getRowUrl($row)
    {

        return $this->getUrl(
            'videogallery/*/edit',
            ['video_id' => $row->getId()]
        );

    }


        static public function getOptionArray5()
        {
            $data_array=array(); 
            $data_array[1]='Enabled';
            $data_array[0]='Disabled';
            return($data_array);
        }
        static public function getValueArray5()
        {
            $data_array=array();
            foreach(\CustomModule\Videogallery\Block\Adminhtml\Videogallery\Grid::getOptionArray5() as $k=>$v){
               $data_array[]=array('value'=>$k,'label'=>$v);        
            }
            return($data_array);

        }


}
  • Are you running though cloudflare? try reindexing your site and running flush cache – Dava Gordon Aug 19 at 10:22
  • Did you checked if status got updated in database ? – Abdul Pathan Aug 19 at 10:33
  • @AbdulPathan yes status update when i go to edit single record after status change save in database – Rv Singh Aug 19 at 10:35
  • but in mass action select any record after change status not updated – Rv Singh Aug 19 at 10:35
  • could you please add your massAction code in the question ? – Abdul Pathan Aug 19 at 10:41
1

This issue is resolved in controller got to CustomModule/Videogallery/Controller/Adminhtml/videogallery/massstatus.php inside execute function

$post->setIsActive($status)->save();

change to

$post->setStatus($status)->save();

After clear flush issue resolved.

  • thanks for upvote – Rv Singh Oct 1 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.