Yireo_Vm2Mage - Version 0.10.21

Version Notes

No notes

Download this release

Release Info

Developer Yireo
Extension Yireo_Vm2Mage
Version 0.10.21
Comparing to
See all releases


Code changes from version 0.10.9 to 0.10.21

app/code/community/Yireo/Vm2Mage/Block/Check.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/Helper/Attribute.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/Helper/Category.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
@@ -25,7 +25,11 @@ class Yireo_Vm2Mage_Helper_Category extends Yireo_Vm2Mage_Helper_Data
25
  {
26
  $db = Mage::getSingleton('core/resource')->getConnection('core_read');
27
  $table = Mage::getSingleton('core/resource')->getTableName('vm2mage_categories');
28
- $mage_id = $db->fetchOne( "SELECT `mage_id` FROM `$table` WHERE `vm_id` = '$vm_id' AND `migration_code` = '$migration_code'" );
 
 
 
 
29
  return $mage_id;
30
  }
31
 
@@ -53,5 +57,21 @@ class Yireo_Vm2Mage_Helper_Category extends Yireo_Vm2Mage_Helper_Data
53
  $db->query($query);
54
  return true;
55
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
57
 
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
25
  {
26
  $db = Mage::getSingleton('core/resource')->getConnection('core_read');
27
  $table = Mage::getSingleton('core/resource')->getTableName('vm2mage_categories');
28
+ if(!empty($migration_code)) {
29
+ $mage_id = $db->fetchOne( "SELECT `mage_id` FROM `$table` WHERE `vm_id` = '$vm_id' AND `migration_code` = '$migration_code'" );
30
+ } else {
31
+ $mage_id = $db->fetchOne( "SELECT `mage_id` FROM `$table` WHERE `vm_id` = '$vm_id'");
32
+ }
33
  return $mage_id;
34
  }
35
 
57
  $db->query($query);
58
  return true;
59
  }
60
+
61
+ /*
62
+ * Method to remove the relation between a Magento ID and a VirtueMart ID
63
+ *
64
+ * @param int $vm_id
65
+ * @param string $migration_code
66
+ * @return bool
67
+ */
68
+ public function removeRelation($vm_id = 0, $migration_code = null)
69
+ {
70
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
71
+ $table = Mage::getSingleton('core/resource')->getTableName('vm2mage_categories');
72
+ $query = "DELETE FROM `$table` WHERE `vm_id` = '$vm_id' AND `migration_code` = '$migration_code'";
73
+ $db->query($query);
74
+ return true;
75
+ }
76
  }
77
 
app/code/community/Yireo/Vm2Mage/Helper/Data.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
@@ -108,6 +108,7 @@ class Yireo_Vm2Mage_Helper_Data extends Mage_Core_Helper_Abstract
108
  } elseif(!empty($value)) {
109
  $value = base64_encode($value);
110
  }
 
111
  $array[$name] = $value;
112
  }
113
  return $array;
@@ -122,14 +123,27 @@ class Yireo_Vm2Mage_Helper_Data extends Mage_Core_Helper_Abstract
122
  if(is_array($value)) {
123
  $value = Mage::helper('vm2mage')->decode($value);
124
  } elseif(!empty($value) && preg_match('/^V2M___/', $value)) {
125
- $value = preg_replace('/^V2M___/', '', $value);
126
- $value = base64_decode($value);
127
  }
128
 
 
129
  if(!empty($value)) {
130
  $array[$name] = $value;
131
  }
132
  }
133
  return $array;
134
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  }
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
108
  } elseif(!empty($value)) {
109
  $value = base64_encode($value);
110
  }
111
+
112
  $array[$name] = $value;
113
  }
114
  return $array;
123
  if(is_array($value)) {
124
  $value = Mage::helper('vm2mage')->decode($value);
125
  } elseif(!empty($value) && preg_match('/^V2M___/', $value)) {
126
+ $value = Mage::helper('vm2mage')->decodeString($value);
 
127
  }
128
 
129
+ $name = Mage::helper('vm2mage')->decodeString($name);
130
  if(!empty($value)) {
131
  $array[$name] = $value;
132
  }
133
  }
134
  return $array;
135
  }
136
+
137
+ /*
138
+ * Recursive function to decode a value
139
+ */
140
+ public function decodeString($string = null)
141
+ {
142
+ if(!empty($string) && preg_match('/^V2M___/', $string)) {
143
+ $string = preg_replace('/^V2M___/', '', $string);
144
+ $string = base64_decode($string);
145
+ }
146
+
147
+ return $string;
148
+ }
149
  }
app/code/community/Yireo/Vm2Mage/Helper/Image.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
@@ -71,44 +71,74 @@ class Yireo_Vm2Mage_Helper_Image extends Yireo_Vm2Mage_Helper_Data
71
  }
72
  $product->save();
73
  }
 
74
 
