Magefast_ProductBreadcrumbs - Version 1.0.1

Version Notes

Add localization uk_UA, ru_RU.
Small fix for Observer.

Download this release

Release Info

Developer Alex
Extension Magefast_ProductBreadcrumbs
Version 1.0.1
Comparing to
See all releases


Code changes from version 0.0.1 to 1.0.1

app/code/community/Magefast/ProductBreadcrumbs/Helper/Data.php CHANGED
@@ -3,6 +3,7 @@
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
 
3
  class Magefast_ProductBreadcrumbs_Helper_Data extends Mage_Core_Helper_Abstract
4
  {
5
  const XML_PATH_CATEGORY_URL_SUFFIX = 'catalog/productbreadcrumbs/skip_categories';
6
+ const CACHE_TAG = 'magefast_product_breadcrumbs';
7
 
8
  protected $_skipCategoryIDs = array();
9
 
app/code/community/Magefast/ProductBreadcrumbs/Model/Observer.php CHANGED
@@ -5,6 +5,16 @@ class Magefast_ProductBreadcrumbs_Model_Observer
5
  protected $_categoriesLevel4 = null;
6
 
7
 
 
 
 
 
 
 
 
 
 
 
8
  public function updateBreadcrumbs($observer)
9
  {
10
  $layout = $observer->getLayout();
@@ -36,92 +46,71 @@ class Magefast_ProductBreadcrumbs_Model_Observer
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
  }
@@ -139,13 +128,22 @@ class Magefast_ProductBreadcrumbs_Model_Observer
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();
@@ -157,4 +155,48 @@ class Magefast_ProductBreadcrumbs_Model_Observer
157
  return $categoryArray;
158
  }
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  }
5
  protected $_categoriesLevel4 = null;
6
 
7
 
8
+ public function refreshCache($observer)
9
+ {
10
+ // $tags = $observer->getEvent()->getData('tags');
11
+ //
12
+ // if (is_array($tags) && count($tags) == 0) {
13
+ // Mage::app()->getCache()->clean('all', array(Magefast_ProductBreadcrumbs_Helper_Data::CACHE_TAG));
14
+ // }
15
+ }
16
+
17
+
18
  public function updateBreadcrumbs($observer)
