Buscape_Sitemap - Version 0.1.4

Version Notes

Melhoria em performance

Download this release

Release Info

Developer Magento Core Team
Extension Buscape_Sitemap
Version 0.1.4
Comparing to
See all releases


Code changes from version 0.1.3 to 0.1.4

app/code/community/Buscape/Sitemap/Model/Sitemap.php CHANGED
@@ -117,27 +117,6 @@ class Buscape_Sitemap_Model_Sitemap extends Mage_Sitemap_Model_Sitemap
117
 
118
  public function xmlBuscape()
119
  {
120
- $io = new Varien_Io_File();
121
-
122
- $io->setAllowCreateFolders(true);
123
-
124
- $io->open(array('path' => $this->getData('path')));
125
-
126
- if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
127
- Mage::throwException(Mage::helper('buscapemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
128
- }
129
-
130
- if($io->fileExists($this->getSitemapFilename()))
131
- {
132
- $io->rm($this->getSitemapFilename());
133
- }
134
-
135
- $io->streamOpen($this->getSitemapFilename());
136
-
137
- $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>');
138
-
139
- $io->streamWrite("\n<sitemap>\n");
140
-
141
  $storeId = $this->getStoreId();
142
 
143
  $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
@@ -145,15 +124,70 @@ class Buscape_Sitemap_Model_Sitemap extends Mage_Sitemap_Model_Sitemap
145
  /**
146
  * Generate products sitemap
147
  */
148
- $collection = Mage::getModel('catalog/product')
149
- ->setStoreId($storeId)
150
- ->getCollection();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
  foreach($collection as $item) {
153
 
154
- $product = Mage::getModel("catalog/product")->load($item->getId());
155
 
156
- $template = <<<EOT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  <produto>
158
  <descricao>%s</descricao>
159
  <preco>%s</preco>
@@ -166,28 +200,14 @@ class Buscape_Sitemap_Model_Sitemap extends Mage_Sitemap_Model_Sitemap
166
  <id_filial>%s</id_filial>
167
  </produto>
168
  EOT;
169
-
170
- try {
171
-
172
- $category_filter = Mage::getModel('catalog/category')
173
- ->getCollection()
174
- ->addFieldToFilter('entity_id', array('in' => implode(",", $product->getCategoryIds())))
175
- ->getFirstItem();
176
-
177
- $category = Mage::getModel('catalog/category')->load($category_filter->getId());
178
-
179
- $category_name = str_replace('"', '', $category->getName());
180
-
181
- $category_name = str_replace('\'', '', $category_name);
182
-
183
  $xml = sprintf($template,
184
  str_replace("&", " ", $product->getName()),
185
  str_replace(".", ",", Mage::helper('checkout')->convertPrice($product->getFinalPrice(), false)),
186
  $product->getId(),
187
  $product->getSku(),
188
  $product->getProductUrl(),
189
- $product->getImageUrl(),
190
- $category_name,
191
  intval($product->getStockItem()->getQty()),
192
  $this->_getConfig()->getAccount()
193
  );
@@ -196,18 +216,47 @@ EOT;
196
 
197
  $io->streamWrite($xml);
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  } catch(Exception $e) {
200
 
 
 
 
 
201
  continue;
202
  }
203
  }
204
 
205
  unset($collection);
206
 
207
- $io->streamWrite("</sitemap>");
208
 
209
- $io->streamClose();
 
 
 
 
210
 
 
 
 
 
 
 
 
211
  $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
212
 
213
  $this->save();
117
 
118
  public function xmlBuscape()
119
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  $storeId = $this->getStoreId();
121
 
122
  $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
124
  /**
125
  * Generate products sitemap
126
  */
127
+ $store = Mage::app()->getStore();
128
+
129
+ $collection = Mage::getModel('catalog/product')
130
+ ->getCollection()
131
+ ->addAttributeToSelect('name')
132
+ ->addAttributeToSelect('image')
133
+ ->addAttributeToSelect('sku')
134
+ ->addAttributeToFilter('type_id',
135
+ array('in' =>
136
+ array(
137
+ Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
138
+ Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL,
139
+ )));
140
+ /*
141
+ $collection = Mage::getModel('catalog/product')->getCollection()
142
+ ->joinField('category_id', 'catalog_category_product', 'category_id', 'product_id=entity_id', null, 'inner')
143
+ ->joinField('category_path', 'catalog_category_entity', 'path', 'entity_id=category_id', null, 'inner')
144
+ ->groupByAttribute('entity_id');*/
145
+
146
+ $i = 1;
147
+
148
+ $files = 1;
149
+
150
+ $lines = 2000;
151
+
152
+ $size = $collection->count();
153
 
154
  foreach($collection as $item) {
155
 
156
+ try {
157
 
158
+ if($i == 1) {
159
+
160
+ $io = new Varien_Io_File();
161
+
162
+ $io->setAllowCreateFolders(true);
163
+
164
+ $io->open(array('path' => $this->getData('path')));
165
+
166
+ //$filename = str_replace(".xml", "{$files}.xml", $this->getSitemapFilename());
167
+
168
+ $filename = $this->getSitemapFilename();
169
+
170
+ $this->setSitemapFilename($filename);
171
+
172
+ if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
173
+ Mage::throwException(Mage::helper('buscapemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
174
+ }
175
+
176
+ if($io->fileExists($this->getSitemapFilename()))
177
+ {
178
+ $io->rm($this->getSitemapFilename());
179
+ }
180
+
181
+ $io->streamOpen($filename);
182
+
183
+ $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>');
184
+
185
+ $io->streamWrite("\n<sitemap>\n");
186
+ }
187
+
188
+ $product = Mage::getModel("catalog/product")->load($item->getId());
189
+
190
+ $template = <<<EOT
191
  <produto>
192
  <descricao>%s</descricao>
193
  <preco>%s</preco>
200
  <id_filial>%s</id_filial>
201
  </produto>
202
  EOT;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  $xml = sprintf($template,
204
  str_replace("&", " ", $product->getName()),
205
  str_replace(".", ",", Mage::helper('checkout')->convertPrice($product->getFinalPrice(), false)),
206
  $product->getId(),
207
  $product->getSku(),
208
  $product->getProductUrl(),
209
+ '',//($io->fileExists($product->getImageUrl())) ? $product->getImageUrl() : '',
210
+ str_replace("/", ":", $product->getCategoryCollection()->getFirstItem()->getPath()),
211
  intval($product->getStockItem()->getQty()),
212
  $this->_getConfig()->getAccount()
213
  );
216
 
217
  $io->streamWrite($xml);
218
 
219
+ //if ($lines == $i || $size == $i) {
220
+ if ($size == $i) {
221
+
222
+ $io->streamWrite("\n</sitemap>\n");
223
+
224
+ $io->streamClose();
225
+
226
+ $i = 1;
227
+
228
+ $files++;
229
+ }
230
+
231
+ $i++;
232
+
233
  } catch(Exception $e) {
234
 
235
+ $size--;
236
+
237
+ Mage::logException($e);
238
+
239
  continue;
240
  }
241
  }
242
 
243
  unset($collection);
244
 
245
+ // verifica a quantidade de arquivos, caso tenham mais de 1 xml, deve ser criado o HTML e declarado o caminho do(s) xml nele.
246
 
247
+ /*
248
+ * $io = new Varien_Io_File();
249
+ * $io->setAllowCreateFolders(true);
250
+ * $io->open(array('path' => $this->getData('path')));
251
+ * $filename = str_replace(".xml", "{$files}.xml", $this->getSitemapFilename());
252
 
253
+ foreach($listxml as $files)
254
+ {
255
+ $io->streamWrite('<a href="'.$files.'">'.$files.'</a><br />');
256
+ }
257
+
258
+ $io->streamClose();*/
259
+
260
  $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
261
 
262
  $this->save();
package.xml CHANGED
@@ -1,18 +1,27 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Buscape_Sitemap</name>
4
- <version>0.1.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Extens&#xE3;o Buscap&#xE9; Sitemap para Magento</summary>
10
- <description>Permite que voc&#xEA; crie sitemap para utilizar na central de neg&#xF3;cios, inclu&#xED;ndo seus produtos e servi&#xE7;os em ofertas no Buscap&#xE9;.com e Bondfaro.com</description>
11
- <notes>Extens&#xE3;o Buscap&#xE9; Sitemap para Magento CE 1.4+, PE 1.9+ e EE 1.7+.</notes>
12
- <authors><author><name>BuscaP&#xE9; Developer</name><user>auto-converted</user><email>suporte.developer@buscape-inc.com</email></author></authors>
13
- <date>2012-03-27</date>
14
- <time>13:37:39</time>
15
- <contents><target name="mageetc"><dir name="modules"><file name="Buscape_Sitemap.xml" hash="e49a3a6d37df6cd56928f2ba4d517559"/></dir></target><target name="magecommunity"><dir name="Buscape"><dir name="Sitemap"><dir name="Block"><dir name="Admin"><dir name="Edit"><file name="Form.php" hash="4eabebc5239ba40ef9d7ed01b87338de"/></dir><dir name="Grid"><dir name="Renderer"><file name="Link.php" hash="c3fc7d89a673e8eba245240eeca1eba0"/></dir></dir><dir name="Main"><file name="Grid.php" hash="a1708e4296c4963f920d4218b7009e0e"/></dir><dir name="New"><file name="Form.php" hash="98e92a67cd4fbd3d7a4e65704f542f2e"/></dir><file name="Edit.php" hash="fe15ceb6569bcdcd99a08d53599aaca9"/><file name="Main.php" hash="a6c4688b7cbe3a5d2fd18733e9f1a56e"/><file name="New.php" hash="74afbf19d3a6bdb83cf345de916a0242"/></dir></dir><dir name="Helper"><file name="Data.php" hash="fe038765e31661ba27cf8784a1559d6b"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Sitemap"><file name="Collection.php" hash="28c00c86c4fe5aa87325643a5255b32a"/></dir><file name="Sitemap.php" hash="c78328a3a52da29e242b00822935a615"/></dir><file name="Config.php" hash="4386e1c98918d5a114b7a9d31afea296"/><file name="Observer.php" hash="ff2c01550acf78584d6ab56bfbf9b579"/><file name="Sitemap.php" hash="bbffd318b21398da70dbf2d2abcbc5a6"/></dir><dir name="controllers"><file name="AdminController.php" hash="c1efb71e16840a721f775f4fb480405d"/></dir><dir name="etc"><file name="config.xml" hash="454a1b3168caf55dc84f90e9d4455d97"/><file name="system.xml" hash="11d6d0609d435447bf1f2c5229f78158"/></dir><dir name="sql"><dir name="buscapemap_setup"><file name="mysql4-install-0.1.0.php" hash="915a5dc3b7a2ba4d5c634db00780303c"/></dir></dir></dir></dir></target></contents>
 
 
 
 
 
 
 
 
 
16
  <compatible/>
17
  <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Buscape_Sitemap</name>
4
+ <version>0.1.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Buscap&#xE9; Sitemap extension for Magento</summary>
10
+ <description>&lt;p&gt;Buscap&#xE9; Sitemap extension for Magento generates a XML file containing all product offers of your store so they can be shown in Buscap&#xE9; comparison shopping.&lt;/p&gt;&#xD;
11
+ &#xD;
12
+ &lt;p&gt;For support, contacts us: &lt;a href="mailto:suporte.developer@buscapecompany.com"&gt;suporte.developer@buscapecompany.com&lt;/a&gt;&lt;/p&gt;&#xD;
13
+ &#xD;
14
+ &#xD;
15
+ *&#xD;
16
+ &#xD;
17
+ &lt;p&gt; A extens&#xE3;o Buscap&#xE9; Sitemap para Magento cria um arquivo XML com todas as ofertas de sua loja virtual para que elas possam ser exibidas no comparador de pre&#xE7;os Buscap&#xE9;.&lt;/p&gt;&#xD;
18
+ &#xD;
19
+ &lt;p&gt;Para suporte, envie um e-mail para: &lt;a href="mailto:suporte.developer@buscapecompany.com"&gt;suporte.developer@buscapecompany.com&lt;/a&gt;&lt;/p&gt;</description>
20
+ <notes>Melhoria em performance</notes>
21
+ <authors><author><name>Buscap&#xE9; Developer</name><user>auto-converted</user><email>suporte.developer@buscape-inc.com</email></author></authors>
22
+ <date>2013-08-08</date>
23
+ <time>14:30:34</time>
24
+ <contents><target name="mageetc"><dir name="modules"><file name="Buscape_Sitemap.xml" hash="e49a3a6d37df6cd56928f2ba4d517559"/></dir></target><target name="magecommunity"><dir name="Buscape"><dir name="Sitemap"><dir name="Block"><dir name="Admin"><dir name="Edit"><file name="Form.php" hash="4eabebc5239ba40ef9d7ed01b87338de"/></dir><dir name="Grid"><dir name="Renderer"><file name="Link.php" hash="c3fc7d89a673e8eba245240eeca1eba0"/></dir></dir><dir name="Main"><file name="Grid.php" hash="a1708e4296c4963f920d4218b7009e0e"/></dir><dir name="New"><file name="Form.php" hash="98e92a67cd4fbd3d7a4e65704f542f2e"/></dir><file name="Edit.php" hash="fe15ceb6569bcdcd99a08d53599aaca9"/><file name="Main.php" hash="a6c4688b7cbe3a5d2fd18733e9f1a56e"/><file name="New.php" hash="74afbf19d3a6bdb83cf345de916a0242"/></dir></dir><dir name="Helper"><file name="Data.php" hash="fe038765e31661ba27cf8784a1559d6b"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Sitemap"><file name="Collection.php" hash="28c00c86c4fe5aa87325643a5255b32a"/></dir><file name="Sitemap.php" hash="c78328a3a52da29e242b00822935a615"/></dir><file name="Config.php" hash="4386e1c98918d5a114b7a9d31afea296"/><file name="Observer.php" hash="ff2c01550acf78584d6ab56bfbf9b579"/><file name="Sitemap.php" hash="06cc53d315489baa2d5004b7103408fb"/></dir><dir name="controllers"><file name="AdminController.php" hash="c1efb71e16840a721f775f4fb480405d"/></dir><dir name="etc"><file name="config.xml" hash="454a1b3168caf55dc84f90e9d4455d97"/><file name="system.xml" hash="11d6d0609d435447bf1f2c5229f78158"/></dir><dir name="sql"><dir name="buscapemap_setup"><file name="mysql4-install-0.1.0.php" hash="915a5dc3b7a2ba4d5c634db00780303c"/></dir></dir></dir></dir></target></contents>
25
  <compatible/>
26
  <dependencies/>
27
  </package>