Mashon_Sync - Version 1.5.0

Version Notes

developed on magento 1.5.1.0;
added fixes including:

- now using php curl for making requests to Dabble Admin
- custom option prices are now being synced and updated properly
- fixed dabble-media.phtml to point to production

Download this release

Release Info

Developer brandonWargo
Extension Mashon_Sync
Version 1.5.0
Comparing to
See all releases


Code changes from version 1.4.3 to 1.5.0

app/code/community/Mashon/Sync/Helper/Data.php CHANGED
@@ -159,7 +159,7 @@ class Mashon_Sync_Helper_Data extends Mage_Core_Helper_Abstract
159
  </block>
160
  <block type="core/text" name="mystuff.js">
161
  <action method="setText">
162
- <text><![CDATA[<script type="text/javascript" src="http://creator.dabbleapp.com/loaders/instantiation.js?width=500&height=593&designedId='.$data->{'_id'}.'&new=true&productChangeCallback=changeTheProduct&frameborder=1"></script>]]></text>
163
  </action>
164
  </block>
165
  </reference>
@@ -239,21 +239,18 @@ class Mashon_Sync_Helper_Data extends Mage_Core_Helper_Abstract
239
  * @return Json $jsonResponse - dabble data
240
  */
241
  protected function _getDabbleJson($dabbleId,$designedProduct){
242
- //check to see if Custom Variable dabble_server exists, if not, then just default to the Live site
243
- //$dabbleUrl = null;
244
- //$dabbleUrl = Mage::getModel('core/variable')->loadByCode('dabble_server')->getValue('plain');
245
- //if(!$dabbleUrl){
246
- $dabbleUrl = "justdabble.com";
247
- //}
248
- if($designedProduct == 'true'){
249
-
250
- $jsonResponse = json_decode(file_get_contents("http://".$dabbleUrl."/dabble-admin/design/get/".$dabbleId));
251
- }
252
- else{
253
- $jsonResponse = json_decode(file_get_contents("http://".$dabbleUrl."/dabble-admin/template/get/".$dabbleId));
254
- }
255
 
256
- return $jsonResponse;
 
 
 
 
 
 
 
 
 
 
257
  }
258
 
259
  /**
@@ -454,7 +451,7 @@ class Mashon_Sync_Helper_Data extends Mage_Core_Helper_Abstract
454
  </block>
455
  <block type="core/text" name="mystuff.js">
456
  <action method="setText">
457
- <text><![CDATA[<script type="text/javascript" src="http://creator.dabbleapp.com/loaders/instantiation.js?width=500&height=593&designedId='.$data->{'_id'}.'&new=true&productChangeCallback=changeTheProduct&frameborder=1"></script>]]></text>
458
  </action>
459
  </block>
460
  </reference>
@@ -674,7 +671,7 @@ class Mashon_Sync_Helper_Data extends Mage_Core_Helper_Abstract
674
  default:
675
  $title = trim($v);
676
  $custom_options[count($custom_options) - 1]['values'][] = array(
677
- 'is_delete' => 0 , 'title' => $titleopt , 'price_type' => 'fixed' , 'price' => intval($price) , 'sku' => '' , 'sort_order' => $sort_order++);
678
  break;
679
  }
680
  }
@@ -685,7 +682,7 @@ class Mashon_Sync_Helper_Data extends Mage_Core_Helper_Abstract
685
  $is_required = 0;
686
  $sort_order = '';
687
  $custom_options[] = array(
688
- 'is_delete' => 0 , 'title' => $title , 'previous_group' => '' , 'previous_type' => '', 'type' => $type , 'is_require' => $is_required, 'price_type' => 'fixed' , 'price' => intval($prices[0]),'visible_on_front' => 0
689
  );
690
  return $custom_options;
691
  }
@@ -846,4 +843,4 @@ class Mashon_Sync_Helper_Data extends Mage_Core_Helper_Abstract
846
 
847
  return $xml;
848
  }
849
- }
159
  </block>
160
  <block type="core/text" name="mystuff.js">
161
  <action method="setText">
162
+ <text><![CDATA[<script type="text/javascript" src="http://www.dabbleapp.com/loaders/instantiation.js?width=500&height=593&designedId='.$data->{'_id'}.'&new=true&productChangeCallback=changeTheProduct&frameborder=1"></script>]]></text>
163
  </action>
164
  </block>
165
  </reference>
239
  * @return Json $jsonResponse - dabble data
240
  */
