Facebook_Ads_Toolbox - Version 2.1.16

Version Notes

Product Feed Improvements:
- Fix product count displayed in the UI.
- Fix enclosure not terminated in feed.
- Increase max allowed feed generation time.

Download this release

Release Info

Developer Jordan Rogers-Smith
Extension Facebook_Ads_Toolbox
Version 2.1.16
Comparing to
See all releases


Code changes from version 2.1.15 to 2.1.16

app/code/community/Facebook/AdsToolbox/Block/Adminhtml/Diaindex.php CHANGED
@@ -90,6 +90,11 @@ class Facebook_AdsToolbox_Block_Adminhtml_Diaindex
90
  Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
91
  )
92
  )
 
 
 
 
 
93
  ->getSize();
94
  }
95
 
90
  Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
91
  )
92
  )
93
+ ->addAttributeToFilter('status',
94
+ array(
95
+ 'eq' =>
96
+ Mage_Catalog_Model_Product_Status::STATUS_ENABLED
97
+ ))
98
  ->getSize();
99
  }
100
 
app/code/community/Facebook/AdsToolbox/Model/FacebookProductFeed.php CHANGED
@@ -278,7 +278,18 @@ class FacebookProductFeed {
278
 
279
  $store_id = FacebookAdsToolbox::getDefaultStoreId();
280
  $collection = Mage::getModel('catalog/product')->getCollection()
281
- ->addStoreFilter($store_id);
 
 
 
 
 
 
 
 
 
 
 
282
  $total_number_of_products = $collection->getSize();
283
  unset($collection);
284
 
@@ -309,6 +320,10 @@ class FacebookProductFeed {
309
  $total_number_of_products));
310
  }
311
 
 
 
 
 
