CosmicCart - Version 1.0.0

Version Notes

Initial release.

Download this release

Release Info

Developer Cosmic Cart, Inc.
Extension CosmicCart
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (29) hide show
  1. app/code/community/CosmicCart/Integration/Helper/Data.php +18 -0
  2. app/code/community/CosmicCart/Integration/Model/AccessToken.php +58 -0
  3. app/code/community/CosmicCart/Integration/Model/Api.php +41 -0
  4. app/code/community/CosmicCart/Integration/Model/Api/Resource.php +28 -0
  5. app/code/community/CosmicCart/Integration/Model/Api/V2.php +25 -0
  6. app/code/community/CosmicCart/Integration/Model/Client.php +51 -0
  7. app/code/community/CosmicCart/Integration/Model/Order/Api/V2.php +261 -0
  8. app/code/community/CosmicCart/Integration/Model/Pay.php +81 -0
  9. app/code/community/CosmicCart/Integration/Model/Product/Api/V2.php +83 -0
  10. app/code/community/CosmicCart/Integration/Model/Resource/AccessToken.php +57 -0
  11. app/code/community/CosmicCart/Integration/Model/Resource/AccessToken/Collection.php +20 -0
  12. app/code/community/CosmicCart/Integration/Model/Resource/Client.php +57 -0
  13. app/code/community/CosmicCart/Integration/Model/Resource/Client/Collection.php +20 -0
  14. app/code/community/CosmicCart/Integration/Model/Resource/Setup.php +16 -0
  15. app/code/community/CosmicCart/Integration/Model/Shipment/Observer.php +79 -0
  16. app/code/community/CosmicCart/Integration/OAuth2Client.php +223 -0
  17. app/code/community/CosmicCart/Integration/controllers/Adminhtml/ActivationController.php +118 -0
  18. app/code/community/CosmicCart/Integration/etc/api.xml +41 -0
  19. app/code/community/CosmicCart/Integration/etc/config.xml +176 -0
  20. app/code/community/CosmicCart/Integration/etc/cosmiccart.ini +1 -0
  21. app/code/community/CosmicCart/Integration/etc/system.xml +16 -0
  22. app/code/community/CosmicCart/Integration/etc/wsdl.xml +44 -0
  23. app/code/community/CosmicCart/Integration/etc/wsi.xml +359 -0
  24. app/code/community/CosmicCart/Integration/sql/cosmiccart_integration_setup/install-1.0.0.php +68 -0
  25. app/design/adminhtml/default/default/layout/cosmiccart/integration.xml +9 -0
  26. app/design/adminhtml/default/default/template/cosmiccart/activation.phtml +42 -0
  27. app/etc/modules/CosmicCart_Integration.xml +14 -0
  28. app/locale/en_US/CosmicCart_Integration.csv +10 -0
  29. package.xml +18 -0
