LinnLiveConnect - Version 1.1.38

Version Notes

Bug fixes:
* Mapping wrong attribute code fix.

Download this release

Release Info

Developer Albert Andrejev
Extension LinnLiveConnect
Version 1.1.38
Comparing to
See all releases


Code changes from version 1.1.37 to 1.1.38

app/code/local/LinnSystems/LinnLiveConnect/Model/Api/V2.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
  class Settings {
3
- static $VERSION = 37;
4
  }
5
 
6
  class LinnSystems_LinnLiveConnect_Model_Api_V2{
7
 
8
  public function configurableProduct($version, $set, $sku, $reindex, $productData, $productsSet, $attributesSet, $store=null)
9
- {
10
  $worker = Factory::createWorker($version);
11
- return $worker->configurableProduct($set, $sku, $reindex, $productData, $productsSet, $attributesSet, $store);
12
  }
13
 
14
  public function updateConfigurableProduct($version, $productId, $reindex, $productData, $productsSet, $attributesSet, $store=null, $identifierType='id')
@@ -22,25 +22,25 @@ class LinnSystems_LinnLiveConnect_Model_Api_V2{
22
  $worker = Factory::createWorker($version);
23
  return $worker->storesList();
24
  }
25
-
26
  public function getStoreCode($version, $store=null)
27
  {
28
  $worker = Factory::createWorker($version);
29
  return $worker->getStoreCode($store);
30
  }
31
-
32
  public function deleteAssigned($version, $productId, $store=null, $identifierType='id')
33
  {
34
  $worker = Factory::createWorker($version);
35
  return $worker->deleteAssigned($productId, $store, $identifierType);
36
  }
37
-
38
  public function assignImages($version, $productImages)
39
  {
40
  $worker = Factory::createWorker($version);
41
  return $worker->assignImages($productImages);
42
  }
43
-
44
  public function productList($version, $page, $perPage, $filters = null, $store = null)
45
  {
46
  $worker = Factory::createWorker($version);
@@ -73,22 +73,22 @@ class LinnSystems_LinnLiveConnect_Model_Api_V2{
73
  }
74
 
75
  class Factory{
76
-
77
  private function _checkVersion($version)
78
  {
79
  $version = intval($version);
80
-
81
  if ($version == 0)
82
  throw new Mage_Api_Exception('version is not specified');
83
  if (Settings::$VERSION < $version )
84
  throw new Mage_Api_Exception('wrong_version');
85
  }
86
-
87
-
88
  public static function createWorker($version)
89
  {
90
  self::_checkVersion($version);
91
-
92
  if(Mage::GetEdition() == Mage::EDITION_COMMUNITY)
93
  {
94
  return new LinnLiveCommunity();
@@ -101,13 +101,13 @@ class Factory{
101
  {
102
  throw new Mage_Api_Exception('unsupported_edition');
103
  }
104
-
105
  }
106
  }
107
 
108
  class LinnLiveMain extends Mage_Core_Model_Abstract{
109
 
110
-
111
  private $_ignoredAttributes = array(
112
  'created_at',
113
  'updated_at',
@@ -134,53 +134,53 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
134
  'stock_item',
135
  'description',
136
  );
137
-
138
  private $_permittedAttributes = array (
139
  'select',
140
  'multiselect',
141
- 'text',
142
- 'textarea',
143
  'date',
144
  'price'
145
  );
146
-
147
  private function _prepareConfigurableData(
148
- & $store, & $productData, & $assignedProductsArray,
149
  & $attributesSetArray, $productsSet, $attributesSet)
150
  {
151
- $store = $this->_currentStoreCode($store);
152
-
153
  $this->_updateConfigurableQuantity($productData);
154
-
155
  $productData = $this->_fixAttributes($productData);
156
-
157
  if (!is_array($attributesSet))
158
  {
159
  $tmpSet = $attributesSet;
160
  $attributesSet = array();
161
  $attributesSet[] = $tmpSet;
162
  }
163
-
164
  $assignedProductsData = $this->_createProductsData($productsSet);
165
  $assignedProductsArray = $this->_objectToArray($assignedProductsData);
166
-
167
- $_newAttributeOptions = $this->_newConfigurableOptions($assignedProductsArray);
168
  if (count($_newAttributeOptions) > 0)
169
  {
170
  $_availableOptions = $this->_createOptions($_newAttributeOptions);
171
  $this->_checkAssignedProductsOptions($_availableOptions, $assignedProductsArray);
172
  }
173
-
174
  $attributesSetArray = $this->_objectToArray($attributesSet);
175
  $attributesSetArray = $this->_prepareAttributesData($attributesSetArray, $assignedProductsArray);
176
-
177
  foreach($attributesSetArray as $key=>$value)
178
  {
179
  $attributesSetArray[$key]["id"] = NULL;
180
  $attributesSetArray[$key]["position"] = NULL;
181
-
182
- }
183
-
184
  }
185
 
186
  private function _checkAssignedProductsOptions($availableOptions, & $assignedProductsArray)
@@ -192,9 +192,9 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
192
  if (isset($availableOptions[$option['attribute_id']][strtolower($option['label'])]))
193
  {
194
  $assignedProductsArray[$id][$index]['value_index'] = $availableOptions[$option['attribute_id']][strtolower($option['label'])];
195
- }
196
  }
197
- }
198
  }
199
 
200
  private function _createOptions($newOptions)
@@ -202,46 +202,46 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
202
  $installer = new Mage_Eav_Model_Entity_Setup('core_setup');
203
  $attributeApi = Mage::getModel('catalog/product_attribute_api');
204
  $helperCatalog = Mage::helper('catalog');
205
-
206
  $installer->startSetup();
207
-
208
  $attributesList = array();
209
-
210
  foreach($newOptions as $attribute_id=>$options)
211
  {
212
  $aOption = array();
213
  $aOption['attribute_id'] = $attribute_id;
214
  $attributesList[] = $attribute_id;
215
-
216
  $i=0;
217
  foreach($options as $option)
218
  {
219
  $optionTitle = $helperCatalog->stripTags($option);
220
-
221
- $aOption['value']['option'.$i][0] = $optionTitle;
222
  $i++;
223
  }
224
  $installer->addAttributeOption($aOption);
225
- }
226
  $installer->endSetup();
227
 
228
  Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG));
229
 
230
-
231
  $currentOptions = array();
232
  $attributeApi = Mage::getModel('catalog/product_attribute_api');
233
  foreach($attributesList as $attribute_id)
234
  {
235
  if (!isset($currentOptions[$attribute_id]))
236
  $currentOptions[$attribute_id] = array();
237
-
238
  $attributeOptions = $attributeApi->options($attribute_id);
239
-
240
  foreach ($attributeOptions as $opts)
241
  {
242
  $label = strtolower($opts['label']);
243
  $optionId = $opts['value'];
244
- if (!isset($currentOptions[$attribute_id][$label]))
245
  $currentOptions[$attribute_id][$label] = $optionId;
246
  else {
247
  $oldId = $currentOptions[$attribute_id][$label];
@@ -253,14 +253,14 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
253
  else
254
  {
255
  $attributeApi->removeOption($attribute_id, $optionId);
256
- }
257
  }
258
  }
259
- }
260
-
261
- return $currentOptions;
262
  }
263
-
264
  private function _newConfigurableOptions($assignedProductsArray)
265
  {
266
  $_attributesOptions = array();
@@ -277,17 +277,17 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
277
  else
278
  {
279
  $_attributesOptions[$option['attribute_id']] = array($option['label']);
280
- }
281
- }
282
  }
283
- }
284
  return $_attributesOptions;
285
  }
286
-
287
  private function _newOptions($productData)
288
  {
289
  $_attributesOptions = array();
290
-
291
  if (property_exists($productData, 'additional_attributes')) {
292
  $_attributes = $productData->additional_attributes;
293
  if (is_array($_attributes)) {
@@ -302,7 +302,7 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
302
  {
303
  $_attributesOptions[$_attribute->attribute_id] = array($_attribute->label);
304
  }
305
- }
306
  }
307
  }
308
  else
@@ -318,21 +318,21 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
318
  $_attributesOptions[$_attributes->attribute_id] = array($_attributes->label);
319
  }
320
  }
321
- }
322
-
323
  }
324
-
325
  return $_attributesOptions;
326
  }
327
-
328
  private function _containsOption($attributeOption, $option)
329
  {
330
  foreach ($attributeOption as $inArrayOption)
331
  if ($inArrayOption['value_index'] == $option['value_index']) return true;
332
-
333
  return false;
334
  }
335
-
336
  private function _prepareAttributesData($attributesSetArray, $assignedProductsArray)
337
  {
338
  $_attributesOptions = array();
@@ -340,7 +340,7 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
340
  {
341
  foreach($productOptions as $option)
342
  {
343
- if (isset($_attributesOptions[$option['attribute_id']]) &&
344
  !$this->_containsOption($_attributesOptions[$option['attribute_id']], $option))
345
  {
346
  $_attributesOptions[$option['attribute_id']][] = $option;
@@ -349,16 +349,16 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
349
  {
350
  $_attributesOptions[$option['attribute_id']] = array();
351
  $_attributesOptions[$option['attribute_id']][] = $option;
352
- }
353
  }
354
  }
355
-
356
  foreach($attributesSetArray as $key => $attribute)
357
  {
358
  if (isset($_attributesOptions[$attribute['attribute_id']]))
359
  $attributesSetArray[$key]['values'] = $_attributesOptions[$attribute['attribute_id']];
360
  }
361
-
362
  return $attributesSetArray;
363
  }
364
 
@@ -369,9 +369,9 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
369
  {
370
  $store = Mage::app()->getStore($store)->getId();
371
  }
372
-
373
  $product = Mage::helper('catalog/product')->getProduct($productId, $store, $identifierType);
374
-
375
  $product->setConfigurableProductsData($assignedProducts);
376
  if (!$isUpdate)
377
  $product->setConfigurableAttributesData($assignedAttributes);
@@ -383,7 +383,7 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
383
  catch (Exception $e){
384
  throw new Mage_Api_Exception('configurable_creating_error', $e->getMessage());
385
  }
386
-
387
  if ($reindex === true)
388
  {
389
  try {
@@ -394,16 +394,16 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
394
  throw new Mage_Api_Exception('configurable_creating_error', $e->getMessage());
395
  }
396
  }
397
-
398
  return $result;
399
  }
