Skip to content

Commit

Permalink
Merge pull request #23 from riha112/2377
Browse files Browse the repository at this point in the history
2377
  • Loading branch information
carinadues committed Jul 19, 2021
2 parents 5b83e9a + 3de1ae7 commit 828aca8
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/Api/Data/ItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ItemInterface
const URL = 'url';
const OPEN_TYPE = 'open_type';
const URL_TYPE = 'url_type';
const CMS_PAGE_IDENTIFIER = 'cms_page_identifier';
const CMS_PAGE_ID = 'cms_page_id';
const CATEGORY_ID = 'category_id';
const POSITION = 'position';
const IS_ACTIVE = 'is_active';
Expand Down
4 changes: 2 additions & 2 deletions src/Block/Adminhtml/Item/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ protected function _addCategoryField(\Magento\Framework\Data\Form\Element\Fields
protected function _addCmsPageSelect(\Magento\Framework\Data\Form\Element\Fieldset $fieldset)
{
$fieldset->addField(
'cms_page_identifier',
'cms_page_id',
'select',
[
'label' => __('CMS Page'),
'title' => __('CMS Page'),
'values' => $this->_menumanagerHelper->getCmsPagesAsOptions(true),
'name' => 'cms_page_identifier',
'name' => 'cms_page_id',
'required' => true
]
);
Expand Down
4 changes: 3 additions & 1 deletion src/Helper/Adminhtml/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public function getCmsPagesAsOptions($addEmptyField = true)
foreach ($collection as $page) {
$name = $page->getTitle();
$identifier = $page->getIdentifier();
$id = $page->getId();

if (isset($name) && isset($identifier)) {
$suffix = '';
Expand All @@ -212,7 +213,7 @@ public function getCmsPagesAsOptions($addEmptyField = true)
}

$pages[] = [
'value' => $identifier,
'value' => $id,
'label' => __($name) . ' ' . $suffix
];
}
Expand All @@ -233,6 +234,7 @@ protected function _getCmsPageCollection()
* @var $collection \Magento\Cms\Model\ResourceModel\Page\Collection
*/
$collection = $objectManager->create($this->_pageCollectionClass);
$collection->addFieldToSelect('page_id');
$collection->addFieldToSelect('title');
$collection->addFieldToSelect('identifier');
$collection->addFieldToSelect('is_active');
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ public function setUrlType($urlType)
*/
public function getCmsPageIdentifier()
{
return $this->getData(self::CMS_PAGE_IDENTIFIER);
return $this->getData(self::CMS_PAGE_ID);
}

/**
* @param string $identifier
* @param string $id
*
* @return $this
*/
public function setCmsPageIdentifier($identifier)
public function setCmsPageIdentifier($id)
{
return $this->setData(self::CMS_PAGE_IDENTIFIER, $identifier);
return $this->setData(self::CMS_PAGE_ID, $id);
}

/**
Expand Down
21 changes: 11 additions & 10 deletions src/Model/Resolver/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Menu implements ResolverInterface
{
public const CATEGORY_ID_KEY = 'category_id';

public const CMS_PAGE_IDENTIFIER = 'cms_page_identifier';
public const CMS_PAGE_ID = 'cms_page_id';

/** @var MenuFactory */
protected $menuFactory;
Expand Down Expand Up @@ -143,7 +143,7 @@ private function getMenuItems(string $menuId): array
->getData();

$categoryIds = [];
$pageIdentifiers = [];
$pageIds = [];
$itemsMap = [];

foreach ($menuItems as $item) {
Expand All @@ -157,13 +157,13 @@ private function getMenuItems(string $menuId): array
} else {
$categoryIds[$catId] = [$itemId];
}
} else if (isset($item[self::CMS_PAGE_IDENTIFIER])) {
$pageIdentifier = $item[self::CMS_PAGE_IDENTIFIER];
} else if (isset($item[self::CMS_PAGE_ID])) {
$pageId = $item[self::CMS_PAGE_ID];

if (isset($pageIdentifiers[$pageIdentifier])) {
$pageIdentifiers[$pageIdentifier][] = $itemId;
if (isset($pageIds[$pageId])) {
$pageIds[$pageId][] = $itemId;
} else {
$pageIdentifiers[$pageIdentifier] = [$itemId];
$pageIds[$pageId] = [$itemId];
}
}

Expand All @@ -189,17 +189,18 @@ private function getMenuItems(string $menuId): array

$pageCollection = $this->pageCollectionFactory->create();
$pages = $pageCollection
->addFieldToFilter('identifier', ['in' => array_keys($pageIdentifiers)])
->addFieldToFilter('page_id', ['in' => array_keys($pageIds)])
->addFieldToFilter('is_active', 1)
->addStoreFilter($this->storeManager->getStore()->getId())
->getItems();

foreach ($pages as $page) {
$pageIdentifier = $page->getIdentifier();
$itemIds = $pageIdentifiers[$pageIdentifier];
$pageId = $page->getId();
$itemIds = $pageIds[$pageId];

foreach ($itemIds as $itemId) {
$url = $this->urlBuilder->getUrl(null, ['_direct' => $page->getIdentifier()]);
$url = $this->urlBuilder->getUrl(null, ['_direct' => $pageIdentifier]);
$itemsMap[$itemId]['url'] = parse_url($url, PHP_URL_PATH);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/ResourceModel/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected function _processUrlSave($object)
switch ($object->getUrlType()) {
case 0:
default:
$object->setData('cms_page_identifier', null);
$object->setData('cms_page_id', null);
$object->setData('category_id', null);
break;
case 1:
Expand All @@ -140,7 +140,7 @@ protected function _processUrlSave($object)
break;
case 2:
$object->setData('url', null);
$object->setData('cms_page_identifier', null);
$object->setData('cms_page_id', null);
break;
}
}
Expand Down
55 changes: 0 additions & 55 deletions src/Observer/UpdatePageIdentifier.php

This file was deleted.

3 changes: 0 additions & 3 deletions src/etc/adminhtml/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="cms_page_save_after">
<observer name="update_menu" instance="ScandiPWA\MenuOrganizer\Observer\UpdatePageIdentifier" />
</event>
<event name="catalog_category_delete_after">
<observer name="update_menu" instance="ScandiPWA\MenuOrganizer\Observer\DeleteCategoryItem" />
</event>
Expand Down
4 changes: 2 additions & 2 deletions src/etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<column xsi:type="text" name="url" nullable="true"/>
<column xsi:type="smallint" name="open_type" padding="6" unsigned="false" nullable="false" identity="false" default="0"/>
<column xsi:type="smallint" name="url_type" padding="6" unsigned="false" nullable="false" identity="false" default="0"/>
<column xsi:type="varchar" name="cms_page_identifier" nullable="true" length="100"/>
<column xsi:type="smallint" name="cms_page_id" padding="6" unsigned="false" nullable="true" identity="false"/>
<column xsi:type="int" name="category_id" padding="10" unsigned="true" nullable="true" identity="false"/>
<column xsi:type="smallint" name="position" padding="6" unsigned="false" nullable="false" identity="false" default="0"/>
<column xsi:type="smallint" name="is_active" padding="6" unsigned="false" nullable="false" identity="false" default="1"/>
Expand All @@ -49,7 +49,7 @@
</constraint>
<constraint xsi:type="foreign" referenceId="SCANDIWEB_MENUMANAGER_ITEM_MENU_ID" table="scandiweb_menumanager_item" column="menu_id" referenceTable="scandiweb_menumanager_menu" referenceColumn="menu_id" onDelete="CASCADE"/>
<constraint xsi:type="foreign" referenceId="SCANDIWEB_MENUMANAGER_ITEM_CATEGORY_ID" table="scandiweb_menumanager_item" column="category_id" referenceTable="catalog_category_entity" referenceColumn="entity_id" onDelete="SET NULL"/>
<constraint xsi:type="foreign" referenceId="SCANDIWEB_MENUMANAGER_ITEM_CMS_PAGE_ID" table="scandiweb_menumanager_item" column="cms_page_identifier" referenceTable="cms_page" referenceColumn="identifier" onDelete="SET NULL"/>
<constraint xsi:type="foreign" referenceId="SCANDIWEB_MENUMANAGER_ITEM_CMS_PAGE_ID" table="scandiweb_menumanager_item" column="cms_page_id" referenceTable="cms_page" referenceColumn="page_id" onDelete="SET NULL"/>
<index referenceId="SCANDIWEB_MENUMANAGER_ITEM_IDENTIFIER" indexType="btree">
<column name="identifier"/>
</index>
Expand Down
4 changes: 2 additions & 2 deletions src/etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"url": true,
"open_type": true,
"url_type": true,
"cms_page_identifier": true,
"cms_page_id": true,
"category_id": true,
"position": true,
"is_active": true,
Expand All @@ -41,7 +41,7 @@
"PRIMARY": true,
"FK_0AB456CB28F7294C1412103466C201D3": true,
"SCANDIWEB_MENUMANAGER_ITEM_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID": true,
"FK_2058573FEB4C380B79E88A7E2C6B2FE1": true
"SCANDIWEB_MENUMANAGER_ITEM_CMS_PAGE_ID_CMS_PAGE_PAGE_ID": true
}
},
"scandiweb_menumanager_menu_store": {
Expand Down

0 comments on commit 828aca8

Please sign in to comment.