Skip to content

Commit

Permalink
Fixed setting of storeviews
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjaap committed Feb 23, 2021
1 parent fd6c8a1 commit 0d3e7ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions Controller/Adminhtml/Route/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function execute()
return $resultRedirect->setPath('*/*/');
}
}
$model->setData('store_id', implode(',', $model->getStoreIds()));
$this->dataPersistor->set('prismicio_route', $model->getData());

// 3. Build edit form
Expand Down
28 changes: 27 additions & 1 deletion Controller/Adminhtml/Route/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@

namespace Elgentos\PrismicIO\Controller\Adminhtml\Route;

use Elgentos\PrismicIO\Model\ResourceModel\Route\Store\Collection as RouteStoreCollection;
use Elgentos\PrismicIO\Model\Route\Store;
use Magento\Framework\Exception\LocalizedException;
use Elgentos\PrismicIO\Model\Route\StoreFactory as RouteStoreFactory;

class Save extends \Magento\Backend\App\Action
{

/**
* @var RouteStoreFactory
*/
public $routeStoryFactory;
/**
* @var Collection
*/
public $routeStoreCollection;
protected $dataPersistor;

/**
Expand All @@ -20,10 +31,14 @@ class Save extends \Magento\Backend\App\Action
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
\Magento\Framework\App\Request\DataPersistorInterface $dataPersistor,
RouteStoreCollection $routeStoreCollection,
RouteStoreFactory $routeStoreFactory
) {
$this->dataPersistor = $dataPersistor;
$this->routeStoryFactory = $routeStoreFactory;
parent::__construct($context);
$this->routeStoreCollection = $routeStoreCollection;
}

/**
Expand All @@ -49,6 +64,17 @@ public function execute()

try {
$model->save();

$this->routeStoreCollection->addFieldToFilter('route_id', $model->getId())->each(function ($routeStore) {
$routeStore->delete();
});
foreach ($model->getData('store_id') as $storeId) {
$this->routeStoryFactory->create()->setData([
'route_id' => $model->getId(),
'store_id' => $storeId
])->save();
}

$this->messageManager->addSuccessMessage(__('You saved the Route.'));
$this->dataPersistor->clear('prismicio_route');

Expand Down

0 comments on commit 0d3e7ca

Please sign in to comment.