Magefast_ProductBreadcrumbs - Version 0.0.1

Version Notes

First realise

Download this release

Release Info

Developer Alex
Extension Magefast_ProductBreadcrumbs
Version 0.0.1
Comparing to
See all releases


Version 0.0.1

app/code/community/Magefast/ProductBreadcrumbs/Helper/Data.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magefast_ProductBreadcrumbs_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ const XML_PATH_CATEGORY_URL_SUFFIX = 'catalog/productbreadcrumbs/skip_categories';
6
+
7
+ protected $_skipCategoryIDs = array();
8
+
9
+
10
+ /**
11
+ * Get skip category IDs
12
+ *
13
+ * @param null $storeId
14
+ * @return mixed
15
+ */
16
+ public function getSkipCategoryIDs($storeId = null)
17
+ {
18
+ if (is_null($storeId)) {
19
+ $storeId = Mage::app()->getStore()->getId();
20
+ }
21
+
22
+ if (!isset($this->_skipCategoryIDs[$storeId])) {
23
+ $arrayData = array();
24
+ $configData = Mage::getStoreConfig(self::XML_PATH_CATEGORY_URL_SUFFIX, $storeId);
25
+ $configData = trim($configData);
26
+
27
+ $configDataArray = explode(',', $configData);
28
+
29
+ foreach ($configDataArray as $a) {
30
+ $arrayData[intval(trim($a))] = intval(trim($a));
31
+ }
32
+
33
+ $this->_skipCategoryIDs[$storeId] = $arrayData;
34
+ }
35
+ return $this->_skipCategoryIDs[$storeId];
36
+ }
37
+
38
+ }
app/code/community/Magefast/ProductBreadcrumbs/Model/Observer.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magefast_ProductBreadcrumbs_Model_Observer
4
+ {
5
+ protected $_categoriesLevel4 = null;
6
+
7
+
8
+ public function updateBreadcrumbs($observer)
9
+ {
10
+ $layout = $observer->getLayout();
11
+
12
+ /**
13
+ * Return, if have not Bradcrubs block
14
+ */
15
+ if (!$layout->getBlock('breadcrumbs')) {
16
+ return $this;
17
+ }
18
+
19
+ /**
20
+ * Return, if exist current category - go to Standart logic
21
+ */
22
+ $currentCategory = Mage::registry('current_category');
23
+
24
+ if ($currentCategory) {
25
+ return $this;
26
+ }
27
+
28
+ /**
29
+ * Return, if have not product, not product page
30
+ */
31
+ $currentProduct = Mage::registry('current_product');
32
+
33
+ if (!$currentProduct) {
34
+ return $this;
35
+ }
36
+
37
+
38
+ if ($catIds = $currentProduct->getCategoryIds()) {
39
+
40
+ if (is_array($catIds) && count($catIds) > 0) {
41
+ $categories = $this->_getCategoriesArray();
42
+
43
+ foreach ($catIds as $c) {
44
+ if (isset($skipCategoryIDsArray[$c])) {
45
+ continue;
46
+ }
47
+ if (isset($categories[$c]) && $categories[$c]['level'] == 4) {
48
+ $productCategory = $categories[$c];
49
+ break;
50
+ }
51
+
52
+ if (isset($categories[$c]) && $categories[$c]['level'] == 3) {
53
+ $productCategory = $categories[$c];
54
+ break;
55
+ }
56
+
57
+ if (isset($categories[$c]) && $categories[$c]['level'] == 2) {
58
+ $productCategory = $categories[$c];
59
+ break;
60
+ }
61
+ }
62
+
63
+ }
64
+
65
+ if (!isset($productCategory)) {
66
+ return $this;
67
+ }
68
+
69
+
70
+ $path = $productCategory['path'];
71
+
72
+ $pathCategories = explode('/', $path);
73
+
74
+ foreach ($pathCategories as $pc) {
75
+ if ($pc == 1 || $pc == 2) {
76
+ continue;
77
+ }
78
+ $breadcrumbs[$pc]['name'] = $categories[$pc]['name'];
79
+ $breadcrumbs[$pc]['url'] = $categories[$pc]['url'];
80
+ $breadcrumbs[$pc]['category'] = $pc;
81
+ }
82
+
83
+ if (isset($breadcrumbs)) {
84
+ if ($breadcrumbs_block = $layout->getBlock('breadcrumbs')) {
85
+
86
+ /**
87
+ * Remove crumb for Product
88
+ */
89
+ $breadcrumbs_block->removeCrumbs('product');
90
+
91
+ /**
92
+ * Add new crumbs,
93
+ * for Homepage
94
+ */
95
+ $breadcrumbs_block->addCrumb(
96
+ 'home',
97
+ array(
98
+ 'label' => Mage::helper('cms')->__('Home'),
99
+ 'title' => Mage::helper('cms')->__('Go to Home Page'),
100
+ 'link' => Mage::getBaseUrl()
101
+ )
102
+ );
103
+
104
+ /**
105
+ * For categories, where include product
106
+ */
107
+ foreach ($breadcrumbs as $b) {
108
+ $breadcrumbs_block->addCrumb('category' . $b['category'], array(
109
+ 'label' => $b['name'],
110
+ 'title' => $b['name'],
111
+ 'link' => $b['url'],
112
+ 'first' => true,
113
+
114
+ ));
115
+ }
116
+
117
+ /**
118
+ * And for current produtc
119
+ */
120
+ $breadcrumbs_block->addCrumb('product', array(
121
+ 'label' => $currentProduct->getName(),
122
+ 'readonly' => false,
123
+ 'last' => true
124
+ ));
125
+ }
126
+ }
127
+ }
128
+
129
+ return $this;
130
+ }
131
+
132
+
133
+ /**
134
+ * Get array with categories
135
+ *
136
+ * @return array
137
+ */
138
+ protected function _getCategoriesArray()
139
+ {
140
+ $skipCategoryIDsArray = Mage::helper('magefast_productbreadcrumbs')->getSkipCategoryIDs();
141
+
142
+ $categoriesArray = Mage::getModel('catalog/category')
143
+ ->getCollection()
144
+ ->addAttributeToSelect('name');
145
+
146
+ $categoryArray = array();
147
+ foreach ($categoriesArray as $category) {
148
+ if ($skipCategoryIDsArray[$category->getId()]) {
149
+ continue;
150
+ }
151
+ $categoryData = $category->getData();
152
+ $categoryArray[$categoryData['entity_id']] = $categoryData;
153
+ $categoryArray[$categoryData['entity_id']]['url'] = $category->getUrl();
154
+ }
155
+ unset($categoriesArray);
156
+
157
+ return $categoryArray;
158
+ }
159
+
160
+ }
app/code/community/Magefast/ProductBreadcrumbs/etc/config.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Magefast_ProductBreadcrumbs>
5
+ <version>0.0.1</version>
6
+ </Magefast_ProductBreadcrumbs>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <magefast_productbreadcrumbs>
11
+ <class>Magefast_ProductBreadcrumbs_Helper</class>
12
+ </magefast_productbreadcrumbs>
13
+ </helpers>
14
+ </global>
15
+ <frontend>
16
+ <events>
17
+ <controller_action_layout_generate_blocks_after>
18
+ <observers>
19
+ <magefast_productbreadcrumbs_observer>
20
+ <type>singleton</type>
21
+ <class>Magefast_ProductBreadcrumbs_Model_Observer</class>
22
+ <method>updateBreadcrumbs</method>
23
+ </magefast_productbreadcrumbs_observer>
24
+ </observers>
25
+ </controller_action_layout_generate_blocks_after>
26
+ </events>
27
+ </frontend>
28
+ </config>
app/code/community/Magefast/ProductBreadcrumbs/etc/system.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <catalog>
5
+ <tab>catalog</tab>
6
+ <groups>
7
+ <productbreadcrumbs translate="label" module="magefast_productbreadcrumbs">
8
+ <label>Product Breadcrumbs</label>
9
+ <frontend_type>text</frontend_type>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <sort_order>1000</sort_order>
14
+ <fields>
15
+ <skip_categories translate="label comment">
16
+ <label>Skip categories IDs</label>
17
+ <frontend_type>textarea</frontend_type>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ <comment>Please add categories IDs, that need skip when will build Product Breadcrumbs. Separator - comma</comment>
23
+ </skip_categories>
24
+ </fields>
25
+ </productbreadcrumbs>
26
+ </groups>
27
+ </catalog>
28
+ </sections>
29
+ </config>
app/code/local/Magefast/RemoveCrumbs/Block/Html/Breadcrumbs.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magefast_RemoveCrumbs_Block_Html_Breadcrumbs extends Mage_Page_Block_Html_Breadcrumbs
4
+ {
5
+ /**
6
+ * Remove breadcrumbs
7
+ *
8
+ * @param string $name
9
+ * @return $this
10
+ */
11
+ public function removeCrumbs($name = 'product')
12
+ {
13
+ unset($this->_crumbs[$name]);
14
+ return $this;
15
+ }
16
+
17
+ }
app/code/local/Magefast/RemoveCrumbs/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magefast_RemoveCrumbs_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Magefast/RemoveCrumbs/etc/config.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Magefast_RemoveCrumbs>
5
+ <version>1.0.0</version>
6
+ </Magefast_RemoveCrumbs>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <page>
11
+ <rewrite>
12
+ <html_breadcrumbs>Magefast_RemoveCrumbs_Block_Html_Breadcrumbs</html_breadcrumbs>
13
+ </rewrite>
14
+ </page>
15
+ </blocks>
16
+ <helpers>
17
+ <magefast_removecrumbs>
18
+ <class>Magefast_RemoveCrumbs_Helper</class>
19
+ </magefast_removecrumbs>
20
+ </helpers>
21
+ </global>
22
+ </config>
app/etc/modules/Magefast_ProductBreadcrumbs.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Magefast_ProductBreadcrumbs>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Magefast_ProductBreadcrumbs>
8
+ </modules>
9
+ </config>
app/etc/modules/Magefast_RemoveCrumbs.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Magefast_RemoveCrumbs>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Magefast_RemoveCrumbs>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Magefast_ProductBreadcrumbs</name>
4
+ <version>0.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>AFL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Breadcrumbs for Product page, with categories link</summary>
10
+ <description>Add breadcrumbs for Product page, if customers go to Product page by current link.&#xD;
11
+ Good for improve Google result page.</description>
12
+ <notes>First realise</notes>
13
+ <authors><author><name>Alex</name><user>alexhost</user><email>magento@magefast.com</email></author></authors>
14
+ <date>2015-05-03</date>
15
+ <time>20:53:52</time>
16
+ <contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Magefast"><dir name="ProductBreadcrumbs"><dir name="Helper"><file name="Data.php" hash="9733634caf0c2821a3421b2251c8c451"/></dir><dir name="Model"><file name="Observer.php" hash="ee22c9c3e7d758e57686b48027eb84d5"/></dir><dir name="etc"><file name="config.xml" hash="7af0ee4a3fe8b41b35cbe7487b2a85c0"/><file name="system.xml" hash="55b5246448b7c92e5c493bc9d76edf0f"/></dir></dir></dir></dir><dir name="local"><dir name="Magefast"><dir name="RemoveCrumbs"><dir name="Block"><dir name="Html"><file name="Breadcrumbs.php" hash="f2ac7bfd76bcccd9bb774bf971e0e911"/></dir></dir><dir name="Helper"><file name="Data.php" hash="4d7a688a276acd82309ed56a7f8e7584"/></dir><dir name="etc"><file name="config.xml" hash="3afcc96685c1a34584861135b763bc9e"/></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Magefast_RemoveCrumbs.xml" hash="9d65e88f7956ed10f31413863abab01a"/><file name="Magefast_ProductBreadcrumbs.xml" hash="d2eeb802b3e2d341c260d48d869d45f9"/></dir></dir></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>