75
- // Loop through the images and create them
76
- $migratedFiles = array();
77
- if(is_array($images) && !empty($images)) {
78
- foreach($images as $image) {
79
-
80
- if(in_array($image['md5sum'], $migratedFiles)) continue;
81
- if(empty($image['label'])) $image['label'] = $product->getName();
82
- if(empty($image['file'])) $image['file'] = null;
83
- if(empty($image['md5sum'])) $image['md5sum'] = null;
84
-
85
- $imageTypes = array();
86
- if($image['type'] == 'full_image') {
87
- $imageTypes[] = 'image';
88
- $imageTypes[] = 'small_image';
89
- if(count($images) == 1) $imageTypes[] = 'thumbnail';
90
- } elseif($image['type'] == 'thumb_image') {
91
- $imageTypes[] = 'thumbnail';
92
- }
 
 
 
93
 
94
- $result = self::addLocalImage($product, $image['file'], $image['label'], $imageTypes);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  if($result != false) {
96
  $product = $result;
97
  $migratedFiles[] = $image['md5sum'];
98
- } else {
99
- $result = self::addRemoteImage($product, $image['url'], $image['md5sum'], $image['type'], $image['label'], $imageTypes);
100
- if($result != false) {
101
- $product = $result;
102
- $migratedFiles[] = $image['md5sum'];
103
- }
104
  }
105
  }
106
  }
107
-
108
- // Save the product
109
- $product->save();
110
  }
111
 
 
 
 
112
  return $product;
113
  }
114
 
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
71
  }
72
  $product->save();
73
  }
74
+ }
75
 
76
+ // Detect images first
77
+ $hasFullImage = false;
78
+ $hasThumbImage = false;
79
+ if(is_array($images) && !empty($images)) {
80
+ foreach($images as $image) {
81
+ if($image['type'] == 'full_image') $hasFullImage = true;
82
+ if($image['type'] == 'thumbnail') $hasThumbImage = true;
83
+ }
84
+ }
85
+
86
+ // Loop through the images and create them
87
+ $migratedFiles = array();
88
+ if(is_array($images) && !empty($images)) {
89
+ foreach($images as $image) {
90
+
91
+ if(empty($image['md5sum'])) $image['md5sum'] = null;
92
+ if(empty($image['label'])) $image['label'] = $product->getName();
93
+ if(empty($image['file'])) $image['file'] = null;
94
+ if(!empty($image['md5sum']) && in_array($image['md5sum'], $migratedFiles)) continue;
95
+
96
+ $imageTypes = array();
97
 
98
+ if(count($images) == 1) {
99
+ $imageTypes[] = 'thumbnail';
100
+ $imageTypes[] = 'image';
101
+ $imageTypes[] = 'small_image';
102
+
103
+ } elseif($image['type'] == 'full_image') {
104
+ $imageTypes[] = 'image';
105
+ $imageTypes[] = 'small_image';
106
+ if(count($images) == 1) $imageTypes[] = 'thumbnail';
107
+
108
+ } elseif($image['type'] == 'thumb_image') {
109
+ $imageTypes[] = 'thumbnail';
110
+ }
111
+
112
+ if($hasFullImage == false) {
113
+ $imageTypes[] = 'image';
114
+ $imageTypes[] = 'small_image';
115
+ $hasFullImage = true;
116
+ }
117
+
118
+ if($hasThumbImage == false) {
119
+ $imageTypes[] = 'thumbnail';
120
+ $hasThumbImage = true;
121
+ }
122
+
123
+ $imageTypes = array_unique($imageTypes);
124
+
125
+ $result = self::addLocalImage($product, $image['file'], $image['label'], $imageTypes);
126
+ if($result != false) {
127
+ $product = $result;
128
+ $migratedFiles[] = $image['md5sum'];
129
+ } elseif(!empty($image['url'])) {
130
+ $result = self::addRemoteImage($product, $image['url'], $image['md5sum'], $image['type'], $image['label'], $imageTypes);
131
  if($result != false) {
132
  $product = $result;
133
  $migratedFiles[] = $image['md5sum'];
 
 
 
 
 
 
134
  }
135
  }
136
  }
 
 
 
137
  }
138
 
139
+ // Save the product
140
+ $product->save();
141
+
142
  return $product;
143
  }
144
 
app/code/community/Yireo/Vm2Mage/Helper/Price.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/Helper/Product.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
@@ -27,15 +27,24 @@ class Yireo_Vm2Mage_Helper_Product extends Yireo_Vm2Mage_Helper_Data
27
  foreach($children as $child) {
28
  $childId = Mage::getModel('catalog/product')->getIdBySku($child['sku']);
29
 
30
- // @todo: Should we re-migrate the product or not?
31
- //if(empty($childId)) {
32
- if(empty($child['price']['product_price'])) $child['price']['product_price'] = $product->getPrice();
33
- Mage::getModel('vm2mage/product_api')->migrate($child);
34
- $childId = Mage::getModel('catalog/product')->getIdBySku($child['sku']);
35
- //}
 
36
  $childIds[] = $childId;
37
  }