241
  protected function _getDabbleJson($dabbleId,$designedProduct){
 
 
 
 
 
 
 
 
 
 
 
 
 
242
 
243
+ $type = ($designedProduct == 'true') ? "design" : "template";
244
+ $url = "http://justdabble.com/dabble-admin/$type/get/$dabbleId";
245
+
246
+ $ch = curl_init();
247
+ curl_setopt($ch, CURLOPT_URL, $url);
248
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
249
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
250
+ $data = curl_exec($ch);
251
+ curl_close($ch);
252
+
253
+ return json_decode($data);
254
  }
255
 
256
  /**
451
  </block>
452
  <block type="core/text" name="mystuff.js">
453
  <action method="setText">
454
+ <text><![CDATA[<script type="text/javascript" src="http://www.dabbleapp.com/loaders/instantiation.js?width=500&height=593&designedId='.$data->{'_id'}.'&new=true&productChangeCallback=changeTheProduct&frameborder=1"></script>]]></text>
455
  </action>
456
  </block>
457
  </reference>
671
  default:
672
  $title = trim($v);
673
  $custom_options[count($custom_options) - 1]['values'][] = array(
674
+ 'is_delete' => 0 , 'title' => $titleopt , 'price_type' => 'fixed' , 'price' => floatval($price) , 'sku' => '' , 'sort_order' => $sort_order++);
675
  break;
676
  }
677
  }
682
  $is_required = 0;
683
  $sort_order = '';
684
  $custom_options[] = array(
685
+ 'is_delete' => 0 , 'title' => $title , 'previous_group' => '' , 'previous_type' => '', 'type' => $type , 'is_require' => $is_required, 'price_type' => 'fixed' , 'price' => floatval($prices[0]),'visible_on_front' => 0
686
  );
687
  return $custom_options;
688
  }
843
 
844
  return $xml;
845
  }
846
+ }
app/code/community/Mashon/Sync/Helper/DataOld.php ADDED
@@ -0,0 +1,483 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mashon Sync Helper Class for Dabble
4
+ *
5
+ * @category Mashon
6
+ * @package Mashon_Sync
7
+ * @copyright Mashon
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+ class Mashon_Sync_Helper_Data extends Mage_Core_Helper_Abstract
11
+ {
12
+ /**
13
+ * Handles Request from Mashon_Sync Controller, calls back to Dabble website for Product Template/Design data, then
14
+ * sends request to create Magento Product
15
+ *
16
+ * @param Array $params - parameters from Http Request to Mashon_Sync Controller
17
+ * @return String $response - newly created Product Id
18
+ */
19
+ public function createShopProduct(Array $params){
20
+
21
+ $response = null;
22
+ $jsonResponse = null;
23
+ $designedProduct = false;
24
+
25
+ //check to see if Custom Variable dabble_server exists, if not, then just default to the Live site
26
+ $dabbleUrl = null;
27
+ //$dabbleUrl = Mage::getModel('core/variable')->loadByCode('dabble_server')->getValue('plain');
28
+ //if(!$dabbleUrl){
29
+ $dabbleUrl = "justdabble.com";
30
+ //}
31
+
32
+ try {
33
+ $dabbleId = $params['id'];
34
+ $designedProduct = $params['designedProduct'];
35
+ if($designedProduct == 'true'){
36
+
37
+ $jsonResponse = json_decode(file_get_contents("http://".$dabbleUrl."/dabble-admin/design/get/".$dabbleId));
38
+ }
39
+ else{
40
+ $jsonResponse = json_decode(file_get_contents("http://".$dabbleUrl."/dabble-admin/template/get/".$dabbleId));
41
+ }
42
+
43
+
44
+ //create a Magento Product out of Dabble Product Json
45
+ if($jsonResponse){
46
+ $response = $this->_createShopProduct($jsonResponse,$designedProduct);
47
+ }
48
+ else{
49
+ return null;
50
+ }
51
+
52
+ } catch (Exception $e) {
53
+ Mage::log($e->getMessage());
54
+ return null;
55
+ }
56
+ return $response; //newly created Magento Shop Product Id
57
+ }
58
+
59
+
60
+ /**
61
+ * Handles Request from Mashon_Sync Controller, calls back to Dabble website for Configured Product data from Dabble Cart, then
62
+ * adds corresponding Magento Product(s) to Magento Cart
63
+ *
64
+ * @param Array $params - parameters from Http Request to Mashon_Sync Controller
65
+ * @return Json $response - success true or false
66
+ */
67
+ public function addToCart(Array $params){
68
+
69
+ $response = null;
70
+ $cartId = $params['cartId'];
71
+ $hash = md5($cartId.'th9megenatas');
72
+
73
+ //http://shop.mgm.com/scripts/processItems.php?cartId=4e9399c3e4b0c585927817f3&dataCallbackUrl=http://www.dabbleapp.com/magento/getCartItems&callback=jsonp1318295986466
74
+ $data = json_decode(file_get_contents($params['dataCallbackUrl'].'?id='.$cartId.'&hash='.$hash), true);
75
+ foreach($data as $productData) {
76
+ $productsData[] = $this->_array_to_object($productData);
77
+ }
78
+
79
+ //ok, let's add the items to the cart!
80
+ foreach($productsData as $productData) {
81
+ try {
82
+ if(isset($optionsArray)) unset($optionsArray);
83
+ if(isset($params)) unset($params);
84
+ if(isset($product)) unset($product);
85
+ if(isset($_product)) unset($_product);
86
+ if(isset($options)) unset($options);
87
+ if(isset($productId)) unset($productId);
88
+
89
+ $optionsArray = array();
90
+ $params = array();
91
+
92
+ $cart = Mage::getSingleton('checkout/cart');
93
+ $cart->init();
94
+
95
+ $_product = Mage::getModel('catalog/product');
96
+ $productId = $_product->getIdBySku($productData->attributes['internalSku']);
97
+ $product = $_product->load($productId);
98
+ $product->setCanSaveConfigurableAttributes(true);
99
+ $product->setCanSaveCustomOptions(true);
100
+
101
+ $options = $product->getOptions();
102
+
103
+ if(isset($productData->attributes['id'])) {
104
+ $productData->attributes['dabbleid'] = $productData->attributes['id'];
105
+ }
106
+
107
+ if(isset($productData->attributes['qty'])) {
108
+ $qty = intval($productData->attributes['qty']);
109
+ } else {
110
+ $qty = intval($productData->attributes['quantity']);
111
+ }
112
+ if ($qty <= 0) continue; // nothing to add
113
+
114
+ $i = 0;
115
+
116
+ //set or select the Custom Options
117
+ foreach($options as $ok => $ov) {
118
+ $label = strtolower($ov->getTitle());
119
+ if(isset($productData->attributes[$label])) {
120
+ switch($ov->getType()) {
121
+ case "drop_down":
122
+ foreach($ov->getValues() as $k => $v) {
123
+ $optionValueLabel = strtolower($v->getTitle());
124
+ if($optionValueLabel == strtolower($productData->attributes[$label])) {
125
+ $optionsArray[(string)$ok] = $v->getId();
126
+ }
127
+ }
128
+ break;
129
+ case "multiple":
130
+ foreach($ov->getValues() as $k => $v) {
131
+ $optionValueLabel = $v->getTitle();
132
+ if(in_array($optionValueLabel, $productData->attributes[$label])) {
133
+ $optionsArray[(string)$ok][] = $v->getId();
134
+ }
135
+ }
136
+ break;
137
+ default:
138
+ $optionsArray[(string)$ok] = $productData->attributes[$label];
139
+ break;
140
+ }
141
+ }
142
+ }
143
+
144
+ $params = array(
145
+ 'product' => $productId,
146
+ 'related_product' => null,
147
+ 'options' => $optionsArray,
148
+ 'qty' => $qty
149
+ );
150
+
151
+ Mage::dispatchEvent('checkout_cart_before_add', $params);
152
+ $cart->addProduct($product, $params);
153
+ Mage::dispatchEvent('checkout_cart_after_add', $params);
154
+ $cart->save();
155
+ Mage::dispatchEvent('checkout_cart_add_product', array('product'=>$params));
156
+ Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
157
+
158
+ //$message = $this->__('Custom message: %s was successfully added to your shopping cart.', $product->getName());
159
+ //Mage::getSingleton('checkout/session')->addSuccess($message);
160
+ }
161
+ catch (Mage_Core_Exception $e) {
162
+ if (Mage::getSingleton('checkout/session')->getUseNotice(true)) {
163
+ Mage::getSingleton('checkout/session')->addNotice($product->getName() . ': ' . $e->getMessage());
164
+ }
165
+ else {
166
+ Mage::getSingleton('checkout/session')->addError($product->getName() . ': ' . $e->getMessage());
167
+ }
168
+ }
169
+ catch (Exception $e) {
170
+ exit(var_dump($e));
171
+ //Mage::getSingleton('checkout/session')->addException($e, $this->__('Can not add item to shopping cart'));
172
+ }
173
+ }
174
+
175
+ $response = '({success:true})';
176
+ return $response;
177
+
178
+ }
179
+
180
+
181
+ /**
182
+ * Creates a new Magento Shop Product
183
+ *
184
+ * @param Json $data - Dabble Product data
185
+ * @param String $designedProduct - true or false
186
+ * @return String $productId - newly created Product Id
187
+ */
188
+ protected function _createShopProduct($data, $designedProduct){
189
+
190
+ // Build the product
191
+ $product = new Mage_Catalog_Model_Product();
192
+ $product->setAttributeSetId(Mage::getModel('catalog/product')->getResource()->getEntityType()->getDefaultAttributeSetId());
193
+ $product->setTypeId('simple');
194
+ /*if (Mage::app()->isSingleStoreMode()) {
195
+ $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsiteId()));
196
+ }
197
+ else {
198
+ $storesIdCode = array();
199
+ $product->setWebsiteIds(array($store->getWebsiteId()));
200
+ $stores = Mage::app()->getStores(true, true);
201
+ foreach ($stores as $code => $store) {
202
+ $storesIdCode[$store->getId()] = $code;
203
+ }
204
+ }*/
205
+ //$product->setWebsiteIds(array(Mage::app()->getStore(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID)));
206
+ //$websiteIds = array(0=>"1", 1=>"4");
207
+ //$product->setWebsiteIds($websiteIds); # (default frontend)
208
+ //$product->setWebsites($websiteIds);
209
+ //$product->setWebsiteIds(array(1));
210
+ $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
211
+ //$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsiteId());
212
+ //$product->setStoreId(1);
213
+ //$product->setStore(1);
214
+ $product->setName($data->{'alias'});
215
+ $product->setDescription($data->{'description'});
216
+ $product->setShortDescription($data->{'shortDescription'});
217
+ $product->setPrice($data->{'MSRP'});
218
+ $product->setWeight($data->{'weight'});
219
+ $product->setDabbleid($data->{'_id'});
220
+ $product->setStatus(1);
221
+ $product->setTaxClassId(0); # 0 - not taxed, 2 - taxable goods, 4 - taxable shipping
222
+ $product->setStockData(array(
223
+ 'is_in_stock' => 1,
224
+ 'qty' => 99999
225
+ ));
226
+ $product->setHasOptions(1);
227
+
228
+ #set custom design to design/dabble and layout to one column
229
+ $product->setCustomDesign('default/dabble');
230
+ $product->setPageLayout('one_column');
231
+
232
+ if($designedProduct == "true"){
233
+ $product->setSku($data->{'clientSku'});
234
+ $product->setDesignedproduct(1);
235
+ }
236
+ else {
237
+ $product->setSku($data->{'internalSku'});
238
+
239
+ }
240
+
241
+ if($data->{'template'} == "true"){
242
+ $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
243
+ }
244
+ else{
245
+ //$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
246
+ $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
247
+ }
248
+
249
+ $product->setCreatedAt(strtotime('now'));
250
+
251
+ try {
252
+ $product->save();
253
+ $productId = $product->getId();
254
+ $arrayOption = array();
255
+
256
+ #set colors and size options
257
+ foreach($data->{'options'} as $optionKey => $optionValue){
258
+ if($optionKey == 'sizes'){
259
+ $tempOptions = array();
260
+ $tempPrices = array();
261
+ foreach($optionValue as $sizeKey => $sizeValue){
262
+ if($sizeValue->{'enabled'}){
263
+ foreach($sizeValue as $name => $price){
264
+ //if($name == 'enabled' && $price){
265
+ if($name == 'name'){
266
+ $tempOptions[] = $price;
267
+ }
268
+ if($name == 'price'){
269
+ $tempPrices[] = $price;
270
+ }
271
+ // }
272
+ }
273
+ }
274
+ }
275
+ if(count($tempOptions) > 1){
276
+ $arrayOption[] = $this->_setCustomOption($tempOptions, "Size", "drop_down", false, $tempPrices, 1);
277
+ }
278
+ else{
279
+ $arrayOption[] = $this->_setCustomOption($tempOptions, "Size", "drop_down", false, $tempPrices, 0);
280
+ }
281
+ }
282
+ if($optionKey == 'colors'){
283
+ $tempOptions = array();
284
+ $tempPrices = array();
285
+ foreach($optionValue as $sizeKey => $sizeValue){
286
+ if($sizeValue->{'enabled'}){
287
+ foreach($sizeValue as $name => $price){
288
+ if($name == 'name'){
289
+ $tempOptions[] = $price;
290
+ }
291
+ if($name == 'price'){
292
+ $tempPrices[] = $price;
293
+ }
294
+ }
295
+ }
296
+ }
297
+ if(count($tempOptions) > 1){
298
+ $arrayOption[] = $this->_setCustomOption($tempOptions, "Color", "drop_down", false, $tempPrices, 1);
299
+ }
300
+ else{
301
+ $arrayOption[] = $this->_setCustomOption($tempOptions, "Color", "drop_down", false, $tempPrices, 0);
302
+ }
303
+ }
304
+ } //end foreach
305
+ if($designedProduct != "true"){
306
+ #set Dabbleid and Thumbnail
307
+ $arrayOption[] = $this->_setCustomOption("", "Dabbleid", "field", true, array(), 1);
308
+ $arrayOption[] = $this->_setCustomOption("", "Thumbnail", "field", true, array(), 1);
309
+ #build perspectives
310
+ $magentoAreas = array();
311
+ $magentoAreaPrices = array();
312
+ foreach($data->{'perspectives'} as $perspectives){
313
+ if($perspectives->{'enabled'}){
314
+ $magentoPerspective = $perspectives->{'name'}."_";
315
+ foreach($perspectives->{'views'} as $view){
316
+ $magentoView = $view->{'name'};
317
+ $magentoArea = $magentoPerspective.$magentoView;
318
+ $magentoAreas[] = $magentoArea;
319
+ $magentoPerspective = $perspectives->{'name'}."_";
320
+ $magentoAreaPrices[] = $view->{'price'};
321
+ }
322
+ }
323
+ }
324
+ $arrayOption[] = $this->_setCustomOption($magentoAreas, "Area", "multiple", false, $magentoAreaPrices, 0);
325
+ }
326
+
327
+ $product = Mage::getModel("catalog/product")->load($productId);
328
+ $product->setHasOptions(1);
329
+
330
+ foreach ($arrayOption as $options){
331
+ foreach ($options as $option) {
332
+ $opt = Mage::getModel('catalog/product_option');
333
+ $opt->setProduct($product);
334
+ $opt->addOption($option);
335
+ $opt->saveOptions();
336
+ }
337
+ }
338
+ }
339
+ catch (PDOException $pdoException){
340
+ //duplicate SKU, we need to send proper response back to dabble admin for this
341
+ Mage::log("Duplicate sku for Dabble Id: ".$data->{'_id'});
342
+ Mage::log($pdoException->getMessage());
343
+ Mage::log($pdoException->getTraceAsString());
344
+ //Mage::log($errorMessage, Zend_Log::ERR);
345
+ return null;
346
+ }
347
+ catch (Exception $ex) {
348
+ Mage::log($ex->getMessage());
349
+ Mage::log($ex->getTraceAsString());
350
+ //Mage::log($mess, Zend_Log::ERR);
351
+ //Mage::log($trace, Zend_Log::ERR);
352
+ return null;
353
+ }
354
+
355
+ return $productId;
356
+
357
+ }
358
+
359
+
360
+ /**
361
+ * Forms a product's Custom Option for creation
362
+ *
363
+ * @param Array $values - Values of the Option
364
+ * @param String $title - Title of the Option
365
+ * @param String $type - Type of Option
366
+ * @param Boolean $noOption - if options exist or not (Sizes/Colors for example)
367
+ * @param Array $prices - Price Adjustments of the Option's values
368
+ * @param Boolean $required - Whether option is required or not
369
+ * @return Array $custom_options - New Built Array of the Custom Option, its values, and prices; returns false if there is an error
370
+ */
371
+ protected function _setCustomOption ($values, $title, $type, $noOption = false, $prices = array(), $required)
372
+ {
373
+ $custom_options = array();
374
+ // if ($type && $value != "" && $value) {
375
+ //$values = explode(',', $value);
376
+ //$prices = explode(',', $price);
377
+ if (count($values)) {
378
+ #If the custom option has options
379
+ if (! $noOption) {
380
+ $is_required = $required;
381
+ $sort_order = 0;
382
+ $custom_options[] = array(
383
+ 'is_delete' => 0 , 'title' => $title , 'previous_group' => '' , 'previous_type' => '' , 'type' => $type , 'is_require' => $is_required , 'sort_order' => $sort_order , 'values' => array()
384
+ );
385
+ //foreach ($values as $v) {;
386
+ foreach (array_combine(array_values($values), array_values($prices)) as $v => $price){
387
+ $titleopt = ucfirst(trim($v));
388
+ switch ($type) {
389
+ case 'drop_down':
390
+ case 'radio':
391
+ case 'checkbox':
392
+ case 'multiple':
393
+ default:
394
+ $title = ucfirst(trim($v));
395
+ $custom_options[count($custom_options) - 1]['values'][] = array(
396
+ 'is_delete' => 0 , 'title' => $titleopt , 'price_type' => 'fixed' , 'price' => intval($price) , 'sku' => '' , 'sort_order' => '');
397
+ break;
398
+ }
399
+ }
400
+ return $custom_options;
401
+ }
402
+ #If the custom option doesn't have options | Case: area and field
403
+ else {
404
+ $is_required = 0;
405
+ $sort_order = '';
406
+ $custom_options[] = array(
407
+ "is_delete" => 0 , "title" => $title , "previous_group" => "text" , "price_type" => 'fixed' , "price" => intval($prices[0]) , "type" => $type , "is_required" => $is_required
408
+ );
409
+ return $custom_options;
410
+ }
411
+ }
412
+ // }
413
+ return false;
414
+ }
415
+
416
+
417
+ /**
418
+ * Transforms an array to an object
419
+ *
420
+ * @param Array $array - php array
421
+ * @return Object $data - Json Object
422
+ */
423
+ protected function _array_to_object($array = array()) {
424
+ if (!empty($array)) {
425
+ $data = false;
426
+ foreach ($array as $akey => $aval) {
427
+ $data -> {$akey} = $aval;
428
+ }
429
+ return $data;
430
+ }
431
+ return false;
432
+ }
433
+
434
+ public function getWebsites(){
435
+
436
+ $data = null;
437
+ $websites = Mage::app()->getWebsites();
438
+ //$data = Mage::app()->getStores()->getWebsiteIDs(); #get all stores
439
+ foreach ($websites as $website):
440
+ $data = $website->getCode();
441
+ //var_dump($data);
442
+ $data = $website->getId();
443
+ //var_dump($data);
444
+ endforeach;
445
+ $data = Mage::app()->isSingleStoreMode();
446
+
447
+ //var_dump($data);
448
+ $data = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID;
449
+ //var_dump($data);
450
+
451
+ $stores = Mage::app()->getStores(true, true);
452
+ $storeIds = array();
453
+ foreach ($stores as $code => $store) {
454
+ $storeIds[$store->getId()] = $code;
455
+ }
456
+
457
+ var_dump($storeIds);
458
+ $allids = Mage::app()->getStore()->getWebsite()->getStoreIds(true);
459
+ var_dump($allids);
460
+ $oldway = array(1);
461
+ var_dump($oldway);
462
+ //$data = Mage::app()->getStores()->getWebsiteIds();
463
+
464
+ $arrayOption = array();
465
+ $product = Mage::getModel("catalog/product")->load(10);
466
+ $product->setHasOptions(1);
467
+ $arrayOption[] = $this->_setCustomOption("", "Dabbleid", "field", true, array(), 1);
468
+ $arrayOption[] = $this->_setCustomOption("", "Thumbnail", "field", true, array(), 1);
469
+
470
+ foreach ($arrayOption as $options){
471
+ foreach ($options as $option) {
472
+ echo "hi";
473
+ $opt = Mage::getModel('catalog/product_option');
474
+ $opt->setProduct($product);
475
+ $opt->addOption($option);
476
+ $opt->saveOptions();
477
+ }
478
+ }
479
+
480
+ return $data;
481
+ }
482
+
483
+ }
app/code/community/Mashon/Sync/etc/config.xml CHANGED
@@ -11,7 +11,7 @@
11
  <config>