400
 
401
  private function _createProductsData($productData)
402
  {
403
  $assignedProductsData = array();
404
-
405
  if (is_array($productData))
406
- {
407
  foreach ($productData as $product)
408
  {
409
  $assignedProductsData[$product->product_id] = array();
@@ -414,12 +414,12 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
414
  {
415
  $assignedProductsData[$productData->product_id] = array();
416
  $this->_fillAssignedProductValues($product, $assignedProductsData);
417
- }
418
-
419
-
420
  return $assignedProductsData;
421
  }
422
-
423
  private function _fillAssignedProductValues(& $product, & $assignedProductsData)
424
  {
425
  if (is_array($product->values))
@@ -434,20 +434,20 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
434
  $assignedProductsData[$product->product_id][] = $product->values;
435
  }
436
  }
437
-
438
  private function _updateConfigurableQuantity( & $productData)
439
  {
440
  $this->_updateQuantity($productData);
441
-
442
  if (!property_exists($productData, 'stock_data'))
443
  {
444
  $productData->stock_data = new stdClass();
445
  }
446
-
447
  $productData->stock_data->manage_stock = 1;
448
  $productData->stock_data->is_in_stock = 1;
449
  }
450
-
451
  private function _updateQuantity( & $productData)
452
  {
453
  if (property_exists($productData, 'stock_data') && property_exists($productData->stock_data, 'qty')) {
@@ -471,47 +471,47 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
471
  $array[$key]=$value;
472
  }
473
  }
474
- return $array;
475
  }
476
-
477
  private function _getCurrentVersion()
478
  {
479
  $verInfo = Mage::getVersionInfo();
480
-
481
- return intval($verInfo['major'].$verInfo['minor'].$verInfo['revision']);
482
  }
483
-
484
  private function _productImages($attributesList)
485
  {
486
- $_images = array();
487
-
488
  if (is_array($attributesList) && count($attributesList) > 0 && isset($attributesList['media_gallery']))
489
  {
490
  $small = empty($attributesList['small_image']) ? false : $attributesList['small_image'];
491
  $base = empty($attributesList['image']) ? false : $attributesList['image'];
492
  $thumb = empty($attributesList['thumbnail']) ? false : $attributesList['thumbnail'];
493
-
494
  foreach($attributesList['media_gallery']['images'] as $key=>$value)
495
  {
496
  $newImage = array();
497
  $newImage['file'] = $value['file'];
498
  $newImage['label'] = $value['label'];
499
  $newImage['disabled'] = $value['disabled'] ? true : false;
500
-
501
- $newImage['small_image'] = $small == $newImage['file'];
502
- $newImage['image'] = $base == $newImage['file'];
503
- $newImage['thumbnail'] = $thumb == $newImage['file'];
504
-
505
  $_images[] = $newImage;
506
  }
507
  }
508
-
509
  return $_images;
510
  }
511
 
512
  private function _removeIgnoredAttributes($attributesList)
513
  {
514
- $_preparedAttributes = array();
515
  if (is_array($attributesList) && count($attributesList) > 0)
516
  {
517
  foreach($attributesList as $key=>$value)
@@ -520,30 +520,30 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
520
  $_preparedAttributes[]= array('key' => $key, 'value' => $value);
521
  }
522
  }
523
-
524
  return $_preparedAttributes;
525
  }
526
-
527
  private function _currentStoreCode($store=null)
528
  {
529
  if ($store != null)
530
  return $store;
531
-
532
  return $this->_getStore()->getCode();
533
  }
534
-
535
  private function _getStore($storeCode=null)
536
  {
537
  if (Mage::app()->isSingleStoreMode()) {
538
  return Mage::app()->getWebsite(true)->getDefaultStore();
539
  }
540
-
541
  $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
542
  $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
543
 
544
  if ($storeCode != null)
545
  return Mage::getModel('core/store')->load( $storeCode, 'code');
546
-
547
  if ($mageRunType == 'store') {
548
  if (!empty($mageRunCode))
549
  {
@@ -551,11 +551,11 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
551
  }
552
  }
553
  else {
554
- if ($mageRunType == 'website')
555
  $websiteCode = empty($mageRunCode) ? '' : $mageRunCode;
556
  else
557
  $websiteCode = empty($mageRunType) ? '' : $mageRunType;
558
-
559
  if (!empty($websiteCode))
560
  {
561
  $currentWebSite = Mage::getModel('core/website')->load( $websiteCode, 'code');
@@ -564,16 +564,16 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
564
  return $defaultStore;
565
  }
566
  }
567
-
568
-
569
  return Mage::app()->getWebsite(true)->getDefaultStore();//Mage::app()->getStore();
570
  }
571
-
572
  private function _getWebsiteId($store=null)
573
  {
574
  return array($this->_getStore($store)->getWebsiteId());
575
  }
576
-
577
  private function _productAttributeInfo($attribute_id, $attributeAPI)
578
  {
579
  $model = Mage::getResourceModel('catalog/eav_attribute')
@@ -624,17 +624,17 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
624
 
625
  return $result;
626
  }
627
-
628
  //Fix for buggy associativeArray implementation
629
  private function _fixAttributes($productData)