app/code/community/CosmicCart/Integration/Helper/Data.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+
14
+ class CosmicCart_Integration_Helper_Data extends Mage_Core_Helper_Abstract
15
+ {
16
+
17
+
18
+ }
app/code/community/CosmicCart/Integration/Model/AccessToken.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+
14
+ /**
15
+ * AccessToken model
16
+ *
17
+ * @method CosmicCart_Integration_Model_Resource_AccessToken _getResource()
18
+ * @method CosmicCart_Integration_Model_Resource_AccessToken getResource()
19
+ * @method string getAccessToken()
20
+ * @method CosmicCart_Integration_Model_AccessToken setAccessToken(string $value)
21
+ * @method string getRefreshToken()
22
+ * @method CosmicCart_Integration_Model_AccessToken setRefreshToken(string $value)
23
+ * @method string getTokenType()
24
+ * @method CosmicCart_Integration_Model_AccessToken setTokenType(string $value)
25
+ * @method string getScope()
26
+ * @method CosmicCart_Integration_Model_AccessToken setScope(string $value)
27
+ * @method date getExpires()
28
+ * @method CosmicCart_Integration_Model_AccessToken setExpires(date $value)
29
+ */class CosmicCart_Integration_Model_AccessToken extends Mage_Core_Model_Abstract
30
+ {
31
+ protected $_resourceCollectionName = 'cosmiccart_integration/accessToken_collection';
32
+
33
+ protected function _construct()
34
+ {
35
+ $this->_init('cosmiccart_integration/accessToken');
36
+ }
37
+
38
+ public function exists() {
39
+ $existing = $this->findExisting();
40
+ return !empty($existing);
41
+ }
42
+
43
+ public function findExisting() {
44
+ $accessToken = null;
45
+ foreach($this->getCollection() as $token) {
46
+ $accessToken = $token;
47
+ break;
48
+ }
49
+ return $accessToken;
50
+ }
51
+
52
+ public function deleteExisting() {
53
+ foreach($this->getCollection() as $accessToken) {
54
+ $accessToken->delete();
55
+ }
56
+ }
57
+
58
+ }
app/code/community/CosmicCart/Integration/Model/Api.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+
14
+ /**
15
+ * Integration Test API
16
+ *
17
+ * @category Local
18
+ * @package CosmicCart_Integration
19
+ * @author Erik Dannenberg <erik.dannenberg@bbe-consulting.de>
20
+ */
21
+ class CosmicCart_Integration_Model_Api extends CosmicCart_Integration_Model_Api_Resource {
22
+
23
+ // constructor
24
+ public function __construct()
25
+ {
26
+ }
27
+
28
+ /**
29
+ * Says hello
30
+ *
31
+ * @param string name to greet
32
+ * @return string the greeting
33
+ */
34
+ public function helloWorld($name) {
35
+ if ( $name != '' ) {
36
+ return sprintf('Hello %s! Nice day isn\'t it?', $name);
37
+ } else {
38
+ $this->_fault('myerror_code');
39
+ }
40
+ }
41
+ }
app/code/community/CosmicCart/Integration/Model/Api/Resource.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+
14
+ /**
15
+ * Integration API base class
16
+ *
17
+ * @category Local
18
+ * @package CosmicCart_Integration
19
+ * @author Erik Dannenberg <erik.dannenberg@bbe-consulting.de>
20
+ */
21
+ class CosmicCart_Integration_Model_Api_Resource extends Mage_Api_Model_Resource_Abstract
22
+ {
23
+ // constructor
24
+ public function __construct()
25
+ {
26
+ }
27
+
28
+ } // Class CosmicCart_Integration_Model_Api_Resource End
app/code/community/CosmicCart/Integration/Model/Api/V2.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+ /**
14
+ * The class that actually get's called for V2 api calls,
15
+ * usually the business logic is the same for each api so
16
+ * we just extend from the v1 api class and be done with it.
17
+ *
18
+ */
19
+ class CosmicCart_Integration_Model_Api_V2 extends CosmicCart_Integration_Model_Api
20
+ {
21
+ // constructor
22
+ public function __construct()
23
+ {
24
+ }
25
+ }
app/code/community/CosmicCart/Integration/Model/Client.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+
14
+ /**
15
+ * Client model
16
+ *
17
+ * @method string getClientId()
18
+ * @method CosmicCart_Integration_Model_Client setClientId(string $value)
19
+ * @method string getClientSecret()
20
+ * @method CosmicCart_Integration_Model_Client setClientSecret(string $value)
21
+ */
22
+ class CosmicCart_Integration_Model_Client extends Mage_Core_Model_Abstract
23
+ {
24
+ protected $_resourceCollectionName = 'cosmiccart_integration/client_collection';
25
+
26
+ protected function _construct()
27
+ {
28
+ $this->_init('cosmiccart_integration/client');
29
+ }
30
+
31
+ public function exists() {
32
+ $existing = $this->findExisting();
33
+ return !empty($existing);
34
+ }
35
+
36
+ public function findExisting() {
37
+ $client = null;
38
+ foreach($this->getCollection() as $c) {
39
+ $client = $c;
40
+ break;
41
+ }
42
+ return $client;
43
+ }
44
+
45
+ public function deleteExisting() {
46
+ foreach($this->getCollection() as $client) {
47
+ $client->delete();
48
+ }
49
+ }
50
+
51
+ }
app/code/community/CosmicCart/Integration/Model/Order/Api/V2.php ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * NOTICE OF LICENSE
3
+ *
4
+ * This source file is subject to the Cosmic Cart license, a commercial license.
5
+ *
6
+ * @category CosmicCart
7
+ * @package Integration
8
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
9
+ * @license Proprietary
10
+ */
11
+
12
+ <?
13
+
14
+ class CosmicCart_Integration_Model_Order_Api_V2 extends Mage_Sales_Model_Order_Api_V2
15
+ {
16
+
17
+ public function create($orderData)
18
+ {
19
+ $response = null;
20
+ try {
21
+ /* Determine stock status for each requested item and make adjustments if necessary. */
22
+ $itemsToAdd = array();
23
+ $itemsToFail = array();
24
+ foreach ($orderData->items as $item) {
25
+ /* Check the stock level of each item and sort appropriately. */
26
+ $item->originalQty = $item->qty;
27
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->sku);
28
+ if (!empty($product) && $product->isSaleable()) {
29
+ $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
30
+ if (!empty($stockItem)) {
31
+ $inStock = $stockItem->getIsInStock();
32
+ $qtyInStock = $stockItem->getQty();
33
+ $isBackorderable = $stockItem->getBackorders() != Mage_CatalogInventory_Model_Stock::BACKORDERS_NO;
34
+ if ($inStock && ($isBackorderable || $qtyInStock >= $item->qty)) {
35
+ /* If we have plenty of stock or the item is backorderable, proceed as normal. */
36
+ $itemsToAdd[] = $item;
37
+ } else if ($inStock && $qtyInStock > 0) {
38
+ /* If we only have a few we can allocate from our requested quantity, do that, and put the rest
39
+ in a failed item. */
40
+ $item->qty = $qtyInStock;
41
+ $itemsToAdd[] = $item;
42
+ $itemToFail = new stdClass;
43
+ $itemToFail->sku = $item->sku;
44
+ $itemToFail->qty = $item->originalQty - $qtyInStock;
45
+ $itemsToFail[] = $itemToFail;
46
+ } else {
47
+ $itemsToFail[] = $item;
48
+ }
49
+ } else {
50
+ $itemsToFail[] = $item;
51
+ }
52
+ } else {
53
+ $itemsToFail[] = $item;
54
+ }
55
+ }
56
+
57
+ /* Break our results into those added and those backordered. */
58
+ $itemStatuses = array();
59
+ $itemsFailed = array();
60
+
61
+ /* Can't add any items if none are available. */
62
+ if (sizeof($itemsToAdd) > 0) {
63
+ /* Create the quote */
64
+ $cartApi = Mage::getSingleton("Mage_Checkout_Model_Cart_Api_V2");
65
+ $quoteId = $cartApi->create();
66
+
67
+ /* Add the items to the quote */
68
+ $cartProductApi = Mage::getSingleton("Mage_Checkout_Model_Cart_Product_Api_V2");
69
+ $cartProductApi->add($quoteId, $itemsToAdd);
70
+
71
+ /* The default api does not allow us to set custom pricing. So let's do that ourselves. */
72
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
73
+ $quote->setCosmicCartOrderId($orderData->orderId);
74
+ $quoteItems = $quote->getItemsCollection();
75
+ foreach ($quoteItems as &$quoteItem) {
76
+ foreach ($itemsToAdd as $item) {
77
+ if ($item->sku == $quoteItem->getSku()) {
78
+ $quoteItem->setCosmicCartOrderItemId($item->orderItemId);
79
+ $quoteItem->setOriginalCustomPrice($item->price);
80
+ break;
81
+ }
82
+ }
83
+ }
84
+ $quote->setTotalsCollectedFlag(false)->collectTotals();
85
+ $quote->save();
86
+
87
+ /* Set the customer */
88
+ $cartCustomerApi = Mage::getSingleton("Mage_Checkout_Model_Cart_Customer_Api_V2");
89
+ $cartCustomerApi->set($quoteId, $orderData->customer);
90
+ $cartCustomerApi->setAddresses($quoteId, $orderData->customer_addresses);
91
+
92
+ /*
93
+ Set the shipping method.
94
+
95
+ What happens here is that Cosmic Cart has set a ShippingOption on each OrderItem in the Order.
96
+ However, we must currently use the same ShippingOption for all OrderItems. #businessrule
97
+ */
98
+ $cartShippingApi = Mage::getSingleton("Mage_Checkout_Model_Cart_Shipping_Api_V2");
99
+ $cartShippingApi->setShippingMethod($quoteId, $itemsToAdd[0]->shippingOption);
100
+
101
+ /* Set our custom payment method */
102
+ $cartPaymentApi = Mage::getSingleton("Mage_Checkout_Model_Cart_Payment_Api");
103
+ $cartPaymentApi->setPaymentMethod($quoteId, array("method" => "cosmiccart"));
104
+
105
+ /* Convert our cart to an order */
106
+ $orderId = $cartApi->createOrder($quoteId);
107
+ $order = $this->_initOrder($orderId);
108
+ $order->setCustomerEmail($orderData->customer->email);
109
+ $order->setCosmicCartOrderId($orderData->orderId);
110
+ $order->save();
111
+
112
+ /* Invoice (pay for) our order. */
113
+ $salesOrderInvoiceApi = Mage::getSingleton("Mage_Sales_Model_Order_Invoice_Api_V2");
114
+ $invoiceId = $salesOrderInvoiceApi->create($orderId, array(), "Payment authorized. Awaiting settlement via Cosmic Cart when items ship.");
115
+ $invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
116
+ $invoice->pay();
117
+ $transactionSave = Mage::getModel('core/resource_transaction')
118
+ ->addObject($invoice)
119
+ ->addObject($invoice->getOrder())
120
+ ->save();
121
+
122
+ /* Gotta reload the order to get a version with all the updates performed by the invoicing. */
123
+ $order = $this->_initOrder($orderId);
124
+
125
+ foreach ($order->getItemsCollection() as $item) {
126
+ $itemStatus = new stdClass;
127
+ $itemStatus->qtyFailed = 0; // Default
128
+ $itemStatus->sku = $item->getSku();
129
+ foreach ($itemsToAdd as $itemRequested) {
130
+ if ($itemRequested->sku == $itemStatus->sku) {
131
+ $item->setCosmicCartOrderItemId($itemRequested->orderItemId);
132
+ $item->save();
133
+ $itemStatus->qtyRequested = $itemRequested->originalQty;
134
+ break;
135
+ }
136
+ }
137
+ $itemStatus->tax = $item->getTaxAmount();
138
+ $itemStatus->qtyBackordered = $item->getQtyBackordered();
139
+ foreach ($itemsToFail as $itemToFail) {
140
+ if ($itemToFail->sku == $itemStatus->sku) {
141
+ $itemStatus->qtyFailed = $itemToFail->qty;
142
+ $itemsFailed[] = $itemStatus;
143
+ break;
144
+ }
145
+ }
146
+ $itemStatus->qtyAllocated = $itemStatus->qtyRequested - $itemStatus->qtyBackordered - $itemStatus->qtyFailed;
147
+ $itemStatuses[] = $itemStatus;
148
+ }
149
+ }
150
+ /* Completely failed items won't be returned by the other API calls, but we still need to return a status for them. */
151
+ foreach ($itemsToFail as $itemToFail) {
152
+ $yetToFail = true;
153
+ foreach ($itemsFailed as $itemAlreadyFailed) {
154
+ if ($itemAlreadyFailed->sku == $itemToFail->sku) {
155
+ $yetToFail = false;
156
+ break;
157
+ }
158
+ }
159
+ if ($yetToFail) {
160
+ $itemStatus = new stdClass;
161
+ $itemStatus->sku = $itemToFail->sku;
162
+ $itemStatus->qtyRequested = $itemToFail->qty;
163
+ $itemStatus->qtyAllocated = 0;
164
+ $itemStatus->qtyBackordered = 0;
165
+ $itemStatus->qtyFailed = $itemToFail->qty;
166
+ $itemStatuses[] = $itemStatus;
167
+ }
168
+ }
169
+
170
+ $response = array(
171
+ 'orderId' => $orderId,
172
+ 'items' => $itemStatuses
173
+ );
174
+
175
+ } catch (Mage_Core_Exception $e) {
176
+ error_log($e->getMessage());
177
+ throw $e;
178
+ }
179
+
180
+ return $response;
181
+ }
182
+
183
+ public function getShippingMethodsList($addressData, $orderItemsData)
184
+ {
185
+ $quote = $this->createTemporaryQuote($addressData, $orderItemsData);
186
+
187
+ $cartShippingApi = Mage::getSingleton("Mage_Checkout_Model_Cart_Shipping_Api_V2");
188
+ $results = $cartShippingApi->getShippingMethodsList($quote->getId());
189
+
190
+ // Clean up anything we saved to the db.
191
+ $quote->delete();
192
+
193
+ return $results;
194
+ }
195
+
196
+ protected function createTemporaryQuote($addressData, $orderItemsData, $doSave = true)
197
+ {
198
+ /* Create a quote to hold the items */
199
+ $cartApi = Mage::getSingleton("Mage_Checkout_Model_Cart_Api_V2");
200
+ $quoteId = $cartApi->create();
201
+
202
+ /* Add the items to the quote */
203
+ $cartProductApi = Mage::getSingleton("Mage_Checkout_Model_Cart_Product_Api_V2");
204
+ $cartProductApi->add($quoteId, $orderItemsData);
205
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
206
+ $quote->getBillingAddress();
207
+ $quoteItems = $quote->getItemsCollection();
208
+ foreach ($quoteItems as &$quoteItem) {
209
+ foreach ($orderItemsData as $item) {
210
+ if ($item->sku == $quoteItem->getSku()) {
211
+ $quoteItem->setOriginalCustomPrice($item->price);
212
+ break;
213
+ }
214
+ }
215
+ }
216
+
217
+ // Create shipping address model
218
+ $shippingAddress = Mage::getModel('sales/quote_address');
219
+ $shippingAddress->setCity($addressData->city);
220
+ $shippingAddress->setCountryId($addressData->country_id);
221
+ $shippingAddress->setRegion($addressData->region);
222
+ $shippingAddress->setStreet($addressData->street);
223
+ $shippingAddress->setPostcode($addressData->postcode);
224
+ $shippingAddress->setAddressType('shipping');
225
+ $shippingAddress->setCollectShippingRates(true);
226
+ $quote->setShippingAddress($shippingAddress)->setCollectShippingRates(true);
227
+
228
+ $quote->setTotalsCollectedFlag(false)->collectTotals();
229
+ if ($doSave) {
230
+ $quote->save();
231
+ }
232
+ return $quote;
233
+ }
234
+
235
+ public function getSalesTax($addressData, $orderItemsData)
236
+ {
237
+ $quote = $this->createTemporaryQuote($addressData, $orderItemsData, false);
238
+ $salesTax = $quote->getTotals()['tax']->getValue();
239
+ return $salesTax;
240
+ }
241
+
242
+ public function getShippingCost($addressData, $orderItemsData)
243
+ {
244
+ $quote = $this->createTemporaryQuote($addressData, $orderItemsData);
245
+ $quoteId = $quote->getId();
246
+
247
+ $shippingCost = 0.0;
248
+
249
+ $cartShippingApi = Mage::getSingleton("Mage_Checkout_Model_Cart_Shipping_Api_V2");
250
+ if ($cartShippingApi->setShippingMethod($quote->getId(), $orderItemsData[0]->shippingOption)) {
251
+ $quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);
252
+ $shippingCost = $quote->getShippingAddress()->getShippingAmount();
253
+ }
254
+
255
+ // Clean up anything we saved to the db.
256
+ $quote->delete();
257
+
258
+ return $shippingCost;
259
+ }
260
+
261
+ }
app/code/community/CosmicCart/Integration/Model/Pay.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+ /**
14
+ * Created by IntelliJ IDEA.
15
+ * User: mcsenter
16
+ * Date: 9/7/13
17
+ * Time: 9:24 PM
18
+ * To change this template use File | Settings | File Templates.
19
+ */
20
+ class CosmicCart_Integration_Model_Pay extends Mage_Payment_Model_Method_Abstract
21
+ {
22
+ protected $_code = 'cosmiccart';
23
+
24
+ /**
25
+ * Is this payment method a gateway (online auth/charge) ?
26
+ */
27
+ protected $_isGateway = true;
28
+
29
+ /**
30
+ * Can authorize online?
31
+ */
32
+ protected $_canAuthorize = false;
33
+
34
+ /**
35
+ * Can capture funds online?
36
+ */
37
+ protected $_canCapture = false;
38
+
39
+ /**
40
+ * Can capture partial amounts online?
41
+ */
42
+ protected $_canCapturePartial = false;
43
+
44
+ /**
45
+ * Can refund online?
46
+ */
47
+ protected $_canRefund = false;
48
+
49
+ /**
50
+ * Can void transactions online?
51
+ */
52
+ protected $_canVoid = false;
53
+
54
+ /**
55
+ * Can use this payment method in administration panel?
56
+ */
57
+ protected $_canUseInternal = false;
58
+
59
+ /**
60
+ * Can show this payment method as an option on checkout payment page?
61
+ */
62
+ protected $_canUseCheckout = false;
63
+
64
+ /**
65
+ * Is this payment method suitable for multi-shipping checkout?
66
+ */
67
+ protected $_canUseForMultishipping = false;
68
+
69
+ /**
70
+ * Can save credit card information for future processing?
71
+ */
72
+ protected $_canSaveCc = false;
73
+
74
+ public function canUseForCountry($country) {
75
+ return 'US' === $country;
76
+ }
77
+
78
+ public function canUseForCurrency($currencyCode) {
79
+ return 'USD' === $currencyCode;
80
+ }
81
+ }
app/code/community/CosmicCart/Integration/Model/Product/Api/V2.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * NOTICE OF LICENSE
3
+ *
4
+ * This source file is subject to the Cosmic Cart license, a commercial license.
5
+ *
6
+ * @category CosmicCart
7
+ * @package Integration
8
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
9
+ * @license Proprietary
10
+ */
11
+
12
+ <?
13
+ class CosmicCart_Integration_Model_Product_Api_V2 extends Mage_Catalog_Model_Product_Api_V2
14
+ {
15
+
16
+ public function listPageable($filters = null, $store = null, $page = 0, $pageSize = 50)
17
+ {
18
+ $collection = Mage::getModel('catalog/product')->getCollection()
19
+ ->addStoreFilter($this->_getStoreId($store))
20
+ ->addFilter('type_id', 'simple') // We don't want groups or configurables
21
+ // ->addAttributeToSelect('name')
22
+ ->setPage($page, $pageSize);
23
+
24
+ /** @var $apiHelper Mage_Api_Helper_Data */
25
+ $apiHelper = Mage::helper('api');
26
+ $filters = $apiHelper->parseFilters($filters, $this->_filtersMap);
27
+ try {
28
+ foreach ($filters as $field => $value) {
29
+ $collection->addFieldToFilter($field, $value);
30
+ }
31
+ } catch (Mage_Core_Exception $e) {
32
+ $this->_fault('filters_invalid', $e->getMessage());
33
+ }
34
+ $result = array();
35
+ $catalogInventoryApi = Mage::getSingleton("Mage_CatalogInventory_Model_Stock_Item_Api_V2");
36
+ foreach ($collection as $product) {
37
+ $productId = $product->getId();
38
+ $data = $this->info($productId);
39
+ $data['manufacturer'] = $product->getAttributeText('manufacturer');
40
+ $inventoryData = $catalogInventoryApi->items($productId);
41
+ foreach ($inventoryData[0] as $key => $value) {
42
+ $data[$key] = $value;
43
+ }
44
+
45
+ /* Find parents, if any. */
46
+ $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($productId);
47
+ $parentCollection = Mage::getResourceModel('catalog/product_collection')
48
+ ->addFieldToFilter('entity_id', array('in' => $parentIds))
49
+ ->addAttributeToSelect('sku');
50
+ $parentSkus = $parentCollection->getColumnValues('sku');
51
+ foreach ($parentSkus as $parentSku) {
52
+ $data['parentSku'] = $parentSku;
53
+ break;
54
+ }
55
+
56
+ /* Find attributes */
57
+ foreach ($parentCollection as $parent) {
58
+ $data['attributes'] = array();
59
+ $eavProduct = Mage::getModel('catalog/product')->load($productId);
60
+ $configurableAttributes = $parent->getTypeInstance(true)->getConfigurableAttributesAsArray($parent);
61
+ foreach ($configurableAttributes as $attribute) {
62
+ $label = $attribute['frontend_label'];
63
+ $attributeCode = $attribute['attribute_code'];
64
+ $value = $eavProduct->getAttributeText($attributeCode);
65
+ $data['attributes'][] = array(
66
+ 'attribute' => $label,
67
+ 'value' => $value
68
+ );
69
+ }
70
+ break;
71
+ }
72
+
73
+ /* Images */
74
+ $mediaApi = Mage::getSingleton('Mage_Catalog_Model_Product_Attribute_Media_Api_V2');
75
+ $data['images'] = $mediaApi->items($productId, $store);
76
+
77
+ /* Add to result. */
78
+ $result[] = $data;
79
+ }
80
+ return $result;
81
+ }
82
+
83
+ }
app/code/community/CosmicCart/Integration/Model/Resource/AccessToken.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+ /**
14
+ * Created by IntelliJ IDEA.
15
+ * User: mcsenter
16
+ * Date: 9/11/13
17
+ * Time: 1:42 PM
18
+ * To change this template use File | Settings | File Templates.
19
+ */
20
+ class CosmicCart_Integration_Model_Resource_AccessToken extends Mage_Core_Model_Resource_Db_Abstract
21
+ {
22
+ /**
23
+ * Event prefix
24
+ *
25
+ * @var string
26
+ */
27
+ protected $_eventPrefix = 'cosmiccart_accessToken';
28
+ /**
29
+ * Event object
30
+ *
31
+ * @var string
32
+ */
33
+ protected $_eventObject = 'resource';
34
+ /**
35
+ * Is grid
36
+ *
37
+ * @var boolean
38
+ */
39
+ protected $_grid = false;
40
+ /**
41
+ * Use increment id
42
+ *
43
+ * @var boolean
44
+ */
45
+ protected $_useIncrementId = false;
46
+ /**
47
+ * Primery key auto increment flag
48
+ *
49
+ * @var bool
50
+ */
51
+ protected $_isPkAutoIncrement = false;
52
+
53
+ public function _construct()
54
+ {
55
+ $this->_init('cosmiccart_integration/accessToken', 'access_token');
56
+ }
57
+ }
app/code/community/CosmicCart/Integration/Model/Resource/AccessToken/Collection.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+
14
+ class CosmicCart_Integration_Model_Resource_AccessToken_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
15
+ {
16
+ public function _construct()
17
+ {
18
+ $this->_init('cosmiccart_integration/accessToken');
19
+ }
20
+ }
app/code/community/CosmicCart/Integration/Model/Resource/Client.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+ /**
14
+ * Created by IntelliJ IDEA.
15
+ * User: mcsenter
16
+ * Date: 3/19/14
17
+ * Time: 9:50 AM
18
+ * To change this template use File | Settings | File Templates.
19
+ */
20
+ class CosmicCart_Integration_Model_Resource_Client extends Mage_Core_Model_Resource_Db_Abstract
21
+ {
22
+ /**
23
+ * Event prefix
24
+ *
25
+ * @var string
26
+ */
27
+ protected $_eventPrefix = 'cosmiccart_client';
28
+ /**
29
+ * Event object
30
+ *
31
+ * @var string
32
+ */
33
+ protected $_eventObject = 'resource';
34
+ /**
35
+ * Is grid
36
+ *
37
+ * @var boolean
38
+ */
39
+ protected $_grid = false;
40
+ /**
41
+ * Use increment id
42
+ *
43
+ * @var boolean
44
+ */
45
+ protected $_useIncrementId = false;
46
+ /**
47
+ * Primery key auto increment flag
48
+ *
49
+ * @var bool
50
+ */
51
+ protected $_isPkAutoIncrement = false;
52
+
53
+ public function _construct()
54
+ {
55
+ $this->_init('cosmiccart_integration/client', 'client_id');
56
+ }
57
+ }
app/code/community/CosmicCart/Integration/Model/Resource/Client/Collection.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+
14
+ class CosmicCart_Integration_Model_Resource_Client_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
15
+ {
16
+ public function _construct()
17
+ {
18
+ $this->_init('cosmiccart_integration/client');
19
+ }
20
+ }
app/code/community/CosmicCart/Integration/Model/Resource/Setup.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+
14
+ class CosmicCart_Integration_Model_Resource_Setup extends Mage_Sales_Model_Resource_Setup
15
+ {
16
+ }
app/code/community/CosmicCart/Integration/Model/Shipment/Observer.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+ require_once('CosmicCart/Integration/OAuth2Client.php');
14
+ /**
15
+ * Created by IntelliJ IDEA.
16
+ * User: mcsenter
17
+ * Date: 9/30/13
18
+ * Time: 10:50 AM
19
+ * To change this template use File | Settings | File Templates.
20
+ */
21
+ class CosmicCart_Integration_Model_Shipment_Observer
22
+ {
23
+ public function onSalesOrderShipmentSaveAfter(Varien_Event_Observer $observer)
24
+ {
25
+ error_log("Shipment was saved!");
26
+ /* We are observing all shipments, but we are really interested in only those resulting from a Cosmic Cart purchase. */
27
+ $shipment = $observer->getEvent()->getShipment();
28
+ $order = $shipment->getOrder();
29
+ error_log("Getting orderId from order...");
30
+ $cosmicOrderId = $order->getCosmicCartOrderId();
31
+ error_log("Cosmic cart Order Id: $cosmicOrderId");
32
+ if (!empty($cosmicOrderId)) {
33
+ $payment = $order->getPayment();
34
+ if (!empty($payment)) {
35
+ /* We must have a Payment and that Payment must have been with our custom "cosmiccart" method */
36
+ $method = $payment->getMethod();
37
+ error_log("payment method: $method");
38
+ if ('cosmiccart' == $method) {
39
+ $package = $this->shipmentToPackage($shipment);
40
+ $client = new OAuth2Client();
41
+ error_log("shipandsettle()");
42
+ $package = $client->shipAndSettle($package);
43
+ }
44
+ }
45
+ }
46
+
47
+ return $this;
48
+ }
49
+
50
+ private function shipmentToPackage(Mage_Sales_Model_Order_Shipment $shipment)
51
+ {
52
+ $dateTime = DateTime::createFromFormat('Y-m-d H:i:s', $shipment->getCreatedAt());
53
+ ob_start();
54
+ var_dump(DateTime::getLastErrors());
55
+ $contents = ob_get_contents();
56
+ ob_end_clean();
57
+ error_log($contents);
58
+ $package = array(
59
+ 'subOrder' => array('id' => (int) $shipment->getOrder()->getCosmicCartOrderId()),
60
+ 'packageItems' => array(),
61
+ 'shipDate' => $dateTime->format('c'),
62
+ 'trackings' => array()
63
+ );
64
+ foreach ($shipment->getTracksCollection() as $track) {
65
+ $package['trackings'][] = $track->getNumber();
66
+ }
67
+ foreach ($shipment->getItemsCollection() as $item) {
68
+ $orderItem = Mage::getModel('sales/order_item')->load($item->getOrderItemId());
69
+ for ($i = 0; $i < $item->getQty(); ++$i) {
70
+ $packageItem = array(
71
+ 'orderItem' => array('id' => (int) $orderItem->getCosmicCartOrderItemId()),
72
+ 'number' => $i
73
+ );
74
+ $package['packageItems'][] = $packageItem;
75
+ }
76
+ }
77
+ return $package;
78
+ }
79
+ }
app/code/community/CosmicCart/Integration/OAuth2Client.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+ /**
14
+ * Created by IntelliJ IDEA.
15
+ * User: mcsenter
16
+ * Date: 9/11/13
17
+ * Time: 10:39 AM
18
+ * To change this template use File | Settings | File Templates.
19
+ */
20
+ class OAuth2Client
21
+ {
22
+ public $baseApiUrl = '';
23
+ public $client_id = '';
24
+ public $client_secret = '';
25
+ public $grant_type = 'password';
26
+ public $accessTokenUri = 'oauth/token';
27
+
28
+ public function OAuth2Client($client_id = null, $client_secret = null)
29
+ {
30
+ $settings = parse_ini_file('app/code/community/CosmicCart/Integration/etc/cosmiccart.ini');
31
+ $this->baseApiUrl = $settings['base_api_url'];
32
+ if (empty($client_id)) {
33
+ $client = $this->loadClient();
34
+ $client_id = $client->getClientId();
35
+ $client_secret = $client->getClientSecret();
36
+ }
37
+ $this->client_id = $client_id;
38
+ $this->client_secret = $client_secret;
39
+ }
40
+
41
+ public function getAccessToken($username, $password)
42
+ {
43
+ $params = array(
44
+ 'username' => $username,
45
+ 'password' => $password,
46
+ 'grant_type' => $this->grant_type
47
+ );
48
+ $accessTokenResponse = $this->get($this->accessTokenUri, $params, $this->createAuthHeader());
49
+ return $this->storeAccessTokenFromResponse($accessTokenResponse);
50
+ }
51
+
52
+ public function get($api, $params, $header = null)
53
+ {
54
+ $url = $this->getApiUrl($api, $params);
55
+ error_log("GET URL: $url");
56
+ $ch = curl_init($url);
57
+ curl_setopt_array($ch, array(
58
+ CURLOPT_RETURNTRANSFER => 1,
59
+ CURLOPT_HTTPHEADER => array($header)
60
+ ));
61
+ $response = curl_exec($ch);
62
+ curl_close($ch);
63
+ return json_decode($response);
64
+ }
65
+
66
+ protected function getApiUrl($api, $params = null)
67
+ {
68
+ if (strncmp($api, '/', 1)) {
69
+ $api = '/' . $api;
70
+ }
71
+ $api = $this->baseApiUrl . $api;
72
+ if (!empty($params)) {
73
+ $api .= '?' . http_build_query($params);
74
+ }
75
+ return $api;
76
+ }
77
+
78
+ protected function createAuthHeader()
79
+ {
80
+ return 'Authorization: Basic ' . base64_encode($this->client_id . ':' . $this->client_secret);
81
+ }
82
+
83
+ private function storeAccessTokenFromResponse($accessTokenResponse)
84
+ {
85
+ if (empty($accessTokenResponse)) {
86
+ throw new Exception('Could not connect to Cosmic Cart.');
87
+ }
88
+ if (!empty($accessTokenResponse->error)) {
89
+ throw new Exception($accessTokenResponse->error_description);
90
+ }
91
+
92
+ /* Let's remove our existing token. Should be only one at any given time. */
93
+ Mage::getModel('cosmiccart_integration/accessToken')->deleteExisting();
94
+
95
+ $accessToken = Mage::getModel('cosmiccart_integration/accessToken');
96
+ $accessToken->setAccessToken($accessTokenResponse->access_token);
97
+ $accessToken->setRefreshToken($accessTokenResponse->refresh_token);
98
+ $accessToken->setTokenType($accessTokenResponse->token_type);
99
+ $accessToken->setScope($accessTokenResponse->scope);
100
+ $expires_in = $accessTokenResponse->expires_in;
101
+ $now = time();
102
+ $expires = $now + $expires_in;
103
+ $accessToken->setExpires($expires);
104
+
105
+ $accessToken->save();
106
+
107
+ return $accessToken;
108
+ }
109
+
110
+ public function shipAndSettle($package)
111
+ {
112
+ return $this->post('subOrder/package', $package);
113
+ }
114
+
115
+ private function post($api, $params, $accessToken = null)
116
+ {
117
+ $response = null;
118
+ if (empty($accessToken)) {
119
+ $accessToken = $this->loadAccessToken();
120
+ }
121
+ if (!empty($accessToken)) {
122
+ error_log('Posting to: ' . $this->getApiUrl($api));
123
+ $ch = curl_init($this->getApiUrl($api));
124
+ $params = json_encode($params);
125
+ error_log($params);
126
+ $headers = array(
127
+ 'Content-Type: application/json',
128
+ 'Content-Length: ' . strlen($params)
129
+ );
130
+ $headers[] = $this->createAccessTokenHeader($accessToken);
131
+ curl_setopt_array($ch, array(
132
+ CURLOPT_POST => 1,
133
+ CURLOPT_SSL_VERIFYPEER => false, // TODO Do not use this option in production!
134
+ CURLOPT_POSTFIELDS => $params,
135
+ CURLOPT_RETURNTRANSFER => true,
136
+ CURLOPT_HTTPHEADER => $headers
137
+ ));
138
+ $response = curl_exec($ch);
139
+ curl_close($ch);
140
+ error_log($response);
141
+ if (empty($response)) {
142
+ throw new Exception('Could not communicate with Cosmic Cart.');
143
+ } else {
144
+ $response = json_decode($response);
145
+ if (!empty($response->error)) {
146
+ throw new Exception($response->error_description);
147
+ }
148
+ }
149
+ } else {
150
+ throw new Exception("Unable to load Cosmic Cart API access token.");
151
+ }
152
+ return $response;
153
+ }
154
+
155
+ public function saveClient() {
156
+ // First delete any old ones.
157
+ Mage::getModel('cosmiccart_integration/client')->deleteExisting();
158
+ $client = Mage::getModel('cosmiccart_integration/client');
159
+ $client->setClientId($this->client_id);
160
+ $client->setClientSecret($this->client_secret);
161
+ $client->save();
162
+ }
163
+
164
+ private function loadClient() {
165
+ return Mage::getModel('cosmiccart_integration/client')->findExisting();
166
+ }
167
+
168
+ private function loadAccessToken()
169
+ {
170
+ error_log("Need to load accessToken...");
171
+ $accessToken = null;
172
+ $accessTokens = Mage::getModel('cosmiccart_integration/accessToken')->getCollection();
173
+ foreach ($accessTokens as $token) {
174
+ $accessToken = $token;
175
+ break;
176
+ }
177
+ if (!empty($accessToken)) {
178
+ error_log("Found access token in database: $accessToken");
179
+ $now = time();
180
+ $expires = $accessToken->getExpires();
181
+ if ($now >= $expires) {
182
+ /* Our access token has expired. Refresh it! */
183
+ $params = array(
184
+ 'refresh_token' => $accessToken->getRefreshToken(),
185
+ 'grant_type' => 'refresh_token'
186
+ );
187
+ $accessTokenResponse = $this->get($this->accessTokenUri, $params, $this->createAuthHeader());
188
+ $accessToken = $this->storeAccessTokenFromResponse($accessTokenResponse);
189
+ }
190
+ }
191
+ if (empty($accessToken)) {
192
+ throw new Exception("No access token found. Has the module been activated?");
193
+ }
194
+ return $accessToken;
195
+ }
196
+
197
+ protected function createAccessTokenHeader($accessToken)
198
+ {
199
+ $header = 'Authorization: Bearer ' . $accessToken->getAccessToken();
200
+ error_log("added auth header: $header");
201
+ return $header;
202
+ }
203
+
204
+ public function registerStores($stores, $accessToken)
205
+ {
206
+ return $this->post('seller/store', $stores, $accessToken);
207
+ }
208
+
209
+ public function debugJson($data)
210
+ {
211
+ echo "<pre>";
212
+ print_r($data);
213
+ echo "</pre>";
214
+
215
+ # Redirect where ever you need **************************************************************
216
+ #$c_session = $this->provider."_profile";
217
+ #$_SESSION[$this->provider] = "true";
218
+ #$_SESSION[$c_session] = $data;
219
+
220
+ #echo("<script> top.location.href='index.php#".$this->provider."'</script>");
221
+
222
+ }
223
+ }
app/code/community/CosmicCart/Integration/controllers/Adminhtml/ActivationController.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+ require_once('CosmicCart/Integration/OAuth2Client.php');
14
+
15
+ class CosmicCart_Integration_Adminhtml_ActivationController extends Mage_Adminhtml_Controller_Action
16
+ {
17
+ // default action
18
+ public function indexAction()
19
+ {
20
+ $this->loadLayout();
21
+ $this->_setActiveMenu('cosmiccart');
22
+ $block = $this->getLayout()->getBlock('activation');
23
+ $block->setData('activated', Mage::getModel('cosmiccart_integration/accessToken')->exists());
24
+ $this->renderLayout();
25
+ }
26
+
27
+ public function postAction()
28
+ {
29
+ $post = $this->getRequest()->getPost();
30
+ try {
31
+ if (empty($post)) {
32
+ Mage::throwException($this->__('Invalid form data.'));
33
+ }
34
+
35
+ /* Configure our client. */
36
+ $client = new OAuth2Client($post['clientId'], $post['clientSecret']);
37
+
38
+ /* Request an access token */
39
+ $accessToken = $client->getAccessToken($post['username'], $post['password']);
40
+
41
+ /* Register our stores with Cosmic Cart. */
42
+ $stores = array();
43
+ foreach (Mage::getModel('core/store')->getCollection() as $store) {
44
+ $stores[] = array(
45
+ 'remoteId' => $store->getId(),
46
+ 'locale' => $store->getConfig('general/locale/code'),
47
+ 'active' => ($store->getIsActive() == 1)
48
+ );
49
+ }
50
+ $registerStoresResponse = $client->registerStores($stores, $accessToken);
51
+ if (empty($registerStoresResponse)) {
52
+ throw new Exception('Could not connect to Cosmic Cart to register store(s).');
53
+ }
54
+ $apiUsername = $registerStoresResponse->apiUsername;
55
+ $apiKey = $registerStoresResponse->apiKey;
56
+
57
+ /* Find or create a CosmicCartIntegration API Role and User */
58
+ $role = Mage::getModel('api/roles')->getCollection()
59
+ ->addFieldToFilter('role_name', 'CosmicCartIntegration')
60
+ ->addFieldToFilter('role_type', 'G')
61
+ ->getFirstItem();
62
+ if (!$role->getId()) {
63
+ /* Create our API Role */
64
+ error_log("Creating role...");
65
+ $role = Mage::getModel('api/roles')
66
+ ->setName('CosmicCartIntegration')
67
+ ->setPid(false)
68
+ ->setRoleType('G')
69
+ ->save();
70
+ /* Add permission to our API Role. */
71
+ error_log("Adding permissions to role: " . $role->getId());
72
+ Mage::getModel('api/rules')
73
+ ->setRoleId($role->getId())
74
+ ->setResources(array('all'))
75
+ ->saveRel();
76
+ }
77
+ $user = Mage::getModel('api/user')->getCollection()
78
+ ->addFieldToFilter('email', 'integration@cosmiccart.com')
79
+ ->getFirstItem();
80
+ if ($user->getId()) {
81
+ /* Remove the old user. */
82
+ error_log("Deleting previous user");
83
+ $user->delete();
84
+ }
85
+ /* Create our API User. */
86
+ error_log("Creating user...");
87
+ $user = Mage::getModel('api/user')
88
+ ->setData(array(
89
+ 'username' => $apiUsername,
90
+ 'firstname' => 'Cosmic',
91
+ 'lastname' => 'Cart',
92
+ 'email' => 'integration@cosmiccart.com',
93
+ 'api_key' => $apiKey,
94
+ 'api_key_confirmation' => $apiKey,
95
+ 'is_active' => 1,
96
+ 'user_roles' => '',
97
+ 'assigned_user_role' => '',
98
+ 'role_name' => '',
99
+ 'roles' => array($role->getId())
100
+ ));
101
+ $user->save()->load($user->getId());
102
+ /* Assign our API Role to our API User. */
103
+ error_log("Adding our role to our user " . $user->getId());
104
+ $user->setRoleIds(array($role->getId()))
105
+ ->setRoleUserId($user->getId())
106
+ ->saveRelations();
107
+
108
+ $client->saveClient();
109
+
110
+ $message = $this->__('activation.success');
111
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
112
+ } catch (Exception $e) {
113
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
114
+ }
115
+ $this->_redirect('*/*');
116
+ }
117
+
118
+ }
app/code/community/CosmicCart/Integration/etc/api.xml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <sales_order translate="title" module="sales">
6
+ <title>Create Order API</title>
7
+ <model>CosmicCart_Integration_Model_Order_Api</model>
8
+ <acl>sales/order</acl>
9
+ <methods>
10
+ <create translate="title" module="sales">
11
+ <title>Create Order</title>
12
+ <acl>sales/order/create</acl>
13
+ </create>
14
+ <getShippingMethodsList translate="title" module="sales">
15
+ <title>Get Shipping Methods List</title>
16
+ <acl>sales/order/getShippingMethodsList</acl>
17
+ </getShippingMethodsList>
18
+ <getSalesTax translate="title" module="sales">
19
+ <title>Get Sales Tax</title>
20
+ <acl>sales/order/getSalesTax</acl>
21
+ </getSalesTax>>
22
+ <getShippingCost translate="title" module="sales">
23
+ <title>Get Shipping Cost</title>
24
+ <acl>sales/order/getShippingCost</acl>
25
+ </getShippingCost>>
26
+ </methods>
27
+ </sales_order>
28
+ <catalog_product translate="title" module="catalog">
29
+ <title>Catalog Product API</title>
30
+ <model>CosmicCart_Integration_Model_Product_Api</model>
31
+ <acl>catalog/product</acl>
32
+ <methods>
33
+ <listPageable translate="title" module="catalog">
34
+ <title>Retrieve pageable product list by features</title>
35
+ <acl>catalog/product/info</acl>
36
+ </listPageable>
37
+ </methods>
38
+ </catalog_product>
39
+ </resources>
40
+ </api>
41
+ </config>
app/code/community/CosmicCart/Integration/etc/config.xml ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+
4
+ <!-- ecomdev phpunit config -->
5
+ <phpunit>
6
+ <suite>
7
+ <modules>
8
+ <CosmicCart_Integration/>
9
+ </modules>
10
+ </suite>
11
+ </phpunit>
12
+
13
+ <!-- define the module, version and dependencies -->
14
+ <modules>
15
+ <CosmicCart_Integration>
16
+ <version>1.0.0</version>
17
+ </CosmicCart_Integration>
18
+ </modules>
19
+
20
+ <global>
21
+ <!-- model configuration -->
22
+ <models>
23
+ <sales>
24
+ <rewrite>
25
+ <order_api_v2>CosmicCart_Integration_Model_Order_Api_V2</order_api_v2>
26
+ </rewrite>
27
+ </sales>
28
+ <catalog>
29
+ <rewrite>
30
+ <product_api_v2>CosmicCart_Integration_Model_Product_Api_V2</product_api_v2>
31
+ </rewrite>
32
+ </catalog>
33
+ <cosmiccart_integration>
34
+ <class>CosmicCart_Integration_Model</class>
35
+ <resourceModel>cosmiccart_integration_resource</resourceModel>
36
+ </cosmiccart_integration>
37
+ <cosmiccart_integration_resource>
38
+ <class>CosmicCart_Integration_Model_Resource</class>
39
+ <entities>
40
+ <accessToken>
41
+ <table>cosmiccart_integration_access_token</table>
42
+ </accessToken>
43
+ <client>
44
+ <table>cosmiccart_integration_client</table>
45
+ </client>
46
+ </entities>
47
+ </cosmiccart_integration_resource>
48
+ <events>
49
+ </events>
50
+ </models>
51
+
52
+ <!-- resource model configuration -->
53
+ <resources>
54
+ <cosmiccart_integration_setup>
55
+ <setup>
56
+ <module>CosmicCart_Integration</module>
57
+ <class>CosmicCart_Integration_Model_Resource_Setup</class>
58
+ </setup>
59
+ <connection>
60
+ <use>core_setup</use>
61
+ </connection>
62
+ </cosmiccart_integration_setup>
63
+ <integration_write>
64
+ <connection>
65
+ <use>core_write</use>
66
+ </connection>
67
+ </integration_write>
68
+ <integration_read>
69
+ <connection>
70
+ <use>core_read</use>
71
+ </connection>
72
+ </integration_read>
73
+ </resources>
74
+
75
+ <!-- helper classes -->
76
+ <helpers>
77
+ <integration>
78
+ <class>CosmicCart_Integration_Helper</class>
79
+ </integration>
80
+ </helpers>
81
+
82
+ <!-- events -->
83
+ <events>
84
+ <sales_order_shipment_save_after>
85
+ <observers>
86
+ <cosmiccart_integration_shipment_observer>
87
+ <type>singleton</type>
88
+ <class>CosmicCart_Integration_Model_Shipment_Observer</class>
89
+ <method>onSalesOrderShipmentSaveAfter</method>
90
+ </cosmiccart_integration_shipment_observer>
91
+ </observers>
92
+ </sales_order_shipment_save_after>
93
+ </events>
94
+
95
+ </global>
96
+
97
+ <!-- backend routing -->
98
+ <admin>
99
+ <routers>
100
+ <integration>
101
+ <use>admin</use>
102
+ <args>
103
+ <module>CosmicCart_Integration</module>
104
+ <frontName>cosmiccart</frontName>
105
+ </args>
106
+ </integration>>
107
+ </routers>
108
+ </admin>
109
+
110
+ <adminhtml>
111
+ <acl>
112
+ <resources>
113
+ <admin>
114
+ <children>
115
+ <integration translate="title" module="integration">
116
+ <children>
117
+ <integration_activation>
118
+ <title>Activation</title>
119
+ </integration_activation>
120
+ </children>
121
+ <sort_order>1</sort_order>
122
+ </integration>
123
+ </children>
124
+ </admin>
125
+ </resources>
126
+ </acl>
127
+ <!-- backend menu entries -->
128
+ <menu>
129
+ <cosmiccart module="integration">
130
+ <title>Cosmic Cart</title>
131
+ <sort_order>100</sort_order>
132
+ <children>
133
+ <integration_activation module="integration">
134
+ <title>Activation</title>
135
+ <sort_order>1</sort_order>
136
+ <action>integration/adminhtml_activation</action>
137
+ </integration_activation>
138
+ </children>
139
+ </cosmiccart>
140
+ </menu>
141
+ <!-- locale files -->
142
+ <translate>
143
+ <modules>
144
+ <integration>
145
+ <files>
146
+ <default>CosmicCart_Integration.csv</default>
147
+ </files>
148
+ </integration>
149
+ </modules>
150
+ </translate>
151
+ <!-- layout files -->
152
+ <layout>
153
+ <updates>
154
+ <integration>
155
+ <file>cosmiccart/integration.xml</file>
156
+ </integration>
157
+ </updates>
158
+ </layout>
159
+ </adminhtml>
160
+ <!-- crontab configuration -->
161
+ <!-- <crontab> <jobs> <integration> <schedule><cron_expr>*/15
162
+ * * * *</cron_expr></schedule> <run><model>cosmiccart_integration/accessToken::cronMethod</model></run>
163
+ </integration> </jobs> </crontab> -->
164
+
165
+ <default>
166
+ <payment>
167
+ <cosmiccart>
168
+ <model>CosmicCart_Integration_Model_Pay</model>
169
+ <active>1</active>
170
+ <order_status>Processing</order_status>
171
+ <title>Cosmic Cart</title>
172
+ <payment_action>sale</payment_action>
173
+ </cosmiccart>
174
+ </payment>
175
+ </default>
176
+ </config>
app/code/community/CosmicCart/Integration/etc/cosmiccart.ini ADDED
@@ -0,0 +1 @@
 
