Version Notes
- Added level field to the cmsmenu table.
- Fixed child assignment issue.
Download this release
Release Info
Developer | Damian A. Pastorini |
Extension | DwD_CmsMenu |
Version | 0.1.4 |
Comparing to | |
See all releases |
Code changes from version 0.1.3 to 0.1.4
- app/code/community/DwD/CmsMenu/Helper/Data.php +33 -8
- app/code/community/DwD/CmsMenu/Model/Mysql4/Cmsmenu/Collection.php +1 -0
- app/code/community/DwD/CmsMenu/Model/Observer.php +28 -21
- app/code/community/DwD/CmsMenu/etc/config.xml +1 -1
- app/code/community/DwD/CmsMenu/sql/cmsmenu_setup/mysql4-upgrade-0.1.3-0.1.4.php +52 -0
- package.xml +6 -7
app/code/community/DwD/CmsMenu/Helper/Data.php
CHANGED
@@ -17,14 +17,8 @@ class DwD_CmsMenu_Helper_Data extends Mage_Core_Helper_Abstract
|
|
17 |
// options:
|
18 |
$options = array(
|
19 |
'0' => '',
|
20 |
-
'1' => array(
|
21 |
-
|
22 |
-
'value' => array()
|
23 |
-
),
|
24 |
-
'2' => array(
|
25 |
-
'label'=> 'Categories',
|
26 |
-
'value' => array()
|
27 |
-
),
|
28 |
);
|
29 |
// get table name:
|
30 |
$cmsTable = Mage::getSingleton('core/resource')->getTableName('cmsmenu');
|
@@ -50,4 +44,35 @@ class DwD_CmsMenu_Helper_Data extends Mage_Core_Helper_Abstract
|
|
50 |
return $options;
|
51 |
}
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
17 |
// options:
|
18 |
$options = array(
|
19 |
'0' => '',
|
20 |
+
'1' => array('label'=> 'Pages', 'value' => array()),
|
21 |
+
'2' => array('label'=> 'Categories', 'value' => array()),
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
);
|
23 |
// get table name:
|
24 |
$cmsTable = Mage::getSingleton('core/resource')->getTableName('cmsmenu');
|
44 |
return $options;
|
45 |
}
|
46 |
|
47 |
+
public function getTreeLevel($childOf, $level = 0, $recursive = false)
|
48 |
+
{
|
49 |
+
if($childOf) {
|
50 |
+
// if is a category child:
|
51 |
+
if(strpos($childOf, 'c-')!==false) {
|
52 |
+
// get the category id:
|
53 |
+
$categoryId = substr($childOf, 2);
|
54 |
+
// load the category:
|
55 |
+
$category = Mage::getModel('catalog/category')->load($categoryId);
|
56 |
+
// get the level:
|
57 |
+
$categoryLevel = $category->getLevel();
|
58 |
+
if(!$recursive){
|
59 |
+
// calculate the cms page level by removing 1 level to the category:
|
60 |
+
$level = $categoryLevel-1; // category level - base category level (2) + 1 that will be the next level
|
61 |
+
} else {
|
62 |
+
$level = $categoryLevel; // if is a recursive request we need to return to category level.
|
63 |
+
}
|
64 |
+
} else {
|
65 |
+
// load the parent item and add 1 to the parent level:
|
66 |
+
$cmsMenuItem = Mage::getModel('dwd_cmsmenu/cmsmenu')->load($childOf, 'cms_page_id');
|
67 |
+
if(!$recursive) {
|
68 |
+
$level = $cmsMenuItem->getLevel()+1;
|
69 |
+
} else {
|
70 |
+
$level++;
|
71 |
+
$level = $this->getTreeLevel($cmsMenuItem->getChildOf(), $level, true);
|
72 |
+
}
|
73 |
+
}
|
74 |
+
}
|
75 |
+
return $level;
|
76 |
+
}
|
77 |
+
|
78 |
}
|
app/code/community/DwD/CmsMenu/Model/Mysql4/Cmsmenu/Collection.php
CHANGED
@@ -41,6 +41,7 @@ class DwD_CmsMenu_Model_Mysql4_Cmsmenu_Collection extends Mage_Core_Model_Mysql4
|
|
41 |
|
42 |
public function setChildOfOrder()
|
43 |
{
|
|
|
44 |
$this->getSelect()->order(new Zend_Db_Expr('child_of+0'), self::SORT_ORDER_ASC);
|
45 |
$this->getSelect()->order('child_of', self::SORT_ORDER_ASC);
|
46 |
return $this;
|
41 |
|
42 |
public function setChildOfOrder()
|
43 |
{
|
44 |
+
$this->getSelect()->order('level', self::SORT_ORDER_ASC);
|
45 |
$this->getSelect()->order(new Zend_Db_Expr('child_of+0'), self::SORT_ORDER_ASC);
|
46 |
$this->getSelect()->order('child_of', self::SORT_ORDER_ASC);
|
47 |
return $this;
|
app/code/community/DwD/CmsMenu/Model/Observer.php
CHANGED
@@ -16,27 +16,33 @@ class DwD_CmsMenu_Model_Observer
|
|
16 |
{
|
17 |
$isEnabled = Mage::getStoreConfig('dwd_cmsmenu/general/enabled');
|
18 |
if($isEnabled) {
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
$cmsMenu
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
$
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
}
|
42 |
}
|
@@ -52,6 +58,7 @@ class DwD_CmsMenu_Model_Observer
|
|
52 |
$page->setData('child_of', $cmsMenu->getChildOf());
|
53 |
$page->setData('add_before', $cmsMenu->getAddBefore());
|
54 |
$page->setData('menu_item_title', $cmsMenu->getMenuItemTitle());
|
|
|
55 |
return $page;
|
56 |
}
|
57 |
}
|
16 |
{
|
17 |
$isEnabled = Mage::getStoreConfig('dwd_cmsmenu/general/enabled');
|
18 |
if($isEnabled) {
|
19 |
+
try {
|
20 |
+
$request = Mage::app()->getRequest();
|
21 |
+
$post = $request->getPost();
|
22 |
+
$page = $observer->getObject();
|
23 |
+
$pageId = $page->getId();
|
24 |
+
$cmsMenu = Mage::getModel('dwd_cmsmenu/cmsmenu')->load($pageId, 'cms_page_id');
|
25 |
+
if (!$cmsMenu || ($cmsMenu && !$cmsMenu->getId())) {
|
26 |
+
$cmsMenu = Mage::getModel('dwd_cmsmenu/cmsmenu');
|
27 |
+
}
|
28 |
+
$level = Mage::helper('dwd_cmsmenu')->getTreeLevel($post['child_of']);
|
29 |
+
$cmsMenu->setLevel($level);
|
30 |
+
$cmsMenu->setCmsPageId($pageId);
|
31 |
+
$cmsMenu->setShowInMenu($post['show_in_menu']);
|
32 |
+
$cmsMenu->setChildOf($post['child_of']);
|
33 |
+
$cmsMenu->setAddBefore($post['add_before']);
|
34 |
+
$itemTitle = $post['menu_item_title'];
|
35 |
+
if (!$itemTitle) {
|
36 |
+
$itemTitle = $post['title'];
|
37 |
+
}
|
38 |
+
$cmsMenu->setMenuItemTitle($itemTitle);
|
39 |
+
$cmsMenu->save();
|
40 |
+
$flushCache = Mage::getStoreConfig('dwd_cmsmenu/general/cache');
|
41 |
+
if($flushCache) {
|
42 |
+
Mage::app()->getCacheInstance()->flush();
|
43 |
+
}
|
44 |
+
} catch (Exception $e) {
|
45 |
+
Mage::log($e->getMessage(), null, 'dwd-cmsmenu-error.log');
|
46 |
}
|
47 |
}
|
48 |
}
|
58 |
$page->setData('child_of', $cmsMenu->getChildOf());
|
59 |
$page->setData('add_before', $cmsMenu->getAddBefore());
|
60 |
$page->setData('menu_item_title', $cmsMenu->getMenuItemTitle());
|
61 |
+
$page->setData('level', $cmsMenu->getLevel());
|
62 |
return $page;
|
63 |
}
|
64 |
}
|
app/code/community/DwD/CmsMenu/etc/config.xml
CHANGED
@@ -12,7 +12,7 @@
|
|
12 |
<config>
|
13 |
<modules>
|
14 |
<DwD_CmsMenu>
|
15 |
-
<version>0.1.
|
16 |
</DwD_CmsMenu>
|
17 |
</modules>
|
18 |
<global>
|
12 |
<config>
|
13 |
<modules>
|
14 |
<DwD_CmsMenu>
|
15 |
+
<version>0.1.4</version>
|
16 |
</DwD_CmsMenu>
|
17 |
</modules>
|
18 |
<global>
|
app/code/community/DwD/CmsMenu/sql/cmsmenu_setup/mysql4-upgrade-0.1.3-0.1.4.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* DwD-CmsMenu - Magento Extension
|
6 |
+
*
|
7 |
+
* @copyright Copyright (c) 2015 DwDesigner Inc. (http://www.dwdeveloper.com/)
|
8 |
+
* @author Damian A. Pastorini - damian.pastorini@dwdeveloper.com
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
|
12 |
+
$installer = $this;
|
13 |
+
|
14 |
+
$installer->startSetup();
|
15 |
+
|
16 |
+
// run query:
|
17 |
+
$installer->getConnection()
|
18 |
+
->addColumn($installer->getTable('dwd_cmsmenu/cmsmenu'), 'level', array(
|
19 |
+
'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
|
20 |
+
'nullable' => false,
|
21 |
+
'unsigned' => true,
|
22 |
+
'length' => 6,
|
23 |
+
'comment' => 'CMS Menu item tree level.'
|
24 |
+
));
|
25 |
+
|
26 |
+
// load old cmsmenu items:
|
27 |
+
$cmsMenuCollection = Mage::getModel('dwd_cmsmenu/cmsmenu')->getCollection();
|
28 |
+
|
29 |
+
// loop and fix:
|
30 |
+
foreach($cmsMenuCollection as $c) {
|
31 |
+
$childOf = $c->getChildOf();
|
32 |
+
$level = 0;
|
33 |
+
if($childOf) {
|
34 |
+
if(strpos($childOf, 'c-')!==false) {
|
35 |
+
// get the category id:
|
36 |
+
$categoryId = substr($childOf, 2);
|
37 |
+
// load the category:
|
38 |
+
$category = Mage::getModel('catalog/category')->load($categoryId);
|
39 |
+
// get the level:
|
40 |
+
$categoryLevel = $category->getLevel();
|
41 |
+
// calculate the cms page level by removing 1 level to the category:
|
42 |
+
$level = $categoryLevel-1; // category level - base category level (2) + 1 that will be the next level
|
43 |
+
} else {
|
44 |
+
$level++;
|
45 |
+
$level = Mage::helper('dwd_cmsmenu')->getTreeLevel($childOf, $level, true);
|
46 |
+
}
|
47 |
+
}
|
48 |
+
$c->setLevel($level);
|
49 |
+
$c->save();
|
50 |
+
}
|
51 |
+
|
52 |
+
$installer->endSetup();
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>DwD_CmsMenu</name>
|
4 |
-
<version>0.1.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/afl-3.0.php">Academic Free License (AFL 3.0)</license>
|
7 |
<channel>community</channel>
|
@@ -47,13 +47,12 @@ With this extension everything will be much easier and you will get everything w
|
|
47 |
<p>For support, contact us at <a href="mailto:info@dwdeveloper.com">info@dwdeveloper.com</a></p>
|
48 |
<p>You can also get the extension from our GitHub repository: <a href="https://github.com/damian-pastorini/DwD-Mage-Extension-CMS-Menu" target="_blank">https://github.com/damian-pastorini/DwD-Mage-Extension-CMS-Menu</a>.</p>
|
49 |
<p>Please feel free to report any issues there.</p></description>
|
50 |
-
<notes>-
|
51 |
-
-
|
52 |
-
- Added setup script to fix old items created.</notes>
|
53 |
<authors><author><name>Damian A. Pastorini</name><user>MAG002087848</user><email>damian.pastorini@dwdeveloper.com</email></author></authors>
|
54 |
-
<date>2015-10-
|
55 |
-
<time>
|
56 |
-
<contents><target name="mageetc"><dir name="modules"><file name="DwD_CmsMenu.xml" hash="9b1288160fc81a13f811056ca9f49123"/></dir></target><target name="magecommunity"><dir name="DwD"><dir name="CmsMenu"><dir name="Block"><dir name="Adminhtml"><dir name="Cms"><dir name="Page"><dir name="Edit"><dir name="Tab"><file name="Content.php" hash="3694e6d33bae1c5db9ca91163523f357"/></dir></dir></dir></dir></dir><dir name="Page"><dir name="Html"><dir name="Topmenu"><file name="Observer.php" hash="4bfd9dfc6732b1fe8093c025c135a6cf"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="
|
57 |
<compatible/>
|
58 |
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
59 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>DwD_CmsMenu</name>
|
4 |
+
<version>0.1.4</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/afl-3.0.php">Academic Free License (AFL 3.0)</license>
|
7 |
<channel>community</channel>
|
47 |
<p>For support, contact us at <a href="mailto:info@dwdeveloper.com">info@dwdeveloper.com</a></p>
|
48 |
<p>You can also get the extension from our GitHub repository: <a href="https://github.com/damian-pastorini/DwD-Mage-Extension-CMS-Menu" target="_blank">https://github.com/damian-pastorini/DwD-Mage-Extension-CMS-Menu</a>.</p>
|
49 |
<p>Please feel free to report any issues there.</p></description>
|
50 |
+
<notes>- Added level field to the cmsmenu table.
|
51 |
+
- Fixed child assignment issue.</notes>
|
|
|
52 |
<authors><author><name>Damian A. Pastorini</name><user>MAG002087848</user><email>damian.pastorini@dwdeveloper.com</email></author></authors>
|
53 |
+
<date>2015-10-13</date>
|
54 |
+
<time>23:23:53</time>
|
55 |
+
<contents><target name="mageetc"><dir name="modules"><file name="DwD_CmsMenu.xml" hash="9b1288160fc81a13f811056ca9f49123"/></dir></target><target name="magecommunity"><dir name="DwD"><dir name="CmsMenu"><dir name="Block"><dir name="Adminhtml"><dir name="Cms"><dir name="Page"><dir name="Edit"><dir name="Tab"><file name="Content.php" hash="3694e6d33bae1c5db9ca91163523f357"/></dir></dir></dir></dir></dir><dir name="Page"><dir name="Html"><dir name="Topmenu"><file name="Observer.php" hash="4bfd9dfc6732b1fe8093c025c135a6cf"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="939ba6a32fbbbad3d81be3812fd5dd20"/></dir><dir name="Model"><file name="Cmsmenu.php" hash="27a1044475f1a225142baa025051b5fb"/><dir name="Mysql4"><dir name="Cmsmenu"><file name="Collection.php" hash="6ef952b4fe717960250ea4c3784ca4da"/></dir><file name="Cmsmenu.php" hash="f317ca72b5de8d0cf7a018b4deb8cdb8"/></dir><file name="Observer.php" hash="b40b421086bb3afddd169b1c992e6b5d"/></dir><dir name="etc"><file name="adminhtml.xml" hash="a47c8fe2ed9bdcc5a91595d9f633397e"/><file name="config.xml" hash="4288d059c2bd1377674fde2c364f3dcf"/><file name="system.xml" hash="6d644417492685a439629dfb59ef6051"/></dir><dir name="sql"><dir name="cmsmenu_setup"><file name="mysql4-install-0.1.0.php" hash="f7917d067ce6b37abca95c3d9a15afbe"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="f7917d067ce6b37abca95c3d9a15afbe"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="f7917d067ce6b37abca95c3d9a15afbe"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="bbe36b889cfe7b582ff763e8a4c981eb"/><file name="mysql4-upgrade-0.1.3-0.1.4.php" hash="98be2360182089f7a3bf67b6c081a34a"/></dir></dir></dir></dir></target></contents>
|
56 |
<compatible/>
|
57 |
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
58 |
</package>
|