630
  {
631
  $_newAttributeOptions = $this->_newOptions($productData);
632
- $_availableOptions = array();
633
  if (count($_newAttributeOptions) > 0)
634
  {
635
  $_availableOptions = $this->_createOptions($_newAttributeOptions);
636
  }
637
-
638
  if (property_exists($productData, 'additional_attributes')) {
639
  $tmpAttr = $productData->additional_attributes;
640
  if (count($tmpAttr) == 0)
@@ -642,7 +642,7 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
642
  unset($productData->additional_attributes);
643
  return $productData;
644
  }
645
-
646
  $i=0;
647
  if (is_array($tmpAttr))
648
  {
@@ -652,7 +652,7 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
652
  {
653
  $productData->$code = array();
654
  }
655
- if (isset($_availableOptions[$option->attribute_id][strtolower($option->label)]))
656
  {
657
  if ($option->type == 'multiselect')
658
  {
@@ -680,20 +680,20 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
680
  else
681
  {
682
  $code = $tmpAttr->code;
683
- if (isset($_availableOptions[$tmpAttr->attribute_id][strtolower($tmpAttr->label)]))
684
  $productData->$code = $_availableOptions[$tmpAttr->attribute_id][strtolower($tmpAttr->label)];
685
  else
686
- $productData->$code = $tmpAttr->value;
687
- }
688
  }
689
 
690
  unset($productData->additional_attributes);
691
-
692
  return $productData;
693
  }
694
-
695
-
696
-
697
  /*
698
  *
699
  * Public functions(API)
@@ -703,18 +703,18 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
703
  {
704
  if (!$set || !$sku) {
705
  throw new Mage_Api_Exception('data_invalid');
706
- }
707
-
708
  $this->_prepareConfigurableData($store, $productData, $assignedProductsArray,
709
  $attributesSetArray, $productsSet, $attributesSet);
710
-
711
  $DefaultStore = $this->_getStore();
712
-
713
  if (property_exists($productData, 'websites') === false && isset($DefaultStore) ) {
714
  $productData->websites = array($DefaultStore->getWebsiteId());
715
  }
716
-
717
- if (property_exists($productData, 'category_ids') && !is_array($productData->category_ids))
718
  {
719
  if (is_string($productData->category_ids)) {
720
  $productData->category_ids = array($productData->category_ids);
@@ -724,43 +724,43 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
724
  {
725
  $productData->category_ids = array();
726
  }
727
-
728
  $productData->categories = $productData->category_ids;
729
 
730
- $productAPI = new Mage_Catalog_Model_Product_Api_V2();
731
  $productId = $productAPI->create('configurable', $set, $sku, $productData, $store);
732
-
733
  $this->_updateConfigurable($store, $productId, $productData, $assignedProductsArray, $attributesSetArray, 'id', false, $reindex);
734
-
735
- return $productId;
736
  }
737
 
738
  public function updateConfigurableProduct($productId, $reindex, $productData, $productsSet, $attributesSet, $store=null, $identifierType='id')
739
- {
740
  if ($identifierType == 'id')
741
  {
742
  $productId = intval($productId);
743
-
744
  if ($productId < 1) {
745
  throw new Mage_Api_Exception('product_not_exists', null);
746
  }
747
  }
748
-
749
  $this->_prepareConfigurableData($store, $productData, $assignedProductsArray,
750
  $attributesSetArray, $productsSet, $attributesSet);
751
-
752
  try {
753
  $storeId = Mage::app()->getStore($store)->getId();
754
  } catch (Mage_Core_Model_Store_Exception $e) {
755
  throw new Mage_Api_Exception('store_not_exists', null);
756
  }
757
-
758
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($productId, $storeId, $identifierType);
759
-
760
  $_categoryIds = $_loadedProduct->getCategoryIds();
761
- if (property_exists($productData, 'category_ids'))
762
  {
763
-
764
  if (!is_array($productData->category_ids))
765
  {
766
  $productData->category_ids = array($productData->category_ids);
@@ -769,41 +769,41 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
769
  $productData->category_ids = array_merge($_categoryIds, $productData->category_ids);
770
 
771
  }
772
- else
773
  {
774
  $productData->category_ids = $_categoryIds;
775
  }
776
-
777
  $productData->category_ids = array_unique($productData->category_ids);
778
-
779
- if ( (property_exists($productData, 'removed_categories') === true)
780
  && (is_array($productData->removed_categories) === true)
781
  && (count($productData->removed_categories) > 0) )
782
  {
783
  $tmpCats = array();
784
-
785
  $productData->category_ids = array_diff($productData->category_ids, $productData->removed_categories);
786
  }
787
-
788
  $productData->categories = $productData->category_ids;
789
-
790
  if (property_exists($productData, 'add_to_websites') && $productData->add_to_websites === true)
791
  {
792
  $currentWebsites = $_loadedProduct->getWebsiteIds();
793
  $websiteId = $this->_getWebsiteId();
794
  $websiteId = $websiteId[0];
795
-
796
  if (in_array($websiteId, $currentWebsites) === false)
797
  {
798
  $currentWebsites[] = $websiteId;
799
  $productData->websites = $currentWebsites;
800
- }
801
  }
802
-
803
- $productAPI = new Mage_Catalog_Model_Product_Api_V2();
804
-
805
  $productAPI->update($productId, $productData, $store, $identifierType);
806
-
807
  return $this->_updateConfigurable($store, $productId, $productData, $assignedProductsArray, $attributesSetArray, $identifierType, true, $reindex);
808
  }
809
 
@@ -811,75 +811,75 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
811
  * Checks if this Magento server has valid Extension installed
812
  */
813
  public function storesList()
814
- {
815
  return ($this->_getCurrentVersion() >= 160);
816
  }
817
-
818
  public function getStoreCode($store=null)
819
- {
820
  return $this->_currentStoreCode($store);
821
  }
822
-
823
  public function deleteAssigned($productId, $store=null, $identifierType='id')
824
  {
825
  if ($identifierType == 'id')
826
  {
827
  $productId = intval($productId);
828
-
829
  if ($productId < 1) {
830
  throw new Mage_Api_Exception('product_not_exists', null);
831
  }
832
  }
833
-
834
  $store = $this->_currentStoreCode($store);
835
-
836
  try {
837
  $storeId = Mage::app()->getStore($store)->getId();
838
  } catch (Mage_Core_Model_Store_Exception $e) {
839
  throw new Mage_Api_Exception('store_not_exists', null);
840
  }
841
-
842
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($productId, $storeId, $identifierType);
843
  $currentWebsites = $_loadedProduct->getWebsiteIds();
844
  $websiteId = $this->_getWebsiteId($store);
845
  $websiteId = $websiteId[0];
846
-
847
  $newWebsiteIds = array();
848
-
849
  if (in_array($websiteId, $currentWebsites) === true)
850
  {
851
- for($i = 0; $i < count($currentWebsites); $i++)
852
  {
853
  if ($currentWebsites[$i] != $websiteId)
854
  {
855
  $newWebsiteIds[] = $currentWebsites[$i];
856
  }
857
  }
858
-
859
  $_loadedProduct->setWebsiteIds($newWebsiteIds);
860
-
861
  $_loadedProduct->save();
862
- }
863
-
864
  return true;
865
  }
866
-
867
-
868
  public function assignImages($productImages)
869
  {
870
  $store = $this->_currentStoreCode(null);
871
-
872
  foreach($productImages as $imageData)
873
  {
874
  $productId = intval($imageData->product_id);
875
  if ($productId < 1) {
876
  throw new Mage_Api_Exception('product_not_exists', null);
877
  }
878
-
879
  $product = Mage::helper('catalog/product')->getProduct($productId, $store, 'id');
880
-
881
  $images = $imageData->images;
882
-
883
  $baseImageExist = false;
884
  foreach($images as $image)
885
  {
@@ -900,7 +900,7 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
900
  {
901
  $catalogProductDir = Mage::getBaseDir('media') . DS . 'catalog/product';
902
  $filePath = $catalogProductDir.$image->image_name;
903
-
904
  if (is_array($image->types) && count($image->types) > 0)
905
  {
906
  $imageTypes = $image->types;
@@ -909,27 +909,27 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
909
  {
910
  $imageTypes = "";
911
  }
912
-
913
- try
914
  {
915
  $product->addImageToMediaGallery($filePath, $imageTypes, false, false);
916
- }
917
  catch (Exception $e) { }
918
-
919
  }
920
 
921
  $product->save();
922
  }
923
-
924
  return true;
925
  }
926
-
927
  /*
928
- * Implementation of catalogProductList because of bug in associativeArray.
929
  * Extended to filter by category id too.
930
  *
931
  * Use 'entity_id' for product_id,
932
- * 'type_id' instead of product type.
933
  */
934
  public function productList($page, $perPage, $filters = null, $store = null)
935
  {
@@ -937,9 +937,9 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
937
  'nin',
938
  'in',
939
  );
940
-
941
  $store = $this->_currentStoreCode($store);
942
-
943
  try {
944
  $storeId = Mage::app()->getStore($store)->getId();
945
  } catch (Mage_Core_Model_Store_Exception $e) {
@@ -955,22 +955,24 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
955
  if (isset($filters->complex_filter)) {
956
  foreach ($filters->complex_filter as $_key => $_filter) {
957
  $_op = $_filter->key;
958
- $_filterVal = $_filter->value;
 
959
 
960
  if (in_array($_op, $arrayParams)) {
961
- $values = implode(',', $_filterVal);
962
  }
963
  else {
964
  $values = $_filterVal;
965
  }
966
- $preparedFilters[$_key] = array(
967
- $_op => $values
968
- );
 
969
  }
970
  }
971
 
972
- if (isset($preparedFilters['category']) &&
973
- is_string($preparedFilters['category']))
974
  {
975
  $_categoryId = intval($preparedFilters['category']);
976
  unset($preparedFilters['category']);
@@ -980,7 +982,7 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
980
  }
981
 
982
  if (!empty($preparedFilters)) {
983
- if ($_categoryId > 0)
984
  {
985
  $_category = Mage::getModel('catalog/category')->load($_categoryId);
986
  $collection = Mage::getModel('catalog/product')->getCollection()
@@ -1012,7 +1014,7 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1012
  ->setCurPage($page);
1013
  $count = 0;
1014
  }
1015
-
1016
  $result = array();
1017
  $result['count'] = $count;
1018
  $result['products'] = array();
@@ -1024,17 +1026,17 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1024
  foreach ($collection as $_product) {
1025
  if ($i >= ($perPage * $page)) break;
1026
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($_product->getId(), $storeId, 'id');
1027
-
1028
  $_allAttributes = $_loadedProduct->getData();
1029
-
1030
-
1031
  $_description = isset($_allAttributes['description']) ? $_allAttributes['description'] : '';
1032
-
1033
  $_productImages = $this->_productImages($_allAttributes);
1034
  $_productAttributes = $this->_removeIgnoredAttributes($_allAttributes);
1035
-
1036
  $_fetchedIds[] = $_loadedProduct->getId();
1037
-
1038
  $result['products'][$i] = array(
1039
  'product_id' => $_loadedProduct->getId(),
1040
  'sku' => $_loadedProduct->getSku(),
@@ -1065,36 +1067,36 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1065
  'price_diff' => $price['pricing_value'],
1066
  'label' => $price['label'],
1067
  );
1068
-
1069
  }
1070
-
1071
  $result['products'][$i]['conf_attrib_ids'][] = array(
1072
  'code' => $attribute->getProductAttribute()->getAttributeCode(),
1073
  'prices' => $_prices
1074
- );
1075
  }
1076
  $_assignedIds = array_merge($_assignedIds, $result['products'][$i]['assigned_ids']);
1077
  }
1078
-
1079
  $i++;
1080
  }
1081
 
1082
  $_absentIds = array_diff($_assignedIds, $_fetchedIds);
1083
-
1084
  if (count($_absentIds) > 0)
1085
  {
1086
  $collection = Mage::getModel('catalog/product')->getCollection()->addIdFilter($_absentIds);
1087
-
1088
  foreach ($collection as $_product) {
1089
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($_product->getId(), $storeId, 'id');
1090
-
1091
  $_allAttributes = $_product->getData();
1092
-
1093
  $_description = isset($_allAttributes['description']) ? $_allAttributes['description'] : '';
1094
-
1095
  $_productImages = $this->_productImages($_allAttributes);
1096
  $_productAttributes = $this->_removeIgnoredAttributes($_allAttributes);
1097
-
1098
  $result['products'][] = array(
1099
  'product_id' => $_loadedProduct->getId(),
1100
  'sku' => $_loadedProduct->getSku(),
@@ -1120,23 +1122,23 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1120
  public function productAttributeOptions($setId)
1121
  {
1122
  $result = array();
1123
-
1124
  $setId = intval($setId);
1125
  if ($setId <= 0) return $result;
1126
-
1127
  $attributeAPI = Mage::getModel('catalog/product_attribute_api');
1128
-
1129
  $items = $attributeAPI->items($setId);
1130
-
1131
  $attributes = Mage::getModel('catalog/product')->getResource()
1132
  ->loadAllAttributes();
1133
-
1134
- $i=0;
1135
  foreach ($items as $item) {
1136
  if (!isset($item['attribute_id']) || empty($item['attribute_id'])) continue;
1137
  $attributeId = intval($item['attribute_id']);
1138
  if ($attributeId <= 0) continue;
1139
-
1140
  $additionInfo = $this->_productAttributeInfo($attributeId, $attributeAPI);
1141
 
1142
  if (in_array($additionInfo['frontend_input'], $this->_permittedAttributes) &&
@@ -1150,9 +1152,9 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1150
  'scope' => $additionInfo['scope'],
1151
  'can_config' => 0
1152
  );
1153
-
1154
  if ( ($additionInfo['frontend_input'] == 'select') || ($additionInfo['frontend_input'] == 'multiselect') ) {
1155
- if (($additionInfo['scope'] == 'global') &&
1156
  ($additionInfo['is_configurable']))
1157
  {
1158
  foreach ($additionInfo['apply_to'] as $applyTo)
@@ -1162,16 +1164,16 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1162
  $result[$i]['can_config'] = 1;
1163
  break;
1164
  }
1165
- }
1166
-
1167
  }
1168
  if (isset($additionInfo['options']))
1169
  $result[$i]['attribute_options'] = $additionInfo['options'];
1170
- }
1171
  $i++;
1172
  }
1173
  }
1174
-
1175
  return $result;
1176
  }
1177
 
@@ -1180,21 +1182,21 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1180
  if ($identifierType == 'id')
1181
  {
1182
  $productId = intval($productId);
1183
-
1184
  if ($productId < 1) {
1185
  throw new Mage_Api_Exception('product_not_exists', null);
1186
  }
1187
  }
1188
-
1189
  $store = $this->_currentStoreCode($store);
1190
  try {
1191
  $storeId = Mage::app()->getStore($store)->getId();
1192
  } catch (Mage_Core_Model_Store_Exception $e) {
1193
  throw new Mage_Api_Exception('store_not_exists', null);
1194
  }
1195
-
1196
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($productId, $storeId, $identifierType);
1197
-
1198
  $_categoryIds = $_loadedProduct->getCategoryIds();
1199
  if (property_exists($productData, 'category_ids'))
1200
  {
@@ -1202,46 +1204,46 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1202
  {
1203
  $productData->category_ids = array($productData->category_ids);
1204
  }
1205
-
1206
  $productData->category_ids = array_merge($_categoryIds, $productData->category_ids);
1207
  }
1208
- else
1209
  {
1210
  $productData->category_ids = $_categoryIds;
1211
  }
1212
-
1213
  $productData->category_ids = array_unique($productData->category_ids);
1214
-
1215
- if ( (property_exists($productData, 'removed_categories') === true)
1216
  && (is_array($productData->removed_categories) === true)
1217
  && (count($productData->removed_categories) > 0) )
1218
  {
1219
  $tmpCats = array();
1220
-
1221
  $productData->category_ids = array_diff($productData->category_ids, $productData->removed_categories);
1222
  }
1223
-
1224
  $productData->categories = $productData->category_ids;
1225
-
1226
  if (property_exists($productData, 'add_to_websites') && $productData->add_to_websites === true)
1227
- {
1228
  $currentWebsites = $_loadedProduct->getWebsiteIds();
1229
  $websiteId = $this->_getWebsiteId();
1230
  $websiteId = $websiteId[0];
1231
-
1232
  if (in_array($websiteId, $currentWebsites) === false)
1233
  {
1234
  $currentWebsites[] = $websiteId;
1235
  $productData->websites = $currentWebsites;
1236
  }
1237
  }
1238
-
1239
  $this->_updateQuantity($productData);
1240
 
1241
  $productData = $this->_fixAttributes($productData);
1242
 
1243
  $productAPI = new Mage_Catalog_Model_Product_Api_V2();
1244
-
1245
  $result = $productAPI->update($productId, $productData, $store, $identifierType);
1246
 
1247
  return $result;
@@ -1250,13 +1252,13 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1250
  public function create($type, $set, $sku, $productData, $store = null)
1251
  {
1252
  $store = $this->_currentStoreCode($store);
1253
-
1254
  $DefaultStore = $this->_getStore();
1255
-
1256
- if (property_exists($productData, 'websites') === false && isset($DefaultStore)) {
1257
  $productData->websites = array($DefaultStore->getWebsiteId());
1258
  }
1259
-
1260
  if (property_exists($productData, 'category_ids') && !is_array($productData->category_ids)) {
1261
  if (is_string($productData->category_ids))
1262
  $productData->category_ids = array($productData->category_ids);
@@ -1265,50 +1267,50 @@ class LinnLiveMain extends Mage_Core_Model_Abstract{
1265
  {
1266
  $productData->category_ids = array();
1267
  }
1268
-
1269
- $productData->categories = $productData->category_ids;
1270
-
1271
  $this->_updateQuantity($productData);
1272
-
1273
  $productData = $this->_fixAttributes($productData);
1274
-
1275
  $productAPI = new Mage_Catalog_Model_Product_Api_V2();
1276
-
1277
  return $productAPI->create($type, $set, $sku, $productData, $store);
1278
  }
1279
 
1280
  public function debugInfo()
1281
  {
1282
  $verInfo = Mage::getVersionInfo();
1283
-
1284
  $result = array(
1285
  'llc_ver' => Settings::$VERSION,
1286
  'magento_ver' => $verInfo
1287
  );
1288
-
1289
  return $result;
1290
- }
1291
  }
1292
 
1293
  class LinnLiveEnterprise extends LinnLiveMain{
1294
-
1295
  public function productAttributeOptions($setId)
1296
  {
1297
  $result = array();
1298
-
1299
  $setId = intval($setId);
1300
  if ($setId <= 0) return $result;
1301
-
1302
  $attributeAPI = Mage::getModel('catalog/product_attribute_api');
1303
-
1304
  $attributes = Mage::getModel('catalog/product')->getResource()
1305
  ->loadAllAttributes()
1306
  ->getSortedAttributes($setId);
1307
-
1308
  $i=0;
1309
-
1310
  foreach ($attributes as $attribute) {
1311
-
1312
  if ((!$attribute->getId() || $attribute->isInSet($setId))
1313
  && !in_array($attribute->getAttributeCode(), $this->_ignoredAttributes)
1314
  && in_array($attribute->getFrontendInput(), $this->_permittedAttributes)) {
@@ -1329,26 +1331,26 @@ class LinnLiveEnterprise extends LinnLiveMain{
1329
  'scope' => $scope,
1330
  'can_config' => 0
1331
  );
1332
-
1333
  if ( ($attribute->getFrontendInput() == 'select') || ($attribute->getFrontendInput() == 'multiselect') ) {
1334
- if (($scope == 'global') &&
1335
  $attribute->getIsConfigurable())
1336
  {
1337
  if (strpos($attribute->getApplyTo(), 'simple') !== false)
1338
  $result[$i]['can_config'] = 1;
1339
  }
1340
-
1341
  $options = $attributeAPI->options($attribute->getId());
1342
-
1343
  // remove empty first element
1344
  if ($attribute->getFrontendInput() != 'boolean') {
1345
  array_shift($options);
1346
  }
1347
-
1348
  if (count($options) > 0) {
1349
  $result[$i]['attribute_options'] = $options;
1350
  }
1351
- }
1352
  $i++;
1353
  }
1354
  }
@@ -1360,12 +1362,12 @@ class LinnLiveEnterprise extends LinnLiveMain{
1360
  private function _fixAttributes($productData)
1361
  {
1362
  $_newAttributeOptions = $this->_newOptions($productData);
1363
- $_availableOptions = array();
1364
  if (count($_newAttributeOptions) > 0)
1365
  {
1366
  $_availableOptions = $this->_createOptions($_newAttributeOptions);
1367
  }
1368
-
1369
  if (property_exists($productData, 'additional_attributes')) {
1370
  $tmpAttr = $productData->additional_attributes;
1371
  if (count($tmpAttr) == 0)
@@ -1381,13 +1383,13 @@ class LinnLiveEnterprise extends LinnLiveMain{
1381
  foreach ($tmpAttr as $option) {
1382
  $productData->additional_attributes->single_data[$i] = new stdClass();
1383
  $productData->additional_attributes->single_data[$i]->key = $option->code;
1384
-
1385
  if ( ($option->type == 'multiselect') && (is_array($productData->additional_attributes->single_data[$i]->value) == false) )
1386
  {
1387
  $productData->additional_attributes->single_data[$i]->value = array();
1388
  }
1389
-
1390
- if (isset($_availableOptions[$option->attribute_id][strtolower($option->label)]))
1391
  {
1392
  if ($option->type == 'multiselect')
1393
  {
@@ -1416,18 +1418,18 @@ class LinnLiveEnterprise extends LinnLiveMain{
1416
  {
1417
  $productData->additional_attributes->single_data[0] = new stdClass();
1418
  $productData->additional_attributes->single_data[0]->key = $tmpAttr->code;
1419
- if (isset($_availableOptions[$tmpAttr->attribute_id][strtolower($tmpAttr->label)]))
1420
  $productData->additional_attributes->single_data[0]->value = $_availableOptions[$tmpAttr->attribute_id][strtolower($tmpAttr->label)];
1421
  else
1422
  $productData->additional_attributes->single_data[0]->value = $tmpAttr->value;
1423
- }
1424
  }
1425
-
1426
  return $productData;
1427
  }
1428
  }
1429
 
1430
  class LinnLiveCommunity extends LinnLiveMain{
1431
-
1432
  }
1433
  ?>
1
  <?php
2
  class Settings {
3
+ static $VERSION = 38;
4
  }
5
 
6
  class LinnSystems_LinnLiveConnect_Model_Api_V2{
7
 
8
  public function configurableProduct($version, $set, $sku, $reindex, $productData, $productsSet, $attributesSet, $store=null)
9
+ {
10
  $worker = Factory::createWorker($version);
11
+ return $worker->configurableProduct($set, $sku, $reindex, $productData, $productsSet, $attributesSet, $store);
12
  }
13
 
14
  public function updateConfigurableProduct($version, $productId, $reindex, $productData, $productsSet, $attributesSet, $store=null, $identifierType='id')
22
  $worker = Factory::createWorker($version);
23
  return $worker->storesList();
24
  }
25
+
26
  public function getStoreCode($version, $store=null)
27
  {
28
  $worker = Factory::createWorker($version);
29
  return $worker->getStoreCode($store);
30
  }
31
+
32
  public function deleteAssigned($version, $productId, $store=null, $identifierType='id')
33
  {
34
  $worker = Factory::createWorker($version);
35
  return $worker->deleteAssigned($productId, $store, $identifierType);
36
  }
37
+
38
  public function assignImages($version, $productImages)
39
  {
40
  $worker = Factory::createWorker($version);
41
  return $worker->assignImages($productImages);
42
  }
43
+
44
  public function productList($version, $page, $perPage, $filters = null, $store = null)
45
  {
46
  $worker = Factory::createWorker($version);
73
  }
74
 
75
  class Factory{
76
+
77
  private function _checkVersion($version)
78
  {
79
  $version = intval($version);
80
+
81
  if ($version == 0)
82
  throw new Mage_Api_Exception('version is not specified');
83
  if (Settings::$VERSION < $version )
84
  throw new Mage_Api_Exception('wrong_version');
85
  }
86
+
87
+
88
  public static function createWorker($version)
89
  {
90
  self::_checkVersion($version);
91
+
92
  if(Mage::GetEdition() == Mage::EDITION_COMMUNITY)
93
  {
94
  return new LinnLiveCommunity();
101
  {
102
  throw new Mage_Api_Exception('unsupported_edition');
103
  }
104
+
105
  }
106
  }
107
 
108
  class LinnLiveMain extends Mage_Core_Model_Abstract{
109
 
110
+
111
  private $_ignoredAttributes = array(
112
  'created_at',
113
  'updated_at',
134
  'stock_item',
135
  'description',
136
  );
137
+
138
  private $_permittedAttributes = array (
139
  'select',
140
  'multiselect',
141
+ 'text',
142
+ 'textarea',
143
  'date',
144
  'price'
145
  );
146
+
147
  private function _prepareConfigurableData(
148
+ & $store, & $productData, & $assignedProductsArray,
149
  & $attributesSetArray, $productsSet, $attributesSet)
150
  {
151
+ $store = $this->_currentStoreCode($store);
152
+
153
  $this->_updateConfigurableQuantity($productData);
154
+
155
  $productData = $this->_fixAttributes($productData);
156
+
157
  if (!is_array($attributesSet))
158
  {
159
  $tmpSet = $attributesSet;
160
  $attributesSet = array();
161
  $attributesSet[] = $tmpSet;
162
  }
163
+
164
  $assignedProductsData = $this->_createProductsData($productsSet);
165
  $assignedProductsArray = $this->_objectToArray($assignedProductsData);
166
+
167
+ $_newAttributeOptions = $this->_newConfigurableOptions($assignedProductsArray);
168
  if (count($_newAttributeOptions) > 0)
169
  {
170
  $_availableOptions = $this->_createOptions($_newAttributeOptions);
171
  $this->_checkAssignedProductsOptions($_availableOptions, $assignedProductsArray);
172
  }
173
+
174
  $attributesSetArray = $this->_objectToArray($attributesSet);
175
  $attributesSetArray = $this->_prepareAttributesData($attributesSetArray, $assignedProductsArray);
176
+
177
  foreach($attributesSetArray as $key=>$value)
178
  {
179
  $attributesSetArray[$key]["id"] = NULL;
180
  $attributesSetArray[$key]["position"] = NULL;
181
+
182
+ }
183
+
184
  }
185
 
186
  private function _checkAssignedProductsOptions($availableOptions, & $assignedProductsArray)
192
  if (isset($availableOptions[$option['attribute_id']][strtolower($option['label'])]))
193
  {
194
  $assignedProductsArray[$id][$index]['value_index'] = $availableOptions[$option['attribute_id']][strtolower($option['label'])];
195
+ }
196
  }
197
+ }
198
  }
199
 
200
  private function _createOptions($newOptions)
202
  $installer = new Mage_Eav_Model_Entity_Setup('core_setup');
203
  $attributeApi = Mage::getModel('catalog/product_attribute_api');
204
  $helperCatalog = Mage::helper('catalog');
205
+
206
  $installer->startSetup();
207
+
208
  $attributesList = array();
209
+
210
  foreach($newOptions as $attribute_id=>$options)
211
  {
212
  $aOption = array();
213
  $aOption['attribute_id'] = $attribute_id;
214
  $attributesList[] = $attribute_id;
215
+
216
  $i=0;
217
  foreach($options as $option)
218
  {
219
  $optionTitle = $helperCatalog->stripTags($option);
220
+
221
+ $aOption['value']['option'.$i][0] = $optionTitle;
222
  $i++;
223
  }
224
  $installer->addAttributeOption($aOption);
225
+ }
226
  $installer->endSetup();
227
 
228
  Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG));
229
 
230
+
231
  $currentOptions = array();
232
  $attributeApi = Mage::getModel('catalog/product_attribute_api');
233
  foreach($attributesList as $attribute_id)
234
  {
235
  if (!isset($currentOptions[$attribute_id]))
236
  $currentOptions[$attribute_id] = array();
237
+
238
  $attributeOptions = $attributeApi->options($attribute_id);
239
+
240
  foreach ($attributeOptions as $opts)
241
  {
242
  $label = strtolower($opts['label']);
243
  $optionId = $opts['value'];
244
+ if (!isset($currentOptions[$attribute_id][$label]))
245
  $currentOptions[$attribute_id][$label] = $optionId;
246
  else {
247
  $oldId = $currentOptions[$attribute_id][$label];
253
  else
254
  {
255
  $attributeApi->removeOption($attribute_id, $optionId);
256
+ }
257
  }
258
  }
259
+ }
260
+
261
+ return $currentOptions;
262
  }
263
+
264
  private function _newConfigurableOptions($assignedProductsArray)
265
  {
266
  $_attributesOptions = array();
277
  else
278
  {
279
  $_attributesOptions[$option['attribute_id']] = array($option['label']);
280
+ }
281
+ }
282
  }
283
+ }
284
  return $_attributesOptions;
285
  }
286
+
287
  private function _newOptions($productData)
288
  {
289
  $_attributesOptions = array();
290
+
291
  if (property_exists($productData, 'additional_attributes')) {
292
  $_attributes = $productData->additional_attributes;
293
  if (is_array($_attributes)) {
302
  {
303
  $_attributesOptions[$_attribute->attribute_id] = array($_attribute->label);
304
  }
305
+ }
306
  }
307
  }
308
  else
318
  $_attributesOptions[$_attributes->attribute_id] = array($_attributes->label);
319
  }
320
  }
321
+ }
322
+
323
  }
