Version Notes
Automatically create SKUs for products that are manually added via admin or imported via CSV of XML files.
Download this release
Release Info
Developer | Magento Core Team |
Extension | SKU_Auto_Generator |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php
DELETED
@@ -1,927 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Magento
|
4 |
-
*
|
5 |
-
* NOTICE OF LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
-
* that is bundled with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* DISCLAIMER
|
16 |
-
*
|
17 |
-
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
-
* versions in the future. If you wish to customize Magento for your
|
19 |
-
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
-
*
|
21 |
-
* @category Mage
|
22 |
-
* @package Mage_Catalog
|
23 |
-
* @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
|
24 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
-
*/
|
26 |
-
|
27 |
-
|
28 |
-
class Mage_Catalog_Model_Convert_Adapter_Product
|
29 |
-
extends Mage_Eav_Model_Convert_Adapter_Entity
|
30 |
-
{
|
31 |
-
const MULTI_DELIMITER = ' , ';
|
32 |
-
const ENTITY = 'catalog_product_import';
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Event prefix
|
36 |
-
*
|
37 |
-
* @var string
|
38 |
-
*/
|
39 |
-
protected $_eventPrefix = 'catalog_product_import';
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Product model
|
43 |
-
*
|
44 |
-
* @var Mage_Catalog_Model_Product
|
45 |
-
*/
|
46 |
-
protected $_productModel;
|
47 |
-
|
48 |
-
/**
|
49 |
-
* product types collection array
|
50 |
-
*
|
51 |
-
* @var array
|
52 |
-
*/
|
53 |
-
protected $_productTypes;
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Product Type Instances singletons
|
57 |
-
*
|
58 |
-
* @var array
|
59 |
-
*/
|
60 |
-
protected $_productTypeInstances = array();
|
61 |
-
|
62 |
-
/**
|
63 |
-
* product attribute set collection array
|
64 |
-
*
|
65 |
-
* @var array
|
66 |
-
*/
|
67 |
-
protected $_productAttributeSets;
|
68 |
-
|
69 |
-
protected $_stores;
|
70 |
-
|
71 |
-
protected $_attributes = array();
|
72 |
-
|
73 |
-
protected $_configs = array();
|
74 |
-
|
75 |
-
protected $_requiredFields = array();
|
76 |
-
|
77 |
-
protected $_ignoreFields = array();
|
78 |
-
|
79 |
-
/**
|
80 |
-
* @deprecated after 1.5.0.0-alpha2
|
81 |
-
*
|
82 |
-
* @var array
|
83 |
-
*/
|
84 |
-
protected $_imageFields = array();
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Inventory Fields array
|
88 |
-
*
|
89 |
-
* @var array
|
90 |
-
*/
|
91 |
-
protected $_inventoryFields = array();
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Inventory Fields by product Types
|
95 |
-
*
|
96 |
-
* @var array
|
97 |
-
*/
|
98 |
-
protected $_inventoryFieldsProductTypes = array();
|
99 |
-
|
100 |
-
protected $_toNumber = array();
|
101 |
-
|
102 |
-
/**
|
103 |
-
* Retrieve event prefix for adapter
|
104 |
-
*
|
105 |
-
* @return string
|
106 |
-
*/
|
107 |
-
public function getEventPrefix()
|
108 |
-
{
|
109 |
-
return $this->_eventPrefix;
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Affected entity ids
|
114 |
-
*
|
115 |
-
* @var array
|
116 |
-
*/
|
117 |
-
protected $_affectedEntityIds = array();
|
118 |
-
|
119 |
-
/**
|
120 |
-
* Store affected entity ids
|
121 |
-
*
|
122 |
-
* @param int|array $ids
|
123 |
-
* @return Mage_Catalog_Model_Convert_Adapter_Product
|
124 |
-
*/
|
125 |
-
protected function _addAffectedEntityIds($ids)
|
126 |
-
{
|
127 |
-
if (is_array($ids)) {
|
128 |
-
foreach ($ids as $id) {
|
129 |
-
$this->_addAffectedEntityIds($id);
|
130 |
-
}
|
131 |
-
} else {
|
132 |
-
$this->_affectedEntityIds[] = $ids;
|
133 |
-
}
|
134 |
-
|
135 |
-
return $this;
|
136 |
-
}
|
137 |
-
|
138 |
-
/**
|
139 |
-
* Retrieve affected entity ids
|
140 |
-
*
|
141 |
-
* @return array
|
142 |
-
*/
|
143 |
-
public function getAffectedEntityIds()
|
144 |
-
{
|
145 |
-
return $this->_affectedEntityIds;
|
146 |
-
}
|
147 |
-
|
148 |
-
/**
|
149 |
-
* Clear affected entity ids results
|
150 |
-
*
|
151 |
-
* @return Mage_Catalog_Model_Convert_Adapter_Product
|
152 |
-
*/
|
153 |
-
public function clearAffectedEntityIds()
|
154 |
-
{
|
155 |
-
$this->_affectedEntityIds = array();
|
156 |
-
return $this;
|
157 |
-
}
|
158 |
-
|
159 |
-
/**
|
160 |
-
* Load product collection Id(s)
|
161 |
-
*/
|
162 |
-
public function load()
|
163 |
-
{
|
164 |
-
$attrFilterArray = array();
|
165 |
-
$attrFilterArray ['name'] = 'like';
|
166 |
-
$attrFilterArray ['sku'] = 'startsWith';
|
167 |
-
$attrFilterArray ['type'] = 'eq';
|
168 |
-
$attrFilterArray ['attribute_set'] = 'eq';
|
169 |
-
$attrFilterArray ['visibility'] = 'eq';
|
170 |
-
$attrFilterArray ['status'] = 'eq';
|
171 |
-
$attrFilterArray ['price'] = 'fromTo';
|
172 |
-
$attrFilterArray ['qty'] = 'fromTo';
|
173 |
-
$attrFilterArray ['store_id'] = 'eq';
|
174 |
-
|
175 |
-
$attrToDb = array(
|
176 |
-
'type' => 'type_id',
|
177 |
-
'attribute_set' => 'attribute_set_id'
|
178 |
-
);
|
179 |
-
|
180 |
-
$filters = $this->_parseVars();
|
181 |
-
|
182 |
-
if ($qty = $this->getFieldValue($filters, 'qty')) {
|
183 |
-
$qtyFrom = isset($qty['from']) ? (float) $qty['from'] : 0;
|
184 |
-
$qtyTo = isset($qty['to']) ? (float) $qty['to'] : 0;
|
185 |
-
|
186 |
-
$qtyAttr = array();
|
187 |
-
$qtyAttr['alias'] = 'qty';
|
188 |
-
$qtyAttr['attribute'] = 'cataloginventory/stock_item';
|
189 |
-
$qtyAttr['field'] = 'qty';
|
190 |
-
$qtyAttr['bind'] = 'product_id=entity_id';
|
191 |
-
$qtyAttr['cond'] = "{{table}}.qty between '{$qtyFrom}' AND '{$qtyTo}'";
|
192 |
-
$qtyAttr['joinType'] = 'inner';
|
193 |
-
|
194 |
-
$this->setJoinField($qtyAttr);
|
195 |
-
}
|
196 |
-
|
197 |
-
parent::setFilter($attrFilterArray, $attrToDb);
|
198 |
-
|
199 |
-
if ($price = $this->getFieldValue($filters, 'price')) {
|
200 |
-
$this->_filter[] = array(
|
201 |
-
'attribute' => 'price',
|
202 |
-
'from' => $price['from'],
|
203 |
-
'to' => $price['to']
|
204 |
-
);
|
205 |
-
$this->setJoinAttr(array(
|
206 |
-
'alias' => 'price',
|
207 |
-
'attribute' => 'catalog_product/price',
|
208 |
-
'bind' => 'entity_id',
|
209 |
-
'joinType' => 'LEFT'
|
210 |
-
));
|
211 |
-
}
|
212 |
-
|
213 |
-
return parent::load();
|
214 |
-
}
|
215 |
-
|
216 |
-
/**
|
217 |
-
* Retrieve product model cache
|
218 |
-
*
|
219 |
-
* @return Mage_Catalog_Model_Product
|
220 |
-
*/
|
221 |
-
public function getProductModel()
|
222 |
-
{
|
223 |
-
if (is_null($this->_productModel)) {
|
224 |
-
$productModel = Mage::getModel('catalog/product');
|
225 |
-
$this->_productModel = Mage::objects()->save($productModel);
|
226 |
-
}
|
227 |
-
return Mage::objects()->load($this->_productModel);
|
228 |
-
}
|
229 |
-
|
230 |
-
/**
|
231 |
-
* Retrieve eav entity attribute model
|
232 |
-
*
|
233 |
-
* @param string $code
|
234 |
-
* @return Mage_Eav_Model_Entity_Attribute
|
235 |
-
*/
|
236 |
-
public function getAttribute($code)
|
237 |
-
{
|
238 |
-
if (!isset($this->_attributes[$code])) {
|
239 |
-
$this->_attributes[$code] = $this->getProductModel()->getResource()->getAttribute($code);
|
240 |
-
}
|
241 |
-
if ($this->_attributes[$code] instanceof Mage_Catalog_Model_Resource_Eav_Attribute) {
|
242 |
-
$applyTo = $this->_attributes[$code]->getApplyTo();
|
243 |
-
if ($applyTo && !in_array($this->getProductModel()->getTypeId(), $applyTo)) {
|
244 |
-
return false;
|
245 |
-
}
|
246 |
-
}
|
247 |
-
return $this->_attributes[$code];
|
248 |
-
}
|
249 |
-
|
250 |
-
/**
|
251 |
-
* Retrieve product type collection array
|
252 |
-
*
|
253 |
-
* @return array
|
254 |
-
*/
|
255 |
-
public function getProductTypes()
|
256 |
-
{
|
257 |
-
if (is_null($this->_productTypes)) {
|
258 |
-
$this->_productTypes = array();
|
259 |
-
$options = Mage::getModel('catalog/product_type')
|
260 |
-
->getOptionArray();
|
261 |
-
foreach ($options as $k => $v) {
|
262 |
-
$this->_productTypes[$k] = $k;
|
263 |
-
}
|
264 |
-
}
|
265 |
-
return $this->_productTypes;
|
266 |
-
}
|
267 |
-
|
268 |
-
/**
|
269 |
-
* ReDefine Product Type Instance to Product
|
270 |
-
*
|
271 |
-
* @param Mage_Catalog_Model_Product $product
|
272 |
-
* @return Mage_Catalog_Model_Convert_Adapter_Product
|
273 |
-
*/
|
274 |
-
public function setProductTypeInstance(Mage_Catalog_Model_Product $product)
|
275 |
-
{
|
276 |
-
$type = $product->getTypeId();
|
277 |
-
if (!isset($this->_productTypeInstances[$type])) {
|
278 |
-
$this->_productTypeInstances[$type] = Mage::getSingleton('catalog/product_type')
|
279 |
-
->factory($product, true);
|
280 |
-
}
|
281 |
-
$product->setTypeInstance($this->_productTypeInstances[$type], true);
|
282 |
-
return $this;
|
283 |
-
}
|
284 |
-
|
285 |
-
/**
|
286 |
-
* Retrieve product attribute set collection array
|
287 |
-
*
|
288 |
-
* @return array
|
289 |
-
*/
|
290 |
-
public function getProductAttributeSets()
|
291 |
-
{
|
292 |
-
if (is_null($this->_productAttributeSets)) {
|
293 |
-
$this->_productAttributeSets = array();
|
294 |
-
|
295 |
-
$entityTypeId = Mage::getModel('eav/entity')
|
296 |
-
->setType('catalog_product')
|
297 |
-
->getTypeId();
|
298 |
-
$collection = Mage::getResourceModel('eav/entity_attribute_set_collection')
|
299 |
-
->setEntityTypeFilter($entityTypeId);
|
300 |
-
foreach ($collection as $set) {
|
301 |
-
$this->_productAttributeSets[$set->getAttributeSetName()] = $set->getId();
|
302 |
-
}
|
303 |
-
}
|
304 |
-
return $this->_productAttributeSets;
|
305 |
-
}
|
306 |
-
|
307 |
-
/**
|
308 |
-
* Init stores
|
309 |
-
*/
|
310 |
-
protected function _initStores ()
|
311 |
-
{
|
312 |
-
if (is_null($this->_stores)) {
|
313 |
-
$this->_stores = Mage::app()->getStores(true, true);
|
314 |
-
foreach ($this->_stores as $code => $store) {
|
315 |
-
$this->_storesIdCode[$store->getId()] = $code;
|
316 |
-
}
|
317 |
-
}
|
318 |
-
}
|
319 |
-
|
320 |
-
/**
|
321 |
-
* selectDataFromDB:select query on given table
|
322 |
-
* @param table name,array to select field,where condition apply on ,where condition apply ,limit
|
323 |
-
* @return array
|
324 |
-
*/
|
325 |
-
protected function _selectDataFromDB($tableName,$selectArray,$whereClause,$whereValue){
|
326 |
-
$tableName=$this->prefix.$tableName;
|
327 |
-
$select = $this->dbRead->select()
|
328 |
-
->from($tableName, $selectArray)
|
329 |
-
->where($whereClause.'=?',$whereValue)->limit(1);
|
330 |
-
$rowArray =$this->dbRead->fetchRow($select);//return a row
|
331 |
-
return $rowArray ;
|
332 |
-
|
333 |
-
|
334 |
-
}
|
335 |
-
/**
|
336 |
-
* @_getProductSku :-if sku not present in given sheet autogenerate sku.
|
337 |
-
* @param $param is 'core_read' or 'core_write'
|
338 |
-
* @return object
|
339 |
-
*/
|
340 |
-
protected function _getProductSku($skuField,$productType){
|
341 |
-
if (!empty($skuField)) return $skuField;
|
342 |
-
else {
|
343 |
-
$selectproductPrevId = $this->dbRead->select()
|
344 |
-
->from('catalog_product_entity', 'entity_id')
|
345 |
-
->order('entity_id DESC')->limit(1);
|
346 |
-
$productPrevId=$this->dbRead->fetchOne($selectproductPrevId);
|
347 |
-
$skuautores =$this->_selectDataFromDB('skuautogenerate',array('skuautogenerate_id','suffixstring','prefixstring','stringfunction','min_length'),'product_type',$productType);
|
348 |
-
if(!$skuautores["skuautogenerate_id"]){
|
349 |
-
$skuautores =$this->_selectDataFromDB('skuautogenerate',array('skuautogenerate_id','suffixstring','prefixstring','stringfunction','min_length'),'product_type','unique');
|
350 |
-
}
|
351 |
-
if($skuautores["stringfunction"]=="append"){
|
352 |
-
$skustring = ($productPrevId + 1).$skuautores["suffixstring"];
|
353 |
-
if(strlen($skustring) < $skuautores["min_length"]){
|
354 |
-
$skuLength= $this->_getSkuMatchLenght($skustring,$skuautores["min_length"],($productPrevId + 1));
|
355 |
-
$skuField= $skuLength.$skuautores["suffixstring"];}
|
356 |
-
else $skuField=$skustring;
|
357 |
-
}
|
358 |
-
else if($skuautores["stringfunction"]=="prepend"){
|
359 |
-
$skustring = $skuautores["prefixstring"].($productPrevId + 1);
|
360 |
-
if(strlen($skustring) < $skuautores["min_length"]){
|
361 |
-
$skuLength= $this->_getSkuMatchLenght($skustring,$skuautores["min_length"],($productPrevId + 1));
|
362 |
-
$skuField= $skuautores["prefixstring"].$skuLength;}
|
363 |
-
else $skuField=$skustring;
|
364 |
-
}
|
365 |
-
else { $skustring = $skuautores["prefixstring"].($productPrevId + 1).$skuautores["suffixstring"];
|
366 |
-
if(strlen($skustring) < $skuautores["min_length"]){
|
367 |
-
$skuLength= $this->_getSkuMatchLenght($skustring,$skuautores["min_length"],($productPrevId + 1));
|
368 |
-
$skuField= $skuautores["prefixstring"].$skuLength.$skuautores["suffixstring"];}
|
369 |
-
else $skuField=$skustring;
|
370 |
-
}
|
371 |
-
return $skuField;
|
372 |
-
|
373 |
-
}
|
374 |
-
}
|
375 |
-
protected function _getSkuMatchLenght($skustring,$minLegth,$productPrevId){
|
376 |
-
|
377 |
-
$getLenght=$minLegth-strlen($skustring);
|
378 |
-
$zeros=str_repeat("0",$getLenght);
|
379 |
-
return $skuLeght= $zeros.$productPrevId;
|
380 |
-
}
|
381 |
-
/**
|
382 |
-
* Retrieve store object by code
|
383 |
-
*
|
384 |
-
* @param string $store
|
385 |
-
* @return Mage_Core_Model_Store
|
386 |
-
*/
|
387 |
-
public function getStoreByCode($store)
|
388 |
-
{
|
389 |
-
$this->_initStores();
|
390 |
-
/**
|
391 |
-
* In single store mode all data should be saved as default
|
392 |
-
*/
|
393 |
-
if (Mage::app()->isSingleStoreMode()) {
|
394 |
-
return Mage::app()->getStore(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
|
395 |
-
}
|
396 |
-
|
397 |
-
if (isset($this->_stores[$store])) {
|
398 |
-
return $this->_stores[$store];
|
399 |
-
}
|
400 |
-
|
401 |
-
return false;
|
402 |
-
}
|
403 |
-
|
404 |
-
/**
|
405 |
-
* Retrieve store object by code
|
406 |
-
*
|
407 |
-
* @param string $store
|
408 |
-
* @return Mage_Core_Model_Store
|
409 |
-
*/
|
410 |
-
public function getStoreById($id)
|
411 |
-
{
|
412 |
-
$this->_initStores();
|
413 |
-
/**
|
414 |
-
* In single store mode all data should be saved as default
|
415 |
-
*/
|
416 |
-
if (Mage::app()->isSingleStoreMode()) {
|
417 |
-
return Mage::app()->getStore(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
|
418 |
-
}
|
419 |
-
|
420 |
-
if (isset($this->_storesIdCode[$id])) {
|
421 |
-
return $this->getStoreByCode($this->_storesIdCode[$id]);
|
422 |
-
}
|
423 |
-
|
424 |
-
return false;
|
425 |
-
}
|
426 |
-
|
427 |
-
public function parse()
|
428 |
-
{
|
429 |
-
$batchModel = Mage::getSingleton('dataflow/batch');
|
430 |
-
/* @var $batchModel Mage_Dataflow_Model_Batch */
|
431 |
-
|
432 |
-
$batchImportModel = $batchModel->getBatchImportModel();
|
433 |
-
$importIds = $batchImportModel->getIdCollection();
|
434 |
-
|
435 |
-
foreach ($importIds as $importId) {
|
436 |
-
//print '<pre>'.memory_get_usage().'</pre>';
|
437 |
-
$batchImportModel->load($importId);
|
438 |
-
$importData = $batchImportModel->getBatchData();
|
439 |
-
|
440 |
-
$this->saveRow($importData);
|
441 |
-
}
|
442 |
-
}
|
443 |
-
|
444 |
-
protected $_productId = '';
|
445 |
-
|
446 |
-
/**
|
447 |
-
* Initialize convert adapter model for products collection
|
448 |
-
*
|
449 |
-
*/
|
450 |
-
public function __construct()
|
451 |
-
{ $this->dbRead = Mage::getSingleton('core/resource')->getConnection('core_read');
|
452 |
-
$this->prefix = Mage::getConfig()->getNode('global/resources/db/table_prefix');
|
453 |
-
$fieldset = Mage::getConfig()->getFieldset('catalog_product_dataflow', 'admin');
|
454 |
-
foreach ($fieldset as $code => $node) {
|
455 |
-
/* @var $node Mage_Core_Model_Config_Element */
|
456 |
-
if ($node->is('inventory')) {
|
457 |
-
foreach ($node->product_type->children() as $productType) {
|
458 |
-
$productType = $productType->getName();
|
459 |
-
$this->_inventoryFieldsProductTypes[$productType][] = $code;
|
460 |
-
if ($node->is('use_config')) {
|
461 |
-
$this->_inventoryFieldsProductTypes[$productType][] = 'use_config_' . $code;
|
462 |
-
}
|
463 |
-
}
|
464 |
-
|
465 |
-
$this->_inventoryFields[] = $code;
|
466 |
-
if ($node->is('use_config')) {
|
467 |
-
$this->_inventoryFields[] = 'use_config_'.$code;
|
468 |
-
}
|
469 |
-
}
|
470 |
-
if ($node->is('required')) {
|
471 |
-
$this->_requiredFields[] = $code;
|
472 |
-
}
|
473 |
-
if ($node->is('ignore')) {
|
474 |
-
$this->_ignoreFields[] = $code;
|
475 |
-
}
|
476 |
-
if ($node->is('to_number')) {
|
477 |
-
$this->_toNumber[] = $code;
|
478 |
-
}
|
479 |
-
}
|
480 |
-
|
481 |
-
$this->setVar('entity_type', 'catalog/product');
|
482 |
-
if (!Mage::registry('Object_Cache_Product')) {
|
483 |
-
$this->setProduct(Mage::getModel('catalog/product'));
|
484 |
-
}
|
485 |
-
|
486 |
-
if (!Mage::registry('Object_Cache_StockItem')) {
|
487 |
-
$this->setStockItem(Mage::getModel('cataloginventory/stock_item'));
|
488 |
-
}
|
489 |
-
}
|
490 |
-
|
491 |
-
/**
|
492 |
-
* Retrieve not loaded collection
|
493 |
-
*
|
494 |
-
* @param string $entityType
|
495 |
-
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
|
496 |
-
*/
|
497 |
-
protected function _getCollectionForLoad($entityType)
|
498 |
-
{
|
499 |
-
$collection = parent::_getCollectionForLoad($entityType)
|
500 |
-
->setStoreId($this->getStoreId())
|
501 |
-
->addStoreFilter($this->getStoreId());
|
502 |
-
return $collection;
|
503 |
-
}
|
504 |
-
|
505 |
-
public function setProduct(Mage_Catalog_Model_Product $object)
|
506 |
-
{
|
507 |
-
$id = Mage::objects()->save($object);
|
508 |
-
//$this->_product = $object;
|
509 |
-
Mage::register('Object_Cache_Product', $id);
|
510 |
-
}
|
511 |
-
|
512 |
-
public function getProduct()
|
513 |
-
{
|
514 |
-
return Mage::objects()->load(Mage::registry('Object_Cache_Product'));
|
515 |
-
}
|
516 |
-
|
517 |
-
public function setStockItem(Mage_CatalogInventory_Model_Stock_Item $object)
|
518 |
-
{
|
519 |
-
$id = Mage::objects()->save($object);
|
520 |
-
Mage::register('Object_Cache_StockItem', $id);
|
521 |
-
}
|
522 |
-
|
523 |
-
public function getStockItem()
|
524 |
-
{
|
525 |
-
return Mage::objects()->load(Mage::registry('Object_Cache_StockItem'));
|
526 |
-
}
|
527 |
-
|
528 |
-
public function save()
|
529 |
-
{
|
530 |
-
$stores = array();
|
531 |
-
foreach (Mage::getConfig()->getNode('stores')->children() as $storeNode) {
|
532 |
-
$stores[(int)$storeNode->system->store->id] = $storeNode->getName();
|
533 |
-
}
|
534 |
-
|
535 |
-
$collections = $this->getData();
|
536 |
-
if ($collections instanceof Mage_Catalog_Model_Entity_Product_Collection) {
|
537 |
-
$collections = array($collections->getEntity()->getStoreId()=>$collections);
|
538 |
-
} elseif (!is_array($collections)) {
|
539 |
-
$this->addException(
|
540 |
-
Mage::helper('catalog')->__('No product collections found.'),
|
541 |
-
Mage_Dataflow_Model_Convert_Exception::FATAL
|
542 |
-
);
|
543 |
-
}
|
544 |
-
|
545 |
-
$stockItems = Mage::registry('current_imported_inventory');
|
546 |
-
if ($collections) foreach ($collections as $storeId=>$collection) {
|
547 |
-
$this->addException(Mage::helper('catalog')->__('Records for "'.$stores[$storeId].'" store found.'));
|
548 |
-
|
549 |
-
if (!$collection instanceof Mage_Catalog_Model_Entity_Product_Collection) {
|
550 |
-
$this->addException(
|
551 |
-
Mage::helper('catalog')->__('Product collection expected.'),
|
552 |
-
Mage_Dataflow_Model_Convert_Exception::FATAL
|
553 |
-
);
|
554 |
-
}
|
555 |
-
try {
|
556 |
-
$i = 0;
|
557 |
-
foreach ($collection->getIterator() as $model) {
|
558 |
-
$new = false;
|
559 |
-
// if product is new, create default values first
|
560 |
-
if (!$model->getId()) {
|
561 |
-
$new = true;
|
562 |
-
$model->save();
|
563 |
-
|
564 |
-
// if new product and then store is not default
|
565 |
-
// we duplicate product as default product with store_id -
|
566 |
-
if (0 !== $storeId ) {
|
567 |
-
$data = $model->getData();
|
568 |
-
$default = Mage::getModel('catalog/product');
|
569 |
-
$default->setData($data);
|
570 |
-
$default->setStoreId(0);
|
571 |
-
$default->save();
|
572 |
-
unset($default);
|
573 |
-
} // end
|
574 |
-
|
575 |
-
#Mage::getResourceSingleton('catalog_entity/convert')->addProductToStore($model->getId(), 0);
|
576 |
-
}
|
577 |
-
if (!$new || 0!==$storeId) {
|
578 |
-
if (0!==$storeId) {
|
579 |
-
Mage::getResourceSingleton('catalog_entity/convert')->addProductToStore(
|
580 |
-
$model->getId(),
|
581 |
-
$storeId
|
582 |
-
);
|
583 |
-
}
|
584 |
-
$model->save();
|
585 |
-
}
|
586 |
-
|
587 |
-
if (isset($stockItems[$model->getSku()]) && $stock = $stockItems[$model->getSku()]) {
|
588 |
-
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($model->getId());
|
589 |
-
$stockItemId = $stockItem->getId();
|
590 |
-
|
591 |
-
if (!$stockItemId) {
|
592 |
-
$stockItem->setData('product_id', $model->getId());
|
593 |
-
$stockItem->setData('stock_id', 1);
|
594 |
-
$data = array();
|
595 |
-
} else {
|
596 |
-
$data = $stockItem->getData();
|
597 |
-
}
|
598 |
-
|
599 |
-
foreach($stock as $field => $value) {
|
600 |
-
if (!$stockItemId) {
|
601 |
-
if (in_array($field, $this->_configs)) {
|
602 |
-
$stockItem->setData('use_config_'.$field, 0);
|
603 |
-
}
|
604 |
-
$stockItem->setData($field, $value?$value:0);
|
605 |
-
} else {
|
606 |
-
|
607 |
-
if (in_array($field, $this->_configs)) {
|
608 |
-
if ($data['use_config_'.$field] == 0) {
|
609 |
-
$stockItem->setData($field, $value?$value:0);
|
610 |
-
}
|
611 |
-
} else {
|
612 |
-
$stockItem->setData($field, $value?$value:0);
|
613 |
-
}
|
614 |
-
}
|
615 |
-
}
|
616 |
-
$stockItem->save();
|
617 |
-
unset($data);
|
618 |
-
unset($stockItem);
|
619 |
-
unset($stockItemId);
|
620 |
-
}
|
621 |
-
unset($model);
|
622 |
-
$i++;
|
623 |
-
}
|
624 |
-
$this->addException(Mage::helper('catalog')->__("Saved %d record(s)", $i));
|
625 |
-
} catch (Exception $e) {
|
626 |
-
if (!$e instanceof Mage_Dataflow_Model_Convert_Exception) {
|
627 |
-
$this->addException(
|
628 |
-
Mage::helper('catalog')->__(
|
629 |
-
'An error occurred while saving the collection, aborting. Error message: %s',
|
630 |
-
$e->getMessage()
|
631 |
-
),
|
632 |
-
Mage_Dataflow_Model_Convert_Exception::FATAL
|
633 |
-
);
|
634 |
-
}
|
635 |
-
}
|
636 |
-
}
|
637 |
-
unset($collections);
|
638 |
-
|
639 |
-
return $this;
|
640 |
-
}
|
641 |
-
|
642 |
-
/**
|
643 |
-
* Save product (import)
|
644 |
-
*
|
645 |
-
* @param array $importData
|
646 |
-
* @throws Mage_Core_Exception
|
647 |
-
* @return bool
|
648 |
-
*/
|
649 |
-
public function saveRow(array $importData)
|
650 |
-
{
|
651 |
-
$product = $this->getProductModel()
|
652 |
-
->reset();
|
653 |
-
|
654 |
-
if (empty($importData['store'])) {
|
655 |
-
if (!is_null($this->getBatchParams('store'))) {
|
656 |
-
$store = $this->getStoreById($this->getBatchParams('store'));
|
657 |
-
} else {
|
658 |
-
$message = Mage::helper('catalog')->__(
|
659 |
-
'Skipping import row, required field "%s" is not defined.',
|
660 |
-
'store'
|
661 |
-
);
|
662 |
-
Mage::throwException($message);
|
663 |
-
}
|
664 |
-
} else {
|
665 |
-
$store = $this->getStoreByCode($importData['store']);
|
666 |
-
}
|
667 |
-
|
668 |
-
if ($store === false) {
|
669 |
-
$message = Mage::helper('catalog')->__(
|
670 |
-
'Skipping import row, store "%s" field does not exist.',
|
671 |
-
$importData['store']
|
672 |
-
);
|
673 |
-
Mage::throwException($message);
|
674 |
-
}
|
675 |
-
$importData['sku']=$this->_getProductSku($importData['sku'],$importData['type']);
|
676 |
-
if (empty($importData['sku'])) {
|
677 |
-
|
678 |
-
$message = Mage::helper('catalog')->__('Skipping import row, required field "%s" is not defined.', 'sku');
|
679 |
-
Mage::throwException($message);
|
680 |
-
}
|
681 |
-
$product->setStoreId($store->getId());
|
682 |
-
$productId = $product->getIdBySku($importData['sku']);
|
683 |
-
|
684 |
-
if ($productId) {
|
685 |
-
$product->load($productId);
|
686 |
-
} else {
|
687 |
-
$productTypes = $this->getProductTypes();
|
688 |
-
$productAttributeSets = $this->getProductAttributeSets();
|
689 |
-
|
690 |
-
/**
|
691 |
-
* Check product define type
|
692 |
-
*/
|
693 |
-
if (empty($importData['type']) || !isset($productTypes[strtolower($importData['type'])])) {
|
694 |
-
$value = isset($importData['type']) ? $importData['type'] : '';
|
695 |
-
$message = Mage::helper('catalog')->__(
|
696 |
-
'Skip import row, is not valid value "%s" for field "%s"',
|
697 |
-
$value,
|
698 |
-
'type'
|
699 |
-
);
|
700 |
-
Mage::throwException($message);
|
701 |
-
}
|
702 |
-
$product->setTypeId($productTypes[strtolower($importData['type'])]);
|
703 |
-
/**
|
704 |
-
* Check product define attribute set
|
705 |
-
*/
|
706 |
-
if (empty($importData['attribute_set']) || !isset($productAttributeSets[$importData['attribute_set']])) {
|
707 |
-
$value = isset($importData['attribute_set']) ? $importData['attribute_set'] : '';
|
708 |
-
$message = Mage::helper('catalog')->__(
|
709 |
-
'Skip import row, the value "%s" is invalid for field "%s"',
|
710 |
-
$value,
|
711 |
-
'attribute_set'
|
712 |
-
);
|
713 |
-
Mage::throwException($message);
|
714 |
-
}
|
715 |
-
$product->setAttributeSetId($productAttributeSets[$importData['attribute_set']]);
|
716 |
-
|
717 |
-
foreach ($this->_requiredFields as $field) {
|
718 |
-
$attribute = $this->getAttribute($field);
|
719 |
-
if (!isset($importData[$field]) && $attribute && $attribute->getIsRequired()) {
|
720 |
-
$message = Mage::helper('catalog')->__(
|
721 |
-
'Skipping import row, required field "%s" for new products is not defined.',
|
722 |
-
$field
|
723 |
-
);
|
724 |
-
Mage::throwException($message);
|
725 |
-
}
|
726 |
-
}
|
727 |
-
}
|
728 |
-
|
729 |
-
$this->setProductTypeInstance($product);
|
730 |
-
|
731 |
-
if (isset($importData['category_ids'])) {
|
732 |
-
$product->setCategoryIds($importData['category_ids']);
|
733 |
-
}
|
734 |
-
|
735 |
-
foreach ($this->_ignoreFields as $field) {
|
736 |
-
if (isset($importData[$field])) {
|
737 |
-
unset($importData[$field]);
|
738 |
-
}
|
739 |
-
}
|
740 |
-
|
741 |
-
if ($store->getId() != 0) {
|
742 |
-
$websiteIds = $product->getWebsiteIds();
|
743 |
-
if (!is_array($websiteIds)) {
|
744 |
-
$websiteIds = array();
|
745 |
-
}
|
746 |
-
if (!in_array($store->getWebsiteId(), $websiteIds)) {
|
747 |
-
$websiteIds[] = $store->getWebsiteId();
|
748 |
-
}
|
749 |
-
$product->setWebsiteIds($websiteIds);
|
750 |
-
}
|
751 |
-
|
752 |
-
if (isset($importData['websites'])) {
|
753 |
-
$websiteIds = $product->getWebsiteIds();
|
754 |
-
if (!is_array($websiteIds) || !$store->getId()) {
|
755 |
-
$websiteIds = array();
|
756 |
-
}
|
757 |
-
$websiteCodes = explode(',', $importData['websites']);
|
758 |
-
foreach ($websiteCodes as $websiteCode) {
|
759 |
-
try {
|
760 |
-
$website = Mage::app()->getWebsite(trim($websiteCode));
|
761 |
-
if (!in_array($website->getId(), $websiteIds)) {
|
762 |
-
$websiteIds[] = $website->getId();
|
763 |
-
}
|
764 |
-
} catch (Exception $e) {}
|
765 |
-
}
|
766 |
-
$product->setWebsiteIds($websiteIds);
|
767 |
-
unset($websiteIds);
|
768 |
-
}
|
769 |
-
|
770 |
-
foreach ($importData as $field => $value) {
|
771 |
-
if (in_array($field, $this->_inventoryFields)) {
|
772 |
-
continue;
|
773 |
-
}
|
774 |
-
if (is_null($value)) {
|
775 |
-
continue;
|
776 |
-
}
|
777 |
-
|
778 |
-
$attribute = $this->getAttribute($field);
|
779 |
-
if (!$attribute) {
|
780 |
-
continue;
|
781 |
-
}
|
782 |
-
|
783 |
-
$isArray = false;
|
784 |
-
$setValue = $value;
|
785 |
-
|
786 |
-
if ($attribute->getFrontendInput() == 'multiselect') {
|
787 |
-
$value = explode(self::MULTI_DELIMITER, $value);
|
788 |
-
$isArray = true;
|
789 |
-
$setValue = array();
|
790 |
-
}
|
791 |
-
|
792 |
-
if ($value && $attribute->getBackendType() == 'decimal') {
|
793 |
-
$setValue = $this->getNumber($value);
|
794 |
-
}
|
795 |
-
|
796 |
-
if ($attribute->usesSource()) {
|
797 |
-
$options = $attribute->getSource()->getAllOptions(false);
|
798 |
-
|
799 |
-
if ($isArray) {
|
800 |
-
foreach ($options as $item) {
|
801 |
-
if (in_array($item['label'], $value)) {
|
802 |
-
$setValue[] = $item['value'];
|
803 |
-
}
|
804 |
-
}
|
805 |
-
} else {
|
806 |
-
$setValue = false;
|
807 |
-
foreach ($options as $item) {
|
808 |
-
if (is_array($item['value'])) {
|
809 |
-
foreach ($item['value'] as $subValue) {
|
810 |
-
if (isset($subValue['value']) && $subValue['value'] == $value) {
|
811 |
-
$setValue = $value;
|
812 |
-
}
|
813 |
-
}
|
814 |
-
} else if ($item['label'] == $value) {
|
815 |
-
$setValue = $item['value'];
|
816 |
-
}
|
817 |
-
}
|
818 |
-
}
|
819 |
-
}
|
820 |
-
|
821 |
-
$product->setData($field, $setValue);
|
822 |
-
}
|
823 |
-
|
824 |
-
if (!$product->getVisibility()) {
|
825 |
-
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
|
826 |
-
}
|
827 |
-
|
828 |
-
$stockData = array();
|
829 |
-
$inventoryFields = isset($this->_inventoryFieldsProductTypes[$product->getTypeId()])
|
830 |
-
? $this->_inventoryFieldsProductTypes[$product->getTypeId()]
|
831 |
-
: array();
|
832 |
-
foreach ($inventoryFields as $field) {
|
833 |
-
if (isset($importData[$field])) {
|
834 |
-
if (in_array($field, $this->_toNumber)) {
|
835 |
-
$stockData[$field] = $this->getNumber($importData[$field]);
|
836 |
-
} else {
|
837 |
-
$stockData[$field] = $importData[$field];
|
838 |
-
}
|
839 |
-
}
|
840 |
-
}
|
841 |
-
$product->setStockData($stockData);
|
842 |
-
|
843 |
-
$mediaGalleryBackendModel = $this->getAttribute('media_gallery')->getBackend();
|
844 |
-
|
845 |
-
$arrayToMassAdd = array();
|
846 |
-
|
847 |
-
foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
|
848 |
-
if (isset($importData[$mediaAttributeCode])) {
|
849 |
-
$file = trim($importData[$mediaAttributeCode]);
|
850 |
-
if (!empty($file) && !$mediaGalleryBackendModel->getImage($product, $file)) {
|
851 |
-
$arrayToMassAdd[] = array('file' => trim($file), 'mediaAttribute' => $mediaAttributeCode);
|
852 |
-
}
|
853 |
-
}
|
854 |
-
}
|
855 |
-
|
856 |
-
$addedFilesCorrespondence = $mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
|
857 |
-
$product,
|
858 |
-
$arrayToMassAdd, Mage::getBaseDir('media') . DS . 'import',
|
859 |
-
false,
|
860 |
-
false
|
861 |
-
);
|
862 |
-
|
863 |
-
foreach ($product->getMediaAttributes() as $mediaAttributeCode => $mediaAttribute) {
|
864 |
-
$addedFile = '';
|
865 |
-
if (isset($importData[$mediaAttributeCode . '_label'])) {
|
866 |
-
$fileLabel = trim($importData[$mediaAttributeCode . '_label']);
|
867 |
-
if (isset($importData[$mediaAttributeCode])) {
|
868 |
-
$keyInAddedFile = array_search($importData[$mediaAttributeCode],
|
869 |
-
$addedFilesCorrespondence['alreadyAddedFiles']);
|
870 |
-
if ($keyInAddedFile !== false) {
|
871 |
-
$addedFile = $addedFilesCorrespondence['alreadyAddedFilesNames'][$keyInAddedFile];
|
872 |
-
}
|
873 |
-
}
|
874 |
-
|
875 |
-
if (!$addedFile) {
|
876 |
-
$addedFile = $product->getData($mediaAttributeCode);
|
877 |
-
}
|
878 |
-
if ($fileLabel && $addedFile) {
|
879 |
-
$mediaGalleryBackendModel->updateImage($product, $addedFile, array('label' => $fileLabel));
|
880 |
-
}
|
881 |
-
}
|
882 |
-
}
|
883 |
-
|
884 |
-
$product->setIsMassupdate(true);
|
885 |
-
$product->setExcludeUrlRewrite(true);
|
886 |
-
|
887 |
-
$product->save();
|
888 |
-
|
889 |
-
// Store affected products ids
|
890 |
-
$this->_addAffectedEntityIds($product->getId());
|
891 |
-
|
892 |
-
return true;
|
893 |
-
}
|
894 |
-
|
895 |
-
/**
|
896 |
-
* Silently save product (import)
|
897 |
-
*
|
898 |
-
* @param array $importData
|
899 |
-
* @return bool
|
900 |
-
*/
|
901 |
-
public function saveRowSilently(array $importData)
|
902 |
-
{
|
903 |
-
try {
|
904 |
-
$result = $this->saveRow($importData);
|
905 |
-
return $result;
|
906 |
-
} catch (Exception $e) {
|
907 |
-
return false;
|
908 |
-
}
|
909 |
-
}
|
910 |
-
|
911 |
-
/**
|
912 |
-
* Process after import data
|
913 |
-
* Init indexing process after catalog product import
|
914 |
-
*/
|
915 |
-
public function finish()
|
916 |
-
{
|
917 |
-
/**
|
918 |
-
* Back compatibility event
|
919 |
-
*/
|
920 |
-
Mage::dispatchEvent($this->_eventPrefix . '_after', array());
|
921 |
-
|
922 |
-
$entity = new Varien_Object();
|
923 |
-
Mage::getSingleton('index/indexer')->processEntityAction(
|
924 |
-
$entity, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE
|
925 |
-
);
|
926 |
-
}
|
927 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/Neev/Skuautogenerate/Block/Adminhtml/Catalog/Product/Edit.php
CHANGED
@@ -35,91 +35,13 @@
|
|
35 |
class Neev_Skuautogenerate_Block_Adminhtml_Catalog_Product_Edit extends Mage_Adminhtml_Block_Catalog_Product_Edit
|
36 |
{
|
37 |
|
38 |
-
|
39 |
-
{
|
40 |
-
if (!$this->getRequest()->getParam('popup')) {
|
41 |
-
$this->setTemplate('skuautogenerate/catalog/product/edit.phtml');
|
42 |
-
|
43 |
-
$this->setChild('back_button',
|
44 |
-
$this->getLayout()->createBlock('adminhtml/widget_button')
|
45 |
-
->setData(array(
|
46 |
-
'label' => Mage::helper('catalog')->__('Back'),
|
47 |
-
'onclick' => 'setLocation(\''.$this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store', 0))).'\')',
|
48 |
-
'class' => 'back'
|
49 |
-
))
|
50 |
-
);
|
51 |
-
} else {
|
52 |
-
$this->setChild('back_button',
|
53 |
-
$this->getLayout()->createBlock('adminhtml/widget_button')
|
54 |
-
->setData(array(
|
55 |
-
'label' => Mage::helper('catalog')->__('Close Window'),
|
56 |
-
'onclick' => 'window.close()',
|
57 |
-
'class' => 'cancel'
|
58 |
-
))
|
59 |
-
);
|
60 |
-
}
|
61 |
-
|
62 |
-
if (!$this->getProduct()->isReadonly()) {
|
63 |
-
$this->setChild('reset_button',
|
64 |
-
$this->getLayout()->createBlock('adminhtml/widget_button')
|
65 |
-
->setData(array(
|
66 |
-
'label' => Mage::helper('catalog')->__('Reset'),
|
67 |
-
'onclick' => 'setLocation(\''.$this->getUrl('*/*/*', array('_current'=>true)).'\')'
|
68 |
-
))
|
69 |
-
);
|
70 |
-
|
71 |
-
$this->setChild('save_button',
|
72 |
-
$this->getLayout()->createBlock('adminhtml/widget_button')
|
73 |
-
->setData(array(
|
74 |
-
'label' => Mage::helper('catalog')->__('Save'),
|
75 |
-
'onclick' => 'productForm.submit()',
|
76 |
-
'class' => 'save'
|
77 |
-
))
|
78 |
-
);
|
79 |
-
}
|
80 |
-
|
81 |
-
if (!$this->getRequest()->getParam('popup')) {
|
82 |
-
if (!$this->getProduct()->isReadonly()) {
|
83 |
-
$this->setChild('save_and_edit_button',
|
84 |
-
$this->getLayout()->createBlock('adminhtml/widget_button')
|
85 |
-
->setData(array(
|
86 |
-
'label' => Mage::helper('catalog')->__('Save and Continue Edit'),
|
87 |
-
'onclick' => 'saveAndContinueEdit(\''.$this->getSaveAndContinueUrl().'\')',
|
88 |
-
'class' => 'save'
|
89 |
-
))
|
90 |
-
);
|
91 |
-
}
|
92 |
-
if ($this->getProduct()->isDeleteable()) {
|
93 |
-
$this->setChild('delete_button',
|
94 |
-
$this->getLayout()->createBlock('adminhtml/widget_button')
|
95 |
-
->setData(array(
|
96 |
-
'label' => Mage::helper('catalog')->__('Delete'),
|
97 |
-
'onclick' => 'confirmSetLocation(\''.Mage::helper('catalog')->__('Are you sure?').'\', \''.$this->getDeleteUrl().'\')',
|
98 |
-
'class' => 'delete'
|
99 |
-
))
|
100 |
-
);
|
101 |
-
}
|
102 |
-
|
103 |
-
if ($this->getProduct()->isDuplicable()) {
|
104 |
-
$this->setChild('duplicate_button',
|
105 |
-
$this->getLayout()->createBlock('adminhtml/widget_button')
|
106 |
-
->setData(array(
|
107 |
-
'label' => Mage::helper('catalog')->__('Duplicate'),
|
108 |
-
'onclick' => 'setLocation(\'' . $this->getDuplicateUrl() . '\')',
|
109 |
-
'class' => 'add'
|
110 |
-
))
|
111 |
-
);
|
112 |
-
}
|
113 |
-
}
|
114 |
-
|
115 |
-
return parent::_prepareLayout();
|
116 |
-
}
|
117 |
|
118 |
public function skuAuto($type)
|
119 |
{
|
120 |
$connection = Mage::getSingleton('core/resource')->getConnection('read');
|
121 |
$table = Mage::getSingleton('core/resource')->getTableName('skuautogenerate');
|
122 |
-
$skuauto = $connection->query("SELECT
|
123 |
$skuautores=$skuauto->fetch();
|
124 |
if(!$skuautores["skuautogenerate_id"]){
|
125 |
$skuauto = $connection->query("SELECT * FROM {$table} WHERE product_type='unique'");
|
35 |
class Neev_Skuautogenerate_Block_Adminhtml_Catalog_Product_Edit extends Mage_Adminhtml_Block_Catalog_Product_Edit
|
36 |
{
|
37 |
|
38 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
public function skuAuto($type)
|
41 |
{
|
42 |
$connection = Mage::getSingleton('core/resource')->getConnection('read');
|
43 |
$table = Mage::getSingleton('core/resource')->getTableName('skuautogenerate');
|
44 |
+
$skuauto = $connection->query("SELECT skuautogenerate_id,appendstring , min_length FROM {$table} WHERE status = 1 AND product_type='{$type}'");
|
45 |
$skuautores=$skuauto->fetch();
|
46 |
if(!$skuautores["skuautogenerate_id"]){
|
47 |
$skuauto = $connection->query("SELECT * FROM {$table} WHERE product_type='unique'");
|
app/design/adminhtml/default/default/template/skuautogenerate/catalog/product/edit.phtml
CHANGED
@@ -138,13 +138,15 @@ function setSettings(urlTemplate, setElement, typeElement) {
|
|
138 |
|
139 |
<?php
|
140 |
$getprevEntityId=$this->getprevEntityId();
|
141 |
-
|
|
|
142 |
$skuautores= $this->skuAuto($this->getRequest()->getParam('type'));
|
143 |
-
|
144 |
?>
|
145 |
|
146 |
<script type="text/javascript">
|
147 |
if(document.getElementById('sku').value == ""){
|
|
|
148 |
var skustring,finalskustring;
|
149 |
var skustringtoprefix="<?php echo $skuautores["prefixstring"]; ?>";
|
150 |
var minlen=<?php echo $skuautores["min_length"]; ?>;
|
@@ -181,3 +183,5 @@ if(document.getElementById('sku').value == ""){
|
|
181 |
document.getElementById('sku').value =finalskustring;}}
|
182 |
toggleValueElements($('isauto'), $('isauto').parentNode);
|
183 |
</script>
|
|
|
|
138 |
|
139 |
<?php
|
140 |
$getprevEntityId=$this->getprevEntityId();
|
141 |
+
print_r($getprevEntityId);
|
142 |
+
if($this->getRequest()->getParam('type') ):
|
143 |
$skuautores= $this->skuAuto($this->getRequest()->getParam('type'));
|
144 |
+
if($skuautores):
|
145 |
?>
|
146 |
|
147 |
<script type="text/javascript">
|
148 |
if(document.getElementById('sku').value == ""){
|
149 |
+
alert('hi');
|
150 |
var skustring,finalskustring;
|
151 |
var skustringtoprefix="<?php echo $skuautores["prefixstring"]; ?>";
|
152 |
var minlen=<?php echo $skuautores["min_length"]; ?>;
|
183 |
document.getElementById('sku').value =finalskustring;}}
|
184 |
toggleValueElements($('isauto'), $('isauto').parentNode);
|
185 |
</script>
|
186 |
+
<?php endif; ?>
|
187 |
+
<?php endif; ?>
|
package.xml
CHANGED
@@ -1,19 +1,18 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>SKU_Auto_Generator</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
-
<summary>
|
10 |
-
<description>
|
11 |
-
|
12 |
-
<
|
13 |
-
<
|
14 |
-
<
|
15 |
-
<
|
16 |
-
<contents><target name="mage"><dir name="app"><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="skuautogenerate.xml" hash="daaef43e86f6b7da79c2d48cd5d1ca15"/></dir><dir name="template"><dir name="skuautogenerate"><dir name="catalog"><dir name="product"><file name="edit.phtml" hash="e957cae12769c867689bb00ddae8b539"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Neev_Skuautogenerate.xml" hash="bcbd229d7ef67308e8b8802233d96da2"/></dir></dir><dir name="code"><dir name="local"><dir name="Mage"><dir name="Catalog"><dir name="Model"><dir name="Convert"><dir name="Adapter"><file name="Product.php" hash="c91f219c27977e614885dc3bb876b67f"/></dir></dir></dir></dir></dir><dir name="Neev"><dir name="Skuautogenerate"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><file name="Edit.php" hash="e79f8c757117e336b5c2bf3426b9c463"/></dir></dir><dir name="Skuautogenerate"><dir name="Edit"><dir name="Tab"><file name="Form.php" hash="b395242561f3880f45fac6b534ba0457"/></dir><file name="Form.php" hash="6d3cea1cb156ab627f78be0809ef69f1"/><file name="Tabs.php" hash="7e3677bb77a034f28742cbd8cebafac4"/></dir><file name="Edit.php" hash="5630983d8c038d4772e996b5bbf5868c"/><file name="Grid.php" hash="927513b143d1ec99532fa5a71903f967"/></dir><file name="Skuautogenerate.php" hash="dd8e6d26cba313240428e8cc7f5a9fc3"/></dir><file name="Skuautogenerate.php" hash="5c4fa69402f87f9ac3a0aa15ca790b58"/></dir><dir name="Helper"><file name="Data.php" hash="4e9fb6d3fa6104bbf645815831615bf7"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Skuautogenerate"><file name="Collection.php" hash="cd83d79930f6141b72f4eb885d648522"/></dir><file name="Skuautogenerate.php" hash="b2fc3235c1dfc0c7592354597fff696e"/></dir><file name="Skuautogenerate.php" hash="1b3d1452e9152f0225d0055205edb5f0"/><file name="Status.php" hash="044ca08797c2ac7643e14c65d1e7cbc6"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="SkuautogenerateController.php" hash="741da95b0774e7835958d4984f08c402"/></dir><file name="IndexController.php" hash="14a0aa7d2586c277fbe896dc379f2bce"/></dir><dir name="etc"><file name="config.xml" hash="fecc9aa2b9129bfb86a8a30ae23f8a7f"/></dir><dir name="sql"><dir name="skuautogenerate_setup"><file name="mysql4-install-0.1.0.php" hash="255a1f9c7199d43b88a216f0b3db2514"/></dir></dir></dir></dir></dir></dir></dir></target></contents>
|
17 |
<compatible/>
|
18 |
<dependencies/>
|
19 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>SKU_Auto_Generator</name>
|
4 |
+
<version>1.0.3</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
+
<summary>Automatically create SKUs for products that are manually added via admin or imported via CSV of XML files.</summary>
|
10 |
+
<description>Automatically create SKUs for products that are manually added via admin or imported via CSV of XML files.</description>
|
11 |
+
<notes>Automatically create SKUs for products that are manually added via admin or imported via CSV of XML files.</notes>
|
12 |
+
<authors><author><name>saurab_chandra</name><user>auto-converted</user><email>magentoaccount@neevtech.com</email></author></authors>
|
13 |
+
<date>2013-02-15</date>
|
14 |
+
<time>13:19:28</time>
|
15 |
+
<contents><target name="mage"><dir name="app"><dir name="code"><dir name="local"><dir name="Neev"><dir name="Skuautogenerate"><dir name="Block"><file name="Skuautogenerate.php" hash="5c4fa69402f87f9ac3a0aa15ca790b58"/><dir name="Adminhtml"><file name="Skuautogenerate.php" hash="dd8e6d26cba313240428e8cc7f5a9fc3"/><dir name="Catalog"><dir name="Product"><file name="Edit.php" hash="f4b93a5482b5a5334a7fa6040b68a794"/></dir></dir><dir name="Skuautogenerate"><file name="Edit.php" hash="5630983d8c038d4772e996b5bbf5868c"/><file name="Grid.php" hash="927513b143d1ec99532fa5a71903f967"/><dir name="Edit"><file name="Form.php" hash="6d3cea1cb156ab627f78be0809ef69f1"/><file name="Tabs.php" hash="7e3677bb77a034f28742cbd8cebafac4"/><dir name="Tab"><file name="Form.php" hash="b395242561f3880f45fac6b534ba0457"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="14a0aa7d2586c277fbe896dc379f2bce"/><dir name="Adminhtml"><file name="SkuautogenerateController.php" hash="741da95b0774e7835958d4984f08c402"/></dir></dir><dir name="etc"><file name="config.xml" hash="fecc9aa2b9129bfb86a8a30ae23f8a7f"/></dir><dir name="Helper"><file name="Data.php" hash="4e9fb6d3fa6104bbf645815831615bf7"/></dir><dir name="Model"><file name="Skuautogenerate.php" hash="1b3d1452e9152f0225d0055205edb5f0"/><file name="Status.php" hash="044ca08797c2ac7643e14c65d1e7cbc6"/><dir name="Mysql4"><file name="Skuautogenerate.php" hash="b2fc3235c1dfc0c7592354597fff696e"/><dir name="Skuautogenerate"><file name="Collection.php" hash="cd83d79930f6141b72f4eb885d648522"/></dir></dir></dir><dir name="sql"><dir name="skuautogenerate_setup"><file name="mysql4-install-0.1.0.php" hash="255a1f9c7199d43b88a216f0b3db2514"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="skuautogenerate.xml" hash="daaef43e86f6b7da79c2d48cd5d1ca15"/></dir><dir name="template"><dir name="skuautogenerate"><dir name="catalog"><dir name="product"><file name="edit.phtml" hash="32db0b8eeef3921f004db969c2e18283"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Neev_Skuautogenerate.xml" hash="bcbd229d7ef67308e8b8802233d96da2"/></dir></dir></dir></target></contents>
|
|
|
16 |
<compatible/>
|
17 |
<dependencies/>
|
18 |
</package>
|