shipping_easy - Version 0.1.0

Version Notes

Easily integrate your Magento store with ShippingEasy to allow your order, tracking and fulfillment data to populate in real-time across all systems. Plug in your UPS and FedEx accounts or other marketplaces like eBay or Amazon to download all new orders and easily assign shipping preferences, rates and delivery options in real-time.

Download this release

Release Info

Developer Jack
Extension shipping_easy
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Shippingeasy/Fulfilment/Block/Adminhtml/Sales/Order/View.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml sales order view
5
+ *
6
+ * @category Mage
7
+ * @package Shippingeasy_Fulfilment
8
+ */
9
+ class Shippingeasy_Fulfilment_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
10
+
11
+ public function __construct() {
12
+
13
+ parent::__construct();
14
+
15
+ if (Mage::getModel('fulfilment/fulfilment')->isEnabled()):
16
+
17
+ if ($this->getOrder()->getIsExported() == '0'):
18
+ $message = Mage::helper('fulfilment')->__('Are you sure you want to send this order to ShippingEasy?');
19
+ $this->_addButton('shippingeasy_id', array(
20
+ 'label' => Mage::helper('fulfilment')->__('Export to ShippingEasy'),
21
+ 'onclick' => "confirmSetLocation('{$message}', '{$this->getshippingEastUrl()}')",
22
+ 'class' => 'go'), 0, 100, 'header', 'header');
23
+ endif;
24
+
25
+ if ($this->getOrder()->getIsExported() == '1'):
26
+ $messageCancel = Mage::helper('fulfilment')->__('Are you sure you want to cancel this order in ShippingEasy?');
27
+ $this->_addButton('shippingeasy_cancel', array(
28
+ 'label' => Mage::helper('fulfilment')->__('Cancel Order in ShippingEasy'),
29
+ 'onclick' => "confirmSetLocation('{$messageCancel}', '{$this->getshippingEastCancelUrl()}')",
30
+ 'class' => 'go'), 1, 110, 'header', 'header');
31
+ endif;
32
+ endif;
33
+ }
34
+
35
+ public function getshippingEastUrl() {
36
+ return $this->getUrl('shippingeasy/adminhtml_fulfilment/export/');
37
+ }
38
+
39
+ public function getshippingEastCancelUrl() {
40
+ return $this->getUrl('shippingeasy/adminhtml_fulfilment/cancel/');
41
+ }
42
+
43
+ }
44
+
app/code/community/Shippingeasy/Fulfilment/Block/Adminhtml/System/Config/Error/Log.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shippingeasy
4
+ * @package Shippingeasy_Fulfilment
5
+ *
6
+ */
7
+
8
+ class Shippingeasy_Fulfilment_Block_Adminhtml_System_Config_Error_Log
9
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
10
+ {
11
+ /*
12
+ * Set template
13
+ */
14
+ protected function _construct()
15
+ {
16
+ parent::_construct();
17
+ $this->setTemplate('shippingeasy/errorlog.phtml');
18
+ }
19
+
20
+ public function render(Varien_Data_Form_Element_Abstract $element)
21
+ {
22
+ $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
23
+ return parent::render($element);
24
+ }
25
+
26
+ /**
27
+ * Return element html
28
+ *
29
+ * @param Varien_Data_Form_Element_Abstract $element
30
+ * @return string
31
+ */
32
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
33
+ {
34
+ return $this->_toHtml();
35
+ }
36
+
37
+ }
app/code/community/Shippingeasy/Fulfilment/Helper/Data.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Shippingeasy
5
+ * @package Shippingeasy_Fulfilment
6
+ *
7
+ */
8
+ class Shippingeasy_Fulfilment_Helper_Data extends Mage_Core_Helper_Abstract {
9
+
10
+ }
app/code/community/Shippingeasy/Fulfilment/Model/Fulfilment.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Shippingeasy
5
+ * @package Shippingeasy_Fulfilment
6
+ *
7
+ */
8
+ require_once(Mage::getBaseDir('lib') . '/ShippingEasy.php');
9
+
10
+ class Shippingeasy_Fulfilment_Model_Fulfilment extends Mage_Core_Model_Abstract {
11
+
12
+ const SHIPEASY_ENABLED = 'shippingeasy/fulfilment/active';
13
+ const SHIPEASY_STORE_APIKEY = 'shippingeasy/fulfilment/apikey';
14
+ const SHIPEASY_SECRET_APIKEY = 'shippingeasy/fulfilment/secretkey';
15
+ const SHIPEASY_STORE_URL = 'shippingeasy/fulfilment/url';
16
+ const STORE_APIKEY = 'shippingeasy/fulfilment/store_apikey';
17
+ const WEIGHT_UNIT = 'shippingeasy/fulfilment/weight_unit';
18
+
19
+ public function _construct() {
20
+ parent::_construct();
21
+ $this->_init('fulfilment/fulfilment');
22
+ }
23
+
24
+ public function isEnabled() {
25
+ if (Mage::getStoreConfig(self::SHIPEASY_ENABLED) == false):
26
+ return FALSE;
27
+ else:
28
+ return TRUE;
29
+ endif;
30
+ }
31
+
32
+ public function exportMissingProcessedOrders() {
33
+ Mage::getModel('fulfilment/observer')->submitOrder('36', true);
34
+ }
35
+
36
+ public function cancelOrder($orderId) {
37
+ $order = Mage::getModel('sales/order')->load($orderId);
38
+
39
+ if ($order) {
40
+ Mage::getModel('fulfilment/observer')->setShippingEasyConfiguration();
41
+
42
+ $cancellation = new ShippingEasy_Cancellation(Mage::getStoreConfig(Shippingeasy_Fulfilment_Model_Observer::STORE_APIKEY), $order->getIncrementId());
43
+ $response = $cancellation->create();
44
+
45
+ if (isset($response)):
46
+ if ($response['order']['external_order_identifier'] == $order->getIncrementId()):
47
+ $comment = 'Order successfully cancelled in ShippingEasy';
48
+ $order->addStatusHistoryComment($comment, false);
49
+ $order->setIsExported('2')->save();
50
+ return true;
51
+ else:
52
+ return false;
53
+ endif;
54
+ else:
55
+ return false;
56
+ endif;
57
+ }
58
+ }
59
+
60
+ public function createShipment($orderIncrementId, $trackingNo, $carrierKey, $carrierServiceKey) {
61
+ $itemsToship = array();
62
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
63
+ if ($order) {
64
+ if ($order->canShip()) { /// Making shipments
65
+ $convertor = Mage::getModel('sales/convert_order');
66
+ $shipment = $convertor->toShipment($order);
67
+ $totalToShip = count($order->getAllItems());
68
+ foreach ($order->getAllItems() as $orderItem) {
69
+ if (!$orderItem->getQtyToShip()) {
70
+ continue;
71
+ }
72
+ if ($orderItem->getIsVirtual()) {
73
+ continue;
74
+ }
75
+ $item = $convertor->itemToShipmentItem($orderItem);
76
+ $qty = $orderItem->getQtyToShip();
77
+ $item->setQty($qty);
78
+ $shipment->addItem($item);
79
+ } //end of foreach
80
+
81
+ if ($shipment && $totalToShip != '') {
82
+ $shipment->register();
83
+ $order->setIsInProcess(true);
84
+ $transactionSave = Mage::getModel('core/resource_transaction')
85
+ ->addObject($shipment)
86
+ ->addObject($shipment->getOrder())
87
+ ->save();
88
+
89
+ Mage::log('New Shipment created for ' . $incId, 'shippingEasy.log');
90
+ $shipment = Mage::getModel('sales/order_shipment')->load($shipment->getEntityId());
91
+ } else { //echo "BBB"; exit;
92
+ $shipment = Mage::getResourceModel('sales/order_shipment_collection')
93
+ ->addAttributeToSelect('*')
94
+ ->setOrderFilter($order->getData('entity_id'));
95
+ $shipment = $shipment->getFirstItem(); // loading collection and get 1st shipment
96
+ }
97
+ } else { // shipment already added -load shipment Object and add tracking information only.
98
+ $shipment = Mage::getResourceModel('sales/order_shipment_collection')
99
+ ->addAttributeToSelect('*')
100
+ ->setOrderFilter($order->getData('entity_id'));
101
+ $shipment = $shipment->getFirstItem(); // loading collection and get 1st shipment
102
+ }
103
+
104
+ // add tracking information ///
105
+ if ($shipment)
106
+ $trackingCodes = array();
107
+ if ($shipment->getData('entity_id')) {
108
+ $shipment = Mage::getModel('sales/order_shipment')->load($shipment->getEntityId());
109
+ if ($this->checkAlreadyAdded($trackingNo) && !in_array($trackingNo, $trackingCodes)) {
110
+ $sendEmail = true;
111
+ $track = Mage::getModel('sales/order_shipment_track')
112
+ ->setNumber($trackingNo)
113
+ ->setCarrierCode(strtolower($carrierKey))
114
+ ->setTitle($carrierKey . " - " . $carrierServiceKey);
115
+ $shipment->addTrack($track);
116
+ array_push($trackingCodes, $trackingNo);
117
+ unset($track);
118
+ }
119
+ if ($sendEmail == true) {
120
+ $shipment->save();
121
+ $shipment->sendEmail(true)->setEmailSent(true)->save();
122
+ $order->save();
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ public function checkAlreadyAdded($trackingCode) {
129
+ $track = Mage::getModel('sales/order_shipment_track')->getCollection();
130
+ $track->addFieldtoFilter('track_number', $trackingCode);
131
+ if ($track->getSize() == 0) {
132
+ return true;
133
+ } else {
134
+ return false;
135
+ }
136
+ }
137
+
138
+ }
app/code/community/Shippingeasy/Fulfilment/Model/Mysql4/Setup.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Shippingeasy Setup
5
+ *
6
+ * @category Shippingeasy
7
+ * @package Shippingeasy_Fulfilment
8
+ *
9
+ */
10
+ class Shippingeasy_Fulfilment_Model_Mysql4_Setup extends Mage_Core_Model_Resource_Setup {
11
+
12
+ }
app/code/community/Shippingeasy/Fulfilment/Model/Observer.php ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Shippingeasy
5
+ * @package Shippingeasy_Fulfilment
6
+ *
7
+ */
8
+ require_once(Mage::getBaseDir('lib') . '/ShippingEasy.php');
9
+
10
+ class Shippingeasy_Fulfilment_Model_Observer {
11
+
12
+ const SHIPEASY_ENABLED = 'shippingeasy/fulfilment/active';
13
+ const SHIPEASY_STORE_APIKEY = 'shippingeasy/fulfilment/apikey';
14
+ const SHIPEASY_SECRET_APIKEY = 'shippingeasy/fulfilment/secretkey';
15
+ const SHIPEASY_STORE_URL = 'shippingeasy/fulfilment/url';
16
+ const STORE_APIKEY = 'shippingeasy/fulfilment/store_apikey';
17
+ const WEIGHT_UNIT = 'shippingeasy/fulfilment/weight_unit';
18
+ const BIN_PICKING_NUMBER = 'shippingeasy/fulfilment/bin_picking_number';
19
+
20
+ public function multiShippingOrders($observer) {
21
+
22
+ $orderIds = $observer->getOrderIds();
23
+ if (is_array($orderIds)):
24
+ foreach ($orderIds as $i => $id):
25
+ $this->submitOrder($id, TRUE);
26
+ endforeach;
27
+ endif;
28
+ }
29
+
30
+ public function submitOrder($observer, $missing = false) {
31
+
32
+ if (Mage::getStoreConfig(self::SHIPEASY_ENABLED) == false):
33
+ return;
34
+ endif;
35
+
36
+ $orderId = Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastOrderId();
37
+ $checkOutType = Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod();
38
+ if ($missing == true) {
39
+ $orderId = $observer;
40
+ } else if (empty($orderId)) { // backend order
41
+ $order = $observer->getEvent()->getOrder();
42
+ $orderId = $order->getData('entity_id');
43
+ }
44
+
45
+ $shipEasy = new Varien_Object();
46
+
47
+ $order = Mage::getModel('sales/order')->load($orderId);
48
+ $shipping = $order->getShippingAddress();
49
+
50
+ $shipEasy->setExternalOrderIdentifier($order->getIncrementId());
51
+ $shipEasy->setOrderedAt($order->getCreatedAt());
52
+ $shipEasy->setOrderStatus('awaiting_shipment');
53
+ $shipEasy->setSubtotalIncludingTax($this->fnumb($order->getSubtotalInclTax()));
54
+ $shipEasy->setTotalIncludingTax($this->fnumb($order->getGrandTotal()));
55
+ $shipEasy->setTotalExcludingTax($this->fnumb( ($order->getGrandTotal() - $order->getTaxAmount() ) ));
56
+
57
+ $shipEasy->setDiscountAmount($this->fnumb( $order->getDiscountAmount() ));
58
+ $shipEasy->setCouponDiscount($this->fnumb(0));
59
+ $shipEasy->setSubtotalIncludingTax($this->fnumb($order->getSubtotalInclTax() ));
60
+ $shipEasy->setSubtotalExcludingTax($this->fnumb($order->getSubtotal() ));
61
+ $shipEasy->setSubtotalTax($this->fnumb($order->getTaxAmount() ));
62
+
63
+ $shipEasy->setTotalTax($this->fnumb( $order->getTaxAmount()));
64
+ $shipEasy->setBaseShippingCost($this->fnumb($order->getBaseShippingAmount()));
65
+ $shipEasy->setShippingCostIncludingTax($this->fnumb($order->getShippingAmount()));
66
+ $shipEasy->setShippingCostExcludingTax($this->fnumb($order->getShippingAmount()));
67
+
68
+ $shipEasy->setShippingCostTax($this->fnumb($order->getBaseShippingTaxAmount()));
69
+ $shipEasy->setBaseHandlingCost(0.00);
70
+ $shipEasy->setHandlingCostExcludingTax(0.00);
71
+ $shipEasy->setHandlingCostIncludingTax(0.00);
72
+ $shipEasy->setHandlingCostTax(0.00);
73
+ $shipEasy->setBaseWrappingCost(0.00);
74
+ $shipEasy->setWrappingCostExcludingTax(0.00);
75
+ $shipEasy->setWrappingCostIncludingTax(0.00);
76
+ $shipEasy->setWrappingCostTax(0.00);
77
+ $shipEasy->setNotes("");
78
+
79
+
80
+ //billing
81
+ $billing = $order->getBillingAddress();
82
+ //$bill_country = Mage::getModel('directory/country')->load($billing->getCountryId())->getData('iso3_code');
83
+ $bill_country = Mage::getModel('directory/country')->load($billing->getCountryId())->getName();
84
+ if (is_array($billing->getStreet())):
85
+ $billAddress = $billing->getStreet();
86
+ if (isset($billAddress[1])):
87
+ $shipEasy->setBillingAddress($billAddress[0]);
88
+ $shipEasy->setBillingAddress2($billAddress[1]);
89
+ else:
90
+ $shipEasy->setBillingAddress($billAddress[0]);
91
+ endif;
92
+ else:
93
+ $shipEasy->setBillingAddress($billing->getStreet());
94
+ endif;
95
+
96
+ $shipEasy->setBillingCompany($billing->getCompany());
97
+ $shipEasy->setBillingFirstName($billing->getFirstname());
98
+ $shipEasy->setBillingLastName($billing->getLastname());
99
+ $shipEasy->setBillingCity($billing->getCity());
100
+ $shipEasy->setBillingState($billing->getRegion());
101
+ $shipEasy->setBillingPostalCode($billing->getPostcode());
102
+
103
+ $shipEasy->setBillingCountry($bill_country);
104
+ $shipEasy->setBillingPhoneNumber($billing->getTelephone());
105
+ $shipEasy->setBillingEmail($billing->getEmail());
106
+
107
+ // shipping
108
+ $recipients = new Varien_Object();
109
+ $shipping = $order->getShippingAddress();
110
+ $shipCountry = Mage::getModel('directory/country')->load($shipping->getCountryId())->getData('iso3_code');
111
+ $shipCountry = Mage::getModel('directory/country')->load($shipping->getCountryId())->getName();
112
+ if (is_array($shipping->getStreet())):
113
+ $shipAddress = $shipping->getStreet();
114
+ if (isset($shipAddress[1])):
115
+ $recipients->setAddress($shipAddress[0]);
116
+ $recipients->setAddress2($shipAddress[1]);
117
+ else:
118
+ $recipients->setAddress($shipAddress[0]);
119
+ endif;
120
+ else:
121
+ $recipients->setAddress($shipping->getStreet());
122
+ endif;
123
+
124
+ $recipients->setCompany($shipping->getCompany());
125
+ $recipients->setFirstName($shipping->getFirstname());
126
+ $recipients->setLastName($shipping->getLastname());
127
+ $recipients->setCity($shipping->getCity());
128
+ $recipients->setState($shipping->getRegion());
129
+ $recipients->setPostalCode($shipping->getPostcode());
130
+
131
+ $recipients->setCountry($shipCountry);
132
+ $recipients->setPhoneNumber($shipping->getTelephone());
133
+ $recipients->setEmail($shipping->getEmail());
134
+ $recipients->setResidential(true);
135
+ $recipients->setShippingMethod($order->getShippingDescription());
136
+ $recipients->setBaseCost($this->fnumb( $order->getBaseShippingInclTax()));
137
+ $recipients->setCostExcludingTax($this->fnumb(($order->getBaseShippingAmount() - $order->getBaseShippingTaxAmount())));
138
+ $recipients->setCostTax($this->fnumb($order->getBaseShippingTaxAmount()));
139
+ $recipients->setBaseHandlingCost(0.00);
140
+ $recipients->setHandlingCostExcludingTax(0.00);
141
+ $recipients->setHandlingCostIncludingTax(0.00);
142
+ $recipients->setHandlingCostTax(0.00);
143
+ $recipients->setShippingZoneId("123");
144
+ $recipients->setShippingZoneName("XYZ");
145
+
146
+
147
+
148
+ // line items
149
+ $lineItems = array();
150
+ $items = $order->getAllVisibleItems();
151
+ foreach ($items as $i => $item):
152
+
153
+ // if ($item->getData('product_type') == 'simple') :
154
+ $_unit = Mage::getStoreConfig(self::WEIGHT_UNIT);
155
+ if ($_unit == 'KGS')
156
+ $weight = $item->getWeight() * "35.274";
157
+ if ($_unit == 'LBS')
158
+ $weight = $item->getWeight() * "16";
159
+
160
+ $lineItem = new Varien_Object();
161
+ $lineItem->setItemName($item->getName());
162
+ $lineItem->setSku($item->getSku());
163
+ $lineItem->setBinPickingNumber(Mage::getStoreConfig(self::BIN_PICKING_NUMBER));
164
+ $lineItem->setUnitPrice($this->fnumb($item->getPrice()));
165
+ $lineItem->setTotalExcludingTax($this->fnumb($item->getPrice()));
166
+ $lineItem->setWeightInOunces($weight);
167
+ $lineItem->setQuantity((int) $item->getQtyOrdered());
168
+ /*
169
+ if ($item->getData('product_type') == 'configurable') :
170
+ $_option = $this->getItemOptions($item);
171
+ $optStr = "";
172
+ foreach($_option as $lb=>$vall) {
173
+ $optStr .= "#".$vall['label']."=".$vall['value'].":";
174
+ }
175
+ $lineItem->setProductOptions($optStr);
176
+ endif;
177
+ */
178
+
179
+ $lineItems[] = $lineItem->toArray();
180
+
181
+
182
+ //array_push($lineItems, $lineItem->toArray());
183
+ //endif;
184
+ endforeach;
185
+
186
+ $recipients->setItemsTotal(count($lineItems));
187
+ $recipients->setItemsShipped(0);
188
+ $recipients->setLineItems($lineItems);
189
+ $recpArray = array();
190
+ $recpArray[] = $recipients->toArray();
191
+ $shipEasy->setRecipients($recpArray);
192
+
193
+ $_succ = false;
194
+ try {
195
+ $this->setShippingEasyConfiguration();
196
+ $_shippingEasy = new ShippingEasy_Order(Mage::getStoreConfig(self::STORE_APIKEY), $shipEasy->toArray());
197
+ $result = $_shippingEasy->create();
198
+ $_succ = true;
199
+ Mage::log("Order #" . $order->getData('increment_id') . " exported to shipping Easy", null, 'shippingEasy.log');
200
+ } catch (Exception $e) {
201
+ $_succ = false;
202
+ $_errorMsg = "Unable to connect with shippingEasy " . $e->getMessage();
203
+ Mage::log("Unable to connect with shippingEasy " . $e->getMessage().".Order #".$order->getData('increment_id')." failed to export.", null, 'shippingEasy.log');
204
+ Mage::log("Unable to connect with shippingEasy " . $e->getMessage().".Order #".$order->getData('increment_id')." failed to export.".print_r($shipEasy->toArray(), true), null, 'shippingEasyDetails.log');
205
+
206
+ }
207
+
208
+ if($_succ == true) {
209
+ $order->setData('is_exported', '1');
210
+ $comment = 'Order successfully exported to Shipping Easy';
211
+ $order->addStatusHistoryComment($comment, false);
212
+ $order->save();
213
+ } else {
214
+ $comment = $_errorMsg;
215
+ $order->addStatusHistoryComment($comment, false);
216
+ $order->save();
217
+ }
218
+ if($missing == true)
219
+ return $_succ;
220
+ }
221
+
222
+ public function cancelOrder($observer) {
223
+
224
+ try {
225
+ $_orderId = $observer->getOrder()->getEntityId();
226
+ Mage::getModel('fulfilment/fulfilment')->cancelOrder($_orderId);
227
+ } catch (Exception $e) {
228
+ Mage::log("Unable to connect with shippingEasy " . $e->getMessage(), null, 'shippingEasy.log');
229
+ }
230
+ }
231
+
232
+ public function setShippingEasyConfiguration() {
233
+ ShippingEasy::setApiKey(Mage::getStoreConfig(self::SHIPEASY_STORE_APIKEY)); //api key
234
+ ShippingEasy::setApiSecret(Mage::getStoreConfig(self::SHIPEASY_SECRET_APIKEY));
235
+ ShippingEasy::setApiBase(Mage::getStoreConfig(self::SHIPEASY_STORE_URL));
236
+ }
237
+
238
+ public function fnumb($number) {
239
+ return number_format($number, 2, '.', '');
240
+ }
241
+
242
+ public function getItemOptions($item)
243
+ {
244
+ $result = array();
245
+ if ($options = $item->getProductOptions()) {
246
+ if (isset($options['options'])) {
247
+ $result = array_merge($result, $options['options']);
248
+ }
249
+ if (isset($options['additional_options'])) {
250
+ $result = array_merge($result, $options['additional_options']);
251
+ }
252
+ if (isset($options['attributes_info'])) {
253
+ $result = array_merge($result, $options['attributes_info']);
254
+ }
255
+ }
256
+ return $result;
257
+ }
258
+ }
app/code/community/Shippingeasy/Fulfilment/controllers/Adminhtml/FulfilmentController.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Shippingeasy
5
+ * @package Shippingeasy_Fulfilment
6
+ *
7
+ */
8
+ class Shippingeasy_Fulfilment_Adminhtml_FulfilmentController extends Mage_Adminhtml_Controller_action {
9
+
10
+ public function exportAction() {
11
+ $_orderId = $this->getRequest()->getParam('order_id');
12
+ if ($_orderId) {
13
+ try {
14
+ $resp = Mage::getModel('fulfilment/observer')->submitOrder($_orderId, true);
15
+ if($resp == true)
16
+ $this->_getSession()->addSuccess($this->__('The order has been sent to ShippingEasy.'));
17
+ else
18
+ $this->_getSession()->addError($this->__('Failed to send the order to ShippingEasy.'));
19
+ } catch (Mage_Core_Exception $e) {
20
+ $this->_getSession()->addError($e->getMessage());
21
+ } catch (Exception $e) {
22
+ $this->_getSession()->addError($this->__('Failed to send the order to ShippingEasy. %s', $e->getMessage()));
23
+ Mage::logException($e);
24
+ }
25
+ }
26
+ Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/sales_order/view", array('order_id' => $_orderId)));
27
+ }
28
+
29
+ public function cancelAction() {
30
+ $_orderId = $this->getRequest()->getParam('order_id');
31
+ if ($_orderId) {
32
+ try {
33
+ Mage::getModel('fulfilment/fulfilment')->cancelOrder($_orderId);
34
+ $this->_getSession()->addSuccess($this->__('The order has been successfully cancelled in ShippingEasy.'));
35
+ } catch (Mage_Core_Exception $e) {
36
+ $this->_getSession()->addError($e->getMessage());
37
+ } catch (Exception $e) {
38
+ $this->_getSession()->addError($this->__('Unable to cancel the order in ShippingEasy. %s', $e->getMessage()));
39
+ Mage::logException($e);
40
+ }
41
+ }
42
+ Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/sales_order/view", array('order_id' => $_orderId)));
43
+ }
44
+
45
+ }
app/code/community/Shippingeasy/Fulfilment/controllers/CallbackController.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Shippingeasy
5
+ * @package Shippingeasy_Fulfilment
6
+ *
7
+ */
8
+ require_once(Mage::getBaseDir('lib') . '/ShippingEasy.php');
9
+
10
+ class Shippingeasy_Fulfilment_CallbackController extends Mage_Core_Controller_Front_Action {
11
+
12
+ const SHIPEASY_ENABLED = 'shippingeasy/fulfilment/active';
13
+ const SHIPEASY_STORE_APIKEY = 'shippingeasy/fulfilment/apikey';
14
+ const SHIPEASY_SECRET_APIKEY = 'shippingeasy/fulfilment/secretkey';
15
+ const SHIPEASY_STORE_URL = 'shippingeasy/fulfilment/url';
16
+ const STORE_APIKEY = 'shippingeasy/fulfilment/store_apikey';
17
+ const WEIGHT_UNIT = 'shippingeasy/fulfilment/weight_unit';
18
+
19
+ public function indexAction() {
20
+
21
+ $this->setShippingEasyConfiguration();
22
+ $values = file_get_contents('php://input');
23
+ $output = json_decode($values, true);
24
+ $params = $_REQUEST;
25
+ $authenticator = new ShippingEasy_Authenticator("get", "/magento/shippingeasy/callback", $params, $values, Mage::getStoreConfig(self::SHIPEASY_SECRET_APIKEY));
26
+ Mage::log($values, null, "shippingEasy.log");
27
+ Mage::log($output, null, "shippingEasy.log");
28
+ Mage::log($authenticator, null, "shippingEasy.log");
29
+
30
+ Mage::log("====" . $authenticator->getExpectedSignature() . "======" . $authenticator->getSuppliedSignatureString(), null, "shippingEasy.log");
31
+ Mage::log("====" . $authenticator->isAuthenticated(), null, "shippingEasy.log");
32
+ $orderIncrementId = $output['shipment']['orders']['0']['external_order_identifier'];
33
+ $trackingNo = $output['shipment']['tracking_number'];
34
+ $carrierKey = $output['shipment']['carrier_key'];
35
+ $carrierServiceKey = $output['shipment']['carrier_service_key'];
36
+
37
+ Mage::log($orderIncrementId . "===" . $trackingNo . "===" . $carrierKey . "===" . $carrierServiceKey, null, "shippingEasy.log");
38
+ Mage::getModel('fulfilment/fulfilment')->createShipment($orderIncrementId, $trackingNo, $carrierKey, $carrierServiceKey);
39
+ }
40
+
41
+ public function setShippingEasyConfiguration() {
42
+ ShippingEasy::setApiKey(Mage::getStoreConfig(self::SHIPEASY_STORE_APIKEY)); //api key
43
+ ShippingEasy::setApiSecret(Mage::getStoreConfig(self::SHIPEASY_SECRET_APIKEY));
44
+ ShippingEasy::setApiBase(Mage::getStoreConfig(self::SHIPEASY_STORE_URL));
45
+ }
46
+
47
+ }
app/code/community/Shippingeasy/Fulfilment/controllers/IndexController.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shippingeasy_Fulfilment_IndexController extends Mage_Core_Controller_Front_Action {
4
+
5
+ public function indexAction() {
6
+ $this->loadLayout();
7
+ $this->renderLayout();
8
+ }
9
+
10
+ }
app/code/community/Shippingeasy/Fulfilment/etc/config.xml ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shippingeasy_Fulfilment>
5
+ <version>0.1.0</version>
6
+ </Shippingeasy_Fulfilment>
7
+ </modules>
8
+ <frontend>
9
+ <secure_url>
10
+ <customer>/shippingeasy/</customer>
11
+ </secure_url>
12
+ <routers>
13
+ <fulfilment>
14
+ <use>standard</use>
15
+ <args>
16
+ <module>Shippingeasy_Fulfilment</module>
17
+ <frontName>shippingeasy</frontName>
18
+ </args>
19
+ </fulfilment>
20
+ </routers>
21
+ <events>
22
+ <checkout_onepage_controller_success_action>
23
+ <observers>
24
+ <shippingeasy_order_success>
25
+ <type>singleton</type>
26
+ <class>fulfilment/observer</class>
27
+ <method>submitOrder</method>
28
+ </shippingeasy_order_success>
29
+ </observers>
30
+ </checkout_onepage_controller_success_action>
31
+
32
+ <checkout_multishipping_controller_success_action>
33
+ <observers>
34
+ <shippingeasy_order_success>
35
+ <type>singleton</type>
36
+ <class>fulfilment/observer</class>
37
+ <method>multiShippingOrders</method>
38
+ </shippingeasy_order_success>
39
+ </observers>
40
+ </checkout_multishipping_controller_success_action>
41
+ </events>
42
+ </frontend>
43
+ <admin>
44
+ <routers>
45
+ <fulfilment>
46
+ <use>admin</use>
47
+ <args>
48
+ <module>Shippingeasy_Fulfilment</module>
49
+ <frontName>shippingeasy</frontName>
50
+ </args>
51
+ </fulfilment>
52
+ </routers>
53
+ </admin>
54
+ <adminhtml>
55
+ <acl>
56
+ <resources>
57
+ <admin>
58
+ <children>
59
+ <system>
60
+ <children>
61
+ <config>
62
+ <children>
63
+ <shippingeasy>
64
+ <title>Shipping Easy Integration Configuration</title>
65
+ </shippingeasy>
66
+ </children>
67
+ </config>
68
+ </children>
69
+ </system>
70
+ </children>
71
+ </admin>
72
+ </resources>
73
+ </acl>
74
+
75
+
76
+ <events>
77
+ <checkout_submit_all_after>
78
+ <observers>
79
+ <adminhtml_order_success>
80
+ <type>singleton</type>
81
+ <class>fulfilment/observer</class>
82
+ <method>submitOrder</method>
83
+ </adminhtml_order_success>
84
+ </observers>
85
+ </checkout_submit_all_after>
86
+ <order_cancel_after>
87
+ <observers>
88
+ <shippingeasy_order_cancel_after>
89
+ <type>singleton</type>
90
+ <class>fulfilment/observer</class>
91
+ <method>cancelOrder</method>
92
+ </shippingeasy_order_cancel_after>
93
+ </observers>
94
+ </order_cancel_after>
95
+ </events>
96
+ </adminhtml>
97
+
98
+ <global>
99
+ <blocks>
100
+ <adminhtml>
101
+ <rewrite>
102
+ <sales_order_view>Shippingeasy_Fulfilment_Block_Adminhtml_Sales_Order_View</sales_order_view>
103
+ </rewrite>
104
+ </adminhtml>
105
+ </blocks>
106
+ <models>
107
+ <fulfilment>
108
+ <class>Shippingeasy_Fulfilment_Model</class>
109
+ <resourceModel>fulfilment_mysql4</resourceModel>
110
+ </fulfilment>
111
+ </models>
112
+ <resources>
113
+ <fulfilment_setup>
114
+ <setup>
115
+ <module>Shippingeasy_Fulfilment</module>
116
+ <class>Shippingeasy_Fulfilment_Model_Mysql4_Setup</class>
117
+ </setup>
118
+ </fulfilment_setup>
119
+ </resources>
120
+
121
+ <helpers>
122
+ <fulfilment>
123
+ <class>Shippingeasy_Fulfilment_Helper</class>
124
+ </fulfilment>
125
+ </helpers>
126
+ </global>
127
+ </config>
app/code/community/Shippingeasy/Fulfilment/etc/system.xml ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Shippingeasy
5
+ * @package Shippingeasy_Fulfilment
6
+ */
7
+ -->
8
+
9
+
10
+ <config>
11
+ <sections>
12
+ <shippingeasy>
13
+ <label>ShippingEasy Configuration</label>
14
+ <tab>sales</tab>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>306</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <groups>
21
+ <fulfilment translate="label" module="fulfilment">
22
+ <label>ShippingEasy Configuration</label>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>1</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>0</show_in_store>
28
+ <fields>
29
+ <active translate="label">
30
+ <label>Enabled</label>
31
+ <frontend_type>select</frontend_type>
32
+ <source_model>adminhtml/system_config_source_yesno</source_model>
33
+ <sort_order>0</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>1</show_in_website>
36
+ <show_in_store>0</show_in_store>
37
+ </active>
38
+
39
+ <apikey translate="label">
40
+ <label>ShippingEasy API Key</label>
41
+ <frontend_type>text</frontend_type>
42
+ <sort_order>1</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>0</show_in_store>
46
+ </apikey>
47
+
48
+ <secretkey translate="label">
49
+ <label>ShippingEasy Secret Key</label>
50
+ <frontend_type>text</frontend_type>
51
+ <sort_order>2</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>0</show_in_store>
55
+ </secretkey>
56
+
57
+ <url translate="label">
58
+ <label>ShippingEasy URL</label>
59
+ <frontend_type>text</frontend_type>
60
+ <sort_order>2</sort_order>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>0</show_in_store>
64
+ </url>
65
+
66
+ <store_apikey translate="label">
67
+ <label>Store API Key</label>
68
+ <frontend_type>text</frontend_type>
69
+ <sort_order>3</sort_order>
70
+ <show_in_default>1</show_in_default>
71
+ <show_in_website>1</show_in_website>
72
+ <show_in_store>0</show_in_store>
73
+ </store_apikey>
74
+
75
+ <weight_unit translate="label">
76
+ <label>Product Weight Unit</label>
77
+ <!-- <frontend_type>text</frontend_type>-->
78
+ <frontend_type>select</frontend_type>
79
+ <source_model>usa/shipping_carrier_ups_source_unitofmeasure</source_model>
80
+ <sort_order>3</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>0</show_in_store>
84
+ <!-- <comment>Either KG/LB/Ounce</comment>-->
85
+ </weight_unit>
86
+
87
+ <bin_picking_number translate="label">
88
+ <label>Bin Picking Number</label>
89
+ <frontend_type>text</frontend_type>
90
+ <sort_order>3</sort_order>
91
+ <show_in_default>1</show_in_default>
92
+ <show_in_website>1</show_in_website>
93
+ <show_in_store>0</show_in_store>
94
+ </bin_picking_number>
95
+ <errorlogs translate="label comment">
96
+ <label>ShippingEasy Log Information</label>
97
+ <frontend_type>textarea</frontend_type>
98
+ <frontend_model>Shippingeasy_Fulfilment_Block_Adminhtml_System_Config_Error_Log</frontend_model>
99
+ <sort_order>300</sort_order>
100
+ <show_in_default>1</show_in_default>
101
+ <show_in_website>0</show_in_website>
102
+ <show_in_store>0</show_in_store>
103
+ <comment>Displays error.</comment>
104
+ </errorlogs>
105
+ </fields>
106
+ </fulfilment>
107
+ </groups>
108
+ </shippingeasy>
109
+ </sections>
110
+ </config>
app/code/community/Shippingeasy/Fulfilment/sql/fulfilment_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * adding an order level attribute for Shipping Easy module in order Module
6
+ *
7
+ *
8
+ */
9
+ $installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('sales_setup');
10
+ $installer->startSetup();
11
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'is_exported', "TINYINT(1) UNSIGNED DEFAULT '0'");
12
+
13
+ $installer->addAttribute('order', 'is_exported', array(
14
+ 'type' => 'int',
15
+ 'label' => 'Exported to Shipping Easy',
16
+ 'input' => 'select',
17
+ 'source' => 'eav/entity_attribute_source_boolean',
18
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
19
+ 'required' => false,
20
+ 'default' => '0'
21
+ ));
22
+
23
+
24
+ $installer->endSetup();
25
+ ?>
app/etc/modules/Shippingeasy_Fulfilment.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shippingeasy_Fulfilment>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Shippingeasy_Fulfilment>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>shipping_easy</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Multi-carrier and platform shipping. Best USPS rates, easy batching, endless support. Save time &amp; money today.&#xD;
10
+ </summary>
11
+ <description>Easily integrate your Magento store with ShippingEasy to allow your order, tracking and fulfillment data to populate in real-time across all systems. Plug in your UPS and FedEx accounts or other marketplaces like eBay or Amazon to download all new orders and easily assign shipping preferences, rates and delivery options in real-time.&#xD;
12
+ </description>
13
+ <notes>Easily integrate your Magento store with ShippingEasy to allow your order, tracking and fulfillment data to populate in real-time across all systems. Plug in your UPS and FedEx accounts or other marketplaces like eBay or Amazon to download all new orders and easily assign shipping preferences, rates and delivery options in real-time.&#xD;
14
+ </notes>
15
+ <authors><author><name>Jack</name><user>shippingdev</user><email>product@shippingeasy.com</email></author></authors>
16
+ <date>2014-06-25</date>
17
+ <time>08:52:58</time>
18
+ <contents><target name="magecommunity"><dir name="Shippingeasy"><dir name="Fulfilment"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="View.php" hash="4b07d6ef2eb76152552a8779396fd497"/></dir></dir><dir name="System"><dir name="Config"><dir name="Error"><file name="Log.php" hash="670c7844e74c77edbf8e107302bec459"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="35389df0229decf33cc6edbc40fe9a8e"/></dir><dir name="Model"><file name="Fulfilment.php" hash="0dab199d609570acc1a739d78fb1c16f"/><dir name="Mysql4"><file name="Setup.php" hash="65f5bfe931f05bb7e6a909945139f8a6"/></dir><file name="Observer.php" hash="2b53bf77d3621dff01365997653caf69"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FulfilmentController.php" hash="20a95b5004ec6f4a4ebc69701e1a447e"/></dir><file name="CallbackController.php" hash="1bf5faf00175da8caeab358ee589ff57"/><file name="IndexController.php" hash="9eb94acf7209f47c88b3422fb91a419d"/></dir><dir name="etc"><file name="config.xml" hash="863312552edc2cb323a2cb5d98c5301a"/><file name="system.xml" hash="b21e5500f85c2bc96bead2ef1d63d39a"/></dir><dir name="sql"><dir name="fulfilment_setup"><file name="mysql4-install-0.1.0.php" hash="421334e32d1cf529edfbfd4120d36239"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Shippingeasy_Fulfilment.xml" hash="02b8c2b545259a8f5a0ae457f5690ed7"/></dir></target><target name="magelocal"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><file name="shippingeasy.phtml" hash=""/></dir></dir></dir></dir></target></contents>
19
+ <compatible/>
20
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
21
+ </package>