324
+
325
  return $_attributesOptions;
326
  }
327
+
328
  private function _containsOption($attributeOption, $option)
329
  {
330
  foreach ($attributeOption as $inArrayOption)
331
  if ($inArrayOption['value_index'] == $option['value_index']) return true;
332
+
333
  return false;
334
  }
335
+
336
  private function _prepareAttributesData($attributesSetArray, $assignedProductsArray)
337
  {
338
  $_attributesOptions = array();
340
  {
341
  foreach($productOptions as $option)
342
  {
343
+ if (isset($_attributesOptions[$option['attribute_id']]) &&
344
  !$this->_containsOption($_attributesOptions[$option['attribute_id']], $option))
345
  {
346
  $_attributesOptions[$option['attribute_id']][] = $option;
349
  {
350
  $_attributesOptions[$option['attribute_id']] = array();
351
  $_attributesOptions[$option['attribute_id']][] = $option;
352
+ }
353
  }
354
  }
355
+
356
  foreach($attributesSetArray as $key => $attribute)
357
  {
358
  if (isset($_attributesOptions[$attribute['attribute_id']]))
359
  $attributesSetArray[$key]['values'] = $_attributesOptions[$attribute['attribute_id']];
360
  }
361
+
362
  return $attributesSetArray;
363
  }
364
 
369
  {
370
  $store = Mage::app()->getStore($store)->getId();
371
  }
372
+
373
  $product = Mage::helper('catalog/product')->getProduct($productId, $store, $identifierType);
374
+
375
  $product->setConfigurableProductsData($assignedProducts);
376
  if (!$isUpdate)
377
  $product->setConfigurableAttributesData($assignedAttributes);
383
  catch (Exception $e){
384
  throw new Mage_Api_Exception('configurable_creating_error', $e->getMessage());
385
  }
386
+
387
  if ($reindex === true)
388
  {
389
  try {
394
  throw new Mage_Api_Exception('configurable_creating_error', $e->getMessage());
395
  }
396
  }
397
+
398
  return $result;
399
  }