19
  {
20
  $layout = $observer->getLayout();
46
 
47
 
48
  if ($catIds = $currentProduct->getCategoryIds()) {
 
49
  if (is_array($catIds) && count($catIds) > 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
+ $cacheId = 'magefast_product_breadcrumbs_' . $currentProduct->getId() . '_' . Mage::app()->getStore()->getId();
52
+ if (false !== ($data = Mage::app()->getCache()->load($cacheId))) {
53
+ $breadcrumbs = unserialize($data);
54
+ } else {
55
+ $breadcrumbs = $this->_getDataForNewBreadcrumbs($catIds);
56
+ Mage::app()->getCache()->save(
57
+ serialize($breadcrumbs),
58
+ $cacheId,
 
 
 
59
  array(
60
+ Mage_Core_Block_Abstract::CACHE_GROUP,
61
+ Mage_Core_Model_Store::CACHE_TAG,
62
+ Mage_Catalog_Model_Product::CACHE_TAG,
63
+ Mage_Catalog_Model_Category::CACHE_TAG,
64
+ Magefast_ProductBreadcrumbs_Helper_Data::CACHE_TAG
65
+ ),
66
+ 999999
67
  );
68
+ }
69
 
70
+ //$breadcrumbs = $this->_getDataForNewBreadcrumbs($catIds);
71
+
72
+ if (isset($breadcrumbs) && count($breadcrumbs) > 0) {
73
+ if ($breadcrumbs_block = $layout->getBlock('breadcrumbs')) {
74
+
75
+ /**
76
+ * Remove crumb for Product
77
+ */
78
+ $breadcrumbs_block->removeCrumbs('product');
79
+
80
+ /**
81
+ * Add new crumbs,
82
+ * for Homepage
83
+ */
84
+ $breadcrumbs_block->addCrumb(
85
+ 'home',
86
+ array(
87
+ 'label' => Mage::helper('cms')->__('Home'),
88
+ 'title' => Mage::helper('cms')->__('Go to Home Page'),
89
+ 'link' => Mage::getBaseUrl()
90
+ )
91
+ );
92
+
93
+ /**
94
+ * For categories, where include product
95
+ */
96
+ foreach ($breadcrumbs as $b) {
97
+ $breadcrumbs_block->addCrumb('category' . $b['category'], array(
98
+ 'label' => $b['name'],
99
+ 'title' => $b['name'],
100
+ 'link' => $b['url'],
101
+ 'first' => true,
102
+ ));
103
+ }
104
+
105
+ /**
106
+ * And for current product
107
+ */
108
+ $breadcrumbs_block->addCrumb('product', array(
109
+ 'label' => $currentProduct->getName(),
110
+ 'readonly' => false,
111
+ 'last' => true
112
  ));
113
  }
 
 
 
 
 
 
 
 
 
114
  }
115
  }
116
  }
128
  {
129
  $skipCategoryIDsArray = Mage::helper('magefast_productbreadcrumbs')->getSkipCategoryIDs();
130
 
131
+ $storeId = Mage::app()->getStore()->getId();
132
+ $rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
133
+ $rootCategoryPath = Mage::getModel('catalog/category')->load($rootCategoryId)->getPath();
134
+
135
  $categoriesArray = Mage::getModel('catalog/category')
136
+ ->setStoreId($storeId)
137
  ->getCollection()
138
+ ->addAttributeToSelect('name')
139
+ ->addAttributeToSelect('path')
140
+ ->addAttributeToSelect('is_active')
141
+ ->addAttributeToFilter('is_active', array('in' => array(1)))
142
+ ->addAttributeToFilter('path', array("like" => $rootCategoryPath . "/" . "%"));;
143
 
144
  $categoryArray = array();
145
  foreach ($categoriesArray as $category) {
146
+ if (isset($skipCategoryIDsArray[$category->getId()]) && $skipCategoryIDsArray[$category->getId()]) {
147
  continue;
148
  }
149
  $categoryData = $category->getData();
155
  return $categoryArray;
156
  }
157
 
158
+ protected function _getDataForNewBreadcrumbs($catIds)
159
+ {
160
+ $breadcrumbs = array();
161
+ $categories = $this->_getCategoriesArray();
162
+
163
+ foreach ($catIds as $c) {
164
+ if (isset($skipCategoryIDsArray[$c])) {
165
+ continue;
166
+ }
167
+ if (isset($categories[$c]) && $categories[$c]['level'] == 4) {
168
+ $productCategory = $categories[$c];
169
+ break;
170
+ }
171
+
172
+ if (isset($categories[$c]) && $categories[$c]['level'] == 3) {
173
+ $productCategory = $categories[$c];
174
+ break;
175
+ }
176
+
177
+ if (isset($categories[$c]) && $categories[$c]['level'] == 2) {
178
+ $productCategory = $categories[$c];
179
+ break;
180
+ }
181
+ }
182
+
183
+ if (!isset($productCategory)) {
184
+ return $breadcrumbs;
185
+ }
186
+
187
+ $path = $productCategory['path'];
188
+ $pathCategories = explode('/', $path);
189
+ $rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
190
+
191
+ foreach ($pathCategories as $pc) {
192
+ if ($pc == 1 || $pc == intval($rootCategoryId)) {
193
+ continue;
194
+ }
195
+ $breadcrumbs[$pc]['name'] = $categories[$pc]['name'];
196
+ $breadcrumbs[$pc]['url'] = $categories[$pc]['url'];
197
+ $breadcrumbs[$pc]['category'] = $pc;
198
+ }
199
+
200
+ return $breadcrumbs;
201
+ }
202
  }
app/code/community/Magefast/ProductBreadcrumbs/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Magefast_ProductBreadcrumbs>
5
- <version>0.0.1</version>
6
  </Magefast_ProductBreadcrumbs>
7
  </modules>
8
  <global>
@@ -11,6 +11,17 @@
11
  <class>Magefast_ProductBreadcrumbs_Helper</class>
12
  </magefast_productbreadcrumbs>
13
  </helpers>
 
 
 
 
 
 
 
 
 
 
 
14
  </global>
15
  <frontend>
16
  <events>
@@ -25,4 +36,15 @@
25
  </controller_action_layout_generate_blocks_after>
26
  </events>
27
  </frontend>
 
 
 
 
 
 
 
 
 
 
 
28
  </config>
2
  <config>
3
  <modules>
4
  <Magefast_ProductBreadcrumbs>
5
+ <version>1.0.1</version>
6
  </Magefast_ProductBreadcrumbs>
7
  </modules>
8
  <global>
11
  <class>Magefast_ProductBreadcrumbs_Helper</class>
12
  </magefast_productbreadcrumbs>
13
  </helpers>
14
+ <!--<events>-->
15
+ <!--<application_clean_cache>-->
16
+ <!--<observers>-->
17
+ <!--<magefast_productbreadcrumbs_observer_cache>-->
18
+ <!--<type>singleton</type>-->
19
+ <!--<class>Magefast_ProductBreadcrumbs_Model_Observer</class>-->
20
+ <!--<method>refreshCache</method>-->
21
+ <!--</magefast_productbreadcrumbs_observer_cache>-->
22
+ <!--</observers>-->
23
+ <!--</application_clean_cache>-->
24
+ <!--</events>-->
25
  </global>
26
  <frontend>
27
  <events>
36
  </controller_action_layout_generate_blocks_after>
37
  </events>
38
  </frontend>
39
+ <adminhtml>
40
+ <translate>
41
+ <modules>
42
+ <Magefast_ProductBreadcrumbs>
43
+ <files>
44
+ <default>Magefast_ProductBreadcrumbs.csv</default>
45
+ </files>
46
+ </Magefast_ProductBreadcrumbs>
47
+ </modules>
48
+ </translate>
49
+ </adminhtml>
50
  </config>
app/locale/ru_RU/Magefast_ProductBreadcrumbs.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ "Product Breadcrumbs","Хлебные крошки для Товаров"
2
+ "Skip categories IDs","Не применять для категорий товаров с ID"
3
+ "Please add categories IDs, that need skip when will build Product Breadcrumbs. Separator - comma","Добавьте ID категорий, для которых не применять Хлебные крошки для Товаров. Разделитель - запятая"
app/locale/uk_UA/Magefast_ProductBreadcrumbs.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ "Product Breadcrumbs","Хлібні крихти для Товарів"
2
+ "Skip categories IDs","Не застосовувати для категорій товарів з ID"
3
+ "Please add categories IDs, that need skip when will build Product Breadcrumbs. Separator - comma","Додайте ID категорій, для яких не застосовувати Хлібні крихти для Товарів. Символ роздільника елементів списку - кома"
package.xml CHANGED
@@ -1,19 +1,21 @@
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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Magefast_ProductBreadcrumbs</name>
4
+ <version>1.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.&amp;#xD;&#xD;
11
  Good for improve Google result page.</description>
12
+ <notes>Add localization uk_UA, ru_RU.&#xD;
13
+ Small fix for Observer.&#xD;
14
+ </notes>
15
  <authors><author><name>Alex</name><user>alexhost</user><email>magento@magefast.com</email></author></authors>
16
+ <date>2015-06-03</date>
17
+ <time>19:53:01</time>
18
+ <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="10df491f7cb0244637c15bebd59be9c0"/></dir><dir name="Model"><file name="Observer.php" hash="86d916ac57e13cf5b3d8fee4a08c42db"/></dir><dir name="etc"><file name="config.xml" hash="7be5f5a238648c1c5a63db697e790ac0"/><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_ProductBreadcrumbs.xml" hash="d2eeb802b3e2d341c260d48d869d45f9"/><file name="Magefast_RemoveCrumbs.xml" hash="9d65e88f7956ed10f31413863abab01a"/></dir></dir><dir name="locale"><dir name="uk_UA"><file name="Magefast_ProductBreadcrumbs.csv" hash="8e0a05e802cac514ef6bd989b702bf24"/></dir><dir name="ru_RU"><file name="Magefast_ProductBreadcrumbs.csv" hash="b7afd0f0b9f9434eceb828bd5e38c9f0"/></dir></dir></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
21
  </package>