From b65a26ce8212725b2654d26f804d0dca07c9e0cf Mon Sep 17 00:00:00 2001 From: Anton Samuelsson Date: Sat, 17 Sep 2016 14:03:59 +0200 Subject: [PATCH 1/3] Adding Magento 1.9.2.4 core file --- .../Catalog/Helper/Category/Url/Rewrite.php | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php diff --git a/app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php b/app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php new file mode 100644 index 0000000..4770746 --- /dev/null +++ b/app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php @@ -0,0 +1,121 @@ + + */ +class Mage_Catalog_Helper_Category_Url_Rewrite + implements Mage_Catalog_Helper_Category_Url_Rewrite_Interface +{ + /** + * Adapter instance + * + * @var Varien_Db_Adapter_Interface + */ + protected $_connection; + + /** + * Resource instance + * + * @var Mage_Core_Model_Resource + */ + protected $_resource; + + /** + * Initialize resource and connection instances + * + * @param array $args + */ + public function __construct(array $args = array()) + { + $this->_resource = Mage::getSingleton('core/resource'); + $this->_connection = !empty($args['connection']) ? $args['connection'] : $this->_resource + ->getConnection(Mage_Core_Model_Resource::DEFAULT_READ_RESOURCE); + } + + /** + * Join url rewrite table to eav collection + * + * @param Mage_Eav_Model_Entity_Collection_Abstract $collection + * @param int $storeId + * @return Mage_Catalog_Helper_Category_Url_Rewrite + */ + public function joinTableToEavCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection, $storeId) + { + $collection->joinTable( + 'core/url_rewrite', + 'category_id=entity_id', + array('request_path'), + "{{table}}.is_system=1 AND " . + "{{table}}.store_id='{$storeId}' AND " . + "{{table}}.id_path LIKE 'category/%'", + 'left' + ); + return $this; + } + + /** + * Join url rewrite table to collection + * + * @param Mage_Catalog_Model_Resource_Category_Flat_Collection $collection + * @param int $storeId + * @return Mage_Catalog_Helper_Category_Url_Rewrite|Mage_Catalog_Helper_Category_Url_Rewrite_Interface + */ + public function joinTableToCollection(Mage_Catalog_Model_Resource_Category_Flat_Collection $collection, $storeId) + { + $collection->getSelect()->joinLeft( + array('url_rewrite' => $collection->getTable('core/url_rewrite')), + 'url_rewrite.category_id = main_table.entity_id AND url_rewrite.is_system = 1 '. + ' AND ' . $collection->getConnection()->quoteInto('url_rewrite.store_id = ?', $storeId). + ' AND ' . $collection->getConnection()->quoteInto('url_rewrite.id_path LIKE ?', 'category/%'), + array('request_path') + ); + return $this; + } + + /** + * Join url rewrite to select + * + * @param Varien_Db_Select $select + * @param int $storeId + * @return Mage_Catalog_Helper_Category_Url_Rewrite + */ + public function joinTableToSelect(Varien_Db_Select $select, $storeId) + { + $select->joinLeft( + array('url_rewrite' => $this->_resource->getTableName('core/url_rewrite')), + 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND ' . + $this->_connection->quoteInto('url_rewrite.store_id = ? AND ', + (int)$storeId) . + $this->_connection->prepareSqlCondition('url_rewrite.id_path', array('like' => 'category/%')), + array('request_path' => 'url_rewrite.request_path')); + return $this; + } +} From d8849d643ff2a780c31a58e14819334b021ccd09 Mon Sep 17 00:00:00 2001 From: Anton Samuelsson Date: Sat, 17 Sep 2016 14:04:49 +0200 Subject: [PATCH 2/3] Improved url rewrite join by replacing the LIKE path --- .../community/Mage/Catalog/Helper/Category/Url/Rewrite.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php b/app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php index 4770746..ade9e9d 100644 --- a/app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php +++ b/app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php @@ -75,9 +75,11 @@ public function joinTableToEavCollection(Mage_Eav_Model_Entity_Collection_Abstra array('request_path'), "{{table}}.is_system=1 AND " . "{{table}}.store_id='{$storeId}' AND " . - "{{table}}.id_path LIKE 'category/%'", + "{{table}}.category_id IS NOT NULL AND " . + "{{table}}.product_id IS NULL", 'left' ); + return $this; } From 4f956469832db367657d23b991393183b3a4a022 Mon Sep 17 00:00:00 2001 From: Anton Samuelsson Date: Sat, 17 Sep 2016 14:11:53 +0200 Subject: [PATCH 3/3] Updated composer file --- composer.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/composer.json b/composer.json index 59450fe..5d465c2 100755 --- a/composer.json +++ b/composer.json @@ -21,6 +21,10 @@ "app/code/community/Webbhuset/Bugfix/", "app/code/community/Webbhuset/Bugfix/" ], + [ + "app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php", + "app/code/community/Mage/Catalog/Helper/Category/Url/Rewrite.php" + ], [ "app/code/community/Mage/Adminhtml/Block/Media/Uploader.php", "app/code/community/Mage/Adminhtml/Block/Media/Uploader.php"