400
 
401
  private function _createProductsData($productData)
402
  {
403
  $assignedProductsData = array();
404
+
405
  if (is_array($productData))
406
+ {
407
  foreach ($productData as $product)
408
  {
409
  $assignedProductsData[$product->product_id] = array();
414
  {
415
  $assignedProductsData[$productData->product_id] = array();
416
  $this->_fillAssignedProductValues($product, $assignedProductsData);
417
+ }
418
+
419
+
420
  return $assignedProductsData;
421
  }
422
+
423
  private function _fillAssignedProductValues(& $product, & $assignedProductsData)
424
  {
425
  if (is_array($product->values))
434
  $assignedProductsData[$product->product_id][] = $product->values;
435
  }
436
  }
437
+
438
  private function _updateConfigurableQuantity( & $productData)
439
  {
440
  $this->_updateQuantity($productData);
441
+
442
  if (!property_exists($productData, 'stock_data'))
443
  {
444
  $productData->stock_data = new stdClass();
445
  }
446
+
447
  $productData->stock_data->manage_stock = 1;
448
  $productData->stock_data->is_in_stock = 1;
449
  }
450
+
451
  private function _updateQuantity( & $productData)
452
  {
453
  if (property_exists($productData, 'stock_data') && property_exists($productData->stock_data, 'qty')) {
471
  $array[$key]=$value;
472
  }
473
  }
474
+ return $array;
475
  }
