IG_CategoryParents - Version 1.0.0

Version Notes

Enjoy it ;)

Download this release

Release Info

Developer Magento Core Team
Extension IG_CategoryParents
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/IG/CategoryParents/COMPATIBILITY.txt ADDED
@@ -0,0 +1,9 @@
1
+ This file reports the compatibility table for this extension.
2
+ If your Magento version is not included in this list you may try
3
+ using the extension but AT YOUR OWN RISK.
4
+
5
+ CE 1.4.2
6
+ CE 1.5.0
7
+ CE 1.5.1
8
+ CE 1.6.0
9
+ CE 1.6.1
app/code/community/IG/CategoryParents/Helper/Data.php ADDED
@@ -0,0 +1,88 @@
1
+ <?php
2
+ /**
3
+ * IDEALIAGroup srl
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.idealiagroup.com/magento-ext-license.html
11
+ *
12
+ * @category IG
13
+ * @package IG_CategoryParents
14
+ * @copyright Copyright (c) 2010-2011 IDEALIAGroup srl (http://www.idealiagroup.com)
15
+ * @license http://www.idealiagroup.com/magento-ext-license.html
16
+ */
17
+
18
+ class IG_CategoryParents_Helper_Data extends Mage_Core_Helper_Abstract
19
+ {
20
+ protected $_categorModel;
21
+
22
+ /**
23
+ * Recursively load category's parents
24
+ *
25
+ * @param Mage_Catalog_Model_Category $category
26
+ * @return array
27
+ */
28
+ public function getRecursiveCategoryParents(Mage_Catalog_Model_Category $category)
29
+ {
30
+ $return = array();
31
+
32
+ $parentId = $category->getParentId();
33
+
34
+ if ($parentId == 1)
35
+ return null;
36
+
37
+ if (!$parentId)
38
+ return null;
39
+
40
+ $parent = Mage::getModel('catalog/category');
41
+ $parent->load($parentId);
42
+
43
+ $return = $this->getRecursiveCategoryParents($parent);
44
+ $return[] = $parentId;
45
+
46
+ return $return;
47
+ }
48
+
49
+ /**
50
+ * Recursively load product's parents
51
+ *
52
+ * @param Mage_Catalog_Model_Product $product
53
+ * @return array
54
+ */
55
+ public function getRecursiveProductParents(Mage_Catalog_Model_Product $product)
56
+ {
57
+ $return = array();
58
+
59
+ $categoryIds = $product->getCategoryIds();
60
+ if (!count($categoryIds))
61
+ return null;
62
+
63
+ rsort($categoryIds);
64
+
65
+ $category = Mage::getModel('catalog/category');
66
+ foreach ($categoryIds as $categoryId)
67
+ {
68
+ if (in_array($categoryId, $return))
69
+ continue;
70
+
71
+ if ($parentId == 1)
72
+ continue;
73
+
74
+ $category
75
+ ->setData(array())
76
+ ->load($categoryId);
77
+
78
+ $res = $this->getRecursiveCategoryParents($category);
79
+ $res[] = $categoryId;
80
+
81
+ $return = array_merge($return, $res);
82
+ }
83
+
84
+ $return = array_values(array_unique($return));
85
+
86
+ return $return;
87
+ }
88
+ }
app/code/community/IG/CategoryParents/LICENSE.txt ADDED
@@ -0,0 +1,72 @@
1
+ IDEALIAGroup srl EULA
2
+ www.idealiagroup.com
3
+ www.magentospecialist.it
4
+
5
+ THIS LICENSE AGREEMENT (HEREINAFTER AGREEMENT) IS AN AGREEMENT BETWEEN YOU (THE
6
+ PERSON OR COMPANY WHO IS BEING LICENSED TO USE THE SOFTWARE OR DOCUMENTATION)
7
+ AND IDEALIAGROUP SRL. (HEREINAFTER WE/US/OUR). THE AGREEMENT APPLIES TO ALL
8
+ PRODUCTS/SOFTWARE/SCRIPTS/SERVICES YOU PURCHASE FROM US.
9
+
10
+ 1. By purchasing the Software you acknowledge that you have read this Agreement,
11
+ and that you agree to the content of the Agreement and its terms, and agree
12
+ to use the Software in compliance with this Agreement.
13
+
14
+ 2. The Agreement comes into legal force at the moment when you order our
15
+ Software from our site or receive it through email or on data medium at the
16
+ our discretion.
17
+
18
+ 3. We are the copyright holder of the Product. The Product or a portion of
19
+ it is a copyrightable matter and is liable to protection by the law.
20
+ Any activity that infringes terms of this Agreement violates copyright
21
+ law and will be prosecuted according to the current law. We reserve the
22
+ right to revoke the license of any user who is holding an invalid
23
+ license.
24
+
25
+ 4. You may not use any part of the code in whole or part in any other
26
+ software or product or website without our explicit written permission.
27
+
28
+ 5. You have the right, within the duration of the license, to modify and
29
+ adapt the product for your specific needs.
30
+
31
+ 6. You may not give, sell, distribute, sub-license, rent, lease or lend
32
+ any portion of the Product or Documentation to anyone without our
33
+ explicit written permission. You may not place the Product on a server
34
+ so that it is accessible via a public network such as the Internet
35
+ for distribution purposes without our explicit written permission.
36
+
37
+ 7. You are bound to preserve the copyright information intact, this
38
+ includes the text/link at bottom of templates.
39
+
40
+ 8. We reserve the right to publish a selected list of buyers of our
41
+ Product.
42
+
43
+ 9. We will not be liable to you for any damages (including any loss of
44
+ profits/saving, or incidental or consequential) caused to you, your
45
+ information and your business arising out of the use or inability to use
46
+ this Product.
47
+
48
+ 10. We are not liable for prosecution arising from use of the Product
49
+ against law or for any illegal use.
50
+
51
+ 11. If you fail to use the Product in accordance with the terms and
52
+ conditions of this License Agreement, it constitutes a breach of the
53
+ agreement, and your license to use the program is revoked.
54
+
55
+ 12. IDEALIAGroup srl reserves the right to change this license agreement at
56
+ any time and impose its clauses at any given time.
57
+
58
+ 13. License agreement remains effective until terminated. We retain the right
59
+ to terminate your license to use the Product at any time, if in its sole
60
+ discretion, you are not abiding by the terms of the Agreement, including,
61
+ but not limited to, obscuring or removing any link or copyright notice as
62
+ specified in this agreement. You may terminate it at any time by
63
+ destroying all copies of the Product. Termination of this Agreement does
64
+ not bind us to return you the amount spent for purchase of the Product.
65
+
66
+ 14. If you continue to use the Software after IDEALIAGroup srl gives you
67
+ notice of termination of your license, you hereby agree to accept an
68
+ injunction to enjoin you from its further use and to pay all costs
69
+ (including but not limited to reasonable attorney fees) to enforce our
70
+ revocation of your license and any damages suffered by us because of
71
+ your misuse of the Product.
72
+
app/code/community/IG/CategoryParents/Model/Observer.php ADDED
@@ -0,0 +1,44 @@
1
+ <?php
2
+ /**
3
+ * IDEALIAGroup srl
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.idealiagroup.com/magento-ext-license.html
11
+ *
12
+ * @category IG
13
+ * @package IG_CategoryParents
14
+ * @copyright Copyright (c) 2010-2011 IDEALIAGroup srl (http://www.idealiagroup.com)
15
+ * @license http://www.idealiagroup.com/magento-ext-license.html
16
+ */
17
+
18
+ class IG_CategoryParents_Model_Observer
19
+ {
20
+ /**
21
+ * Set parent categories
22
+ *
23
+ * @param Varien_Event_Observer $observer
24
+ * @return IG_CategoryParents_Model_Observer
25
+ */
26
+ public function onCatalogProductSaveBefore($observer)
27
+ {
28
+ $product = $observer->getEvent()->getProduct();
29
+
30
+ if (!count($product->getCategoryIds()))
31
+ return $this;
32
+
33
+ $helper = Mage::helper('ig_categoryparents');
34
+ $recursiveParents = $helper->getRecursiveProductParents($product);
35
+
36
+ if (!count($recursiveParents))
37
+ return $this;
38
+
39
+ $product
40
+ ->setCategoryIds($recursiveParents);
41
+
42
+ return $this;
43
+ }
44
+ }
app/code/community/IG/CategoryParents/etc/config.xml ADDED
@@ -0,0 +1,70 @@
1
+ <config>
2
+ <modules>
3
+ <IG_CategoryParents>
4
+ <version>1.0.0</version>
5
+ </IG_CategoryParents>
6
+ </modules>
7
+
8
+ <global>
9
+ <helpers>
10
+ <ig_categoryparents>
11
+ <class>IG_CategoryParents_Helper</class>
12
+ </ig_categoryparents>
13
+ </helpers>
14
+ <models>
15
+ <ig_categoryparents>
16
+ <class>IG_CategoryParents_Model</class>
17
+ </ig_categoryparents>
18
+ </models>
19
+ </global>
20
+
21
+ <adminhtml>
22
+ <translate>
23
+ <modules>
24
+ <ig_categoryparents>
25
+ <files>
26
+ <default>IG_CategoryParents.csv</default>
27
+ </files>
28
+ </ig_categoryparents>
29
+ </modules>
30
+ </translate>
31
+ <events>
32
+ <catalog_product_save_before>
33
+ <observers>
34
+ <ig_categoryparents>
35
+ <class>ig_categoryparents/observer</class>
36
+ <method>onCatalogProductSaveBefore</method>
37
+ </ig_categoryparents>
38
+ </observers>
39
+ </catalog_product_save_before>
40
+ </events>
41
+ <acl>
42
+ <resources>
43
+ <admin>
44
+ <children>
45
+ <system>
46
+ <children>
47
+ <config>
48
+ <children>
49
+ <ig_categoryparents translate="title" module="ig_categoryparents">
50
+ <title>IG CategoryParents</title>
51
+ <sort_order>50</sort_order>
52
+ </ig_categoryparents>
53
+ </children>
54
+ </config>
55
+ </children>
56
+ </system>
57
+ </children>
58
+ </admin>
59
+ </resources>
60
+ </acl>
61
+ </adminhtml>
62
+
63
+ <default>
64
+ <ig_categoryparents>
65
+ <general>
66
+ <enabled>1</enabled>
67
+ </general>
68
+ </ig_categoryparents>
69
+ </default>
70
+ </config>
app/code/community/IG/CategoryParents/etc/system.xml ADDED
@@ -0,0 +1,41 @@
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <ig translate="label" module="ig_categoryparents">
5
+ <label>IdealiaGroup</label>
6
+ <sort_order>200</sort_order>
7
+ </ig>
8
+ </tabs>
9
+ <sections>
10
+ <ig_categoryparents translate="label" module="ig_categoryparents">
11
+ <label>IG CategoryParents</label>
12
+ <tab>ig</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>10</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <general translate="label">
20
+ <label>General</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>10</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <enabled translate="label">
28
+ <label>Enable</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>10</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </enabled>
36
+ </fields>
37
+ </general>
38
+ </groups>
39
+ </ig_categoryparents>
40
+ </sections>
41
+ </config>
app/etc/modules/IG_CategoryParents.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <IG_CategoryParents>
5
+ <active>false</active>
6
+ <codePool>community</codePool>
7
+ </IG_CategoryParents>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>IG_CategoryParents</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.idealiagroup.com/magento-ext-license.html">Commercial</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>IDEALIAGroup Category Parents</summary>
10
+ <description>IDEALIAGroup Category Parents</description>
11
+ <notes>Enjoy it ;)</notes>
12
+ <authors><author><name>Riccardo Tempesta</name><user>auto-converted</user><email>tempesta@idealiagroup.com</email></author><author><name>Marco Giorgetti</name><user>auto-converted</user><email>giorgetti@idealiagroup.com</email></author></authors>
13
+ <date>2011-12-28</date>
14
+ <time>10:14:22</time>
15
+ <contents><target name="magecommunity"><dir name="IG"><dir name="CategoryParents"><dir name="Helper"><file name="Data.php" hash="deeac4c99b519bc2bea1f82f092890b3"/></dir><dir name="Model"><file name="Observer.php" hash="b29f1284b9a21e14e101452e0f81350e"/></dir><dir name="etc"><file name="config.xml" hash="f1d215815ddf7c9ea2ffb64118925749"/><file name="system.xml" hash="dfc7f81b75f54020957b6a37bb97beed"/></dir><file name="COMPATIBILITY.txt" hash="d3b64c7bb51137148e6b0feed3224af5"/><file name="LICENSE.txt" hash="b3688e16b11d101dd15b47c62cd2567d"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="IG_CategoryParents.xml" hash="70412844e73006347cacf0a340824bc2"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>