38
 
 
 
 
 
 
 
 
 
39
  // Insert the Simple Products that belong in this Configurable Product
40
  $loader = Mage::getResourceModel('catalog/product_type_configurable')->load($product, null);
41
  $loader->saveProducts($product, $childIds);
@@ -165,13 +174,17 @@ class Yireo_Vm2Mage_Helper_Product extends Yireo_Vm2Mage_Helper_Data
165
  * @param array $values
166
  * @return $product
167
  */
168
- public function addCustomOptionsToProduct($product, $name, $values)
169
  {
 
 
 
 
170
  $option = array(
171
  'title' => $name,
172
  'type' => 'drop_down',
173
  'is_require' => 1,
174
- 'sort_order' => 0,
175
  'values' => array(),
176
  );
177
 
@@ -182,15 +195,10 @@ class Yireo_Vm2Mage_Helper_Product extends Yireo_Vm2Mage_Helper_Data
182
  'price' => $value['price'],
183
  'price_type' => 'fixed',
184
  'sku' => '',
185
- 'sort_order' => '1'
186
  );
187
  }
188
 
189
- if(!$product->getOptionsReadonly()) {
190
- $product->setProductOptions(array($option));
191
- $product->setCanSaveCustomOptions(true);
192
- }
193
-
194
- return $product;
195
  }
196
  }
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
27
  foreach($children as $child) {
28
  $childId = Mage::getModel('catalog/product')->getIdBySku($child['sku']);
29
 
30
+ if(empty($child['price']['product_price'])) {
31
+ $child['price']['product_price'] = $product->getPrice();
32
+ }
33
+
34
+ Mage::getModel('vm2mage/product_api')->migrate($child);
35
+ $childId = Mage::getModel('catalog/product')->getIdBySku($child['sku']);
36
+
37
  $childIds[] = $childId;
38
  }
39
 
40
+ // Clean up the Configurable Product data first
41
+ if ($product->getId() > 0) {
42
+ $resource = Mage::getSingleton('core/resource');
43
+ $write = $resource->getConnection('core_write');
44
+ $table = $resource->getTableName('catalog/product_super_attribute');
45
+ $write->delete($table, 'product_id = ' . $product->getId());
46
+ }
47
+
48
  // Insert the Simple Products that belong in this Configurable Product
49
  $loader = Mage::getResourceModel('catalog/product_type_configurable')->load($product, null);
50
  $loader->saveProducts($product, $childIds);
174
  * @param array $values
175
  * @return $product
176
  */
177
+ public function addCustomOptionToProduct($product, $custom_option)
178
  {
179
+ $name = $custom_option['name'];
180
+ $values = $custom_option['values'];
181
+ $ordering = $custom_option['ordering'];
182
+
183
  $option = array(
184
  'title' => $name,
185
  'type' => 'drop_down',
186
  'is_require' => 1,
187
+ 'sort_order' => $ordering,
188
  'values' => array(),
189
  );
190
 
195
  'price' => $value['price'],
196
  'price_type' => 'fixed',
197
  'sku' => '',
198
+ 'sort_order' => $value['ordering'],
199
  );
200
  }
201
 
202
+ return $option;
 
 
 
 
 
203
  }
204
  }
app/code/community/Yireo/Vm2Mage/Model/Attribute/Api.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/Model/Category/Api.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
@@ -43,10 +43,9 @@ class Yireo_Vm2Mage_Model_Category_Api extends Mage_Catalog_Model_Category_Api
43
  // Get the parent by taking it from VirtueMart
44
  if(isset($data['parent_id']) && $data['parent_id'] > 0) {
45
  $parentId = Mage::helper('vm2mage/category')->getMageId($data['parent_id'], $data['migration_code']);
46
-
47
- // Do not migrate this category (yet) if its parent does not exist yet
48
- if(!$parentId > 0) {
49
- return array(0, "Parent category ".$data['parent_id']." does not yet exist");
50
  }
51
  }
52
 
@@ -63,6 +62,10 @@ class Yireo_Vm2Mage_Model_Category_Api extends Mage_Catalog_Model_Category_Api
63
 
64
  // Load the parent category
65
  $parentCategory = Mage::getModel('catalog/category')->load($parentId);
 
 
 
 
66
 
67
  // Detect whether this is a new category or not
68
  if(!$category->getName()) {
@@ -79,6 +82,11 @@ class Yireo_Vm2Mage_Model_Category_Api extends Mage_Catalog_Model_Category_Api
79
 
80
  } else {
81
  $isNew = false;
 
 
 
 
 
82
  }
83
 
