2f0ed0fddbc299a929e59604a51b5159 - Version 1.0.4

Version Notes

Added multistore support

Download this release

Release Info

Developer Marcin Klauza
Extension 2f0ed0fddbc299a929e59604a51b5159
Version 1.0.4
Comparing to
See all releases


Code changes from version 1.0.3 to 1.0.4

app/code/community/Mklauza/CustomProductUrls/Block/Adminhtml/Form/Abstract.php CHANGED
@@ -37,7 +37,8 @@ abstract class Mklauza_CustomProductUrls_Block_Adminhtml_Form_Abstract extends M
37
  public abstract function getSubmitUrl();
38
 
39
  public function getExampleUrl() {
40
- return Mage::helper('adminhtml')->getUrl('adminhtml/ProductUrls/example');
 
41
  }
42
 
43
  protected function getPatternObject() {
37
  public abstract function getSubmitUrl();
38
 
39
  public function getExampleUrl() {
40
+ $storeId = Mage::app()->getRequest()->getParam('store', 0);
41
+ return Mage::helper('adminhtml')->getUrl('adminhtml/ProductUrls/example', array('store' => $storeId));
42
  }
43
 
44
  protected function getPatternObject() {
app/code/community/Mklauza/CustomProductUrls/Block/Adminhtml/Form/Massaction.php CHANGED
@@ -28,7 +28,8 @@ class Mklauza_CustomProductUrls_Block_Adminhtml_Form_Massaction extends Mklauza_
28
  }
29
 
30
  public function getSubmitUrl() {
31
- return Mage::helper('adminhtml')->getUrl('adminhtml/ProductUrlsMassAction/save');
 
32
  }
33
 
34
  public function getSaveRewritesHistory() {
28
  }
29
 
30
  public function getSubmitUrl() {
31
+ $storeId = Mage::app()->getRequest()->getParam('store', 0);
32
+ return Mage::helper('adminhtml')->getUrl('adminhtml/ProductUrlsMassAction/save', array('store' => $storeId));
33
  }
34
 
35
  public function getSaveRewritesHistory() {
app/code/community/Mklauza/CustomProductUrls/Helper/Data.php CHANGED
@@ -22,146 +22,20 @@
22
 
23
  class Mklauza_CustomProductUrls_Helper_Data extends Mage_Core_Helper_Abstract {
24
 
25
- // private $_attributesCollection;
26
- // private $_productAttributes;
27
- // private $_patternChunks;
28
 
29
  public function getIsEnabled() {
30
- return Mage::getStoreConfigFlag('mklauza_customproducturls/general/is_active');
31
  }
32
 
33
  public function getApplyToNewFlag() {
34
- return Mage::getStoreConfigFlag('mklauza_customproducturls/general/apply_to_new');
35
  }
36
 
37
  public function getConfigPattern() {
38
- return Mage::getStoreConfig('mklauza_customproducturls/general/pattern');
39
- }
40
-
41
- // public function getAttributesCollection() {
42
- // if($this->_attributesCollection === null) {
43
- // $this->_attributesCollection = Mage::getResourceModel('catalog/product_attribute_collection')
44
- // ->addVisibleFilter('is_visible_on_front', array('=' => '1'))
45
- // ->addFieldTofilter('attribute_code', array('neq' => 'url_key'));
46
- // }
47
- // return $this->_attributesCollection;
48
- // }
49
- //
50
- // public function getProductAttributes() {
51
- // if($this->_productAttributes === null) {
52
- //
53
- // $attributes = array();
54
- // foreach ($this->getAttributesCollection() as $productAttr) { /** @var Mage_Catalog_Model_Resource_Eav_Attribute $productAttr */
55
- // $attributes[$productAttr->getAttributeCode()] = $this->jsQuoteEscape($productAttr->getFrontendLabel());
56
- // }
57
- // $this->_productAttributes = $attributes;
58
- // }
59
- // return $this->_productAttributes;
60
- // }
61
- //
62
- // public function extractChunks($urlPattern = '') {
63
- // $regex = '/(\{(\w+)\})?([^\{\}]+)?/';
64
- //
65
- // $chunks = array();
66
- // $doesMatch = true;
67
- // while(strlen($urlPattern) && $doesMatch)
68
- // {
69
- // $matches = array();
70
- // $doesMatch = preg_match($regex, $urlPattern, $matches);
71
- // if(!empty($matches[2])) {
72
- // $chunks[] = array('value' => $matches[2], 'type' => 'attribute');
73
- // }
74
- // if(!empty($matches[3])) {
75
- // $chunks[] = array('value' => $matches[3], 'type' => 'text');
76
- // }
77
- //
78
- // $urlPattern = str_replace($matches[0], '', $urlPattern);
79
- // }
80
- //
81
- // return $chunks;
82
- // }
83
- //
84
- // public function getPatternChunks($urlPattern) {
85
- // if($this->_patternChunks === null) {
86
- // $this->_patternChunks = $this->extractChunks($urlPattern);
87
- // }
88
- // return $this->_patternChunks;
89
- // }
90
- //
91
- // private function _getPatternAttributes() {
92
- // $chunks = $this->getPatternChunks();
93
- // foreach($chunks as $chunk) {
94
- // if($chunk['type'] === 'attribute') {
95
- // $attributes[] = $chunk['value'];
96
- // }
97
- // }
98
- // $attributes = array_flip($attributes);
99
- // foreach($attributes as $_code => $val) {
100
- // $attribute = Mage::getSingleton('eav/config')
101
- // ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $_code);
102
- // if ($attribute->usesSource()) {
103
- // $htmlOptions = $attribute->getSource()->getAllOptions(false);
104
- // if($htmlOptions && is_array($htmlOptions) && count($htmlOptions))
105
- // {
106
- // $options = array();
107
- // foreach($htmlOptions as $option) {
108
- // $options[$option['value']] = $option['label'];
109
- // }
110
- // $attributes[$_code]= $options;
111
- // }
112
- // }
113
- // }
114
- // return $attributes;
115
- // }
116
- //
117
- // public function prepareUrlKey($productId, $urlPattern, $storeId) {
118
- // $chunks = $this->getPatternChunks($urlPattern);
119
- // $patternAttributes = $this->_getPatternAttributes();
120
- //
121
- // foreach($patternAttributes as $code => &$value) {
122
- // $rawValue = Mage::getModel('catalog/product')->getResource()->getAttributeRawValue($productId, $code, $storeId);
123
- // // options
124
- // if(is_array($value)) {
125
- // $textOption = $value[$rawValue];
126
- // $value = $textOption;
127
- // } elseif($code === 'price') {
128
- // $value = number_format($rawValue, 2);
129
- // } else {
130
- // $value = $rawValue;
131
- // }
132
- // }
133
- //
134
- // $url_str = '';
135
- // foreach($chunks as $chunk) {
136
- // if($chunk['type'] === 'attribute') {
137
- // $attrCode = $chunk['value'];
138
- // $url_str .= $patternAttributes[$attrCode];
139
- // } elseif($chunk['type'] === 'text') {
140
- // $url_str .= $chunk['value'];
141
- // }
142
- // }
143
- //
144
- // return $url_str;
145
- // }
146
- //
147
- // public function getRandomExample($pattern) {
148
- // $storeId = Mage::app()->getStore()->getStoreId();
149
- ////// @test
150
- ////$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')->getProfiler();
151
- ////$profiler->setEnabled(true);
152
- // // get random product Id
153
- // $collection = Mage::getResourceModel('catalog/product_collection')
154
- // ->addStoreFilter($storeId)
155
- // ->addFieldToFilter('visibility', array('neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE));
156
- // $collection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns('entity_id')->order(new Zend_Db_Expr('RAND()'))->limit(1);
157
- // $productId = $collection->getFirstItem()->getId();
158
- ////// @test
159
- ////Mage::log(print_r($profiler->getQueryProfiles(), true), null, 'example.log', true);
160
- ////Mage::log(array($profiler->getTotalNumQueries(), $profiler->getTotalElapsedSecs()), null, 'example.log', true);
161
- ////$profiler->setEnabled(false);
162
- // $url_key = $this->prepareUrlKey($productId, $pattern, $storeId);
163
- // $url_key = Mage::getModel('catalog/product_url')->formatUrlKey($url_key);
164
- // return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . $url_key . Mage::getStoreConfig('catalog/seo/product_url_suffix');
165
- // }
166
 
167
  }
22
 
23
  class Mklauza_CustomProductUrls_Helper_Data extends Mage_Core_Helper_Abstract {
24
 
25
+ public function getStoreId() {
26
+ return Mage::app()->getRequest()->getParam('store', null);
27
+ }
28
 
29
  public function getIsEnabled() {
30
+ return Mage::getStoreConfigFlag('mklauza_customproducturls/general/is_active', $this->getStoreId());
31
  }
32
 
33
  public function getApplyToNewFlag() {
34
+ return Mage::getStoreConfigFlag('mklauza_customproducturls/general/apply_to_new', $this->getStoreId());
35
  }
36
 
37
  public function getConfigPattern() {
38
+ return Mage::getStoreConfig('mklauza_customproducturls/general/pattern', $this->getStoreId());
39
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  }
app/code/community/Mklauza/CustomProductUrls/Model/Adminhtml/Observer.php CHANGED
@@ -30,9 +30,10 @@ class Mklauza_CustomProductUrls_Model_Adminhtml_Observer {
30
  $block->getMassactionBlock()->setFormFieldName('product');
31
  // $block->getMassactionBlock()->setUseSelectAll(false);
32
 
 
33
  $block->getMassactionBlock()->addItem('mklauza_customproducturls', array(
34
  'label' => 'Set custom URL',
35
- 'url' => $block->getUrl('*/productUrlsMassAction/edit'),
36
  ));
37
 
38
  return $this;
@@ -53,9 +54,7 @@ class Mklauza_CustomProductUrls_Model_Adminhtml_Observer {
53
  public function generateUrlKey(Varien_Event_Observer $observer) { // catalog_product_save_after
54
  $product = $observer->getEvent()->getProduct();
55
 
56
- if(Mage::registry('generate_url') && $product->getId()) { // in case we save product with empty url key
57
- // && !($product->getTypeId() == 'simple' && $product->getAttributeSetId() == $this->getAttributeSetId('prenumerata'))
58
-
59
  $urlPattern = Mage::helper('mklauza_customproducturls')->getConfigPattern();
60
  $storeId = Mage::app()->getStore()->getId();
61
 
30
  $block->getMassactionBlock()->setFormFieldName('product');
31
  // $block->getMassactionBlock()->setUseSelectAll(false);
32
 
33
+ $storeId = Mage::app()->getRequest()->getParam('store', 0);
34
  $block->getMassactionBlock()->addItem('mklauza_customproducturls', array(
35
  'label' => 'Set custom URL',
36
+ 'url' => $block->getUrl('*/productUrlsMassAction/edit', array('store' => $storeId)),
37
  ));
38
 
39
  return $this;
54
  public function generateUrlKey(Varien_Event_Observer $observer) { // catalog_product_save_after
55
  $product = $observer->getEvent()->getProduct();
56
 
57
+ if(Mage::registry('generate_url') && $product->getId()) { // in case we save product with empty url key
 
 
58
  $urlPattern = Mage::helper('mklauza_customproducturls')->getConfigPattern();
59
  $storeId = Mage::app()->getStore()->getId();
60
 
app/code/community/Mklauza/CustomProductUrls/controllers/Adminhtml/Catalog/Product/Action/ProductUrlsMassActionController.php CHANGED
@@ -25,7 +25,7 @@ class Mklauza_CustomProductUrls_Adminhtml_Catalog_Product_Action_ProductUrlsMass
25
  // @overridden
26
  public function preDispatch() {
27
  parent::preDispatch();
28
- if(!Mage::GetStoreConfigFlag('mklauza_customproducturls/general/is_active')) {
29
  $this->_redirect('adminhtml/dashboard');
30
  return;
31
  }
@@ -117,7 +117,7 @@ class Mklauza_CustomProductUrls_Adminhtml_Catalog_Product_Action_ProductUrlsMass
117
  //Mage::log(print_r($profiler->getQueryProfiles(), true), null, 'queries.log', true);
118
  //Mage::log(array($profiler->getTotalNumQueries(), $profiler->getTotalElapsedSecs()), null, 'queries.log', true);
119
  //$profiler->setEnabled(false);
120
- //die();
121
  $this->_redirect('*/catalog_product/', array('store'=>$this->_helper()->getSelectedStoreId()));
122
  }
123
 
25
  // @overridden
26
  public function preDispatch() {
27
  parent::preDispatch();
28
+ if(!Mage::helper('mklauza_customproducturls')->getIsEnabled()) {
29
  $this->_redirect('adminhtml/dashboard');
30
  return;
31
  }
117
  //Mage::log(print_r($profiler->getQueryProfiles(), true), null, 'queries.log', true);
118
  //Mage::log(array($profiler->getTotalNumQueries(), $profiler->getTotalElapsedSecs()), null, 'queries.log', true);
119
  //$profiler->setEnabled(false);
120
+
121
  $this->_redirect('*/catalog_product/', array('store'=>$this->_helper()->getSelectedStoreId()));
122
  }
123
 
app/code/community/Mklauza/CustomProductUrls/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Mklauza_CustomProductUrls>
5
- <version>0.0.2</version>
6
  </Mklauza_CustomProductUrls>
7
  </modules>
8
 
2
  <config>
3
  <modules>
4
  <Mklauza_CustomProductUrls>
5
+ <version>0.0.4</version>
6
  </Mklauza_CustomProductUrls>
7
  </modules>
8
 
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>2f0ed0fddbc299a929e59604a51b5159</name>
4
- <version>1.0.3</version>
5
  <stability>stable</stability>
6
  <license>OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Create mass custom product urls.</summary>
10
  <description>Extension allowing to mass change product url key according to template consisting of product attributes.</description>
11
- <notes>notes</notes>
12
  <authors><author><name>Marcin Klauza</name><user>marcin</user><email>marcinklauza@gmail.com</email></author></authors>
13
- <date>2016-05-02</date>
14
- <time>11:40:18</time>
15
- <contents><target name="magecommunity"><dir><dir name="Mklauza"><dir name="CustomProductUrls"><dir name="Block"><dir name="Adminhtml"><dir name="Form"><file name="Abstract.php" hash="91974ad804d2d8df79d1917dbf846288"/><file name="Massaction.php" hash="32bb6193eea4b61a47ac589879b6a231"/><file name="Settings.php" hash="daeaa0ed5176e34677169b6f73f26f3e"/></dir><dir name="System"><dir name="Config"><dir name="Form"><file name="Pattern.php" hash="34dc42258f8d40b3d6adb64371e9d1f6"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="2c4bbf6096320edab9f21943277299e3"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Observer.php" hash="deecbfbedf51140a32f748102fc6e471"/></dir><dir name="Catalog"><dir name="Product"><file name="Url.php" hash="94a90ca37095d7b2cda703336474befe"/></dir><dir name="Resource"><dir name="Product"><file name="Action.php" hash="7fbb37b1529f1d9ae981a8edc58b352d"/></dir></dir></dir><file name="Pattern.php" hash="cba585ea2d11050aab3a6c8c5089d47e"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Action"><file name="ProductUrlsMassActionController.php" hash="9e5741fd9fff16b7c9791543ff99ad79"/></dir></dir></dir><file name="ProductUrlsController.php" hash="5fcb9eb4ab89f9c611837e37058e46fd"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="dad9c0dd1088595d6da2474e69ff7ce6"/><file name="config.xml" hash="16cc3389cbb18191a4f3e9a2e7d32a83"/><file name="system.xml" hash="bd5402bc4b30168d4aa67a91b94b11d3"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="mklauza"><file name="product_urls.xml" hash="972b7551a3fbcb7b8bc87aff5732c52c"/></dir></dir><dir name="template"><dir name="mklauza"><dir name="customproducturls"><file name="massaction.phtml" hash="f00d86e1cd3d5e310e76b64616d2be52"/><dir name="system"><file name="settings.phtml" hash="d2c9195d497cd76a4b0cc541b1165fa0"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Mklauza_CustomProductUrls.xml" hash="0f6d8d6a5dd2261fed9f49e853f68adf"/></dir></dir></target><target name="mage"><dir><dir name="js"><dir name="mklauza_customproducturls"><file name="jquery-1.11.2.min.js" hash="019c5fb7c4771808dc65e1096c771348"/><file name="jquery-ui.min.js" hash="7403b37e7918413f5a43131b95c86abb"/><file name="loadingdots.css" hash="b9f95df94e9f9384093edad63ae4cff1"/><file name="template.css" hash="c08f3bb77f768b2f728881626a486783"/><file name="template.js" hash="35e4143558041c04210c933120f75afc"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>2f0ed0fddbc299a929e59604a51b5159</name>
4
+ <version>1.0.4</version>
5
  <stability>stable</stability>
6
  <license>OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Create mass custom product urls.</summary>
10
  <description>Extension allowing to mass change product url key according to template consisting of product attributes.</description>
11
+ <notes>Added multistore support</notes>
12
  <authors><author><name>Marcin Klauza</name><user>marcin</user><email>marcinklauza@gmail.com</email></author></authors>
13
+ <date>2016-09-05</date>
14
+ <time>20:14:51</time>
15
+ <contents><target name="magecommunity"><dir><dir name="Mklauza"><dir name="CustomProductUrls"><dir name="Block"><dir name="Adminhtml"><dir name="Form"><file name="Abstract.php" hash="bab4fac7f108f5cbbb31f4bf090aa3d8"/><file name="Massaction.php" hash="a5409bd20ded3fa7efc64b432cc67499"/><file name="Settings.php" hash="daeaa0ed5176e34677169b6f73f26f3e"/></dir><dir name="System"><dir name="Config"><dir name="Form"><file name="Pattern.php" hash="34dc42258f8d40b3d6adb64371e9d1f6"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="1c02b0aaa35ee4e5fb9565760a083823"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Observer.php" hash="25a293717b2c5c546cde2e9617669d3b"/></dir><dir name="Catalog"><dir name="Product"><file name="Url.php" hash="94a90ca37095d7b2cda703336474befe"/></dir><dir name="Resource"><dir name="Product"><file name="Action.php" hash="7fbb37b1529f1d9ae981a8edc58b352d"/></dir></dir></dir><file name="Pattern.php" hash="cba585ea2d11050aab3a6c8c5089d47e"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Action"><file name="ProductUrlsMassActionController.php" hash="8b89c330f89a9d18cf06fac3255b358d"/></dir></dir></dir><file name="ProductUrlsController.php" hash="5fcb9eb4ab89f9c611837e37058e46fd"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="dad9c0dd1088595d6da2474e69ff7ce6"/><file name="config.xml" hash="5fca911010b15cacb9f0d813df82f8ec"/><file name="system.xml" hash="bd5402bc4b30168d4aa67a91b94b11d3"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="mklauza"><file name="product_urls.xml" hash="972b7551a3fbcb7b8bc87aff5732c52c"/></dir></dir><dir name="template"><dir name="mklauza"><dir name="customproducturls"><file name="massaction.phtml" hash="f00d86e1cd3d5e310e76b64616d2be52"/><dir name="system"><file name="settings.phtml" hash="d2c9195d497cd76a4b0cc541b1165fa0"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Mklauza_CustomProductUrls.xml" hash="0f6d8d6a5dd2261fed9f49e853f68adf"/></dir></dir></target><target name="mage"><dir><dir name="js"><dir name="mklauza_customproducturls"><file name="jquery-1.11.2.min.js" hash="019c5fb7c4771808dc65e1096c771348"/><file name="jquery-ui.min.js" hash="7403b37e7918413f5a43131b95c86abb"/><file name="loadingdots.css" hash="b9f95df94e9f9384093edad63ae4cff1"/><file name="template.css" hash="c08f3bb77f768b2f728881626a486783"/><file name="template.js" hash="35e4143558041c04210c933120f75afc"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>