DwD_CmsMenu - Version 0.1.3

Version Notes

- Fixed sort order to avoid child of not showing up issue.
- Added categories level and status filters for admin select box.
- Added setup script to fix old items created.

Download this release

Release Info

Developer Damian A. Pastorini
Extension DwD_CmsMenu
Version 0.1.3
Comparing to
See all releases


Code changes from version 0.1.2 to 0.1.3

app/code/community/DwD/CmsMenu/Block/Page/Html/Topmenu/Observer.php CHANGED
@@ -17,7 +17,11 @@ class DwD_CmsMenu_Block_Page_Html_Topmenu_Observer extends Mage_Page_Block_Html_
17
  $isEnabled = Mage::getStoreConfig('dwd_cmsmenu/general/enabled');
18
  if($isEnabled) {
19
  // get all items that should be added at the end of the tree:
20
- $cmsMenuItems = Mage::getModel('dwd_cmsmenu/cmsmenu')->getCollection()->addActiveFilter()->setChildOfOrder()->setAddBeforeOrder();
 
 
 
 
21
  // loop items and add to the menu:
22
  foreach ($cmsMenuItems as $menuItem) {
23
  // get item name:
@@ -43,7 +47,13 @@ class DwD_CmsMenu_Block_Page_Html_Topmenu_Observer extends Mage_Page_Block_Html_
43
  // get all child nodes:
44
  $allChildNodes = $observer->getMenu()->getAllChildNodes();
45
  // look for the parent item:
46
- $parentItem = $allChildNodes[$menuItem->getChildOf()];
 
 
 
 
 
 
47
  if($parentItem) {
48
  // create new item node:
49
  $itemNode = new Varien_Data_Tree_Node($itemNodeData, 'cmsmenu-'.$menuItem->getCmsPageId(), $parentItem->getTree());
@@ -57,7 +67,8 @@ class DwD_CmsMenu_Block_Page_Html_Topmenu_Observer extends Mage_Page_Block_Html_
57
  // loop and reorder items:
58
  foreach($currentChilds as $childIndex => $currentChild) {
59
  $parentItem->removeChild($currentChild);
60
- if($childIndex == $menuItem->getAddBefore()) {
 
61
  $parentItem->addChild($itemNode);
62
  }
63
  $parentItem->addChild($currentChild);
@@ -82,7 +93,8 @@ class DwD_CmsMenu_Block_Page_Html_Topmenu_Observer extends Mage_Page_Block_Html_
82
  // loop and reorder items:
83
  foreach($currentChilds as $childIndex => $currentChild) {
84
  $observer->getMenu()->removeChild($currentChild);
85
- if($childIndex == $menuItem->getAddBefore()) {
 
86
  $observer->getMenu()->addChild($itemNode);
87
  }
88
  $observer->getMenu()->addChild($currentChild);
@@ -123,4 +135,14 @@ class DwD_CmsMenu_Block_Page_Html_Topmenu_Observer extends Mage_Page_Block_Html_
123
  return $isActive;
124
  }
125
 
 
 
 
 
 
 
 
 
 
 
126
  }
17
  $isEnabled = Mage::getStoreConfig('dwd_cmsmenu/general/enabled');
18
  if($isEnabled) {
19
  // get all items that should be added at the end of the tree:
20
+ $cmsMenuItems = Mage::getModel('dwd_cmsmenu/cmsmenu')
21
+ ->getCollection()
22
+ ->addActiveFilter()
23
+ ->setChildOfOrder()
24
+ ->setAddBeforeOrder();
25
  // loop items and add to the menu:
26
  foreach ($cmsMenuItems as $menuItem) {
27
  // get item name:
47
  // get all child nodes:
48
  $allChildNodes = $observer->getMenu()->getAllChildNodes();
49
  // look for the parent item:
50
+ $parentItem = false;
51
+ // get child of value:
52
+ $childOf = $this->formatedItemValue($menuItem->getChildOf());
53
+ // look for cmsmenu items:
54
+ if(isset($allChildNodes[$childOf])) {
55
+ $parentItem = $allChildNodes[$childOf];
56
+ }
57
  if($parentItem) {
58
  // create new item node:
59
  $itemNode = new Varien_Data_Tree_Node($itemNodeData, 'cmsmenu-'.$menuItem->getCmsPageId(), $parentItem->getTree());
67
  // loop and reorder items:
68
  foreach($currentChilds as $childIndex => $currentChild) {
69
  $parentItem->removeChild($currentChild);
70
+ $addBeforeValue = $this->formatedItemValue($menuItem->getAddBefore());
71
+ if($childIndex == $addBeforeValue) {
72
  $parentItem->addChild($itemNode);
73
  }
74
  $parentItem->addChild($currentChild);
93
  // loop and reorder items:
94
  foreach($currentChilds as $childIndex => $currentChild) {
95
  $observer->getMenu()->removeChild($currentChild);
96
+ $addBeforeValue = $this->formatedItemValue($menuItem->getAddBefore());
97
+ if($childIndex == $addBeforeValue) {
98
  $observer->getMenu()->addChild($itemNode);
99
  }
100
  $observer->getMenu()->addChild($currentChild);
135
  return $isActive;
136
  }
137
 
138
+ public function formatedItemValue($value)
139
+ {
140
+ if(strpos($value, 'c-')!==false) {
141
+ $result = 'category-node-'.str_replace('c-', '', $value);
142
+ } else {
143
+ $result = 'cmsmenu-'.$value;
144
+ }
145
+ return $result;
146
+ }
147
+
148
  }
app/code/community/DwD/CmsMenu/Helper/Data.php CHANGED
@@ -14,6 +14,7 @@ class DwD_CmsMenu_Helper_Data extends Mage_Core_Helper_Abstract
14
 
15
  public function getFathersList()
16
  {
 
17
  $options = array(
18
  '0' => '',
19
  '1' => array(
@@ -25,14 +26,26 @@ class DwD_CmsMenu_Helper_Data extends Mage_Core_Helper_Abstract
25
  'value' => array()
26
  ),
27
  );
28
- $pages = Mage::getModel('cms/page')->getCollection();
29
- foreach ($pages as $p) {
30
- $options['1']['value'][] = array ('value'=>'cmsmenu-'.$p->getId(), 'label' => $p->getTitle());
 
 
 
 
 
 
 
 
31
  }
32
- // TODO: add categories filters for status and level.
33
- $categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect(array('name'));
 
 
 
 
34
  foreach ($categories as $c) {
35
- $options['2']['value'][] = array('value'=>'category-node-'.$c->getId(), 'label' => $c->getName());
36
  }
37
  return $options;
38
  }
14
 
15
  public function getFathersList()
16
  {
17
+ // options:
18
  $options = array(
19
  '0' => '',
20
  '1' => array(
26
  'value' => array()
27
  ),
28
  );
29
+ // get table name:
30
+ $cmsTable = Mage::getSingleton('core/resource')->getTableName('cmsmenu');
31
+ // get available pages:
32
+ $pagesCollection = Mage::getModel('cms/page')->getCollection();
33
+ $pagesCollection->getSelect()->joinRight(
34
+ array('cmsm' => $cmsTable),
35
+ 'main_table.page_id = cmsm.cms_page_id',
36
+ array('cmsmenu_id' => 'cmsm.id')
37
+ );
38
+ foreach ($pagesCollection as $p) {
39
+ $options['1']['value'][] = array ('value'=>$p->getId(), 'label' => $p->getTitle());
40
  }
41
+ // get available categories:
42
+ $categories = Mage::getModel('catalog/category')
43
+ ->getCollection()
44
+ ->addIsActiveFilter()
45
+ ->addFieldToFilter('level', array('gteq' => 2))
46
+ ->addAttributeToSelect(array('name'));
47
  foreach ($categories as $c) {
48
+ $options['2']['value'][] = array('value'=>'c-'.$c->getId(), 'label' => $c->getName());
49
  }
50
  return $options;
51
  }
app/code/community/DwD/CmsMenu/Model/Mysql4/Cmsmenu/Collection.php CHANGED
@@ -26,7 +26,7 @@ class DwD_CmsMenu_Model_Mysql4_Cmsmenu_Collection extends Mage_Core_Model_Mysql4
26
  public function addChildOfFilter($childOf=false)
27
  {
28
  if(!$childOf) {
29
- $this->addFieldToFilter('child_of', array('attribute' => 'child_of', array('eq'=>'0', 'n8ull'=>true)));
30
  } else {
31
  $this->addFieldToFilter('child_of', array('attribute' => 'child_of', 'eq' => $childOf));
32
  }
@@ -41,12 +41,14 @@ class DwD_CmsMenu_Model_Mysql4_Cmsmenu_Collection extends Mage_Core_Model_Mysql4
41
 
42
  public function setChildOfOrder()
43
  {
 
44
  $this->getSelect()->order('child_of', self::SORT_ORDER_ASC);
45
  return $this;
46
  }
47
 
48
  public function setAddBeforeOrder()
49
  {
 
50
  $this->getSelect()->order('add_before', self::SORT_ORDER_ASC);
51
  return $this;
52
  }
26
  public function addChildOfFilter($childOf=false)
27
  {
28
  if(!$childOf) {
29
+ $this->addFieldToFilter('child_of', array('attribute' => 'child_of', array('eq'=>'0', 'null'=>true)));
30
  } else {
31
  $this->addFieldToFilter('child_of', array('attribute' => 'child_of', 'eq' => $childOf));
32
  }
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;
47
  }
48
 
49
  public function setAddBeforeOrder()
50
  {
51
+ $this->getSelect()->order(new Zend_Db_Expr('add_before+0'), self::SORT_ORDER_ASC);
52
  $this->getSelect()->order('add_before', self::SORT_ORDER_ASC);
53
  return $this;
54
  }
app/code/community/DwD/CmsMenu/etc/config.xml CHANGED
@@ -12,7 +12,7 @@
12
  <config>
13
  <modules>
14
  <DwD_CmsMenu>
15
- <version>0.1.2</version>
16
  </DwD_CmsMenu>
17
  </modules>
18
  <global>
12
  <config>
13
  <modules>
14
  <DwD_CmsMenu>
15
+ <version>0.1.3</version>
16
  </DwD_CmsMenu>
17
  </modules>
18
  <global>
app/code/community/DwD/CmsMenu/sql/cmsmenu_setup/mysql4-upgrade-0.1.2-0.1.3.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // load old cmsmenu items:
17
+ $cmsMenuCollection = Mage::getModel('dwd_cmsmenu/cmsmenu')->getCollection();
18
+
19
+ // loop and fix:
20
+ foreach($cmsMenuCollection as $c) {
21
+ $childOf = $c->getChildOf();
22
+ if($childOf) {
23
+ if(strpos($childOf, 'cmsmenu-')!==false) {
24
+ $c->setChildOf(str_replace('cmsmenu-', '', $childOf));
25
+ }
26
+ if(strpos($childOf, 'category-node-')!==false) {
27
+ $c->setChildOf(str_replace('category-node-', 'c-', $childOf));
28
+ }
29
+ }
30
+ $addBefore = $c->getAddBefore();
31
+ if($addBefore) {
32
+ if(strpos($addBefore, 'cmsmenu-')!==false) {
33
+ $c->setAddBefore(str_replace('cmsmenu-', '', $addBefore));
34
+ }
35
+ if(strpos($addBefore, 'category-node-')!==false) {
36
+ $c->setAddBefore(str_replace('category-node-', 'c-', $addBefore));
37
+ }
38
+ }
39
+ $c->save();
40
+ }
41
+
42
+ $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.2</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,13 +47,13 @@ With this extension everything will be much easier and you will get everything w
47
  &lt;p&gt;For support, contact us at &lt;a href="mailto:info@dwdeveloper.com"&gt;info@dwdeveloper.com&lt;/a&gt;&lt;/p&gt;&#xD;
48
  &lt;p&gt;You can also get the extension from our GitHub repository: &lt;a href="https://github.com/damian-pastorini/DwD-Mage-Extension-CMS-Menu" target="_blank"&gt;https://github.com/damian-pastorini/DwD-Mage-Extension-CMS-Menu&lt;/a&gt;.&lt;/p&gt;&#xD;
49
  &lt;p&gt;Please feel free to report any issues there.&lt;/p&gt;</description>
50
- <notes>- Fixed setup scripts.&#xD;
51
- - Fixed case issues in configuration.&#xD;
52
- - Added automatic cache flush feature.</notes>
53
  <authors><author><name>Damian A. Pastorini</name><user>MAG002087848</user><email>damian.pastorini@dwdeveloper.com</email></author></authors>
54
- <date>2015-10-06</date>
55
- <time>22:17:52</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="fd1a67f069d30dd2e72a89fd2468c95f"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="531295ed2a3e9dba53f54f828f9604d4"/></dir><dir name="Model"><file name="Cmsmenu.php" hash="27a1044475f1a225142baa025051b5fb"/><dir name="Mysql4"><dir name="Cmsmenu"><file name="Collection.php" hash="d53ae01bcbec3719de7c5f2653b2790c"/></dir><file name="Cmsmenu.php" hash="f317ca72b5de8d0cf7a018b4deb8cdb8"/></dir><file name="Observer.php" hash="4de3cf8763ecbbedec952f4c7ec881a6"/></dir><dir name="etc"><file name="adminhtml.xml" hash="a47c8fe2ed9bdcc5a91595d9f633397e"/><file name="config.xml" hash="c81ccac4aaeaa90e3242a01b9100c442"/><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"/></dir></dir></dir></dir></target></contents>
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.3</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
  &lt;p&gt;For support, contact us at &lt;a href="mailto:info@dwdeveloper.com"&gt;info@dwdeveloper.com&lt;/a&gt;&lt;/p&gt;&#xD;
48
  &lt;p&gt;You can also get the extension from our GitHub repository: &lt;a href="https://github.com/damian-pastorini/DwD-Mage-Extension-CMS-Menu" target="_blank"&gt;https://github.com/damian-pastorini/DwD-Mage-Extension-CMS-Menu&lt;/a&gt;.&lt;/p&gt;&#xD;
49
  &lt;p&gt;Please feel free to report any issues there.&lt;/p&gt;</description>
50
+ <notes>- Fixed sort order to avoid child of not showing up issue.&#xD;
51
+ - Added categories level and status filters for admin select box.&#xD;
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-11</date>
55
+ <time>15:37:26</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="51aff44ee5ebe0fabcad15d8fa171d06"/></dir><dir name="Model"><file name="Cmsmenu.php" hash="27a1044475f1a225142baa025051b5fb"/><dir name="Mysql4"><dir name="Cmsmenu"><file name="Collection.php" hash="49f2c0fd4bd39fbc12c68af4e4f407a6"/></dir><file name="Cmsmenu.php" hash="f317ca72b5de8d0cf7a018b4deb8cdb8"/></dir><file name="Observer.php" hash="4de3cf8763ecbbedec952f4c7ec881a6"/></dir><dir name="etc"><file name="adminhtml.xml" hash="a47c8fe2ed9bdcc5a91595d9f633397e"/><file name="config.xml" hash="58bb46d52a6fd8e983d82fd1b0d9a86b"/><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"/></dir></dir></dir></dir></target></contents>
57
  <compatible/>
58
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
59
  </package>