Version Notes
Added missing shell script in installation package. As usual, you can find the shell script in the folder "shell".
Download this release
Release Info
| Developer | Matthias Kerstner |
| Extension | BothInteract_ConfigurableProductVariantsImageAssignment |
| Version | 1.3.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.2.0 to 1.3.0
- app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/Model/Observer.php +64 -49
- app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/Model/System/Config/Source/View.php +2 -2
- app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/etc/config.xml +2 -1
- app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/etc/system.xml +14 -2
- package.xml +6 -12
- shell/set_required_images_for_configurable_product_variants.php +136 -0
app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/Model/Observer.php
CHANGED
|
@@ -20,8 +20,8 @@
|
|
| 20 |
* @see self::$LOG_FILE.
|
| 21 |
*
|
| 22 |
* @author Matthias Kerstner <matthias@both-interact.com>
|
| 23 |
-
* @version 1.
|
| 24 |
-
* @copyright (c)
|
| 25 |
*/
|
| 26 |
class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
|
| 27 |
|
|
@@ -63,12 +63,50 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
|
|
| 63 |
return isset($arr[$value]) ? $arr[$value] : null;
|
| 64 |
}
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
/**
|
| 67 |
* Returns absolute path the product's based image if set, otherwise NULL.
|
| 68 |
* @param Mage_Catalog_Model_Product $product
|
|
|
|
| 69 |
* @return string|NULL
|
| 70 |
*/
|
| 71 |
-
private function getProductBaseImagePath(Mage_Catalog_Model_Product $product) {
|
| 72 |
|
| 73 |
$this->logToFile('Product Base image: ' . $product->getImage());
|
| 74 |
$this->logToFile('Product Small image: ' . $product->getSmallImage());
|
|
@@ -81,7 +119,7 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
|
|
| 81 |
return null;
|
| 82 |
}
|
| 83 |
|
| 84 |
-
$productBaseImagePath = $this->getImagePath($product, self::$IMAGE_TYPE_BASE_IMAGE);
|
| 85 |
|
| 86 |
if (!is_file($productBaseImagePath)) {
|
| 87 |
$this->logToFile('WARNING: parent product ' . $product->getId()
|
|
@@ -109,7 +147,9 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
|
|
| 109 |
. mb_strtoupper($childProduct->getTypeId())
|
| 110 |
. ' product ' . $childProduct->getId());
|
| 111 |
|
| 112 |
-
$
|
|
|
|
|
|
|
| 113 |
|
| 114 |
if (!$parentProductBaseImagePath) {
|
| 115 |
$this->logToFile('WARNING: Failed to determine parent product '
|
|
@@ -175,7 +215,13 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
|
|
| 175 |
*/
|
| 176 |
$childProduct->addImageToMediaGallery($parentProductBaseImagePath, $requiredChildProductImageTypes, false, false);
|
| 177 |
|
| 178 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
$childProduct->save();
|
| 180 |
}
|
| 181 |
|
|
@@ -185,42 +231,6 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
|
|
| 185 |
}
|
| 186 |
}
|
| 187 |
|
| 188 |
-
/**
|
| 189 |
-
* Returns absolute path to base image set on $product. If no image of type
|
| 190 |
-
* $imageType is currently set will return NULL.
|
| 191 |
-
* @param Mage_Catalog_Model_Product $product
|
| 192 |
-
* @param string $imageType image type, i.e. image (base image),
|
| 193 |
-
* small_image, thumbnail
|
| 194 |
-
* @return string|NULL
|
| 195 |
-
*/
|
| 196 |
-
private function getImagePath(Mage_Catalog_Model_Product $product, $imageType) {
|
| 197 |
-
|
| 198 |
-
if ($product->getImage() == '' ||
|
| 199 |
-
$product->getImage() == self::$IMAGE_NO_SELECTION) {
|
| 200 |
-
return null;
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
$image = null;
|
| 204 |
-
|
| 205 |
-
if ($imageType === self::$IMAGE_TYPE_BASE_IMAGE) {
|
| 206 |
-
$image = $product->getImage();
|
| 207 |
-
} else if ($imageType === self::$IMAGE_TYPE_SMALL_IMAGE) {
|
| 208 |
-
$image = $product->getSmallImage();
|
| 209 |
-
} else if ($imageType === self::$IMAGE_TYPE_THUMBNAIL) {
|
| 210 |
-
$image = $product->getThumbnail();
|
| 211 |
-
} else {
|
| 212 |
-
$this->logToFile('Invalid image type specified: ' . $imageType);
|
| 213 |
-
return null;
|
| 214 |
-
}
|
| 215 |
-
|
| 216 |
-
$imageUrl = Mage::getModel('catalog/product_media_config')
|
| 217 |
-
->getMediaUrl($image);
|
| 218 |
-
$baseDir = Mage::getBaseDir();
|
| 219 |
-
$withoutIndex = str_replace('index.php/', '', Mage::getBaseUrl());
|
| 220 |
-
$imageWithoutBase = str_replace($withoutIndex, '', $imageUrl);
|
| 221 |
-
return ($baseDir . DIRECTORY_SEPARATOR . $imageWithoutBase);
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
/**
|
| 225 |
* Handles simple products.
|
| 226 |
* @param Mage_Catalog_Model_Product $product
|
|
@@ -302,18 +312,23 @@ class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
|
|
| 302 |
*/
|
| 303 |
public function catalog_product_save_after(Varien_Event_Observer $observer) {
|
| 304 |
try {
|
| 305 |
-
|
| 306 |
if (!Mage::getStoreConfig('bothinteract_configurableproductvariantsimageassignment/general/is_active', Mage::app()->getStore())) {
|
| 307 |
$this->logToFile('Extension INACTIVE - Quitting...');
|
| 308 |
return;
|
| 309 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
|
|
|
| 317 |
$this->logToFile('==================================================');
|
| 318 |
$this->logToFile('Checking product ' . $product->getId()
|
| 319 |
. ' of type ' . mb_strtoupper($product->getTypeId())
|
| 20 |
* @see self::$LOG_FILE.
|
| 21 |
*
|
| 22 |
* @author Matthias Kerstner <matthias@both-interact.com>
|
| 23 |
+
* @version 1.3.0
|
| 24 |
+
* @copyright (c) 2015, Both Interact GmbH
|
| 25 |
*/
|
| 26 |
class BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer {
|
| 27 |
|
| 63 |
return isset($arr[$value]) ? $arr[$value] : null;
|
| 64 |
}
|
| 65 |
|
| 66 |
+
/**
|
| 67 |
+
* Returns absolute path to base image set on $product. If no image of type
|
| 68 |
+
* $imageType is currently set will return NULL.
|
| 69 |
+
* @param Mage_Catalog_Model_Product $product
|
| 70 |
+
* @param string $imageType image type, i.e. image (base image),
|
| 71 |
+
* small_image, thumbnail
|
| 72 |
+
* @param boolean $isHttps
|
| 73 |
+
* @return string|NULL
|
| 74 |
+
*/
|
| 75 |
+
private function getImagePath(Mage_Catalog_Model_Product $product, $imageType, $isHttps = false) {
|
| 76 |
+
|
| 77 |
+
if ($product->getImage() == '' ||
|
| 78 |
+
$product->getImage() == self::$IMAGE_NO_SELECTION) {
|
| 79 |
+
return null;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
$image = null;
|
| 83 |
+
|
| 84 |
+
if ($imageType === self::$IMAGE_TYPE_BASE_IMAGE) {
|
| 85 |
+
$image = $product->getImage();
|
| 86 |
+
} else if ($imageType === self::$IMAGE_TYPE_SMALL_IMAGE) {
|
| 87 |
+
$image = $product->getSmallImage();
|
| 88 |
+
} else if ($imageType === self::$IMAGE_TYPE_THUMBNAIL) {
|
| 89 |
+
$image = $product->getThumbnail();
|
| 90 |
+
} else {
|
| 91 |
+
$this->logToFile('Invalid image type specified: ' . $imageType);
|
| 92 |
+
return null;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
$imageUrl = Mage::getModel('catalog/product_media_config')
|
| 96 |
+
->getMediaUrl($image, array('_secure' => $isHttps));
|
| 97 |
+
$baseDir = Mage::getBaseDir();
|
| 98 |
+
$withoutIndex = str_replace('index.php/', '', Mage::getBaseUrl($isHttps));
|
| 99 |
+
$imageWithoutBase = str_replace($withoutIndex, '', $imageUrl);
|
| 100 |
+
return ($baseDir . DIRECTORY_SEPARATOR . $imageWithoutBase);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
/**
|
| 104 |
* Returns absolute path the product's based image if set, otherwise NULL.
|
| 105 |
* @param Mage_Catalog_Model_Product $product
|
| 106 |
+
* @param boolean $isHttps
|
| 107 |
* @return string|NULL
|
| 108 |
*/
|
| 109 |
+
private function getProductBaseImagePath(Mage_Catalog_Model_Product $product, $isHttps = false) {
|
| 110 |
|
| 111 |
$this->logToFile('Product Base image: ' . $product->getImage());
|
| 112 |
$this->logToFile('Product Small image: ' . $product->getSmallImage());
|
| 119 |
return null;
|
| 120 |
}
|
| 121 |
|
| 122 |
+
$productBaseImagePath = $this->getImagePath($product, self::$IMAGE_TYPE_BASE_IMAGE, $isHttps);
|
| 123 |
|
| 124 |
if (!is_file($productBaseImagePath)) {
|
| 125 |
$this->logToFile('WARNING: parent product ' . $product->getId()
|
| 147 |
. mb_strtoupper($childProduct->getTypeId())
|
| 148 |
. ' product ' . $childProduct->getId());
|
| 149 |
|
| 150 |
+
$isHttps = true; //TODO: load from config
|
| 151 |
+
|
| 152 |
+
$parentProductBaseImagePath = $this->getProductBaseImagePath($parentProduct, $isHttps);
|
| 153 |
|
| 154 |
if (!$parentProductBaseImagePath) {
|
| 155 |
$this->logToFile('WARNING: Failed to determine parent product '
|
| 215 |
*/
|
| 216 |
$childProduct->addImageToMediaGallery($parentProductBaseImagePath, $requiredChildProductImageTypes, false, false);
|
| 217 |
|
| 218 |
+
if (Mage::getStoreConfig('bothinteract_configurableproductvariantsimageassignment/general/is_simulation')) {
|
| 219 |
+
$this->logToFile('************************************');
|
| 220 |
+
$this->logToFile('SIMULATION: Not saving child product '
|
| 221 |
+
. $childProduct->getId());
|
| 222 |
+
$this->logToFile('************************************');
|
| 223 |
+
} else {
|
| 224 |
+
$this->logToFile('Saving child product ' . $childProduct->getId());
|
| 225 |
$childProduct->save();
|
| 226 |
}
|
| 227 |
|
| 231 |
}
|
| 232 |
}
|
| 233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
/**
|
| 235 |
* Handles simple products.
|
| 236 |
* @param Mage_Catalog_Model_Product $product
|
| 312 |
*/
|
| 313 |
public function catalog_product_save_after(Varien_Event_Observer $observer) {
|
| 314 |
try {
|
|
|
|
| 315 |
if (!Mage::getStoreConfig('bothinteract_configurableproductvariantsimageassignment/general/is_active', Mage::app()->getStore())) {
|
| 316 |
$this->logToFile('Extension INACTIVE - Quitting...');
|
| 317 |
return;
|
| 318 |
}
|
| 319 |
+
$this->processProduct($observer->getEvent()->getProduct());
|
| 320 |
+
} catch (Exception $e) {
|
| 321 |
+
$this->logToFile('ERROR: ' . $e->getMessage());
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
|
| 325 |
+
/**
|
| 326 |
+
* Can be of any product type, e.g. configurable, grouped, simple,
|
| 327 |
+
* @param Mage_Catalog_Model_Product $product Can be of any valid product
|
| 328 |
+
* type, e.g. configurable, grouped, simple, ...
|
| 329 |
+
*/
|
| 330 |
+
public function processProduct(Mage_Catalog_Model_Product $product) {
|
| 331 |
+
try {
|
| 332 |
$this->logToFile('==================================================');
|
| 333 |
$this->logToFile('Checking product ' . $product->getId()
|
| 334 |
. ' of type ' . mb_strtoupper($product->getTypeId())
|
app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/Model/System/Config/Source/View.php
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
|
| 3 |
/**
|
| 4 |
* @author Matthias Kerstner <matthias@both-interact.com>
|
| 5 |
-
* @version 1.
|
| 6 |
-
* @copyright (c)
|
| 7 |
*/
|
| 8 |
class BothInteract_ConfigurableProductVariantsImageAssignment_Model_System_Config_Source_View {
|
| 9 |
|
| 2 |
|
| 3 |
/**
|
| 4 |
* @author Matthias Kerstner <matthias@both-interact.com>
|
| 5 |
+
* @version 1.3.0
|
| 6 |
+
* @copyright (c) 2015, Both Interact GmbH
|
| 7 |
*/
|
| 8 |
class BothInteract_ConfigurableProductVariantsImageAssignment_Model_System_Config_Source_View {
|
| 9 |
|
app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/etc/config.xml
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
|
| 5 |
<modules>
|
| 6 |
<BothInteract_ConfigurableProductVariantsImageAssignment>
|
| 7 |
-
<version>1.
|
| 8 |
</BothInteract_ConfigurableProductVariantsImageAssignment>
|
| 9 |
</modules>
|
| 10 |
|
|
@@ -34,6 +34,7 @@
|
|
| 34 |
<general>
|
| 35 |
<is_active>0</is_active>
|
| 36 |
<is_simulation>1</is_simulation>
|
|
|
|
| 37 |
<required_image_types></required_image_types>
|
| 38 |
<log_file>configurableproductvariantsimageassignment.log</log_file>
|
| 39 |
</general>
|
| 4 |
|
| 5 |
<modules>
|
| 6 |
<BothInteract_ConfigurableProductVariantsImageAssignment>
|
| 7 |
+
<version>1.3.0</version>
|
| 8 |
</BothInteract_ConfigurableProductVariantsImageAssignment>
|
| 9 |
</modules>
|
| 10 |
|
| 34 |
<general>
|
| 35 |
<is_active>0</is_active>
|
| 36 |
<is_simulation>1</is_simulation>
|
| 37 |
+
<is_https_media_urls>0</is_https_media_urls>
|
| 38 |
<required_image_types></required_image_types>
|
| 39 |
<log_file>configurableproductvariantsimageassignment.log</log_file>
|
| 40 |
</general>
|
app/code/community/BothInteract/ConfigurableProductVariantsImageAssignment/etc/system.xml
CHANGED
|
@@ -55,6 +55,18 @@
|
|
| 55 |
<show_in_website>1</show_in_website>
|
| 56 |
<show_in_store>1</show_in_store>
|
| 57 |
</is_simulation>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
<required_image_types translate="label">
|
| 59 |
<label>Required Image Types</label>
|
| 60 |
<comment>
|
|
@@ -62,7 +74,7 @@
|
|
| 62 |
</comment>
|
| 63 |
<frontend_type>multiselect</frontend_type>
|
| 64 |
<source_model>BothInteract_ConfigurableProductVariantsImageAssignment_Model_System_Config_Source_View</source_model>
|
| 65 |
-
<sort_order>
|
| 66 |
<show_in_default>1</show_in_default>
|
| 67 |
<show_in_website>1</show_in_website>
|
| 68 |
<show_in_store>1</show_in_store>
|
|
@@ -73,7 +85,7 @@
|
|
| 73 |
<![CDATA[Please specify a name for your custom <b>log file</b>.]]>
|
| 74 |
</comment>
|
| 75 |
<frontend_type>text</frontend_type>
|
| 76 |
-
<sort_order>
|
| 77 |
<show_in_default>1</show_in_default>
|
| 78 |
<show_in_website>1</show_in_website>
|
| 79 |
<show_in_store>1</show_in_store>
|
| 55 |
<show_in_website>1</show_in_website>
|
| 56 |
<show_in_store>1</show_in_store>
|
| 57 |
</is_simulation>
|
| 58 |
+
<is_https_media_urls translate="label">
|
| 59 |
+
<label>Secure Media URLs (https)</label>
|
| 60 |
+
<comment>
|
| 61 |
+
<![CDATA[Check this box if your media files are linked using <b>https</b>.]]>
|
| 62 |
+
</comment>
|
| 63 |
+
<frontend_type>select</frontend_type>
|
| 64 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 65 |
+
<sort_order>3</sort_order>
|
| 66 |
+
<show_in_default>1</show_in_default>
|
| 67 |
+
<show_in_website>1</show_in_website>
|
| 68 |
+
<show_in_store>1</show_in_store>
|
| 69 |
+
</is_https_media_urls>
|
| 70 |
<required_image_types translate="label">
|
| 71 |
<label>Required Image Types</label>
|
| 72 |
<comment>
|
| 74 |
</comment>
|
| 75 |
<frontend_type>multiselect</frontend_type>
|
| 76 |
<source_model>BothInteract_ConfigurableProductVariantsImageAssignment_Model_System_Config_Source_View</source_model>
|
| 77 |
+
<sort_order>4</sort_order>
|
| 78 |
<show_in_default>1</show_in_default>
|
| 79 |
<show_in_website>1</show_in_website>
|
| 80 |
<show_in_store>1</show_in_store>
|
| 85 |
<![CDATA[Please specify a name for your custom <b>log file</b>.]]>
|
| 86 |
</comment>
|
| 87 |
<frontend_type>text</frontend_type>
|
| 88 |
+
<sort_order>5</sort_order>
|
| 89 |
<show_in_default>1</show_in_default>
|
| 90 |
<show_in_website>1</show_in_website>
|
| 91 |
<show_in_store>1</show_in_store>
|
package.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>BothInteract_ConfigurableProductVariantsImageAssignment</name>
|
| 4 |
-
<version>1.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.opensource.org/licenses/mit-license.php">MIT License (MITL)</license>
|
| 7 |
<channel>community</channel>
|
|
@@ -37,17 +37,11 @@
|
|
| 37 |
<p>So you have the option to easily track events handled by this extension and check for possible problems.</p>
|
| 38 |

|
| 39 |
</description>
|
| 40 |
-
<notes>
|
| 41 |
-

|
| 42 |
-
Features: 
|
| 43 |
-

|
| 44 |
-
+ simple configuration via backend
|
| 45 |
-
+ simulate auto assigning image without changing products
|
| 46 |
-
+ specify required image types to be copied from parent product to child </notes>
|
| 47 |
<authors><author><name>Matthias Kerstner</name><user>mkbothinteract</user><email>matthias@both-interact.com</email></author></authors>
|
| 48 |
-
<date>2015-
|
| 49 |
-
<time>
|
| 50 |
-
<contents><target name="magecommunity"><dir name="BothInteract"><dir name="ConfigurableProductVariantsImageAssignment"><dir name="Model"><file name="Observer.php" hash="
|
| 51 |
<compatible/>
|
| 52 |
-
<dependencies><required><php><min>5.3.0</min><max>5.6.
|
| 53 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>BothInteract_ConfigurableProductVariantsImageAssignment</name>
|
| 4 |
+
<version>1.3.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>
|
| 37 |
<p>So you have the option to easily track events handled by this extension and check for possible problems.</p>
|
| 38 |

|
| 39 |
</description>
|
| 40 |
+
<notes>Added missing shell script in installation package. As usual, you can find the shell script in the folder "shell".</notes>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
<authors><author><name>Matthias Kerstner</name><user>mkbothinteract</user><email>matthias@both-interact.com</email></author></authors>
|
| 42 |
+
<date>2015-04-07</date>
|
| 43 |
+
<time>14:10:10</time>
|
| 44 |
+
<contents><target name="magecommunity"><dir name="BothInteract"><dir name="ConfigurableProductVariantsImageAssignment"><dir name="Model"><file name="Observer.php" hash="5257af94ca4c72a54a4fd4e156646ec5"/><dir name="System"><dir name="Config"><dir name="Source"><file name="View.php" hash="8ea5abd7c8bf603a5bf666a24ec68595"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="a21de6ed7d48ea42587f92894ca5ae83"/><file name="system.xml" hash="cbc673f91bccab614b9a6e653f38b3a4"/><file name="adminhtml.xml" hash="17ff98ec54bdda6275f8024ee5d5d39f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><dir name="BothInteract_BothInteract"><dir name="ConfigurableProductVariantsImageAssignment"><file name="BothInteract_ConfigurableProductVariantsImageAssignment.xml" hash=""/></dir></dir></dir></target><target name="mage"><dir><dir name="shell"><file name="set_required_images_for_configurable_product_variants.php" hash="23c00b4a92639d329fbfa6929cd54985"/></dir></dir></target></contents>
|
| 45 |
<compatible/>
|
| 46 |
+
<dependencies><required><php><min>5.3.0</min><max>5.6.6</max></php></required></dependencies>
|
| 47 |
</package>
|
shell/set_required_images_for_configurable_product_variants.php
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
require_once 'abstract.php';
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* @author Matthias Kerstner <matthias@both-interact.com>
|
| 7 |
+
* @version 1.3.0
|
| 8 |
+
* @copyright (c) 2015, Both Interact GmbH
|
| 9 |
+
*/
|
| 10 |
+
class Mage_Shell_Set_Required_Images_For_Configurable_Product_Variants extends Mage_Shell_Abstract {
|
| 11 |
+
|
| 12 |
+
const PAGE_SIZE = 100;
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Parse string with id's and return array
|
| 16 |
+
*
|
| 17 |
+
* @param string $string
|
| 18 |
+
* @return array
|
| 19 |
+
*/
|
| 20 |
+
protected function _parseString($string) {
|
| 21 |
+
$ids = array();
|
| 22 |
+
if (!empty($string)) {
|
| 23 |
+
$ids = explode(',', $string);
|
| 24 |
+
$ids = array_map('trim', $ids);
|
| 25 |
+
}
|
| 26 |
+
return $ids;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Run script based on CL options specified.
|
| 31 |
+
*/
|
| 32 |
+
public function run() {
|
| 33 |
+
if ($this->getArg('products')) {
|
| 34 |
+
|
| 35 |
+
// switch to admin event area
|
| 36 |
+
Mage::app()->addEventArea('admin');
|
| 37 |
+
|
| 38 |
+
// product model observer to be called on products
|
| 39 |
+
$productModelObserver = new BothInteract_ConfigurableProductVariantsImageAssignment_Model_Observer();
|
| 40 |
+
|
| 41 |
+
//allowed attribute types
|
| 42 |
+
$types = array('varchar', 'text', 'decimal', 'datetime', 'int');
|
| 43 |
+
|
| 44 |
+
//attribute sets array
|
| 45 |
+
$attributeSets = array();
|
| 46 |
+
|
| 47 |
+
//user defined attribute ids
|
| 48 |
+
$entityType = Mage::getModel('eav/entity_type')
|
| 49 |
+
->loadByCode('catalog_product');
|
| 50 |
+
|
| 51 |
+
//connection for raw queries
|
| 52 |
+
$connection = Mage::getSingleton('core/resource')
|
| 53 |
+
->getConnection('core_write');
|
| 54 |
+
|
| 55 |
+
$attributeCollection = $entityType
|
| 56 |
+
->getAttributeCollection()
|
| 57 |
+
->addFilter('is_user_defined', '1')
|
| 58 |
+
->getItems();
|
| 59 |
+
$attrIds = array();
|
| 60 |
+
foreach ($attributeCollection as $attribute) {
|
| 61 |
+
$attrIds[] = $attribute->getId();
|
| 62 |
+
}
|
| 63 |
+
$userDefined = implode(',', $attrIds);
|
| 64 |
+
|
| 65 |
+
//product collection based on attribute filters
|
| 66 |
+
$collection = Mage::getModel('catalog/product')->getCollection();
|
| 67 |
+
$entityTable = $collection
|
| 68 |
+
->getTable(Mage::getModel('eav/entity_type')
|
| 69 |
+
->loadByCode('catalog_product')
|
| 70 |
+
->getEntityTable());
|
| 71 |
+
|
| 72 |
+
// load only configurable products
|
| 73 |
+
$collection->addAttributeToFilter('type_id', array('eq' => 'configurable'));
|
| 74 |
+
|
| 75 |
+
// load product IDs specified only
|
| 76 |
+
if ($this->getArg('products') != 'all') {
|
| 77 |
+
if ($ids = $this->_parseString($this->getArg('products'))) {
|
| 78 |
+
$collection->addAttributeToFilter('entity_id', array('in' => $ids));
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
$collection->setPageSize(self::PAGE_SIZE);
|
| 82 |
+
|
| 83 |
+
$pages = $collection->getLastPageNumber();
|
| 84 |
+
$currentPage = 1;
|
| 85 |
+
|
| 86 |
+
//light product collection iterating
|
| 87 |
+
while ($currentPage <= $pages) {
|
| 88 |
+
|
| 89 |
+
echo 'Processing page ' . $currentPage . ' of ' . $pages
|
| 90 |
+
. '...' . PHP_EOL;
|
| 91 |
+
|
| 92 |
+
$collection->setCurPage($currentPage);
|
| 93 |
+
$collection->load();
|
| 94 |
+
|
| 95 |
+
foreach ($collection->getItems() as $item) {
|
| 96 |
+
|
| 97 |
+
// load product to manipulate
|
| 98 |
+
$product = Mage::getModel('catalog/product')
|
| 99 |
+
->load($item->getId());
|
| 100 |
+
|
| 101 |
+
// manually call our observer to update child products
|
| 102 |
+
$productModelObserver->processProduct($product);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
$currentPage++;
|
| 106 |
+
$collection->clear();
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
echo 'Done!' . PHP_EOL;
|
| 110 |
+
} else {
|
| 111 |
+
echo $this->usageHelp();
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
* Retrieve Usage Help Message
|
| 117 |
+
*
|
| 118 |
+
*/
|
| 119 |
+
public function usageHelp() {
|
| 120 |
+
return <<<USAGE
|
| 121 |
+
|
| 122 |
+
Usage: php -f set_required_images_for_configurable_product_variants -- [options]
|
| 123 |
+
|
| 124 |
+
--products all Fix all products
|
| 125 |
+
--products <product_ids> Fix products by ids
|
| 126 |
+
help This help
|
| 127 |
+
|
| 128 |
+
<product_ids> Comma separated id's of products
|
| 129 |
+
|
| 130 |
+
USAGE;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
$shell = new Mage_Shell_Set_Required_Images_For_Configurable_Product_Variants();
|
| 136 |
+
$shell->run();
|
