Dnd_Patchindexurl - Version 1.0.0.0

Version Notes

v1.0.0.0 Stable

Download this release

Release Info

Developer Agence Dn'D
Extension Dnd_Patchindexurl
Version 1.0.0.0
Comparing to
See all releases


Version 1.0.0.0

app/code/community/Dnd/Patchindexurl/Model/Indexer/Url.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @version 1.0.0.0
4
+ * @copyright Copyright (c) 2012 Agence Dn'D
5
+ * @author Agence Dn'D - Conseil en cr�ation de site e-Commerce Magento : http://www.dnd.fr/
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ class Dnd_Patchindexurl_Model_Indexer_Url extends Mage_Catalog_Model_Indexer_Url
10
+ {
11
+
12
+ protected function _registerProductEvent(Mage_Index_Model_Event $event)
13
+ {
14
+ $product = $event->getDataObject();
15
+ $dataChange2 = false;
16
+
17
+ if(($product->dataHasChangedFor('status')&&$product->getData('status')=="1")||($product->dataHasChangedFor('visibility')&&$product->getData('visibility')!="1"))
18
+ {
19
+ $dataChange2 = true;
20
+ }
21
+
22
+ $dataChange = $product->dataHasChangedFor('url_key')
23
+ || $product->getIsChangedCategories()
24
+ || $product->getIsChangedWebsites()
25
+ || $dataChange2;
26
+
27
+ if (!$product->getExcludeUrlRewrite() && $dataChange) {
28
+ $event->addNewData('rewrite_product_ids', array($product->getId()));
29
+ }
30
+ }
31
+ }
app/code/community/Dnd/Patchindexurl/Model/Resource/Eav/Mysql4/Url.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @version 1.0.0.0
4
+ * @copyright Copyright (c) 2012 Agence Dn'D
5
+ * @author Agence Dn'D - Conseil en création de site e-Commerce Magento : http://www.dnd.fr/
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ class Dnd_Patchindexurl_Model_Resource_Eav_Mysql4_Url extends Mage_Catalog_Model_Resource_Eav_Mysql4_Url
10
+ {
11
+
12
+ protected function _getProducts($productIds = null, $storeId, $entityId = 0, &$lastEntityId)
13
+ {
14
+ $products = array();
15
+ $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
16
+ if (!is_null($productIds)) {
17
+ if (!is_array($productIds)) {
18
+ $productIds = array($productIds);
19
+ }
20
+ }
21
+ $select = $this->_getWriteAdapter()->select()
22
+ ->useStraightJoin(true)
23
+ ->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))
24
+ ->join(
25
+ array('w' => $this->getTable('catalog/product_website')),
26
+ $this->_getWriteAdapter()->quoteInto('e.entity_id=w.product_id AND w.website_id=?', $websiteId),
27
+ array()
28
+ )
29
+ ->where('e.entity_id>?', $entityId)
30
+ ->order('e.entity_id')
31
+ ->limit($this->_productLimit);
32
+ if (!is_null($productIds)) {
33
+ $select->where('e.entity_id IN(?)', $productIds);
34
+ }
35
+
36
+ $query = $this->_getWriteAdapter()->query($select);
37
+ while ($row = $query->fetch()) {
38
+ $product = new Varien_Object($row);
39
+ $product->setIdFieldName('entity_id');
40
+ $product->setCategoryIds(array());
41
+ $product->setStoreId($storeId);
42
+ $products[$product->getId()] = $product;
43
+ $lastEntityId = $product->getId();
44
+ }
45
+
46
+ unset($query);
47
+
48
+ if ($products) {
49
+ $select = $this->_getReadAdapter()->select()
50
+ ->from(
51
+ $this->getTable('catalog/category_product'),
52
+ array('product_id', 'category_id'))
53
+ ->where('product_id IN(?)', array_keys($products));
54
+ $categories = $this->_getReadAdapter()->fetchAll($select);
55
+ foreach ($categories as $category) {
56
+ $productId = $category['product_id'];
57
+ $categoryIds = $products[$productId]->getCategoryIds();
58
+ $categoryIds[] = $category['category_id'];
59
+ $products[$productId]->setCategoryIds($categoryIds);
60
+ }
61
+
62
+ foreach (array('name', 'url_key', 'url_path','visibility',"status") as $attributeCode) {
63
+ $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
64
+ foreach ($attributes as $productId => $attributeValue) {
65
+ $products[$productId]->setData($attributeCode, $attributeValue);
66
+ }
67
+ }
68
+ }
69
+
70
+ return $products;
71
+ }
72
+
73
+ }
app/code/community/Dnd/Patchindexurl/Model/Url.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @version 1.0.0.0
4
+ * @copyright Copyright (c) 2012 Agence Dn'D
5
+ * @author Agence Dn'D - Conseil en création de site e-Commerce Magento : http://www.dnd.fr/
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ class Dnd_Patchindexurl_Model_Url extends Mage_Catalog_Model_Url
10
+ {
11
+
12
+ public function refreshProductRewrites($storeId)
13
+ {
14
+ $this->_categories = array();
15
+ $storeRootCategoryId = $this->getStores($storeId)->getRootCategoryId();
16
+ $this->_categories[$storeRootCategoryId] = $this->getResource()->getCategory($storeRootCategoryId, $storeId);
17
+
18
+ $lastEntityId = 0;
19
+ $process = true;
20
+
21
+ $enableOptimisation = Mage::getStoreConfigFlag('dev/index/enable');
22
+ $excludeProductsDisabled = Mage::getStoreConfigFlag('dev/index/disable');
23
+ $excludeProductsNotVisible = Mage::getStoreConfigFlag('dev/index/notvisible');
24
+ $useCategoriesInUrl = Mage::getStoreConfig('catalog/seo/product_use_categories');
25
+
26
+ while ($process == true) {
27
+ $products = $this->getResource()->getProductsByStore($storeId, $lastEntityId);
28
+ if (!$products) {
29
+ $process = false;
30
+ break;
31
+ }
32
+
33
+ $this->_rewrites = array();
34
+ $this->_rewrites = $this->getResource()->prepareRewrites($storeId, false, array_keys($products));
35
+
36
+ $loadCategories = array();
37
+ foreach ($products as $product) {
38
+ foreach ($product->getCategoryIds() as $categoryId) {
39
+ if (!isset($this->_categories[$categoryId])) {
40
+ $loadCategories[$categoryId] = $categoryId;
41
+ }
42
+ }
43
+ }
44
+
45
+ if ($loadCategories) {
46
+ foreach ($this->getResource()->getCategories($loadCategories, $storeId) as $category) {
47
+ $this->_categories[$category->getId()] = $category;
48
+ }
49
+ }
50
+
51
+
52
+ foreach ($products as $product) {
53
+
54
+ if($enableOptimisation&&$excludeProductsDisabled&&$product->getData("status")==2)
55
+ {
56
+ continue;
57
+ }
58
+
59
+ if($enableOptimisation&&$excludeProductsNotVisible&&$product->getData("visibility")==1)
60
+ {
61
+ continue;
62
+ }
63
+
64
+ // Always Reindex short url
65
+ $this->_refreshProductRewrite($product, $this->_categories[$storeRootCategoryId]);
66
+
67
+
68
+ if($useCategoriesInUrl!="0"||!$enableOptimisation)
69
+ {
70
+ foreach ($product->getCategoryIds() as $categoryId) {
71
+ if ($categoryId != $storeRootCategoryId && isset($this->_categories[$categoryId])) {
72
+ $this->_refreshProductRewrite($product, $this->_categories[$categoryId]);
73
+ }
74
+ }
75
+ }
76
+
77
+ }
78
+
79
+ unset($products);
80
+ $this->_rewrites = array();
81
+ }
82
+
83
+ $this->_categories = array();
84
+ return $this;
85
+ }
86
+ }
app/code/community/Dnd/Patchindexurl/etc/config.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Dnd_Patchindexurl>
5
+ <version>1.0.0.0</version>
6
+ </Dnd_Patchindexurl>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <catalog>
11
+ <rewrite>
12
+ <url>Dnd_Patchindexurl_Model_Url</url>
13
+ </rewrite>
14
+ </catalog>
15
+ <catalog>
16
+ <rewrite>
17
+ <indexer_url>Dnd_Patchindexurl_Model_Indexer_Url</indexer_url>
18
+ </rewrite>
19
+ </catalog>
20
+ <catalog_resource_eav_mysql4>
21
+ <rewrite>
22
+ <url>Dnd_Patchindexurl_Model_Resource_Eav_Mysql4_Url</url>
23
+ </rewrite>
24
+ </catalog_resource_eav_mysql4>
25
+ <patchindexurl>
26
+ <class>Dnd_Patchindexurl_Model</class>
27
+ </patchindexurl>
28
+ </models>
29
+ </global>
30
+ </config>
app/code/community/Dnd/Patchindexurl/etc/system.xml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <dev>
5
+ <groups>
6
+ <index>
7
+ <label>Index Url Optimisation</label>
8
+ <show_in_default>1</show_in_default>
9
+ <show_in_website>0</show_in_website>
10
+ <show_in_store>0</show_in_store>
11
+ <sort_order>1</sort_order>
12
+ <fields>
13
+ <enable>
14
+ <label>Enable optimisation</label>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>0</show_in_website>
17
+ <show_in_store>0</show_in_store>
18
+ <frontend_type>select</frontend_type>
19
+ <source_model>adminhtml/system_config_source_yesno</source_model>
20
+ <sort_order>1</sort_order>
21
+ </enable>
22
+ <disable>
23
+ <label>Exclude disabled product</label>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>0</show_in_website>
26
+ <show_in_store>0</show_in_store>
27
+ <frontend_type>select</frontend_type>
28
+ <source_model>adminhtml/system_config_source_yesno</source_model>
29
+ <sort_order>2</sort_order>
30
+ </disable>
31
+ <notvisible>
32
+ <label>Exclude not visible product</label>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>0</show_in_website>
35
+ <show_in_store>0</show_in_store>
36
+ <frontend_type>select</frontend_type>
37
+ <source_model>adminhtml/system_config_source_yesno</source_model>
38
+ <sort_order>3</sort_order>
39
+ </notvisible>
40
+ </fields>
41
+ </index>
42
+ </groups>
43
+ </dev>
44
+ </sections>
45
+ </config>
app/etc/modules/Dnd_Patchindexurl.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Dnd_Patchindexurl>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Dnd_Patchindexurl>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Dnd_Patchindexurl</name>
4
+ <version>1.0.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">Extension license name (OSL v3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Patch Index Url</summary>
10
+ <description>Optimize re-index processing time for Url Rewrite</description>
11
+ <notes>v1.0.0.0 Stable</notes>
12
+ <authors><author><name>Agence Dn'D</name><user>cdidier</user><email>agencednd@gmail.com</email></author></authors>
13
+ <date>2012-10-28</date>
14
+ <time>14:44:42</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Dnd_Patchindexurl.xml" hash="999fc5ddb359a5a12a42cd71ed7200db"/></dir></target><target name="magecommunity"><dir name="Dnd"><dir name="Patchindexurl"><dir name="Model"><dir name="Indexer"><file name="Url.php" hash="aa88e55a9ae2b1d5d554be213ede818a"/></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><file name="Url.php" hash="9ed97ba1fa6a49320f62d6088665a19e"/></dir></dir></dir><file name="Url.php" hash="106e74d70fd45b6bc3d87ae2ff5745f9"/></dir><dir name="etc"><file name="config.xml" hash="b2afeedfeafb134b15a05d8609f365b2"/><file name="system.xml" hash="f07fbaf6394a3488bb62b68a07742cb0"/></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>