Version Notes
Fixed Not Showing Gallery Images
Download this release
Release Info
| Developer | WebCreta |
| Extension | webcreta_import_gallery |
| Version | 1.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0
- app/code/community/Webcreta/GalleryImport/Helper/Data.php +6 -0
- app/code/community/Webcreta/GalleryImport/Model/Convert/Adapter/Product.php +879 -0
- app/code/community/Webcreta/GalleryImport/etc/config.xml +18 -0
- app/etc/modules/Webcreta_GalleryImport.xml +9 -0
- package.xml +22 -0
- sample-csv/sample-gallery-product-import.csv +2 -0
app/code/community/Webcreta/GalleryImport/Helper/Data.php
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Webcreta_GalleryImport_Helper_Data extends Mage_Core_Helper_Abstract
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
}
|
app/code/community/Webcreta/GalleryImport/Model/Convert/Adapter/Product.php
ADDED
|
@@ -0,0 +1,879 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Import Multiple Images during Product Import
|
| 4 |
+
*
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
class Webcreta_GalleryImport_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product
|
| 8 |
+
{
|
| 9 |
+
const MULTI_DELIMITER = ' , ';
|
| 10 |
+
const ENTITY = 'catalog_product_import';
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Event prefix
|
| 14 |
+
*
|
| 15 |
+
* @var string
|
| 16 |
+
*/
|
| 17 |
+
protected $_eventPrefix = 'catalog_product_import';
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Product model
|
| 21 |
+
*
|
| 22 |
+
* @var Mage_Catalog_Model_Product
|
| 23 |
+
*/
|
| 24 |
+
protected $_productModel;
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* product types collection array
|
| 28 |
+
*
|
| 29 |
+
* @var array
|
| 30 |
+
*/
|
| 31 |
+
protected $_productTypes;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Product Type Instances singletons
|
| 35 |
+
*
|
| 36 |
+
* @var array
|
| 37 |
+
*/
|
| 38 |
+
protected $_productTypeInstances = array();
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* product attribute set collection array
|
| 42 |
+
*
|
| 43 |
+
* @var array
|
| 44 |
+
*/
|
| 45 |
+
protected $_productAttributeSets;
|
| 46 |
+
|
| 47 |
+
protected $_stores;
|
| 48 |
+
|
| 49 |
+
protected $_attributes = array();
|
| 50 |
+
|
| 51 |
+
protected $_configs = array();
|
| 52 |
+
|
| 53 |
+
protected $_requiredFields = array();
|
| 54 |
+
|
| 55 |
+
protected $_ignoreFields = array();
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* @deprecated after 1.5.0.0-alpha2
|
| 59 |
+
*
|
| 60 |
+
* @var array
|
| 61 |
+
*/
|
| 62 |
+
protected $_imageFields = array();
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Inventory Fields array
|
| 66 |
+
*
|
| 67 |
+
* @var array
|
| 68 |
+
*/
|
| 69 |
+
protected $_inventoryFields = array();
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Inventory Fields by product Types
|
| 73 |
+
*
|
| 74 |
+
* @var array
|
| 75 |
+
*/
|
| 76 |
+
protected $_inventoryFieldsProductTypes = array();
|
| 77 |
+
|
| 78 |
+
protected $_toNumber = array();
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Gallery backend model
|
| 82 |
+
*
|
| 83 |
+
* @var Mage_Catalog_Model_Product_Attribute_Backend_Media
|
| 84 |
+
*/
|
| 85 |
+
protected $_galleryBackendModel;
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Retrieve event prefix for adapter
|
| 89 |
+
*
|
| 90 |
+
* @return string
|
| 91 |
+
*/
|
| 92 |
+
public function getEventPrefix()
|
| 93 |
+
{
|
| 94 |
+
return $this->_eventPrefix;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Affected entity ids
|
| 99 |
+
*
|
| 100 |
+
* @var array
|
| 101 |
+
*/
|
| 102 |
+
protected $_affectedEntityIds = array();
|
| 103 |
+
|
| 104 |
+
/**
|
| 105 |
+
* Store affected entity ids
|
| 106 |
+
*
|
| 107 |
+
* @param int|array $ids
|
| 108 |
+
* @return Mage_Catalog_Model_Convert_Adapter_Product
|
| 109 |
+
*/
|
| 110 |
+
protected function _addAffectedEntityIds($ids)
|
| 111 |
+
{
|
| 112 |
+
if (is_array($ids)) {
|
| 113 |
+
foreach ($ids as $id) {
|
| 114 |
+
$this->_addAffectedEntityIds($id);
|
| 115 |
+
}
|
| 116 |
+
} else {
|
| 117 |
+
$this->_affectedEntityIds[] = $ids;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
return $this;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* Retrieve affected entity ids
|
| 125 |
+
*
|
| 126 |
+
* @return array
|
| 127 |
+
*/
|
| 128 |
+
public function getAffectedEntityIds()
|
| 129 |
+
{
|
| 130 |
+
return $this->_affectedEntityIds;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Clear affected entity ids results
|
| 135 |
+
*
|
| 136 |
+
* @return Mage_Catalog_Model_Convert_Adapter_Product
|
| 137 |
+
*/
|
| 138 |
+
public function clearAffectedEntityIds()
|
| 139 |
+
{
|
| 140 |
+
$this->_affectedEntityIds = array();
|
| 141 |
+
return $this;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Load product collection Id(s)
|
| 146 |
+
*/
|
| 147 |
+
public function load()
|
| 148 |
+
{
|
| 149 |
+
$attrFilterArray = array();
|
| 150 |
+
$attrFilterArray ['name'] = 'like';
|
| 151 |
+
$attrFilterArray ['sku'] = 'startsWith';
|
| 152 |
+
$attrFilterArray ['type'] = 'eq';
|
| 153 |
+
$attrFilterArray ['attribute_set'] = 'eq';
|
| 154 |
+
$attrFilterArray ['visibility'] = 'eq';
|
| 155 |
+
$attrFilterArray ['status'] = 'eq';
|
| 156 |
+
$attrFilterArray ['price'] = 'fromTo';
|
| 157 |
+
$attrFilterArray ['qty'] = 'fromTo';
|
| 158 |
+
$attrFilterArray ['store_id'] = 'eq';
|
| 159 |
+
|
| 160 |
+
$attrToDb = array(
|
| 161 |
+
'type' => 'type_id',
|
| 162 |
+
'attribute_set' => 'attribute_set_id'
|
| 163 |
+
);
|
| 164 |
+
|
| 165 |
+
$filters = $this->_parseVars();
|
| 166 |
+
|
| 167 |
+
if ($qty = $this->getFieldValue($filters, 'qty')) {
|
| 168 |
+
$qtyFrom = isset($qty['from']) ? (float) $qty['from'] : 0;
|
| 169 |
+
$qtyTo = isset($qty['to']) ? (float) $qty['to'] : 0;
|
| 170 |
+
|
| 171 |
+
$qtyAttr = array();
|
| 172 |
+
$qtyAttr['alias'] = 'qty';
|
| 173 |
+
$qtyAttr['attribute'] = 'cataloginventory/stock_item';
|
| 174 |
+
$qtyAttr['field'] = 'qty';
|
| 175 |
+
$qtyAttr['bind'] = 'product_id=entity_id';
|
| 176 |
+
$qtyAttr['cond'] = "{{table}}.qty between '{$qtyFrom}' AND '{$qtyTo}'";
|
| 177 |
+
$qtyAttr['joinType'] = 'inner';
|
| 178 |
+
|
| 179 |
+
$this->setJoinField($qtyAttr);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
parent::setFilter($attrFilterArray, $attrToDb);
|
| 183 |
+
|
| 184 |
+
if ($price = $this->getFieldValue($filters, 'price')) {
|
| 185 |
+
$this->_filter[] = array(
|
| 186 |
+
'attribute' => 'price',
|
| 187 |
+
'from' => $price['from'],
|
| 188 |
+
'to' => $price['to']
|
| 189 |
+
);
|
| 190 |
+
$this->setJoinAttr(array(
|
| 191 |
+
'alias' => 'price',
|
| 192 |
+
'attribute' => 'catalog_product/price',
|
| 193 |
+
'bind' => 'entity_id',
|
| 194 |
+
'joinType' => 'LEFT'
|
| 195 |
+
));
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
return parent::load();
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
/**
|
| 202 |
+
* Retrieve product model cache
|
| 203 |
+
*
|
| 204 |
+
* @return Mage_Catalog_Model_Product
|
| 205 |
+
*/
|
| 206 |
+
public function getProductModel()
|
| 207 |
+
{
|
| 208 |
+
if (is_null($this->_productModel)) {
|
| 209 |
+
$productModel = Mage::getModel('catalog/product');
|
| 210 |
+
$this->_productModel = Mage::objects()->save($productModel);
|
| 211 |
+
}
|
| 212 |
+
return Mage::objects()->load($this->_productModel);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
/**
|
| 216 |
+
* Retrieve eav entity attribute model
|
| 217 |
+
*
|
| 218 |
+
* @param string $code
|
| 219 |
+
* @return Mage_Eav_Model_Entity_Attribute
|
| 220 |
+
*/
|
| 221 |
+
public function getAttribute($code)
|
| 222 |
+
{
|
| 223 |
+
if (!isset($this->_attributes[$code])) {
|
| 224 |
+
$this->_attributes[$code] = $this->getProductModel()->getResource()->getAttribute($code);
|
| 225 |
+
}
|
| 226 |
+
if ($this->_attributes[$code] instanceof Mage_Catalog_Model_Resource_Eav_Attribute) {
|
| 227 |
+
$applyTo = $this->_attributes[$code]->getApplyTo();
|
| 228 |
+
if ($applyTo && !in_array($this->getProductModel()->getTypeId(), $applyTo)) {
|
| 229 |
+
return false;
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
return $this->_attributes[$code];
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
/**
|
| 236 |
+
* Retrieve product type collection array
|
| 237 |
+
*
|
| 238 |
+
* @return array
|
| 239 |
+
*/
|
| 240 |
+
public function getProductTypes()
|
| 241 |
+
{
|
| 242 |
+
if (is_null($this->_productTypes)) {
|
| 243 |
+
$this->_productTypes = array();
|
| 244 |
+
$options = Mage::getModel('catalog/product_type')
|
| 245 |
+
->getOptionArray();
|
| 246 |
+
foreach ($options as $k => $v) {
|
| 247 |
+
$this->_productTypes[$k] = $k;
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
return $this->_productTypes;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
/**
|
| 254 |
+
* ReDefine Product Type Instance to Product
|
| 255 |
+
*
|
| 256 |
+
* @param Mage_Catalog_Model_Product $product
|
| 257 |
+
* @return Mage_Catalog_Model_Convert_Adapter_Product
|
| 258 |
+
*/
|
| 259 |
+
public function setProductTypeInstance(Mage_Catalog_Model_Product $product)
|
| 260 |
+
{
|
| 261 |
+
$type = $product->getTypeId();
|
| 262 |
+
if (!isset($this->_productTypeInstances[$type])) {
|
| 263 |
+
$this->_productTypeInstances[$type] = Mage::getSingleton('catalog/product_type')
|
| 264 |
+
->factory($product, true);
|
| 265 |
+
}
|
| 266 |
+
$product->setTypeInstance($this->_productTypeInstances[$type], true);
|
| 267 |
+
return $this;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/**
|
| 271 |
+
* Retrieve product attribute set collection array
|
| 272 |
+
*
|
| 273 |
+
* @return array
|
| 274 |
+
*/
|
| 275 |
+
public function getProductAttributeSets()
|
| 276 |
+
{
|
| 277 |
+
if (is_null($this->_productAttributeSets)) {
|
| 278 |
+
$this->_productAttributeSets = array();
|
| 279 |
+
|
| 280 |
+
$entityTypeId = Mage::getModel('eav/entity')
|
| 281 |
+
->setType('catalog_product')
|
| 282 |
+
->getTypeId();
|
| 283 |
+
$collection = Mage::getResourceModel('eav/entity_attribute_set_collection')
|
| 284 |
+
->setEntityTypeFilter($entityTypeId);
|
| 285 |
+
foreach ($collection as $set) {
|
| 286 |
+
$this->_productAttributeSets[$set->getAttributeSetName()] = $set->getId();
|
| 287 |
+
}
|
| 288 |
+
}
|
| 289 |
+
return $this->_productAttributeSets;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
/**
|
| 293 |
+
* Init stores
|
| 294 |
+
*/
|
| 295 |
+
protected function _initStores ()
|
| 296 |
+
{
|
| 297 |
+
if (is_null($this->_stores)) {
|
| 298 |
+
$this->_stores = Mage::app()->getStores(true, true);
|
| 299 |
+
foreach ($this->_stores as $code => $store) {
|
| 300 |
+
$this->_storesIdCode[$store->getId()] = $code;
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
/**
|
| 306 |
+
* Retrieve store object by code
|
| 307 |
+
*
|
| 308 |
+
* @param string $store
|
| 309 |
+
* @return Mage_Core_Model_Store
|
| 310 |
+
*/
|
| 311 |
+
public function getStoreByCode($store)
|
| 312 |
+
{
|
| 313 |
+
$this->_initStores();
|
| 314 |
+
/**
|
| 315 |
+
* In single store mode all data should be saved as default
|
| 316 |
+
*/
|
| 317 |
+
if (Mage::app()->isSingleStoreMode()) {
|
| 318 |
+
return Mage::app()->getStore(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
if (isset($this->_stores[$store])) {
|
| 322 |
+
return $this->_stores[$store];
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
return false;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
/**
|
| 329 |
+
* Retrieve store object by code
|
| 330 |
+
*
|
| 331 |
+
* @param string $store
|
| 332 |
+
* @return Mage_Core_Model_Store
|
| 333 |
+
*/
|
| 334 |
+
public function getStoreById($id)
|
| 335 |
+
{
|
| 336 |
+
$this->_initStores();
|
| 337 |
+
/**
|
| 338 |
+
* In single store mode all data should be saved as default
|
| 339 |
+
*/
|
| 340 |
+
if (Mage::app()->isSingleStoreMode()) {
|
| 341 |
+
return Mage::app()->getStore(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
if (isset($this->_storesIdCode[$id])) {
|
| 345 |
+
return $this->getStoreByCode($this->_storesIdCode[$id]);
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
return false;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
public function parse()
|
| 352 |
+
{
|
| 353 |
+
$batchModel = Mage::getSingleton('dataflow/batch');
|
| 354 |
+
/* @var $batchModel Mage_Dataflow_Model_Batch */
|
| 355 |
+
|
| 356 |
+
$batchImportModel = $batchModel->getBatchImportModel();
|
| 357 |
+
$importIds = $batchImportModel->getIdCollection();
|
| 358 |
+
|
| 359 |
+
foreach ($importIds as $importId) {
|
| 360 |
+
//print '<pre>'.memory_get_usage().'</pre>';
|
| 361 |
+
$batchImportModel->load($importId);
|
| 362 |
+
$importData = $batchImportModel->getBatchData();
|
| 363 |
+
|
| 364 |
+
$this->saveRow($importData);
|
| 365 |
+
}
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
protected $_productId = '';
|
| 369 |
+
|
| 370 |
+
/**
|
| 371 |
+
* Initialize convert adapter model for products collection
|
| 372 |
+
*
|
| 373 |
+
*/
|
| 374 |
+
public function __construct()
|
| 375 |
+
{
|
| 376 |
+
$fieldset = Mage::getConfig()->getFieldset('catalog_product_dataflow', 'admin');
|
| 377 |
+
foreach ($fieldset as $code => $node) {
|
| 378 |
+
/* @var $node Mage_Core_Model_Config_Element */
|
| 379 |
+
if ($node->is('inventory')) {
|
| 380 |
+
foreach ($node->product_type->children() as $productType) {
|
| 381 |
+
$productType = $productType->getName();
|
| 382 |
+
$this->_inventoryFieldsProductTypes[$productType][] = $code;
|
| 383 |
+
if ($node->is('use_config')) {
|
| 384 |
+
$this->_inventoryFieldsProductTypes[$productType][] = 'use_config_' . $code;
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
$this->_inventoryFields[] = $code;
|
| 389 |
+
if ($node->is('use_config')) {
|
| 390 |
+
$this->_inventoryFields[] = 'use_config_'.$code;
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
if ($node->is('required')) {
|
| 394 |
+
$this->_requiredFields[] = $code;
|
| 395 |
+
}
|
| 396 |
+
if ($node->is('ignore')) {
|
| 397 |
+
$this->_ignoreFields[] = $code;
|
| 398 |
+
}
|
| 399 |
+
if ($node->is('to_number')) {
|
| 400 |
+
$this->_toNumber[] = $code;
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
$this->setVar('entity_type', 'catalog/product');
|
| 405 |
+
if (!Mage::registry('Object_Cache_Product')) {
|
| 406 |
+
$this->setProduct(Mage::getModel('catalog/product'));
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
if (!Mage::registry('Object_Cache_StockItem')) {
|
| 410 |
+
$this->setStockItem(Mage::getModel('cataloginventory/stock_item'));
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
$this->_galleryBackendModel = $this->getAttribute('media_gallery')->getBackend();
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
/**
|
| 417 |
+
* Retrieve not loaded collection
|
| 418 |
+
*
|
| 419 |
+
* @param string $entityType
|
| 420 |
+
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
|
| 421 |
+
*/
|
| 422 |
+
protected function _getCollectionForLoad($entityType)
|
| 423 |
+
{
|
| 424 |
+
$collection = parent::_getCollectionForLoad($entityType)
|
| 425 |
+
->setStoreId($this->getStoreId())
|
| 426 |
+
->addStoreFilter($this->getStoreId());
|
| 427 |
+
return $collection;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
public function setProduct(Mage_Catalog_Model_Product $object)
|
| 431 |
+
{
|
| 432 |
+
$id = Mage::objects()->save($object);
|
| 433 |
+
//$this->_product = $object;
|
| 434 |
+
Mage::register('Object_Cache_Product', $id);
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
public function getProduct()
|
| 438 |
+
{
|
| 439 |
+
return Mage::objects()->load(Mage::registry('Object_Cache_Product'));
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
public function setStockItem(Mage_CatalogInventory_Model_Stock_Item $object)
|
| 443 |
+
{
|
| 444 |
+
$id = Mage::objects()->save($object);
|
| 445 |
+
Mage::register('Object_Cache_StockItem', $id);
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
public function getStockItem()
|
| 449 |
+
{
|
| 450 |
+
return Mage::objects()->load(Mage::registry('Object_Cache_StockItem'));
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
public function save()
|
| 454 |
+
{
|
| 455 |
+
$stores = array();
|
| 456 |
+
foreach (Mage::getConfig()->getNode('stores')->children() as $storeNode) {
|
| 457 |
+
$stores[(int)$storeNode->system->store->id] = $storeNode->getName();
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
$collections = $this->getData();
|
| 461 |
+
if ($collections instanceof Mage_Catalog_Model_Entity_Product_Collection) {
|
| 462 |
+
$collections = array($collections->getEntity()->getStoreId()=>$collections);
|
| 463 |
+
} elseif (!is_array($collections)) {
|
| 464 |
+
$this->addException(
|
| 465 |
+
Mage::helper('catalog')->__('No product collections found.'),
|
| 466 |
+
Mage_Dataflow_Model_Convert_Exception::FATAL
|
| 467 |
+
);
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
$stockItems = Mage::registry('current_imported_inventory');
|
| 471 |
+
if ($collections) foreach ($collections as $storeId=>$collection) {
|
| 472 |
+
$this->addException(Mage::helper('catalog')->__('Records for "%s" store found.', $stores[$storeId]));
|
| 473 |
+
|
| 474 |
+
if (!$collection instanceof Mage_Catalog_Model_Entity_Product_Collection) {
|
| 475 |
+
$this->addException(
|
| 476 |
+
Mage::helper('catalog')->__('Product collection expected.'),
|
| 477 |
+
Mage_Dataflow_Model_Convert_Exception::FATAL
|
| 478 |
+
);
|
| 479 |
+
}
|
| 480 |
+
try {
|
| 481 |
+
$i = 0;
|
| 482 |
+
foreach ($collection->getIterator() as $model) {
|
| 483 |
+
$new = false;
|
| 484 |
+
// if product is new, create default values first
|
| 485 |
+
if (!$model->getId()) {
|
| 486 |
+
$new = true;
|
| 487 |
+
$model->save();
|
| 488 |
+
|
| 489 |
+
// if new product and then store is not default
|
| 490 |
+
// we duplicate product as default product with store_id -
|
| 491 |
+
if (0 !== $storeId ) {
|
| 492 |
+
$data = $model->getData();
|
| 493 |
+
$default = Mage::getModel('catalog/product');
|
| 494 |
+
$default->setData($data);
|
| 495 |
+
$default->setStoreId(0);
|
| 496 |
+
$default->save();
|
| 497 |
+
unset($default);
|
| 498 |
+
} // end
|
| 499 |
+
|
| 500 |
+
#Mage::getResourceSingleton('catalog_entity/convert')->addProductToStore($model->getId(), 0);
|
| 501 |
+
}
|
| 502 |
+
if (!$new || 0!==$storeId) {
|
| 503 |
+
if (0!==$storeId) {
|
| 504 |
+
Mage::getResourceSingleton('catalog_entity/convert')->addProductToStore(
|
| 505 |
+
$model->getId(),
|
| 506 |
+
$storeId
|
| 507 |
+
);
|
| 508 |
+
}
|
| 509 |
+
$model->save();
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
if (isset($stockItems[$model->getSku()]) && $stock = $stockItems[$model->getSku()]) {
|
| 513 |
+
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($model->getId());
|
| 514 |
+
$stockItemId = $stockItem->getId();
|
| 515 |
+
|
| 516 |
+
if (!$stockItemId) {
|
| 517 |
+
$stockItem->setData('product_id', $model->getId());
|
| 518 |
+
$stockItem->setData('stock_id', 1);
|
| 519 |
+
$data = array();
|
| 520 |
+
} else {
|
| 521 |
+
$data = $stockItem->getData();
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
foreach($stock as $field => $value) {
|
| 525 |
+
if (!$stockItemId) {
|
| 526 |
+
if (in_array($field, $this->_configs)) {
|
| 527 |
+
$stockItem->setData('use_config_'.$field, 0);
|
| 528 |
+
}
|
| 529 |
+
$stockItem->setData($field, $value?$value:0);
|
| 530 |
+
} else {
|
| 531 |
+
|
| 532 |
+
if (in_array($field, $this->_configs)) {
|
| 533 |
+
if ($data['use_config_'.$field] == 0) {
|
| 534 |
+
$stockItem->setData($field, $value?$value:0);
|
| 535 |
+
}
|
| 536 |
+
} else {
|
| 537 |
+
$stockItem->setData($field, $value?$value:0);
|
| 538 |
+
}
|
| 539 |
+
}
|
| 540 |
+
}
|
| 541 |
+
$stockItem->save();
|
| 542 |
+
unset($data);
|
| 543 |
+
unset($stockItem);
|
| 544 |
+
unset($stockItemId);
|
| 545 |
+
}
|
| 546 |
+
unset($model);
|
| 547 |
+
$i++;
|
| 548 |
+
}
|
| 549 |
+
$this->addException(Mage::helper('catalog')->__("Saved %d record(s)", $i));
|
| 550 |
+
} catch (Exception $e) {
|
| 551 |
+
if (!$e instanceof Mage_Dataflow_Model_Convert_Exception) {
|
| 552 |
+
$this->addException(
|
| 553 |
+
Mage::helper('catalog')->__('An error occurred while saving the collection, aborting. Error message: %s', $e->getMessage()),
|
| 554 |
+
Mage_Dataflow_Model_Convert_Exception::FATAL
|
| 555 |
+
);
|
| 556 |
+
}
|
| 557 |
+
}
|
| 558 |
+
}
|
| 559 |
+
unset($collections);
|
| 560 |
+
|
| 561 |
+
return $this;
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
/**
|
| 565 |
+
* Save data row with gallery image info only
|
| 566 |
+
*
|
| 567 |
+
* @param Mage_Catalog_Model_Product $product
|
| 568 |
+
* @param array $importData
|
| 569 |
+
*
|
| 570 |
+
* @return Mage_Catalog_Model_Convert_Adapter_Product
|
| 571 |
+
*/
|
| 572 |
+
public function saveImageDataRow($product, $importData)
|
| 573 |
+
{
|
| 574 |
+
$imageData = array(
|
| 575 |
+
'label' => $importData['_media_lable'],
|
| 576 |
+
'position' => $importData['_media_position'],
|
| 577 |
+
'disabled' => $importData['_media_is_disabled']
|
| 578 |
+
);
|
| 579 |
+
|
| 580 |
+
$imageFile = trim($importData['_media_image']);
|
| 581 |
+
$imageFile = ltrim($imageFile, DS);
|
| 582 |
+
$imageFilePath = Mage::getBaseDir('media') . DS . 'import' . DS . $imageFile;
|
| 583 |
+
|
| 584 |
+
$updatedFileName = $this->_galleryBackendModel->addImage($product, $imageFilePath, null, false,
|
| 585 |
+
(bool) $importData['_media_is_disabled']);
|
| 586 |
+
$this->_galleryBackendModel->updateImage($product, $updatedFileName, $imageData);
|
| 587 |
+
|
| 588 |
+
$this->_addAffectedEntityIds($product->getId());
|
| 589 |
+
$product->setIsMassupdate(true)
|
| 590 |
+
->setExcludeUrlRewrite(true)
|
| 591 |
+
->save();
|
| 592 |
+
|
| 593 |
+
return $this;
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
/**
|
| 597 |
+
* Save product (import)
|
| 598 |
+
*
|
| 599 |
+
* @param array $importData
|
| 600 |
+
* @throws Mage_Core_Exception
|
| 601 |
+
* @return bool
|
| 602 |
+
*/
|
| 603 |
+
public function saveRow(array $importData)
|
| 604 |
+
{
|
| 605 |
+
$product = $this->getProductModel()
|
| 606 |
+
->reset();
|
| 607 |
+
|
| 608 |
+
if (empty($importData['store'])) {
|
| 609 |
+
if (!is_null($this->getBatchParams('store'))) {
|
| 610 |
+
$store = $this->getStoreById($this->getBatchParams('store'));
|
| 611 |
+
} else {
|
| 612 |
+
$message = Mage::helper('catalog')->__('Skipping import row, required field "%s" is not defined.', 'store');
|
| 613 |
+
Mage::throwException($message);
|
| 614 |
+
}
|
| 615 |
+
} else {
|
| 616 |
+
$store = $this->getStoreByCode($importData['store']);
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
if ($store === false) {
|
| 620 |
+
$message = Mage::helper('catalog')->__('Skipping import row, store "%s" field does not exist.', $importData['store']);
|
| 621 |
+
Mage::throwException($message);
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
if (empty($importData['sku'])) {
|
| 625 |
+
$message = Mage::helper('catalog')->__('Skipping import row, required field "%s" is not defined.', 'sku');
|
| 626 |
+
Mage::throwException($message);
|
| 627 |
+
}
|
| 628 |
+
$product->setStoreId($store->getId());
|
| 629 |
+
$productId = $product->getIdBySku($importData['sku']);
|
| 630 |
+
|
| 631 |
+
if ($productId) {
|
| 632 |
+
$product->load($productId);
|
| 633 |
+
} else {
|
| 634 |
+
$productTypes = $this->getProductTypes();
|
| 635 |
+
$productAttributeSets = $this->getProductAttributeSets();
|
| 636 |
+
|
| 637 |
+
/**
|
| 638 |
+
* Check product define type
|
| 639 |
+
*/
|
| 640 |
+
if (empty($importData['type']) || !isset($productTypes[strtolower($importData['type'])])) {
|
| 641 |
+
$value = isset($importData['type']) ? $importData['type'] : '';
|
| 642 |
+
$message = Mage::helper('catalog')->__('Skip import row, is not valid value "%s" for field "%s"', $value, 'type');
|
| 643 |
+
Mage::throwException($message);
|
| 644 |
+
}
|
| 645 |
+
$product->setTypeId($productTypes[strtolower($importData['type'])]);
|
| 646 |
+
/**
|
| 647 |
+
* Check product define attribute set
|
| 648 |
+
*/
|
| 649 |
+
if (empty($importData['attribute_set']) || !isset($productAttributeSets[$importData['attribute_set']])) {
|
| 650 |
+
$value = isset($importData['attribute_set']) ? $importData['attribute_set'] : '';
|
| 651 |
+
$message = Mage::helper('catalog')->__('Skip import row, the value "%s" is invalid for field "%s"', $value, 'attribute_set');
|
| 652 |
+
Mage::throwException($message);
|
| 653 |
+
}
|
| 654 |
+
$product->setAttributeSetId($productAttributeSets[$importData['attribute_set']]);
|
| 655 |
+
|
| 656 |
+
foreach ($this->_requiredFields as $field) {
|
| 657 |
+
$attribute = $this->getAttribute($field);
|
| 658 |
+
if (!isset($importData[$field]) && $attribute && $attribute->getIsRequired()) {
|
| 659 |
+
$message = Mage::helper('catalog')->__('Skipping import row, required field "%s" for new products is not defined.', $field);
|
| 660 |
+
Mage::throwException($message);
|
| 661 |
+
}
|
| 662 |
+
}
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
// process row with media data only
|
| 666 |
+
if (isset($importData['_media_image']) && strlen($importData['_media_image'])) {
|
| 667 |
+
$this->saveImageDataRow($product, $importData);
|
| 668 |
+
return true;
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
$this->setProductTypeInstance($product);
|
| 672 |
+
|
| 673 |
+
if (isset($importData['category_ids'])) {
|
| 674 |
+
$product->setCategoryIds($importData['category_ids']);
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
foreach ($this->_ignoreFields as $field) {
|
| 678 |
+
if (isset($importData[$field])) {
|
| 679 |
+
unset($importData[$field]);
|
| 680 |
+
}
|
| 681 |
+
}
|
| 682 |
+
|
| 683 |
+
if ($store->getId() != 0) {
|
| 684 |
+
$websiteIds = $product->getWebsiteIds();
|
| 685 |
+
if (!is_array($websiteIds)) {
|
| 686 |
+
$websiteIds = array();
|
| 687 |
+
}
|
| 688 |
+
if (!in_array($store->getWebsiteId(), $websiteIds)) {
|
| 689 |
+
$websiteIds[] = $store->getWebsiteId();
|
| 690 |
+
}
|
| 691 |
+
$product->setWebsiteIds($websiteIds);
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
if (isset($importData['websites'])) {
|
| 695 |
+
$websiteIds = $product->getWebsiteIds();
|
| 696 |
+
if (!is_array($websiteIds) || !$store->getId()) {
|
| 697 |
+
$websiteIds = array();
|
| 698 |
+
}
|
| 699 |
+
$websiteCodes = explode(',', $importData['websites']);
|
| 700 |
+
foreach ($websiteCodes as $websiteCode) {
|
| 701 |
+
try {
|
| 702 |
+
$website = Mage::app()->getWebsite(trim($websiteCode));
|
| 703 |
+
if (!in_array($website->getId(), $websiteIds)) {
|
| 704 |
+
$websiteIds[] = $website->getId();
|
| 705 |
+
}
|
| 706 |
+
} catch (Exception $e) {}
|
| 707 |
+
}
|
| 708 |
+
$product->setWebsiteIds($websiteIds);
|
| 709 |
+
unset($websiteIds);
|
| 710 |
+
}
|
| 711 |
+
|
| 712 |
+
foreach ($importData as $field => $value) {
|
| 713 |
+
if (in_array($field, $this->_inventoryFields)) {
|
| 714 |
+
continue;
|
| 715 |
+
}
|
| 716 |
+
if (is_null($value)) {
|
| 717 |
+
continue;
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
$attribute = $this->getAttribute($field);
|
| 721 |
+
if (!$attribute) {
|
| 722 |
+
continue;
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
$isArray = false;
|
| 726 |
+
$setValue = $value;
|
| 727 |
+
|
| 728 |
+
if ($attribute->getFrontendInput() == 'multiselect') {
|
| 729 |
+
$value = explode(self::MULTI_DELIMITER, $value);
|
| 730 |
+
$isArray = true;
|
| 731 |
+
$setValue = array();
|
| 732 |
+
}
|
| 733 |
+
|
| 734 |
+
if ($value && $attribute->getBackendType() == 'decimal') {
|
| 735 |
+
$setValue = $this->getNumber($value);
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
if ($attribute->usesSource()) {
|
| 739 |
+
$options = $attribute->getSource()->getAllOptions(false);
|
| 740 |
+
|
| 741 |
+
if ($isArray) {
|
| 742 |
+
foreach ($options as $item) {
|
| 743 |
+
if (in_array($item['label'], $value)) {
|
| 744 |
+
$setValue[] = $item['value'];
|
| 745 |
+
}
|
| 746 |
+
}
|
| 747 |
+
} else {
|
| 748 |
+
$setValue = false;
|
| 749 |
+
foreach ($options as $item) {
|
| 750 |
+
if (is_array($item['value'])) {
|
| 751 |
+
foreach ($item['value'] as $subValue) {
|
| 752 |
+
if (isset($subValue['value']) && $subValue['value'] == $value) {
|
| 753 |
+
$setValue = $value;
|
| 754 |
+
}
|
| 755 |
+
}
|
| 756 |
+
} else if ($item['label'] == $value) {
|
| 757 |
+
$setValue = $item['value'];
|
| 758 |
+
}
|
| 759 |
+
}
|
| 760 |
+
}
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
$product->setData($field, $setValue);
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
if (!$product->getVisibility()) {
|
| 767 |
+
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
|
| 768 |
+
}
|
| 769 |
+
|
| 770 |
+
$stockData = array();
|
| 771 |
+
$inventoryFields = isset($this->_inventoryFieldsProductTypes[$product->getTypeId()])
|
| 772 |
+
? $this->_inventoryFieldsProductTypes[$product->getTypeId()]
|
| 773 |
+
: array();
|
| 774 |
+
foreach ($inventoryFields as $field) {
|
| 775 |
+
if (isset($importData[$field])) {
|
| 776 |
+
if (in_array($field, $this->_toNumber)) {
|
| 777 |
+
$stockData[$field] = $this->getNumber($importData[$field]);
|
| 778 |
+
} else {
|
| 779 |
+
$stockData[$field] = $importData[$field];
|
| 780 |
+
}
|
| 781 |
+
}
|
| 782 |
+
}
|
| 783 |
+
$product->setStockData($stockData);
|
| 784 |
+
|
| 785 |
+
$arrayToMassAdd = array();
|
| 786 |
+
|
| 787 |
+
foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
|
| 788 |
+
if (isset($importData[$mediaAttributeCode])) {
|
| 789 |
+
$file = trim($importData[$mediaAttributeCode]);
|
| 790 |
+
if (!empty($file) && !$this->_galleryBackendModel->getImage($product, $file)) {
|
| 791 |
+
$arrayToMassAdd[] = array('file' => trim($file), 'mediaAttribute' => $mediaAttributeCode);
|
| 792 |
+
}
|
| 793 |
+
}
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
$addedFilesCorrespondence = $this->_galleryBackendModel->addImagesWithDifferentMediaAttributes(
|
| 797 |
+
$product,
|
| 798 |
+
$arrayToMassAdd, Mage::getBaseDir('media') . DS . 'import',
|
| 799 |
+
false,
|
| 800 |
+
false
|
| 801 |
+
);
|
| 802 |
+
|
| 803 |
+
foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
|
| 804 |
+
$addedFile = '';
|
| 805 |
+
if (isset($importData[$mediaAttributeCode . '_label'])) {
|
| 806 |
+
$fileLabel = trim($importData[$mediaAttributeCode . '_label']);
|
| 807 |
+
if (isset($importData[$mediaAttributeCode])) {
|
| 808 |
+
$keyInAddedFile = array_search($importData[$mediaAttributeCode],
|
| 809 |
+
$addedFilesCorrespondence['alreadyAddedFiles']);
|
| 810 |
+
if ($keyInAddedFile !== false) {
|
| 811 |
+
$addedFile = $addedFilesCorrespondence['alreadyAddedFilesNames'][$keyInAddedFile];
|
| 812 |
+
}
|
| 813 |
+
}
|
| 814 |
+
|
| 815 |
+
if (!$addedFile) {
|
| 816 |
+
$addedFile = $product->getData($mediaAttributeCode);
|
| 817 |
+
}
|
| 818 |
+
if ($fileLabel && $addedFile) {
|
| 819 |
+
$this->_galleryBackendModel->updateImage($product, $addedFile, array('label' => $fileLabel));
|
| 820 |
+
}
|
| 821 |
+
}
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
$product->setIsMassupdate(true);
|
| 825 |
+
$product->setExcludeUrlRewrite(true);
|
| 826 |
+
/**
|
| 827 |
+
* Allows you to import multiple images for each product.
|
| 828 |
+
* Simply add a 'gallery' column to the import file, and separate
|
| 829 |
+
* each image with a semi-colon.
|
| 830 |
+
*/
|
| 831 |
+
try {
|
| 832 |
+
$galleryData = explode(';',$importData["gallery"]);
|
| 833 |
+
|
| 834 |
+
foreach($galleryData as $gallery_img){
|
| 835 |
+
$product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . $gallery_img, null, false, false);
|
| 836 |
+
}
|
| 837 |
+
}catch (Exception $e) {}
|
| 838 |
+
/* End Modification */
|
| 839 |
+
$product->save();
|
| 840 |
+
|
| 841 |
+
// Store affected products ids
|
| 842 |
+
$this->_addAffectedEntityIds($product->getId());
|
| 843 |
+
|
| 844 |
+
return true;
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
/**
|
| 848 |
+
* Silently save product (import)
|
| 849 |
+
*
|
| 850 |
+
* @param array $importData
|
| 851 |
+
* @return bool
|
| 852 |
+
*/
|
| 853 |
+
public function saveRowSilently(array $importData)
|
| 854 |
+
{
|
| 855 |
+
try {
|
| 856 |
+
$result = $this->saveRow($importData);
|
| 857 |
+
return $result;
|
| 858 |
+
} catch (Exception $e) {
|
| 859 |
+
return false;
|
| 860 |
+
}
|
| 861 |
+
}
|
| 862 |
+
|
| 863 |
+
/**
|
| 864 |
+
* Process after import data
|
| 865 |
+
* Init indexing process after catalog product import
|
| 866 |
+
*/
|
| 867 |
+
public function finish()
|
| 868 |
+
{
|
| 869 |
+
/**
|
| 870 |
+
* Back compatibility event
|
| 871 |
+
*/
|
| 872 |
+
Mage::dispatchEvent($this->_eventPrefix . '_after', array());
|
| 873 |
+
|
| 874 |
+
$entity = new Varien_Object();
|
| 875 |
+
Mage::getSingleton('index/indexer')->processEntityAction(
|
| 876 |
+
$entity, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE
|
| 877 |
+
);
|
| 878 |
+
}
|
| 879 |
+
}
|
app/code/community/Webcreta/GalleryImport/etc/config.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Webcreta_GalleryImport>
|
| 5 |
+
<version>0.1.0</version>
|
| 6 |
+
</Webcreta_GalleryImport>
|
| 7 |
+
</modules>
|
| 8 |
+
<global>
|
| 9 |
+
<models>
|
| 10 |
+
<catalog>
|
| 11 |
+
<rewrite>
|
| 12 |
+
<!-- Override Mage_Catalog_Model_Convert_Adapter_Product -->
|
| 13 |
+
<convert_adapter_product>Webcreta_GalleryImport_Model_Convert_Adapter_Product</convert_adapter_product>
|
| 14 |
+
</rewrite>
|
| 15 |
+
</catalog>
|
| 16 |
+
</models>
|
| 17 |
+
</global>
|
| 18 |
+
</config>
|
app/etc/modules/Webcreta_GalleryImport.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Webcreta_GalleryImport>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>community</codePool>
|
| 7 |
+
</Webcreta_GalleryImport>
|
| 8 |
+
</modules>
|
| 9 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>webcreta_import_gallery</name>
|
| 4 |
+
<version>1.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Webcreta Import Gallery Extension Provide ability to upload Gallery Images</summary>
|
| 10 |
+
<description>Webcreta Import Gallery Extension is very useful to upload multiple gallery images in magento via dataflow import product profile.
|
| 11 |
+

|
| 12 |
+
This Extension Support csv file to upload.Also Attached sample csv file to upload gallery images
|
| 13 |
+

|
| 14 |
+
After Uploaded file into your magento folder go to system->Import/Export -> Dataflow - Profiles and select Import All Product</description>
|
| 15 |
+
<notes>Fixed Not Showing Gallery Images</notes>
|
| 16 |
+
<authors><author><name>WebCreta</name><user>WebCreta</user><email>webcreta@gmail.com</email></author></authors>
|
| 17 |
+
<date>2016-04-16</date>
|
| 18 |
+
<time>07:39:38</time>
|
| 19 |
+
<contents><target name="magecommunity"><dir name="Webcreta"><dir name="GalleryImport"><dir name="Helper"><file name="Data.php" hash="91c234eecd9062c8d560c12a958e907d"/></dir><dir name="Model"><dir name="Convert"><dir name="Adapter"><file name="Product.php" hash="9aa1e8006e7880c7d43b6a66f2b76469"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="3cd9b365528dd06d90a93caa5f1d81b4"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Webcreta_GalleryImport.xml" hash="7cfe73ecd7936b69d156d08fcd24f4a9"/></dir></target><target name="mage"><dir name="sample-csv"><file name="sample-gallery-product-import.csv" hash="71f2af4cd1589d9c192211522caa2de7"/></dir></target></contents>
|
| 20 |
+
<compatible/>
|
| 21 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 22 |
+
</package>
|
sample-csv/sample-gallery-product-import.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
| 1 |
+
store,websites,attribute_set,type,category_ids,sku,has_options,name,meta_title,meta_description,image,small_image,thumbnail,url_key,url_path,custom_design,page_layout,options_container,image_label,small_image_label,thumbnail_label,country_of_manufacture,msrp_enabled,msrp_display_actual_price_type,gift_message_available,price,special_price,weight,msrp,status,is_recurring,visibility,tax_class_id,description,short_description,meta_keyword,custom_layout_update,special_from_date,special_to_date,news_from_date,news_to_date,custom_design_from,custom_design_to,qty,min_qty,use_config_min_qty,is_qty_decimal,backorders,use_config_backorders,min_sale_qty,use_config_min_sale_qty,max_sale_qty,use_config_max_sale_qty,is_in_stock,low_stock_date,notify_stock_qty,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,stock_status_changed_auto,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,stock_status_changed_automatically,use_config_enable_qty_increments,product_name,store_id,product_type_id,product_status_changed,product_changed_websites,gallery,website
|
| 2 |
+
admin,base,Default,simple,4,webcreta-test-product,0,Webcreta Test Product,,,/lighthouse.jpg,/penguins.jpg,/tulips-1.jpg,webcreta-test-products,webcreta-test-products.html,,No layout updates,Product Info Column,,,, ,Use config,Use config,No,100,,1,,Enabled,No,"Catalog, Search",None,Webcreta Product,Webcreta Product,,,,,,,,,1000,0,1,0,0,1,1,1,0,1,1,,,1,0,1,0,1,0,1,0,0,0,1,Webcreta Test Products,0,simple,,,/1008.jpg;/1009.jpg;/1010.jpg,
|