12
  <modules>
13
  <Mashon_Sync>
14
- <version>1.4.0</version>
15
  </Mashon_Sync>
16
  </modules>
17
  <global>
@@ -39,4 +39,4 @@
39
  </sync>
40
  </routers>
41
  </frontend>
42
- </config>
11
  <config>
12
  <modules>
13
  <Mashon_Sync>
14
+ <version>1.4.4444</version>
15
  </Mashon_Sync>
16
  </modules>
17
  <global>
39
  </sync>
40
  </routers>
41
  </frontend>
42
+ </config>
app/design/frontend/default/default/template/catalog/product/view/dabble-media.phtml CHANGED
@@ -35,7 +35,7 @@
35
  $_helper = $this->helper('catalog/output');
36
  ?>
37
  <?php if($_product->getProducttype() == 'configured'): ?>
38
- <script type="text/javascript"src="http://stage.dabbleapp.com/loaders/instantiation.js?width=500&height=593&templateId=<?php echo $_product->getTemplateid(); ?>&new=true&productChangeCallback=changeTheProduct&frameborder=1"></script>
39
  <?php else: ?>
40
  <?php if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
41
  <p class="product-image product-image-zoom">
35
  $_helper = $this->helper('catalog/output');
36
  ?>
37
  <?php if($_product->getProducttype() == 'configured'): ?>