476
+
477
  private function _getCurrentVersion()
478
  {
479
  $verInfo = Mage::getVersionInfo();
480
+
481
+ return intval($verInfo['major'].$verInfo['minor'].$verInfo['revision']);
482
  }
483
+
484
  private function _productImages($attributesList)
485
  {
486
+ $_images = array();
487
+
488
  if (is_array($attributesList) && count($attributesList) > 0 && isset($attributesList['media_gallery']))
489
  {
490
  $small = empty($attributesList['small_image']) ? false : $attributesList['small_image'];
491
  $base = empty($attributesList['image']) ? false : $attributesList['image'];
492
  $thumb = empty($attributesList['thumbnail']) ? false : $attributesList['thumbnail'];
493
+
494
  foreach($attributesList['media_gallery']['images'] as $key=>$value)
495
  {
496
  $newImage = array();
497
  $newImage['file'] = $value['file'];
498
  $newImage['label'] = $value['label'];
499
  $newImage['disabled'] = $value['disabled'] ? true : false;
500
+
501
+ $newImage['small_image'] = $small == $newImage['file'];
502
+ $newImage['image'] = $base == $newImage['file'];
503
+ $newImage['thumbnail'] = $thumb == $newImage['file'];
504
+
505
  $_images[] = $newImage;
506
  }
507
  }
508
+
509
  return $_images;
510
  }
511
 
512
  private function _removeIgnoredAttributes($attributesList)
513
  {
514
+ $_preparedAttributes = array();
515
  if (is_array($attributesList) && count($attributesList) > 0)
516
  {
517
  foreach($attributesList as $key=>$value)
520
  $_preparedAttributes[]= array('key' => $key, 'value' => $value);
521
  }
522
  }
523
+
524
  return $_preparedAttributes;
525
  }
526
+
527
  private function _currentStoreCode($store=null)
528
  {
529
  if ($store != null)
530
  return $store;
531
+
532
  return $this->_getStore()->getCode();
533
  }
534
+
535
  private function _getStore($storeCode=null)
536
  {
537
  if (Mage::app()->isSingleStoreMode()) {
538
  return Mage::app()->getWebsite(true)->getDefaultStore();
539
  }
540
+
541
  $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
542
  $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
543
 
544
  if ($storeCode != null)
545
  return Mage::getModel('core/store')->load( $storeCode, 'code');
546
+
547
  if ($mageRunType == 'store') {
548
  if (!empty($mageRunCode))
549
  {
551
  }
552
  }
553
  else {
554
+ if ($mageRunType == 'website')
555
  $websiteCode = empty($mageRunCode) ? '' : $mageRunCode;
556
  else
557
  $websiteCode = empty($mageRunType) ? '' : $mageRunType;
558
+
559
  if (!empty($websiteCode))
560
  {
561
  $currentWebSite = Mage::getModel('core/website')->load( $websiteCode, 'code');
564
  return $defaultStore;
565
  }
566
  }
567
+
568
+
569
  return Mage::app()->getWebsite(true)->getDefaultStore();//Mage::app()->getStore();
570
  }
571
+
572
  private function _getWebsiteId($store=null)
573
  {
574
  return array($this->_getStore($store)->getWebsiteId());
575
  }
576
+
577
  private function _productAttributeInfo($attribute_id, $attributeAPI)
578
  {
579
  $model = Mage::getResourceModel('catalog/eav_attribute')
624
 
625
  return $result;
626
  }
627
+
628
  //Fix for buggy associativeArray implementation
629
  private function _fixAttributes($productData)
