Citybeach_Omnivore - Version 1.0.0

Version Notes

First post-beta GA release

Download this release

Release Info

Developer City Beach Software
Extension Citybeach_Omnivore
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Citybeach/Omnivore/Block/Adminhtml/Payment.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Citybeach_Omnivore_Block_Adminhtml_Payment extends Mage_Payment_Block_Info
4
+ {
5
+ private $order = NULL;
6
+
7
+ // ########################################
8
+
9
+ protected function _construct()
10
+ {
11
+ parent::_construct();
12
+ $this->setTemplate('omnivore/payment.phtml');
13
+ }
14
+
15
+ /**
16
+ * Get absolute path to template
17
+ *
18
+ * @return string
19
+ */
20
+ public function getTemplateFile()
21
+ {
22
+ $params = array(
23
+ '_relative' => true,
24
+ '_area' => 'adminhtml',
25
+ '_package' => 'default',
26
+ '_theme' => 'default'
27
+ );
28
+
29
+ return Mage::getDesign()->getTemplateFilename($this->getTemplate(), $params);
30
+ }
31
+
32
+ public function getPoNumber()
33
+ {
34
+ /** @var Mage_Sales_Model_Order_Payment $foo */
35
+ $foo = $this->getInfo();
36
+ Mage::log("--> foo is " . get_class($foo));
37
+
38
+ return $foo->getPoNumber();
39
+ }
40
+
41
+ public function getAdditionalInformation()
42
+ {
43
+ /** @var Mage_Sales_Model_Order_Payment $foo */
44
+ $foo = $this->getInfo();
45
+ }
46
+
47
+ public function getTransactionNumber()
48
+ {
49
+ return "abc123";
50
+ }
51
+ }
app/code/community/Citybeach/Omnivore/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Citybeach_Omnivore_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ // nothing useful here
6
+ }
app/code/community/Citybeach/Omnivore/Model/Mysql4/Rego.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: radu
5
+ * Date: 24/05/15
6
+ * Time: 12:25 PM
7
+ */
8
+
9
+ class Citybeach_Omnivore_Model_Mysql4_Rego extends Mage_Core_Model_Mysql4_Abstract
10
+ {
11
+ public function _construct()
12
+ {
13
+ $this->_init('citybeach_omnivore/rego', 'rego_id');
14
+ }
15
+ }
app/code/community/Citybeach/Omnivore/Model/Mysql4/Rego/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Citybeach_Omnivore_Model_Mysql4_Rego_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('citybeach_omnivore/rego');
8
+ parent::_construct();
9
+ }
10
+ }
app/code/community/Citybeach/Omnivore/Model/Order.php ADDED
@@ -0,0 +1,510 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * User: radu
5
+ * Date: 19/08/15
6
+ */
7
+ class Citybeach_Omnivore_Model_Order
8
+ {
9
+
10
+ public $storeId;
11
+ public $guestCheckout;
12
+
13
+ // the data structure parsed from the JSON string;
14
+ public $json;
15
+
16
+ // some strings we need for shipping, but we compute in validate()
17
+ private $carrierCode, $carrierTitle, $methodCode, $methodTitle;
18
+
19
+ /** @var $quote Mage_Sales_Model_Quote */
20
+ private $quote = NULL;
21
+
22
+ /** @var $order Mage_Sales_Model_Order */
23
+ private $order = NULL;
24
+
25
+ // TODO: custom options
26
+ private $additionalData = array();
27
+
28
+
29
+ public function __construct()
30
+ {
31
+ }
32
+
33
+ public function __toString()
34
+ {
35
+ //return print_r($this, true);
36
+ return "orderNumber = {$this->json->marketplaceOrderNumber}";
37
+ }
38
+
39
+ public function validate()
40
+ {
41
+ /** @var Mage_Core_Model_Store $store */
42
+ $store = Mage::getModel('core/store')->load($this->storeId);
43
+
44
+ if (!$store->getId())
45
+ {
46
+ throw new Exception("Cannot load store id {$this->storeId}");
47
+ }
48
+
49
+ if ($this->json->currency != $store->getBaseCurrency()->getCurrencyCode())
50
+ {
51
+ throw new Exception("Order currency {$this->json->currency} is different than store base currency {$store->getBaseCurrency()->getCurrencyCode()}");
52
+ }
53
+
54
+ // shippingMethod is carrierCode_methodCode, eg: flatrate_flatrate or ups_GND
55
+ // NOTE: some methods have an underscore or more in the code, eg: fedex_STANDARD_OVERNIGHT, usps_INT_10
56
+ $pos = strpos($this->json->shippingMethod, "_");
57
+
58
+ if ($pos === false)
59
+ {
60
+ throw new Exception("Cannot find an underscore character in the shipping method");
61
+ }
62
+
63
+ $carrierCode = substr($this->json->shippingMethod, 0, $pos);
64
+ $methodCode = substr($this->json->shippingMethod, $pos + 1, strlen($this->json->shippingMethod));
65
+
66
+ //Mage::log("carrierCode = {$carrierCode}, methodCode = {$methodCode}");
67
+
68
+ $found = false;
69
+
70
+ $carriers = Mage::getSingleton('shipping/config')->getAllCarriers();
71
+ // $carriers is a map where the key is the carrier "code" and the value is an object that extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
72
+ foreach ($carriers as $key1 => $value1)
73
+ {
74
+ //Mage::log("key = {$key1}, value class is = " . get_class($value1) . ", methods = " . print_r($value1->getAllowedMethods(), true));
75
+ //Mage::log("carrier as array = " . print_r($value1, true));
76
+
77
+ if ($carrierCode == $value1->getCarrierCode())
78
+ {
79
+ // found a matching carrier, let's check the method
80
+ $methods = $value1->getAllowedMethods();
81
+
82
+ // $methods is a map where the key is the method "code" and the value is a display label, apparently
83
+ foreach ($methods as $key2 => $value2)
84
+ {
85
+ if ($methodCode == $key2)
86
+ {
87
+ $found = true;
88
+
89
+ $this->carrierCode = $carrierCode;
90
+ $this->carrierTitle = $value1->getConfigData('title');
91
+ $this->methodCode = $methodCode;
92
+ $this->methodTitle = $value2;
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ if (!$found)
99
+ {
100
+ throw new Exception("Cannot find a carrier {$carrierCode} with method {$methodCode}");
101
+ }
102
+
103
+ //throw new Exception("Validation failed for marketplace {$this->json->marketplaceCode} order {$this->json->marketplaceOrderNumber}");
104
+ }
105
+
106
+ public function persist()
107
+ {
108
+ try
109
+ {
110
+ $this->createMagentoQuote();
111
+ $this->createMagentoOrder();
112
+ }
113
+ catch (Exception $ex)
114
+ {
115
+ //Mage::log("exception = {$ex}");
116
+ error_log("exception = {$ex}");
117
+
118
+ $this->quote->setIsActive(false)->save();
119
+
120
+ throw $ex;
121
+ }
122
+ }
123
+
124
+ public function getOrderId()
125
+ {
126
+ if ($this->order == null)
127
+ {
128
+ //Mage::log("returning *null*");
129
+ return null;
130
+ }
131
+ else
132
+ {
133
+ //Mage::log("getOrderId: returning increment id = {$this->order->getIncrementId()} for order id = {$this->order->getId()}");
134
+ return $this->order->getIncrementId();
135
+ }
136
+ }
137
+
138
+ public function createMagentoQuote()
139
+ {
140
+ try
141
+ {
142
+ $this->setupQuote();
143
+ $this->setupCustomer();
144
+ $this->setupAddresses();
145
+ $this->setupTaxCalculation();
146
+ $this->setupCurrency();
147
+ $this->setupQuoteItems();
148
+ $this->setupPaymentData();
149
+
150
+ $this->quote->collectTotals();
151
+
152
+ $this->quote->save();
153
+
154
+ //Mage::log("quote id = " . $this->quote->getId());
155
+ }
156
+ catch (Exception $ex)
157
+ {
158
+ error_log("exception = {$ex}");
159
+
160
+ //Mage::log("exception = {$ex}");
161
+ //Mage::log("quote = " . print_r($this->quote, true));
162
+
163
+ $this->quote->setIsActive(false)->save();
164
+ throw $ex;
165
+ }
166
+ }
167
+
168
+ private function setupQuote()
169
+ {
170
+ /** @var Mage_Core_Model_Store $store */
171
+ $store = Mage::getModel('core/store')->load($this->storeId);
172
+
173
+ $this->quote = Mage::getModel('sales/quote');
174
+
175
+ $this->quote->setCheckoutMethod('todo');
176
+ $this->quote->setStore($store);
177
+ $this->quote->setQuoteCurrencyCode($this->json->currency);
178
+
179
+ //$this->quote->getStore()->setData('current_currency', $this->quote->getStore()->getBaseCurrency());
180
+
181
+ $this->quote->save();
182
+
183
+ Mage::getSingleton('checkout/session')->replaceQuote($this->quote);
184
+ }
185
+
186
+ private function setupCustomer()
187
+ {
188
+
189
+ if ($this->guestCheckout)
190
+ {
191
+ $this->quote
192
+ ->setCustomerId(null)
193
+ ->setCustomerEmail($this->json->customer->email)
194
+ ->setCustomerFirstname($this->json->customer->firstName)
195
+ ->setCustomerLastname($this->json->customer->lastName)
196
+ ->setCustomerIsGuest(true)
197
+ ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
198
+ }
199
+ else
200
+ {
201
+ /** @var Mage_Customer_Model_Customer $customer */
202
+ $customer = null;
203
+
204
+ $customers = Mage::getModel('customer/customer')->getCollection();
205
+ $customers->addFieldToFilter('email', $this->json->customer->email);
206
+
207
+ if ($customers->count() > 0)
208
+ {
209
+ $customer = $customers->getFirstItem();
210
+ //Mage::log("Found existing customer id = {$customer->getId()}");
211
+ //$this->quote->assignCustomer($customer);
212
+ }
213
+ else
214
+ {
215
+ /** @var Mage_Core_Model_Store $store */
216
+ $store = Mage::getModel('core/store')->load($this->storeId);
217
+
218
+ $password = Mage::helper('core')->getRandomString(12);
219
+
220
+ $customer = Mage::getModel('customer/customer')
221
+ ->setData('firstname', $this->json->billingAddress->firstName)
222
+ ->setData('lastname', $this->json->billingAddress->lastName)
223
+ ->setData('website_id', $store->getWebsiteId())
224
+ ->setData('email', $this->json->customer->email)
225
+ ->setData('confirmation', $password);
226
+
227
+ $customer->setPassword($password);
228
+ $customer->save();
229
+
230
+ //Mage::log("Created new customer id = {$customer->getId()}");
231
+
232
+ $street = '';
233
+ if ($this->json->shippingAddress->line2 != '')
234
+ {
235
+ $street = $this->json->shippingAddress->line1 . ', ' . $this->json->shippingAddress->line2;
236
+ }
237
+ else
238
+ {
239
+ $street = $this->json->shippingAddress->line1;
240
+ }
241
+
242
+ /** @var Mage_Customer_Model_Address $customerAddress */
243
+ $customerAddress = Mage::getModel('customer/address')
244
+ ->setData('firstname', $this->json->shippingAddress->firstName)
245
+ ->setData('lastname', $this->json->shippingAddress->lastName)
246
+ ->setData('street', $street)
247
+ ->setData('city', $this->json->shippingAddress->city)
248
+ ->setData('country_id', $this->json->shippingAddress->countryCode)
249
+ ->setData('postcode', $this->json->shippingAddress->postcode)
250
+ ->setData('telephone', $this->json->shippingAddress->phone)
251
+ ->setData('email', $this->json->customer->email)
252
+ ->setData('region', $this->json->shippingAddress->state)
253
+ //->setData('region_id', $this->json->shippingAddress->state)
254
+ ->setCustomerId($customer->getId())
255
+ ->setIsDefaultBilling(true)
256
+ ->setIsDefaultShipping(true);
257
+
258
+ $customerAddress->implodeStreetAddress();
259
+ $customerAddress->save();
260
+ }
261
+
262
+ if (is_null($customer))
263
+ {
264
+ throw new Exception("Cannot find or create the customer");
265
+ }
266
+ else
267
+ {
268
+ //Mage:log("Setting customer id = {$customer->getId()}");
269
+ $this->quote
270
+ ->setCustomerId($customer->getId())
271
+ ->setCustomerEmail($this->json->customer->email)
272
+ ->setCustomerFirstname($this->json->customer->firstName)
273
+ ->setCustomerLastname($this->json->customer->lastName)
274
+ ->setCustomerIsGuest(false)
275
+ ->setCustomerGroupId(Mage_Customer_Model_Group::CUST_GROUP_ALL); // TODO???
276
+ }
277
+ }
278
+
279
+ }
280
+
281
+ private function setupAddresses()
282
+ {
283
+ // Billing:
284
+
285
+ $billingAddressData = array();
286
+ $billingAddressData['firstname'] = $this->json->billingAddress->firstName;
287
+ $billingAddressData['lastname'] = $this->json->billingAddress->lastName;
288
+ if ($this->json->billingAddress->line2 != '')
289
+ {
290
+ $billingAddressData['street'] = $this->json->billingAddress->line1 . ', ' . $this->json->billingAddress->line2;
291
+ }
292
+ else
293
+ {
294
+ $billingAddressData['street'] = $this->json->billingAddress->line1;
295
+ }
296
+
297
+ $billingAddressData['city'] = $this->json->billingAddress->city;
298
+ $billingAddressData['region'] = $this->json->billingAddress->state;
299
+ //$billingAddressData['region_id'] = $this->json->billingAddress->state;
300
+ $billingAddressData['country_id'] = $this->json->billingAddress->countryCode;
301
+ $billingAddressData['postcode'] = $this->json->billingAddress->postcode;
302
+ $billingAddressData['telephone'] = $this->json->billingAddress->phone;
303
+ $billingAddressData['email'] = $this->json->customer->email;
304
+
305
+ $billingAddress = $this->quote->getBillingAddress();
306
+ $billingAddress->addData($billingAddressData);
307
+ $billingAddress->implodeStreetAddress();
308
+
309
+ // looks like billing address doesn't need a shipping method
310
+ $billingAddress->setShippingMethod(null);
311
+ $billingAddress->setCollectShippingRates(false);
312
+ $billingAddress->setShouldIgnoreValidation(true);
313
+
314
+ // Shipping:
315
+
316
+ $shippingAddressData = array();
317
+ $shippingAddressData['firstname'] = $this->json->shippingAddress->firstName;
318
+ $shippingAddressData['lastname'] = $this->json->shippingAddress->lastName;
319
+
320
+ if ($this->json->shippingAddress->line2 != '')
321
+ {
322
+ $shippingAddressData['street'] = $this->json->shippingAddress->line1 . ', ' . $this->json->shippingAddress->line2;
323
+ }
324
+ else
325
+ {
326
+ $shippingAddressData['street'] = $this->json->shippingAddress->line1;
327
+ }
328
+
329
+ $shippingAddressData['city'] = $this->json->shippingAddress->city;
330
+ $shippingAddressData['region'] = $this->json->shippingAddress->state;
331
+ //$shippingAddressData['region_id'] = $this->json->shippingAddress->state;
332
+ $shippingAddressData['country_id'] = $this->json->shippingAddress->countryCode;
333
+ $shippingAddressData['postcode'] = $this->json->shippingAddress->postcode;
334
+ $shippingAddressData['telephone'] = $this->json->shippingAddress->phone;
335
+ $shippingAddressData['email'] = $this->json->customer->email;
336
+
337
+ $shippingAddress = $this->quote->getShippingAddress();
338
+ $shippingAddress->setSameAsBilling(0);
339
+ $shippingAddress->addData($shippingAddressData);
340
+ $shippingAddress->implodeStreetAddress();
341
+
342
+ // database values seem to be of the form carrierCode underscore methodCode, eg: flatrate_flatrate or ups_GND
343
+ $shippingAddress->setShippingMethod($this->json->shippingMethod);
344
+ $shippingAddress->setCollectShippingRates(false);
345
+
346
+ // Mage::log("shippingAddress id = " . $shippingAddress->getId());
347
+
348
+ /** @var Mage_Sales_Model_Quote_Address_Rate $rate */
349
+ $rate = Mage::getModel('sales/quote_address_rate');
350
+
351
+ $rate->setCode($this->json->shippingMethod);
352
+ $rate->setCarrier($this->carrierCode);
353
+ $rate->setCarrierTitle($this->carrierTitle);
354
+ $rate->setMethod($this->methodCode);
355
+ $rate->setMethodTitle($this->methodTitle);
356
+ $rate->setPrice($this->json->shippingPrice);
357
+
358
+ $shippingAddress->addShippingRate($rate);
359
+
360
+ //Mage::log("rate = {$rate}");
361
+ }
362
+
363
+ private function setupCurrency()
364
+ {
365
+
366
+ $currentCurrency = Mage::getModel('directory/currency')->load($this->json->currency);
367
+ $this->quote->getStore()->setData('current_currency', $currentCurrency);
368
+
369
+ //Mage::log("initializeCurrency: store base currency = " . $this->quote->getStore()->getBaseCurrency());
370
+ //Mage::log("initializeCurrency: store current currency = " . $this->quote->getStore()->getCurrentCurrency());
371
+
372
+ if ($this->json->currency != $this->quote->getStore()->getBaseCurrency()->getCurrencyCode())
373
+ {
374
+ throw new Exception("Order currency {$this->json->currency} is different than store currency {$this->quote->getStore()->getBaseCurrency()->getCurrencyCode()}");
375
+ }
376
+
377
+ }
378
+
379
+
380
+ private function setupTaxCalculation()
381
+ {
382
+ // see Mage_Tax_Model_Calculation::setCustomer()
383
+ Mage::getSingleton('tax/calculation')->setCustomer($this->quote->getCustomer());
384
+ }
385
+
386
+
387
+ private function setupQuoteItems()
388
+ {
389
+ //$prods = $this->json->products;
390
+ //Mage::log("initializeQuoteItems: prods = " . $prods);
391
+
392
+ foreach ($this->json->products as $lineItem)
393
+ {
394
+ // a lineItem has these properties: sku, variantCode, variantName, externalId, quantity, unitPrice
395
+
396
+ //Mage::log("initializeQuoteItems: item = " . print_r($item, true));
397
+ $productId = $lineItem->externalId;
398
+
399
+ $this->clearQuoteItemsCache();
400
+
401
+ /** @var $product Mage_Catalog_Model_Product */
402
+ $product = Mage::getModel('catalog/product')->load($productId);
403
+
404
+ //Mage::log("setupQuoteItems: Magento product id = {$product->getId()}, sku = {$product->getSku()}");
405
+
406
+ // TODO: add product options to $request
407
+
408
+ $request = new Varien_Object();
409
+ $request->setQty($lineItem->quantity);
410
+
411
+ $productOriginalPrice = (float)$product->getPrice();
412
+
413
+ $price = $lineItem->unitPrice;
414
+ $product->setPrice($price);
415
+ $product->setSpecialPrice($price);
416
+
417
+ // see Mage_Sales_Model_Observer::substractQtyFromQuotes
418
+ $this->quote->setItemsCount($this->quote->getItemsCount() + 1);
419
+ $this->quote->setItemsQty((float)$this->quote->getItemsQty() + $request->getQty());
420
+
421
+ $result = $this->quote->addProduct($product, $request);
422
+ if (is_string($result))
423
+ {
424
+ throw new Exception($result);
425
+ }
426
+
427
+ $quoteItem = $this->quote->getItemByProduct($product);
428
+ //Mage::log(" ***** quoteItem = " . $quoteItem);
429
+
430
+ if ($quoteItem !== false)
431
+ {
432
+ $weight = $product->getTypeInstance()->getWeight();
433
+ if ($product->isConfigurable())
434
+ {
435
+ $simpleProductId = $product->getCustomOption('simple_product')->getProductId();
436
+ $weight = Mage::getResourceModel('catalog/product')->getAttributeRawValue(
437
+ $simpleProductId, 'weight', 0
438
+ );
439
+ }
440
+
441
+ $quoteItem->setStoreId($this->quote->getStoreId());
442
+ $quoteItem->setOriginalCustomPrice($lineItem->unitPrice);
443
+ $quoteItem->setOriginalPrice($productOriginalPrice);
444
+ $quoteItem->setBaseOriginalPrice($productOriginalPrice);
445
+ $quoteItem->setWeight($weight);
446
+ $quoteItem->setNoDiscount(1);
447
+
448
+ }
449
+ }
450
+ }
451
+
452
+ private function clearQuoteItemsCache()
453
+ {
454
+ foreach ($this->quote->getAllAddresses() as $address)
455
+ {
456
+ /** @var $address Mage_Sales_Model_Quote_Address */
457
+
458
+ $address->unsetData('cached_items_all');
459
+ $address->unsetData('cached_items_nominal');
460
+ $address->unsetData('cached_items_nonominal');
461
+ }
462
+ }
463
+
464
+ private function setupPaymentData()
465
+ {
466
+ $quotePayment = $this->quote->getPayment();
467
+ $paymentData = array();
468
+
469
+ $paymentData['method'] = 'omnivorepayment';
470
+
471
+ $payment = $this->json->payment;
472
+
473
+ if ($payment->paymentType == 'paypal')
474
+ {
475
+ $paymentData['po_number'] = $payment->transactionId . ' : ' . $payment->paypalPayerId;
476
+ $paymentData['additional_information'] = 'PayPal Transaction: ' . $payment->transactionId . ', PayPal Payer Id: ' . $payment->paypalPayerId .
477
+ ', Amount: ' . $payment->amount . ', Currency: ' . $payment->currency;
478
+ }
479
+ else
480
+ {
481
+ // don't really expect to be here anytime soon
482
+ $paymentData['po_number'] = $payment->transactionId;
483
+ }
484
+
485
+ $quotePayment->importData($paymentData);
486
+ }
487
+
488
+ private function createMagentoOrder()
489
+ {
490
+ try
491
+ {
492
+ // NOTE: we don't support Magento versions < 1.5.0
493
+
494
+ /** @var $service Mage_Sales_Model_Service_Quote */
495
+ $service = Mage::getModel('sales/service_quote', $this->quote);
496
+ $service->setOrderData($this->additionalData);
497
+ $service->submitAll();
498
+
499
+ $this->order = $service->getOrder();
500
+
501
+ $this->quote->setIsActive(false)->save();
502
+ }
503
+ catch (Exception $e)
504
+ {
505
+ $this->quote->setIsActive(false)->save();
506
+ throw $e;
507
+ }
508
+ }
509
+
510
+ }
app/code/community/Citybeach/Omnivore/Model/Order/Api.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Citybeach_Omnivore_Model_Order_Api extends Mage_Checkout_Model_Cart_Api
3
+ {
4
+
5
+ public function json2order($jsonOrder, $storeId, $guestCheckout)
6
+ {
7
+ //Mage::log(__FILE__);
8
+ //Mage::log("createQuoteAndOrder: storeId = {$storeId}, json = {$jsonOrder}");
9
+
10
+
11
+ /** @var $order Citybeach_Omnivore_Model_Order */
12
+ $order = Mage::getModel('citybeach_omnivore/order');
13
+
14
+ $order->json = json_decode($jsonOrder);
15
+ $order->storeId = $storeId;
16
+ $order->guestCheckout = $guestCheckout;
17
+
18
+ $order->validate();
19
+
20
+ $order->persist();
21
+
22
+ return $order->getOrderId();
23
+ }
24
+
25
+ }
26
+ ?>
app/code/community/Citybeach/Omnivore/Model/Payment.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Citybeach_Omnivore_Model_Payment extends Mage_Payment_Model_Method_Abstract
4
+ {
5
+ protected $_code = 'omnivorepayment';
6
+
7
+ protected $_canUseCheckout = false;
8
+ protected $_canUseInternal = false;
9
+ protected $_canUseForMultishipping = false;
10
+
11
+ //protected $_infoBlockType = 'citybeach_omnivore/adminhtml_payment';
12
+ protected $_infoBlockType = 'Citybeach_Omnivore_Block_Adminhtml_Payment';
13
+
14
+ //
15
+ // public function assignData($data)
16
+ // {
17
+ // if ($data instanceof Varien_Object) {
18
+ // $data = $data->getData();
19
+ // }
20
+ //
21
+ // $details = array(
22
+ // 'component_mode' => $data['component_mode'],
23
+ // 'payment_method' => $data['payment_method'],
24
+ // 'channel_order_id' => $data['channel_order_id'],
25
+ // 'channel_final_fee' => $data['channel_final_fee'],
26
+ // 'transactions' => $data['transactions'],
27
+ // 'tax_id' => isset($data['tax_id']) ? $data['tax_id'] : null,
28
+ // );
29
+ //
30
+ // $this->getInfoInstance()->setAdditionalData(serialize($details));
31
+ //
32
+ // return $this;
33
+ // }
34
+
35
+ }
app/code/community/Citybeach/Omnivore/Model/Product/Api.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Citybeach_Omnivore_Model_Product_Api extends Mage_Catalog_Model_Product_Api
3
+ {
4
+ /**
5
+ * Retrieve product info and all associated simple products/variants
6
+ *
7
+ * @param int|string $productId
8
+ * @param string|int $store
9
+ * @param array $attributes
10
+ * @return array
11
+ */
12
+ public function info($productId, $store = null, $attributes = null, $identifierType = null)
13
+ {
14
+ //mage::log(__FILE__);
15
+ //error_log('Citybeach_Omnivore_Model_Product_Api->info() productId = ' . $productId);
16
+
17
+ $result = parent::info ( $productId, $store, $attributes, $identifierType );
18
+
19
+ if ($result ['type'] == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
20
+
21
+ $product = Mage::getModel ( 'catalog/product' )->load ( $result ['product_id'] );
22
+
23
+ if ($product->isConfigurable ()) {
24
+ $children = $product->getTypeInstance ( true )->getUsedProductIds ( $product );
25
+ $result['associated_ids'] = $children;
26
+ }
27
+ }
28
+
29
+
30
+ return $result;
31
+ }
32
+ }
33
+ ?>
app/code/community/Citybeach/Omnivore/Model/Rego.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Citybeach_Omnivore_Model_Rego extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('citybeach_omnivore/rego');
8
+ parent::_construct();
9
+ }
10
+ }
app/code/community/Citybeach/Omnivore/Model/Resource/Setup.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Citybeach_Omnivore_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
4
+ {
5
+ public function startSetup()
6
+ {
7
+ $this->getConnection()->startSetup();
8
+ return $this;
9
+ }
10
+ }
app/code/community/Citybeach/Omnivore/Model/Store/Api.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * User: radu
4
+ * Date: 4/09/15
5
+ */
6
+
7
+ class Citybeach_Omnivore_Model_Store_Api extends Mage_Core_Model_Store_Api
8
+ {
9
+
10
+ public function shipping($storeId)
11
+ {
12
+ Mage::log("shipping: storeId = {$storeId}");
13
+
14
+ /** @var Mage_Core_Model_Store $store */
15
+ $store = Mage::getModel('core/store')->load($storeId);
16
+
17
+ if (!$store->getId())
18
+ {
19
+ throw new Exception("Cannot load store id {$storeId}");
20
+ }
21
+
22
+ $result = array();
23
+
24
+ $carriers = Mage::getSingleton('shipping/config')->getAllCarriers();
25
+ // $carriers is a map where the key is the carrier "code" and the value is an object that extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
26
+ foreach ($carriers as $key1 => $value1)
27
+ {
28
+ //Mage::log("key = {$key1}, value class is = " . get_class($value1) . ", methods = " . print_r($value1->getAllowedMethods(), true));
29
+ //Mage::log("carrier as array = " . print_r($value1, true));
30
+
31
+ $carrier = array();
32
+
33
+ $carrier['code'] = $value1->getCarrierCode();
34
+ $carrier['title'] = $value1->getConfigData('title');
35
+ $carrier['methods'] = $value1->getAllowedMethods();
36
+
37
+
38
+ $result[] = $carrier;
39
+ }
40
+
41
+ // Mage::log("shipping: result = " . print_r($result, true));
42
+
43
+
44
+ return $result;
45
+ }
46
+
47
+ }
48
+ ?>
app/code/community/Citybeach/Omnivore/controllers/Adminhtml/OmnivoreController.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Citybeach_Omnivore_Adminhtml_OmnivoreController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function indexAction()
6
+ {
7
+ // TODO: move logic for install/assign here
8
+ $sess = Mage::getSingleton('admin/session');
9
+ $sessUser = $sess->getUser();
10
+
11
+ $userId = Mage::helper('adminhtml')->getCurrentUserId();
12
+
13
+ $email = $sessUser->getEmail();
14
+
15
+ $this->loadLayout();
16
+ $this->renderLayout();
17
+
18
+ return $this;
19
+ }
20
+ }
app/code/community/Citybeach/Omnivore/etc/adminhtml.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <citybeach_omnivore module="citybeach_omnivore">
5
+ <title>Omnivore</title>
6
+ <sort_order>99</sort_order>
7
+ <action>adminhtml/omnivore/index</action>
8
+ <!--<children>-->
9
+ <!--<items module="cbs_omnivore">-->
10
+ <!--<title>Launch</title>-->
11
+ <!--<sort_order>0</sort_order>-->
12
+ <!--<action>adminhtml/omnivore/index</action>-->
13
+ <!--</items>-->
14
+ <!--</children>-->
15
+ </citybeach_omnivore>
16
+ </menu>
17
+ </config>
app/code/community/Citybeach/Omnivore/etc/api.xml ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <omproduct translate="title" module="citybeach_omnivore">
6
+ <title>Omnivore extension to Product API</title>
7
+ <acl>omproduct</acl>
8
+ <model>Citybeach_Omnivore_Model_Product_Api</model> <!-- not in magento example -->
9
+ <methods>
10
+ <info translate="title" module="citybeach_omnivore">
11
+ <title>Retrieve product info and associated IDs</title>
12
+ <acl>omproduct/info</acl>
13
+ </info>
14
+ </methods>
15
+ <faults module="citybeach_omnivore">
16
+ </faults>
17
+ </omproduct>
18
+ <omorder translate="title" module="citybeach_omnivore">
19
+ <title>Omnivore extension to Cart API</title>
20
+ <acl>omorder</acl>
21
+ <model>Citybeach_Omnivore_Model_Order_Api</model>
22
+ <methods>
23
+ <json2order translate="title" module="citybeach_omnivore">
24
+ <title>Create a Quote and transform it into an Order</title>
25
+ <acl>omorder/json2order</acl>
26
+ </json2order>
27
+ </methods>
28
+ <faults module="citybeach_omnivore">
29
+ </faults>
30
+ </omorder>
31
+ <omstore translate="title" module="citybeach_omnivore">
32
+ <title>Omnivore extension to Store API</title>
33
+ <acl>omstore</acl>
34
+ <model>Citybeach_Omnivore_Model_Store_Api</model>
35
+ <methods>
36
+ <shipping translate="title" module="citybeach_omnivore">
37
+ <title>List carriers and shipping methods</title>
38
+ <acl>omstore/shipping</acl>
39
+ </shipping>
40
+ </methods>
41
+ <faults module="citybeach_omnivore">
42
+ </faults>
43
+ </omstore>
44
+ </resources>
45
+ <acl>
46
+ <resources>
47
+ <omproduct translate="title" module="citybeach_omnivore">
48
+ <title>Omnivore extension to Product API</title>
49
+ <info translate="title" module="citybeach_omnivore">
50
+ <title>Retrieve product info and associated IDs</title>
51
+ </info>
52
+ </omproduct>
53
+ <omorder translate="title" module="citybeach_omnivore">
54
+ <title>Omnivore extension to Cart API</title>
55
+ <json2order translate="title" module="citybeach_omnivore">
56
+ <title>Create a Quote and transform it into an Order</title>
57
+ </json2order>
58
+ </omorder>
59
+ <omstore translate="title" module="citybeach_omnivore">
60
+ <title>Omnivore extension to Store API</title>
61
+ <shipping translate="title" module="citybeach_omnivore">
62
+ <title>List carriers and shipping methods</title>
63
+ </shipping>
64
+ </omstore>
65
+ </resources>
66
+ </acl>
67
+ </api>
68
+ </config>
app/code/community/Citybeach/Omnivore/etc/config.xml ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <config>
3
+ <modules>
4
+ <Citybeach_Omnivore>
5
+ <version>1.0.0</version>
6
+ </Citybeach_Omnivore>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <citybeach_omnivore>
11
+ <class>Citybeach_Omnivore_Model</class>
12
+ <resourceModel>citybeach_omnivore_mysql4</resourceModel>
13
+ </citybeach_omnivore>
14
+ <citybeach_omnivore_mysql4>
15
+ <class>Citybeach_Omnivore_Model_Mysql4</class>
16
+ <entities>
17
+ <rego>
18
+ <table>citybeach_omnivore_rego</table>
19
+ </rego>
20
+ </entities>
21
+ </citybeach_omnivore_mysql4>
22
+ </models>
23
+
24
+ <helpers>
25
+ <citybeach_omnivore>
26
+ <class>Citybeach_Omnivore_Helper</class>
27
+ </citybeach_omnivore>
28
+ </helpers>
29
+
30
+ <resources>
31
+ <citybeach_omnivore_setup>
32
+ <setup>
33
+ <module>Citybeach_Omnivore</module>
34
+ <class>Citybeach_Omnivore_Model_Resource_Setup</class>
35
+ </setup>
36
+ <connection>
37
+ <use>core_setup</use>
38
+ </connection>
39
+ </citybeach_omnivore_setup>
40
+ <citybeach_omnivore_write>
41
+ <connection>
42
+ <use>core_write</use>
43
+ </connection>
44
+ </citybeach_omnivore_write>
45
+ <citybeach_omnivore_read>
46
+ <connection>
47
+ <use>core_read</use>
48
+ </connection>
49
+ </citybeach_omnivore_read>
50
+ </resources>
51
+
52
+ </global>
53
+
54
+ <admin>
55
+ <routers>
56
+ <adminhtml>
57
+ <args>
58
+ <modules>
59
+ <citybeach_omnivore before="Mage_Adminhtml">Citybeach_Omnivore_Adminhtml</citybeach_omnivore>
60
+ </modules>
61
+ </args>
62
+ </adminhtml>
63
+ </routers>
64
+
65
+ </admin>
66
+
67
+ <adminhtml>
68
+ <layout>
69
+ <updates>
70
+ <citybeach_omnivore module="citybeach_omnivore">
71
+ <file>omnivore.xml</file>
72
+ </citybeach_omnivore>
73
+ </updates>
74
+ </layout>
75
+ </adminhtml>
76
+
77
+ <frontend>
78
+ <routers />
79
+ <events />
80
+ <translate />
81
+ <layout />
82
+ </frontend>
83
+ <default>
84
+ <config_vars />
85
+ <payment>
86
+ <omnivorepayment>
87
+ <active>1</active>
88
+ <model>Citybeach_Omnivore_Model_Payment</model>
89
+ <order_status>pending</order_status>
90
+ <title>Omnivore Payment</title>
91
+ <allowspecific>0</allowspecific>
92
+ <group>offline</group>
93
+ </omnivorepayment>
94
+ </payment>
95
+ </default>
96
+ </config>
app/code/community/Citybeach/Omnivore/etc/system.xml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <omnivorepayment translate="label">
7
+ <label>Omnivore Payment</label>
8
+ <sort_order>999</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>0</show_in_store>
12
+ <fields>
13
+ <active translate="label">
14
+ <label>Enabled</label>
15
+ <frontend_type>select</frontend_type>
16
+ <source_model>adminhtml/system_config_source_yesno</source_model>
17
+ <sort_order>1</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ </active>
22
+ <title translate="label">
23
+ <label>Title</label>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>2</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>0</show_in_store>
29
+ </title>
30
+ </fields>
31
+ </omnivorepayment>
32
+ </groups>
33
+ </payment>
34
+ </sections>
35
+ </config>
app/code/community/Citybeach/Omnivore/sql/citybeach_omnivore_setup/install-1.0.0.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $OMNIVORE_ROLE = 'omnivore_role';
4
+ $OMNIVORE_USER = 'omnivore_user';
5
+
6
+ $installer = $this;
7
+ $admin = Mage::getSingleton('admin/session')->getUser();
8
+ $adminUserId = null;
9
+ $adminEmail = null;
10
+
11
+ if (isset($admin))
12
+ {
13
+ error_log("Admin user id = {$admin->getUserId()}, running installer = " . get_class($installer));
14
+ }
15
+ else
16
+ {
17
+ error_log("Running installer " . get_class($installer) . ", admin user is not set!");
18
+ }
19
+
20
+ $installer->startSetup();
21
+
22
+ $tableName = $installer->getTable('citybeach_omnivore/rego');
23
+
24
+ // create the table if it doesn't exist
25
+ if ($installer->getConnection()->isTableExists($tableName) != true)
26
+ {
27
+ error_log("Creating table {$tableName}");
28
+ $table = $installer->getConnection()
29
+ ->newTable($tableName)
30
+ ->addColumn('rego_id', Varien_Db_Ddl_Table::TYPE_INTEGER,
31
+ null,
32
+ array(
33
+ 'identity' => true,
34
+ 'unsigned' => true,
35
+ 'nullable' => false,
36
+ 'primary' => true,
37
+ ),
38
+ 'Rego Id'
39
+ )
40
+ ->addColumn('user_id', Varien_Db_Ddl_Table::TYPE_INTEGER,
41
+ null,
42
+ array(
43
+ 'unsigned' => true,
44
+ 'nullable' => false,
45
+ 'default' => '0',
46
+ ),
47
+ 'User Id'
48
+ )
49
+ ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 255,
50
+ array(),
51
+ 'Email'
52
+ )
53
+ ->addColumn('key', Varien_Db_Ddl_Table::TYPE_TEXT, 255,
54
+ array(),
55
+ 'Key'
56
+ )
57
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 255,
58
+ array(),
59
+ 'Key'
60
+ );
61
+
62
+ $installer->getConnection()->createTable($table);
63
+ }
64
+ else
65
+ {
66
+ error_log("Table {$tableName} exists!");
67
+ }
68
+
69
+ // generate random key to be used as API key and Omnivore account password:
70
+ $key = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'), 0, 20);
71
+ //error_log("Random key = {$key}");
72
+
73
+ // check if there are existing records in the rego table
74
+ $regos = Mage::getModel('citybeach_omnivore/rego')->getCollection();
75
+ if ($regos->count() > 0)
76
+ {
77
+ error_log("Table {$tableName} contains {$regos->count()} records!");
78
+ }
79
+ else
80
+ {
81
+ $rego = Mage::getModel('citybeach_omnivore/rego');
82
+
83
+ $rego->setUserId($adminUserId);
84
+ $rego->setEmail($adminEmail);
85
+ $rego->setKey($key);
86
+ $rego->setStatus('installed');
87
+
88
+ $rego->save();
89
+ error_log("Rego record created, rego id = {$rego->getId()}");
90
+ }
91
+
92
+ $role = Mage::getModel('api/roles');
93
+ $user = Mage::getModel('api/user');
94
+
95
+ // create the omnivore role if it doesn't exist
96
+ $roles = Mage::getModel('api/roles')->getCollection();
97
+ $roles->addFieldToFilter('role_name', $OMNIVORE_ROLE);
98
+ if ($roles->count() > 0)
99
+ {
100
+ error_log("The API role {$OMNIVORE_ROLE} already exists, rules not updated!");
101
+ $role = $roles->getFirstItem();
102
+ }
103
+ else
104
+ {
105
+ $role = $role
106
+ ->setName('omnivore_role')
107
+ ->setPid(0)
108
+ ->setRoleType('G')
109
+ ->save();
110
+
111
+ error_log("API role created, role id = {$role->getId()}");
112
+
113
+ Mage::getModel("api/rules")
114
+ ->setRoleId($role->getId())
115
+ ->setResources(array("all"))
116
+ ->saveRel();
117
+
118
+ error_log("API rules created, permissions set to 'all' ");
119
+ }
120
+
121
+ // create the omnivore user if it doesn't exist
122
+ $users = Mage::getModel('api/user')->getCollection();
123
+ $users->addFieldToFilter('username', $OMNIVORE_USER);
124
+ if ($users->count() > 0)
125
+ {
126
+ error_log("The API user {$OMNIVORE_USER} already exists, roles not updated!");
127
+ $user = $users->getFirstItem();
128
+ }
129
+ else
130
+ {
131
+ $user->setData(array(
132
+ 'username' => $OMNIVORE_USER,
133
+ 'firstname' => 'Omnivore',
134
+ 'lastname' => 'Api User',
135
+ 'email' => 'omnivore@citybeachsoftware.com',
136
+ 'api_key' => $key,
137
+ 'is_active' => 1,
138
+ 'user_roles' => '',
139
+ 'assigned_user_role' => '',
140
+ 'role_name' => '',
141
+ 'roles' => array($role->getId())
142
+ ));
143
+ $user->save();
144
+
145
+ error_log("API user created, user id = " . $user->getId());
146
+
147
+ $user->setRoleIds(array($role->getId()))
148
+ ->setRoleUserId($user->getUserId())
149
+ ->saveRelations();
150
+ }
151
+
152
+ $installer->endSetup();
153
+
154
+ // this does a clean uninstall:
155
+ //drop table citybeach_omnivore_rego;
156
+ //delete from core_resource where code = 'citybeach_omnivore_setup';
157
+ //delete from api_rule where role_id in (select role_id from api_role where role_name = 'omnivore_role');
158
+ //delete from api_role where role_type = 'U' and role_name = 'Omnivore';
159
+ //delete from api_role where role_type = 'G' and role_name = 'omnivore_role';
160
+ //delete from api_user where username = 'omnivore_user';
app/design/adminhtml/default/default/layout/omnivore.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <adminhtml_omnivore_index>
4
+ <reference name="content">
5
+ <block type="core/template" name="omnivore" template="omnivore/omnivore.phtml" />
6
+ </reference>
7
+ </adminhtml_omnivore_index>
8
+ </layout>
app/design/adminhtml/default/default/template/omnivore/omnivore.phtml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $OMNIVORE_URL = 'http://m1.omnivore.com.au';
4
+ //$OMNIVORE_URL = 'http://localhost:8080';
5
+
6
+ $url = Mage::helper("adminhtml")->getUrl("adminhtml/index/index");
7
+
8
+ $admin = Mage::getSingleton('admin/session')->getUser();
9
+ $adminEmail = $admin->getEmail();
10
+
11
+ error_log("Admin email = {$adminEmail}");
12
+
13
+ $email = null;
14
+ $key = null;
15
+ $rego = null;
16
+
17
+ $regos = Mage::getModel('citybeach_omnivore/rego')->getCollection()
18
+ ->addFieldToFilter('status', 'installed')
19
+ ->addFieldToFilter('email', array('null' => true));
20
+
21
+ if ($regos->count() > 0 && isset($adminEmail))
22
+ {
23
+ $rego = $regos->getFirstItem()
24
+ ->setEmail($adminEmail)
25
+ ->setStatus('assigned')
26
+ ->save();
27
+
28
+ error_log("Omnivore login assigned to {$adminEmail}");
29
+ }
30
+ else
31
+ {
32
+ $rego = Mage::getModel('citybeach_omnivore/rego')->getCollection()
33
+ ->addFieldToFilter('status', 'assigned')
34
+ ->getFirstItem();
35
+ error_log("Using rego id = {$rego->getId()}, email = {$rego->getEmail()}");
36
+ }
37
+
38
+ $key = $rego->getKey();
39
+ $email = $rego->getEmail();
40
+
41
+ ?>
42
+
43
+
44
+
45
+ <h3>Access Omnivore</h3>
46
+
47
+ <p>
48
+ Click the button to access Omnivore:
49
+ </p>
50
+ <form action="<?php echo $OMNIVORE_URL; ?>/magento/rego" method="post" target="_blank">
51
+
52
+ <input type="hidden" name="url" value="<?php echo $url; ?>" />
53
+ <input type="hidden" name="key" value="<?php echo $key; ?>" />
54
+ <input type="hidden" name="email" value="<?php echo $email; ?>" />
55
+
56
+ <button>Go To Omnivore</button>
57
+
58
+ </form>
app/design/adminhtml/default/default/template/omnivore/payment.phtml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ Omnivore Payment
3
+ <br/>
4
+
5
+ Transaction Number:
6
+
7
+ <strong><?php echo $this->escapeHtml($this->getPoNumber()); ?></strong>
8
+
9
+ <br/>
app/etc/modules/Citybeach_Omnivore.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Citybeach_Omnivore>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <!--<depends>-->
8
+ <!--<Mage_adminhtml />-->
9
+ <!--</depends>-->
10
+ </Citybeach_Omnivore>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Citybeach_Omnivore</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.omnivore.com.au/index.php/omnivore-application-terms-of-use/">Omnivore Application Terms of Use</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Integrate your Magento store with eBay/Westfield/Google shopping in minutes; auto-synch orders and listings</summary>
10
+ <description>Install the Omnivore Magento extension for a quick and easy way to connect to eBay.com.au, eBay.ca, Westfield and Google Shopping marketplaces.&#xD;
11
+ &#xD;
12
+ We specialise in Australian marketplaces and have over 600 retailers of all shapes and sizes using Omnivore, including many of the top 50.&#xD;
13
+ &#xD;
14
+ The Omnivore Magento extension will not interfere with any customisations you may already have. &#xD;
15
+ &#xD;
16
+ &lt;b&gt;Installation and Set Up&lt;/b&gt;&#xD;
17
+ &#xD;
18
+ It only takes a few minutes to install the extension, then depending on the marketplace you choose you could be listing your products within the hour.&#xD;
19
+ &#xD;
20
+ &lt;b&gt;Support&lt;/b&gt;&#xD;
21
+ &#xD;
22
+ We provide phone and email support to ensure you have the help you need, when you need it.&#xD;
23
+ &#xD;
24
+ &lt;b&gt;Here&#x2019;s why Omnivore makes selling on multiple marketplaces easy&lt;/b&gt;&#xD;
25
+ &#xD;
26
+ 1. Listings&#xD;
27
+ &#xD;
28
+ Omnivore creates and updates product listings automatically. Choose which products you want to list on each marketplace.&#xD;
29
+ &#xD;
30
+ 2. Marketplace Category Mapping&#xD;
31
+ &#xD;
32
+ Categorise your products to the right categories on each marketplace easily with our Category Mapping feature so that your products end up on the right &#x2018;shelves&#x2019;. Use recommended categories or choose from the full list.&#xD;
33
+ &#xD;
34
+ 3. Orders flow back to Magento&#xD;
35
+ &#xD;
36
+ Omnivore checks for Orders every couple of minutes, when we receive an order we send it straight through to your Magento store for fulfilment.&#xD;
37
+ &#xD;
38
+ 4. Customise Pricing and Promotions&#xD;
39
+ &#xD;
40
+ The Promotions Manager lets you target and enhance your products for each marketplace. Sell dusty stock by targeting customers in each marketplace with great deals without changing prices on your ecommerce store.&#xD;
41
+ &#xD;
42
+ 5. Product Bundles&#xD;
43
+ &#xD;
44
+ Group the same or different products together and price them differently to create product bundles.&#xD;
45
+ &#xD;
46
+ 6. Prevent Overselling with Stock Buffers&#xD;
47
+ &#xD;
48
+ You can set a stock buffer so that you never oversell and receive poor customer feedback.&#xD;
49
+ &#xD;
50
+ 7. Buy online, Pick up Instore&#xD;
51
+ &#xD;
52
+ Customers love having the option to save on postage and pick up their purchase instore. NB: Only available for on request.&#xD;
53
+ &#xD;
54
+ For more information about Omnivore visit:&#xD;
55
+ &#xD;
56
+ www.omnivore.com.au</description>
57
+ <notes>First post-beta GA release</notes>
58
+ <authors><author><name>City Beach Software</name><user>omnivore</user><email>ilogan@citybeachsoftware.com</email></author></authors>
59
+ <date>2016-02-02</date>
60
+ <time>11:36:49</time>
61
+ <contents><target name="magecommunity"><dir name="Citybeach"><dir name="Omnivore"><dir name="Block"><dir name="Adminhtml"><file name="Payment.php" hash="ee4ffe77673c583cfca4c92624c962a2"/></dir></dir><dir name="Helper"><file name="Data.php" hash="8633af317628bbaa17bc0b98bbef9395"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Rego"><file name="Collection.php" hash="bbf62854180e85d24952b1b4b8ce9135"/></dir><file name="Rego.php" hash="4d7ab20314f5f39df0dc4557a2a1c781"/></dir><dir name="Order"><file name="Api.php" hash="10435b83f13df7b095117dad69a1456f"/></dir><file name="Order.php" hash="4b9b5100f4c855f8dabc730ee8ca0b37"/><file name="Payment.php" hash="21d74bcef388399e80aa68cfbce31c6c"/><dir name="Product"><file name="Api.php" hash="c6e2cdfb324144559f1d629a8134687e"/></dir><file name="Rego.php" hash="b08186f0b5341100bea9a97c20006bf3"/><dir name="Resource"><file name="Setup.php" hash="01a9f8f313a702ecbc3cb64dd4dd11ff"/></dir><dir name="Store"><file name="Api.php" hash="357f88f8914601b996eb62f1d99de84e"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="OmnivoreController.php" hash="22c370bc5013ecf564e78fbe5a4c3406"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="5041fcdd6bc108508db254312e0dd5d9"/><file name="api.xml" hash="1b432747b85973fe69ba249dbe6ed8d5"/><file name="config.xml" hash="62109abc8c1b58bfd3de31526bb9e80c"/><file name="system.xml" hash="85b1e13759fe11ebab04a07592aea491"/></dir><dir name="sql"><dir name="citybeach_omnivore_setup"><file name="install-1.0.0.php" hash="88ea3e8b17aa6f90e463462e55b5b5ad"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Citybeach_Omnivore.xml" hash="6383f5a2c140edb19dc47341f89f8c1b"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="omnivore.xml" hash="359b2ed74cb29212d55845f8b73e75c0"/></dir><dir name="template"><dir name="omnivore"><file name="omnivore.phtml" hash="d5bd4cd5a64bb9c98dec680a6c69be88"/><file name="payment.phtml" hash="f7855e06c687fd45e04cc729e9f96a7b"/></dir></dir></dir></dir></dir></target></contents>
62
+ <compatible/>
63
+ <dependencies><required><php><min>5.3.0</min><max>5.6.99</max></php></required></dependencies>
64
+ </package>