38
+ <script type="text/javascript"src="http://www.dabbleapp.com/loaders/instantiation.js?width=500&height=593&templateId=<?php echo $_product->getTemplateid(); ?>&new=true&productChangeCallback=changeTheProduct&frameborder=1"></script>
39
  <?php else: ?>
40
  <?php if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
41
  <p class="product-image product-image-zoom">
package.xml CHANGED
@@ -1,21 +1,24 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mashon_Sync</name>
4
- <version>1.4.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>For integrating Dabble into your Magento 1.5.1.0 shop</summary>
10
- <description>Mashon_Sync allows the Magento shop owner to easily integrate Dabble into their Magento version 1.5.1.0 shop. This extension allows you to sync your Dabble Templates and Designed Products into Magento.</description>
 
11
  <notes>developed on magento 1.5.1.0;&#xD;
12
  added fixes including:&#xD;
13
  &#xD;
14
- - Fix sort order for custom options</notes>
 
 
15
  <authors><author><name>brandonWargo</name><user>brandonWargo</user><email>brandon.wargo@mashon.com</email></author></authors>
16
- <date>2013-02-21</date>
17
- <time>01:08:15</time>
18
- <contents><target name="magecommunity"><dir name="Mashon"><dir name="Sync"><dir name="Block"><file name="Sync.php" hash="d880873f5863ac7d2e627edad0289266"/></dir><dir name="Helper"><file name="Data.php" hash="5164d75d1ff39b2e1dab6db62237269f"/></dir><dir name="controllers"><file name="CartController.php" hash="646e6d845951cb09810759cf6268073a"/><file name="OrderController.php" hash="5a834a5d4980b05f8684e7d10739e20a"/><file name="ProductController.php" hash="1558404804f2174b04d7163059522bf0"/></dir><dir name="etc"><file name="config.xml" hash="04f32bf3558fbd20d508df4fd06b2b21"/></dir><dir name="sql"><dir name="mashon_setup"><file name="mysql4-install-1.0.php" hash="8ffe4d77aa3131392caa80e891afe3f9"/><file name="mysql4-upgrade-1.0-1.1.php" hash="46e3030b6acf2a66aaa843924a8af710"/><file name="mysql4-upgrade-1.3.4-1.4.php" hash="bb8f8b6247d5fdd4ccc4b43334a2dca5"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mashon_All.xml" hash="2929381275448f2ea1409a08703b6349"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="dabble"><dir name="template"><dir name="catalog"><dir name="product"><dir name="view"><file name="createyourown.phtml" hash="0e79cd3ec104ca8dde52f2b60122d0c2"/></dir><file name="view.phtml" hash="1883d9ac26da40bfbba351448d0997cc"/></dir></dir><dir name="checkout"><dir name="cart"><dir name="item"><file name="default.phtml" hash="7cb8b98411059ecd0651cc116fa973e3"/></dir></dir></dir></dir></dir><dir name="default"><dir name="template"><dir name="catalog"><dir name="product"><dir name="view"><file name="dabble-media.phtml" hash="957ee1c9ba1df455dc5ddc661c4ecd9e"/><file name="dabble-options.phtml" hash="c3565ab4bf3827231862617b1eab3c2b"/><dir name="options"><file name="dabble-wrapper.phtml" hash="2394c7f5b059b76848607535e5cb2925"/><dir name="wrapper"><file name="createyourown.phtml" hash="0e79cd3ec104ca8dde52f2b60122d0c2"/><file name="dabble-bottom.phtml" hash="2fca682fc852b7293b6e640ff3e523b5"/></dir></dir></dir></dir></dir><dir name="checkout"><dir name="cart"><dir name="item"><file name="default.phtml" hash="c315fb734b15f219a11cb5a1814fea88"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="css"><file name="dabble-styles.css" hash="f99b83b8fc9c194f64ae528b530e02ec"/></dir></dir></dir></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>Mashon_Sync</name>
4
+ <version>1.5.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>For integrating Dabble into your Magento shop</summary>
10
+ <description>Mashon_Sync allows the Magento shop owner to easily integrate Dabble into their Magento Community version 1.5.1.0 shop or newer. This extension allows you to sync your Dabble Templates and Designed Products into Magento.&#xD;
11
+ Magento Enterprise 1.12 and newer has also been proven to work.</description>
12
  <notes>developed on magento 1.5.1.0;&#xD;
