Skip to content

Commit

Permalink
added store configs to action
Browse files Browse the repository at this point in the history
  • Loading branch information
matesich committed Jan 23, 2023
1 parent b94d268 commit 0b2c088
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
14 changes: 7 additions & 7 deletions src/Controller/Pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class Pwa extends Action implements HttpGetActionInterface, HttpPostActionInterf
protected $catalogDefaultSortBy;

/**
* @var string
* @var array|null
*/
protected $catalogDefaultSortByConfig;
protected $storeConfig;

/**
* @param string $type
Expand Down Expand Up @@ -182,12 +182,12 @@ public function setCatalogDefaultSortBy(string $catalogDefaultSortBy): self
}

/**
* @param string $catalogDefaultSortByConfig
* @param $storeConfig
* @return Pwa
*/
public function setCatalogDefaultSortByConfig(string $catalogDefaultSortByConfig): self
public function setStoreConfig($storeConfig): self
{
$this->catalogDefaultSortByConfig = $catalogDefaultSortByConfig;
$this->storeConfig = $storeConfig;
return $this;
}

Expand All @@ -210,7 +210,7 @@ public function __construct(
$this->identifier = '';
$this->description = '';
$this->catalogDefaultSortBy = '';
$this->catalogDefaultSortByConfig = '';
$this->storeConfig = null;
parent::__construct($context);
}

Expand All @@ -232,7 +232,7 @@ public function execute()
$resultLayout->setDisplayMode($this->display_mode);
$resultLayout->setDescription($this->description);
$resultLayout->setCatalogDefaultSortBy($this->catalogDefaultSortBy);
$resultLayout->setCatalogDefaultSortByConfig($this->catalogDefaultSortByConfig);
$resultLayout->setStoreConfig($this->storeConfig);
try{
$templateName = 'pwa-root';
$resultLayout->setRootTemplate($templateName);
Expand Down
33 changes: 26 additions & 7 deletions src/Controller/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Magento\Catalog\Model\ProductRepository;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;

class Router extends BaseRouter
{
const XML_PATH_CMS_HOME_PAGE = 'web/default/cms_home_page';
Expand All @@ -44,6 +45,11 @@ class Router extends BaseRouter
const PAGE_TYPE_CATEGORY = 'CATEGORY';
const PAGE_TYPE_CMS_PAGE = 'CMS_PAGE';

const CRUCIAL_STORE_CONFIG_VALUES = [
'cms_home_page' => self::XML_PATH_CMS_HOME_PAGE,
'catalog_default_sort_by' => self::XML_PATH_CATALOG_DEFAULT_SORT_BY
];

/**
* @var ValidationManagerInterface
*/
Expand Down Expand Up @@ -208,13 +214,6 @@ public function match(RequestInterface $request)
$action = $this->actionFactory->create(Pwa::class);
$rewrite = $this->getRewrite($request);

$catalogDefaultSortByConfig = $this->scopeConfig->getValue(
self::XML_PATH_CATALOG_DEFAULT_SORT_BY,
ScopeInterface::SCOPE_STORE,
$this->storeId
);

$action->setCatalogDefaultSortByConfig($catalogDefaultSortByConfig);

if ($rewrite) {
// Do not execute any action for external rewrites,
Expand Down Expand Up @@ -266,6 +265,8 @@ protected function setPageDetails(UrlRewrite $urlRewrite, ActionInterface $actio
$this->setResponseCategory($entityId, $action);
break;
}

$this->setStoreConfigs($action);
}

protected function setResponseHomePage(ActionInterface $action)
Expand Down Expand Up @@ -357,6 +358,24 @@ protected function setResponseCategory($id, ActionInterface $action)
}
}

protected function setStoreConfigs(ActionInterface $action)
{
$storeConfig = [];
$crucialStoreConfigs = self::CRUCIAL_STORE_CONFIG_VALUES;

foreach ($crucialStoreConfigs as $configKey => $path) {
$configValue = $this->scopeConfig->getValue(
$path,
ScopeInterface::SCOPE_STORE,
$this->storeId
);

$storeConfig[$configKey] = $configValue;
}

$action->setStoreConfig($storeConfig);
}

/**
* Set "404 Not Found" response
*
Expand Down
18 changes: 9 additions & 9 deletions src/View/Result/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ class Page extends ExtendedPage
*/
protected $catalogDefaultSortBy;

/**
* @var string
/**
* @var array|null
*/
protected $catalogDefaultSortByConfig;
protected $storeConfig;

/**
* Constructor
Expand Down Expand Up @@ -188,7 +188,7 @@ public function __construct(
$this->identifier = '';
$this->description = '';
$this->catalogDefaultSortBy = '';
$this->catalogDefaultSortByConfig = '';
$this->storeConfig = null;
}

/**
Expand Down Expand Up @@ -322,19 +322,19 @@ public function getCatalogDefaultSortBy()
return $this->catalogDefaultSortBy;
}

public function setCatalogDefaultSortByConfig(string $catalogDefaultSortByConfig)
public function setStoreConfig($storeConfig)
{
if($this->catalogDefaultSortByConfig === '') {
$this->catalogDefaultSortByConfig = $catalogDefaultSortByConfig;
if($this->storeConfig === null) {
$this->storeConfig = $storeConfig;
return $this;
}

return '';
return null;
}

public function getCatalogDefaultSortByConfig()
{
return $this->catalogDefaultSortByConfig;
return $this->storeConfig;
}

/**
Expand Down

0 comments on commit 0b2c088

Please sign in to comment.