activo_categoryurlseo - Version 2.0.0

Version Notes

Complete rewrite. Using less overwrites. No more rewrite URL with numbers at the end for products - issue fully resolved!

Download this release

Release Info

Developer Activo Extensions
Extension activo_categoryurlseo
Version 2.0.0
Comparing to
See all releases


Code changes from version 1.0.4.1 to 2.0.0

app/code/community/Activo/Categoryurlseo/Helper/Category.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
-
3
- class Activo_Categoryurlseo_Helper_Category extends Mage_Catalog_Helper_Category
4
- {
5
- /**
6
- * Retrieve clear url for category as parrent
7
- *
8
- * @param string $url
9
- * @param bool $slash
10
- * @param int $storeId
11
- *
12
- * @return string
13
- */
14
- public function getCategoryUrlPath($urlPath, $slash = false, $storeId = null)
15
- {
16
- if (Mage::getStoreConfig('activo_categoryurlseo/global/enabled')==0)
17
- {
18
- return parent::getCategoryUrlPath($urlPath, $slash, $storeId);
19
- }
20
- else
21
- {
22
- return Mage::getStoreConfig('activo_categoryurlseo/global/toplevel');
23
- }
24
- }
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Activo/Categoryurlseo/Helper/Data.php CHANGED
@@ -1,22 +1,17 @@
1
  <?php
2
  /**
3
- * Activo OpenSource
4
  *
5
- * LICENSE
6
  *
7
- * This source file is subject to the new BSD license that is bundled
8
- * with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://store.delorumcommerce.com/license/new-bsd
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@tinybrick.com so we can send you a copy immediately.
14
  *
15
- * @category Activo
16
- * @package Activo_BulkImages
17
- * @copyright Copyright (c) 2011 Activo Inc. (http://www.activo.com)
18
- * @license OSL 3.0
19
  */
 
20
 
21
  class Activo_Categoryurlseo_Helper_Data extends Mage_Core_Helper_Abstract
22
  {
1
  <?php
2
  /**
3
+ * Activo Extensions
4
  *
5
+ * NOTICE OF LICENSE
6
  *
7
+ * This source file is subject to the Activo Commercial License
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://extensions.activo.com/license_professional
 
 
 
 
10
  *
11
+ * @copyright Copyright (c) 2014 Activo Extensions (http://extensions.activo.com)
12
+ * @license OSL 3.0
 
 
13
  */
14
+
15
 
16
  class Activo_Categoryurlseo_Helper_Data extends Mage_Core_Helper_Abstract
17
  {
app/code/community/Activo/Categoryurlseo/Model/Feed.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Activo Extensions
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Activo Commercial License
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://extensions.activo.com/license_professional
10
+ *
11
+ * @copyright Copyright (c) 2014 Activo Extensions (http://extensions.activo.com)
12
+ * @license OSL 3.0
13
+ */
14
+
15
+ //http://www.nicksays.co.uk/2009/05/magento-custom-admin-notifications/
16
+ class Activo_Categoryurlseo_Model_Feed extends Mage_AdminNotification_Model_Feed
17
+ {
18
+ public function getFeedUrl()
19
+ {
20
+ preg_match('/(.*)_Model_Feed/', get_class($this), $matches);
21
+ $module = isset($matches[1]) ? $matches[1] : "";
22
+
23
+ if (is_null($this->_feedUrl)) {
24
+ $this->_feedUrl = 'http://extensions.activo.com/adminrss.php?s='
25
+ .urlencode(Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_UNSECURE_URL))
26
+ .'&m='. $module;
27
+ // Mage::log($this->_feedUrl);
28
+ }
29
+ return $this->_feedUrl;
30
+ }
31
+
32
+ public function observe()
33
+ {
34
+ $model = Mage::getModel('categoryurlseo/feed');
35
+ $model->checkUpdate();
36
+ }
37
+
38
+ // public function getFrequency()
39
+ // {
40
+ // return 1;
41
+ // }
42
+
43
+ }
app/code/community/Activo/Categoryurlseo/Model/Url.php CHANGED
@@ -1,102 +1,69 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  class Activo_Categoryurlseo_Model_Url extends Mage_Catalog_Model_Url
3
  {
 
4
  /**
5
- * Get unique product request path
6
  *
7
- * @param Varien_Object $product
8
- * @param Varien_Object $category
9
- * @return string
10
  */
11
- public function getProductRequestPath($product, $category)
12
  {
13
- if (Mage::getStoreConfig('activo_categoryurlseo/global/enabled')==0)
14
- {
15
- return parent::getProductRequestPath($product, $category);
 
 
 
 
16
  }
17
- else
18
- {
19
- if ($product->getUrlKey() == '') {
20
- $urlKey = $this->getProductModel()->formatUrlKey($product->getName());
21
- } else {
22
- $urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey());
23
- }
24
- $storeId = $category->getStoreId();
25
- $suffix = $this->getProductUrlSuffix($storeId);
26
- $idPath = $this->generatePath('id', $product, $category);
27
- /**
28
- * Prepare product base request path
29
- */
30
- if ($category->getLevel() > 1) {
31
- // To ensure, that category has path either from attribute or generated now
32
- $this->_addCategoryUrlPath($category);
33
- $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(),
34
- false, $storeId);
35
- if ($categoryUrl == "")
36
- {
37
- $requestPath = $urlKey;
38
- }
39
- else
40
- {
41
- $requestPath = $categoryUrl . '/' . $urlKey;
42
- }
43
- $requestPath = str_ireplace('//', '/', $requestPath);
44
- } else {
45
- $requestPath = $urlKey;
46
- }
47
 
48
- if (strlen($requestPath) > self::MAX_REQUEST_PATH_LENGTH + self::ALLOWED_REQUEST_PATH_OVERFLOW) {
49
- $requestPath = substr($requestPath, 0, self::MAX_REQUEST_PATH_LENGTH);
50
- }
 
 
 
51
 
52
- $this->_rewrite = null;
53
- /**
54
- * Check $requestPath should be unique
55
- */
56
- if (isset($this->_rewrites[$idPath])) {
57
- $this->_rewrite = $this->_rewrites[$idPath];
58
- $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
59
- $existingRequestPath = str_replace($suffix, '', $existingRequestPath);
 
 
60
 
61
- if ($existingRequestPath == $requestPath) {
62
- return $requestPath.$suffix;
63
- }
64
- /**
65
- * Check if existing request past can be used
66
- */
67
- if ($product->getUrlKey() == '' && !empty($requestPath)
68
- && strpos($existingRequestPath, $requestPath) !== false
69
- ) {
70
- $existingRequestPath = str_replace($requestPath, '', $existingRequestPath);
71
- if (preg_match('#^-([0-9]+)$#i', $existingRequestPath)) {
72
- return $this->_rewrites[$idPath]->getRequestPath();
73
- }
74
- }
75
- /**
76
- * check if current generated request path is one of the old paths
77
- */
78
- $fullPath = $requestPath.$suffix;
79
- $finalOldTargetPath = $this->getResource()->findFinalTargetPath($fullPath, $storeId);
80
- if ($finalOldTargetPath && $finalOldTargetPath == $idPath) {
81
- $this->getResource()->deleteRewrite($fullPath, $storeId);
82
- return $fullPath;
83
- }
84
- }
85
- /**
86
- * Check 2 variants: $requestPath and $requestPath . '-' . $productId
87
- */
88
- $validatedPath = $this->getResource()->checkRequestPaths(
89
- array($requestPath.$suffix, $requestPath.'-'.$product->getId().$suffix),
90
- $storeId
91
- );
92
 
93
- if ($validatedPath) {
94
- return $validatedPath;
95
- }
96
- /**
97
- * Use unique path generator
98
- */
99
- return $this->getUnusedPath($storeId, $requestPath.$suffix, $idPath);
100
  }
 
 
 
 
101
  }
 
102
  }
1
  <?php
2
+ /**
3
+ * Activo Extensions
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Activo Commercial License
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://extensions.activo.com/license_professional
10
+ *
11
+ * @copyright Copyright (c) 2014 Activo Extensions (http://extensions.activo.com)
12
+ * @license OSL 3.0
13
+ */
14
+
15
+
16
  class Activo_Categoryurlseo_Model_Url extends Mage_Catalog_Model_Url
17
  {
18
+
19
  /**
20
+ * Get unique category request path
21
  *
22
+ * @param Varien_Object $category
23
+ * @param string $parentPath
24
+ * @return string
25
  */
26
+ public function getCategoryRequestPath($category, $parentPath)
27
  {
28
+ $storeId = $category->getStoreId();
29
+ $idPath = $this->generatePath('id', null, $category);
30
+ $suffix = $this->getCategoryUrlSuffix($storeId);
31
+
32
+ if (isset($this->_rewrites[$idPath])) {
33
+ $this->_rewrite = $this->_rewrites[$idPath];
34
+ $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
35
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ if ($category->getUrlKey() == '') {
38
+ $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName());
39
+ }
40
+ else {
41
+ $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey());
42
+ }
43
 
44
+ $categoryUrlSuffix = $this->getCategoryUrlSuffix($category->getStoreId());
45
+ if (null === $parentPath) {
46
+ $parentPath = $this->getResource()->getCategoryParentPath($category);
47
+ }
48
+ elseif ($parentPath == '/') {
49
+ $parentPath = '';
50
+ }
51
+ // $parentPath = Mage::helper('catalog/category')->getCategoryUrlPath($parentPath,
52
+ // true, $category->getStoreId());
53
+ $parentPath = '';
54
 
55
+ $requestPath = $parentPath . $urlKey . $categoryUrlSuffix;
56
+ if (isset($existingRequestPath) && $existingRequestPath == $requestPath . $suffix) {
57
+ return $existingRequestPath;
58
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
+ if ($this->_deleteOldTargetPath($requestPath, $idPath, $storeId)) {
61
+ return $requestPath;
 
 
 
 
 
62
  }
63
+
64
+ return $this->getUnusedPath($category->getStoreId(), $requestPath,
65
+ $this->generatePath('id', null, $category)
66
+ );
67
  }
68
+
69
  }
app/code/community/Activo/Categoryurlseo/etc/config.xml CHANGED
@@ -1,8 +1,22 @@
1
  <?xml version="1.0"?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  <config>
3
  <modules>
4
  <Activo_Categoryurlseo>
5
- <version>1.0.0</version>
6
  </Activo_Categoryurlseo>
7
  </modules>
8
 
@@ -11,11 +25,6 @@
11
  <categoryurlseo>
12
  <class>Activo_Categoryurlseo_Helper</class>
13
  </categoryurlseo>
14
- <catalog>
15
- <rewrite>
16
- <category>Activo_Categoryurlseo_Helper_Category</category>
17
- </rewrite>
18
- </catalog>
19
  </helpers>
20
  <models>
21
  <categoryurlseo>
@@ -29,6 +38,17 @@
29
  </models>
30
  </global>
31
  <adminhtml>
 
 
 
 
 
 
 
 
 
 
 
32
  <acl>
33
  <resources>
34
  <admin>
@@ -53,7 +73,6 @@
53
  <activo_categoryurlseo>
54
  <global>
55
  <enabled>1</enabled>
56
- <toplevel></toplevel>
57
  </global>
58
  </activo_categoryurlseo>
59
  </default>
1
  <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Activo Extensions
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Activo Commercial License
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://extensions.activo.com/license_professional
11
+ *
12
+ * @copyright Copyright (c) 2014 Activo Extensions (http://extensions.activo.com)
13
+ * @license OSL 3.0
14
+ */
15
+ -->
16
  <config>
17
  <modules>
18
  <Activo_Categoryurlseo>
19
+ <version>2.0.0</version>
20
  </Activo_Categoryurlseo>
21
  </modules>
22
 
25
  <categoryurlseo>
26
  <class>Activo_Categoryurlseo_Helper</class>
27
  </categoryurlseo>
 
 
 
 
 
28
  </helpers>
29
  <models>
30
  <categoryurlseo>
38
  </models>
39
  </global>
40
  <adminhtml>
41
+ <events>
42
+ <controller_action_predispatch>
43
+ <observers>
44
+ <activo_news_categoryurlseo>
45
+ <type>singleton</type>
46
+ <class>categoryurlseo/feed</class>
47
+ <method>observe</method>
48
+ </activo_news_categoryurlseo>
49
+ </observers>
50
+ </controller_action_predispatch>
51
+ </events>
52
  <acl>
53
  <resources>
54
  <admin>
73
  <activo_categoryurlseo>
74
  <global>
75
  <enabled>1</enabled>
 
76
  </global>
77
  </activo_categoryurlseo>
78
  </default>
app/code/community/Activo/Categoryurlseo/etc/system.xml CHANGED
@@ -1,28 +1,16 @@
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
- * Magento
5
  *
6
  * NOTICE OF LICENSE
7
  *
8
- * This source file is subject to the Academic Free License (AFL 3.0)
9
- * that is bundled with this package in the file LICENSE_AFL.txt.
10
- * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/afl-3.0.php
12
- * If you did not receive a copy of the license and are unable to
13
- * obtain it through the world-wide-web, please send an email
14
- * to license@magentocommerce.com so we can send you a copy immediately.
15
  *
16
- * DISCLAIMER
17
- *
18
- * Do not edit or add to this file if you wish to upgrade Magento to newer
19
- * versions in the future. If you wish to customize Magento for your
20
- * needs please refer to http://www.magentocommerce.com for more information.
21
- *
22
- * @category
23
- * @package _home
24
- * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
25
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
@@ -38,7 +26,7 @@
38
  <label>SEO Friendly Category</label>
39
  <tab>activo</tab>
40
  <frontend_type>text</frontend_type>
41
- <sort_order>67</sort_order>
42
  <show_in_default>1</show_in_default>
43
  <show_in_website>1</show_in_website>
44
  <show_in_store>1</show_in_store>
@@ -61,15 +49,6 @@
61
  <show_in_store>1</show_in_store>
62
  <comment>Select Yes if you wish to ignore the parent category(s) in the Category URLs. Notice once you change this value you may need to reindex the Catalog URL Rewrites.</comment>
63
  </enabled>
64
- <toplevel translate="label">
65
- <label>Manual Top Level</label>
66
- <frontend_type>text</frontend_type>
67
- <sort_order>20</sort_order>
68
- <show_in_default>1</show_in_default>
69
- <show_in_website>1</show_in_website>
70
- <show_in_store>1</show_in_store>
71
- <comment>Add a top level manual category that will apply to all products accross the store. No need for the preceeding forward slash, add a trailing forward slash if needed.</comment>
72
- </toplevel>
73
  </fields>
74
  </global>
75
  </groups>
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
+ * Activo Extensions
5
  *
6
  * NOTICE OF LICENSE
7
  *
8
+ * This source file is subject to the Activo Commercial License
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://extensions.activo.com/license_professional
 
 
 
 
11
  *
12
+ * @copyright Copyright (c) 2014 Activo Extensions (http://extensions.activo.com)
13
+ * @license OSL 3.0
 
 
 
 
 
 
 
 
14
  */
15
  -->
16
  <config>
26
  <label>SEO Friendly Category</label>
27
  <tab>activo</tab>
28
  <frontend_type>text</frontend_type>
29
+ <sort_order>68</sort_order>
30
  <show_in_default>1</show_in_default>
31
  <show_in_website>1</show_in_website>
32
  <show_in_store>1</show_in_store>
49
  <show_in_store>1</show_in_store>
50
  <comment>Select Yes if you wish to ignore the parent category(s) in the Category URLs. Notice once you change this value you may need to reindex the Catalog URL Rewrites.</comment>
51
  </enabled>
 
 
 
 
 
 
 
 
 
52
  </fields>
53
  </global>
54
  </groups>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>activo_categoryurlseo</name>
4
- <version>1.0.4.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL 3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Flattens the SEO structure of your entire catalog.</summary>
10
  <description>This FREE SEO Friendly Categories extension lets you flatten your URL structure by using only the last subcategory name in the URL. So instead of mystore.com/category/subcategory1/subcategory2/subcategory3 you will have just mystore.com/subcategory3 in your URL.</description>
11
- <notes>Flattens the SEO structure of your entire catalog: fixed double slash bug in certain cases.</notes>
12
  <authors><author><name>Activo Extensions</name><user>activo</user><email>extensions@activo.com</email></author></authors>
13
- <date>2012-10-23</date>
14
- <time>19:05:57</time>
15
- <contents><target name="magecommunity"><dir name="Activo"><dir name="Categoryurlseo"><dir><dir name="Helper"><file name="Category.php" hash="15ae9939d3b789f194747ffd2163e204"/><file name="Data.php" hash="6892bf5f068f01ecbe4bc746ed0be85b"/></dir><dir name="Model"><file name="Url.php" hash="2e970a0b97c40f38d46da150410170d9"/></dir><dir name="etc"><file name="config.xml" hash="c6b25932abab4588478b2ccf46f5ee36"/><file name="system.xml" hash="d8d6fa1b7e04ada0c492b3738b6d9de7"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Activo_Categoryurlseo.xml" hash="cbb2d56a19efe3658ff0b6bf21376dd3"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>8.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>activo_categoryurlseo</name>
4
+ <version>2.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL 3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Flattens the SEO structure of your entire catalog.</summary>
10
  <description>This FREE SEO Friendly Categories extension lets you flatten your URL structure by using only the last subcategory name in the URL. So instead of mystore.com/category/subcategory1/subcategory2/subcategory3 you will have just mystore.com/subcategory3 in your URL.</description>
11
+ <notes>Complete rewrite. Using less overwrites. No more rewrite URL with numbers at the end for products - issue fully resolved!</notes>
12
  <authors><author><name>Activo Extensions</name><user>activo</user><email>extensions@activo.com</email></author></authors>
13
+ <date>2014-06-11</date>
14
+ <time>00:29:36</time>
15
+ <contents><target name="magecommunity"><dir name="Activo"><dir name="Categoryurlseo"><dir><dir name="Helper"><file name="Data.php" hash="bdaa75a35d985d61efd5d1c366a7c43b"/></dir><dir name="Model"><file name="Feed.php" hash="0e855a40f023242c42fa57efe5a0dec5"/><file name="Url.php" hash="434b685f1e47a2d52d81be667a341af1"/></dir><dir name="etc"><file name="config.xml" hash="056762ef135e50775cda23a8f7cf8441"/><file name="system.xml" hash="efd57e66e2c55fd1a4960d6601aca62b"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Activo_Categoryurlseo.xml" hash="cbb2d56a19efe3658ff0b6bf21376dd3"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>8.0.0</max></php></required></dependencies>
18
  </package>