BothInteract_ConfigurableProductVariantsImageAssignment - Version 1.6.1

Version Notes

+ now uses configuration setting via admin for secure image URLs
* fixed media path calculation issue

Download this release

Release Info

Developer Matthias Kerstner
Extension BothInteract_ConfigurableProductVariantsImageAssignment
Version 1.6.1
Comparing to
See all releases


Code changes from version 1.6.0 to 1.6.1

app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/Helper/Data.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /**
4
  * @author Matthias Kerstner <matthias@both-interact.com>
5
- * @version 1.6.0
6
  * @copyright (c) 2016, Both Interact GmbH
7
  */
8
  class BothInteract_ConfigurableProductVariantsImageAssignment_Helper_Data extends Mage_Core_Helper_Abstract {
2
 
3
  /**
4
  * @author Matthias Kerstner <matthias@both-interact.com>
5
+ * @version 1.6.1
6
  * @copyright (c) 2016, Both Interact GmbH
7
  */
8
  class BothInteract_ConfigurableProductVariantsImageAssignment_Helper_Data extends Mage_Core_Helper_Abstract {
app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/Model/Observer.php CHANGED
@@ -20,7 +20,7 @@
20
  * @see self::$LOG_FILE.
21
  *
22
  * @author Matthias Kerstner <matthias@both-interact.com>
23
- * @version 1.6.0
24
  * @copyright (c) 2016, Both Interact GmbH
25
  */
26
  class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
@@ -70,6 +70,7 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
70
  /**
71
  * Returns absolute path to base image set on $product. If no image of type
72
  * $imageType is currently set will return NULL.
 
73
  * @param Mage_Catalog_Model_Product $product
74
  * @param string $imageType image type, i.e. image (base image),
75
  * small_image, thumbnail
@@ -99,13 +100,15 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
99
  $imageUrl = Mage::getModel('catalog/product_media_config')
100
  ->getMediaUrl($image, array('_secure' => $isHttps));
101
  $baseDir = Mage::getBaseDir();
102
- $withoutIndex = str_replace('index.php/', '', Mage::getBaseUrl($isHttps));
103
- $imageWithoutBase = str_replace($withoutIndex, '', $imageUrl);
104
- return ($baseDir . DIRECTORY_SEPARATOR . $imageWithoutBase);
 
105
  }
106
 
107
  /**
108
  * Returns absolute path the product's based image if set, otherwise NULL.
 
109
  * @param Mage_Catalog_Model_Product $product
110
  * @param boolean $isHttps
111
  * @return string|NULL
@@ -119,12 +122,17 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
119
  if ($product->getImage() == '' ||
120
  $product->getImage() == self::$IMAGE_NO_SELECTION) {
121
  $this->logToFile('WARNING: product ' . $product->getId()
122
- . ' does not have a base image set');
 
 
 
123
  return null;
124
  }
125
 
126
  $productBaseImagePath = $this->getImagePath($product, self::$IMAGE_TYPE_BASE_IMAGE, $isHttps);
127
 
 
 
128
  if (!is_file($productBaseImagePath)) {
129
  $this->logToFile('WARNING: parent product ' . $product->getId()
130
  . ' base image not readable ' . $productBaseImagePath);
@@ -151,7 +159,10 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
151
  . mb_strtoupper($childProduct->getTypeId())
152
  . ' product ' . $childProduct->getId());
153
 
154
- $isHttps = true; //TODO: load from config
 
 
 
155
 
156
  $parentProductBaseImagePath = $this->getProductBaseImagePath($parentProduct, $isHttps);
157
 
@@ -278,7 +289,9 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
278
  }
279
 
280
  /**
281
- * Handles configurable prod
 
 
282
  * @param Mage_Catalog_Model_Product $product
283
  * @param array $requiredChildProductImageTypes
284
  */
@@ -311,8 +324,9 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
311
  }
312
 
313
  /**
314
- * Handles product save event calls by checking product type and settings
315
  * required image types.
 
316
  * @param Varien_Event_Observer $observer
317
  */
318
  public function catalog_product_save_after(Varien_Event_Observer $observer) {
@@ -329,12 +343,25 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
329
  }
330
 
331
  /**
332
- * Can be of any product type, e.g. configurable, grouped, simple,
 
 
 
 
 
333
  * @param Mage_Catalog_Model_Product $product Can be of any valid product
334
  * type, e.g. configurable, grouped, simple, ...
335
  */
336
  public function processProduct(Mage_Catalog_Model_Product $product) {
337
  try {
 
 
 
 
 
 
 
 
338
  $this->logToFile('==================================================');
339
  $this->logToFile('Checking product ' . $product->getId()
340
  . ' of type ' . mb_strtoupper($product->getTypeId())
@@ -348,7 +375,7 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
348
  * - IMAGE_TYPE_SMALL_IMAGE
349
  * - IMAGE_TYPE_THUMBNAIL.
350
  *
351
- * Make sure that this list always includes at least
352
  * IMAGE_TYPE_BASE_IMAGE for e.g. Amazon Listing to work since it
353
  * requires a base image.
354
  *
20
  * @see self::$LOG_FILE.
21
  *
22
  * @author Matthias Kerstner <matthias@both-interact.com>
23
+ * @version 1.6.1
24
  * @copyright (c) 2016, Both Interact GmbH
25
  */
26
  class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
70
  /**
71
  * Returns absolute path to base image set on $product. If no image of type
72
  * $imageType is currently set will return NULL.
73
+ *
74
  * @param Mage_Catalog_Model_Product $product
75
  * @param string $imageType image type, i.e. image (base image),
76
  * small_image, thumbnail
100
  $imageUrl = Mage::getModel('catalog/product_media_config')
101
  ->getMediaUrl($image, array('_secure' => $isHttps));
102
  $baseDir = Mage::getBaseDir();
103
+ $mediaUrlwithoutIndex = str_replace('index.php/', '', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
104
+ $mediaUrlwithoutBase = str_replace($mediaUrlwithoutIndex, '', $imageUrl);
105
+
106
+ return ($baseDir . DIRECTORY_SEPARATOR . $mediaUrlwithoutBase);
107
  }
108
 
109
  /**
110
  * Returns absolute path the product's based image if set, otherwise NULL.
111
+ *
112
  * @param Mage_Catalog_Model_Product $product
113
  * @param boolean $isHttps
114
  * @return string|NULL
122
  if ($product->getImage() == '' ||
123
  $product->getImage() == self::$IMAGE_NO_SELECTION) {
124
  $this->logToFile('WARNING: product ' . $product->getId()
125
+ . ' does not have a base image set.'
126
+ . ' Make sure that parent product has a base image set and '
127
+ . 'check that entry "No image" is not set as base image in '
128
+ . 'admin backend.');
129
  return null;
130
  }
131
 
132
  $productBaseImagePath = $this->getImagePath($product, self::$IMAGE_TYPE_BASE_IMAGE, $isHttps);
133
 
134
+ $this->logToFile('Using parent product image: ' . $productBaseImagePath);
135
+
136
  if (!is_file($productBaseImagePath)) {
137
  $this->logToFile('WARNING: parent product ' . $product->getId()
138
  . ' base image not readable ' . $productBaseImagePath);
159
  . mb_strtoupper($childProduct->getTypeId())
160
  . ' product ' . $childProduct->getId());
161
 
162
+ $isHttps = Mage::getStoreConfig(self::$_MODULE_NAMESPACE
163
+ . '/general/is_https_media_urls');
164
+
165
+ $this->logToFile('Using SSL for image URLs: ' . ($isHttps ? 'YES' : 'NO'));
166
 
167
  $parentProductBaseImagePath = $this->getProductBaseImagePath($parentProduct, $isHttps);
168
 
289
  }
290
 
291
  /**
292
+ * Handles configurable product and determine associated (child) products
293
+ * to process.
294
+ *
295
  * @param Mage_Catalog_Model_Product $product
296
  * @param array $requiredChildProductImageTypes
297
  */
324
  }
325
 
326
  /**
327
+ * Handles product save_after events by checking product type and settings
328
  * required image types.
329
+ *
330
  * @param Varien_Event_Observer $observer
331
  */
332
  public function catalog_product_save_after(Varien_Event_Observer $observer) {
343
  }
344
 
345
  /**
346
+ * Product specified can be of any type, e.g. configurable, grouped,
347
+ * simple, etc.
348
+ *
349
+ * Make sure that this product is loaded here once for the remaining
350
+ * process.
351
+ *
352
  * @param Mage_Catalog_Model_Product $product Can be of any valid product
353
  * type, e.g. configurable, grouped, simple, ...
354
  */
355
  public function processProduct(Mage_Catalog_Model_Product $product) {
356
  try {
357
+
358
+ /**
359
+ * first make sure that $product is fully loaded and keep reference
360
+ * to original product from event
361
+ */
362
+ $_product = $product; // copy
363
+ $product = Mage::getModel('catalog/product')->load($product->getId());
364
+
365
  $this->logToFile('==================================================');
366
  $this->logToFile('Checking product ' . $product->getId()
367
  . ' of type ' . mb_strtoupper($product->getTypeId())
375
  * - IMAGE_TYPE_SMALL_IMAGE
376
  * - IMAGE_TYPE_THUMBNAIL.
377
  *
378
+ * Make sure that this list *always* includes at least
379
  * IMAGE_TYPE_BASE_IMAGE for e.g. Amazon Listing to work since it
380
  * requires a base image.
381
  *
app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/Model/System/Config/Source/View.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /**
4
  * @author Matthias Kerstner <matthias@both-interact.com>
5
- * @version 1.6.0
6
  * @copyright (c) 2016, Both Interact GmbH
7
  */
8
  class BothInteract_ConfigurableProductVariantsImageAssignment_Model_System_Config_Source_View {
2
 
3
  /**
4
  * @author Matthias Kerstner <matthias@both-interact.com>
5
+ * @version 1.6.1
6
  * @copyright (c) 2016, Both Interact GmbH
7
  */
8
  class BothInteract_ConfigurableProductVariantsImageAssignment_Model_System_Config_Source_View {
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>BothInteract_ConfigurableProductVariantsImageAssignment</name>
4
- <version>1.6.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/mit-license.php">MIT License (MITL)</license>
7
  <channel>community</channel>
@@ -36,13 +36,12 @@
36
  &#xD;
37
  &lt;p&gt;So you have the option to easily track events handled by this extension and check for possible problems.&lt;/p&gt;&#xD;
38
  </description>
39
- <notes>+ Added missing Data.php.&#xD;
40
- + Checked against latest CE 1.9.x&#xD;
41
- + Checked against latest PHP 7.x</notes>
42
  <authors><author><name>Matthias Kerstner</name><user>mkbothinteract</user><email>matthias@both-interact.com</email></author></authors>
43
  <date>2016-04-25</date>
44
- <time>10:40:51</time>
45
- <contents><target name="magecommunity"><dir name="BothInteract"><dir name="ConfigurableProductVariantsImageAssignment"><dir name="Helper"><file name="Data.php" hash="4b5b15da7789b17cdd19d5b34735acac"/></dir><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="View.php" hash="a73d3fbfacffb84d7715f2fe40798d94"/></dir></dir></dir><file name="Observer.php" hash="9bf6085b0388745091dd49e817335e97"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash=""/><file name="system.xml" hash=""/><file name="adminhtml.xml" hash=""/></dir></target><target name="mageetc"><dir name="modules"><file name="BothInteract_ConfigurableProductVariantsImageAssignment.xml" hash="d38ef35b9d75fee8e4832a1659a82391"/></dir></target><target name="mage"><dir name="shell"><file name="set_required_images_for_configurable_product_variants.php" hash="8b665b60c520743f9403a230d5b2d344"/></dir></target><target name="magelocale"><dir name="en_US"><file name="BothInteract_ConfigurableProductVariantsImageAssignment.csv" hash=""/></dir><dir name="de_DE"><file name="BothInteract_ConfigurableProductVariantsImageAssignment.csv" hash=""/></dir></target></contents>
46
  <compatible/>
47
  <dependencies><required><php><min>5.3.0</min><max>7.0.4</max></php></required></dependencies>
48
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>BothInteract_ConfigurableProductVariantsImageAssignment</name>
4
+ <version>1.6.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/mit-license.php">MIT License (MITL)</license>
7
  <channel>community</channel>
36
  &#xD;
37
  &lt;p&gt;So you have the option to easily track events handled by this extension and check for possible problems.&lt;/p&gt;&#xD;
38
  </description>
39
+ <notes>+ now uses configuration setting via admin for secure image URLs&#xD;
40
+ * fixed media path calculation issue</notes>
 
41
  <authors><author><name>Matthias Kerstner</name><user>mkbothinteract</user><email>matthias@both-interact.com</email></author></authors>
42
  <date>2016-04-25</date>
43
+ <time>12:07:03</time>
44
+ <contents><target name="magecommunity"><dir name="BothInteract"><dir name="ConfigurableProductVariantsImageAssignment"><dir name="Helper"><file name="Data.php" hash="de951bf7bcd104767a9469efc94a4c81"/></dir><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="View.php" hash="f92b6ff799c59fa6965c3f9b8a42c7db"/></dir></dir></dir><file name="Observer.php" hash="7f20822d7e9a3cacac62f05b55e22d5f"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash=""/><file name="system.xml" hash=""/><file name="adminhtml.xml" hash=""/></dir></target><target name="mageetc"><dir name="modules"><file name="BothInteract_ConfigurableProductVariantsImageAssignment.xml" hash="d38ef35b9d75fee8e4832a1659a82391"/></dir></target><target name="mage"><dir name="shell"><file name="set_required_images_for_configurable_product_variants.php" hash="de89b039ca425e9bc00063f65c869260"/></dir></target><target name="magelocale"><dir name="en_US"><file name="BothInteract_ConfigurableProductVariantsImageAssignment.csv" hash=""/></dir><dir name="de_DE"><file name="BothInteract_ConfigurableProductVariantsImageAssignment.csv" hash=""/></dir></target></contents>
45
  <compatible/>
46
  <dependencies><required><php><min>5.3.0</min><max>7.0.4</max></php></required></dependencies>
47
  </package>
shell/set_required_images_for_configurable_product_variants.php CHANGED
@@ -4,7 +4,7 @@ require_once 'abstract.php';
4
 
5
  /**
6
  * @author Matthias Kerstner <matthias@both-interact.com>
7
- * @version 1.6.0
8
  * @copyright (c) 2016, Both Interact GmbH
9
  */
10
  class Mage_Shell_Set_Required_Images_For_Configurable_Product_Variants extends Mage_Shell_Abstract {
4
 
5
  /**
6
  * @author Matthias Kerstner <matthias@both-interact.com>
7
+ * @version 1.6.1
8
  * @copyright (c) 2016, Both Interact GmbH
9
  */
10
  class Mage_Shell_Set_Required_Images_For_Configurable_Product_Variants extends Mage_Shell_Abstract {