1
+ base_api_url=https://cosmiccart.com/api
app/code/community/CosmicCart/Integration/etc/system.xml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <cosmiccart translate="label" module="integration">
7
+ <label>Cosmic Cart Payment</label>
8
+ <sort_order>670</sort_order>
9
+ <show_in_default>0</show_in_default>
10
+ <show_in_website>0</show_in_website>
11
+ <show_in_store>0</show_in_store>
12
+ </cosmiccart>
13
+ </groups>
14
+ </payment>
15
+ </sections>
16
+ </config>
app/code/community/CosmicCart/Integration/etc/wsdl.xml ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/" name="{{var wsdl.name}}"
4
+ targetNamespace="urn:{{var wsdl.name}}">
5
+ <types>
6
+ <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
7
+ <import namespace="http://schemas.xmlsoap.org/soap/encoding/"
8
+ schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
9
+ <complexType name="salesOrderEntityToCreate">
10
+ <all>
11
+ <element name="customer_id" type="xsd:int"/>
12
+ </all>
13
+ </complexType>
14
+ </schema>
15
+ </types>
16
+ <message name="salesOrderCreateRequest">
17
+ <part name="sessionId" type="xsd:string"/>
18
+ <part name="orderData" type="typens:salesOrderEntityToCreate"/>
19
+ </message>
20
+ <message name="salesOrderCreateResponse">
21
+ <part name="result" type="xsd:int"/>
22
+ </message>
23
+ <portType name="{{var wsdl.handler}}PortType">
24
+ <operation name="salesOrderCreate">
25
+ <documentation>Create sales order</documentation>
26
+ <input message="typens:salesOrderCreateRequest"/>
27
+ <output message="typens:salesOrderCreateResponse"/>
28
+ </operation>
29
+ </portType>
30
+ <binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
31
+ <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
32
+ <operation name="salesOrderCreate">
33
+ <soap:operation soapAction="urn:{{var wsdl.handler}}Action"/>
34
+ <input>
35
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
36
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
37
+ </input>
38
+ <output>
39
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
40
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
41
+ </output>
42
+ </operation>
43
+ </binding>
44
+ </definitions>
app/code/community/CosmicCart/Integration/etc/wsi.xml ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <wsdl:definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
4
+ name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
5
+ <wsdl:types>
6
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:{{var wsdl.name}}">
7
+ <xsd:complexType name="salesOrderEntityToCreate">
8
+ <xsd:sequence>
9
+ <xsd:element name="orderId" type="xsd:string" minOccurs="1"></xsd:element>
10
+ <xsd:element name="customer" type="typens:shoppingCartCustomerEntity" minOccurs="1"></xsd:element>
11
+ <xsd:element name="customer_addresses" type="typens:shoppingCartCustomerAddressEntityArray"
12
+ minOccurs="1"></xsd:element>
13
+ <xsd:element name="items" type="typens:salesOrderCreateProductEntityArray"
14
+ minOccurs="1"></xsd:element>
15
+ </xsd:sequence>
16
+ </xsd:complexType>
17
+ <xsd:complexType name="salesOrderCreateProductEntityArray">
18
+ <xsd:sequence>
19
+ <xsd:element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray"
20
+ type="typens:salesOrderCreateProductEntity"/>
21
+ </xsd:sequence>
22
+ </xsd:complexType>
23
+ <xsd:complexType name="salesOrderCreateProductEntity">
24
+ <xsd:sequence>
25
+ <xsd:element name="orderItemId" type="xsd:string" minOccurs="1"/>
26
+ <xsd:element name="sku" type="xsd:string" minOccurs="1"/>
27
+ <xsd:element name="qty" type="xsd:double" minOccurs="1"/>
28
+ <xsd:element name="price" type="xsd:double" minOccurs="1"/>
29
+ <xsd:element name="shippingOption" type="xsd:string" minOccurs="1"/>
30
+ </xsd:sequence>
31
+ </xsd:complexType>
32
+ <xsd:element name="salesOrderCreateRequestParam">
33
+ <xsd:complexType>
34
+ <xsd:sequence>
35
+ <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string"/>
36
+ <xsd:element minOccurs="1" maxOccurs="1" name="orderData"
37
+ type="typens:salesOrderEntityToCreate"/>
38
+ </xsd:sequence>
39
+ </xsd:complexType>
40
+ </xsd:element>
41
+ <xsd:element name="salesOrderCreateResponseParam">
42
+ <xsd:complexType>
43
+ <xsd:sequence>
44
+ <xsd:element minOccurs="1" maxOccurs="1" name="result"
45
+ type="typens:salesOrderCreateResponseStatus"/>
46
+ </xsd:sequence>
47
+ </xsd:complexType>
48
+ </xsd:element>
49
+ <xsd:complexType name="salesOrderCreateResponseStatus">
50
+ <xsd:sequence>
51
+ <xsd:element minOccurs="1" maxOccurs="1" name="orderId" type="xsd:int"/>
52
+ <xsd:element name="items" type="typens:salesOrderCreateResponseProductArray"
53
+ minOccurs="1"></xsd:element>
54
+ </xsd:sequence>
55
+ </xsd:complexType>
56
+ <xsd:complexType name="salesOrderCreateResponseProductArray">
57
+ <xsd:sequence>
58
+ <xsd:element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray"
59
+ type="typens:salesOrderCreateResponseProduct"/>
60
+ </xsd:sequence>
61
+ </xsd:complexType>
62
+ <xsd:complexType name="salesOrderCreateResponseProduct">
63
+ <xsd:sequence>
64
+ <xsd:element name="sku" type="xsd:string" minOccurs="1"/>
65
+ <xsd:element name="qtyRequested" type="xsd:double" minOccurs="1"/>
66
+ <xsd:element name="qtyAllocated" type="xsd:double" minOccurs="1"/>
67
+ <xsd:element name="qtyBackordered" type="xsd:double" minOccurs="1"/>
68
+ <xsd:element name="qtyFailed" type="xsd:double" minOccurs="1"/>
69
+ <xsd:element name="tax" type="xsd:double" minOccurs="1"/>
70
+ </xsd:sequence>
71
+ </xsd:complexType>
72
+ <!--
73
+ The existing Magento endpoint for fetching shipping methods and rates is based on an existing cart,
74
+ but we aren't doing cart sync (yet,) so we need a custom endpoint that allows us to do the same
75
+ operation based on address.
76
+ -->
77
+ <xsd:element name="salesOrderGetShippingMethodsListRequestParam">
78
+ <xsd:complexType>
79
+ <xsd:sequence>
80
+ <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string"/>
81
+ <xsd:element minOccurs="1" maxOccurs="1" name="addressData"
82
+ type="typens:shoppingCartAddressEntity"/>
83
+ <xsd:element minOccurs="1" name="orderItemsData"
84
+ type="typens:salesOrderCreateProductEntityArray"/>
85
+ </xsd:sequence>
86
+ </xsd:complexType>
87
+ </xsd:element>
88
+ <!--
89
+ Custom request/response for fetching sales tax.
90
+ -->
91
+ <xsd:element name="salesOrderGetSalesTaxRequestParam">
92
+ <xsd:complexType>
93
+ <xsd:sequence>
94
+ <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string"/>
95
+ <xsd:element minOccurs="1" maxOccurs="1" name="addressData"
96
+ type="typens:shoppingCartAddressEntity"/>
97
+ <xsd:element minOccurs="1" name="orderItemsData"
98
+ type="typens:salesOrderCreateProductEntityArray"/>
99
+ </xsd:sequence>
100
+ </xsd:complexType>
101
+ </xsd:element>
102
+ <xsd:element name="salesOrderGetSalesTaxResponseParam">
103
+ <xsd:complexType>
104
+ <xsd:sequence>
105
+ <xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:float"/>
106
+ </xsd:sequence>
107
+ </xsd:complexType>
108
+ </xsd:element>
109
+ <!--
110
+ Custom request/response for fetching shipping cost.
111
+ -->
112
+ <xsd:element name="salesOrderGetShippingCostRequestParam">
113
+ <xsd:complexType>
114
+ <xsd:sequence>
115
+ <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string"/>
116
+ <xsd:element minOccurs="1" maxOccurs="1" name="addressData"
117
+ type="typens:shoppingCartAddressEntity"/>
118
+ <xsd:element minOccurs="1" name="orderItemsData"
119
+ type="typens:salesOrderCreateProductEntityArray"/>
120
+ </xsd:sequence>
121
+ </xsd:complexType>
122
+ </xsd:element>
123
+ <xsd:element name="salesOrderGetShippingCostResponseParam">
124
+ <xsd:complexType>
125
+ <xsd:sequence>
126
+ <xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:float"/>
127
+ </xsd:sequence>
128
+ </xsd:complexType>
129
+ </xsd:element>
130
+ <!--
131
+ Catalog Products
132
+ -->
133
+ <xsd:element name="catalogProductListPageableRequestParam">
134
+ <xsd:complexType>
135
+ <xsd:sequence>
136
+ <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string"/>
137
+ <xsd:element minOccurs="1" maxOccurs="1" name="filters" type="typens:filters"/>
138
+ <xsd:element minOccurs="0" maxOccurs="1" name="store" type="xsd:string"/>
139
+ <xsd:element minOccurs="0" maxOccurs="1" name="page" type="xsd:int"/>
140
+ <xsd:element minOccurs="0" maxOccurs="1" name="pageSize" type="xsd:int"/>
141
+ </xsd:sequence>
142
+ </xsd:complexType>
143
+ </xsd:element>
144
+ <xsd:element name="catalogProductListPageableResponseParam">
145
+ <xsd:complexType>
146
+ <xsd:sequence>
147
+ <xsd:element minOccurs="1" maxOccurs="1" name="result"
148
+ type="typens:catalogProductInventoryReturnEntityArray"/>
149
+ </xsd:sequence>
150
+ </xsd:complexType>
151
+ </xsd:element>
152
+ <xsd:complexType name="catalogProductInventoryReturnEntityArray">
153
+ <xsd:sequence>
154
+ <xsd:element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray"
155
+ type="typens:catalogProductInventoryReturnEntity"/>
156
+ </xsd:sequence>
157
+ </xsd:complexType>
158
+ <xsd:complexType name="catalogProductInventoryReturnEntity">
159
+ <xsd:sequence>
160
+ <xsd:element name="product_id" type="xsd:string" minOccurs="0"/>
161
+ <xsd:element name="sku" type="xsd:string" minOccurs="0"/>
162
+ <xsd:element name="set" type="xsd:string" minOccurs="0"/>
163
+ <xsd:element name="type" type="xsd:string" minOccurs="0"/>
164
+ <xsd:element name="categories" type="typens:ArrayOfString" minOccurs="0"/>
165
+ <xsd:element name="websites" type="typens:ArrayOfString" minOccurs="0"/>
166
+ <xsd:element name="created_at" type="xsd:string" minOccurs="0"/>
167
+ <xsd:element name="updated_at" type="xsd:string" minOccurs="0"/>
168
+ <xsd:element name="type_id" type="xsd:string" minOccurs="0"/>
169
+ <xsd:element name="name" type="xsd:string" minOccurs="0"/>
170
+ <xsd:element name="description" type="xsd:string" minOccurs="0"/>
171
+ <xsd:element name="short_description" type="xsd:string" minOccurs="0"/>
172
+ <xsd:element name="weight" type="xsd:string" minOccurs="0"/>
173
+ <xsd:element name="status" type="xsd:string" minOccurs="0"/>
174
+ <xsd:element name="url_key" type="xsd:string" minOccurs="0"/>
175
+ <xsd:element name="url_path" type="xsd:string" minOccurs="0"/>
176
+ <xsd:element name="visibility" type="xsd:string" minOccurs="0"/>
177
+ <xsd:element name="category_ids" type="typens:ArrayOfString" minOccurs="0"/>
178
+ <xsd:element name="website_ids" type="typens:ArrayOfString" minOccurs="0"/>
179
+ <xsd:element name="has_options" type="xsd:string" minOccurs="0"/>
180
+ <xsd:element name="gift_message_available" type="xsd:string" minOccurs="0"/>
181
+ <xsd:element name="price" type="xsd:string" minOccurs="0"/>
182
+ <xsd:element name="special_price" type="xsd:string" minOccurs="0"/>
183
+ <xsd:element name="special_from_date" type="xsd:string" minOccurs="0"/>
184
+ <xsd:element name="special_to_date" type="xsd:string" minOccurs="0"/>
185
+ <xsd:element name="tax_class_id" type="xsd:string" minOccurs="0"/>
186
+ <xsd:element name="tier_price" type="typens:catalogProductTierPriceEntityArray" minOccurs="0"/>
187
+ <xsd:element name="meta_title" type="xsd:string" minOccurs="0"/>
188
+ <xsd:element name="meta_keyword" type="xsd:string" minOccurs="0"/>
189
+ <xsd:element name="meta_description" type="xsd:string" minOccurs="0"/>
190
+ <xsd:element name="custom_design" type="xsd:string" minOccurs="0"/>
191
+ <xsd:element name="custom_layout_update" type="xsd:string" minOccurs="0"/>
192
+ <xsd:element name="options_container" type="xsd:string" minOccurs="0"/>
193
+ <xsd:element name="additional_attributes" type="typens:associativeArray" minOccurs="0"/>
194
+ <xsd:element name="qty" type="xsd:string" minOccurs="0"/>
195
+ <xsd:element name="is_in_stock" type="xsd:string" minOccurs="0"/>
196
+ <xsd:element name="manufacturer" type="xsd:string" minOccurs="0"/>
197
+ <xsd:element name="parentSku" type="xsd:string" minOccurs="0"/>
198
+ <xsd:element name="attributes" type="typens:catalogProductConfigurableAttributeArray" minOccurs="0"
199
+ maxOccurs="1"/>
200
+ <xsd:element name="images" type="typens:catalogProductImageEntityArray" minOccurs="0"
201
+ maxOccurs="1"/>
202
+ </xsd:sequence>
203
+ </xsd:complexType>
204
+ <xsd:complexType name="catalogProductConfigurableAttributeArray">
205
+ <xsd:sequence>
206
+ <xsd:element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray"
207
+ type="typens:catalogProductConfigurableAttribute"/>
208
+ </xsd:sequence>
209
+ </xsd:complexType>
210
+ <xsd:complexType name="catalogProductConfigurableAttribute">
211
+ <xsd:sequence>
212
+ <xsd:element name="attribute" type="xsd:string" minOccurs="1"/>
213
+ <xsd:element name="value" type="xsd:string" minOccurs="1"/>
214
+ </xsd:sequence>
215
+ </xsd:complexType>
216
+ <!-- Fix Magento Bugs -->
217
+ <xsd:element name="catalogProductAttributeRemoveRequestParam">
218
+ <xsd:complexType>
219
+ <xsd:sequence>
220
+ <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string"/>
221
+ <xsd:element minOccurs="1" maxOccurs="1" name="attribute" type="xsd:string"/>
222
+ </xsd:sequence>
223
+ </xsd:complexType>
224
+ </xsd:element>
225
+ <xsd:element name="catalogProductAttributeRemoveResponseParam">
226
+ <xsd:complexType>
227
+ <xsd:sequence>
228
+ <xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:boolean"/>
229
+ </xsd:sequence>
230
+ </xsd:complexType>
231
+ </xsd:element>
232
+ <!-- END Fix Magento Bugs -->
233
+ </xsd:schema>
234
+ </wsdl:types>
235
+ <wsdl:message name="salesOrderCreateRequest">
236
+ <wsdl:part name="parameters" element="typens:salesOrderCreateRequestParam"/>
237
+ </wsdl:message>
238
+ <wsdl:message name="salesOrderCreateResponse">
239
+ <wsdl:part name="parameters" element="typens:salesOrderCreateResponseParam"/>
240
+ </wsdl:message>
241
+ <wsdl:message name="salesOrderGetShippingMethodsListRequest">
242
+ <wsdl:part name="parameters" element="typens:salesOrderGetShippingMethodsListRequestParam"/>
243
+ </wsdl:message>
244
+ <wsdl:message name="salesOrderGetShippingMethodsListResponse">
245
+ <wsdl:part name="parameters" element="typens:shoppingCartShippingListResponseParam"/>
246
+ </wsdl:message>
247
+ <wsdl:message name="salesOrderGetSalesTaxRequest">
248
+ <wsdl:part name="parameters" element="typens:salesOrderGetSalesTaxRequestParam"/>
249
+ </wsdl:message>
250
+ <wsdl:message name="salesOrderGetSalesTaxResponse">
251
+ <wsdl:part name="parameters" element="typens:salesOrderGetSalesTaxResponseParam"/>
252
+ </wsdl:message>
253
+ <wsdl:message name="salesOrderGetShippingCostRequest">
254
+ <wsdl:part name="parameters" element="typens:salesOrderGetShippingCostRequestParam"/>
255
+ </wsdl:message>
256
+ <wsdl:message name="salesOrderGetShippingCostResponse">
257
+ <wsdl:part name="parameters" element="typens:salesOrderGetShippingCostResponseParam"/>
258
+ </wsdl:message>
259
+ <wsdl:message name="catalogProductListPageableRequest">
260
+ <wsdl:part name="parameters" element="typens:catalogProductListPageableRequestParam"/>
261
+ </wsdl:message>
262
+ <wsdl:message name="catalogProductListPageableResponse">
263
+ <wsdl:part name="parameters" element="typens:catalogProductListPageableResponseParam"/>
264
+ </wsdl:message>
265
+ <!--Fix Magento Bugs -->
266
+ <wsdl:message name="catalogProductAttributeRemoveRequest">
267
+ <wsdl:part name="parameters" element="typens:catalogProductAttributeRemoveRequestParam"/>
268
+ </wsdl:message>
269
+ <wsdl:message name="catalogProductAttributeRemoveResponse">
270
+ <wsdl:part name="parameters" element="typens:catalogProductAttributeRemoveResponseParam"/>
271
+ </wsdl:message>
272
+ <!-- END Fix Magento Bugs -->
273
+ <wsdl:portType name="{{var wsdl.handler}}PortType">
274
+ <wsdl:operation name="salesOrderCreate">
275
+ <wsdl:documentation>Create sales order</wsdl:documentation>
276
+ <wsdl:input message="typens:salesOrderCreateRequest"/>
277
+ <wsdl:output message="typens:salesOrderCreateResponse"/>
278
+ </wsdl:operation>
279
+ <wsdl:operation name="salesOrderGetShippingMethodsList">
280
+ <wsdl:documentation>Create sales order</wsdl:documentation>
281
+ <wsdl:input message="typens:salesOrderGetShippingMethodsListRequest"/>
282
+ <wsdl:output message="typens:salesOrderGetShippingMethodsListResponse"/>
283
+ </wsdl:operation>
284
+ <wsdl:operation name="salesOrderGetSalesTax">
285
+ <wsdl:documentation>Create sales order</wsdl:documentation>
286
+ <wsdl:input message="typens:salesOrderGetSalesTaxRequest"/>
287
+ <wsdl:output message="typens:salesOrderGetSalesTaxResponse"/>
288
+ </wsdl:operation>
289
+ <wsdl:operation name="salesOrderGetShippingCost">
290
+ <wsdl:documentation>Create sales order</wsdl:documentation>
291
+ <wsdl:input message="typens:salesOrderGetShippingCostRequest"/>
292
+ <wsdl:output message="typens:salesOrderGetShippingCostResponse"/>
293
+ </wsdl:operation>
294
+ <wsdl:operation name="catalogProductListPageable">
295
+ <wsdl:documentation>Retrive pageable products list by filters</wsdl:documentation>
296
+ <wsdl:input message="typens:catalogProductListPageableRequest"/>
297
+ <wsdl:output message="typens:catalogProductListPageableResponse"/>
298
+ </wsdl:operation>
299
+ </wsdl:portType>
300
+ <wsdl:binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
301
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
302
+ <wsdl:operation name="salesOrderCreate">
303
+ <soap:operation soapAction=""/>
304
+ <wsdl:input>
305
+ <soap:body use="literal"/>
306
+ </wsdl:input>
307
+ <wsdl:output>
308
+ <soap:body use="literal"/>
309
+ </wsdl:output>
310
+ </wsdl:operation>
311
+ <wsdl:operation name="salesOrderGetShippingMethodsList">
312
+ <soap:operation soapAction=""/>
313
+ <wsdl:input>
314
+ <soap:body use="literal"/>
315
+ </wsdl:input>
316
+ <wsdl:output>
317
+ <soap:body use="literal"/>
318
+ </wsdl:output>
319
+ </wsdl:operation>
320
+ <wsdl:operation name="salesOrderGetSalesTax">
321
+ <soap:operation soapAction=""/>
322
+ <wsdl:input>
323
+ <soap:body use="literal"/>
324
+ </wsdl:input>
325
+ <wsdl:output>
326
+ <soap:body use="literal"/>
327
+ </wsdl:output>
328
+ </wsdl:operation>
329
+ <wsdl:operation name="salesOrderGetShippingCost">
330
+ <soap:operation soapAction=""/>
331
+ <wsdl:input>
332
+ <soap:body use="literal"/>
333
+ </wsdl:input>
334
+ <wsdl:output>
335
+ <soap:body use="literal"/>
336
+ </wsdl:output>
337
+ </wsdl:operation>
338
+ <wsdl:operation name="catalogProductListPageable">
339
+ <soap:operation soapAction=""/>
340
+ <wsdl:input>
341
+ <soap:body use="literal"/>
342
+ </wsdl:input>
343
+ <wsdl:output>
344
+ <soap:body use="literal"/>
345
+ </wsdl:output>
346
+ </wsdl:operation>
347
+ <!-- Fix Magento Bugs -->
348
+ <wsdl:operation name="catalogProductAttributeRemove">
349
+ <soap:operation soapAction=""/>
350
+ <wsdl:input>
351
+ <soap:body use="literal"/>
352
+ </wsdl:input>
353
+ <wsdl:output>
354
+ <soap:body use="literal"/>
355
+ </wsdl:output>
356
+ </wsdl:operation>
357
+ <!-- END Fix Magento Bugs -->
358
+ </wsdl:binding>
359
+ </wsdl:definitions>
app/code/community/CosmicCart/Integration/sql/cosmiccart_integration_setup/install-1.0.0.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the Cosmic Cart license, a commercial license.
6
+ *
7
+ * @category CosmicCart
8
+ * @package Integration
9
+ * @copyright Copyright (c) 2014 Cosmic Cart, Inc.
10
+ * @license Proprietary
11
+ */
12
+
13
+ error_log("Install-0.0.1");
14
+ $installer = $this;
15
+ $installer->startSetup();
16
+ error_log("Adding cc order id attribute...");
17
+ $cosmicCartOrderIdAttr = array(
18
+ 'type' => 'varchar',
19
+ 'label' => "Cosmic Cart Id",
20
+ 'required' => false
21
+ );
22
+ $installer->addAttribute('quote', 'cosmic_cart_order_id', $cosmicCartOrderIdAttr);
23
+ $installer->addAttribute('order', 'cosmic_cart_order_id', $cosmicCartOrderIdAttr);
24
+
25
+ error_log("Adding cc order item id attribute...");
26
+ $installer->addAttribute('order_item', 'cosmic_cart_order_item_id', $cosmicCartOrderIdAttr);
27
+ $installer->addAttribute('quote_item', 'cosmic_cart_order_item_id', $cosmicCartOrderIdAttr);
28
+
29
+ error_log("Running install script db");
30
+ error_log("Creating access_token table...");
31
+ $table = $installer->getConnection()
32
+ ->newTable($installer->getTable('cosmiccart_integration_access_token'))
33
+ ->addColumn('access_token', Varien_Db_Ddl_Table::TYPE_CHAR, 36, array(
34
+ 'nullable' => false,
35
+ 'primary' => true
36
+ ))
37
+ ->addColumn('token_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, 32, array(
38
+ 'nullable' => false
39
+ ))
40
+ ->addColumn('refresh_token', Varien_Db_Ddl_Table::TYPE_CHAR, 36, array(
41
+ 'nullable' => false
42
+ ))
43
+ ->addColumn('expires', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
44
+ 'nullable' => false,
45
+ 'unsigned' => true
46
+ ))
47
+ ->addColumn('scope', Varien_Db_Ddl_Table::TYPE_VARCHAR, 32, array(
48
+ 'nullable' => false
49
+ ));
50
+ $installer->getConnection()->createTable($table);
51
+
52
+ error_log("Creating client table...");
53
+ $table = $installer->getConnection()
54
+ ->newTable($installer->getTable('cosmiccart_integration_client'))
55
+ ->addColumn('client_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 64, array(
56
+ 'nullable' => false,
57
+ 'primary' => true
58
+ ))
59
+ ->addColumn('client_secret', Varien_Db_Ddl_Table::TYPE_VARCHAR, 64, array(
60
+ 'nullable' => false
61
+ ));
62
+ $installer->getConnection()->createTable($table);
63
+
64
+ error_log("Cleaning cache...");
65
+ Mage::app()->cleanCache();
66
+
67
+ error_log("ENDING INSTALLATION!!");
68
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/cosmiccart/integration.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <layout>
2
+ <integration_adminhtml_activation_index>
3
+ <update handle="integration_activation_index"/>
4
+ <reference name="content">
5
+ <block type="adminhtml/template" name="activation" template="cosmiccart/activation.phtml">
6
+ </block>
7
+ </reference>
8
+ </integration_adminhtml_activation_index>
9
+ </layout>
app/design/adminhtml/default/default/template/cosmiccart/activation.phtml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0" class="grid-header">
3
+ <tr>
4
+ <td><h3><?=$this->__('activation.title')?></h3></td>
5
+ <td class="a-right">
6
+ <button onclick="editForm.submit()" class="scalable save" type="button"><span><?=$this->__('activation.submit')?></span></button>
7
+ </td>
8
+ </tr>
9
+ </table>
10
+ </div>
11
+ <div class="entry-edit">
12
+ <? if ($this->getData('activated')) { ?>
13
+ <div style="color:#009900;font-size:16px;margin-bottom:10px"><?=$this->__('activation.complete')?></div>
14
+ <? } ?>
15
+ <form id="edit_form" name="edit_form" method="post" action="<?=$this->getUrl('*/*/post')?>">
16
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
17
+ <h4 class="icon-head head-edit-form fieldset-legend"><?=$this->__('activation.api.title')?></h4>
18
+ <fieldset id="my-fieldset">
19
+ <table cellspacing="0" class="form-list">
20
+ <tr>
21
+ <td class="label"><?=$this->__('activation.api.client')?> <span class="required">*</span></td>
22
+ <td class="input-ele"><input type="text" class="input-text required-entry" name="clientId" /></td>
23
+ </tr>
24
+ <tr>
25
+ <td class="label"><?=$this->__('activation.api.secret')?> <span class="required">*</span></td>
26
+ <td class="input-ele"><input type="text" class="input-text required-entry" name="clientSecret" /></td>
27
+ </tr>
28
+ <tr>
29
+ <td class="label"><?=$this->__('activation.api.username')?> <span class="required">*</span></td>
30
+ <td class="input-ele"><input type="text" class="input-text required-entry" name="username" /></td>
31
+ </tr>
32
+ <tr>
33
+ <td class="label"><?=$this->__('activation.api.password')?> <span class="required">*</span></td>
34
+ <td class="input-ele"><input type="password" class="input-text required-entry" name="password" /></td>
35
+ </tr>
36
+ </table>
37
+ </fieldset>
38
+ </form>
39
+ </div>
40
+ <script type="text/javascript">
41
+ var editForm = new varienForm('edit_form');
42
+ </script>
app/etc/modules/CosmicCart_Integration.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <CosmicCart_Integration>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Payment />
9
+ <Mage_Sales />
10
+ <Mage_Catalog />
11
+ </depends>
12
+ </CosmicCart_Integration>
13
+ </modules>
14
+ </config>
app/locale/en_US/CosmicCart_Integration.csv ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ activation.title, "Activation"
2
+ activation.submit, "Activate"
3
+ activation.api.title, "Cosmic Cart API Credentials"
4
+ activation.api.client, "Client ID"
5
+ activation.api.secret, "Client Secret"
6
+ activation.api.username, "Username"
7
+ activation.api.password, "Password"
8
+ activation.success, "Your store has been successfully connected to Cosmic Cart."
9
+ activation.complete, "Activation complete. You need not use this form again unless you are experiencing authentication issues with Cosmic Cart."
10
+ Bad credentials, "Activation was not successful. Please check your credentials and try again."
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>CosmicCart</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://cosmiccart.com/license/apps">Cosmic Cart App License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Cosmic Cart instantly connects your store to any site on the web.</summary>
10
+ <description>Cosmic Cart is the universal shopping cart for the web. Users can buy your products directly out of photos found on any web site. This extension integrates your store with Cosmic Cart's network of publishers.</description>
11
+ <notes>Initial release.</notes>
12
+ <authors><author><name>Cosmic Cart, Inc.</name><user>cosmiccart</user><email>apps@cosmiccart.com</email></author></authors>
13
+ <date>2014-03-20</date>
14
+ <time>03:08:56</time>
15
+ <contents><target name="magecommunity"><dir name="CosmicCart"><dir name="Integration"><dir name="Helper"><file name="Data.php" hash="acf1dcb9a7d4c4a222be6aa7ed48f7d3"/></dir><dir name="Model"><file name="AccessToken.php" hash="1f84f5309ed97c8bc5b5df30021cc74d"/><dir name="Api"><file name="Resource.php" hash="dc3577483182bec3735866ca978c31e4"/><file name="V2.php" hash="ca0175ece351e5fbd210a8b14831562e"/></dir><file name="Api.php" hash="acd4ae1973137e6327543b55c8a5dcf6"/><file name="Client.php" hash="f2f55da3082d4810bf6ce38094441440"/><dir name="Order"><dir name="Api"><file name="V2.php" hash="5b4e28f45df5e46b4b716309fc06344d"/></dir></dir><file name="Pay.php" hash="8d0e0dffafc1b98aa5b5441d1f4a022d"/><dir name="Product"><dir name="Api"><file name="V2.php" hash="1d7b58e13f7d5d89296a77e093c0c9c2"/></dir></dir><dir name="Resource"><dir name="AccessToken"><file name="Collection.php" hash="61d0ff861afe9f000a61fa2fc3f90fc9"/></dir><file name="AccessToken.php" hash="eff9686094e3be55dbe788a9ff2ad58c"/><dir name="Client"><file name="Collection.php" hash="4adba46f0ad7611843f3c3b46dc3f5aa"/></dir><file name="Client.php" hash="967ad8f745c507f76e73fc20378c8da7"/><file name="Setup.php" hash="b87546752cae424e8b05a1d18d36b1ca"/></dir><dir name="Shipment"><file name="Observer.php" hash="e96758f1cbc16ce0c5deac559c34bd80"/></dir></dir><file name="OAuth2Client.php" hash="54b24a536faa657c1fe12c9459d83c60"/><dir name="controllers"><dir name="Adminhtml"><file name="ActivationController.php" hash="fc2c25f8b7f7958dda314be570abdce5"/></dir></dir><dir name="etc"><file name="api.xml" hash="4cae4d1b7c5cb76f0506b39f43205794"/><file name="config.xml" hash="27989b17aa427aa61cdd5d0e69f3f735"/><file name="cosmiccart.ini" hash="7229e7a65baa87a8a90dd5c99252d128"/><file name="system.xml" hash="02de404cbab2f861e98f95a1304d505b"/><file name="wsdl.xml" hash="fd1febd239c3c0d43192474aacbd70b0"/><file name="wsi.xml" hash="3696f3eb1c899b69fe2b154fe00c68b4"/></dir><dir name="sql"><dir name="cosmiccart_integration_setup"><file name="install-1.0.0.php" hash="b6d7fb14feef5107e7858f23146e0452"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="cosmiccart"><file name="integration.xml" hash="c421b9cac7044139ae895ac370a9cfb2"/></dir></dir><dir name="template"><dir name="cosmiccart"><file name="activation.phtml" hash="71d6ce72b450e2c4d9a06c26707a34ce"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="CosmicCart_Integration.xml" hash="b33d7bbfcd97eedaab65dfd8b6869de1"/></dir></target><target name="magelocale"><dir><dir name="en_US"><file name="CosmicCart_Integration.csv" hash="0fb30b06828b751acc792a2b9d77b3a7"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>5.5.10</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.8.0.0</min><max/></package></required></dependencies>
18
+ </package>