84
  $state = (isset($data['status'])) ? $data['status'] : $data['published'];
@@ -90,6 +98,19 @@ class Yireo_Vm2Mage_Model_Category_Api extends Mage_Catalog_Model_Category_Api
90
  ->setIsActive($state)
91
  ;
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  // @todo: Get the remote images
94
 
95
  // Try to safe this category to the database
@@ -99,7 +120,7 @@ class Yireo_Vm2Mage_Model_Category_Api extends Mage_Catalog_Model_Category_Api
99
  return array(0, $e->getMessage());
100
  }
101
 
102
- // Move this categort
103
  if(!in_array($parentId, array(0, $category->getParentId(), $category->getId()))) {
104
  try {
105
  $category->move($category->getId(), $parentId);
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
43
  // Get the parent by taking it from VirtueMart
44
  if(isset($data['parent_id']) && $data['parent_id'] > 0) {
45
  $parentId = Mage::helper('vm2mage/category')->getMageId($data['parent_id'], $data['migration_code']);
46
+ $parentCategory = Mage::getModel('catalog/category')->load($parentId);
47
+ if(!$parentCategory->getId() > 0) {
48
+ Mage::helper('vm2mage/category')->removeRelation($data['parent_id'], $data['migration_code']);
 
49
  }
50
  }
51
 
62
 
63
  // Load the parent category
64
  $parentCategory = Mage::getModel('catalog/category')->load($parentId);
65
+ if($parentCategory->getId() == 0) {
66
+ $parentId = Mage::app()->getAnyStoreView()->getRootCategoryId();
67
+ $parentCategory = Mage::getModel('catalog/category')->load($parentId);
68
+ }
69
 
70
  // Detect whether this is a new category or not
71
  if(!$category->getName()) {
82
 
83
  } else {
84
  $isNew = false;
85
+ $category->setData($category->getData())
86
+ ->setParentId($parentId)
87
+ ->setLevel($parentCategory->getLevel() + 1)
88
+ ->setPath($parentCategory->getPath().'/'.$category->getId())
89
+ ;
90
  }
91
 
92
  $state = (isset($data['status'])) ? $data['status'] : $data['published'];
98
  ->setIsActive($state)
99
  ;
100
 
101
+ // Assign all the products properly to this category
102
+ if(!empty($data['products'])) {
103
+ $positions = $category->getProductsPosition();
104
+ $product = Mage::getModel('catalog/product');
105
+ foreach($data['products'] as $productData) {
106
+ $productSku = $productData['sku'];
107
+ $productOrdering = $productData['ordering'];
108
+ $productId = (int)$product->getIdBySku($productSku);
109
+ if($productId > 0) $positions[$productId] = $productOrdering;
110
+ }
111
+ $category->setPostedProducts($positions);
112
+ }
113
+
114
  // @todo: Get the remote images
115
 
116
  // Try to safe this category to the database
120
  return array(0, $e->getMessage());
121
  }
122
 
123
+ // Move this category
124
  if(!in_array($parentId, array(0, $category->getParentId(), $category->getId()))) {
125
  try {
126
  $category->move($category->getId(), $parentId);
app/code/community/Yireo/Vm2Mage/Model/Observer.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/Model/Order/Api.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/Model/Product/Api.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
@@ -22,7 +22,7 @@ class Yireo_Vm2Mage_Model_Product_Api extends Mage_Catalog_Model_Product_Api
22
  // Check for empty data
23
  if(!is_array($data)) {
24
  //Mage::helper('vm2mage')->debug('VirtueMart product', $data);
25
- return array(0, "Data is not an array");
26
  }
27
 
28
  // Decode all values
@@ -38,6 +38,16 @@ class Yireo_Vm2Mage_Model_Product_Api extends Mage_Catalog_Model_Product_Api
38
  $typeId = Mage_Catalog_Model_Product_Type::TYPE_SIMPLE;
39
  }
40
 
 
 
 
 
 
 
 
 
 
 
41
  // Optionally lock the indexer
42
  Mage::getSingleton('index/indexer')->lockIndexer();
43
 
@@ -125,25 +135,7 @@ class Yireo_Vm2Mage_Model_Product_Api extends Mage_Catalog_Model_Product_Api
125
  $product->setMetaTitle($product->getTitle());
126
  }
127
 
128
- // Set the Custom Options
129
- if(isset($data['attribute'])) {
130
-
131
- // Remove all current options
132
- $options = $product->getOptions();
133
- if(!empty($options)) {
134
- foreach($options as $option) {
135
- $option->delete();
136
- }
137
- }
138
-
139
- // Add the custom options again
140
- foreach($data['attribute'] as $attribute) {
141
- $product = Mage::helper('vm2mage/product')->addCustomOptionsToProduct($product, $attribute['name'], $attribute['values']);
142
- }
143
- }
144
-
145
-
146
- // Set the custom attributes
147
  if(isset($data['attributes'])) {
148
  foreach($data['attributes'] as $name => $value) {
149
  //Mage::helper('vm2mage')->debug('Product attribute', $name);
@@ -163,12 +155,22 @@ class Yireo_Vm2Mage_Model_Product_Api extends Mage_Catalog_Model_Product_Api
163
 
164
  // Set the special price from-date
165
  if(isset($data['special_price']['start_date'])) {
166
- $product->setSpecialFromDate($data['special_price']['start_date']);
 
 
 
 
 
167
  }
168
 
169
  // Set the special price from-date
170
  if(isset($data['special_price']['end_date'])) {
171
- $product->setSpecialToDate($data['special_price']['end_date']);
 
 
 
 
 
172
  }
173
 
174
  // Set the tier pricing
@@ -249,11 +251,54 @@ class Yireo_Vm2Mage_Model_Product_Api extends Mage_Catalog_Model_Product_Api
249
  try {
250
  $request = Mage::app()->getFrontController()->getRequest();
251
  Mage::dispatchEvent('catalog_product_prepare_save', array('product' => $product, 'request' => $request));
252
- $product->save();
 
253
  } catch(Exception $e) {
254
  return array(0, '['.$sku.'] '.$e->getMessage());
255
  }
256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  // Configure this product as configurable product
258
  if($data['has_children'] > 0) {
259
  if($typeId == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
22
  // Check for empty data
23
  if(!is_array($data)) {
24
  //Mage::helper('vm2mage')->debug('VirtueMart product', $data);
25
+ return array(0, 'Data is not an array');
26
  }
27
 
28
  // Decode all values
38
  $typeId = Mage_Catalog_Model_Product_Type::TYPE_SIMPLE;
39
  }
40
 
41
+ // Determine the children of this product already exist
42
+ if($data['has_children'] > 0) {
43
+ foreach($data['children'] as $child) {
44
+ $childId = Mage::getModel('catalog/product')->getIdBySku($child['sku']);
45
+ if($childId > 0) {
46
+ return array(0, 'Child product has not been created yet. Skipping parent.');
47
+ }
48
+ }
49
+ }
50
+
51
  // Optionally lock the indexer
52
  Mage::getSingleton('index/indexer')->lockIndexer();
53
 
135
  $product->setMetaTitle($product->getTitle());
136
  }
137
 
138
+ // Set the attributes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  if(isset($data['attributes'])) {
140
  foreach($data['attributes'] as $name => $value) {
141
  //Mage::helper('vm2mage')->debug('Product attribute', $name);
155
 
156
  // Set the special price from-date
157
  if(isset($data['special_price']['start_date'])) {
158
+ $tmp_date = strtotime($data['special_price']['start_date']);
159
+ if($tmp_date > 0) {
160
+ $product->setSpecialFromDate($data['special_price']['start_date']);
161
+ }
162
+ } else {
163
+ $product->setSpecialFromDate(null);
164
  }
165
 
166
  // Set the special price from-date
167
  if(isset($data['special_price']['end_date'])) {
168
+ $tmp_date = strtotime($data['special_price']['end_date']);
169
+ if($tmp_date > 0) {
170
+ $product->setSpecialToDate($data['special_price']['end_date']);
171
+ }
172
+ } else {
173
+ $product->setSpecialToDate(null);
174
  }
175
 
176
  // Set the tier pricing
251
  try {
252
  $request = Mage::app()->getFrontController()->getRequest();
253
  Mage::dispatchEvent('catalog_product_prepare_save', array('product' => $product, 'request' => $request));
254
+ $product->getResource()->save($product);
255
+ $product = $product->load($product->getId());
256
  } catch(Exception $e) {
257
  return array(0, '['.$sku.'] '.$e->getMessage());
258
  }
259
 
260
+ // Set the Custom Options
261
+ if(isset($data['custom_options']) || isset($data['custom_option'])) {
262
+
263
+ // Merge all options
264
+ $custom_options = array();
265
+ if(isset($data['custom_option'])) $custom_options[] = $data['custom_option'];
266
+ if(!empty($data['custom_options'])) $custom_options = array_merge($custom_options, $data['custom_options']);
267
+
268
+ // Remove all current options
269
+ $options = $product->getOptions();
270
+ if(!empty($options)) {
271
+ foreach($options as $option) {
272
+ $option->delete();
273
+ }
274
+ }
275
+
276
+ // Add the custom options again
277
+ $new_options = array();
278
+ foreach($custom_options as $custom_option) {
279
+ $option = Mage::helper('vm2mage/product')->addCustomOptionToProduct($product, $custom_option);
280
+ //Mage::helper('vm2mage')->debug('Product Custom Option', $option);
281
+
282
+ $product->setHasOptions(1);
283
+ $productOption = Mage::getModel('catalog/product_option')
284
+ ->setProductId($product->getId())
285
+ ->setStoreId($product->getStoreId())
286
+ ->addData($option);
287
+ $productOption->save();
288
+ $product->addOption($productOption);
289
+ }
290
+
291
+ // Try to save this product to the database
292
+ try {
293
+ $request = Mage::app()->getFrontController()->getRequest();
294
+ Mage::dispatchEvent('catalog_product_prepare_save', array('product' => $product, 'request' => $request));
295
+ $product->getResource()->save($product);
296
+ $product = $product->load($product->getId());
297
+ } catch(Exception $e) {
298
+ return array(0, '['.$sku.'] '.$e->getMessage());
299
+ }
300
+ }
301
+
302
  // Configure this product as configurable product
303
  if($data['has_children'] > 0) {
304
  if($typeId == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
app/code/community/Yireo/Vm2Mage/Model/User/Api.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
@@ -29,7 +29,7 @@ class Yireo_Vm2Mage_Model_User_Api extends Mage_Customer_Model_Customer_Api
29
 
30
  // Decode all values
31
  $data = Mage::helper('vm2mage')->decode($data);
32
- #Mage::helper('vm2mage')->debug('VirtueMart user', $data);
33
 
34
  // Check for email
35
  if(empty($data['email'])) {
@@ -161,7 +161,8 @@ class Yireo_Vm2Mage_Model_User_Api extends Mage_Customer_Model_Customer_Api
161
  $address = $billingAddress;
162
  $is_billing = true;
163
  }
164
- #Mage::helper('vm2mage')->debug('Magento address', $address->debug());
 
165
 
166
  // Some extra overrides
167
  $is_shipping = (empty($shippingAddress)) ? true : false;
@@ -194,8 +195,6 @@ class Yireo_Vm2Mage_Model_User_Api extends Mage_Customer_Model_Customer_Api
194
  if(empty($data['state']) && !empty($customerData['state'])) $data['state'] = $customerData['state'];
195
  if(empty($data['state']) && !empty($customerData['region'])) $data['state'] = $customerData['region'];
196
  if(!empty($data['state'])) $region = Mage::getModel('directory/region')->loadByCode($data['state'], $country->getId());
197
- Mage::log('isse: '.$data['state'].' / '.$country->getId());
198
- Mage::log('sisse: '.$region->getId());
199
 
200
  // Set basic values
201
  $address
@@ -375,7 +374,7 @@ class Yireo_Vm2Mage_Model_User_Api extends Mage_Customer_Model_Customer_Api
375
  $model->setModifyDate($order['modify_date']);
376
  $model->setCustomerNote($order['customer_note']);
377
  $model->setPaymentMethod($order['payment_method']);
378
- $model->setShipMethodId($order['shipment_method']);
379
  $model->save(); // skipped: order_id, vendor_id, user_info_id, ip-address
380
 
381
  // Loop through the order-items and save them as well
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
29
 
30
  // Decode all values
31
  $data = Mage::helper('vm2mage')->decode($data);
32
+ //Mage::helper('vm2mage')->debug('VirtueMart user', $data);
33
 
34
  // Check for email
35
  if(empty($data['email'])) {
161
  $address = $billingAddress;
162
  $is_billing = true;
163
  }
164
+
165
+ Mage::helper('vm2mage')->debug('Magento address', $address->debug());
166
 
167
  // Some extra overrides
168
  $is_shipping = (empty($shippingAddress)) ? true : false;
195
  if(empty($data['state']) && !empty($customerData['state'])) $data['state'] = $customerData['state'];
196
  if(empty($data['state']) && !empty($customerData['region'])) $data['state'] = $customerData['region'];
197
  if(!empty($data['state'])) $region = Mage::getModel('directory/region')->loadByCode($data['state'], $country->getId());
 
 
198
 
199
  // Set basic values
200
  $address
374
  $model->setModifyDate($order['modify_date']);
375
  $model->setCustomerNote($order['customer_note']);
376
  $model->setPaymentMethod($order['payment_method']);
377
+ if(isset($order['shipment_method'])) $model->setShipMethodId($order['shipment_method']);
378
  $model->save(); // skipped: order_id, vendor_id, user_info_id, ip-address
379
 
380
  // Loop through the order-items and save them as well
app/code/community/Yireo/Vm2Mage/Model/Widget/Api.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/controllers/IndexController.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/etc/api.xml CHANGED
@@ -5,7 +5,7 @@
5
  *
6
  * @author Yireo
7
  * @package Vm2Mage
8
- * @copyright Copyright 2013
9
  * @license Open Source License
10
  * @link http://www.yireo.com
11
  */
5
  *
6
  * @author Yireo
7
  * @package Vm2Mage
8
+ * @copyright Copyright 2014
9
  * @license Open Source License
10
  * @link http://www.yireo.com
11
  */
app/code/community/Yireo/Vm2Mage/etc/config.xml CHANGED
@@ -5,7 +5,7 @@
5
  *
6
  * @author Yireo
7
  * @package Vm2Mage
8
- * @copyright Copyright 2013
9
  * @license Open Source License
10
  * @link http://www.yireo.com
11
  */
@@ -14,7 +14,7 @@
14
 
15
  <modules>
16
  <Yireo_Vm2Mage>
17
- <version>0.10.9</version>
18
  </Yireo_Vm2Mage>
19
  </modules>
20
 
5
  *
6
  * @author Yireo
7
  * @package Vm2Mage
8
+ * @copyright Copyright 2014
9
  * @license Open Source License
10
  * @link http://www.yireo.com
11
  */
14
 
15
  <modules>
16
  <Yireo_Vm2Mage>
17
+ <version>0.10.21</version>
18
  </Yireo_Vm2Mage>
19
  </modules>
20
 
app/code/community/Yireo/Vm2Mage/etc/system.xml CHANGED
@@ -5,7 +5,7 @@
5
  *
6
  * @author Yireo
7
  * @package Vm2Mage
8
- * @copyright Copyright 2013
9
  * @license Open Source License
10
  * @link http://www.yireo.com
11
  */
5
  *
6
  * @author Yireo
7
  * @package Vm2Mage
8
+ * @copyright Copyright 2014
9
  * @license Open Source License
10
  * @link http://www.yireo.com
11
  */
app/code/community/Yireo/Vm2Mage/sql/vm2mage_setup/mysql4-install-0.10.3.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/sql/vm2mage_setup/mysql4-install-0.5.4.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
app/code/community/Yireo/Vm2Mage/sql/vm2mage_setup/mysql4-upgrade-0.10.2-0.10.3.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
- * @copyright Copyright 2013
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
4
  *
5
  * @author Yireo
6
  * @package Vm2Mage
7
+ * @copyright Copyright 2014
8
  * @license Open Source License
9
  * @link http://www.yireo.com
10
  */
package.xml CHANGED
@@ -1,2 +1,2 @@
1
  <?xml version="1.0"?>
2
- <package><name>Yireo_Vm2Mage</name><version>0.10.9</version><stability>stable</stability><license>Open Source License</license><channel>community</channel><extends></extends><summary>No summary</summary><description>No description</description><notes>No notes</notes><authors><author><name>Yireo</name><user>yireo</user><email>info@yireo.com</email></author></authors><date>2013-12-27</date><time>1:32:50</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="skin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><dir name="vm2mage"><file name="check-error.png" hash="6a3c4bbf7dff2e4db08183b14329ef9c"/><file name="check-ok.png" hash="9fb629c79fc4a487088ac4aeeb23e40b"/><file name="check-warning.png" hash="39ccef05471d39a99a8fa2ddf4471d20"/></dir></dir></dir></dir></dir></dir><dir name="app"><dir name="etc"><dir name="modules"><file name="Yireo_Vm2Mage.xml" hash="bee76713ff8df9db330a8385b2465041"/></dir></dir><dir name="code"><dir name="community"><dir name="Yireo"><dir name="Vm2Mage"><dir name="controllers"><file name="IndexController.php" hash="323ec99b3f63cad12547d197cc31564d"/></dir><dir name="Block"><file name="Check.php" hash="24322e3ec477c16d99847e378e4f684d"/></dir><dir name="etc"><file name="api.xml" hash="c4bf74c7a340a02ff1f095b5371472f9"/><file name="config.xml" hash="dab54617a1f840f95f405434510edf1d"/><file name="system.xml" hash="093a9396a5915e29df53dcdfb596d7cd"/></dir><dir name="sql"><dir name="vm2mage_setup"><file name="mysql4-install-0.10.3.php" hash="c8468feeed506515b538ae9f7ed8c0da"/><file name="mysql4-install-0.5.4.php" hash="de6658876bc68103fa099a814ffb46e0"/><file name="mysql4-upgrade-0.10.2-0.10.3.php" hash="1b08a11ed06b626f9edc6b86dc0f8bb9"/></dir></dir><dir name="Helper"><file name="Attribute.php" hash="35e1c22da300cbe5f72e663c6e3b64a0"/><file name="Category.php" hash="a80a6e7b5fe9b48cc8d80ca5d5a588f8"/><file name="Data.php" hash="241cebe4a1b4dbc4dfd1bf94b633a45a"/><file name="Image.php" hash="01f753f938a2c3025e4286c1cb1a09af"/><file name="Price.php" hash="df91b573272cab2c1e6f86385a75bbae"/><file name="Product.php" hash="70b2a33d99fca8b3eacef7bd8419fb4e"/></dir><dir name="Model"><file name="Observer.php" hash="f0d803b0520bffdd7f14b56316efed0d"/><dir name="User"><file name="Api.php" hash="58413cb5f2d8002a4ff624927142b13b"/></dir><dir name="Rewrite"><dir name="Category"><dir name="Attribute"><dir name="Backend"><file name="Image.php" hash="9880fd05bb4bdbb8fc551ee7cace2e9d"/></dir></dir></dir></dir><dir name="Category"><file name="Api.php" hash="25b451dde1a7cb690553d2bd91614047"/></dir><dir name="Widget"><file name="Api.php" hash="2fbfde9bcb5528f2148c8e9133b7622d"/></dir><dir name="Product"><file name="Api.php" hash="511c4958ec2371481137085a795a0e3c"/></dir><dir name="Order"><file name="Api.php" hash="a66d742bc5011749a84da412b1b8ce32"/></dir><dir name="Attribute"><file name="Api.php" hash="4ed05d30baa43ed8a086066de22c8437"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="vm2mage"><file name="check.phtml" hash="953b257a96841c5efadac97f0cf6614e"/></dir></dir></dir></dir></dir></dir></dir></target></contents></package>
1
  <?xml version="1.0"?>
2
+ <package><name>Yireo_Vm2Mage</name><version>0.10.21</version><stability>stable</stability><license>Open Source License</license><channel>community</channel><extends></extends><summary>No summary</summary><description>No description</description><notes>No notes</notes><authors><author><name>Yireo</name><user>yireo</user><email>info@yireo.com</email></author></authors><date>2015-03-18</date><time>6:07:52</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="skin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><dir name="vm2mage"><file name="check-error.png" hash="6a3c4bbf7dff2e4db08183b14329ef9c"/><file name="check-ok.png" hash="9fb629c79fc4a487088ac4aeeb23e40b"/><file name="check-warning.png" hash="39ccef05471d39a99a8fa2ddf4471d20"/></dir></dir></dir></dir></dir></dir><dir name="app"><dir name="etc"><dir name="modules"><file name="Yireo_Vm2Mage.xml" hash="bee76713ff8df9db330a8385b2465041"/></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="vm2mage"><file name="check.phtml" hash="953b257a96841c5efadac97f0cf6614e"/></dir></dir></dir></dir></dir></dir><dir name="code"><dir name="community"><dir name="Yireo"><dir name="Vm2Mage"><dir name="sql"><dir name="vm2mage_setup"><file name="mysql4-install-0.10.3.php" hash="853a8f5781d1f91356aefbf7ae954d2b"/><file name="mysql4-install-0.5.4.php" hash="af2d480575e32b4f601c0f3d40e49f01"/><file name="mysql4-upgrade-0.10.2-0.10.3.php" hash="39759a5daed7e92bd3aa50c661c2e287"/></dir></dir><dir name="etc"><file name="api.xml" hash="044835e8aef903ec0eaad068d7b428ae"/><file name="config.xml" hash="a1062a3994b6a86347cbf9f3b5673e6d"/><file name="system.xml" hash="675f2984aa4df1298f753be702171a78"/></dir><dir name="controllers"><file name="IndexController.php" hash="beb4a2afae7c48ab6360ccb0759b96bc"/></dir><dir name="Model"><file name="Observer.php" hash="61fca0f64bc8c994a4cab745a77252e0"/><dir name="Widget"><file name="Api.php" hash="dd313f26b2d2f37ee17f632e9b24b182"/></dir><dir name="User"><file name="Api.php" hash="76057284ea5df759cb81f2b9bba271eb"/></dir><dir name="Rewrite"><dir name="Category"><dir name="Attribute"><dir name="Backend"><file name="Image.php" hash="9880fd05bb4bdbb8fc551ee7cace2e9d"/></dir></dir></dir></dir><dir name="Product"><file name="Api.php" hash="930494c6487bb6fb45d75ae7d5121ca4"/></dir><dir name="Order"><file name="Api.php" hash="0e5c94716fbb347e2fef4b1b0f3d19bc"/></dir><dir name="Category"><file name="Api.php" hash="a401028d1d5535f7efc5603463bf4ba6"/></dir><dir name="Attribute"><file name="Api.php" hash="265e9d32e043889f4e07775926233873"/></dir></dir><dir name="Helper"><file name="Attribute.php" hash="84734510b3170b65e782db7a90f715f9"/><file name="Category.php" hash="2780d3ce633e1f6b8ea345506d0cc89a"/><file name="Data.php" hash="affd62abb2fd7e80b599e063128ab4d6"/><file name="Image.php" hash="26bcd12cc33bd37455416035d7f23907"/><file name="Price.php" hash="2d7253c4d727935c79f8e4d861329fa5"/><file name="Product.php" hash="5bc8ab23906478ccd0df546b36f10c2f"/></dir><dir name="Block"><file name="Check.php" hash="1409b8333e818a532fee3aa88c3a1977"/></dir></dir></dir></dir></dir></dir></target></contents></package>