630
  {
631
  $_newAttributeOptions = $this->_newOptions($productData);
632
+ $_availableOptions = array();
633
  if (count($_newAttributeOptions) > 0)
634
  {
635
  $_availableOptions = $this->_createOptions($_newAttributeOptions);
636
  }
637
+
638
  if (property_exists($productData, 'additional_attributes')) {
639
  $tmpAttr = $productData->additional_attributes;
640
  if (count($tmpAttr) == 0)
642
  unset($productData->additional_attributes);
643
  return $productData;
644
  }
645
+
646
  $i=0;
647
  if (is_array($tmpAttr))
648
  {
652
  {
653
  $productData->$code = array();
654
  }
655
+ if (isset($_availableOptions[$option->attribute_id][strtolower($option->label)]))
656
  {
657
  if ($option->type == 'multiselect')
658
  {
680
  else
681
  {
682
  $code = $tmpAttr->code;
683
+ if (isset($_availableOptions[$tmpAttr->attribute_id][strtolower($tmpAttr->label)]))
684
  $productData->$code = $_availableOptions[$tmpAttr->attribute_id][strtolower($tmpAttr->label)];
685
  else
686
+ $productData->$code = $tmpAttr->value;
687
+ }
688
  }
689
 
690
  unset($productData->additional_attributes);
691
+
692
  return $productData;
693
  }
694
+
695
+
696
+
697
  /*
698
  *
699
  * Public functions(API)
703
  {
704
  if (!$set || !$sku) {
705
  throw new Mage_Api_Exception('data_invalid');
706
+ }
707
+
708
  $this->_prepareConfigurableData($store, $productData, $assignedProductsArray,
709
  $attributesSetArray, $productsSet, $attributesSet);
710
+
711
  $DefaultStore = $this->_getStore();
712
+
713
  if (property_exists($productData, 'websites') === false && isset($DefaultStore) ) {
714
  $productData->websites = array($DefaultStore->getWebsiteId());
715
  }
716
+
717
+ if (property_exists($productData, 'category_ids') && !is_array($productData->category_ids))
718
  {
719
  if (is_string($productData->category_ids)) {
720
  $productData->category_ids = array($productData->category_ids);
724
  {
725
  $productData->category_ids = array();
726
  }
727
+
728
  $productData->categories = $productData->category_ids;
729
 
730
+ $productAPI = new Mage_Catalog_Model_Product_Api_V2();
731
  $productId = $productAPI->create('configurable', $set, $sku, $productData, $store);
732
+
733
  $this->_updateConfigurable($store, $productId, $productData, $assignedProductsArray, $attributesSetArray, 'id', false, $reindex);
734
+
735
+ return $productId;
736
  }
737
 
738
  public function updateConfigurableProduct($productId, $reindex, $productData, $productsSet, $attributesSet, $store=null, $identifierType='id')
739
+ {
740
  if ($identifierType == 'id')
741
  {
742
  $productId = intval($productId);
743
+
744
  if ($productId < 1) {
745
  throw new Mage_Api_Exception('product_not_exists', null);
746
  }
747
  }
748
+
749
  $this->_prepareConfigurableData($store, $productData, $assignedProductsArray,
750
  $attributesSetArray, $productsSet, $attributesSet);
751
+
752
  try {
753
  $storeId = Mage::app()->getStore($store)->getId();
754
  } catch (Mage_Core_Model_Store_Exception $e) {
755
  throw new Mage_Api_Exception('store_not_exists', null);
756
  }
757
+
758
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($productId, $storeId, $identifierType);
759
+
760
  $_categoryIds = $_loadedProduct->getCategoryIds();
761
+ if (property_exists($productData, 'category_ids'))
762
  {
763
+
764
  if (!is_array($productData->category_ids))
765
  {
766
  $productData->category_ids = array($productData->category_ids);
769
  $productData->category_ids = array_merge($_categoryIds, $productData->category_ids);
770
 
771
  }
772
+ else
773
  {
774
  $productData->category_ids = $_categoryIds;
775
  }
776
+
777
  $productData->category_ids = array_unique($productData->category_ids);
778
+
779
+ if ( (property_exists($productData, 'removed_categories') === true)
780
  && (is_array($productData->removed_categories) === true)
781
  && (count($productData->removed_categories) > 0) )
782
  {
783
  $tmpCats = array();
784
+
785
  $productData->category_ids = array_diff($productData->category_ids, $productData->removed_categories);
786
  }
787
+
788
  $productData->categories = $productData->category_ids;
789
+
790
  if (property_exists($productData, 'add_to_websites') && $productData->add_to_websites === true)
791
  {
792
  $currentWebsites = $_loadedProduct->getWebsiteIds();
793
  $websiteId = $this->_getWebsiteId();
794
  $websiteId = $websiteId[0];
795
+
796
  if (in_array($websiteId, $currentWebsites) === false)
797
  {
798
  $currentWebsites[] = $websiteId;
799
  $productData->websites = $currentWebsites;
800
+ }
801
  }
802
+
803
+ $productAPI = new Mage_Catalog_Model_Product_Api_V2();
804
+
805
  $productAPI->update($productId, $productData, $store, $identifierType);
806
+
807
  return $this->_updateConfigurable($store, $productId, $productData, $assignedProductsArray, $attributesSetArray, $identifierType, true, $reindex);
808
  }
809
 
811
  * Checks if this Magento server has valid Extension installed
812
  */
813
  public function storesList()
814
+ {
815
  return ($this->_getCurrentVersion() >= 160);
816
  }
817
+
818
  public function getStoreCode($store=null)
819
+ {
820
  return $this->_currentStoreCode($store);
821
  }
822
+
823
  public function deleteAssigned($productId, $store=null, $identifierType='id')
824
  {
825
  if ($identifierType == 'id')
826
  {
827
  $productId = intval($productId);
828
+
829
  if ($productId < 1) {
830
  throw new Mage_Api_Exception('product_not_exists', null);
831
  }
832
  }
833
+
834
  $store = $this->_currentStoreCode($store);
835
+
836
  try {
837
  $storeId = Mage::app()->getStore($store)->getId();
838
  } catch (Mage_Core_Model_Store_Exception $e) {
839
  throw new Mage_Api_Exception('store_not_exists', null);
840
  }
841
+
842
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($productId, $storeId, $identifierType);
843
  $currentWebsites = $_loadedProduct->getWebsiteIds();
844
  $websiteId = $this->_getWebsiteId($store);
845
  $websiteId = $websiteId[0];
846
+
847
  $newWebsiteIds = array();
848
+
849
  if (in_array($websiteId, $currentWebsites) === true)
850
  {
851
+ for($i = 0; $i < count($currentWebsites); $i++)
852
  {
853
  if ($currentWebsites[$i] != $websiteId)
854
  {
855
  $newWebsiteIds[] = $currentWebsites[$i];
856
  }
857
  }
858
+
859
  $_loadedProduct->setWebsiteIds($newWebsiteIds);
860
+
861
  $_loadedProduct->save();
862
+ }
863
+
864
  return true;
865
  }
866
+
867
+
868
  public function assignImages($productImages)
869
  {
870
  $store = $this->_currentStoreCode(null);
871
+
872
  foreach($productImages as $imageData)
873
  {
874
  $productId = intval($imageData->product_id);
875
  if ($productId < 1) {
876
  throw new Mage_Api_Exception('product_not_exists', null);
877
  }
878
+
879
  $product = Mage::helper('catalog/product')->getProduct($productId, $store, 'id');
880
+
881
  $images = $imageData->images;
882
+
883
  $baseImageExist = false;
884
  foreach($images as $image)
885
  {
900
  {
901
  $catalogProductDir = Mage::getBaseDir('media') . DS . 'catalog/product';
902
  $filePath = $catalogProductDir.$image->image_name;
903
+
904
  if (is_array($image->types) && count($image->types) > 0)
905
  {
906
  $imageTypes = $image->types;
909
  {
910
  $imageTypes = "";
911
  }
912
+
913
+ try
914
  {
915
  $product->addImageToMediaGallery($filePath, $imageTypes, false, false);
916
+ }
917
  catch (Exception $e) { }
918
+
919
  }
920
 
921
  $product->save();
922
  }
923
+
924
  return true;
925
  }
926
+
927
  /*
928
+ * Implementation of catalogProductList because of bug in associativeArray.
929
  * Extended to filter by category id too.
930
  *
931
  * Use 'entity_id' for product_id,
932
+ * 'type_id' instead of product type.
933
  */
934
  public function productList($page, $perPage, $filters = null, $store = null)
935
  {
937
  'nin',
938
  'in',
939
  );
940
+
941
  $store = $this->_currentStoreCode($store);
942
+
943
  try {
944
  $storeId = Mage::app()->getStore($store)->getId();
945
  } catch (Mage_Core_Model_Store_Exception $e) {
955
  if (isset($filters->complex_filter)) {
956
  foreach ($filters->complex_filter as $_key => $_filter) {
957
  $_op = $_filter->key;
958
+ $_filterVal = $_filter->value->value;
959
+ $_filterKey = $_filter->value->key;
960
 
961
  if (in_array($_op, $arrayParams)) {
962
+ $values = explode(',', $_filterVal);
963
  }
964
  else {
965
  $values = $_filterVal;
966
  }
967
+
968
+ $preparedFilters[$_op] = array(
969
+ $_filterKey => $values
970
+ );
971
  }
972
  }
973
 
974
+ if (isset($preparedFilters['category']) &&
975
+ is_string($preparedFilters['category']))
976
  {
977
  $_categoryId = intval($preparedFilters['category']);
978
  unset($preparedFilters['category']);
982
  }
983
 
984
  if (!empty($preparedFilters)) {
985
+ if ($_categoryId > 0)
986
  {
987
  $_category = Mage::getModel('catalog/category')->load($_categoryId);
988
  $collection = Mage::getModel('catalog/product')->getCollection()
1014
  ->setCurPage($page);
1015
  $count = 0;
1016
  }
1017
+
1018
  $result = array();
1019
  $result['count'] = $count;
1020
  $result['products'] = array();
1026
  foreach ($collection as $_product) {
1027
  if ($i >= ($perPage * $page)) break;
1028
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($_product->getId(), $storeId, 'id');
1029
+
1030
  $_allAttributes = $_loadedProduct->getData();
1031
+
1032
+
1033
  $_description = isset($_allAttributes['description']) ? $_allAttributes['description'] : '';
1034
+
1035
  $_productImages = $this->_productImages($_allAttributes);
1036
  $_productAttributes = $this->_removeIgnoredAttributes($_allAttributes);
1037
+
1038
  $_fetchedIds[] = $_loadedProduct->getId();
1039
+
1040
  $result['products'][$i] = array(
1041
  'product_id' => $_loadedProduct->getId(),
1042
  'sku' => $_loadedProduct->getSku(),
1067
  'price_diff' => $price['pricing_value'],
1068
  'label' => $price['label'],
1069
  );
1070
+
1071
  }
1072
+
1073
  $result['products'][$i]['conf_attrib_ids'][] = array(
1074
  'code' => $attribute->getProductAttribute()->getAttributeCode(),
1075
  'prices' => $_prices
1076
+ );
1077
  }
1078
  $_assignedIds = array_merge($_assignedIds, $result['products'][$i]['assigned_ids']);
1079
  }
1080
+
1081
  $i++;
1082
  }
1083
 
1084
  $_absentIds = array_diff($_assignedIds, $_fetchedIds);
1085
+
1086
  if (count($_absentIds) > 0)
1087
  {
1088
  $collection = Mage::getModel('catalog/product')->getCollection()->addIdFilter($_absentIds);
1089
+
1090
  foreach ($collection as $_product) {
1091
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($_product->getId(), $storeId, 'id');
1092
+
1093
  $_allAttributes = $_product->getData();
1094
+
1095
  $_description = isset($_allAttributes['description']) ? $_allAttributes['description'] : '';
1096
+
1097
  $_productImages = $this->_productImages($_allAttributes);
1098
  $_productAttributes = $this->_removeIgnoredAttributes($_allAttributes);
1099
+
1100
  $result['products'][] = array(
1101
  'product_id' => $_loadedProduct->getId(),
1102
  'sku' => $_loadedProduct->getSku(),
1122
  public function productAttributeOptions($setId)
1123
  {
1124
  $result = array();
1125
+
1126
  $setId = intval($setId);
1127
  if ($setId <= 0) return $result;
1128
+
1129
  $attributeAPI = Mage::getModel('catalog/product_attribute_api');
1130
+
1131
  $items = $attributeAPI->items($setId);
1132
+
1133
  $attributes = Mage::getModel('catalog/product')->getResource()
1134
  ->loadAllAttributes();
1135
+
1136
+ $i=0;
1137
  foreach ($items as $item) {
1138
  if (!isset($item['attribute_id']) || empty($item['attribute_id'])) continue;
1139
  $attributeId = intval($item['attribute_id']);
1140
  if ($attributeId <= 0) continue;
1141
+
1142
  $additionInfo = $this->_productAttributeInfo($attributeId, $attributeAPI);
1143
 
1144
  if (in_array($additionInfo['frontend_input'], $this->_permittedAttributes) &&
1152
  'scope' => $additionInfo['scope'],
1153
  'can_config' => 0
1154
  );
1155
+
1156
  if ( ($additionInfo['frontend_input'] == 'select') || ($additionInfo['frontend_input'] == 'multiselect') ) {
1157
+ if (($additionInfo['scope'] == 'global') &&
1158
  ($additionInfo['is_configurable']))
1159
  {
1160
  foreach ($additionInfo['apply_to'] as $applyTo)
1164
  $result[$i]['can_config'] = 1;
1165
  break;
1166
  }
1167
+ }
1168
+
1169
  }
1170
  if (isset($additionInfo['options']))
1171
  $result[$i]['attribute_options'] = $additionInfo['options'];
1172
+ }
1173
  $i++;
1174
  }
1175
  }
1176
+
1177
  return $result;
1178
  }
1179
 
1182
  if ($identifierType == 'id')
1183
  {
1184
  $productId = intval($productId);
1185
+
1186
  if ($productId < 1) {
1187
  throw new Mage_Api_Exception('product_not_exists', null);
1188
  }
1189
  }
1190
+
1191
  $store = $this->_currentStoreCode($store);
1192
  try {
1193
  $storeId = Mage::app()->getStore($store)->getId();
1194
  } catch (Mage_Core_Model_Store_Exception $e) {
1195
  throw new Mage_Api_Exception('store_not_exists', null);
1196
  }
1197
+
1198
  $_loadedProduct = Mage::helper('catalog/product')->getProduct($productId, $storeId, $identifierType);
1199
+
1200
  $_categoryIds = $_loadedProduct->getCategoryIds();
1201
  if (property_exists($productData, 'category_ids'))
1202
  {
1204
  {
1205
  $productData->category_ids = array($productData->category_ids);
1206
  }
1207
+
1208
  $productData->category_ids = array_merge($_categoryIds, $productData->category_ids);
1209
  }
1210
+ else
1211
  {
1212
  $productData->category_ids = $_categoryIds;
1213
  }
1214
+
1215
  $productData->category_ids = array_unique($productData->category_ids);
1216
+
1217
+ if ( (property_exists($productData, 'removed_categories') === true)
1218
  && (is_array($productData->removed_categories) === true)
1219
  && (count($productData->removed_categories) > 0) )
1220
  {
1221
  $tmpCats = array();
1222
+
1223
  $productData->category_ids = array_diff($productData->category_ids, $productData->removed_categories);
1224
  }
1225
+
1226
  $productData->categories = $productData->category_ids;
1227
+
1228
  if (property_exists($productData, 'add_to_websites') && $productData->add_to_websites === true)
1229
+ {
1230
  $currentWebsites = $_loadedProduct->getWebsiteIds();
1231
  $websiteId = $this->_getWebsiteId();
1232
  $websiteId = $websiteId[0];
1233
+
1234
  if (in_array($websiteId, $currentWebsites) === false)
1235
  {
1236
  $currentWebsites[] = $websiteId;
1237
  $productData->websites = $currentWebsites;
1238
  }
1239
  }
1240
+
1241
  $this->_updateQuantity($productData);
1242
 
1243
  $productData = $this->_fixAttributes($productData);
1244
 
1245
  $productAPI = new Mage_Catalog_Model_Product_Api_V2();
1246
+
1247
  $result = $productAPI->update($productId, $productData, $store, $identifierType);
1248
 
1249
  return $result;
1252
  public function create($type, $set, $sku, $productData, $store = null)
1253
  {
1254
  $store = $this->_currentStoreCode($store);
1255
+
1256
  $DefaultStore = $this->_getStore();
1257
+
1258
+ if (property_exists($productData, 'websites') === false && isset($DefaultStore)) {
1259
  $productData->websites = array($DefaultStore->getWebsiteId());
1260
  }
1261
+
1262
  if (property_exists($productData, 'category_ids') && !is_array($productData->category_ids)) {
1263
  if (is_string($productData->category_ids))
1264
  $productData->category_ids = array($productData->category_ids);
1267
  {
1268
  $productData->category_ids = array();
1269
  }
1270
+
1271
+ $productData->categories = $productData->category_ids;
1272
+
1273
  $this->_updateQuantity($productData);
1274
+
1275
  $productData = $this->_fixAttributes($productData);
1276
+
1277
  $productAPI = new Mage_Catalog_Model_Product_Api_V2();
1278
+
1279
  return $productAPI->create($type, $set, $sku, $productData, $store);
1280
  }
1281
 
1282
  public function debugInfo()
1283
  {
1284
  $verInfo = Mage::getVersionInfo();
1285
+
1286
  $result = array(
1287
  'llc_ver' => Settings::$VERSION,
1288
  'magento_ver' => $verInfo
1289
  );
1290
+
1291
  return $result;
1292
+ }
1293
  }
1294
 
1295
  class LinnLiveEnterprise extends LinnLiveMain{
1296
+
1297
  public function productAttributeOptions($setId)
1298
  {
1299
  $result = array();
1300
+
1301
  $setId = intval($setId);
1302
  if ($setId <= 0) return $result;
1303
+
1304
  $attributeAPI = Mage::getModel('catalog/product_attribute_api');
1305
+
1306
  $attributes = Mage::getModel('catalog/product')->getResource()
1307
  ->loadAllAttributes()
1308
  ->getSortedAttributes($setId);
1309
+
1310
  $i=0;
1311
+
1312
  foreach ($attributes as $attribute) {
1313
+
1314
  if ((!$attribute->getId() || $attribute->isInSet($setId))
1315
  && !in_array($attribute->getAttributeCode(), $this->_ignoredAttributes)
1316
  && in_array($attribute->getFrontendInput(), $this->_permittedAttributes)) {
1331
  'scope' => $scope,
1332
  'can_config' => 0
1333
  );
1334
+
1335
  if ( ($attribute->getFrontendInput() == 'select') || ($attribute->getFrontendInput() == 'multiselect') ) {
1336
+ if (($scope == 'global') &&
1337
  $attribute->getIsConfigurable())
1338
  {
1339
  if (strpos($attribute->getApplyTo(), 'simple') !== false)
1340
  $result[$i]['can_config'] = 1;
1341
  }
1342
+
1343
  $options = $attributeAPI->options($attribute->getId());
1344
+
1345
  // remove empty first element
1346
  if ($attribute->getFrontendInput() != 'boolean') {
1347
  array_shift($options);
1348
  }
1349
+
1350
  if (count($options) > 0) {
1351
  $result[$i]['attribute_options'] = $options;
1352
  }
1353
+ }
1354
  $i++;
1355
  }
1356
  }
1362
  private function _fixAttributes($productData)
1363
  {
1364
  $_newAttributeOptions = $this->_newOptions($productData);
1365
+ $_availableOptions = array();
1366
  if (count($_newAttributeOptions) > 0)
1367
  {
1368
  $_availableOptions = $this->_createOptions($_newAttributeOptions);
1369
  }
1370
+
1371
  if (property_exists($productData, 'additional_attributes')) {
1372
  $tmpAttr = $productData->additional_attributes;
1373
  if (count($tmpAttr) == 0)
1383
  foreach ($tmpAttr as $option) {
1384
  $productData->additional_attributes->single_data[$i] = new stdClass();
1385
  $productData->additional_attributes->single_data[$i]->key = $option->code;
1386
+
1387
  if ( ($option->type == 'multiselect') && (is_array($productData->additional_attributes->single_data[$i]->value) == false) )
1388
  {
1389
  $productData->additional_attributes->single_data[$i]->value = array();
1390
  }
1391
+
1392
+ if (isset($_availableOptions[$option->attribute_id][strtolower($option->label)]))
1393
  {
1394
  if ($option->type == 'multiselect')
1395
  {
1418
  {
1419
  $productData->additional_attributes->single_data[0] = new stdClass();
1420
  $productData->additional_attributes->single_data[0]->key = $tmpAttr->code;
1421
+ if (isset($_availableOptions[$tmpAttr->attribute_id][strtolower($tmpAttr->label)]))
1422
  $productData->additional_attributes->single_data[0]->value = $_availableOptions[$tmpAttr->attribute_id][strtolower($tmpAttr->label)];
1423
  else
1424
  $productData->additional_attributes->single_data[0]->value = $tmpAttr->value;
1425
+ }
1426
  }
1427
+
1428
  return $productData;
1429
  }
1430
  }
1431
 
1432
  class LinnLiveCommunity extends LinnLiveMain{
1433
+
1434
  }
1435
  ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>LinnLiveConnect</name>
4
- <version>1.1.37</version>
5
  <stability>stable</stability>
6
  <license>GPL v2</license>
7
  <channel>community</channel>
@@ -10,12 +10,12 @@
10
  <description>Extended SOAP WS-I compliant API to support integration with LinnLive2 (http://www.linnlive.com).&#xD;
11
  Contains some workarounds to avoid bugs in original Magento modules and additional functionality to operate Magento store remotely.</description>
12
  <notes>Bug fixes:&#xD;
13
- * Version fix.&#xD;
14
  </notes>
15
  <authors><author><name>Albert Andrejev</name><user>albert_andrejev</user><email>albert@linnsystems.com</email></author><author><name>Pavel Nikolajev</name><user>Pavel_LL2</user><email>pavel.nokolajev@linnsystems.com</email></author></authors>
16
  <date>2014-03-17</date>
17
- <time>08:38:36</time>
18
- <contents><target name="magelocal"><dir name="LinnSystems"><dir name="LinnLiveConnect"><dir name="Helper"><file name="Data.php" hash="5fe5216de67d4e69a0f418b0cd7780ee"/></dir><dir name="Model"><dir name="Api"><file name="V2.php" hash="e428df7fd289d247d239a8ce0360c8c2"/></dir></dir><dir name="etc"><file name="api.xml" hash="2d53cb9b318de468f6d2e3d388bb8732"/><file name="config.xml" hash="2d1d6338d93e36b730efde622893b4e6"/><file name="wsdl.xml" hash="fc21f2963c1253f5f40e5e8414312174"/><file name="wsi.xml" hash="ef000d5115f5988664f58df8b9139e5e"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="LinnSystems_LinnLiveConnect.xml" hash="19c48712cd0516815d6784592ada0881"/></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>LinnLiveConnect</name>
4
+ <version>1.1.38</version>
5
  <stability>stable</stability>
6
  <license>GPL v2</license>
7
  <channel>community</channel>
10
  <description>Extended SOAP WS-I compliant API to support integration with LinnLive2 (http://www.linnlive.com).&#xD;
11
  Contains some workarounds to avoid bugs in original Magento modules and additional functionality to operate Magento store remotely.</description>
12
  <notes>Bug fixes:&#xD;
13
+ * Mapping wrong attribute code fix.&#xD;
14
  </notes>
15
  <authors><author><name>Albert Andrejev</name><user>albert_andrejev</user><email>albert@linnsystems.com</email></author><author><name>Pavel Nikolajev</name><user>Pavel_LL2</user><email>pavel.nokolajev@linnsystems.com</email></author></authors>
16
  <date>2014-03-17</date>
17
+ <time>11:59:03</time>
18
+ <contents><target name="magelocal"><dir name="LinnSystems"><dir name="LinnLiveConnect"><dir name="Helper"><file name="Data.php" hash="5fe5216de67d4e69a0f418b0cd7780ee"/></dir><dir name="Model"><dir name="Api"><file name="V2.php" hash="488b6fe5c1eb60f1d812387cf570a046"/></dir></dir><dir name="etc"><file name="api.xml" hash="2d53cb9b318de468f6d2e3d388bb8732"/><file name="config.xml" hash="2d1d6338d93e36b730efde622893b4e6"/><file name="wsdl.xml" hash="fc21f2963c1253f5f40e5e8414312174"/><file name="wsi.xml" hash="ef000d5115f5988664f58df8b9139e5e"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="LinnSystems_LinnLiveConnect.xml" hash="19c48712cd0516815d6784592ada0881"/></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
21
  </package>