13
  added fixes including:&#xD;
14
  &#xD;
15
+ - now using php curl for making requests to Dabble Admin&#xD;
16
+ - custom option prices are now being synced and updated properly&#xD;
17
+ - fixed dabble-media.phtml to point to production</notes>
18
  <authors><author><name>brandonWargo</name><user>brandonWargo</user><email>brandon.wargo@mashon.com</email></author></authors>
19
+ <date>2013-07-26</date>
20
+ <time>00:55:33</time>
21
+ <contents><target name="magecommunity"><dir name="Mashon"><dir name="Sync"><dir name="Block"><file name="Sync.php" hash="d880873f5863ac7d2e627edad0289266"/></dir><dir name="Helper"><file name="Data.php" hash="580800ee0b72ea24fd76cc2d2fd909e1"/><file name="DataOld.php" hash="11f0cae755331b8df4272cd1e56ae743"/></dir><dir name="controllers"><file name="CartController.php" hash="646e6d845951cb09810759cf6268073a"/><file name="OrderController.php" hash="5a834a5d4980b05f8684e7d10739e20a"/><file name="ProductController.php" hash="1558404804f2174b04d7163059522bf0"/></dir><dir name="etc"><file name="config.xml" hash="5e6f3f3af235df4ebcf4e0eac5f75832"/></dir><dir name="sql"><dir name="mashon_setup"><file name="mysql4-install-1.0.php" hash="8ffe4d77aa3131392caa80e891afe3f9"/><file name="mysql4-upgrade-1.0-1.1.php" hash="46e3030b6acf2a66aaa843924a8af710"/><file name="mysql4-upgrade-1.3.4-1.4.php" hash="bb8f8b6247d5fdd4ccc4b43334a2dca5"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mashon_All.xml" hash="2929381275448f2ea1409a08703b6349"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="dabble"><dir name="template"><dir name="catalog"><dir name="product"><dir name="view"><file name="createyourown.phtml" hash="0e79cd3ec104ca8dde52f2b60122d0c2"/></dir><file name="view.phtml" hash="1883d9ac26da40bfbba351448d0997cc"/></dir></dir><dir name="checkout"><dir name="cart"><dir name="item"><file name="default.phtml" hash="7cb8b98411059ecd0651cc116fa973e3"/></dir></dir></dir></dir></dir><dir name="default"><dir name="template"><dir name="catalog"><dir name="product"><dir name="view"><file name="dabble-media.phtml" hash="01f35214d7ddc8b8fe09fc078e3bf191"/><file name="dabble-options.phtml" hash="c3565ab4bf3827231862617b1eab3c2b"/><dir name="options"><file name="dabble-wrapper.phtml" hash="2394c7f5b059b76848607535e5cb2925"/><dir name="wrapper"><file name="createyourown.phtml" hash="0e79cd3ec104ca8dde52f2b60122d0c2"/><file name="dabble-bottom.phtml" hash="2fca682fc852b7293b6e640ff3e523b5"/></dir></dir></dir></dir></dir><dir name="checkout"><dir name="cart"><dir name="item"><file name="default.phtml" hash="c315fb734b15f219a11cb5a1814fea88"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="css"><file name="dabble-styles.css" hash="f99b83b8fc9c194f64ae528b530e02ec"/></dir></dir></dir></dir></target></contents>
22
  <compatible/>
23
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
24
  </package>