312
  while ($count < $total_number_of_products) {
313
  // Compute and log memory usage
314
  self::log(
@@ -330,6 +345,16 @@ class FacebookProductFeed {
330
  $products = Mage::getModel('catalog/product')->getCollection()
331
  ->addAttributeToSelect('*')
332
  ->addStoreFilter($store_id)
 
 
 
 
 
 
 
 
 
 
333
  ->setPageSize($batch_max)
334
  ->setCurPage($count / $batch_max + 1)
335
  ->addUrlRewrite();
@@ -337,14 +362,8 @@ class FacebookProductFeed {
337
  foreach ($products as $product) {
338
  try {
339
  $product->setStoreId($store_id);
340
- if ($product->getVisibility() !=
341
- Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE &&
342
- $product->getStatus() !=
343
- Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
344
-
345
- $e = $this->buildProductEntry($product);
346
- $io->streamWrite($e."\n");
347
- }
348
  } catch (\Exception $e) {
349
  $exception_count++;
350
  // Don't overload the logs, log the first 3 exceptions.
@@ -482,11 +501,9 @@ class FacebookProductFeed {
482
  }
483
 
484
  private function lowercaseIfAllCaps($string) {
485
- // if contains lowercase or non-western characters, don't update string
486
- if (!preg_match('/[a-z]/', $string) && !preg_match('/[^\\p{Common}\\p{Latin}]/u', $string)) {
487
- $latin_string = preg_replace('/[^\\p{Latin}]/u', '', $string);
488
- if ($latin_string !== '' &&
489
- mb_strtoupper($latin_string, 'utf-8') === $latin_string) {
490
  return mb_strtolower($string, 'utf-8');
491
  }
492
  }
278
 
279
  $store_id = FacebookAdsToolbox::getDefaultStoreId();
280
  $collection = Mage::getModel('catalog/product')->getCollection()
281
+ ->addStoreFilter($store_id)
282
+ ->addAttributeToFilter('visibility',
283
+ array(
284
+ 'neq' =>
285
+ Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
286
+ ))
287
+ ->addAttributeToFilter('status',
288
+ array(
289
+ 'eq' =>
290
+ Mage_Catalog_Model_Product_Status::STATUS_ENABLED
291
+ ));
292
+
293
  $total_number_of_products = $collection->getSize();
294
  unset($collection);
295
 
320
  $total_number_of_products));
321
  }
322
 
323
+ $time_limit = (int) ini_get('max_execution_time');
324
+ if ($time_limit !== 0 && $time_limit < 1800) {
325
+ set_time_limit(1800);
326
+ }
327
  while ($count < $total_number_of_products) {
328
  // Compute and log memory usage
329
  self::log(
345
  $products = Mage::getModel('catalog/product')->getCollection()
346
  ->addAttributeToSelect('*')
347
  ->addStoreFilter($store_id)
348
+ ->addAttributeToFilter('visibility',
349
+ array(
350
+ 'neq' =>
351
+ Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
352
+ ))
353
+ ->addAttributeToFilter('status',
354
+ array(
355
+ 'eq' =>
356
+ Mage_Catalog_Model_Product_Status::STATUS_ENABLED
357
+ ))
358
  ->setPageSize($batch_max)
359
  ->setCurPage($count / $batch_max + 1)
360
  ->addUrlRewrite();
362
  foreach ($products as $product) {
363
  try {
364
  $product->setStoreId($store_id);
365
+ $e = $this->buildProductEntry($product);
366
+ $io->streamWrite($e."\n");
 
 
 
 
 
 
367
  } catch (\Exception $e) {
368
  $exception_count++;
369
  // Don't overload the logs, log the first 3 exceptions.
501
  }
502
 
503
  private function lowercaseIfAllCaps($string) {
504
+ // if contains lowercase, don't update string
505
+ if (!preg_match('/[a-z]/', $string)) {
506
+ if (mb_strtoupper($string, 'utf-8') === $string) {
 
 
507
  return mb_strtolower($string, 'utf-8');
508
  }
509
  }
app/code/community/Facebook/AdsToolbox/Model/FacebookProductFeedTSV.php CHANGED
@@ -29,6 +29,20 @@ class FacebookProductFeedTSV extends FacebookProductFeed {
29
  // ref: https://developers.facebook.com/docs/marketing-api/dynamic-product-ads/product-catalog
30
  const TSV_HEADER = "id\ttitle\tdescription\tlink\timage_link\tbrand\tcondition\tavailability\tprice\tshort_description\tproduct_type\tgoogle_product_category";
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  protected function tsvescape($t) {
33
  // replace newlines as TSV does not allow multi-line value
34
  return str_replace(array("\r", "\n", "&nbsp;", "\t"), ' ', $t);
@@ -57,7 +71,11 @@ class FacebookProductFeedTSV extends FacebookProductFeed {
57
 
58
  protected function buildProductEntry($product) {
59
  $items = parent::buildProductEntry($product);
60
- return implode("\t", array_values($items));
 
 
 
 
61
  }
62
 
63
  }
29
  // ref: https://developers.facebook.com/docs/marketing-api/dynamic-product-ads/product-catalog
30
  const TSV_HEADER = "id\ttitle\tdescription\tlink\timage_link\tbrand\tcondition\tavailability\tprice\tshort_description\tproduct_type\tgoogle_product_category";
31
 
32
+ function __construct() {
33
+ $this->quote_chars = array(
34
+ chr(145),
35
+ chr(146),
36
+ chr(147),
37
+ chr(148),
38
+ "\xe2\x80\x98",
39
+ "\xe2\x80\x99",
40
+ "\xe2\x80\x9c",
41
+ "\xe2\x80\x9d",
42
+ );
43
+ $this->replacement_chars = array("'", "'", '"', '"', "'", "'", '"', '"');
44
+ }
45
+
46
  protected function tsvescape($t) {
47
  // replace newlines as TSV does not allow multi-line value
48
  return str_replace(array("\r", "\n", "&nbsp;", "\t"), ' ', $t);
71
 
72
  protected function buildProductEntry($product) {
73
  $items = parent::buildProductEntry($product);
74
+ $imploded_str = implode("\t", array_values($items));
75
+ return str_replace(
76
+ $this->quote_chars,
77
+ $this->replacement_chars,
78
+ $imploded_str);
79
  }
80
 
81
  }
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Facebook_Ads_Toolbox</name>
4
- <version>2.1.15</version>
5
  <stability>stable</stability>
6
  <license uri="https://raw.githubusercontent.com/fbsamples/audience-network-support/master/LICENSE">Facebook License</license>
7
  <channel>community</channel>
@@ -59,15 +59,14 @@ _Installation Instructions_&#xD;
59
  &#xD;
60
  Additional FAQ&#xD;
61
  https://www.facebook.com/help/532749253576163</description>
62
- <notes>Product feed improvements:&#xD;
63
- - Fixes issue with certain store names&#xD;
64
- - Fixes issue with Blank Descriptions&#xD;
65
- - Uses TSV url in feed setup&#xD;
66
- </notes>
67
  <authors><author><name>Jordan Rogers-Smith</name><user>jordanrs</user><email>jordanrs@fb.com</email></author><author><name>Yu Li</name><user>liyuhk</user><email>liyuhk@fb.com</email></author><author><name>Dmitri Dranishnikov</name><user>dmitrid</user><email>dmitrid@fb.com</email></author><author><name>Adam Hoff</name><user>ahoff</user><email>ahoff@fb.com</email></author></authors>
68
- <date>2016-11-18</date>
69
- <time>01:53:13</time>
70
- <contents><target name="magecommunity"><dir name="Facebook"><dir name="AdsToolbox"><dir><dir name="Block"><file name="AddToCart.php" hash="2e31117ad8e7b4e3ecf1e235277142ed"/><dir name="Adminhtml"><file name="Diaindex.php" hash="5a9df961999a28ce2d6399e096df318f"/><file name="Feedindex.php" hash="86450e134bcfd4e30b94de3c29d6c101"/><file name="Pixelindex.php" hash="055c1d64fa60ec3909dd9d317392424d"/></dir><file name="Head.php" hash="8e392b70af8647013a9c15c0528ade73"/><file name="InitiateCheckout.php" hash="2ea5eeba2a53336d67081063b570082f"/><file name="Purchase.php" hash="10bd19d5d1687b8967fc1c4b91410e39"/><file name="Search.php" hash="a06d6ba96455beaed85c617ec758258a"/><file name="ViewCategory.php" hash="ecb02aa4085ba56baedf6fde729b4b79"/><file name="ViewContent.php" hash="a079a5a593a7faf389067177057db2a8"/><file name="common.php" hash="651e50d3f2a3d9f681a026fe10790109"/></dir><dir name="Helper"><file name="Data.php" hash="09da04dbb30d6de8b7a873f0447456ba"/></dir><dir name="Model"><file name="FacebookProductFeed.php" hash="8ecbf7bde69e9f09283ed18157937d59"/><file name="FacebookProductFeedSamples.php" hash="56d006dc2cca6ca2e88e9ccae60d274a"/><file name="FacebookProductFeedTSV.php" hash="4391132b3f69b32e534a7a5aa21b779f"/><file name="FacebookProductFeedXML.php" hash="c8ba195a0e85182b8541bd1a655e02d5"/><file name="Observer.php" hash="299a0d315d9ee0e8cb26c0eef3f8e23e"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FbfeedController.php" hash="0d7960608bcde90dd3d65a89e0c21692"/><file name="FbfeedlogController.php" hash="3b94fd3429ecf877cb54af173340a326"/><file name="FbmainController.php" hash="60eca5932835fca49fd0ca39b9ec7880"/><file name="FbpixelController.php" hash="f00c250878671e6e4957239ddd952476"/><file name="FbregenController.php" hash="1837e42c7e6d4d9c77bb386732d08e28"/></dir><file name="DebugController.php" hash="4d1219b72175e8b19d6fd6b3b59c7e8f"/><file name="ProductfeedController.php" hash="08e388ead90067721fb6718cac0779dd"/></dir><dir name="etc"><file name="adminhtml.xml" hash="be7e9a1dfc20ca73654c8e4ac557e4c9"/><file name="config.xml" hash="1e1a2cb4cdfd15bd916d981b39be058e"/></dir><dir name="lib"><file name="fb.php" hash="3cec6abe3ad61fba09ca9f510434ba56"/></dir></dir><file name="LICENSE" hash="4e3837b373e2371aeb3317bc8d245ad6"/><file name="PATENTS" hash="7eb20d51ce76c08c2e6c939674e75c93"/></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="facebookadstoolbox.xml" hash="cd8d60f293f5d1b5925efe01c7e48af7"/></dir><dir name="template"><dir name="facebookadstoolbox"><file name="addtocart.phtml" hash="c1a930b7c09e75f0d9746cba611e3c76"/><file name="head.phtml" hash="f70e26f4f4ee523a17a84ec577fdfde3"/><file name="initiate_checkout.phtml" hash="676e97512a1653bb3965c7171594db98"/><file name="purchase.phtml" hash="1a0383a64698a9d4c2131afc69762fc6"/><file name="search.phtml" hash="35d58ba1a53f73f715c81d2011a9a2d7"/><file name="viewcategory.phtml" hash="857d720f35a902f6ec86e34d5c88f203"/><file name="viewcontent.phtml" hash="55f054f759b06537376774ccbe6dddbe"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="facebookadstoolbox.xml" hash="5974bb612e16c7b7eff07ef06eddebda"/></dir><dir name="template"><dir name="facebookadstoolbox"><file name="dia_index.phtml" hash="839af71b1454571a41243e24cecc84ec"/><file name="feed_index.phtml" hash="157e56ef40e56378bcd07284162fb439"/><file name="pixel_index.phtml" hash="0b8e1171703bfb27ce5c768c6e79dc81"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="Facebook"><dir name="AdsToolbox"><dir><dir name="Adminhtml"><file name="dia.js" hash="9ac2e2030268bcdc33c430f21a6b357b"/><file name="feed.js" hash="134fbbb334e0d2422b77435dc105ebf5"/><dir name="lib"><file name="react-dom.min.js" hash="80dd76fff4872e658666dec43913360c"/><file name="react.min.js" hash="c3207f7bf39699d4279ba404ea55f163"/></dir><file name="pixel.js" hash="916afd85272d48e3b34c8f2a9f4db38a"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Facebook_AdsToolbox.xml" hash="164bc795b6911c5b0a6ca357a56f38cc"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="Facebook"><dir name="AdsToolbox"><dir><dir name="css"><dir name="Adminhtml"><file name="dia.css" hash="201b2a78305d44d6eeebbf67231e7767"/><file name="feed.css" hash="2763caa9c8f3b9b21f85a59915d39157"/><file name="pixel.css" hash="8b143487fcc4a902c0e44de8e2af6eef"/></dir></dir><dir name="images"><dir name="Adminhtml"><file name="buttonbg.png" hash="09adbacda0d592a215277230c48df285"/><file name="fbicons.png" hash="8f1b559a279a3785f1b2492a79f518d8"/></dir></dir></dir></dir></dir></dir></dir></dir></target></contents>
71
  <compatible/>
72
  <dependencies><required><php><min>5.3.0</min><max>8.0.0</max></php></required></dependencies>
73
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Facebook_Ads_Toolbox</name>
4
+ <version>2.1.16</version>
5
  <stability>stable</stability>
6
  <license uri="https://raw.githubusercontent.com/fbsamples/audience-network-support/master/LICENSE">Facebook License</license>
7
  <channel>community</channel>
59
  &#xD;
60
  Additional FAQ&#xD;
61
  https://www.facebook.com/help/532749253576163</description>
62
+ <notes>Product Feed Improvements:&#xD;
63
+ - Fix product count displayed in the UI.&#xD;
64
+ - Fix enclosure not terminated in feed.&#xD;
65
+ - Increase max allowed feed generation time.</notes>
 
66
  <authors><author><name>Jordan Rogers-Smith</name><user>jordanrs</user><email>jordanrs@fb.com</email></author><author><name>Yu Li</name><user>liyuhk</user><email>liyuhk@fb.com</email></author><author><name>Dmitri Dranishnikov</name><user>dmitrid</user><email>dmitrid@fb.com</email></author><author><name>Adam Hoff</name><user>ahoff</user><email>ahoff@fb.com</email></author></authors>
67
+ <date>2016-12-16</date>
68
+ <time>18:02:38</time>
69
+ <contents><target name="magecommunity"><dir name="Facebook"><dir name="AdsToolbox"><dir><dir name="Block"><file name="AddToCart.php" hash="2e31117ad8e7b4e3ecf1e235277142ed"/><dir name="Adminhtml"><file name="Diaindex.php" hash="672bbe77bd2abcaae483d0ecd83a7fbd"/><file name="Feedindex.php" hash="86450e134bcfd4e30b94de3c29d6c101"/><file name="Pixelindex.php" hash="055c1d64fa60ec3909dd9d317392424d"/></dir><file name="Head.php" hash="8e392b70af8647013a9c15c0528ade73"/><file name="InitiateCheckout.php" hash="2ea5eeba2a53336d67081063b570082f"/><file name="Purchase.php" hash="10bd19d5d1687b8967fc1c4b91410e39"/><file name="Search.php" hash="a06d6ba96455beaed85c617ec758258a"/><file name="ViewCategory.php" hash="ecb02aa4085ba56baedf6fde729b4b79"/><file name="ViewContent.php" hash="a079a5a593a7faf389067177057db2a8"/><file name="common.php" hash="651e50d3f2a3d9f681a026fe10790109"/></dir><dir name="Helper"><file name="Data.php" hash="09da04dbb30d6de8b7a873f0447456ba"/></dir><dir name="Model"><file name="FacebookProductFeed.php" hash="7cdf49bb103cb92c0d3af23a1b271e0f"/><file name="FacebookProductFeedSamples.php" hash="56d006dc2cca6ca2e88e9ccae60d274a"/><file name="FacebookProductFeedTSV.php" hash="ceb913121be7465957b7c48fe5a9a297"/><file name="FacebookProductFeedXML.php" hash="c8ba195a0e85182b8541bd1a655e02d5"/><file name="Observer.php" hash="299a0d315d9ee0e8cb26c0eef3f8e23e"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FbfeedController.php" hash="0d7960608bcde90dd3d65a89e0c21692"/><file name="FbfeedlogController.php" hash="3b94fd3429ecf877cb54af173340a326"/><file name="FbmainController.php" hash="60eca5932835fca49fd0ca39b9ec7880"/><file name="FbpixelController.php" hash="f00c250878671e6e4957239ddd952476"/><file name="FbregenController.php" hash="1837e42c7e6d4d9c77bb386732d08e28"/></dir><file name="DebugController.php" hash="4d1219b72175e8b19d6fd6b3b59c7e8f"/><file name="ProductfeedController.php" hash="08e388ead90067721fb6718cac0779dd"/></dir><dir name="etc"><file name="adminhtml.xml" hash="be7e9a1dfc20ca73654c8e4ac557e4c9"/><file name="config.xml" hash="1e1a2cb4cdfd15bd916d981b39be058e"/></dir><dir name="lib"><file name="fb.php" hash="3cec6abe3ad61fba09ca9f510434ba56"/></dir></dir><file name="LICENSE" hash="4e3837b373e2371aeb3317bc8d245ad6"/><file name="PATENTS" hash="7eb20d51ce76c08c2e6c939674e75c93"/></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="facebookadstoolbox.xml" hash="cd8d60f293f5d1b5925efe01c7e48af7"/></dir><dir name="template"><dir name="facebookadstoolbox"><file name="addtocart.phtml" hash="c1a930b7c09e75f0d9746cba611e3c76"/><file name="head.phtml" hash="f70e26f4f4ee523a17a84ec577fdfde3"/><file name="initiate_checkout.phtml" hash="676e97512a1653bb3965c7171594db98"/><file name="purchase.phtml" hash="1a0383a64698a9d4c2131afc69762fc6"/><file name="search.phtml" hash="35d58ba1a53f73f715c81d2011a9a2d7"/><file name="viewcategory.phtml" hash="857d720f35a902f6ec86e34d5c88f203"/><file name="viewcontent.phtml" hash="55f054f759b06537376774ccbe6dddbe"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="facebookadstoolbox.xml" hash="5974bb612e16c7b7eff07ef06eddebda"/></dir><dir name="template"><dir name="facebookadstoolbox"><file name="dia_index.phtml" hash="839af71b1454571a41243e24cecc84ec"/><file name="feed_index.phtml" hash="157e56ef40e56378bcd07284162fb439"/><file name="pixel_index.phtml" hash="0b8e1171703bfb27ce5c768c6e79dc81"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="Facebook"><dir name="AdsToolbox"><dir><dir name="Adminhtml"><file name="dia.js" hash="9ac2e2030268bcdc33c430f21a6b357b"/><file name="feed.js" hash="134fbbb334e0d2422b77435dc105ebf5"/><dir name="lib"><file name="react-dom.min.js" hash="80dd76fff4872e658666dec43913360c"/><file name="react.min.js" hash="c3207f7bf39699d4279ba404ea55f163"/></dir><file name="pixel.js" hash="916afd85272d48e3b34c8f2a9f4db38a"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Facebook_AdsToolbox.xml" hash="164bc795b6911c5b0a6ca357a56f38cc"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="Facebook"><dir name="AdsToolbox"><dir><dir name="css"><dir name="Adminhtml"><file name="dia.css" hash="201b2a78305d44d6eeebbf67231e7767"/><file name="feed.css" hash="2763caa9c8f3b9b21f85a59915d39157"/><file name="pixel.css" hash="8b143487fcc4a902c0e44de8e2af6eef"/></dir></dir><dir name="images"><dir name="Adminhtml"><file name="buttonbg.png" hash="09adbacda0d592a215277230c48df285"/><file name="fbicons.png" hash="8f1b559a279a3785f1b2492a79f518d8"/></dir></dir></dir></dir></dir></dir></dir></dir></target></contents>
70
  <compatible/>
71
  <dependencies><required><php><min>5.3.0</min><max>8.0.0</max></php></required></dependencies>
72
  </package>